Skip to content

Commit 6d5108e

Browse files
committed
1 parent c1f593c commit 6d5108e

File tree

2 files changed

+90
-39
lines changed

2 files changed

+90
-39
lines changed

wiringPi/wiringPi.c

+85-38
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ volatile unsigned int *_wiringPiTimerIrqRaw ;
219219

220220
static volatile unsigned int piGpioBase = 0 ;
221221

222-
const char *piModelNames [21] =
222+
const char *piModelNames [24] =
223223
{
224224
"Model A", // 0
225225
"Model B", // 1
@@ -242,6 +242,18 @@ const char *piModelNames [21] =
242242
"Pi Zero2-W", // 18
243243
"Pi 400", // 19
244244
"CM4", // 20
245+
"CM4S", // 21
246+
"Unknown22", // 22
247+
"Pi 5", // 23
248+
} ;
249+
250+
const char *piProcessor [5] =
251+
{
252+
"BCM2835",
253+
"BCM2836",
254+
"BCM2837",
255+
"BCM2711",
256+
"BCM2712",
245257
} ;
246258

247259
const char *piRevisionNames [16] =
@@ -269,9 +281,9 @@ const char *piMakerNames [16] =
269281
"Sony", // 0
270282
"Egoman", // 1
271283
"Embest", // 2
272-
"Unknown", // 3
284+
"Unknown",// 3
273285
"Embest", // 4
274-
"Unknown05", // 5
286+
"Stadium",// 5
275287
"Unknown06", // 6
276288
"Unknown07", // 7
277289
"Unknown08", // 8
@@ -306,6 +318,8 @@ static int wiringPiMode = WPI_MODE_UNINITIALISED ;
306318
static volatile int pinPass = -1 ;
307319
static pthread_mutex_t pinMutex ;
308320

321+
static int RaspberryPiModel = -1;
322+
309323
// Debugging & Return codes
310324

311325
int wiringPiDebug = FALSE ;
@@ -450,6 +464,8 @@ static int physToGpioR2 [64] =
450464
-1, -1,
451465
} ;
452466

467+
468+
453469
// gpioToGPFSEL:
454470
// Map a BCM_GPIO pin to it's Function Selection
455471
// control port. (GPFSEL 0-5)
@@ -1021,6 +1037,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
10211037
bMem = (revision & (0x07 << 20)) >> 20 ;
10221038
bWarranty = (revision & (0x03 << 24)) != 0 ;
10231039

1040+
// Ref: https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-revision-codes
10241041
*model = bType ;
10251042
*rev = bRev ;
10261043
*mem = bMem ;
@@ -1086,6 +1103,8 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
10861103

10871104
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
10881105
}
1106+
1107+
RaspberryPiModel = model;
10891108
}
10901109

10911110

@@ -2299,10 +2318,14 @@ int wiringPiSetup (void)
22992318

23002319
switch (model)
23012320
{
2302-
case PI_MODEL_A: case PI_MODEL_B:
2303-
case PI_MODEL_AP: case PI_MODEL_BP:
2304-
case PI_ALPHA: case PI_MODEL_CM:
2305-
case PI_MODEL_ZERO: case PI_MODEL_ZERO_W:
2321+
case PI_MODEL_A:
2322+
case PI_MODEL_B:
2323+
case PI_MODEL_AP:
2324+
case PI_MODEL_BP:
2325+
case PI_ALPHA:
2326+
case PI_MODEL_CM:
2327+
case PI_MODEL_ZERO:
2328+
case PI_MODEL_ZERO_W:
23062329
piGpioBase = GPIO_PERI_BASE_OLD ;
23072330
piGpioPupOffset = GPPUD ;
23082331
break ;
@@ -2338,8 +2361,14 @@ int wiringPiSetup (void)
23382361
" hardware then it most certianly won't work\n"
23392362
" Try running with sudo?\n", strerror (errno)) ;
23402363
}
2364+
}
23412365

2342-
// Set the offsets into the memory interface.
2366+
if (PI_MODEL_5 == model) {
2367+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Raspberry Pi 5 not supported.\n"
2368+
" Unable to continue. Keep an eye of new version at https://github.com/GrazerComputerClub/WiringPi\n") ;
2369+
}
2370+
2371+
//Set the offsets into the memory interface.
23432372

23442373
GPIO_PADS = piGpioBase + 0x00100000 ;
23452374
GPIO_CLOCK_BASE = piGpioBase + 0x00101000 ;
@@ -2350,50 +2379,60 @@ int wiringPiSetup (void)
23502379
// Map the individual hardware components
23512380

