|
|
@@ -43,15 +43,18 @@ |
|
|
|
|
|
|
|
extern int wiringPiDebug ; |
|
|
|
|
|
|
|
extern void doReadall (void) ; |
|
|
|
extern void doReadallOld (void) ; |
|
|
|
|
|
|
|
#ifndef TRUE |
|
|
|
# define TRUE (1==1) |
|
|
|
# define FALSE (1==2) |
|
|
|
#endif |
|
|
|
|
|
|
|
#define VERSION "2.07" |
|
|
|
#define VERSION "2.08" |
|
|
|
#define I2CDETECT "/usr/sbin/i2cdetect" |
|
|
|
|
|
|
|
static int wpMode ; |
|
|
|
int wpMode ; |
|
|
|
|
|
|
|
char *usage = "Usage: gpio -v\n" |
|
|
|
" gpio -h\n" |
|
|
@@ -237,95 +240,6 @@ static void doI2Cdetect (int argc, char *argv []) |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* doReadall: |
|
|
|
* Read all the GPIO pins |
|
|
|
* We also want to use this to read the state of pins on an externally |
|
|
|
* connected device, so we need to do some fiddling with the internal |
|
|
|
* wiringPi node structures - since the gpio command can only use |
|
|
|
* one external device at a time, we'll use that to our advantage... |
|
|
|
********************************************************************************* |
|
|
|
*/ |
|
|
|
|
|
|
|
static char *pinNames [] = |
|
|
|
{ |
|
|
|
"GPIO 0", "GPIO 1", "GPIO 2", "GPIO 3", "GPIO 4", "GPIO 5", "GPIO 6", "GPIO 7", |
|
|
|
"SDA ", "SCL ", |
|
|
|
"CE0 ", "CE1 ", "MOSI ", "MISO ", "SCLK ", |
|
|
|
"TxD ", "RxD ", |
|
|
|
"GPIO 8", "GPIO 9", "GPIO10", "GPIO11", |
|
|
|
} ; |
|
|
|
|
|
|
|
static char *alts [] = |
|
|
|
{ |
|
|
|
"IN ", "OUT ", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3" |
|
|
|
} ; |
|
|
|
|
|
|
|
static int wpiToPhys [64] = |
|
|
|
{ |
|
|
|
11, 12, 13, 15, 16, 18, 22, 7, // 0...7 |
|
|
|
3, 5, // 8...9 |
|
|
|
24, 26, 19, 21, 23, // 10..14 |
|
|
|
8, 10, // 15..16 |
|
|
|
3, 4, 5, 6, // 17..20 |
|
|
|
0,0,0,0,0,0,0,0,0,0,0, // 20..31 |
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 32..47 |
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 47..63 |
|
|
|
} ; |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* doReadallExternal: |
|
|
|
* A relatively crude way to read the pins on an external device. |
|
|
|
* We don't know the input/output mode of pins, but we can tell |
|
|
|
* if it's an analog pin or a digital one... |
|
|
|
********************************************************************************* |
|
|
|
*/ |
|
|
|
|
|
|
|
static void doReadallExternal (void) |
|
|
|
{ |
|
|
|
int pin ; |
|
|
|
|
|
|
|
printf ("+------+---------+--------+\n") ; |
|
|
|
printf ("| Pin | Digital | Analog |\n") ; |
|
|
|
printf ("+------+---------+--------+\n") ; |
|
|
|
|
|
|
|
for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin) |
|
|
|
printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ; |
|
|
|
|
|
|
|
printf ("+------+---------+--------+\n") ; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void doReadall (void) |
|
|
|
{ |
|
|
|
int pin ; |
|
|
|
|
|
|
|
if (wiringPiNodes != NULL) // External readall |
|
|
|
doReadallExternal () ; |
|
|
|
else |
|
|
|
{ |
|
|
|
printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ; |
|
|
|
printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ; |
|
|
|
printf ("+----------+------+------+--------+------+-------+\n") ; |
|
|
|
|
|
|
|
for (pin = 0 ; pin < 64 ; ++pin) // Crude, but effective |
|
|
|
{ |
|
|
|
if (wpiPinToGpio (pin) == -1) |
|
|
|
continue ; |
|
|
|
|
|
|
|
printf ("| %6d | %3d | %3d | %s | %s | %s |\n", |
|
|
|
pin, wpiPinToGpio (pin), wpiToPhys [pin], |
|
|
|
pinNames [pin], |
|
|
|
alts [getAlt (pin)], |
|
|
|
digitalRead (pin) == HIGH ? "High" : "Low ") ; |
|
|
|
} |
|
|
|
|
|
|
|
printf ("+----------+------+------+--------+------+-------+\n") ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* doExports: |
|
|
|
* List all GPIO exports |
|
|
|
********************************************************************************* |
|
|
@@ -716,12 +630,15 @@ void doMode (int argc, char *argv []) |
|
|
|
mode = argv [3] ; |
|
|
|
|
|
|
|
/**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ; |
|
|
|
else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ; |
|
|
|
else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ; |
|
|
|
else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ; |
|
|
|
else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ; |
|
|
|
else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ; |
|
|
|
else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ; |
|
|
|
else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ; |
|
|
|
else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ; |
|
|
|
else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ; |
|
|
|
else |
|
|
|
{ |
|
|
|
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ; |
|
|
@@ -1268,18 +1185,19 @@ int main (int argc, char *argv []) |
|
|
|
|
|
|
|
// Pi Specifics |
|
|
|
|
|
|
|
else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doPwmMode (PWM_MODE_BAL) ; |
|
|
|
else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ; |
|
|
|
else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ; |
|
|
|
else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ; |
|
|
|
else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doPwmMode (PWM_MODE_BAL) ; |
|
|
|
else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ; |
|
|
|
else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ; |
|
|
|
else if (strcasecmp (argv [1], "oreadall" ) == 0) doReadallOld () ; |
|
|
|
else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ; |
|
|
|
else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ; |
|
|
|
else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ; |
|
|
|
else |
|
|
|
{ |
|
|
|
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ; |
|
|
|