update for the v3+

This commit is contained in:
Gordon Henderson
2018-03-14 07:17:04 +00:00
parent 96344ff712
commit 8d188fa0e0
17 changed files with 281 additions and 154 deletions

View File

@@ -42,7 +42,7 @@ LIBS = -lwiringPi -lwiringPiDev -lpthread -lrt -lm -lcrypt
# May not need to alter anything below this line
###############################################################################
SRC = gpio.c readall.c pins.c
SRC = gpio.c readall.c
OBJ = $(SRC:.c=.o)
@@ -77,22 +77,22 @@ ifneq ($(WIRINGPI_SUID),0)
$Q chown root.root $(DESTDIR)$(PREFIX)/bin/gpio
$Q chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio
endif
$Q mkdir -p $(DESTDIR)$(PREFIX)/man/man1
$Q cp gpio.1 $(DESTDIR)$(PREFIX)/man/man1
$Q mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1
$Q cp gpio.1 $(DESTDIR)$(PREFIX)/share/man/man1
.PHONY: install-deb
install-deb: gpio
$Q echo "[Install: deb]"
$Q install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/bin
$Q install -m 0755 gpio ~/wiringPi/debian-template/wiringPi/usr/bin
$Q install -m 0755 -d ~/wiringPi/debian-template/wiringPi/man/man1
$Q install -m 0644 gpio.1 ~/wiringPi/debian-template/wiringPi/man/man1
$Q install -m 0755 -d ~/wiringPi/debian-template/wiringPi/usr/share/man/man1
$Q install -m 0644 gpio.1 ~/wiringPi/debian-template/wiringPi/usr/share/man/man1
.PHONY: uninstall
uninstall:
$Q echo "[UnInstall]"
$Q rm -f $(DESTDIR)$(PREFIX)/bin/gpio
$Q rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1
$Q rm -f $(DESTDIR)$(PREFIX)/share/man/man1/gpio.1
.PHONY: depend
depend:

View File

@@ -1,4 +1,4 @@
.TH GPIO 1 "September 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO"
.TH GPIO 1 "March 2018" wiringPi "Command-Line access to Raspberry Pi's GPIO"
.SH NAME
gpio \- Command-line access to Raspberry Pi's GPIO
@@ -9,7 +9,7 @@ gpio \- Command-line access to Raspberry Pi's GPIO
.PP
.B gpio
.B [ \-g | \-1 ]
.B mode/read/write/aread/awrite/wb/pwm/clock/toggle/blink ...
.B mode/read/write/aread/awrite/wb/pwm/pwnTone/clock/toggle/blink ...
.PP
.B gpio
.B [ \-x extension:params ]
@@ -21,6 +21,11 @@ gpio \- Command-line access to Raspberry Pi's GPIO
.B ...
.PP
.B gpio
.B [ \-p ]
.B pwnTone pin frequency
.B ...
.PP
.B gpio
.B readall
.PP
.B gpio
@@ -256,30 +261,6 @@ Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
.B pwmr
Change the PWM range register. The default is 1024.
.TP
.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 in Kb/sec
(or as close as the Pi can manage) The default speed is 100Kb/sec.
Note: On recent kernels with the device tree enabled you should use the
raspi-config program to load/unload the I2C device at boot time.
.TP
.B load spi
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. It used to have the ability to change the buffer size from the
default of 4096 bytes to an arbitrary value, however for some time the
Pi Foundation have compiled the SPI device driver into the kernel and
this has fixed the buffer size. The way to change it now is to edit
the /boot/cmdline.txt file and add on spdev.bufsiz=8192 to set it to
e.g. 8192 bytes then reboot.
Note: On recent kernels with the device tree enabled you should use the
raspi-config program to load/unload the SPI device at boot time.
.TP
.B gbr
channel
@@ -360,7 +341,7 @@ Please report bugs to <projects@drogon.net>
.SH COPYRIGHT
Copyright (c) 2012-2015 Gordon Henderson
Copyright (c) 2012-2018 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.

View File

