From 8fc6b40656281e1c6b8da463f8a2e2a41f53b981 Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Mon, 2 Sep 2024 15:16:06 -0400 Subject: [PATCH 1/5] Fix issue with speed example - does not compile on master branch --- examples/speed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/speed.c b/examples/speed.c index 19b2b06..23a3a50 100644 --- a/examples/speed.c +++ b/examples/speed.c @@ -93,7 +93,7 @@ int main (void) // character device ABI printf ("\ncharacter device ABI method: (%8d iterations)\n", SLOW_COUNT) ; - wiringPiSetupGpioDevice () ; + wiringPiSetupGpioDevice (WPI_PIN_BCM) ; pinMode (17, OUTPUT) ; speedTest (17, SLOW_COUNT) ; From ed871f258acb86984c81f15baa59f4de9eee4fcc Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 8 Sep 2024 18:54:58 +0200 Subject: [PATCH 2/5] #279 root.root -> root:root --- VERSION | 2 +- gpio/Makefile | 4 ++-- version.h | 4 ++-- wiringPiD/Makefile | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index cc1923a..bd28b9c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.8 +3.9 diff --git a/gpio/Makefile b/gpio/Makefile index 249bb24..bc0829f 100644 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -4,7 +4,7 @@ # A swiss-army knige of GPIO shenanigans. # https://github.com/wiringPi/wiringPi # -# Copyright (c) 2012-2016 Gordon Henderson +# Copyright (c) 2012-2024 Gordon Henderson and contributors ################################################################################# # This file is part of wiringPi: # A "wiring" library for the Raspberry Pi @@ -75,7 +75,7 @@ install: gpio $Q mkdir -p $(DESTDIR)$(PREFIX)/bin $Q cp gpio $(DESTDIR)$(PREFIX)/bin ifneq ($(WIRINGPI_SUID),0) - $Q chown root.root $(DESTDIR)$(PREFIX)/bin/gpio + $Q chown root:root $(DESTDIR)$(PREFIX)/bin/gpio $Q chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio endif $Q mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1 diff --git a/version.h b/version.h index b79a6e9..3daf967 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.8" +#define VERSION "3.9" #define VERSION_MAJOR 3 -#define VERSION_MINOR 8 +#define VERSION_MINOR 9 diff --git a/wiringPiD/Makefile b/wiringPiD/Makefile index d7ebec8..6226b2e 100644 --- a/wiringPiD/Makefile +++ b/wiringPiD/Makefile @@ -3,7 +3,7 @@ # The wiringPiD utility: # https://github.com/wiringPi/wiringPi # -# Copyright (c) 2012-2017 Gordon Henderson +# Copyright (c) 2012-2024 Gordon Henderson and contributors ################################################################################# # This file is part of wiringPi: # A "wiring" library for the Raspberry Pi @@ -70,7 +70,7 @@ install: wiringpid $Q echo "[Install]" $Q mkdir -p $(DESTDIR)$(PREFIX)/sbin $Q cp wiringpid $(DESTDIR)$(PREFIX)/sbin - $Q chown root.root $(DESTDIR)$(PREFIX)/sbin/wiringpid + $Q chown root:root $(DESTDIR)$(PREFIX)/sbin/wiringpid # $Q mkdir -p $(DESTDIR)$(PREFIX)/man/man8 # $Q cp gpio.1 $(DESTDIR)$(PREFIX)/man/man8 From d8487da522f6f200bdf05a3ef212ef0ff6879da8 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 8 Sep 2024 19:11:49 +0200 Subject: [PATCH 3/5] #282 compiler warnings --- examples/clock.c | 2 +- examples/delayTest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/clock.c b/examples/clock.c index 5ca98fd..a6b6567 100644 --- a/examples/clock.c +++ b/examples/clock.c @@ -65,7 +65,7 @@ void drawClockHands (void) struct tm *now ; double angle, p, x0, y0, x1, y1 ; int h24, h, m, s ; - char text [20] ; + char text [40] ; time (&t) ; now = localtime (&t) ; diff --git a/examples/delayTest.c b/examples/delayTest.c index 16245c3..af74e9f 100644 --- a/examples/delayTest.c +++ b/examples/delayTest.c @@ -37,7 +37,7 @@ int main() int t ; int max, min ; int del ; - int underRuns, overRuns, exactRuns, bogusRuns, total ; + int underRuns, overRuns, exactRuns, total ; int descheds ; From b6bc43b562ee58cd08fd240875a31c81c8e50174 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 8 Sep 2024 20:46:10 +0200 Subject: [PATCH 4/5] #280 gpiochip0 and optional gpiochip4 with Pi5 --- wiringPi/wiringPi.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index eb2090e..ae4656b 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1658,19 +1658,60 @@ void pinEnableED01Pi (int pin) } #endif +#define ZeroMemory(Destination,Length) memset((Destination),0,(Length)) -const char DEV_GPIO_PI[] ="/dev/gpiochip0"; -const char DEV_GPIO_PI5[]="/dev/gpiochip4"; + +int OpenAndCheckGpioChip(int GPIONo, const char* label, const unsigned int lines) { + char szGPIOChip[30]; + + sprintf(szGPIOChip, "/dev/gpiochip%d", GPIONo); + int Fd = open(szGPIOChip, O_RDWR); + if (Fd < 0) { + fprintf(stderr, "wiringPi: ERROR: %s open ret=%d\n", szGPIOChip, Fd); + return Fd; + } else { + if (wiringPiDebug) { + printf ("wiringPi: Open chip %s succeded, fd=%d\n", szGPIOChip, Fd) ; + } + struct gpiochip_info chipinfo; + ZeroMemory(&chipinfo, sizeof(chipinfo)); + int ret = ioctl(Fd, GPIO_GET_CHIPINFO_IOCTL, &chipinfo); + if (0==ret) { + if (wiringPiDebug) { + printf ("%s: name=%s, label=%s, lines=%u\n", szGPIOChip, chipinfo.name, chipinfo.label, chipinfo.lines) ; + } + int chipOK = 1; + if (label[0]!='\0' && NULL==strstr(chipinfo.label, label)) { + chipOK = 0; + } + if (lines>0 && chipinfo.lines!=lines) { + chipOK = 0; + } + if (chipOK) { + printf ("%s: valid, fd=%d\n", szGPIOChip, Fd); + } else { + if (wiringPiDebug) { + printf ("%s: invalid, search for '%s' with %u lines!\n", szGPIOChip, label, lines) ; + } + close(Fd); + return -1; // invalid chip + } + } + } + return Fd; +} int wiringPiGpioDeviceGetFd() { if (chipFd<0) { piBoard(); - const char* gpiochip = PI_MODEL_5 == RaspberryPiModel ? DEV_GPIO_PI5 : DEV_GPIO_PI; - chipFd = open(gpiochip, O_RDWR); - if (chipFd < 0) { - fprintf(stderr, "wiringPi: ERROR: %s open ret=%d\n", gpiochip, chipFd); - } else if (wiringPiDebug) { - printf ("wiringPi: Open chip %s succeded, fd=%d\n", gpiochip, chipFd) ; + if (PI_MODEL_5 == RaspberryPiModel) { + chipFd = OpenAndCheckGpioChip(0, "rp1", 54); // /dev/gpiochip0 @ Pi5 since Kernel 6.6.47 + if (chipFd<0) { + chipFd = OpenAndCheckGpioChip(4, "rp1", 54); // /dev/gpiochip4 @ Pi5 with older kernel + } + } else { + // not sure if all Pis have 54 lines (Pi1v1, Pi1v2 and CM ?), so this check is disabled + chipFd = OpenAndCheckGpioChip(0, "bcm", 0); } } return chipFd; From 9e7c71f67d58013dc0e08a8c50cdbb8d1c0624a0 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Mon, 9 Sep 2024 14:49:15 +0200 Subject: [PATCH 5/5] #280 --- VERSION | 2 +- gpio/readall.c | 5 +++-- version.h | 4 ++-- wiringPi/wiringPi.c | 12 +++++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/VERSION b/VERSION index bd28b9c..c8cfe39 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.9 +3.10 diff --git a/gpio/readall.c b/gpio/readall.c index c28f7fe..8d2ffba 100644 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -75,8 +75,9 @@ static void doReadallExternal (void) ********************************************************************************* */ +#define MAX_ALTS 11 static const char unknown_alt[] = " - "; -static const char *alts [] = +static const char *alts [MAX_ALTS+1] = { "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3", "ALT6", "ALT7", "ALT8", "ALT9" } ; @@ -84,7 +85,7 @@ static const char *alts [] = static const char* GetAltString(int alt) { - if (alt>=0 && alt<=11) { + if (alt>=0 && alt<=MAX_ALTS) { return alts[alt]; } diff --git a/version.h b/version.h index 3daf967..8ef452a 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.9" +#define VERSION "3.10" #define VERSION_MAJOR 3 -#define VERSION_MINOR 9 +#define VERSION_MINOR 10 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index ae4656b..bc00369 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1671,14 +1671,14 @@ int OpenAndCheckGpioChip(int GPIONo, const char* label, const unsigned int lines return Fd; } else { if (wiringPiDebug) { - printf ("wiringPi: Open chip %s succeded, fd=%d\n", szGPIOChip, Fd) ; + printf("wiringPi: Open chip %s succeded, fd=%d\n", szGPIOChip, Fd) ; } struct gpiochip_info chipinfo; ZeroMemory(&chipinfo, sizeof(chipinfo)); int ret = ioctl(Fd, GPIO_GET_CHIPINFO_IOCTL, &chipinfo); if (0==ret) { if (wiringPiDebug) { - printf ("%s: name=%s, label=%s, lines=%u\n", szGPIOChip, chipinfo.name, chipinfo.label, chipinfo.lines) ; + printf("%s: name=%s, label=%s, lines=%u\n", szGPIOChip, chipinfo.name, chipinfo.label, chipinfo.lines) ; } int chipOK = 1; if (label[0]!='\0' && NULL==strstr(chipinfo.label, label)) { @@ -1688,10 +1688,12 @@ int OpenAndCheckGpioChip(int GPIONo, const char* label, const unsigned int lines chipOK = 0; } if (chipOK) { - printf ("%s: valid, fd=%d\n", szGPIOChip, Fd); + if (wiringPiDebug) { + printf("%s: valid, fd=%d\n", szGPIOChip, Fd); + } } else { if (wiringPiDebug) { - printf ("%s: invalid, search for '%s' with %u lines!\n", szGPIOChip, label, lines) ; + printf("%s: invalid, search for '%s' with %u lines!\n", szGPIOChip, label, lines) ; } close(Fd); return -1; // invalid chip @@ -1710,7 +1712,7 @@ int wiringPiGpioDeviceGetFd() { chipFd = OpenAndCheckGpioChip(4, "rp1", 54); // /dev/gpiochip4 @ Pi5 with older kernel } } else { - // not sure if all Pis have 54 lines (Pi1v1, Pi1v2 and CM ?), so this check is disabled + // not all Pis have same number of lines: Pi0, Pi1, Pi3, 54 lines, Pi4, 58 lines (CM ?), see #280, so this check is disabled chipFd = OpenAndCheckGpioChip(0, "bcm", 0); } }