23522381
// GPIO:
2382+
if (PI_MODEL_5 != model) {
2383+
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ;
2384+
if (gpio == MAP_FAILED)
2385+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ;
23532386

2354-
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ;
2355-
if (gpio == MAP_FAILED)
2356-
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ;
2387+
// PWM
23572388

2358-
// PWM
2389+
pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
2390+
if (pwm == MAP_FAILED)
2391+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ;
23592392

2360-
pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
2361-
if (pwm == MAP_FAILED)
2362-
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ;
2393+
// Clock control (needed for PWM)
23632394

2364-
// Clock control (needed for PWM)
2395+
clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_CLOCK_BASE) ;
2396+
if (clk == MAP_FAILED)
2397+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ;
23652398

2366-
clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_CLOCK_BASE) ;
2367-
if (clk == MAP_FAILED)
2368-
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ;
2399+
// The drive pads
23692400

2370-
// The drive pads
2401+
pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;
2402+
if (pads == MAP_FAILED)
2403+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ;
23712404

2372-
pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;
2373-
if (pads == MAP_FAILED)
2374-
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ;
2405+
// The system timer
23752406

2376-
// The system timer
2407+
timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ;
2408+
if (timer == MAP_FAILED)
2409+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (TIMER) failed: %s\n", strerror (errno)) ;
23772410

2378-
timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ;
2379-
if (timer == MAP_FAILED)
2380-
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (TIMER) failed: %s\n", strerror (errno)) ;
2411+
// Set the timer to free-running, 1MHz.
2412+
// 0xF9 is 249, the timer divide is base clock / (divide+1)
2413+
// so base clock is 250MHz / 250 = 1MHz.
23812414

2382-
// Set the timer to free-running, 1MHz.
2383-
// 0xF9 is 249, the timer divide is base clock / (divide+1)
2384-
// so base clock is 250MHz / 250 = 1MHz.
2415+
*(timer + TIMER_CONTROL) = 0x0000280 ;
2416+
*(timer + TIMER_PRE_DIV) = 0x00000F9 ;
2417+
timerIrqRaw = timer + TIMER_IRQ_RAW ;
23852418

2386-
*(timer + TIMER_CONTROL) = 0x0000280 ;
2387-
*(timer + TIMER_PRE_DIV) = 0x00000F9 ;
2388-
timerIrqRaw = timer + TIMER_IRQ_RAW ;
2419+
_wiringPiGpio = gpio ;
2420+
_wiringPiPwm = pwm ;
2421+
_wiringPiClk = clk ;
2422+
_wiringPiPads = pads ;
2423+
_wiringPiTimer = timer ;
2424+
} else {
2425+
_wiringPiGpio = NULL ;
2426+
_wiringPiPwm = NULL ;
2427+
_wiringPiClk = NULL ;
2428+
_wiringPiPads = NULL ;
2429+
_wiringPiTimer = NULL ;
2430+
}
2431+
23892432

23902433
// Export the base addresses for any external software that might need them
23912434

2392-
_wiringPiGpio = gpio ;
2393-
_wiringPiPwm = pwm ;
2394-
_wiringPiClk = clk ;
2395-
_wiringPiPads = pads ;
2396-
_wiringPiTimer = timer ;
2435+
23972436

23982437
initialiseEpoch () ;
23992438

@@ -2473,6 +2512,9 @@ int wiringPiSetupSys (void)
24732512
if (wiringPiDebug)
24742513
printf ("wiringPi: wiringPiSetupSys called\n") ;
24752514

2515+
int model, rev, mem, maker, overVolted ;
2516+
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
2517+
24762518
if (piGpioLayout () == 1)
24772519
{
24782520
pinToGpio = pinToGpioR1 ;
@@ -2484,6 +2526,11 @@ int wiringPiSetupSys (void)
24842526
physToGpio = physToGpioR2 ;
24852527
}
24862528

2529+
if (PI_MODEL_5 == model) {
2530+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Raspberry Pi 5 not supported.\n"
2531+
" Unable to continue. Keep an eye of new version at https://github.com/GrazerComputerClub/WiringPi\n") ;
2532+
}
2533+
24872534
// Open and scan the directory, looking for exported GPIOs, and pre-open
24882535
// the 'value' interface to speed things up for later
24892536

wiringPi/wiringPi.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
#define PI_MODEL_ZERO_2W 18
108108
#define PI_MODEL_400 19
109109
#define PI_MODEL_CM4 20
110+
#define PI_MODEL_CM4S 21
111+
#define PI_MODEL_5 23
110112

111113
#define PI_VERSION_1 0
112114
#define PI_VERSION_1_1 1
@@ -118,7 +120,9 @@
118120
#define PI_MAKER_EMBEST 2
119121
#define PI_MAKER_UNKNOWN 3
120122

121-
extern const char *piModelNames [21] ;
123+
124+
extern const char *piModelNames [24] ;
125+
extern const char *piProcessor [ 5] ;
122126
extern const char *piRevisionNames [16] ;
123127
extern const char *piMakerNames [16] ;
124128
extern const int piMemorySize [ 8] ;

0 commit comments

Comments
 (0)