with wiringPiISR.
Added the ability to readall/reset from extension modules.
Changed the build script to use /bin/sh rather than /bin/bash as it seems
some installations don't have /bin/bash (or if they do, then the people who
are telling me that ./build gives them command not found are wrong)
-#!/bin/bash
+#!/bin/sh
-check-make-ok()
-{
+check_make_ok() {
if [ $? != 0 ]; then
echo ""
echo "Make Failed..."
cd wiringPi
sudo make uninstall
make
- check-make-ok
+ check_make_ok
sudo make install
- check-make-ok
+ check_make_ok
echo
echo "WiringPi Devices Library"
cd ../devLib
sudo make uninstall
make
- check-make-ok
+ check_make_ok
sudo make install
- check-make-ok
+ check_make_ok
echo
echo "GPIO Utility"
cd ../gpio
make
- check-make-ok
+ check_make_ok
sudo make install
- check-make-ok
+ check_make_ok
# echo
# echo "Examples"
if the pin is in input mode, or the last value written if the pin is in output
mode.
+The readall command is usable with an extension module (via the -x parameter),
+but it's unable to determine pin modes or states, so will perform both a
+digital and analog read on each pin in-turn.
+
.TP
.B reset
Resets the GPIO - As much as it's possible to do. All pins are set to input
mode and all the internal pull-up/down resistors are disconnected (tristate mode).
+The reset command is usable with an extension module (via the -x parameter),
+but it's limited to turning the pin into input mode (if applicable) and
+removing any pull up/down resistor.
+
.TP
.B pwm <pin> <value>
Write a PWM value (0-1023) to the given pin. The pin needs to be put
.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.
+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.
.TP
.B load spi [buffer size in KB]
# define FALSE (1==2)
#endif
-#define VERSION "2.06"
+#define VERSION "2.07"
#define I2CDETECT "/usr/sbin/i2cdetect"
static int wpMode ;
/*
* doReadall:
* Read all the GPIO pins
+ * We also want to use this to read the state of pins on an externally
+ * connected device, so we need to do some fiddling with the internal
+ * wiringPi node structures - since the gpio command can only use
+ * one external device at a time, we'll use that to our advantage...
*********************************************************************************
*/
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 47..63
} ;
-static void doReadall (void)
+
+/*
+ * doReadallExternal:
+ * A relatively crude way to read the pins on an external device.
+ * We don't know the input/output mode of pins, but we can tell
+ * if it's an analog pin or a digital one...
+ *********************************************************************************
+ */
+
+static void doReadallExternal (void)
{
int pin ;
- printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ;
- printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ;
- printf ("+----------+------+------+--------+------+-------+\n") ;
+ printf ("+------+---------+--------+\n") ;
+ printf ("| Pin | Digital | Analog |\n") ;
+ printf ("+------+---------+--------+\n") ;
- for (pin = 0 ; pin < 64 ; ++pin) // Crude, but effective
+ for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
+ printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
+
+ printf ("+------+---------+--------+\n") ;
+}
+
+
+static void doReadall (void)
+{
+ int pin ;
+
+ if (wiringPiNodes != NULL) // External readall
+ doReadallExternal () ;
+ else
{
- if (wpiPinToGpio (pin) == -1)
- continue ;
+ printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ;
+ printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ;
+ printf ("+----------+------+------+--------+------+-------+\n") ;
- printf ("| %6d | %3d | %3d | %s | %s | %s |\n",
- pin, wpiPinToGpio (pin), wpiToPhys [pin],
- pinNames [pin],
- alts [getAlt (pin)],
- digitalRead (pin) == HIGH ? "High" : "Low ") ;
- }
+ for (pin = 0 ; pin < 64 ; ++pin) // Crude, but effective
+ {
+ if (wpiPinToGpio (pin) == -1)
+ continue ;
+
+ printf ("| %6d | %3d | %3d | %s | %s | %s |\n",
+ pin, wpiPinToGpio (pin), wpiToPhys [pin],
+ pinNames [pin],
+ alts [getAlt (pin)],
+ digitalRead (pin) == HIGH ? "High" : "Low ") ;
+ }
- printf ("+----------+------+------+--------+------+-------+\n") ;
+ printf ("+----------+------+------+--------+------+-------+\n") ;
+ }
}
}
+/*
+ * doResetExternal:
+ * Load readallExternal, we try to do this with an external device.
+ *********************************************************************************
+ */
+
+static void doResetExternal (void)
+{
+ int pin ;
+
+ for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
+ {
+ pinMode (pin, INPUT) ;
+ pullUpDnControl (pin, PUD_OFF) ;
+ }
+}
+
+
/*
* doReset:
* Reset the GPIO pins - as much as we can do
{
int pin ;
- doUnexportall (progName) ;
-
- for (pin = 0 ; pin < 64 ; ++pin)
+ if (wiringPiNodes != NULL) // External reset
+ doResetExternal () ;
+ else
{
- if (wpiPinToGpio (pin) == -1)
- continue ;
+ doUnexportall (progName) ;
- digitalWrite (pin, LOW) ;
- pinMode (pin, INPUT) ;
- pullUpDnControl (pin, PUD_OFF) ;
+ for (pin = 0 ; pin < 64 ; ++pin)
+ {
+ if (wpiPinToGpio (pin) == -1)
+ continue ;
+
+ digitalWrite (pin, LOW) ;
+ pinMode (pin, INPUT) ;
+ pullUpDnControl (pin, PUD_OFF) ;
+ }
}
}
#define PI_GPIO_MASK (0xFFFFFFC0)
-static struct wiringPiNodeStruct *wiringPiNodes = NULL ;
+struct wiringPiNodeStruct *wiringPiNodes = NULL ;
// BCM Magic
// sysFds:
// Map a file descriptor from the /sys/class/gpio/gpioX/value
-static int sysFds [64] ;
+static int sysFds [64] =
+{
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+} ;
// ISR Data
*********************************************************************************
*/
-static struct wiringPiNodeStruct *wiringPiFindNode (int pin)
+struct wiringPiNodeStruct *wiringPiFindNode (int pin)
{
struct wiringPiNodeStruct *node = wiringPiNodes ;
char c ;
int bcmGpioPin ;
- pin &= 63 ;
+ if ((pin < 0) || (pin > 63))
+ return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-63 (%d)\n", pin) ;
/**/ if (wiringPiMode == WPI_MODE_UNINITIALISED)
return wiringPiFailure (WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n") ;
sprintf (pinS, "%d", bcmGpioPin) ;
if ((pid = fork ()) < 0) // Fail
- return pid ;
+ return wiringPiFailure (WPI_FATAL, "wiringPiISR: fork failed: %s\n", strerror (errno)) ;
if (pid == 0) // Child, exec
{
execl ("/usr/local/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ;
- return -1 ; // Failure ...
+ return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ;
}
else // Parent, wait
wait (NULL) ;
}
-// Now pre-open the /sys/class node - it may already be open if
-// we are in Sys mode or if we call here twice, if-so, we'll close it.
-
- if (sysFds [bcmGpioPin] != -1)
- close (sysFds [bcmGpioPin]) ;
+// Now pre-open the /sys/class node - but it may already be open if
+// we are in Sys mode...
- sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ;
- if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0)
- return -1 ;
+ if (sysFds [bcmGpioPin] == -1)
+ {
+ sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ;
+ if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0)
+ return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ;
+ }
// Clear any initial pending interrupt
struct wiringPiNodeStruct *next ;
} ;
+extern struct wiringPiNodeStruct *wiringPiNodes ;
+
// Function prototypes
// c++ wrappers thanks to a comment by Nick Lott
// Core wiringPi functions
-extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
+extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
+extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
extern int wiringPiSetup (void) ;
extern int wiringPiSetupSys (void) ;