From 9044333c75fce395d32b814d58ab8344ef821398 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Fri, 3 May 2024 20:29:43 +0200 Subject: [PATCH] #231 --- wiringPi/wiringPi.c | 70 ++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 7d7b503..ec63b6f 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1110,6 +1110,37 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) } RaspberryPiModel = *model; + + switch (RaspberryPiModel){ + case PI_MODEL_A: + case PI_MODEL_B: + case PI_MODEL_AP: + case PI_MODEL_BP: + case PI_ALPHA: + case PI_MODEL_CM: + case PI_MODEL_ZERO: + case PI_MODEL_ZERO_W: + piGpioBase = GPIO_PERI_BASE_OLD ; + piGpioPupOffset = GPPUD ; + break ; + + case PI_MODEL_4B: + case PI_MODEL_400: + case PI_MODEL_CM4: + piGpioBase = GPIO_PERI_BASE_2711 ; + piGpioPupOffset = GPPUPPDN0 ; + break ; + + case PI_MODEL_5: + piGpioBase = GPIO_PERI_BASE_2712 ; + piGpioPupOffset = 0 ; + break ; + + default: + piGpioBase = GPIO_PERI_BASE_2835 ; + piGpioPupOffset = GPPUD ; + break ; + } } @@ -2731,7 +2762,7 @@ int wiringPiGlobalMemoryAccess(void) if (lgpio == MAP_FAILED) { returnvalue = 0; if (wiringPiDebug) - fprintf(stderr,"wiringPiGlobalMemoryAccess: mmap (GPIO) failed: %s\n", strerror (errno)) ; + fprintf(stderr,"wiringPiGlobalMemoryAccess: mmap (GPIO 0x%X,0x%X) failed: %s\n", BaseAddr, MMAP_size, strerror (errno)) ; } else { munmap(lgpio, MMAP_size); if (PI_MODEL_5 == RaspberryPiModel) { @@ -2742,7 +2773,7 @@ int wiringPiGlobalMemoryAccess(void) if (lpwm == MAP_FAILED) { returnvalue = 1; // only GPIO accessible if (wiringPiDebug) - fprintf(stderr,"wiringPiGlobalMemoryAccess: mmap (PWM) failed: %s\n", strerror (errno)) ; + fprintf(stderr,"wiringPiGlobalMemoryAccess: mmap (PWM 0x%X,0x%X) failed: %s\n", PWMAddr, MMAP_size, strerror (errno)) ; } else { returnvalue = 2; // GPIO & PWM accessible munmap(lpwm, BLOCK_SIZE); @@ -2812,40 +2843,6 @@ int wiringPiSetup (void) physToGpio = physToGpioR2 ; } -// ... - - switch (model) - { - case PI_MODEL_A: - case PI_MODEL_B: - case PI_MODEL_AP: - case PI_MODEL_BP: - case PI_ALPHA: - case PI_MODEL_CM: - case PI_MODEL_ZERO: - case PI_MODEL_ZERO_W: - piGpioBase = GPIO_PERI_BASE_OLD ; - piGpioPupOffset = GPPUD ; - break ; - - case PI_MODEL_4B: - case PI_MODEL_400: - case PI_MODEL_CM4: - piGpioBase = GPIO_PERI_BASE_2711 ; - piGpioPupOffset = GPPUPPDN0 ; - break ; - - case PI_MODEL_5: - piGpioBase = GPIO_PERI_BASE_2712 ; - piGpioPupOffset = 0 ; - break ; - - default: - piGpioBase = GPIO_PERI_BASE_2835 ; - piGpioPupOffset = GPPUD ; - break ; - } - // Open the master /dev/ memory control device // Device strategy: December 2016: // Try /dev/mem. If that fails, then @@ -2938,6 +2935,7 @@ int wiringPiSetup (void) _wiringPiPads = pads ; _wiringPiTimer = timer ; _wiringPiRio = NULL ; + } else { unsigned int MMAP_size = (usingGpioMem) ? gpiomem_RP1_Size : pciemem_RP1_Size; GPIO_PADS = (RP1_PADS0_Addr-RP1_IO0_Addr) ;