Synced to git.drogon.net

This commit is contained in:
Gordon Henderson
2013-03-24 20:04:07 +00:00
committed by Philip Howard
parent dda3305ce1
commit 3fbc564d00
41 changed files with 1829 additions and 425 deletions

View File

@@ -30,7 +30,7 @@ INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LIBS = -lwiringPi
LIBS = -lwiringPi -lpthread -lm
# May not need to alter anything below this line
###############################################################################
@@ -70,8 +70,8 @@ install:
.PHONEY: uninstall
uninstall:
@echo "[UnInstall]"
rm -f /usr/local/bin/gpio
rm -f /usr/local/man/man1/gpio.1
@rm -f /usr/local/bin/gpio
@rm -f /usr/local/man/man1/gpio.1
.PHONEY: depend
depend:

BIN
gpio/gpio Executable file

Binary file not shown.

View File

@@ -9,7 +9,7 @@ gpio \- Command-line access to Raspberry Pi and PiFace GPIO
.PP
.B gpio
.B [ \-g ]
.B read/write/wb/pwm/mode ...
.B read/write/wb/pwm/clock/mode ...
.PP
.B gpio
.B [ \-p ]
@@ -38,7 +38,7 @@ group value
range
.PP
.B gpio
.B load \ i2c/spi
.B load \ i2c/spi ...
.PP
.B gpio
.B gbr
@@ -57,6 +57,9 @@ converters on the Gertboard. It's designed for simple testing and
diagnostic purposes, but can be used in shell scripts for general if
somewhat slow control of the GPIO pins.
It can also control the IO's on the PiFace IO board and load the SPI and I2C
kernel modules if required.
Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
interface without needing to be run as root.
@@ -70,6 +73,8 @@ Output the current version including the board revision of the Raspberry Pi.
.TP
.B \-g
Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
\fINOTE:\fR The BCM_GPIO pin numbers are always used with the
export and edge commands.
.TP
.B \-p
@@ -99,7 +104,13 @@ mode.
.TP
.B pwm <pin> <value>
Write a PWM value (0-1023) to the given pin.
Write a PWM value (0-1023) to the given pin. The pin needs to be put
into PWM mode first.
.TP
.B clock <pin> <frequency>
Set the output frequency on the given pin. The pin needs to be put into
clock mode first.
.TP
.B mode <pin> <mode>
@@ -163,9 +174,18 @@ Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
Change the PWM range register. The default is 1024.
.TP
.B load i2c/spi
This loads the i2c or the spi drivers into the system and changes the permissions on
the associated /dev/ entries so that the current user has access to them.
.B load i2c [baudrate]
This loads the i2c or drivers into the kernel and changes the permissions
on the associated /dev/ entries so that the current user has access to
them. Optionally it will set the I2C baudrate to that supplied (or as
close as the Pi can manage) The default speed is 100Kb/sec.
.TP
.B load spi [buffer size in KB]
This loads the spi drivers into the kernel and changes the permissions
on the associated /dev/ entries so that the current user has access to
them. Optionally it will set the SPI buffer size to that supplied. The
default is 4KB.
.TP
.B gbr
@@ -183,7 +203,7 @@ SPI digital to analogue converter.
The board jumpers need to be in-place to do this operation.
.SH "WiringPi vs. GPIO Pin numbering"
.SH "WiringPi vs. BCM_GPIO Pin numbering"
.PP
.TS
@@ -213,6 +233,12 @@ _
20 - 31
.TE
Note that "r1" and "r2" above refers to the board revision. Normally
wiringPi detects the correct board revision with use for it's own
numbering scheme, but if you are using a Revision 2 board with some
of the pins which change numbers between revisions you will need
to alter your software.
.SH FILES
.TP 2.2i
@@ -264,4 +290,5 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH TRADEMARKS AND ACKNOWLEDGEMENTS
Raspberry Pi is a trademark of the Raspberry Pi Foundation.
Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
http://raspberrypi.org/ for full details.

View File

