Latest changes from master repository
This commit is contained in:
committed by
Philip Howard
parent
ae40bdaf6a
commit
a651323139
@@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
#DEBUG = -g -O0
|
||||
DEBUG = -O3
|
||||
DEBUG = -O2
|
||||
CC = gcc
|
||||
INCLUDE = -I/usr/local/include
|
||||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
@@ -32,42 +32,49 @@ CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LIBS = -lwiringPi
|
||||
|
||||
# Should not alter anything below this line
|
||||
# May not need to alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = gpio.c
|
||||
|
||||
OBJ = gpio.o
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: gpio
|
||||
|
||||
gpio: gpio.o /usr/local/lib/libwiringPi.a
|
||||
@echo [LD]
|
||||
gpio: gpio.o
|
||||
@echo [Link]
|
||||
@$(CC) -o $@ gpio.o $(LDFLAGS) $(LIBS)
|
||||
|
||||
.c.o:
|
||||
@echo [CC] $<
|
||||
@echo [Compile] $<
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
.PHONEY: clean
|
||||
clean:
|
||||
rm -f $(OBJ) gpio *~ core tags
|
||||
rm -f $(OBJ) gpio *~ core tags *.bak
|
||||
|
||||
.PHONEY: tags
|
||||
tags: $(SRC)
|
||||
@echo [ctags]
|
||||
@ctags $(SRC)
|
||||
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
||||
|
||||
.PHONEY: install
|
||||
install:
|
||||
cp gpio /usr/local/bin
|
||||
chown root.root /usr/local/bin/gpio
|
||||
chmod 4755 /usr/local/bin/gpio
|
||||
mkdir -p /usr/local/man/man1
|
||||
cp gpio.1 /usr/local/man/man1
|
||||
@echo "[Install]"
|
||||
@cp gpio /usr/local/bin
|
||||
@chown root.root /usr/local/bin/gpio
|
||||
@chmod 4755 /usr/local/bin/gpio
|
||||
@mkdir -p /usr/local/man/man1
|
||||
@cp gpio.1 /usr/local/man/man1
|
||||
|
||||
.PHONEY: uninstall
|
||||
uninstall:
|
||||
@echo "[UnInstall]"
|
||||
rm -f /usr/local/bin/gpio
|
||||
rm -f /usr/local/man/man1/gpio.1
|
||||
|
||||
.PHONEY: depend
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
||||
|
||||
# DO NOT DELETE
|
||||
|
||||
79
gpio/gpio.1
79
gpio/gpio.1
@@ -1,4 +1,4 @@
|
||||
.TH "GPIO" "14 June 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
|
||||
.TH "GPIO" "21st October 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
|
||||
|
||||
.SH NAME
|
||||
gpio \- Command-line access to Raspberry Pi and PiFace GPIO
|
||||
@@ -17,6 +17,9 @@ gpio \- Command-line access to Raspberry Pi and PiFace GPIO
|
||||
.B ...
|
||||
.PP
|
||||
.B gpio
|
||||
.B readall
|
||||
.PP
|
||||
.B gpio
|
||||
.B unexportall/exports
|
||||
.PP
|
||||
.B gpio
|
||||
@@ -48,9 +51,9 @@ channel value
|
||||
.SH DESCRIPTION
|
||||
|
||||
.B GPIO
|
||||
is a swiss army knofe of a command line tool to allow the user easy
|
||||
is a swiss army knife of a command line tool to allow the user easy
|
||||
access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
|
||||
convertors on the Gertboard. It's designed for simple testing and
|
||||
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.
|
||||
|
||||
@@ -62,7 +65,7 @@ interface without needing to be run as root.
|
||||
|
||||
.TP
|
||||
.B \-v
|
||||
Output the current version
|
||||
Output the current version including the board revision of the Raspberry Pi.
|
||||
|
||||
.TP
|
||||
.B \-g
|
||||
@@ -73,20 +76,26 @@ Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
|
||||
Use the PiFace interface board and its corresponding pin numbers.
|
||||
|
||||
.TP
|
||||
.B read
|
||||
.B read <pin>
|
||||
Read the digital value of the given pin and print 0 or 1 to represent the
|
||||
respective logic levels.
|
||||
|
||||
.TP
|
||||
.B write
|
||||
.B write <pin> <value>
|
||||
Write the given value (0 or 1) to the pin.
|
||||
|
||||
.TP
|
||||
.B pwm
|
||||
.B readall
|
||||
Output a table of all GPIO pins values. The values represent the actual values read
|
||||
if the pin is in input mode, or the last value written if the pin is in output
|
||||
mode.
|
||||
|
||||
.TP
|
||||
.B pwm <pin> <value>
|
||||
Write a PWM value (0-1023) to the given pin.
|
||||
|
||||
.TP
|
||||
.B mode
|
||||
.B mode <pin> <mode>
|
||||
Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
|
||||
use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
|
||||
pull-up, pull-down or tristate (off) controls.
|
||||
@@ -122,7 +131,7 @@ the direction to input and set the edge interrupt method to \fInone\fR,
|
||||
above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
|
||||
numbering.
|
||||
|
||||
Like the export commands abovem ownership is set to that of the
|
||||
Like the export commands above, ownership is set to that of the
|
||||
calling user, allowing subsequent access from user programs without
|
||||
requiring root/sudo.
|
||||
|
||||
@@ -155,7 +164,7 @@ the associated /dev/ entries so that the current user has access to them.
|
||||
.B gbr
|
||||
channel
|
||||
|
||||
This reads the analog to digital convertor on the Gertboard on the given
|
||||
This reads the analog to digital converter on the Gertboard on the given
|
||||
channel. The board jumpers need to be in-place to do this operation.
|
||||
|
||||
.TP
|
||||
@@ -163,7 +172,7 @@ channel. The board jumpers need to be in-place to do this operation.
|
||||
channel value
|
||||
|
||||
This writes the supplied value to the output channel on the Gertboards
|
||||
SPI digital to analogue convertor.
|
||||
SPI digital to analogue converter.
|
||||
The board jumpers need to be in-place to do this operation.
|
||||
|
||||
|
||||
@@ -171,26 +180,30 @@ The board jumpers need to be in-place to do this operation.
|
||||
|
||||
.PP
|
||||
.TS
|
||||
r r l.
|
||||
WiringPi GPIO Function
|
||||
r r r l.
|
||||
WiringPi GPIO-r1 GPIO-r2 Function
|
||||
_
|
||||
0 17
|
||||
1 18 (PWM)
|
||||
2 21
|
||||
3 22
|
||||
4 23
|
||||
5 24
|
||||
6 25
|
||||
7 4
|
||||
8 0 SDA0
|
||||
9 1 SCL0
|
||||
10 8 SPI CE0
|
||||
11 7 SPI CE1
|
||||
12 10 SPI MOSI
|
||||
13 9 SPI MISO
|
||||
14 11 SPI SCLK
|
||||
15 14 TxD
|
||||
16 15 RxD
|
||||
0 17 17
|
||||
1 18 18 (PWM)
|
||||
2 21 27
|
||||
3 22 22
|
||||
4 23 23
|
||||
5 24 24
|
||||
6 25 25
|
||||
7 4 4
|
||||
8 0 2 I2C: SDA0
|
||||
9 1 3 I2C: SCL0
|
||||
10 8 8 SPI: CE0
|
||||
11 7 7 SPI: CE1
|
||||
12 10 10 SPI: MOSI
|
||||
13 9 9 SPI: MISO
|
||||
14 11 11 SPI: SCLK
|
||||
15 14 14 TxD
|
||||
16 15 16 RxD
|
||||
17 - 28
|
||||
18 - 29
|
||||
19 - 30
|
||||
20 - 31
|
||||
.TE
|
||||
|
||||
.SH FILES
|
||||
@@ -234,10 +247,14 @@ Gordon Henderson
|
||||
|
||||
.SH "REPORTING BUGS"
|
||||
|
||||
Report bugs to <projects@drogon.net>
|
||||
Please report bugs to <projects@drogon.net>
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright (c) 2012 Gordon Henderson
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
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.
|
||||
|
||||
119
gpio/gpio.c
119
gpio/gpio.c
@@ -40,7 +40,7 @@
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
#define VERSION "1.2"
|
||||
#define VERSION "1.4"
|
||||
|
||||
static int wpMode ;
|
||||
|
||||
@@ -48,13 +48,16 @@ char *usage = "Usage: gpio -v\n"
|
||||
" gpio -h\n"
|
||||
" gpio [-g] <read/write/pwm/mode> ...\n"
|
||||
" gpio [-p] <read/write/mode> ...\n"
|
||||
" gpio export/edge/unexport/unexportall/exports ...\n"
|
||||
" gpio readall\n"
|
||||
" gpio unexportall/exports ...\n"
|
||||
" gpio export/edge/unexport ...\n"
|
||||
" gpio drive <group> <value>\n"
|
||||
" gpio pwm-bal/pwm-ms \n"
|
||||
" gpio pwmr <range> \n"
|
||||
" gpio pwmc <divider> \n"
|
||||
" gpio load spi/i2c\n"
|
||||
" gpio gbr <channel>\n"
|
||||
" gpio gbw <channel> <value>\n" ;
|
||||
" gpio gbw <channel> <value>" ; // No trailing newline needed here.
|
||||
|
||||
|
||||
/*
|
||||
@@ -171,6 +174,65 @@ static void doLoad (int argc, char *argv [])
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doReadall:
|
||||
* Read all the GPIO pins
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
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 void doReadall (void)
|
||||
{
|
||||
int pin ;
|
||||
|
||||
printf ("+----------+------+--------+-------+\n") ;
|
||||
printf ("| wiringPi | GPIO | Name | Value |\n") ;
|
||||
printf ("+----------+------+--------+-------+\n") ;
|
||||
|
||||
for (pin = 0 ; pin < NUM_PINS ; ++pin)
|
||||
printf ("| %6d | %3d | %s | %s |\n",
|
||||
pin, wpiPinToGpio (pin),
|
||||
pinNames [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") ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doExports:
|
||||
@@ -687,8 +749,8 @@ void doPwm (int argc, char *argv [])
|
||||
|
||||
|
||||
/*
|
||||
* doPwmMode: doPwmRange:
|
||||
* Change the PWM mode and Range values
|
||||
* doPwmMode: doPwmRange: doPwmClock:
|
||||
* Change the PWM mode, range and clock divider values
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
@@ -718,6 +780,27 @@ static void doPwmRange (int argc, char *argv [])
|
||||
pwmSetRange (range) ;
|
||||
}
|
||||
|
||||
static void doPwmClock (int argc, char *argv [])
|
||||
{
|
||||
unsigned int clock ;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s pwmc <clock>\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
clock = (unsigned int)strtoul (argv [2], NULL, 10) ;
|
||||
|
||||
if ((clock < 1) || (clock > 4095))
|
||||
{
|
||||
fprintf (stderr, "%s: clock must be between 0 and 4096\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
pwmSetClock (clock) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* main:
|
||||
@@ -731,7 +814,7 @@ int main (int argc, char *argv [])
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
fprintf (stderr, "%s: %s\n", argv [0], usage) ;
|
||||
fprintf (stderr, "%s\n", usage) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
@@ -747,6 +830,8 @@ int main (int argc, char *argv [])
|
||||
printf ("Copyright (c) 2012 Gordon Henderson\n") ;
|
||||
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
|
||||
printf ("For details type: %s -warranty\n", argv [0]) ;
|
||||
printf ("\n") ;
|
||||
printf ("This Raspberry Pi is a revision %d board.\n", piBoardRev ()) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
@@ -785,9 +870,8 @@ int main (int argc, char *argv [])
|
||||
else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argc, argv) ; return 0 ; }
|
||||
else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; }
|
||||
|
||||
// Check for drive or load commands:
|
||||
// Check for load command:
|
||||
|
||||
if (strcasecmp (argv [1], "drive") == 0) { doPadDrive (argc, argv) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
|
||||
|
||||
// Gertboard commands
|
||||
@@ -839,21 +923,24 @@ int main (int argc, char *argv [])
|
||||
wpMode = WPI_MODE_PINS ;
|
||||
}
|
||||
|
||||
// Check for PWM operations
|
||||
// Check for PWM or Pad Drive operations
|
||||
|
||||
if (wpMode != WPI_MODE_PIFACE)
|
||||
{
|
||||
if (strcasecmp (argv [1], "pwm-bal") == 0) { doPwmMode (PWM_MODE_BAL) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "pwm-ms") == 0) { doPwmMode (PWM_MODE_MS) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "pwmr") == 0) { doPwmRange (argc, argv) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "pwm-bal") == 0) { doPwmMode (PWM_MODE_BAL) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "pwm-ms") == 0) { doPwmMode (PWM_MODE_MS) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "pwmr") == 0) { doPwmRange (argc, argv) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "pwmc") == 0) { doPwmClock (argc, argv) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "drive") == 0) { doPadDrive (argc, argv) ; return 0 ; }
|
||||
}
|
||||
|
||||
// Check for wiring commands
|
||||
|
||||
/**/ if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
|
||||
/**/ if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
|
||||
else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
|
||||
|
||||
21
gpio/test.sh
21
gpio/test.sh
@@ -1,4 +1,25 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# test.sh:
|
||||
# Simple test: Assumes LEDs on Pins 0-7 and lights them
|
||||
# in-turn.
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# Wiring Compatable library for the Raspberry Pi
|
||||
#
|
||||
# wiringPi is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# wiringPi is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
#################################################################################
|
||||
|
||||
# Simple test - assumes LEDs on Pins 0-7.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user