Updated mostly to the gpio readall command to support the Raspberry Pi B+

This commit is contained in:
Gordon Henderson
2014-07-14 08:39:38 +01:00
parent 0150b02478
commit dca8a19fb8
4 changed files with 176 additions and 50 deletions

View File

@@ -234,14 +234,16 @@ static void (*isrFunctions [64])(void) ;
// pinToGpio:
// Take a Wiring pin (0 through X) and re-map it to the BCM_GPIO pin
// Cope for 2 different board revisions here.
// Cope for 3 different board revisions here.
static int *pinToGpio ;
// Revision 1, 1.1:
static int pinToGpioR1 [64] =
{
17, 18, 21, 22, 23, 24, 25, 4, // From the Original Wiki - GPIO 0 through 7: wpi 0 - 7
0, 1, // I2C - SDA0, SCL0 wpi 8 - 9
0, 1, // I2C - SDA1, SCL1 wpi 8 - 9
8, 7, // SPI - CE1, CE0 wpi 10 - 11
10, 9, 11, // SPI - MOSI, MISO, SCLK wpi 12 - 14
14, 15, // UART - Tx, Rx wpi 15 - 16
@@ -253,6 +255,8 @@ static int pinToGpioR1 [64] =
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
} ;
// Revision 2:
static int pinToGpioR2 [64] =
{
17, 18, 27, 22, 23, 24, 25, 4, // From the Original Wiki - GPIO 0 through 7: wpi 0 - 7
@@ -260,11 +264,13 @@ static int pinToGpioR2 [64] =
8, 7, // SPI - CE1, CE0 wpi 10 - 11
10, 9, 11, // SPI - MOSI, MISO, SCLK wpi 12 - 14
14, 15, // UART - Tx, Rx wpi 15 - 16
28, 29, 30, 31, // New GPIOs 8 though 11 wpi 17 - 20
28, 29, 30, 31, // Rev 2: New GPIOs 8 though 11 wpi 17 - 20
5, 6, 13, 19, 26, // B+ wpi 21, 22, 23, 24, 25
12, 16, 20, 21, // B+ wpi 26, 27, 28, 29
0, 1, // B+ wpi 30, 31
// Padding:
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 31
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
} ;
@@ -316,16 +322,24 @@ static int physToGpioR2 [64] =
11, 8,
-1, 7, // 25, 26
// B+
0, 1,
5, -1,
6, 12,
13, -1,
19, 16,
26, 20,
-1, 21,
// the P5 connector on the Rev 2 boards:
-1, -1, -1, -1, -1, // ... 31
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
-1, -1, -1, -1, -1, -1, -1, // ... 47
-1, -1, -1, -1, -1, // ... 52
28, 29, 30, 31, // ... 53, 54, 55, 56 - P5
-1, -1, -1, -1, -1, -1, -1, // ... 63
} ;
// gpioToGPFSEL:
// Map a BCM_GPIO pin to it's Function Selection
// control port. (GPFSEL 0-5)
@@ -395,7 +409,7 @@ static uint8_t gpioToEDS [] =
} ;
// gpioToREN
// (Word) offset to the Rising edgde ENable register
// (Word) offset to the Rising edge ENable register
static uint8_t gpioToREN [] =
{
@@ -563,6 +577,7 @@ int wiringPiFailure (int fatal, const char *message, ...)
* 000d - Model B, Rev 2, 512MB, Egoman
* 000e - Model B, Rev 2, 512MB, Sony
* 000f - Model B, Rev 2, 512MB, Qisda
* 0010 - Model B+ 512MB, Sony
* 0011 - Pi compute Module
*
* A small thorn is the olde style overvolting - that will add in
@@ -655,6 +670,7 @@ const char *piModelNames [] =
{
"Model A",
"Model B",
"Model B+",
"Compute Module",
} ;
@@ -663,6 +679,7 @@ const char *piRevisionNames[] =
"1",
"1.1",
"2",
"1.2",
} ;
void piBoardId (int *model, int *rev, int *mem, char **maker)
@@ -721,7 +738,8 @@ void piBoardId (int *model, int *rev, int *mem, char **maker)
else if (strcmp (c, "000d") == 0) { *model = 1 ; *rev = 2 ; *mem = 512 ; *maker = "Egoman" ; }
else if (strcmp (c, "000e") == 0) { *model = 1 ; *rev = 2 ; *mem = 512 ; *maker = "Sony" ; }
else if (strcmp (c, "000f") == 0) { *model = 1 ; *rev = 2 ; *mem = 512 ; *maker = "Egoman" ; }
else if (strcmp (c, "0011") == 0) { *model = 2 ; *rev = 1 ; *mem = 512 ; *maker = "Sony" ; }
else if (strcmp (c, "0010") == 0) { *model = 2 ; *rev = 3 ; *mem = 512 ; *maker = "Sony" ; }
else if (strcmp (c, "0011") == 0) { *model = 3 ; *rev = 1 ; *mem = 512 ; *maker = "Sony" ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = "Unkn" ; }
}
@@ -1081,6 +1099,11 @@ void pinMode (int pin, int mode)
softPwmCreate (origPin, 0, 100) ;
else if (mode == SOFT_TONE_OUTPUT)
softToneCreate (origPin) ;
else if (mode == PWM_TONE_OUTPUT)
{
pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode
pwmSetMode (PWM_MODE_MS) ;
}
else if (mode == PWM_OUTPUT)
{
if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin
@@ -1306,6 +1329,28 @@ void analogWrite (int pin, int value)
}
/*
* pwmToneWrite:
* Pi Specific.
* Output the given frequency on the Pi's PWM pin
*********************************************************************************
*/
void pwmToneWrite (int pin, int freq)
{
int range ;
if (freq == 0)
pwmWrite (pin, 0) ; // Off
else
{
range = 600000 / freq ;
pwmSetRange (range) ;
pwmWrite (pin, freq / 2) ;
}
}
/*
* digitalWriteByte:
@@ -1670,12 +1715,12 @@ int wiringPiSetup (void)
boardRev = piBoardRev () ;
if (boardRev == 1)
/**/ if (boardRev == 1) // A, B, Rev 1, 1.1
{
pinToGpio = pinToGpioR1 ;
physToGpio = physToGpioR1 ;
}
else
else // A, B, Rev 2, B+, CM
{
pinToGpio = pinToGpioR2 ;
physToGpio = physToGpioR2 ;

View File

@@ -44,6 +44,7 @@
#define GPIO_CLOCK 3
#define SOFT_PWM_OUTPUT 4
#define SOFT_TONE_OUTPUT 5
#define PWM_TONE_OUTPUT 6
#define LOW 0
#define HIGH 1
@@ -70,7 +71,8 @@
#define PI_MODEL_A 0
#define PI_MODEL_B 1
#define PI_MODEL_CM 2
#define PI_MODEL_BPLUS 2
#define PI_MODEL_CM 3
// Threads
@@ -128,7 +130,6 @@ extern "C" {
extern const char *piModelNames [] ;
extern const char *piRevisionNames[] ;
extern const char *piComputeRevisionNames[] ;
// Internal
@@ -167,6 +168,7 @@ extern int wpiPinToGpio (int wpiPin) ;
extern int physPinToGpio (int physPin) ;
extern void setPadDrive (int group, int value) ;
extern int getAlt (int pin) ;
extern void pwmToneWrite (int pin, int freq) ;
extern void digitalWriteByte (int value) ;
extern void pwmSetMode (int mode) ;
extern void pwmSetRange (unsigned int range) ;