@@ -35,18 +35,20 @@
#include <wiringPi.h>
#include <gertboard.h>
extern int wiringPiDebug ;
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
#define VERSION "1.5"
#define VERSION "1.12"
static int wpMode ;
char *usage = "Usage: gpio -v\n"
" gpio -h\n"
" gpio [-g] <read/write/wb/pwm/mode> ...\n"
" gpio [-g] <read/write/wb/pwm/clock/mode> ...\n"
" gpio [-p] <read/write/wb> ...\n"
" gpio readall\n"
" gpio unexportall/exports ...\n"
@@ -127,7 +129,7 @@ static int moduleLoaded (char *modName)
static void _doLoadUsage (char *argv [])
{
fprintf (stderr, "Usage: %s load <spi/i2c>\n", argv [0]) ;
fprintf (stderr, "Usage: %s load <spi/i2c> [SPI bufferSize in KB | I2C baudrate in Kb/sec]\n", argv [0]) ;
exit (1) ;
}
@@ -136,16 +138,23 @@ static void doLoad (int argc, char *argv [])
char *module1, *module2 ;
char cmd [80] ;
char *file1, *file2 ;
char args1 [32], args2 [32] ;
if (argc != 3)
if (argc < 3)
_doLoadUsage (argv) ;
args1 [0] = args2 [0] = 0 ;
/**/ if (strcasecmp (argv [2], "spi") == 0)
{
module1 = "spidev" ;
module2 = "spi_bcm2708" ;
file1 = "/dev/spidev0.0" ;
file2 = "/dev/spidev0.1" ;
if (argc == 4)
sprintf (args1, " bufsiz=%d", atoi (argv [3]) * 1024) ;
else if (argc > 4)
_doLoadUsage (argv) ;
}
else if (strcasecmp (argv [2], "i2c") == 0)
{
@@ -153,19 +162,23 @@ static void doLoad (int argc, char *argv [])
module2 = "i2c_bcm2708" ;
file1 = "/dev/i2c-0" ;
file2 = "/dev/i2c-1" ;
if (argc == 4)
sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ;
else if (argc > 4)
_doLoadUsage (argv) ;
}
else
_doLoadUsage (argv) ;
if (!moduleLoaded (module1))
{
sprintf (cmd, "modprobe %s", module1) ;
sprintf (cmd, "modprobe %s%s", module1, args1) ;
system (cmd) ;
}
if (!moduleLoaded (module2))
{
sprintf (cmd, "modprobe %s", module2) ;
sprintf (cmd, "modprobe %s%s", module2, args2) ;
system (cmd) ;
}
@@ -190,55 +203,39 @@ static void doLoad (int argc, char *argv [])
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",
"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 void doReadall (void)
{
int pin ;
printf ("+----------+------+--------+-------+\n") ;
printf ("| wiringPi | GPIO | Name | Value |\n") ;
printf ("+----------+------+--------+-------+\n") ;
printf ("+----------+------+--------+------+-------+\n") ;
printf ("| wiringPi | GPIO | Name | Mode | Value |\n") ;
printf ("+----------+------+--------+------+-------+\n") ;
for (pin = 0 ; pin < NUM_PINS ; ++pin)
printf ("| %6d | %3d | %s | %s |\n",
for (pin = 0 ; pin < 64 ; ++pin)
{
if (wpiPinToGpio (pin) == -1)
continue ;
printf ("| %6d | %3d | %s | %s | %s |\n",
pin, wpiPinToGpio (pin),
pinNames [pin],
alts [getAlt (pin)],
digitalRead (pin) == HIGH ? "High" : "Low ") ;
}
printf ("+----------+------+--------+-------+\n") ;
if (piBoardRev () == 1)
return ;
for (pin = 17 ; pin <= 20 ; ++pin)
printf ("| %6d | %3d | %s | %s |\n",
pin, wpiPinToGpio (pin),
pinNames [pin],
digitalRead (pin) == HIGH ? "High" : "Low ") ;
printf ("+----------+------+--------+-------+\n") ;
printf ("+----------+------+--------+------+-------+\n") ;
}
@@ -544,15 +541,16 @@ void doMode (int argc, char *argv [])
mode = argv [3] ;
/**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
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) ;
/**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
else if (strcasecmp (mode, "out") == 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
{
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/up/down/tri\n", argv [1], mode) ;
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
exit (1) ;
}
}
@@ -757,6 +755,33 @@ void doRead (int argc, char *argv [])
}
/*
* doClock:
* Output a clock on a pin
*********************************************************************************
*/
void doClock (int argc, char *argv [])
{
int pin, freq ;
if (argc != 4)
{
fprintf (stderr, "Usage: %s clock <pin> <freq>\n", argv [0]) ;
exit (1) ;
}
pin = atoi (argv [2]) ;
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
return ;
freq = atoi (argv [3]) ;
gpioClockSet (pin, freq) ;
}
/*
* doPwm:
* Output a PWM value on a pin
@@ -848,6 +873,12 @@ int main (int argc, char *argv [])
{
int i ;
if (getenv ("WIRINGPI_DEBUG") != NULL)
{
printf ("gpio: wiringPi debug mode enabled\n") ;
wiringPiDebug = TRUE ;
}
if (argc == 1)
{
fprintf (stderr, "%s\n", usage) ;
@@ -977,6 +1008,7 @@ int main (int argc, char *argv [])
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
else if (strcasecmp (argv [1], "wb") == 0) doWriteByte (argc, argv) ;
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
else if (strcasecmp (argv [1], "clock") == 0) doClock (argc, argv) ;
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
else
{