Partial update to latest WiringPi
diff --git a/WiringPi/wiringPi/wiringPi.c b/WiringPi/wiringPi/wiringPi.c
index b8e381a..b54ad29 100644
--- a/WiringPi/wiringPi/wiringPi.c
+++ b/WiringPi/wiringPi/wiringPi.c
@@ -88,7 +88,7 @@
#define PI_GPIO_MASK (0xFFFFFFC0)
-static struct wiringPiNodeStruct *wiringPiNodes = NULL ;
+struct wiringPiNodeStruct *wiringPiNodes = NULL ;
// BCM Magic
@@ -118,7 +118,6 @@
#define FSEL_INPT 0b000
#define FSEL_OUTP 0b001
#define FSEL_ALT0 0b100
-#define FSEL_ALT0 0b100
#define FSEL_ALT1 0b101
#define FSEL_ALT2 0b110
#define FSEL_ALT3 0b111
@@ -213,7 +212,13 @@
// 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
@@ -833,7 +838,7 @@
*********************************************************************************
*/
-static struct wiringPiNodeStruct *wiringPiFindNode (int pin)
+struct wiringPiNodeStruct *wiringPiFindNode (int pin)
{
struct wiringPiNodeStruct *node = wiringPiNodes ;
@@ -919,6 +924,32 @@
*********************************************************************************
*/
+/*
+ * pinModeAlt:
+ * This is an un-documented special to let you set any pin to any mode
+ *********************************************************************************
+ */
+
+void pinModeAlt (int pin, int mode)
+{
+ int fSel, shift ;
+
+ if ((pin & PI_GPIO_MASK) == 0) // On-board pin
+ {
+ /**/ if (wiringPiMode == WPI_MODE_PINS)
+ pin = pinToGpio [pin] ;
+ else if (wiringPiMode == WPI_MODE_PHYS)
+ pin = physToGpio [pin] ;
+ else if (wiringPiMode != WPI_MODE_GPIO)
+ return ;
+
+ fSel = gpioToGPFSEL [pin] ;
+ shift = gpioToShift [pin] ;
+
+ *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | ((mode & 0x7) << shift) ;
+ }
+}
+
/*
* pinMode:
@@ -1304,7 +1335,8 @@
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") ;
@@ -1333,26 +1365,26 @@
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.
+// Now pre-open the /sys/class node - but it may already be open if
+// we are in Sys mode...
- if (sysFds [bcmGpioPin] != -1)
- close (sysFds [bcmGpioPin]) ;
-
- 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
@@ -1441,6 +1473,8 @@
void delayMicroseconds (unsigned int howLong)
{
struct timespec sleeper ;
+ unsigned int uSecs = howLong % 1000000 ;
+ unsigned int wSecs = howLong / 1000000 ;
/**/ if (howLong == 0)
return ;
@@ -1448,8 +1482,8 @@
delayMicrosecondsHard (howLong) ;
else
{
- sleeper.tv_sec = 0 ;
- sleeper.tv_nsec = (long)(howLong * 1000) ;
+ sleeper.tv_sec = wSecs ;
+ sleeper.tv_nsec = (long)(uSecs * 1000L) ;
nanosleep (&sleeper, NULL) ;
}
}
@@ -1532,7 +1566,7 @@
// Open the master /dev/memory device
- if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0)
+ if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
// GPIO:
diff --git a/WiringPi/wiringPi/wiringPi.h b/WiringPi/wiringPi/wiringPi.h
index 600b318..ce4680a 100644
--- a/WiringPi/wiringPi/wiringPi.h
+++ b/WiringPi/wiringPi/wiringPi.h
@@ -104,6 +104,8 @@
struct wiringPiNodeStruct *next ;
} ;
+extern struct wiringPiNodeStruct *wiringPiNodes ;
+
// Function prototypes
// c++ wrappers thanks to a comment by Nick Lott
@@ -119,13 +121,15 @@
// 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) ;
extern int wiringPiSetupGpio (void) ;
extern int wiringPiSetupPhys (void) ;
+extern void pinModeAlt (int pin, int mode) ;
extern void pinMode (int pin, int mode) ;
extern void pullUpDnControl (int pin, int pud) ;
extern int digitalRead (int pin) ;
diff --git a/setup.py b/setup.py
index 17db3f1..ac52a91 100644
--- a/setup.py
+++ b/setup.py
@@ -7,13 +7,17 @@
sources=[
'WiringPi/wiringPi/wiringPi.c',
'WiringPi/wiringPi/wiringPiSPI.c',
+ 'WiringPi/wiringPi/max31855.c',
+ 'WiringPi/wiringPi/max5322.c',
'WiringPi/wiringPi/drc.c',
+ 'WiringPi/wiringPi/sn3218.c',
'WiringPi/wiringPi/mcp23s17.c',
'WiringPi/wiringPi/pcf8591.c',
'WiringPi/wiringPi/softTone.c',
'WiringPi/wiringPi/wiringSerial.c',
'WiringPi/wiringPi/mcp23008.c',
'WiringPi/wiringPi/mcp3002.c',
+ 'WiringPi/wiringPi/mcp3004.c',
'WiringPi/wiringPi/piHiPri.c',
'WiringPi/wiringPi/sr595.c',
'WiringPi/wiringPi/wiringShift.c',
@@ -34,6 +38,7 @@
'WiringPi/devLib/lcd.c',
'WiringPi/devLib/piFace.c',
'WiringPi/devLib/piNes.c',
+ 'WiringPi/devLib/piGlow.c',
'wiringpi_wrap.c'
],
)
@@ -54,7 +59,10 @@
headers=[
'WiringPi/wiringPi/wiringPi.h',
'WiringPi/wiringPi/wiringPiI2C.h',
+ 'WiringPi/wiringPi/max31855.h',
+ 'WiringPi/wiringPi/max5322.h',
'WiringPi/wiringPi/drc.h',
+ 'WiringPi/wiringPi/sn3218.h',
'WiringPi/wiringPi/mcp23s08.h',
'WiringPi/wiringPi/mcp3422.h',
'WiringPi/wiringPi/softServo.h',
@@ -74,6 +82,7 @@
'WiringPi/wiringPi/pcf8591.h',
'WiringPi/wiringPi/mcp23017.h',
'WiringPi/wiringPi/mcp3002.h',
+ 'WiringPi/wiringPi/mcp3004.h',
'WiringPi/wiringPi/softPwm.h',
'WiringPi/devLib/ds1302.h',
'WiringPi/devLib/gertboard.h',
@@ -83,5 +92,6 @@
'WiringPi/devLib/lcd128x64.h',
'WiringPi/devLib/maxdetect.h',
'WiringPi/devLib/piNes.h'
+ 'WiringPi/devLib/piGlow.h',
]
)
diff --git a/wiringpi.i b/wiringpi.i
index 1cf28e1..1780955 100644
--- a/wiringpi.i
+++ b/wiringpi.i
@@ -6,6 +6,8 @@
#include "WiringPi/wiringPi/wiringPiI2C.h"
#include "WiringPi/wiringPi/wiringSerial.h"
#include "WiringPi/wiringPi/wiringShift.h"
+#include "WiringPi/wiringPi/max31855.h"
+#include "WiringPi/wiringPi/max5322.h"
#include "WiringPi/wiringPi/mcp23017.h"
#include "WiringPi/wiringPi/mcp4802.h"
#include "WiringPi/wiringPi/mcp3422.h"
@@ -14,7 +16,9 @@
#include "WiringPi/wiringPi/mcp23x08.h"
#include "WiringPi/wiringPi/mcp23016.h"
#include "WiringPi/wiringPi/mcp3002.h"
+#include "WiringPi/wiringPi/mcp3004.h"
#include "WiringPi/wiringPi/mcp23016reg.h"
+#include "WiringPi/wiringPi/sn3218.h"
#include "WiringPi/wiringPi/mcp23x0817.h"
#include "WiringPi/wiringPi/mcp23s17.h"
#include "WiringPi/wiringPi/pcf8574.h"
@@ -32,6 +36,7 @@
#include "WiringPi/devLib/piFace.h"
#include "WiringPi/devLib/ds1302.h"
#include "WiringPi/devLib/piNes.h"
+#include "WiringPi/devLib/piGlow.h"
%}
%apply unsigned char { uint8_t };
@@ -209,6 +214,9 @@
extern int setupNesJoystick (int dPin, int cPin, int lPin) ;
extern unsigned int readNesJoystick (int joystick) ;
-
+// PiGlow
+extern void piGlow1 (const int leg, const int ring, const int intensity) ;
+extern void piGlowLeg (const int leg, const int intensity) ;
+extern void piGlowRing (const int ring, const int intensity) ;
%include "wiringpi2-class.py"
diff --git a/wiringpi2.py b/wiringpi2.py
index 5fb5c37..2a3557d 100644
--- a/wiringpi2.py
+++ b/wiringpi2.py
@@ -503,6 +503,18 @@
def readNesJoystick(*args):
return _wiringpi2.readNesJoystick(*args)
readNesJoystick = _wiringpi2.readNesJoystick
+
+def piGlow1(*args):
+ return _wiringpi2.piGlow1(*args)
+piGlow1 = _wiringpi2.piGlow1
+
+def piGlowLeg(*args):
+ return _wiringpi2.piGlowLeg(*args)
+piGlowLeg = _wiringpi2.piGlowLeg
+
+def piGlowRing(*args):
+ return _wiringpi2.piGlowRing(*args)
+piGlowRing = _wiringpi2.piGlowRing
class nes(object):
def setupNesJoystick(self,*args):
return setupNesJoystick(*args)
@@ -658,7 +670,7 @@
def softPwmCreate(self,*args):
return softPwmCreate(*args)
def softPwmWrite(self,*args):
- return softPwmWrite(*args)
+ return sofPwmWrite(*args)
def softToneCreate(self,*args):
return softToneCreate(*args)
diff --git a/wiringpi2.pyc b/wiringpi2.pyc
index 9735e5b..0ddd717 100644
--- a/wiringpi2.pyc
+++ b/wiringpi2.pyc
Binary files differ
diff --git a/wiringpi_wrap.c b/wiringpi_wrap.c
index fefd55e..d53d4c5 100644
--- a/wiringpi_wrap.c
+++ b/wiringpi_wrap.c
@@ -2972,6 +2972,8 @@
#include "WiringPi/wiringPi/wiringPiI2C.h"
#include "WiringPi/wiringPi/wiringSerial.h"
#include "WiringPi/wiringPi/wiringShift.h"
+#include "WiringPi/wiringPi/max31855.h"
+#include "WiringPi/wiringPi/max5322.h"
#include "WiringPi/wiringPi/mcp23017.h"
#include "WiringPi/wiringPi/mcp4802.h"
#include "WiringPi/wiringPi/mcp3422.h"
@@ -2980,6 +2982,7 @@
#include "WiringPi/wiringPi/mcp23x08.h"
#include "WiringPi/wiringPi/mcp23016.h"
#include "WiringPi/wiringPi/mcp3002.h"
+#include "WiringPi/wiringPi/mcp3004.h"
#include "WiringPi/wiringPi/mcp23016reg.h"
#include "WiringPi/wiringPi/mcp23x0817.h"
#include "WiringPi/wiringPi/mcp23s17.h"
@@ -2998,6 +3001,7 @@
#include "WiringPi/devLib/piFace.h"
#include "WiringPi/devLib/ds1302.h"
#include "WiringPi/devLib/piNes.h"
+#include "WiringPi/devLib/piGlow.h"
SWIGINTERNINLINE PyObject*
@@ -6774,6 +6778,105 @@
}
+SWIGINTERN PyObject *_wrap_piGlow1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *resultobj = 0;
+ int arg1 ;
+ int arg2 ;
+ int arg3 ;
+ int val1 ;
+ int ecode1 = 0 ;
+ int val2 ;
+ int ecode2 = 0 ;
+ int val3 ;
+ int ecode3 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+
+ if (!PyArg_ParseTuple(args,(char *)"OOO:piGlow1",&obj0,&obj1,&obj2)) SWIG_fail;
+ ecode1 = SWIG_AsVal_int(obj0, &val1);
+ if (!SWIG_IsOK(ecode1)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "piGlow1" "', argument " "1"" of type '" "int""'");
+ }
+ arg1 = (int)(val1);
+ ecode2 = SWIG_AsVal_int(obj1, &val2);
+ if (!SWIG_IsOK(ecode2)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "piGlow1" "', argument " "2"" of type '" "int""'");
+ }
+ arg2 = (int)(val2);
+ ecode3 = SWIG_AsVal_int(obj2, &val3);
+ if (!SWIG_IsOK(ecode3)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "piGlow1" "', argument " "3"" of type '" "int""'");
+ }
+ arg3 = (int)(val3);
+ piGlow1(arg1,arg2,arg3);
+ resultobj = SWIG_Py_Void();
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_piGlowLeg(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *resultobj = 0;
+ int arg1 ;
+ int arg2 ;
+ int val1 ;
+ int ecode1 = 0 ;
+ int val2 ;
+ int ecode2 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+
+ if (!PyArg_ParseTuple(args,(char *)"OO:piGlowLeg",&obj0,&obj1)) SWIG_fail;
+ ecode1 = SWIG_AsVal_int(obj0, &val1);
+ if (!SWIG_IsOK(ecode1)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "piGlowLeg" "', argument " "1"" of type '" "int""'");
+ }
+ arg1 = (int)(val1);
+ ecode2 = SWIG_AsVal_int(obj1, &val2);
+ if (!SWIG_IsOK(ecode2)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "piGlowLeg" "', argument " "2"" of type '" "int""'");
+ }
+ arg2 = (int)(val2);
+ piGlowLeg(arg1,arg2);
+ resultobj = SWIG_Py_Void();
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_piGlowRing(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *resultobj = 0;
+ int arg1 ;
+ int arg2 ;
+ int val1 ;
+ int ecode1 = 0 ;
+ int val2 ;
+ int ecode2 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+
+ if (!PyArg_ParseTuple(args,(char *)"OO:piGlowRing",&obj0,&obj1)) SWIG_fail;
+ ecode1 = SWIG_AsVal_int(obj0, &val1);
+ if (!SWIG_IsOK(ecode1)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "piGlowRing" "', argument " "1"" of type '" "int""'");
+ }
+ arg1 = (int)(val1);
+ ecode2 = SWIG_AsVal_int(obj1, &val2);
+ if (!SWIG_IsOK(ecode2)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "piGlowRing" "', argument " "2"" of type '" "int""'");
+ }
+ arg2 = (int)(val2);
+ piGlowRing(arg1,arg2);
+ resultobj = SWIG_Py_Void();
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
static PyMethodDef SwigMethods[] = {
{ (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL},
{ (char *)"wiringPiSetup", _wrap_wiringPiSetup, METH_VARARGS, NULL},
@@ -6885,6 +6988,9 @@
{ (char *)"lcd128x64setup", _wrap_lcd128x64setup, METH_VARARGS, NULL},
{ (char *)"setupNesJoystick", _wrap_setupNesJoystick, METH_VARARGS, NULL},
{ (char *)"readNesJoystick", _wrap_readNesJoystick, METH_VARARGS, NULL},
+ { (char *)"piGlow1", _wrap_piGlow1, METH_VARARGS, NULL},
+ { (char *)"piGlowLeg", _wrap_piGlowLeg, METH_VARARGS, NULL},
+ { (char *)"piGlowRing", _wrap_piGlowRing, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL }
};