Skip to content

Commit a0b52b3

Browse files
authored
Merge pull request WiringPi#284 from WiringPi/develop
Develop
2 parents 1d81e5c + c87aad7 commit a0b52b3

File tree

9 files changed

+64
-20
lines changed

9 files changed

+64
-20
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.8
1+
3.10

examples/clock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void drawClockHands (void)
6565
struct tm *now ;
6666
double angle, p, x0, y0, x1, y1 ;
6767
int h24, h, m, s ;
68-
char text [20] ;
68+
char text [40] ;
6969

7070
time (&t) ;
7171
now = localtime (&t) ;

examples/delayTest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main()
3737
int t ;
3838
int max, min ;
3939
int del ;
40-
int underRuns, overRuns, exactRuns, bogusRuns, total ;
40+
int underRuns, overRuns, exactRuns, total ;
4141
int descheds ;
4242

4343

examples/speed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int main (void)
9393
// character device ABI
9494

9595
printf ("\ncharacter device ABI method: (%8d iterations)\n", SLOW_COUNT) ;
96-
wiringPiSetupGpioDevice () ;
96+
wiringPiSetupGpioDevice (WPI_PIN_BCM) ;
9797
pinMode (17, OUTPUT) ;
9898
speedTest (17, SLOW_COUNT) ;
9999

gpio/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# A swiss-army knige of GPIO shenanigans.
55
# https://github.com/wiringPi/wiringPi
66
#
7-
# Copyright (c) 2012-2016 Gordon Henderson
7+
# Copyright (c) 2012-2024 Gordon Henderson and contributors
88
#################################################################################
99
# This file is part of wiringPi:
1010
# A "wiring" library for the Raspberry Pi
@@ -75,7 +75,7 @@ install: gpio
7575
$Q mkdir -p $(DESTDIR)$(PREFIX)/bin
7676
$Q cp gpio $(DESTDIR)$(PREFIX)/bin
7777
ifneq ($(WIRINGPI_SUID),0)
78-
$Q chown root.root $(DESTDIR)$(PREFIX)/bin/gpio
78+
$Q chown root:root $(DESTDIR)$(PREFIX)/bin/gpio
7979
$Q chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio
8080
endif
8181
$Q mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1

gpio/readall.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ static void doReadallExternal (void)
7575
*********************************************************************************
7676
*/
7777

78+
#define MAX_ALTS 11
7879
static const char unknown_alt[] = " - ";
79-
static const char *alts [] =
80+
static const char *alts [MAX_ALTS+1] =
8081
{
8182
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3", "ALT6", "ALT7", "ALT8", "ALT9"
8283
} ;
8384

8485

