Browse Source

Merge pull request #70 from steveb/master

Add support for Raspberry Pi 4B
pull/71/head
Mark Liffiton 4 years ago
committed by GitHub
parent
commit
16a23e3688
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 34 deletions
  1. +1
    -1
      VERSION
  2. +5
    -2
      gpio/readall.c
  3. +2
    -2
      version.h
  4. +69
    -27
      wiringPi/wiringPi.c
  5. +3
    -2
      wiringPi/wiringPi.h

+ 1
- 1
VERSION View File

@@ -1 +1 @@
2.50
2.60

+ 5
- 2
gpio/readall.c View File

@@ -80,7 +80,7 @@ static char *alts [] =
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3" "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
} ; } ;


static int physToWpi [64] =
static int physToWpi [64] =
{ {
-1, // 0 -1, // 0
-1, -1, // 1, 2 -1, -1, // 1, 2
@@ -113,7 +113,7 @@ static int physToWpi [64] =
-1, -1, -1, -1, -1, -1, -1, -1, -1 -1, -1, -1, -1, -1, -1, -1, -1, -1
} ; } ;


static char *physNames [64] =
static char *physNames [64] =
{ {
NULL, NULL,


@@ -309,6 +309,8 @@ static void plus2header (int model)
printf (" +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+\n") ; printf (" +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_3AP) else if (model == PI_MODEL_3AP)
printf (" +-----+-----+---------+------+---+---Pi 3A+-+---+------+---------+-----+-----+\n") ; printf (" +-----+-----+---------+------+---+---Pi 3A+-+---+------+---------+-----+-----+\n") ;
else if (model == PI_MODEL_4B)
printf (" +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+\n") ;
else else
printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ; printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ;
} }
@@ -356,6 +358,7 @@ void doReadall (void)
(model == PI_MODEL_2) || (model == PI_MODEL_2) ||
(model == PI_MODEL_3AP) || (model == PI_MODEL_3AP) ||
(model == PI_MODEL_3B) || (model == PI_MODEL_3BP) || (model == PI_MODEL_3B) || (model == PI_MODEL_3BP) ||
(model == PI_MODEL_4B) ||
(model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W)) (model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W))
piPlusReadall (model) ; piPlusReadall (model) ;
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || ((model == PI_MODEL_CM3P))) else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || ((model == PI_MODEL_CM3P)))


+ 2
- 2
version.h View File

@@ -1,3 +1,3 @@
#define VERSION "2.50"
#define VERSION "2.60"
#define VERSION_MAJOR 2 #define VERSION_MAJOR 2
#define VERSION_MINOR 50
#define VERSION_MINOR 60

+ 69
- 27
wiringPi/wiringPi.c View File

@@ -213,8 +213,9 @@ volatile unsigned int *_wiringPiTimerIrqRaw ;
// piGpioBase: // piGpioBase:
// The base address of the GPIO memory mapped hardware IO // The base address of the GPIO memory mapped hardware IO


#define GPIO_PERI_BASE_OLD 0x20000000
#define GPIO_PERI_BASE_NEW 0x3F000000
#define GPIO_PERI_BASE_OLD 0x20000000
#define GPIO_PERI_BASE_2835 0x3F000000
#define GPIO_PERI_BASE_2711 0xFE000000


static volatile unsigned int piGpioBase = 0 ; static volatile unsigned int piGpioBase = 0 ;


@@ -237,7 +238,7 @@ const char *piModelNames [20] =
"Pi 3A+", // 14 "Pi 3A+", // 14
"Unknown15", // 15 "Unknown15", // 15
"CM3+", // 16 "CM3+", // 16
"Unknown17", // 17
"Pi 4B", // 17
"Unknown18", // 18 "Unknown18", // 18
"Unknown19", // 19 "Unknown19", // 19
} ; } ;
@@ -542,6 +543,14 @@ static uint8_t gpioToFEN [] =


