Parcourir la source

#17 PinDrive

pull/188/head
mstroh76 il y a 9 mois
Parent
révision
107b9ee4c2
3 fichiers modifiés avec 49 ajouts et 6 suppressions
  1. +28
    -2
      gpio/gpio.c
  2. +20
    -4
      wiringPi/wiringPi.c
  3. +1
    -0
      wiringPi/wiringPi.h

+ 28
- 2
gpio/gpio.c Voir le fichier

@@ -794,6 +794,31 @@ void doMode (int argc, char *argv [])
*********************************************************************************
*/

static void doPadDrivePin (int argc, char *argv [])
{

if (argc != 4) {
fprintf (stderr, "Usage: %s drivepin pin value\n", argv [0]) ;
exit (1) ;
}

int pin = atoi (argv [2]) ;
int val = atoi (argv [3]) ;

if ((pin < 0) || (pin > 27)) {
fprintf (stderr, "%s: drive pin not 0-27: %d\n", argv [0], pin) ;
exit (1) ;
}

if ((val < 0) || (val > 3)) {
fprintf (stderr, "%s: drive value not 0-3: %d\n", argv [0], val) ;
exit (1) ;
}

setPadDrivePin (pin, val) ;
}


static void doPadDrive (int argc, char *argv [])
{
int group, val ;
@@ -807,13 +832,13 @@ static void doPadDrive (int argc, char *argv [])
group = atoi (argv [2]) ;
val = atoi (argv [3]) ;

if ((group < -1) || (group > 2)) //-1 hidden feature for read value of all
if ((group < -1) || (group > 2)) //-1 hidden feature for read and print values
{
fprintf (stderr, "%s: drive group not 0, 1 or 2: %d\n", argv [0], group) ;
exit (1) ;
}

if ((val < -1) || (val > 7))
if ((val < 0) || (val > 7))
{
fprintf (stderr, "%s: drive value not 0-7: %d\n", argv [0], val) ;
exit (1) ;
@@ -1536,6 +1561,7 @@ int main (int argc, char *argv [])
else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ;
else if (strcasecmp (argv [1], "pwmTone" ) == 0) doPwmTone (argc, argv) ;
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
else if (strcasecmp (argv [1], "drivepin" ) == 0) doPadDrivePin(argc, argv) ;
else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
else if (strcasecmp (argv [1], "pins" ) == 0) doReadall () ;


+ 20
- 4
wiringPi/wiringPi.c Voir le fichier

@@ -151,7 +151,10 @@ const unsigned int RP1_STATUS_LEVEL_MASK = 0x00C00000;
const unsigned int RP1_DEBOUNCE_DEFAULT_VALUE = 4;
const unsigned int RP1_DEBOUNCE_MASK = 0x7f;
const unsigned int RP1_DEBOUNCE_DEFAULT = (RP1_DEBOUNCE_DEFAULT_VALUE << 5);
const unsigned int RP1_PAD_DEFAULT = 0x5a;

const unsigned int RP1_PAD_DEFAULT_0TO8 = (0x0B | 0x70); //Slewfast, Schmitt, PullUp, | 12mA, Input enable
const unsigned int RP1_PAD_DEFAULT_FROM9 = (0x07 | 0x70); //Slewfast, Schmitt, PullDown, | 12mA, Input enable

const unsigned int RP1_PAD_DRIVE_MASK = 0x00000030;
const unsigned int RP1_INV_PAD_DRIVE_MASK = ~(RP1_PAD_DRIVE_MASK);

@@ -1248,6 +1251,19 @@ int physPinToGpio (int physPin)
* Set the PAD driver value
*********************************************************************************
*/
void setPadDrivePin (int pin, int value) {
if (PI_MODEL_5 != RaspberryPiModel) return;
if (pin < 0 || pin > GetMaxPin()) return ;

uint32_t wrVal;
value = value & 3; // 0-3 supported
wrVal = (value << 4); //Drive strength 0-3
pads[1+pin] = (pads[1+pin] & RP1_INV_PAD_DRIVE_MASK) | wrVal;
if (wiringPiDebug) {
printf ("setPadDrivePin: pin: %d, value: %d (%08X)\n", pin, value, pads[1+pin]) ;
}
}


void setPadDrive (int group, int value)
{
@@ -1682,8 +1698,8 @@ void pinMode (int pin, int mode)
shift = gpioToShift [pin] ;

if (mode == INPUT) {
if (PI_MODEL_5 == RaspberryPiModel) {
pads[1+pin] = RP1_PAD_DEFAULT;
if (PI_MODEL_5 == RaspberryPiModel) {
pads[1+pin] = (pin<=8) ? RP1_PAD_DEFAULT_0TO8 : RP1_PAD_DEFAULT_FROM9;
gpio[2*pin+1] = RP1_FSEL_GPIO | RP1_DEBOUNCE_DEFAULT; // GPIO
rio[RP1_RIO_OE + RP1_CLR_OFFSET] = 1<<pin; // Input
} else {
@@ -1691,7 +1707,7 @@ void pinMode (int pin, int mode)
}
} else if (mode == OUTPUT) {
if (PI_MODEL_5 == RaspberryPiModel) {
pads[1+pin] = RP1_PAD_DEFAULT;
pads[1+pin] = (pin<=8) ? RP1_PAD_DEFAULT_0TO8 : RP1_PAD_DEFAULT_FROM9;
gpio[2*pin+1] = RP1_FSEL_GPIO | RP1_DEBOUNCE_DEFAULT; // GPIO
rio[RP1_RIO_OE + RP1_SET_OFFSET] = 1<<pin; // Output
} else {


+ 1
- 0
wiringPi/wiringPi.h Voir le fichier

@@ -236,6 +236,7 @@ extern void piBoardId (int *model, int *rev, int *mem, int *m
extern int wpiPinToGpio (int wpiPin) ;
extern int physPinToGpio (int physPin) ;
extern void setPadDrive (int group, int value) ;
extern void setPadDrivePin (int pin, int value); // Interface V2
extern int getAlt (int pin) ;
extern void pwmToneWrite (int pin, int freq) ;
extern void pwmSetMode (int mode) ;


Chargement…
Annuler
Enregistrer