8586
static const char* GetAltString(int alt) {
8687

87-
if (alt>=0 && alt<=11) {
88+
if (alt>=0 && alt<=MAX_ALTS) {
8889
return alts[alt];
8990
}
9091

version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#define VERSION "3.8"
1+
#define VERSION "3.10"
22
#define VERSION_MAJOR 3
3-
#define VERSION_MINOR 8
3+
#define VERSION_MINOR 10

wiringPi/wiringPi.c

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,19 +1658,62 @@ void pinEnableED01Pi (int pin)
16581658
}
16591659
#endif
16601660

1661+
#define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
16611662

1662-
const char DEV_GPIO_PI[] ="/dev/gpiochip0";
1663-
const char DEV_GPIO_PI5[]="/dev/gpiochip4";
1663+
1664+
int OpenAndCheckGpioChip(int GPIONo, const char* label, const unsigned int lines) {
1665+
char szGPIOChip[30];
1666+
1667+
sprintf(szGPIOChip, "/dev/gpiochip%d", GPIONo);
1668+
int Fd = open(szGPIOChip, O_RDWR);
1669+
if (Fd < 0) {
1670+
fprintf(stderr, "wiringPi: ERROR: %s open ret=%d\n", szGPIOChip, Fd);
1671+
return Fd;
1672+
} else {
1673+
if (wiringPiDebug) {
1674+
printf("wiringPi: Open chip %s succeded, fd=%d\n", szGPIOChip, Fd) ;
1675+
}
1676+
struct gpiochip_info chipinfo;
1677+
ZeroMemory(&chipinfo, sizeof(chipinfo));
1678+
int ret = ioctl(Fd, GPIO_GET_CHIPINFO_IOCTL, &chipinfo);
1679+
if (0==ret) {
1680+
if (wiringPiDebug) {
1681+
printf("%s: name=%s, label=%s, lines=%u\n", szGPIOChip, chipinfo.name, chipinfo.label, chipinfo.lines) ;
1682+
}
1683+
int chipOK = 1;
1684+
if (label[0]!='\0' && NULL==strstr(chipinfo.label, label)) {
1685+
chipOK = 0;
1686+
}
1687+
if (lines>0 && chipinfo.lines!=lines) {
1688+
chipOK = 0;
1689+
}
1690+
if (chipOK) {
1691+
if (wiringPiDebug) {
1692+
printf("%s: valid, fd=%d\n", szGPIOChip, Fd);
1693+
}
1694+
} else {
1695+
if (wiringPiDebug) {
1696+
printf("%s: invalid, search for '%s' with %u lines!\n", szGPIOChip, label, lines) ;
1697+
}
1698+
close(Fd);
1699+
return -1; // invalid chip
1700+
}
1701+
}
1702+
}
1703+
return Fd;
1704+
}
16641705

16651706
int wiringPiGpioDeviceGetFd() {
16661707
if (chipFd<0) {
16671708
piBoard();
1668-
const char* gpiochip = PI_MODEL_5 == RaspberryPiModel ? DEV_GPIO_PI5 : DEV_GPIO_PI;
1669-
chipFd = open(gpiochip, O_RDWR);
1670-
if (chipFd < 0) {
1671-
fprintf(stderr, "wiringPi: ERROR: %s open ret=%d\n", gpiochip, chipFd);
1672-
} else if (wiringPiDebug) {
1673-
printf ("wiringPi: Open chip %s succeded, fd=%d\n", gpiochip, chipFd) ;
1709+
if (PI_MODEL_5 == RaspberryPiModel) {
1710+
chipFd = OpenAndCheckGpioChip(0, "rp1", 54); // /dev/gpiochip0 @ Pi5 since Kernel 6.6.47
1711+
if (chipFd<0) {
1712+
chipFd = OpenAndCheckGpioChip(4, "rp1", 54); // /dev/gpiochip4 @ Pi5 with older kernel
1713+
}
1714+
} else {
1715+
// not all Pis have same number of lines: Pi0, Pi1, Pi3, 54 lines, Pi4, 58 lines (CM ?), see #280, so this check is disabled
1716+
chipFd = OpenAndCheckGpioChip(0, "bcm", 0);
16741717
}
16751718
}
16761719
return chipFd;

wiringPiD/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# The wiringPiD utility:
44
# https://github.com/wiringPi/wiringPi
55
#
6-
# Copyright (c) 2012-2017 Gordon Henderson
6+
# Copyright (c) 2012-2024 Gordon Henderson and contributors
77
#################################################################################
88
# This file is part of wiringPi:
99
# A "wiring" library for the Raspberry Pi
@@ -70,7 +70,7 @@ install: wiringpid
7070
$Q echo "[Install]"
7171
$Q mkdir -p $(DESTDIR)$(PREFIX)/sbin
7272
$Q cp wiringpid $(DESTDIR)$(PREFIX)/sbin
73-
$Q chown root.root $(DESTDIR)$(PREFIX)/sbin/wiringpid
73+
$Q chown root:root $(DESTDIR)$(PREFIX)/sbin/wiringpid
7474

7575
# $Q mkdir -p $(DESTDIR)$(PREFIX)/man/man8
7676
# $Q cp gpio.1 $(DESTDIR)$(PREFIX)/man/man8

0 commit comments

Comments
 (0)