#define GPPUD 37 #define GPPUD 37


/* 2711 has a different mechanism for pin pull-up/down/enable */
#define GPPUPPDN0 57 /* Pin pull-up/down for pins 15:0 */
#define GPPUPPDN1 58 /* Pin pull-up/down for pins 31:16 */
#define GPPUPPDN2 59 /* Pin pull-up/down for pins 47:32 */
#define GPPUPPDN3 60 /* Pin pull-up/down for pins 57:48 */

static volatile unsigned int piGpioPupOffset = 0 ;

// gpioToPUDCLK // gpioToPUDCLK
// (Word) offset to the Pull Up Down Clock regsiter // (Word) offset to the Pull Up Down Clock regsiter


@@ -818,7 +827,7 @@ int piGpioLayout (void)


for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ; *c = 0 ;
if (wiringPiDebug) if (wiringPiDebug)
printf ("piGpioLayout: Revision string: %s\n", line) ; printf ("piGpioLayout: Revision string: %s\n", line) ;


@@ -887,7 +896,7 @@ int piBoardRev (void)
* So the distinction between boards that I can see is: * So the distinction between boards that I can see is:
* *
* 0000 - Error * 0000 - Error
* 0001 - Not used
* 0001 - Not used
* *
* Original Pi boards: * Original Pi boards:
* 0002 - Model B, Rev 1, 256MB, Egoman * 0002 - Model B, Rev 1, 256MB, Egoman
@@ -972,7 +981,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)


for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ; *c = 0 ;
if (wiringPiDebug) if (wiringPiDebug)
printf ("piBoardId: Revision string: %s\n", line) ; printf ("piBoardId: Revision string: %s\n", line) ;


@@ -1011,7 +1020,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
bMfg = (revision & (0x0F << 16)) >> 16 ; bMfg = (revision & (0x0F << 16)) >> 16 ;
bMem = (revision & (0x07 << 20)) >> 20 ; bMem = (revision & (0x07 << 20)) >> 20 ;
bWarranty = (revision & (0x03 << 24)) != 0 ; bWarranty = (revision & (0x03 << 24)) != 0 ;
*model = bType ; *model = bType ;
*rev = bRev ; *rev = bRev ;
*mem = bMem ; *mem = bMem ;
@@ -1038,7 +1047,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
// If longer than 4, we'll assume it's been overvolted // If longer than 4, we'll assume it's been overvolted


*warranty = strlen (c) > 4 ; *warranty = strlen (c) > 4 ;
// Extract last 4 characters: // Extract last 4 characters:


c = c + strlen (c) - 4 ; c = c + strlen (c) - 4 ;
@@ -1078,7 +1087,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; } else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
} }
} }




/* /*
@@ -1264,7 +1273,7 @@ void gpioClockSet (int pin, int freq)
pin = physToGpio [pin] ; pin = physToGpio [pin] ;
else if (wiringPiMode != WPI_MODE_GPIO) else if (wiringPiMode != WPI_MODE_GPIO)
return ; return ;
divi = 19200000 / freq ; divi = 19200000 / freq ;
divr = 19200000 % freq ; divr = 19200000 % freq ;
divf = (int)((double)divr * 4096.0 / 19200000.0) ; divf = (int)((double)divr * 4096.0 / 19200000.0) ;
@@ -1508,11 +1517,36 @@ void pullUpDnControl (int pin, int pud)
else if (wiringPiMode != WPI_MODE_GPIO) else if (wiringPiMode != WPI_MODE_GPIO)
return ; return ;


*(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ;
*(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ;
*(gpio + GPPUD) = 0 ; delayMicroseconds (5) ;
*(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ;
if (piGpioPupOffset == GPPUPPDN0)
{
// Pi 4B pull up/down method
int pullreg = GPPUPPDN0 + (pin>>4);
int pullshift = (pin & 0xf) << 1;
unsigned int pullbits;
unsigned int pull;

switch (pud)
{
case PUD_OFF: pull = 0; break;
case PUD_UP: pull = 1; break;
case PUD_DOWN: pull = 2; break;
default: return ; /* An illegal value */
}

