From 39663ba396094657cee64df5eec6f4bc2be64f11 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sat, 9 Mar 2024 14:11:06 +0100 Subject: [PATCH 1/5] #194 --- wiringPi/Makefile | 3 +- wiringPi/wiringPi.c | 92 +++++++++++++++++++++++------------------------ wiringPi/wiringPi.h | 2 +- wiringPi/wiringPiLegacy.c | 57 +++++++++++++++++++++++++++++ wiringPi/wiringPiLegacy.h | 2 ++ 5 files changed, 107 insertions(+), 49 deletions(-) create mode 100644 wiringPi/wiringPiLegacy.c create mode 100644 wiringPi/wiringPiLegacy.h diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 28501ec..88fc48e 100644 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -61,7 +61,8 @@ SRC = wiringPi.c \ bmp180.c htu21d.c ds18b20.c rht03.c \ drcSerial.c drcNet.c \ pseudoPins.c \ - wpiExtensions.c + wpiExtensions.c \ + wiringPiLegacy.c HEADERS = $(shell ls *.h) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index bbf1713..4581adb 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -70,12 +70,14 @@ #include #include #include +#include #include "softPwm.h" #include "softTone.h" #include "wiringPi.h" #include "../version.h" +#include "wiringPiLegacy.h" // Environment Variables @@ -874,7 +876,7 @@ static void usingGpioMemCheck (const char *what) ********************************************************************************* */ -static void piGpioLayoutOops (const char *why) +void piGpioLayoutOops (const char *why) { fprintf (stderr, "Oops: Unable to determine board revision from /proc/cpuinfo\n") ; fprintf (stderr, " -> %s\n", why) ; @@ -1006,7 +1008,7 @@ int piGpioLayout (void) gpioLayout = 2 ; // Covers everything else from the B revision 2 to the B+, the Pi v2, v3, zero and CM's. if (wiringPiDebug) - printf ("piGpioLayoutOops: Returning revision: %d\n", gpioLayout) ; + printf ("piGpioLayout: Returning revision: %d\n", gpioLayout) ; return gpioLayout ; } @@ -1023,6 +1025,36 @@ int piBoardRev (void) } +const char* revfile = "/proc/device-tree/system/linux,revision"; + + +const char* GetPiRevision(char* line, int linelength, unsigned int* revision) { + + const char* c = NULL; + uint32_t Revision = 0; + _Static_assert(sizeof(Revision)==4, "should be unsigend integer with 4 byte size"); + + FILE* fp = fopen(revfile,"rb"); + if (!fp) { + if (wiringPiDebug) + perror(revfile); + return NULL; // revision file not found or no access + } + int result = fread(&Revision, sizeof(Revision), 1, fp); + fclose(fp); + if (result<1) { + if (wiringPiDebug) + perror(revfile); + return NULL; // read error + } + Revision = bswap_32(Revision); + snprintf(line, linelength, "Revision\t: %x", Revision); + c = &line[11]; + *revision = Revision; + if (wiringPiDebug) + printf("GetPiRevision: Revision string: \"%s\" (%s) - 0x%x\n", line, c, *revision); + return c; +} /* * piBoardId: @@ -1093,10 +1125,10 @@ int piBoardRev (void) void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) { - FILE *cpuFd ; - char line [120] ; - char *c ; - unsigned int revision ; + const int maxlength = 120; + char line [maxlength+1] ; + const char *c ; + unsigned int revision = 0x00 ; int bRev, bType, bProc, bMfg, bMem, bWarranty ; // Will deal with the properly later on - for now, lets just get it going... @@ -1104,47 +1136,13 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) (void)piGpioLayout () ; // Call this first to make sure all's OK. Don't care about the result. - if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) - piGpioLayoutOops ("Unable to open /proc/cpuinfo") ; - - while (fgets (line, 120, cpuFd) != NULL) - if (strncmp (line, "Revision", 8) == 0) - break ; - - fclose (cpuFd) ; - - if (strncmp (line, "Revision", 8) != 0) - piGpioLayoutOops ("No \"Revision\" line") ; - -// Chomp trailing CR/NL - - for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) - *c = 0 ; - - if (wiringPiDebug) - printf ("piBoardId: Revision string: %s\n", line) ; - -// Need to work out if it's using the new or old encoding scheme: - -// Scan to the first character of the revision number - - for (c = line ; *c ; ++c) - if (*c == ':') - break ; - - if (*c != ':') - piGpioLayoutOops ("Bogus \"Revision\" line (no colon)") ; - -// Chomp spaces - - ++c ; - while (isspace (*c)) - ++c ; - - if (!isxdigit (*c)) - piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; - - revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x + c = GetPiRevision(line, maxlength, &revision); // device tree + if (NULL==c) { + c = GetPiRevisionLegacy(line, maxlength, &revision); // proc/cpuinfo + } + if (NULL==c) { + piGpioLayoutOops ("GetPiRevision failed!") ; + } // Check for new way: diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 94875b2..1c8c34d 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -195,7 +195,7 @@ extern "C" { // Data // Internal - +extern void piGpioLayoutOops (const char *why); extern int wiringPiFailure (int fatal, const char *message, ...) ; // Core wiringPi functions diff --git a/wiringPi/wiringPiLegacy.c b/wiringPi/wiringPiLegacy.c new file mode 100644 index 0000000..e83816b --- /dev/null +++ b/wiringPi/wiringPiLegacy.c @@ -0,0 +1,57 @@ + +#include +#include "wiringPiLegacy.h" +#include +#include +#include +#include + +extern int wiringPiDebug ; + +const char* GetPiRevisionLegacy(char* line, int linelength, unsigned int* revision) { + FILE *cpuFd ; + char *c = NULL; + + if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) + piGpioLayoutOops ("Unable to open /proc/cpuinfo") ; + + while (fgets (line, linelength, cpuFd) != NULL) + if (strncmp (line, "Revision", 8) == 0) + break ; + + fclose (cpuFd) ; + + if (strncmp (line, "Revision", 8) != 0) + piGpioLayoutOops ("No \"Revision\" line") ; + +// Chomp trailing CR/NL + + for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) + *c = 0 ; + + if (wiringPiDebug) + printf ("GetPiRevisionLegacy: Revision string: %s\n", line) ; + +// Need to work out if it's using the new or old encoding scheme: + +// Scan to the first character of the revision number + + for (c = line ; *c ; ++c) + if (*c == ':') + break ; + + if (*c != ':') + piGpioLayoutOops ("Bogus \"Revision\" line (no colon)") ; + +// Chomp spaces + + ++c ; + while (isspace (*c)) + ++c ; + + if (!isxdigit (*c)) + piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; + + *revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x + return c; +} \ No newline at end of file diff --git a/wiringPi/wiringPiLegacy.h b/wiringPi/wiringPiLegacy.h new file mode 100644 index 0000000..e6edc8b --- /dev/null +++ b/wiringPi/wiringPiLegacy.h @@ -0,0 +1,2 @@ + +const char* GetPiRevisionLegacy(char* line, int linelength, unsigned int* revision); \ No newline at end of file From 6590de3ef4365891cc9979aab5632674c3b9786d Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sat, 9 Mar 2024 19:29:42 +0100 Subject: [PATCH 2/5] #195 --- VERSION | 2 +- build | 7 +- debian-template/wiringPi/control_template | 3 +- gpio/gpio.c | 2 +- newVersion | 16 --- version.h | 4 +- wiringPi/wiringPi.c | 155 +++--------------------------- wiringPi/wiringPi.h | 4 +- wiringPi/wiringPiLegacy.c | 131 +++++++++++++++++++++++++ 9 files changed, 160 insertions(+), 164 deletions(-) diff --git a/VERSION b/VERSION index f398a20..8c50098 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0 \ No newline at end of file +3.1 diff --git a/build b/build index c993792..d898ec7 100755 --- a/build +++ b/build @@ -3,7 +3,7 @@ # build # Simple wiringPi build and install script # -# Copyright (c) 2012-2015 Gordon Henderson +# Copyright (c) 2012-2024 Gordon Henderson and contributors ################################################################################# # This file is part of wiringPi: # A "wiring" library for the Raspberry Pi @@ -83,11 +83,14 @@ fi # Only if you know what you're doing! if [ x$1 = "xdebian" ]; then + vMaj=`cut -d. -f1 VERSION` + vMin=`cut -d. -f2 VERSION` here=`pwd` deb_destdir=${here}/debian-template/wiringPi cd debian-template/wiringPi + export VERSION=$vMaj.$vMin export ARCH=$(dpkg-architecture -qDEB_HOST_ARCH) - echo architecture $ARCH + echo version:$VERSION architecture:$ARCH envsubst < control_template > DEBIAN/control rm -rf usr cd $here/wiringPi diff --git a/debian-template/wiringPi/control_template b/debian-template/wiringPi/control_template index 383b388..7a3cb99 100644 --- a/debian-template/wiringPi/control_template +++ b/debian-template/wiringPi/control_template @@ -1,5 +1,5 @@ Package: wiringpi -Version: 3.0 +Version: $VERSION Section: libraries Priority: optional Architecture: $ARCH @@ -11,3 +11,4 @@ Description: The wiringPi libraries, headers and gpio command programs as well as from the command-line Homepage: https://github.com/WiringPi/WiringPi Bugs: https://github.com/WiringPi/WiringPi/issues + diff --git a/gpio/gpio.c b/gpio/gpio.c index c4d698e..680305a 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -368,7 +368,7 @@ static void doUnLoad (int argc, char *argv []) static void doI2Cdetect (UNU int argc, char *argv []) { - int port = piGpioLayout () == 1 ? 0 : 1 ; + int port = piGpioLayout () == GPIO_LAYOUT_PI1_REV1 ? 0 : 1 ; char *c, *command ; if ((c = findExecutable (I2CDETECT)) == NULL) diff --git a/newVersion b/newVersion index b8cbef1..34eace3 100755 --- a/newVersion +++ b/newVersion @@ -32,19 +32,3 @@ 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 < -Uploaders: Grazer Computer Club - GC2 -Description: The wiringPi libraries, headers and gpio command - Libraries to allow GPIO access on a Raspberry Pi from C and C++ - and BASIC programs as well as from the command-line -Homepage: https://github.com/WiringPi/WiringPi/ -Bugs: https://github.com/WiringPi/WiringPi/ -EOF diff --git a/version.h b/version.h index 5ea9974..607fd6a 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.0" +#define VERSION "3.01" #define VERSION_MAJOR 3 -#define VERSION_MINOR 0 +#define VERSION_MINOR 01 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 4581adb..602c192 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -381,7 +381,8 @@ static int wiringPiMode = WPI_MODE_UNINITIALISED ; static volatile int pinPass = -1 ; static pthread_mutex_t pinMutex ; -static int RaspberryPiModel = -1; +static int RaspberryPiModel = -1; +static int RaspberryPiLayout = -1; // Debugging & Return codes @@ -880,137 +881,17 @@ void piGpioLayoutOops (const char *why) { fprintf (stderr, "Oops: Unable to determine board revision from /proc/cpuinfo\n") ; fprintf (stderr, " -> %s\n", why) ; - fprintf (stderr, " -> You'd best google the error to find out why.\n") ; -//fprintf (stderr, " -> http://www.raspberrypi.org/phpBB3/viewtopic.php?p=184410#p184410\n") ; + fprintf (stderr, " -> Check at https://github.com/wiringpi/wiringpi/issues.\n") ; exit (EXIT_FAILURE) ; } int piGpioLayout (void) { - FILE *cpuFd ; - char line [120] ; - char *c ; - static int gpioLayout = -1 ; - - if (gpioLayout != -1) // No point checking twice - return gpioLayout ; - - if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) - piGpioLayoutOops ("Unable to open /proc/cpuinfo") ; - -#ifdef DONT_CARE_ANYMORE -// Start by looking for the Architecture to make sure we're really running -// on a Pi. I'm getting fed-up with people whinging at me because -// they can't get it to work on weirdFruitPi boards... - while (fgets (line, 120, cpuFd) != NULL) - if (strncmp (line, "Hardware", 8) == 0) - break ; - - if (strncmp (line, "Hardware", 8) != 0) - piGpioLayoutOops ("No \"Hardware\" line") ; - - if (wiringPiDebug) - printf ("piGpioLayout: Hardware: %s\n", line) ; - -// See if it's BCM2708 or BCM2709 or the new BCM2835. - -// OK. As of Kernel 4.8, we have BCM2835 only, regardless of model. -// However I still want to check because it will trap the cheapskates and rip- -// off merchants who want to use wiringPi on non-Raspberry Pi platforms - which -// I do not support so don't email me your bleating whinges about anything -// other than a genuine Raspberry Pi. - - if (! (strstr (line, "BCM2708") || strstr (line, "BCM2709") || strstr (line, "BCM2835"))) - { - fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ; - fprintf (stderr, " - expecting BCM2708, BCM2709 or BCM2835.\n") ; - fprintf (stderr, "If this is a genuine Raspberry Pi then please report this\n") ; - fprintf (stderr, "at GitHub.com/wiringPi/wiringPi. If this is not a Raspberry Pi then you\n") ; - fprintf (stderr, "are on your own as wiringPi is designed to support the\n") ; - fprintf (stderr, "Raspberry Pi ONLY.\n") ; - exit (EXIT_FAILURE) ; + if (-1==RaspberryPiLayout) { + int model, rev, mem, maker, overVolted ; + piBoardId (&model, &rev, &mem, &maker, &overVolted) ; } - -// Actually... That has caused me more than 10,000 emails so-far. Mosty by -// people who think they know better by creating a statically linked -// version that will not run with a new 4.9 kernel. I utterly hate and -// despise those people. -// -// I also get bleats from people running other than Raspbian with another -// distros compiled kernel rather than a foundation compiled kernel, so -// this might actually help them. It might not - I only have the capacity -// to support Raspbian. -// -// However, I've decided to leave this check out and rely purely on the -// Revision: line for now. It will not work on a non-pi hardware or weird -// kernels that don't give you a suitable revision line. - -// So - we're Probably on a Raspberry Pi. Check the revision field for the real -// hardware type -// In-future, I ought to use the device tree as there are now Pi entries in -// /proc/device-tree/ ... -// but I'll leave that for the next revision. Or the next. -#endif - -// Isolate the Revision line - - rewind (cpuFd) ; - while (fgets (line, 120, cpuFd) != NULL) - if (strncmp (line, "Revision", 8) == 0) - break ; - - fclose (cpuFd) ; - - if (strncmp (line, "Revision", 8) != 0) - piGpioLayoutOops ("No \"Revision\" line") ; - -// Chomp trailing CR/NL - - for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) - *c = 0 ; - - if (wiringPiDebug) - printf ("piGpioLayout: Revision string: %s\n", line) ; - -// Scan to the first character of the revision number - - for (c = line ; *c ; ++c) - if (*c == ':') - break ; - - if (*c != ':') - piGpioLayoutOops ("Bogus \"Revision\" line (no colon)") ; - -// Chomp spaces - - ++c ; - while (isspace (*c)) - ++c ; - - if (!isxdigit (*c)) - piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; - -// Make sure its long enough - - if (strlen (c) < 4) - piGpioLayoutOops ("Bogus revision line (too small)") ; - -// Isolate last 4 characters: (in-case of overvolting or new encoding scheme) - - c = c + strlen (c) - 4 ; - - if (wiringPiDebug) - printf ("piGpioLayout: last4Chars are: \"%s\"\n", c) ; - - if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0)) - gpioLayout = 1 ; - else - gpioLayout = 2 ; // Covers everything else from the B revision 2 to the B+, the Pi v2, v3, zero and CM's. - - if (wiringPiDebug) - printf ("piGpioLayout: Returning revision: %d\n", gpioLayout) ; - - return gpioLayout ; + return RaspberryPiLayout; } /* @@ -1131,11 +1012,6 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) unsigned int revision = 0x00 ; int bRev, bType, bProc, bMfg, bMem, bWarranty ; -// Will deal with the properly later on - for now, lets just get it going... -// unsigned int modelNum ; - - (void)piGpioLayout () ; // Call this first to make sure all's OK. Don't care about the result. - c = GetPiRevision(line, maxlength, &revision); // device tree if (NULL==c) { c = GetPiRevisionLegacy(line, maxlength, &revision); // proc/cpuinfo @@ -1144,9 +1020,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) piGpioLayoutOops ("GetPiRevision failed!") ; } -// Check for new way: - - if ((revision & (1 << 23)) != 0) // New way + if ((revision & (1 << 23)) != 0) // New style, not available for Raspberry Pi 1B/A, CM { if (wiringPiDebug) printf ("piBoardId: New Way: revision is: %08X\n", revision) ; @@ -1164,6 +1038,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) *mem = bMem ; *maker = bMfg ; *warranty = bWarranty ; + RaspberryPiLayout = GPIO_LAYOUT_DEFAULT ; //default if (wiringPiDebug) printf ("piBoardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", @@ -1191,9 +1066,9 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) c = c + strlen (c) - 4 ; // Fill out the replys as appropriate - - /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } - else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } + RaspberryPiLayout = GPIO_LAYOUT_DEFAULT ; //default + /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; RaspberryPiLayout = GPIO_LAYOUT_PI1_REV1; } + else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; RaspberryPiLayout = GPIO_LAYOUT_PI1_REV1; } else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; } else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; } @@ -2598,7 +2473,7 @@ int wiringPiSetup (void) // but it will give us information like the GPIO layout scheme (2 variants // on the older 26-pin Pi's) and the GPIO peripheral base address. // and if we're running on a compute module, then wiringPi pin numbers -// don't really many anything, so force native BCM mode anyway. +// don't really mean anything, so force native BCM mode anyway. piBoardId (&model, &rev, &mem, &maker, &overVolted) ; @@ -2609,7 +2484,7 @@ int wiringPiSetup (void) else wiringPiMode = WPI_MODE_PINS ; - /**/ if (piGpioLayout () == 1) // A, B, Rev 1, 1.1 + /**/ if (piGpioLayout () == GPIO_LAYOUT_PI1_REV1) // A, B, Rev 1, 1.1 { pinToGpio = pinToGpioR1 ; physToGpio = physToGpioR1 ; @@ -2865,7 +2740,7 @@ int wiringPiSetupSys (void) int model, rev, mem, maker, overVolted ; piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if (piGpioLayout () == 1) + if (piGpioLayout () == GPIO_LAYOUT_PI1_REV1) { pinToGpio = pinToGpioR1 ; physToGpio = physToGpioR1 ; diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 1c8c34d..0212016 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -120,6 +120,8 @@ #define PI_MAKER_EMBEST 2 #define PI_MAKER_UNKNOWN 3 +#define GPIO_LAYOUT_PI1_REV1 1 //Pi 1 A/B Revision 1, 1.1, CM +#define GPIO_LAYOUT_DEFAULT 2 extern const char *piModelNames [24] ; extern const char *piProcessor [ 5] ; @@ -232,7 +234,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 int piBoardRev (void) ; // Deprecated, but does the same as piGpioLayout 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/wiringPiLegacy.c b/wiringPi/wiringPiLegacy.c index e83816b..faedd4e 100644 --- a/wiringPi/wiringPiLegacy.c +++ b/wiringPi/wiringPiLegacy.c @@ -54,4 +54,135 @@ const char* GetPiRevisionLegacy(char* line, int linelength, unsigned int* revisi *revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x return c; +} + + + +// useless +int piGpioLayoutLegacy (void) +{ + FILE *cpuFd ; + char line [120] ; + char *c ; + static int gpioLayout = -1 ; + + if (gpioLayout != -1) // No point checking twice + return gpioLayout ; + + if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) + piGpioLayoutOops ("Unable to open /proc/cpuinfo") ; + +#ifdef DONT_CARE_ANYMORE +// Start by looking for the Architecture to make sure we're really running +// on a Pi. I'm getting fed-up with people whinging at me because +// they can't get it to work on weirdFruitPi boards... + while (fgets (line, 120, cpuFd) != NULL) + if (strncmp (line, "Hardware", 8) == 0) + break ; + + if (strncmp (line, "Hardware", 8) != 0) + piGpioLayoutOops ("No \"Hardware\" line") ; + + if (wiringPiDebug) + printf ("piGpioLayout: Hardware: %s\n", line) ; + +// See if it's BCM2708 or BCM2709 or the new BCM2835. + +// OK. As of Kernel 4.8, we have BCM2835 only, regardless of model. +// However I still want to check because it will trap the cheapskates and rip- +// off merchants who want to use wiringPi on non-Raspberry Pi platforms - which +// I do not support so don't email me your bleating whinges about anything +// other than a genuine Raspberry Pi. + + if (! (strstr (line, "BCM2708") || strstr (line, "BCM2709") || strstr (line, "BCM2835"))) + { + fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ; + fprintf (stderr, " - expecting BCM2708, BCM2709 or BCM2835.\n") ; + fprintf (stderr, "If this is a genuine Raspberry Pi then please report this\n") ; + fprintf (stderr, "at GitHub.com/wiringPi/wiringPi. If this is not a Raspberry Pi then you\n") ; + fprintf (stderr, "are on your own as wiringPi is designed to support the\n") ; + fprintf (stderr, "Raspberry Pi ONLY.\n") ; + exit (EXIT_FAILURE) ; + } + +// Actually... That has caused me more than 10,000 emails so-far. Mosty by +// people who think they know better by creating a statically linked +// version that will not run with a new 4.9 kernel. I utterly hate and +// despise those people. +// +// I also get bleats from people running other than Raspbian with another +// distros compiled kernel rather than a foundation compiled kernel, so +// this might actually help them. It might not - I only have the capacity +// to support Raspbian. +// +// However, I've decided to leave this check out and rely purely on the +// Revision: line for now. It will not work on a non-pi hardware or weird +// kernels that don't give you a suitable revision line. + +// So - we're Probably on a Raspberry Pi. Check the revision field for the real +// hardware type +// In-future, I ought to use the device tree as there are now Pi entries in +// /proc/device-tree/ ... +// but I'll leave that for the next revision. Or the next. +#endif + +// Isolate the Revision line + + rewind (cpuFd) ; + while (fgets (line, 120, cpuFd) != NULL) + if (strncmp (line, "Revision", 8) == 0) + break ; + + fclose (cpuFd) ; + + if (strncmp (line, "Revision", 8) != 0) + piGpioLayoutOops ("No \"Revision\" line") ; + +// Chomp trailing CR/NL + + for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) + *c = 0 ; + + if (wiringPiDebug) + printf ("piGpioLayout: Revision string: %s\n", line) ; + +// Scan to the first character of the revision number + + for (c = line ; *c ; ++c) + if (*c == ':') + break ; + + if (*c != ':') + piGpioLayoutOops ("Bogus \"Revision\" line (no colon)") ; + +// Chomp spaces + + ++c ; + while (isspace (*c)) + ++c ; + + if (!isxdigit (*c)) + piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; + +// Make sure its long enough + + if (strlen (c) < 4) + piGpioLayoutOops ("Bogus revision line (too small)") ; + +// Isolate last 4 characters: (in-case of overvolting or new encoding scheme) + + c = c + strlen (c) - 4 ; + + if (wiringPiDebug) + printf ("piGpioLayout: last4Chars are: \"%s\"\n", c) ; + + if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0)) + gpioLayout = 1 ; + else + gpioLayout = 2 ; // Covers everything else from the B revision 2 to the B+, the Pi v2, v3, zero and CM's. + + if (wiringPiDebug) + printf ("piGpioLayout: Returning revision: %d\n", gpioLayout) ; + + return gpioLayout ; } \ No newline at end of file From 89dad15d12140564342360a14bf56d7aa272c3e0 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sat, 9 Mar 2024 19:32:12 +0100 Subject: [PATCH 3/5] reinstall script --- reinstall | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 reinstall diff --git a/reinstall b/reinstall new file mode 100755 index 0000000..cf20a0c --- /dev/null +++ b/reinstall @@ -0,0 +1,11 @@ +#!/bin/sh +vMaj=`cut -d. -f1 VERSION` +vMin=`cut -d. -f2 VERSION` +DEBVERSION=$vMaj.$vMin +sudo apt -y remove wiringpi +./build clean +./build debian +mv debian-template/wiringpi_${DEBVERSION}_armhf.deb . +sudo apt install ./wiringpi_${DEBVERSION}_armhf.deb + + From e0580814270c114848479b825852502efca2effc Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sat, 9 Mar 2024 20:59:24 +0100 Subject: [PATCH 4/5] #194 --- wiringPi/wiringPi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 602c192..28dfe61 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -929,7 +929,7 @@ const char* GetPiRevision(char* line, int linelength, unsigned int* revision) { return NULL; // read error } Revision = bswap_32(Revision); - snprintf(line, linelength, "Revision\t: %x", Revision); + snprintf(line, linelength, "Revision\t: %04x", Revision); c = &line[11]; *revision = Revision; if (wiringPiDebug) From 07cd89baa7148a8db0c05abf36d3b930ddb93a9c Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 10 Mar 2024 18:14:23 +0100 Subject: [PATCH 5/5] version 3.1 --- version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.h b/version.h index 607fd6a..5842f31 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.01" +#define VERSION "3.1" #define VERSION_MAJOR 3 -#define VERSION_MINOR 01 +#define VERSION_MINOR 1