#244 add API call getPinModeAlt
This commit is contained in:
@@ -10,6 +10,34 @@
|
||||
const int GPIO = 19;
|
||||
const int GPIOIN = 26;
|
||||
const int ToggleValue = 4;
|
||||
int RaspberryPiModel = -1;
|
||||
|
||||
|
||||
void SetAndCheckMode(int pin, int mode) {
|
||||
enum WPIPinALT AltGpio = WPI_ALT_UNKNOWN;
|
||||
|
||||
switch(mode) {
|
||||
case INPUT:
|
||||
pinMode(pin, INPUT);
|
||||
AltGpio = getPinModeAlt(pin);
|
||||
CheckSame("Pin mode input", AltGpio, WPI_ALT_INPUT);
|
||||
break;
|
||||
case OUTPUT:
|
||||
pinMode(pin, OUTPUT);
|
||||
AltGpio = getPinModeAlt(pin);
|
||||
CheckSame("Pin mode output", AltGpio, WPI_ALT_OUTPUT);
|
||||
break;
|
||||
case PM_OFF:
|
||||
pinMode(pin, PM_OFF);
|
||||
AltGpio = getPinModeAlt(pin);
|
||||
CheckSame("Pin mode off(input)", AltGpio, (PI_MODEL_5 == RaspberryPiModel) ? WPI_NONE : WPI_ALT_INPUT);
|
||||
break;
|
||||
default:
|
||||
pinMode(pin, mode);
|
||||
printf("pinmode %d of pin %d not checked", mode, pin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (void) {
|
||||
@@ -21,8 +49,23 @@ int main (void) {
|
||||
printf("wiringPiSetupGpio failed\n\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
pinMode(GPIOIN, INPUT);
|
||||
pinMode(GPIO, OUTPUT);
|
||||
|
||||
int rev, mem, maker, overVolted;
|
||||
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
|
||||
CheckNotSame("Model: ", RaspberryPiModel, -1);
|
||||
if (PI_MODEL_5 == RaspberryPiModel) {
|
||||
printf("Raspberry Pi 5 with RP1 found\n");
|
||||
} else {
|
||||
printf("Raspberry Pi with BCM GPIO found (not Pi 5)\n");
|
||||
}
|
||||
|
||||
|
||||
enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN;
|
||||
AltGpio = getPinModeAlt(23);
|
||||
CheckSame("Pin mode default", AltGpio, PI_MODEL_5 == RaspberryPiModel ? WPI_NONE : WPI_ALT_INPUT);
|
||||
|
||||
SetAndCheckMode(GPIOIN, INPUT);
|
||||
SetAndCheckMode(GPIO, OUTPUT);
|
||||
|
||||
printf("toggle %d times ...\n", ToggleValue);
|
||||
for (int loop=1; loop<ToggleValue; loop++) {
|
||||
@@ -36,7 +79,9 @@ int main (void) {
|
||||
|
||||
printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input))\n", GPIO, GPIOIN);
|
||||
pullUpDnControl (GPIO, PUD_UP);
|
||||
pinMode(GPIO, INPUT);
|
||||
SetAndCheckMode(GPIO, INPUT);
|
||||
|
||||
|
||||
delayMicroseconds(3000000);
|
||||
pullUpDnControl (GPIOIN, PUD_OFF);
|
||||
|
||||
@@ -50,6 +95,11 @@ int main (void) {
|
||||
//Error wrong direction - only for fun
|
||||
digitalWrite(GPIO, LOW);
|
||||
|
||||
return UnitTestState();
|
||||
}
|
||||
SetAndCheckMode(GPIO, OUTPUT);
|
||||
SetAndCheckMode(GPIO, PM_OFF);
|
||||
//pinModeAlt (GPIO, 0x1F);
|
||||
//AltGpio = getPinModeAlt(GPIO);
|
||||
//CheckSame("Pin mode off(default)", AltGpio, 0x1F);
|
||||
|
||||
return UnitTestState();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ void pullUpDnControlEx (int GPIO, int GPIOIN, int mode) {
|
||||
}
|
||||
|
||||
|
||||
void CheckSameText(const char* msg, const char* value, const char* expect) {
|
||||
if (!strcmp(value, expect)) {
|
||||
printf("%39s (%10s==%10s) -> %spassed%s\n", msg, value, expect, COLORGRN, COLORDEF);
|
||||
} else {
|
||||
printf("%39s (%10s<>%10s) -> %sfailed%s\n", msg, value, expect, COLORRED, COLORDEF);
|
||||
globalError=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CheckSame(const char* msg, int value, int expect) {
|
||||
if (value==expect) {
|
||||
printf("%39s (% 3d==% 3d) -> %spassed%s\n", msg, value, expect, COLORGRN, COLORDEF);
|
||||
@@ -70,6 +80,16 @@ void CheckSame(const char* msg, int value, int expect) {
|
||||
}
|
||||
|
||||
|
||||
void CheckNotSame(const char* msg, int value, int expect) {
|
||||
if (value!=expect) {
|
||||
printf("%39s (% 3d<>% 3d) -> %spassed%s\n", msg, value, expect, COLORGRN, COLORDEF);
|
||||
} else {
|
||||
printf("%39s (% 3d==% 3d) -> %sfailed%s\n", msg, value, expect, COLORRED, COLORDEF);
|
||||
globalError=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CheckSameFloat(const char* msg, float value, float expect) {
|
||||
if (fabs(value-expect)<0.08) {
|
||||
printf("%35s (%.3f==%.3f) -> %spassed%s \n", msg, value, expect, COLORGRN, COLORDEF);
|
||||
|
||||
@@ -156,8 +156,12 @@ const unsigned int RP1_DEBOUNCE_DEFAULT_VALUE = 4;
|
||||
const unsigned int RP1_DEBOUNCE_MASK = 0x7f;
|
||||
const unsigned int RP1_DEBOUNCE_DEFAULT = (RP1_DEBOUNCE_DEFAULT_VALUE << 5);
|
||||
|
||||
const unsigned int RP1_IRQRESET = 0x10000000; //CTRL Bit 28
|
||||
|
||||
const unsigned int RP1_PAD_DEFAULT_0TO8 = (0x0B | 0x70); //Slewfast, Schmitt, PullUp, | 12mA, Input enable
|
||||
const unsigned int RP1_PAD_DEFAULT_FROM9 = (0x07 | 0x70); //Slewfast, Schmitt, PullDown, | 12mA, Input enable
|
||||
const unsigned int RP1_PAD_IC_DEFAULT_0TO8 = 0x9A; //pull-up, Schmitt
|
||||
const unsigned int RP1_PAD_IC_DEFAULT_FROM9 = 0x96; //pull-down, Schmitt
|
||||
|
||||
const unsigned int RP1_PAD_DRIVE_MASK = 0x00000030;
|
||||
const unsigned int RP1_INV_PAD_DRIVE_MASK = ~(RP1_PAD_DRIVE_MASK);
|
||||
@@ -1314,6 +1318,11 @@ int getAlt (int pin)
|
||||
}
|
||||
|
||||
|
||||
enum WPIPinALT getPinModeAlt(int pin) {
|
||||
return (enum WPIPinALT) getAlt(pin);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* pwmSetMode:
|
||||
* Select the native "balanced" mode, or standard mark:space mode
|
||||
@@ -1727,11 +1736,16 @@ void pinMode (int pin, int mode)
|
||||
fSel = gpioToGPFSEL [pin] ;
|
||||
shift = gpioToShift [pin] ;
|
||||
|
||||
if (mode == INPUT) {
|
||||
if (INPUT==mode || PM_OFF==mode) {
|
||||
if (PI_MODEL_5 == RaspberryPiModel) {
|
||||
pads[1+pin] = (pin<=8) ? RP1_PAD_DEFAULT_0TO8 : RP1_PAD_DEFAULT_FROM9;
|
||||
gpio[2*pin+1] = RP1_FSEL_GPIO | RP1_DEBOUNCE_DEFAULT; // GPIO
|
||||
rio[RP1_RIO_OE + RP1_CLR_OFFSET] = 1<<pin; // Input
|
||||
if (INPUT==mode) {
|
||||
pads[1+pin] = (pin<=8) ? RP1_PAD_DEFAULT_0TO8 : RP1_PAD_DEFAULT_FROM9;
|
||||
gpio[2*pin+1] = RP1_FSEL_GPIO | RP1_DEBOUNCE_DEFAULT; // GPIO
|
||||
rio[RP1_RIO_OE + RP1_CLR_OFFSET] = 1<<pin; // Input
|
||||
} else { //PM_OFF
|
||||
pads[1+pin] = (pin<=8) ? RP1_PAD_IC_DEFAULT_0TO8 : RP1_PAD_IC_DEFAULT_FROM9;
|
||||
gpio[2*pin+1] = RP1_IRQRESET | RP1_FSEL_NONE_HW | RP1_DEBOUNCE_DEFAULT; // default but with irq reset
|
||||
}
|
||||
} else {
|
||||
*(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) ; // Sets bits to zero = input
|
||||
}
|
||||
|
||||
@@ -225,8 +225,28 @@ extern int wiringPiSetupPhys (void) ;
|
||||
extern int wiringPiSetupPinType (enum WPIPinType pinType); //Interface V3.3
|
||||
extern int wiringPiSetupGpioDevice(enum WPIPinType pinType); //Interface V3.3
|
||||
|
||||
|
||||
enum WPIPinAlt {
|
||||
WPI_ALT_UNKNOWN = -1,
|
||||
WPI_ALT_INPUT = 0,
|
||||
WPI_ALT_OUTPUT,
|
||||
WPI_ALT5,
|
||||
WPI_ALT4,
|
||||
WPI_ALT0,
|
||||
WPI_ALT1,
|
||||
WPI_ALT2,
|
||||
WPI_ALT3,
|
||||
WPI_ALT6,
|
||||
WPI_ALT7,
|
||||
WPI_ALT8,
|
||||
WPI_ALT9,
|
||||
WPI_NONE = 0x1F, // Pi5 default
|
||||
};
|
||||
|
||||
|
||||
extern int wiringPiGpioDeviceGetFd(); //Interface V3.3
|
||||
extern void pinModeAlt (int pin, int mode) ;
|
||||
extern enum WPIPinAlt getPinModeAlt (int pin) ; // Interface V3.5, same as getAlt but wie enum
|
||||
extern void pinMode (int pin, int mode) ;
|
||||
extern void pullUpDnControl (int pin, int pud) ;
|
||||
extern int digitalRead (int pin) ;
|
||||
|
||||
Reference in New Issue
Block a user