pullbits = *(gpio + pullreg);
pullbits &= ~(3 << pullshift);
pullbits |= (pull << pullshift);
*(gpio + pullreg) = pullbits;
}
else
{
// legacy pull up/down method
*(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ;
*(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ;

*(gpio + GPPUD) = 0 ; delayMicroseconds (5) ;
*(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ;
}
} }
else // Extension module else // Extension module
{ {
@@ -1533,7 +1567,6 @@ int digitalRead (int pin)
{ {
char c ; char c ;
struct wiringPiNodeStruct *node = wiringPiNodes ; struct wiringPiNodeStruct *node = wiringPiNodes ;

if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
{ {
/**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
@@ -1684,7 +1717,7 @@ void pwmWrite (int pin, int value)


/* /*
* analogRead: * analogRead:
* Read the analog value of a given Pin.
* Read the analog value of a given Pin.
* There is no on-board Pi analog hardware, * There is no on-board Pi analog hardware,
* so this needs to go to a new node. * so this needs to go to a new node.
********************************************************************************* *********************************************************************************
@@ -1703,7 +1736,7 @@ int analogRead (int pin)


/* /*
* analogWrite: * analogWrite:
* Write the analog value to the given Pin.
* Write the analog value to the given Pin.
* There is no on-board Pi analog hardware, * There is no on-board Pi analog hardware,
* so this needs to go to a new node. * so this needs to go to a new node.
********************************************************************************* *********************************************************************************
@@ -1752,7 +1785,7 @@ void pwmToneWrite (int pin, int freq)
* Write an 8-bit byte to the first 8 GPIO pins - try to do it as * Write an 8-bit byte to the first 8 GPIO pins - try to do it as
* fast as possible. * fast as possible.
* However it still needs 2 operations to set the bits, so any external * However it still needs 2 operations to set the bits, so any external
* hardware must not rely on seeing a change as there will be a change
* hardware must not rely on seeing a change as there will be a change
* to set the outputs bits to zero, then another change to set the 1's * to set the outputs bits to zero, then another change to set the 1's
* Reading is just bit fiddling. * Reading is just bit fiddling.
* These are wiringPi pin numbers 0..7, or BCM_GPIO pin numbers * These are wiringPi pin numbers 0..7, or BCM_GPIO pin numbers
@@ -1808,7 +1841,7 @@ unsigned int digitalReadByte (void)
data = (data << 1) | x ; data = (data << 1) | x ;
} }
} }
else
else
{ {
raw = *(gpio + gpioToGPLEV [0]) ; // First bank for these pins raw = *(gpio + gpioToGPLEV [0]) ; // First bank for these pins
for (pin = 0 ; pin < 8 ; ++pin) for (pin = 0 ; pin < 8 ; ++pin)
@@ -1865,7 +1898,7 @@ unsigned int digitalReadByte2 (void)
data = (data << 1) | x ; data = (data << 1) | x ;
} }
} }
else
else
data = ((*(gpio + gpioToGPLEV [0])) >> 20) & 0xFF ; // First bank for these pins data = ((*(gpio + gpioToGPLEV [0])) >> 20) & 0xFF ; // First bank for these pins


return data ; return data ;
@@ -2243,7 +2276,9 @@ int wiringPiSetup (void)


piBoardId (&model, &rev, &mem, &maker, &overVolted) ; piBoardId (&model, &rev, &mem, &maker, &overVolted) ;


if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || (model == PI_MODEL_CM3P))
if ((model == PI_MODEL_CM) ||
(model == PI_MODEL_CM3) ||
(model == PI_MODEL_CM3P))
wiringPiMode = WPI_MODE_GPIO ; wiringPiMode = WPI_MODE_GPIO ;
else else
wiringPiMode = WPI_MODE_PINS ; wiringPiMode = WPI_MODE_PINS ;
@@ -2268,16 +2303,23 @@ int wiringPiSetup (void)
case PI_ALPHA: case PI_MODEL_CM: case PI_ALPHA: case PI_MODEL_CM:
case PI_MODEL_ZERO: case PI_MODEL_ZERO_W: case PI_MODEL_ZERO: case PI_MODEL_ZERO_W:
piGpioBase = GPIO_PERI_BASE_OLD ; piGpioBase = GPIO_PERI_BASE_OLD ;
piGpioPupOffset = GPPUD ;
break ;

case PI_MODEL_4B:
piGpioBase = GPIO_PERI_BASE_2711 ;
piGpioPupOffset = GPPUPPDN0 ;
break ; break ;


default: default:
piGpioBase = GPIO_PERI_BASE_NEW ;
piGpioBase = GPIO_PERI_BASE_2835 ;
piGpioPupOffset = GPPUD ;
break ; break ;
} }


// Open the master /dev/ memory control device // Open the master /dev/ memory control device
// Device strategy: December 2016: // Device strategy: December 2016:
// Try /dev/mem. If that fails, then
// Try /dev/mem. If that fails, then
// try /dev/gpiomem. If that fails then game over. // try /dev/gpiomem. If that fails then game over.


if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC)) < 0) if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC)) < 0)
@@ -2315,13 +2357,13 @@ int wiringPiSetup (void)
pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
if (pwm == MAP_FAILED) if (pwm == MAP_FAILED)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ;
// Clock control (needed for PWM) // Clock control (needed for PWM)


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


pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ; pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;
@@ -2441,7 +2483,7 @@ int wiringPiSetupSys (void)


// Open and scan the directory, looking for exported GPIOs, and pre-open // Open and scan the directory, looking for exported GPIOs, and pre-open
// the 'value' interface to speed things up for later // the 'value' interface to speed things up for later
for (pin = 0 ; pin < 64 ; ++pin) for (pin = 0 ; pin < 64 ; ++pin)
{ {
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;


+ 3
- 2
wiringPi/wiringPi.h View File

@@ -102,6 +102,7 @@
#define PI_MODEL_3BP 13 #define PI_MODEL_3BP 13
#define PI_MODEL_3AP 14 #define PI_MODEL_3AP 14
#define PI_MODEL_CM3P 16 #define PI_MODEL_CM3P 16
#define PI_MODEL_4B 17


#define PI_VERSION_1 0 #define PI_VERSION_1 0
#define PI_VERSION_1_1 1 #define PI_VERSION_1_1 1
@@ -134,7 +135,7 @@ extern const int piMemorySize [ 8] ;
// wiringPiNodeStruct: // wiringPiNodeStruct:
// This describes additional device nodes in the extended wiringPi // This describes additional device nodes in the extended wiringPi
// 2.0 scheme of things. // 2.0 scheme of things.
// It's a simple linked list for now, but will hopefully migrate to
// It's a simple linked list for now, but will hopefully migrate to
// a binary tree for efficiency reasons - but then again, the chances // a binary tree for efficiency reasons - but then again, the chances
// of more than 1 or 2 devices being added are fairly slim, so who // of more than 1 or 2 devices being added are fairly slim, so who
// knows.... // knows....
@@ -211,7 +212,7 @@ extern void pwmWrite (int pin, int value) ;
extern int analogRead (int pin) ; extern int analogRead (int pin) ;
extern void analogWrite (int pin, int value) ; extern void analogWrite (int pin, int value) ;


// PiFace specifics
// PiFace specifics
// (Deprecated) // (Deprecated)


extern int wiringPiSetupPiFace (void) ; extern int wiringPiSetupPiFace (void) ;


Loading…
Cancel
Save