Merge branch 'master' of git://git.drogon.net/wiringPi
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
# A swiss-army knige of GPIO shenanigans.
|
||||
# https://projects.drogon.net/wiring-pi
|
||||
#
|
||||
# Copyright (c) 2012-2015 Gordon Henderson
|
||||
# Copyright (c) 2012-2016 Gordon Henderson
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# Wiring Compatable library for the Raspberry Pi
|
||||
# A "wiring" 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
|
||||
@@ -34,10 +34,10 @@ endif
|
||||
DEBUG = -O2
|
||||
CC = gcc
|
||||
INCLUDE = -I$(DESTDIR)$(PREFIX)/include
|
||||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
CFLAGS = $(DEBUG) -Wall -Wextra $(INCLUDE) -Winline -pipe
|
||||
|
||||
LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib
|
||||
LIBS = -lwiringPi -lwiringPiDev -lpthread
|
||||
LIBS = -lwiringPi -lwiringPiDev -lpthread -lrt -lm
|
||||
|
||||
# May not need to alter anything below this line
|
||||
###############################################################################
|
||||
@@ -85,6 +85,8 @@ 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
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
@@ -98,4 +100,4 @@ depend:
|
||||
|
||||
# DO NOT DELETE
|
||||
|
||||
gpio.o: version.h
|
||||
gpio.o: ../version.h
|
||||
|
||||
170
gpio/gpio.c
170
gpio/gpio.c
@@ -2,7 +2,7 @@
|
||||
* gpio.c:
|
||||
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
|
||||
* Pi's GPIO.
|
||||
* Copyright (c) 2012-2015 Gordon Henderson
|
||||
* Copyright (c) 2012-2017 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
@@ -40,7 +40,7 @@
|
||||
#include <gertboard.h>
|
||||
#include <piFace.h>
|
||||
|
||||
#include "version.h"
|
||||
#include "../version.h"
|
||||
|
||||
extern int wiringPiDebug ;
|
||||
|
||||
@@ -57,14 +57,19 @@ extern void doPins (void) ;
|
||||
|
||||
#define PI_USB_POWER_CONTROL 38
|
||||
#define I2CDETECT "/usr/sbin/i2cdetect"
|
||||
#define MODPROBE "/sbin/modprobe"
|
||||
#define RMMOD "/sbin/rmmod"
|
||||
|
||||
int wpMode ;
|
||||
|
||||
char *usage = "Usage: gpio -v\n"
|
||||
" gpio -h\n"
|
||||
" gpio [-g|-1] [-x extension:params] ...\n"
|
||||
" gpio [-g|-1] ...\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 <toggle/blink> <pin>\n"
|
||||
" gpio readall/reset\n"
|
||||
" gpio unexportall/exports\n"
|
||||
" gpio export/edge/unexport ...\n"
|
||||
@@ -76,6 +81,8 @@ char *usage = "Usage: gpio -v\n"
|
||||
" gpio load spi/i2c\n"
|
||||
" gpio unload spi/i2c\n"
|
||||
" gpio i2cd/i2cdetect\n"
|
||||
" gpio rbx/rbd\n"
|
||||
" gpio wb <value>\n"
|
||||
" gpio usbp high/low\n"
|
||||
" gpio gbr <channel>\n"
|
||||
" gpio gbw <channel> <value>" ; // No trailing newline needed here.
|
||||
@@ -102,6 +109,45 @@ static int decodePin (const char *str)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* findExecutable:
|
||||
* Code to locate the path to the given executable. We have a fixed list
|
||||
* of locations to try which completely overrides any $PATH environment.
|
||||
* This may be detrimental, however it avoids the reliance on $PATH
|
||||
* which may be a security issue when this program is run a set-uid-root.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static const char *searchPath [] =
|
||||
{
|
||||
"/sbin",
|
||||
"/usr/sbin",
|
||||
"/bin",
|
||||
"/usr/bin",
|
||||
NULL,
|
||||
} ;
|
||||
|
||||
static char *findExecutable (const char *progName)
|
||||
{
|
||||
static char *path = NULL ;
|
||||
int len = strlen (progName) ;
|
||||
int i = 0 ;
|
||||
struct stat statBuf ;
|
||||
|
||||
for (i = 0 ; searchPath [i] != NULL ; ++i)
|
||||
{
|
||||
path = malloc (strlen (searchPath [i]) + len + 2) ;
|
||||
sprintf (path, "%s/%s", searchPath [i], progName) ;
|
||||
|
||||
if (stat (path, &statBuf) == 0)
|
||||
return path ;
|
||||
free (path) ;
|
||||
}
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* changeOwner:
|
||||
* Change the ownership of the file to the real userId of the calling
|
||||
@@ -230,15 +276,18 @@ static void doLoad (int argc, char *argv [])
|
||||
else
|
||||
_doLoadUsage (argv) ;
|
||||
|
||||
if (findExecutable ("modprobe") == NULL)
|
||||
printf ("No found\n") ;
|
||||
|
||||
if (!moduleLoaded (module1))
|
||||
{
|
||||
sprintf (cmd, "/sbin/modprobe %s%s", module1, args1) ;
|
||||
sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module1, args1) ;
|
||||
system (cmd) ;
|
||||
}
|
||||
|
||||
if (!moduleLoaded (module2))
|
||||
{
|
||||
sprintf (cmd, "/sbin/modprobe %s%s", module2, args2) ;
|
||||
sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module2, args2) ;
|
||||
system (cmd) ;
|
||||
}
|
||||
|
||||
@@ -292,13 +341,13 @@ static void doUnLoad (int argc, char *argv [])
|
||||
|
||||
if (moduleLoaded (module1))
|
||||
{
|
||||
sprintf (cmd, "/sbin/rmmod %s", module1) ;
|
||||
sprintf (cmd, "%s %s", findExecutable (RMMOD), module1) ;
|
||||
system (cmd) ;
|
||||
}
|
||||
|
||||
if (moduleLoaded (module2))
|
||||
{
|
||||
sprintf (cmd, "/sbin/rmmod %s", module2) ;
|
||||
sprintf (cmd, "%s %s", findExecutable (RMMOD), module2) ;
|
||||
system (cmd) ;
|
||||
}
|
||||
}
|
||||
@@ -310,13 +359,12 @@ static void doUnLoad (int argc, char *argv [])
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doI2Cdetect (int argc, char *argv [])
|
||||
static void doI2Cdetect (UNU int argc, char *argv [])
|
||||
{
|
||||
int port = piBoardRev () == 1 ? 0 : 1 ;
|
||||
char command [128] ;
|
||||
struct stat statBuf ;
|
||||
int port = piGpioLayout () == 1 ? 0 : 1 ;
|
||||
char *c, *command ;
|
||||
|
||||
if (stat (I2CDETECT, &statBuf) < 0)
|
||||
if ((c = findExecutable (I2CDETECT)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ;
|
||||
return ;
|
||||
@@ -328,7 +376,8 @@ static void doI2Cdetect (int argc, char *argv [])
|
||||
return ;
|
||||
}
|
||||
|
||||
sprintf (command, "%s -y %d", I2CDETECT, port) ;
|
||||
command = malloc (strlen (c) + 16) ;
|
||||
sprintf (command, "%s -y %d", c, port) ;
|
||||
if (system (command) < 0)
|
||||
fprintf (stderr, "%s: Unable to run i2cdetect: %s\n", argv [0], strerror (errno)) ;
|
||||
|
||||
@@ -341,7 +390,7 @@ static void doI2Cdetect (int argc, char *argv [])
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doExports (int argc, char *argv [])
|
||||
static void doExports (UNU int argc, UNU char *argv [])
|
||||
{
|
||||
int fd ;
|
||||
int i, l, first ;
|
||||
@@ -667,7 +716,7 @@ void doUnexportall (char *progName)
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doReset (char *progName)
|
||||
static void doReset (UNU char *progName)
|
||||
{
|
||||
printf ("GPIO Reset is dangerous and has been removed from the gpio command.\n") ;
|
||||
printf (" - Please write a shell-script to reset the GPIO pins into the state\n") ;
|
||||
@@ -943,7 +992,7 @@ static void doAwrite (int argc, char *argv [])
|
||||
|
||||
/*
|
||||
* doWriteByte:
|
||||
* gpio write value
|
||||
* gpio wb value
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
@@ -963,6 +1012,30 @@ static void doWriteByte (int argc, char *argv [])
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doReadByte:
|
||||
* gpio rbx|rbd value
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doReadByte (int argc, char *argv [], int printHex)
|
||||
{
|
||||
int val ;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s rbx|rbd\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
val = digitalReadByte () ;
|
||||
if (printHex)
|
||||
printf ("%02X\n", val) ;
|
||||
else
|
||||
printf ("%d\n", val) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doRead:
|
||||
* Read a pin and return the value
|
||||
@@ -1026,6 +1099,34 @@ void doToggle (int argc, char *argv [])
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doBlink:
|
||||
* Blink an IO pin
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void doBlink (int argc, char *argv [])
|
||||
{
|
||||
int pin ;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s blink pin\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
pin = atoi (argv [2]) ;
|
||||
|
||||
pinMode (pin, OUTPUT) ;
|
||||
for (;;)
|
||||
{
|
||||
digitalWrite (pin, !digitalRead (pin)) ;
|
||||
delay (500) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doPwmTone:
|
||||
* Output a tone in a PWM pin
|
||||
@@ -1162,9 +1263,14 @@ static void doVersion (char *argv [])
|
||||
{
|
||||
int model, rev, mem, maker, warranty ;
|
||||
struct stat statBuf ;
|
||||
char name [80] ;
|
||||
FILE *fd ;
|
||||
|
||||
printf ("gpio version: %s\n", VERSION) ;
|
||||
printf ("Copyright (c) 2012-2015 Gordon Henderson\n") ;
|
||||
int vMaj, vMin ;
|
||||
|
||||
wiringPiVersion (&vMaj, &vMin) ;
|
||||
printf ("gpio version: %d.%d\n", vMaj, vMin) ;
|
||||
printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
|
||||
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
|
||||
printf ("For details type: %s -warranty\n", argv [0]) ;
|
||||
printf ("\n") ;
|
||||
@@ -1179,12 +1285,18 @@ static void doVersion (char *argv [])
|
||||
if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ...
|
||||
printf (" * Device tree is enabled.\n") ;
|
||||
|
||||
if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO
|
||||
if (stat ("/proc/device-tree/model", &statBuf) == 0) // Output Kernel idea of board type
|
||||
{
|
||||
printf (" * This Raspberry Pi supports user-level GPIO access.\n") ;
|
||||
printf (" -> See the man-page for more details\n") ;
|
||||
printf (" -> ie. export WIRINGPI_GPIOMEM=1\n") ;
|
||||
if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL)
|
||||
{
|
||||
fgets (name, 80, fd) ;
|
||||
fclose (fd) ;
|
||||
printf (" *--> %s\n", name) ;
|
||||
}
|
||||
}
|
||||
|
||||
if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO
|
||||
printf (" * This Raspberry Pi supports user-level GPIO access.\n") ;
|
||||
else
|
||||
printf (" * Root or sudo required for GPIO access.\n") ;
|
||||
}
|
||||
@@ -1225,7 +1337,7 @@ int main (int argc, char *argv [])
|
||||
|
||||
if ((strcmp (argv [1], "-R") == 0) || (strcmp (argv [1], "-V") == 0))
|
||||
{
|
||||
printf ("%d\n", piBoardRev ()) ;
|
||||
printf ("%d\n", piGpioLayout ()) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
@@ -1240,7 +1352,7 @@ int main (int argc, char *argv [])
|
||||
if (strcasecmp (argv [1], "-warranty") == 0)
|
||||
{
|
||||
printf ("gpio version: %s\n", VERSION) ;
|
||||
printf ("Copyright (c) 2012-2015 Gordon Henderson\n") ;
|
||||
printf ("Copyright (c) 2012-2017 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") ;
|
||||
@@ -1340,8 +1452,11 @@ int main (int argc, char *argv [])
|
||||
}
|
||||
|
||||
// Check for -x argument to load in a new extension
|
||||
// -x extension:base:args
|
||||
// Can load many modules, but unless daemon mode we can only send one
|
||||
// command at a time.
|
||||
|
||||
if (strcasecmp (argv [1], "-x") == 0)
|
||||
while (strcasecmp (argv [1], "-x") == 0)
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
@@ -1352,6 +1467,8 @@ int main (int argc, char *argv [])
|
||||
if (!loadWPiExtension (argv [0], argv [2], TRUE)) // Prints its own error messages
|
||||
exit (EXIT_FAILURE) ;
|
||||
|
||||
// Shift args down by 2
|
||||
|
||||
for (i = 3 ; i < argc ; ++i)
|
||||
argv [i - 2] = argv [i] ;
|
||||
argc -= 2 ;
|
||||
@@ -1375,6 +1492,7 @@ int main (int argc, char *argv [])
|
||||
// GPIO Nicies
|
||||
|
||||
else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "blink" ) == 0) doBlink (argc, argv) ;
|
||||
|
||||
// Pi Specifics
|
||||
|
||||
@@ -1391,6 +1509,8 @@ int main (int argc, char *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], "rbx" ) == 0) doReadByte (argc, argv, TRUE) ;
|
||||
else if (strcasecmp (argv [1], "rbd" ) == 0) doReadByte (argc, argv, FALSE) ;
|
||||
else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ;
|
||||
else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ;
|
||||
else
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* pins.c:
|
||||
* Just display a handy Pi pinnout diagram.
|
||||
* Copyright (c) 2012-2015 Gordon Henderson
|
||||
* Copyright (c) 2012-2017 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# Copyright (c) 2013-2015 Gordon Henderson
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# Wiring Compatable library for the Raspberry Pi
|
||||
# A "wiring" 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* readall.c:
|
||||
* The readall functions - getting a bit big, so split them out.
|
||||
* Copyright (c) 2012-2015 Gordon Henderson
|
||||
* Copyright (c) 2012-2017 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
@@ -118,7 +118,7 @@ static char *physNames [64] =
|
||||
NULL,
|
||||
|
||||
" 3.3v", "5v ",
|
||||
" SDA.1", "5V ",
|
||||
" SDA.1", "5v ",
|
||||
" SCL.1", "0v ",
|
||||
"GPIO. 7", "TxD ",
|
||||
" 0v", "RxD ",
|
||||
@@ -348,7 +348,7 @@ void doReadall (void)
|
||||
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))
|
||||
piPlusReadall (model) ;
|
||||
else if (model == PI_MODEL_CM)
|
||||
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3))
|
||||
allReadall () ;
|
||||
else
|
||||
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# in-turn.
|
||||
#################################################################################
|
||||
# This file is part of wiringPi:
|
||||
# Wiring Compatable library for the Raspberry Pi
|
||||
# A "wiring" 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
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#define VERSION "2.32"
|
||||
Reference in New Issue
Block a user