mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2026-03-22 20:02:49 +01:00
Updated mostly to the gpio readall command to support the Raspberry Pi B+
This commit is contained in:
52
gpio/gpio.c
52
gpio/gpio.c
@@ -55,7 +55,7 @@ extern void doPins (void) ;
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
#define VERSION "2.16"
|
||||
#define VERSION "2.18"
|
||||
#define I2CDETECT "/usr/sbin/i2cdetect"
|
||||
|
||||
int wpMode ;
|
||||
@@ -654,16 +654,17 @@ 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) ;
|
||||
/**/ 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, "pwmTone") == 0) pinMode (pin, PWM_TONE_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) ;
|
||||
|
||||
// Undocumented
|
||||
|
||||
@@ -742,7 +743,7 @@ static void doGbw (int argc, char *argv [])
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
if ((value < 0) || (value > 1023))
|
||||
if ((value < 0) || (value > 255))
|
||||
{
|
||||
fprintf (stderr, "%s: gbw: Value must be from 0 to 255\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
@@ -933,6 +934,30 @@ void doToggle (int argc, char *argv [])
|
||||
digitalWrite (pin, !digitalRead (pin)) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doPwmTone:
|
||||
* Output a tone in a PWM pin
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void doPwmTone (int argc, char *argv [])
|
||||
{
|
||||
int pin, freq ;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s pwmTone <pin> <freq>\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
pin = atoi (argv [2]) ;
|
||||
freq = atoi (argv [3]) ;
|
||||
|
||||
pwmToneWrite (pin, freq) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doClock:
|
||||
* Output a clock on a pin
|
||||
@@ -1100,7 +1125,7 @@ int main (int argc, char *argv [])
|
||||
if (strcasecmp (argv [1], "-warranty") == 0)
|
||||
{
|
||||
printf ("gpio version: %s\n", VERSION) ;
|
||||
printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
|
||||
printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
|
||||
printf ("\n") ;
|
||||
printf (" This program is free software; you can redistribute it and/or modify\n") ;
|
||||
printf (" it under the terms of the GNU Leser General Public License as published\n") ;
|
||||
@@ -1228,6 +1253,7 @@ int main (int argc, char *argv [])
|
||||
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], "pwmTone" ) == 0) doPwmTone (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "readall" ) == 0) doReadallOld () ;
|
||||
else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
|
||||
|
||||
101
gpio/readall.c
101
gpio/readall.c
@@ -119,11 +119,16 @@ static int physToWpi [64] =
|
||||
13, 6,
|
||||
14, 10,
|
||||
-1, 11, // 25, 26
|
||||
|
||||
-1, -1, -1, -1, -1, // ... 31
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
|
||||
30, 31, // Actually I2C, but not used
|
||||
21, -1,
|
||||
22, 26,
|
||||
23, -1,
|
||||
24, 27,
|
||||
25, 28,
|
||||
-1, 29,
|
||||
-1, -1, -1, -1, -1, -1, -1, // ... 47
|
||||
-1, -1, -1, -1, -1, // ... 52
|
||||
28, 29, 30, 31, // ... 53, 54, 55, 56 - P5
|
||||
17, 18, 19, 20, // ... 53, 54, 55, 56 - P5
|
||||
-1, -1, -1, -1, -1, -1, -1, // ... 63
|
||||
} ;
|
||||
|
||||
@@ -131,25 +136,34 @@ static char *physNames [64] =
|
||||
{
|
||||
NULL,
|
||||
|
||||
"3.3v", "5v",
|
||||
"SDA", "5V",
|
||||
"SCL", "0v",
|
||||
"GPIO7", "TxD",
|
||||
"0v", "RxD",
|
||||
"GPIO0", "GPIO1",
|
||||
"GPIO2", "0v",
|
||||
"GPIO3", "GPIO4",
|
||||
"3.3v", "GPIO5",
|
||||
"MOSI", "0v",
|
||||
"MISO", "GPIO6",
|
||||
"SCLK", "CE0",
|
||||
"0v", "CE1",
|
||||
|
||||
NULL,NULL,NULL,NULL,NULL, // ... 31
|
||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, // ... 47
|
||||
NULL,NULL,NULL,NULL,NULL, // ... 52
|
||||
"GPIO8", "GPIO9", "GPIO10", "GPIO11", // ... 53, 54, 55, 56 - P5
|
||||
NULL,NULL,NULL,NULL,NULL,NULL, // ... 63
|
||||
" 3.3v", "5v ",
|
||||
" SDA.1", "5V ",
|
||||
" SCL.1", "0v ",
|
||||
"GPIO. 7", "TxD ",
|
||||
" 0v", "RxD ",
|
||||
"GPIO. 0", "GPIO. 1",
|
||||
"GPIO. 2", "0v ",
|
||||
"GPIO. 3", "GPIO. 4",
|
||||
" 3.3v", "GPIO. 5",
|
||||
" MOSI", "0v ",
|
||||
" MISO", "GPIO. 6",
|
||||
" SCLK", "CE0 ",
|
||||
" 0v", "CE1 ",
|
||||
" SDA.0", "SCL0 ",
|
||||
"GPIO.21", "0v ",
|
||||
"GPIO.22", "GPIO.26",
|
||||
"GPIO.23", "0v ",
|
||||
"GPIO.24", "GPIO.27",
|
||||
"GPIO.25", "GPIO.28",
|
||||
" 0v", "GPIO.29",
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
"GPIO.17", "GPIO.18",
|
||||
"GPIO.19", "GPIO.20",
|
||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
||||
} ;
|
||||
|
||||
static void readallPhys (int physPin)
|
||||
@@ -171,7 +185,7 @@ static void readallPhys (int physPin)
|
||||
printf (" | %3d", physToWpi [physPin]) ;
|
||||
}
|
||||
|
||||
printf (" | %5s", physNames [physPin]) ;
|
||||
printf (" | %s", physNames [physPin]) ;
|
||||
|
||||
if (physToWpi [physPin] == -1)
|
||||
printf (" | | ") ;
|
||||
@@ -264,6 +278,39 @@ int cmReadall (void)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* bPlusReadall:
|
||||
* Read all the pins on the model B+
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int bPlusReadall (void)
|
||||
{
|
||||
int model, rev, mem ;
|
||||
int pin ;
|
||||
char *maker ;
|
||||
char *name ;
|
||||
|
||||
piBoardId (&model, &rev, &mem, &maker) ;
|
||||
if (model != PI_MODEL_BPLUS)
|
||||
return FALSE ;
|
||||
|
||||
/**/ if (wpMode == WPI_MODE_GPIO)
|
||||
name = "BCM" ;
|
||||
else
|
||||
name = "wPi" ;
|
||||
|
||||
printf (" +-----+---------+------+----+--B Plus--+----+------+---------+-----+\n") ;
|
||||
printf (" | %s | Name | Mode | Val| Physical |Val | Mode | Name | %s |\n", name, name) ;
|
||||
printf (" +-----+---------+------+----+----++----+----+------+---------+-----+\n") ;
|
||||
for (pin = 1 ; pin <= 40 ; pin += 2)
|
||||
readallPhys (pin) ;
|
||||
printf (" +-----+---------+------+----+----++----+----+------+---------+-----+\n") ;
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
|
||||
void doReadall (void)
|
||||
{
|
||||
int pin ;
|
||||
@@ -277,6 +324,9 @@ void doReadall (void)
|
||||
if (cmReadall ())
|
||||
return ;
|
||||
|
||||
if (bPlusReadall ())
|
||||
return ;
|
||||
|
||||
/**/ if (wpMode == WPI_MODE_GPIO)
|
||||
{
|
||||
printf (" +-----+-------+------+----+-Rev%d-----+----+------+-------+-----+\n", piBoardRev ()) ;
|
||||
@@ -320,6 +370,9 @@ void doReadallOld (void)
|
||||
if (cmReadall ())
|
||||
return ;
|
||||
|
||||
if (bPlusReadall ())
|
||||
return ;
|
||||
|
||||
printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ;
|
||||
printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ;
|
||||
printf ("+----------+------+------+--------+------+-------+\n") ;
|
||||
|
||||
Reference in New Issue
Block a user