From e687f3f2c62079c48c89cbca5a5ebe8ec259d1c0 Mon Sep 17 00:00:00 2001 From: Gordon Henderson Date: Tue, 24 Jan 2017 12:13:39 +0000 Subject: [PATCH] Pushing to 2.39 as I have have not done the last one rightly... --- VERSION | 2 +- debian-template/wiringPi/DEBIAN/control | 4 +- gpio/Makefile | 2 +- gpio/gpio.c | 30 ++++++---- gpio/pins.c | 2 +- gpio/readall.c | 4 +- gpio/version.h | 1 - newVersion | 10 +++- version.h | 4 +- wiringPi/Makefile | 6 +- wiringPi/htu21d.c | 2 +- wiringPi/pcf8591.c | 2 +- wiringPi/wiringPi.c | 80 +++++++++++++++++-------- wiringPi/wiringPi.h | 31 ++++++---- wiringPi/wiringSerial.c | 1 + wiringPi/wpiExtensions.c | 9 ++- 16 files changed, 122 insertions(+), 68 deletions(-) delete mode 100644 gpio/version.h diff --git a/VERSION b/VERSION index 90177b7..23f3620 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.36 +2.39 diff --git a/debian-template/wiringPi/DEBIAN/control b/debian-template/wiringPi/DEBIAN/control index d9f2658..80cd3f8 100644 --- a/debian-template/wiringPi/DEBIAN/control +++ b/debian-template/wiringPi/DEBIAN/control @@ -1,5 +1,5 @@ Package: wiringpi -Version: 2.36 +Version: 2.38 Section: libraries Priority: optional Architecture: armhf @@ -7,4 +7,4 @@ Depends: libc6 Maintainer: Gordon Henderson Description: The wiringPi libraries, headers and gpio command Libraries to allow GPIO access on a Raspberry Pi from C and C++ - programs as well as from the command-line + and BASIC programs as well as from the command-line diff --git a/gpio/Makefile b/gpio/Makefile index cdf954f..9152ea8 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -100,4 +100,4 @@ depend: # DO NOT DELETE -gpio.o: version.h +gpio.o: ../version.h diff --git a/gpio/gpio.c b/gpio/gpio.c index c954f3b..3327308 100644 --- a/gpio/gpio.c +++ b/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 #include -#include "version.h" +#include "../version.h" extern int wiringPiDebug ; @@ -64,7 +64,9 @@ 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] ...\n" " gpio ...\n" " gpio \n" @@ -357,7 +359,7 @@ static void doUnLoad (int argc, char *argv []) ********************************************************************************* */ -static void doI2Cdetect (int argc, char *argv []) +static void doI2Cdetect (UNU int argc, char *argv []) { int port = piGpioLayout () == 1 ? 0 : 1 ; char *c, *command ; @@ -388,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 ; @@ -714,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") ; @@ -1264,8 +1266,11 @@ static void doVersion (char *argv []) 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") ; @@ -1347,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") ; @@ -1447,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) { @@ -1459,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 ; diff --git a/gpio/pins.c b/gpio/pins.c index d889a45..3a4dc15 100644 --- a/gpio/pins.c +++ b/gpio/pins.c @@ -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/ diff --git a/gpio/readall.c b/gpio/readall.c index c447e5e..aec6de6 100644 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -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/ @@ -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) ; diff --git a/gpio/version.h b/gpio/version.h deleted file mode 100644 index 687cc74..0000000 --- a/gpio/version.h +++ /dev/null @@ -1 +0,0 @@ -#define VERSION "2.36" diff --git a/newVersion b/newVersion index 299d7a7..ed4b438 100755 --- a/newVersion +++ b/newVersion @@ -25,8 +25,12 @@ echo Updating to version: `cat VERSION` -rm -f gpio/version.h -echo "#define VERSION \"`cat VERSION`\"" > gpio/version.h +rm -f version.h +vMaj=`cut -d. -f1 VERSION` +vMin=`cut -d. -f2 VERSION` +echo "#define VERSION \"`cat VERSION`\"" > version.h +echo "#define VERSION_MAJOR $vMaj" >> version.h +echo "#define VERSION_MINOR $vMin" >> version.h rm -f debian-template/wiringPi/DEBIAN/control cat > debian-template/wiringPi/DEBIAN/control < Description: The wiringPi libraries, headers and gpio command Libraries to allow GPIO access on a Raspberry Pi from C and C++ - programs as well as from the command-line + and BASIC programs as well as from the command-line EOF diff --git a/version.h b/version.h index 4503af6..fde08f3 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "2.36" +#define VERSION "2.38" #define VERSION_MAJOR 2 -#define VERSION_MINOR 36 +#define VERSION_MINOR 38 diff --git a/wiringPi/Makefile b/wiringPi/Makefile index ffe0012..13d006f 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -140,7 +140,7 @@ depend: # DO NOT DELETE -wiringPi.o: softPwm.h softTone.h wiringPi.h +wiringPi.o: softPwm.h softTone.h wiringPi.h ../version.h wiringSerial.o: wiringSerial.h wiringShift.o: wiringPi.h wiringShift.h piHiPri.o: wiringPi.h @@ -169,7 +169,9 @@ bmp180.o: wiringPi.h wiringPiI2C.h bmp180.h htu21d.o: wiringPi.h wiringPiI2C.h htu21d.h ds18b20.o: wiringPi.h ds18b20.h drcSerial.o: wiringPi.h wiringSerial.h drcSerial.h +pseudoPins.o: wiringPi.h pseudoPins.h wpiExtensions.o: wiringPi.h mcp23008.h mcp23016.h mcp23017.h mcp23s08.h wpiExtensions.o: mcp23s17.h sr595.h pcf8574.h pcf8591.h mcp3002.h mcp3004.h wpiExtensions.o: mcp4802.h mcp3422.h max31855.h max5322.h ads1115.h sn3218.h -wpiExtensions.o: drcSerial.h bmp180.h htu21d.h ds18b20.h wpiExtensions.h +wpiExtensions.o: drcSerial.h pseudoPins.h bmp180.h htu21d.h ds18b20.h +wpiExtensions.o: wpiExtensions.h diff --git a/wiringPi/htu21d.c b/wiringPi/htu21d.c index 9028d60..46c0fcb 100644 --- a/wiringPi/htu21d.c +++ b/wiringPi/htu21d.c @@ -38,7 +38,7 @@ #define I2C_ADDRESS 0x40 -int checksum (uint8_t data [4]) +int checksum (UNU uint8_t data [4]) { return TRUE ; } diff --git a/wiringPi/pcf8591.c b/wiringPi/pcf8591.c index 0c43d26..66c6255 100644 --- a/wiringPi/pcf8591.c +++ b/wiringPi/pcf8591.c @@ -36,7 +36,7 @@ ********************************************************************************* */ -static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value) +static void myAnalogWrite (struct wiringPiNodeStruct *node, UNU int pin, int value) { unsigned char b [2] ; b [0] = 0x40 ; diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 5adfe69..ba86f41 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1,7 +1,7 @@ /* * wiringPi: * Arduino look-a-like Wiring library for the Raspberry Pi - * Copyright (c) 2012-2015 Gordon Henderson + * Copyright (c) 2012-2017 Gordon Henderson * Additional code for pwmSetClock by Chris Hall * * Thanks to code samples from Gert Jan van Loo and the @@ -75,6 +75,7 @@ #include "softTone.h" #include "wiringPi.h" +#include "../version.h" // Environment Variables @@ -196,11 +197,6 @@ static volatile uint32_t *timer ; static volatile uint32_t *timerIrqRaw ; #endif -// GCC warning suppressor - -#define UNU __attribute__((unused)) - - // Data for use with the boardId functions. // The order of entries here to correspond with the PI_MODEL_X // and PI_VERSION_X defines in wiringPi.h @@ -226,7 +222,7 @@ const char *piModelNames [16] = "Unknown07", // 07 "Pi 3", // 08 "Pi Zero", // 09 - "Unknown10", // 10 + "CM3", // 10 "Unknown11", // 11 "Unknown12", // 12 "Unknown13", // 13 @@ -804,20 +800,17 @@ int piGpioLayout (void) return gpioLayout ; } -/*** - if (strstr (line, "BCM2709") != NULL) // Pi v2 - no point doing anything more at this point - { - piModel2 = TRUE ; - fclose (cpuFd) ; - return gpioLayout = 2 ; - } - else if (strstr (line, "BCM2708") == NULL) - { - } -***/ +/* + * piBoardRev: + * Deprecated, but does the same as piGpioLayout + ********************************************************************************* + */ + +int piBoardRev (void) +{ + return piGpioLayout () ; +} -// Now do the rest of it as before - we just need to see if it's an older -// Rev 1 as anything else is rev 2. /* @@ -963,7 +956,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) *warranty = bWarranty ; if (wiringPiDebug) - printf ("piboardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", + printf ("piBoardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", bRev, bType, bProc, bMfg, bMem, bWarranty) ; } else // Old way @@ -1938,11 +1931,19 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) static void initialiseEpoch (void) { +#ifdef OLD_WAY struct timeval tv ; gettimeofday (&tv, NULL) ; epochMilli = (uint64_t)tv.tv_sec * (uint64_t)1000 + (uint64_t)(tv.tv_usec / 1000) ; epochMicro = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)(tv.tv_usec) ; +#else + struct timespec ts ; + + clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ; + epochMilli = (uint64_t)ts.tv_sec * (uint64_t)1000 + (uint64_t)(ts.tv_nsec / 1000000L) ; + epochMicro = (uint64_t)ts.tv_sec * (uint64_t)1000000 + (uint64_t)(ts.tv_nsec / 1000L) ; +#endif } @@ -2016,17 +2017,27 @@ void delayMicroseconds (unsigned int howLong) /* * millis: * Return a number of milliseconds as an unsigned int. + * Wraps at 49 days. ********************************************************************************* */ unsigned int millis (void) { - struct timeval tv ; uint64_t now ; +#ifdef OLD_WAY + struct timeval tv ; + gettimeofday (&tv, NULL) ; now = (uint64_t)tv.tv_sec * (uint64_t)1000 + (uint64_t)(tv.tv_usec / 1000) ; +#else + struct timespec ts ; + + clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ; + now = (uint64_t)ts.tv_sec * (uint64_t)1000 + (uint64_t)(ts.tv_nsec / 1000000L) ; +#endif + return (uint32_t)(now - epochMilli) ; } @@ -2034,20 +2045,41 @@ unsigned int millis (void) /* * micros: * Return a number of microseconds as an unsigned int. + * Wraps after 71 minutes. ********************************************************************************* */ unsigned int micros (void) { - struct timeval tv ; uint64_t now ; +#ifdef OLD_WAY + struct timeval tv ; gettimeofday (&tv, NULL) ; now = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec ; +#else + struct timespec ts ; + + clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ; + now = (uint64_t)ts.tv_sec * (uint64_t)1000000 + (uint64_t)(ts.tv_nsec / 1000) ; +#endif + return (uint32_t)(now - epochMicro) ; } +/* + * wiringPiVersion: + * Return our current version number + ********************************************************************************* + */ + +void wiringPiVersion (int *major, int *minor) +{ + *major = VERSION_MAJOR ; + *minor = VERSION_MINOR ; +} + /* * wiringPiSetup: @@ -2092,7 +2124,7 @@ int wiringPiSetup (void) piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if (model == PI_MODEL_CM) + if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3)) wiringPiMode = WPI_MODE_GPIO ; else wiringPiMode = WPI_MODE_PINS ; diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 7926296..1b50470 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -1,7 +1,7 @@ /* * wiringPi.h: * Arduino like Wiring library for the Raspberry Pi. - * Copyright (c) 2012-2016 Gordon Henderson + * Copyright (c) 2012-2017 Gordon Henderson *********************************************************************** * This file is part of wiringPi: * https://projects.drogon.net/raspberry-pi/wiringpi/ @@ -32,6 +32,10 @@ # define FALSE (!TRUE) #endif +// GCC warning suppressor + +#define UNU __attribute__((unused)) + // Handy defines // wiringPi modes @@ -77,16 +81,17 @@ // Pi model types and version numbers // Intended for the GPIO program Use at your own risk. -#define PI_MODEL_A 0 -#define PI_MODEL_B 1 -#define PI_MODEL_AP 2 -#define PI_MODEL_BP 3 -#define PI_MODEL_2 4 -#define PI_ALPHA 5 -#define PI_MODEL_CM 6 -#define PI_MODEL_07 7 -#define PI_MODEL_3 8 -#define PI_MODEL_ZERO 9 +#define PI_MODEL_A 0 +#define PI_MODEL_B 1 +#define PI_MODEL_AP 2 +#define PI_MODEL_BP 3 +#define PI_MODEL_2 4 +#define PI_ALPHA 5 +#define PI_MODEL_CM 6 +#define PI_MODEL_07 7 +#define PI_MODEL_3 8 +#define PI_MODEL_ZERO 9 +#define PI_MODEL_CM3 10 #define PI_VERSION_1 0 #define PI_VERSION_1_1 1 @@ -108,7 +113,7 @@ extern const int piMemorySize [ 8] ; // Threads -#define PI_THREAD(X) void *X (void *dummy) +#define PI_THREAD(X) void *X (UNU void *dummy) // Failure modes @@ -168,6 +173,7 @@ extern int wiringPiFailure (int fatal, const char *message, ...) ; extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ; extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ; +extern void wiringPiVersion (int *major, int *minor) ; extern int wiringPiSetup (void) ; extern int wiringPiSetupSys (void) ; extern int wiringPiSetupGpio (void) ; @@ -191,6 +197,7 @@ extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio // On-Board Raspberry Pi hardware specific stuff extern int piGpioLayout (void) ; +extern int piBoardRev (void) ; // Deprecated extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; extern int wpiPinToGpio (int wpiPin) ; extern int physPinToGpio (int physPin) ; diff --git a/wiringPi/wiringSerial.c b/wiringPi/wiringSerial.c index 09aeb35..e1587ad 100644 --- a/wiringPi/wiringSerial.c +++ b/wiringPi/wiringSerial.c @@ -60,6 +60,7 @@ int serialOpen (const char *device, const int baud) case 1200: myBaud = B1200 ; break ; case 1800: myBaud = B1800 ; break ; case 2400: myBaud = B2400 ; break ; + case 4800: myBaud = B4800 ; break ; case 9600: myBaud = B9600 ; break ; case 19200: myBaud = B19200 ; break ; case 38400: myBaud = B38400 ; break ; diff --git a/wiringPi/wpiExtensions.c b/wiringPi/wpiExtensions.c index 96852b7..2761945 100644 --- a/wiringPi/wpiExtensions.c +++ b/wiringPi/wpiExtensions.c @@ -439,10 +439,9 @@ static int doExtensionPcf8591 (char *progName, int pinBase, char *params) ********************************************************************************* */ -static int doExtensionPseudoPins (char *progName, int pinBase, char *params) +static int doExtensionPseudoPins (UNU char *progName, int pinBase, UNU char *params) { pseudoPinsSetup (pinBase) ; -printf ("pseudoPins: %d\n", pinBase) ; return TRUE ; } @@ -455,7 +454,7 @@ printf ("pseudoPins: %d\n", pinBase) ; ********************************************************************************* */ -static int doExtensionBmp180 (char *progName, int pinBase, char *params) +static int doExtensionBmp180 (UNU char *progName, int pinBase, UNU char *params) { bmp180Setup (pinBase) ; @@ -470,7 +469,7 @@ static int doExtensionBmp180 (char *progName, int pinBase, char *params) ********************************************************************************* */ -static int doExtensionHtu21d (char *progName, int pinBase, char *params) +static int doExtensionHtu21d (UNU char *progName, int pinBase, UNU char *params) { htu21dSetup (pinBase) ; @@ -633,7 +632,7 @@ static int doExtensionMcp4802 (char *progName, int pinBase, char *params) ********************************************************************************* */ -static int doExtensionSn3218 (char *progName, int pinBase, char *params) +static int doExtensionSn3218 (UNU char *progName, int pinBase, UNU char *params) { sn3218Setup (pinBase) ; return TRUE ;