@@ -2,7 +2,7 @@
* gpio.c:
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
* Pi's GPIO.
* Copyright (c) 2012-2017 Gordon Henderson
* Copyright (c) 2012-2018 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -48,7 +48,7 @@ extern int wiringPiDebug ;
extern void doReadall (void) ;
extern void doAllReadall (void) ;
extern void doPins (void) ;
extern void doQmode (int argc, char *argv []) ;
#ifndef TRUE
# define TRUE (1==1)
@@ -56,9 +56,9 @@ extern void doPins (void) ;
#endif
#define PI_USB_POWER_CONTROL 38
#define I2CDETECT "/usr/sbin/i2cdetect"
#define MODPROBE "/sbin/modprobe"
#define RMMOD "/sbin/rmmod"
#define I2CDETECT "i2cdetect"
#define MODPROBE "modprobe"
#define RMMOD "rmmod"
int wpMode ;
@@ -68,9 +68,9 @@ char *usage = "Usage: gpio -v\n"
" gpio [-d] ...\n"
" [-x extension:params] [[ -x ...]] ...\n"
" gpio [-p] <read/write/wb> ...\n"
" gpio <read/write/aread/awritewb/pwm/clock/mode> ...\n"
" gpio <mode/read/write/aread/awritewb/pwm/pwmTone/clock> ...\n"
" gpio <toggle/blink> <pin>\n"
" gpio readall/reset\n"
" gpio readall\n"
" gpio unexportall/exports\n"
" gpio export/edge/unexport ...\n"
" gpio wfi <pin> <mode>\n"
@@ -221,9 +221,7 @@ static void checkDevTree (char *argv [])
fprintf (stderr,
"%s: Unable to load/unload modules as this Pi has the device tree enabled.\n"
" You need to run the raspi-config program (as root) and select the\n"
" modules (SPI or I2C) that you wish to load/unload there and reboot.\n"
" There is more information here:\n"
" https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314\n", argv [0]) ;
" modules (SPI or I2C) that you wish to load/unload there and reboot.\n", argv [0]) ;
exit (1) ;
}
}
@@ -1270,7 +1268,7 @@ static void doVersion (char *argv [])
wiringPiVersion (&vMaj, &vMin) ;
printf ("gpio version: %d.%d\n", vMaj, vMin) ;
printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
printf ("Copyright (c) 2012-2018 Gordon Henderson\n") ;
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
printf ("For details type: %s -warranty\n", argv [0]) ;
printf ("\n") ;
@@ -1320,8 +1318,11 @@ int main (int argc, char *argv [])
if (argc == 1)
{
fprintf (stderr, "%s\n", usage) ;
return 1 ;
fprintf (stderr,
"%s: At your service!\n"
" Type: gpio -h for full details and\n"
" gpio readall for a quick printout of your connector details\n", argv [0]) ;
exit (EXIT_FAILURE) ;
}
// Help
@@ -1329,7 +1330,7 @@ int main (int argc, char *argv [])
if (strcasecmp (argv [1], "-h") == 0)
{
printf ("%s: %s\n", argv [0], usage) ;
return 0 ;
exit (EXIT_SUCCESS) ;
}
// Version & Warranty
@@ -1338,7 +1339,7 @@ int main (int argc, char *argv [])
if ((strcmp (argv [1], "-R") == 0) || (strcmp (argv [1], "-V") == 0))
{
printf ("%d\n", piGpioLayout ()) ;
return 0 ;
exit (EXIT_SUCCESS) ;
}
// Version and information
@@ -1346,13 +1347,13 @@ int main (int argc, char *argv [])
if (strcmp (argv [1], "-v") == 0)
{
doVersion (argv) ;
return 0 ;
exit (EXIT_SUCCESS) ;
}
if (strcasecmp (argv [1], "-warranty") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
printf ("Copyright (c) 2012-2018 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") ;
@@ -1367,13 +1368,13 @@ int main (int argc, char *argv [])
printf (" You should have received a copy of the GNU Lesser General Public License\n") ;
printf (" along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ;
printf ("\n") ;
return 0 ;
exit (EXIT_SUCCESS) ;
}
if (geteuid () != 0)
{
fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
return 1 ;
exit (EXIT_FAILURE) ;
}
// Initial test for /sys/class/gpio operations:
@@ -1517,7 +1518,8 @@ int main (int argc, char *argv [])
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (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) doPins () ;
else if (strcasecmp (argv [1], "pins" ) == 0) doReadall () ;
else if (strcasecmp (argv [1], "qmode" ) == 0) doQmode (argc, argv) ;
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]) ;
@@ -1531,5 +1533,6 @@ int main (int argc, char *argv [])
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
exit (EXIT_FAILURE) ;
}
return 0 ;
}

View File

@@ -1,33 +0,0 @@
/*
* pins.c:
* Just display a handy Pi pinnout diagram.
* Copyright (c) 2012-2017 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* 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/>.
***********************************************************************
*/
#include <stdio.h>
void doPins (void)
{
printf ("The pins command has been deprecated - sorry. Please use the\n") ;
printf (" gpio readall\n") ;
printf ("command to get a list of the pinnouts for your Pi.\n") ;
}

View File

@@ -1,7 +1,7 @@
/*
* readall.c:
* The readall functions - getting a bit big, so split them out.
* Copyright (c) 2012-2017 Gordon Henderson
* Copyright (c) 2012-2018 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@@ -287,16 +287,16 @@ void abReadall (int model, int rev)
/*
* piPlusReadall:
* Read all the pins on the model A+ or the B+
* Read all the pins on the model A+ or the B+ or actually, all 40-pin Pi's
*********************************************************************************
*/
static void plus2header (int model)
{
/**/ if (model == PI_MODEL_AP)
printf (" +-----+-----+---------+------+---+--A Plus--+---+------+---------+-----+-----+\n") ;
printf (" +-----+-----+---------+------+---+---Pi A+--+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_BP)
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
printf (" +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_ZERO)
printf (" +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_ZERO_W)
@@ -305,6 +305,8 @@ static void plus2header (int model)
printf (" +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_3)
printf (" +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_3P)
printf (" +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+\n") ;
else
printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ;
}
@@ -348,7 +350,10 @@ void doReadall (void)
/**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
abReadall (model, rev) ;
else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) || (model == PI_MODEL_2) || (model == PI_MODEL_3) || (model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W))
else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) ||
(model == PI_MODEL_2) ||
(model == PI_MODEL_3) || (model == PI_MODEL_3P) ||
(model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W))
piPlusReadall (model) ;
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3))
allReadall () ;
@@ -356,6 +361,7 @@ void doReadall (void)
printf ("Oops - unable to determine board type... model: %d\n", model) ;
}
/*
* doAllReadall:
* Force reading of all pins regardless of Pi model
@@ -366,3 +372,24 @@ void doAllReadall (void)
{
allReadall () ;
}
/*
* doQmode:
* Query mode on a pin
*********************************************************************************
*/
void doQmode (int argc, char *argv [])
{
int pin ;
if (argc != 3)
{
fprintf (stderr, "Usage: %s qmode pin\n", argv [0]) ;
exit (EXIT_FAILURE) ;
}
pin = atoi (argv [2]) ;
printf ("%s\n", alts [getAlt (pin)]) ;
}