diff --git a/VERSION b/VERSION index cc1923a..c8cfe39 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.8 +3.10 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 ; 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) ; 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/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 b79a6e9..8ef452a 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.8" +#define VERSION "3.10" #define VERSION_MAJOR 3 -#define VERSION_MINOR 8 +#define VERSION_MINOR 10 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index eb2090e..bc00369 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1658,19 +1658,62 @@ 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) { + 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) ; + } + 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 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); } } return chipFd; 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