@@ -41,7 +41,7 @@ wiringpi_i2c_test1_pcf8574: | |||||
${CC} ${CFLAGS} wiringpi_i2c_test1_pcf8574.c -o wiringpi_i2c_test1_pcf8574 -lwiringPi | ${CC} ${CFLAGS} wiringpi_i2c_test1_pcf8574.c -o wiringpi_i2c_test1_pcf8574 -lwiringPi | ||||
wiringpi_piface_test1: | wiringpi_piface_test1: | ||||
${CC} ${CFLAGS} wiringpi_piface_test1.c -o wiringpi_piface_test1 -lwiringPi | |||||
${CC} ${CFLAGS} wiringpi_piface_test1.c -o wiringpi_piface_test1 -lwiringPi -lwiringPiDev | |||||
test: | test: | ||||
@error_state=false ; \ | @error_state=false ; \ | ||||
@@ -1,17 +1,130 @@ | |||||
#include "wpi_test.h" | |||||
#include "../../version.h" | |||||
// WiringPi piface program IN, OUT, PULL | |||||
// Compile: gcc -Wall wiringpi_piface_test1.c -o wiringpi_piface_test1 -lwiringPi -lwiringPiDev | |||||
// PiFace dummy | |||||
#include "wpi_test.h" | |||||
#include <piFace.h> | |||||
int main (void) { | |||||
int major, minor; | |||||
// Use 200 as the pin-base for the PiFace board, and change all pins | |||||
// for the LED and relays | |||||
const int PIFACE = 200; //Mapped wiringpi IO address | |||||
const int defaultsleep = 200000; // 200 ms | |||||
wiringPiVersion(&major, &minor); | |||||
printf("Testing piface functions with WiringPi %d.%d\n",major, minor); | |||||
printf("------------------------------------------\n\n"); | |||||
void ReadUntilTimeout(int GPIO, int expect, int timeoutSec) { | |||||
const int intervaluS = 250000; //250ms | |||||
int in; | |||||
const char* strexpect = expect ? "HIGH" : "LOW"; | |||||
for(int loop=0, end=(timeoutSec*1000000/intervaluS); loop<end; ++loop) { | |||||
in = digitalRead(GPIO); | |||||
if (in==expect) { | |||||
printf( "took %g sec to set %s\n", loop*intervaluS/1000000.0, strexpect); | |||||
break; | |||||
} | |||||
delayMicroseconds(intervaluS); | |||||
printf(".");fflush(stdout); | |||||
} | |||||
if (in!=expect) { | |||||
printf( "timeout reached %d sec to set %s\n", timeoutSec, strexpect); | |||||
} | |||||
CheckGPIO(GPIO, -1, expect) ; | |||||
} | |||||
int main (int argc, char *argv []) { | |||||
int major, minor; | |||||
wiringPiVersion(&major, &minor); | |||||
printf("Testing piface functions with WiringPi %d.%d\n",major, minor); | |||||
printf("------------------------------------------\n\n"); | |||||
// initialise wiringPi | |||||
if (wiringPiSetupSys() == -1) { | |||||
printf("wiringPiSetupSys failed\n\n"); | |||||
exit(EXIT_FAILURE); | |||||
} | |||||
piFaceSetup (PIFACE); // Setup the PiFace board with default addr 0, 0 | |||||
const int RELAY0 = PIFACE+0; | |||||
const int RELAY0IN = PIFACE+6; | |||||
const int RELAY1 = PIFACE+1; | |||||
const int RELAY1IN = PIFACE+7; | |||||
printf("\nRelays async:\n"); | |||||
for (int loop = 0, end=3 ; loop<end ; ++loop) { | |||||
int sleep = defaultsleep*(end-loop); | |||||
printf("sleep %d ms:\n", sleep/1000); | |||||
digitalWrite (RELAY0, HIGH); | |||||
delayMicroseconds(sleep); | |||||
CheckInversGPIO(RELAY0IN, -1, HIGH) ; | |||||
digitalWrite (RELAY0, LOW); | |||||
delayMicroseconds(sleep); | |||||
CheckInversGPIO(RELAY0IN, -1, LOW); | |||||
digitalWrite (RELAY1, HIGH); | |||||
delayMicroseconds(sleep); | |||||
CheckInversGPIO(RELAY1IN, -1, HIGH); | |||||
digitalWrite (RELAY1, LOW); | |||||
delayMicroseconds(sleep); | |||||
CheckInversGPIO(RELAY1IN, -1, LOW); | |||||
} | |||||
const int OUT7 = PIFACE+7; | |||||
const int OUT7IN = PIFACE+4; | |||||
const int OUT6 = PIFACE+6; | |||||
const int OUT6IN = PIFACE+5; | |||||
printf("\nOUT6/7 sync:\n"); | |||||
delayMicroseconds(defaultsleep); | |||||
for (int loop = 0, end=3 ; loop<end ; ++loop) { | |||||
digitalWrite (OUT7, HIGH); | |||||
delayMicroseconds(defaultsleep); | |||||
CheckInversGPIO(OUT7IN, -1, HIGH); | |||||
digitalWrite (OUT7, LOW); | |||||
delayMicroseconds(defaultsleep); | |||||
CheckInversGPIO(OUT7IN, -1, LOW); | |||||
digitalWrite (OUT6, HIGH); | |||||
delayMicroseconds(defaultsleep); | |||||
CheckInversGPIO(OUT6IN, -1, HIGH); | |||||
digitalWrite (OUT6, LOW); | |||||
delayMicroseconds(defaultsleep); | |||||
CheckInversGPIO(OUT6IN, -1, LOW); | |||||
} | |||||
printf("\nRelays sync:\n"); | |||||
for (int loop = 0, end=3 ; loop<end ; ++loop) { | |||||
int sleep = defaultsleep*(end-loop); | |||||
printf("sleep %d ms:\n", sleep/1000); | |||||
digitalWrite (RELAY0, HIGH); | |||||
digitalWrite (RELAY1, HIGH); | |||||
delayMicroseconds(sleep); | |||||
CheckInversGPIO(RELAY0IN, -1, HIGH) ; | |||||
CheckInversGPIO(RELAY1IN, -1, HIGH) ; | |||||
digitalWrite (RELAY0, LOW); | |||||
digitalWrite (RELAY1, LOW); | |||||
delayMicroseconds(sleep); | |||||
CheckInversGPIO(RELAY0IN, -1, LOW) ; | |||||
CheckInversGPIO(RELAY1IN, -1, LOW) ; | |||||
} | |||||
printf("\nInput pull up/down resistor:\n"); | |||||
for (int IN = 0 ; IN <= 7 ; ++IN) { | |||||
if (4==IN || 5==IN) { | |||||
continue; //4 & 5 connected from out to in -> test not possible | |||||
} | |||||
//6 & 7 connected from relais NO (normaly open) to in -> test possible | |||||
delayMicroseconds(defaultsleep); | |||||
pullUpDnControl (PIFACE + IN, PUD_UP) ; | |||||
ReadUntilTimeout(PIFACE + IN, HIGH, 2) ; | |||||
pullUpDnControl (PIFACE + IN, PUD_DOWN) ; | |||||
// cool down very slowly, connect 680 kOhm pull down resistor to make ist faster | |||||
ReadUntilTimeout(PIFACE + IN, LOW, 60) ; | |||||
pullUpDnControl (PIFACE + IN, PUD_UP) ; // finally up | |||||
ReadUntilTimeout(PIFACE + IN, HIGH, 2) ; | |||||
} | |||||
return UnitTestState(); | |||||
return UnitTestState(); | |||||
} | } |
@@ -7,8 +7,8 @@ | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
const int GPIO = 19; | |||||
const int GPIOIN = 26; | |||||
int GPIO = 19; | |||||
int GPIOIN = 26; | |||||
const int ToggleValue = 4; | const int ToggleValue = 4; | ||||
@@ -21,6 +21,11 @@ int main (void) { | |||||
printf("wiringPiSetupSys failed\n\n"); | printf("wiringPiSetupSys failed\n\n"); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
if (!piBoard40Pin()) { | |||||
GPIO = 23; | |||||
GPIOIN = 24; | |||||
} | |||||
pinMode(GPIOIN, INPUT); | pinMode(GPIOIN, INPUT); | ||||
pinMode(GPIO, OUTPUT); | pinMode(GPIO, OUTPUT); | ||||
@@ -7,8 +7,8 @@ | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
const int GPIO = 19; | |||||
const int GPIOIN = 26; | |||||
int GPIO = 19; | |||||
int GPIOIN = 26; | |||||
const int ToggleValue = 4; | const int ToggleValue = 4; | ||||
@@ -21,6 +21,11 @@ int main (void) { | |||||
printf("wiringPiSetupSys failed\n\n"); | printf("wiringPiSetupSys failed\n\n"); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
if (!piBoard40Pin()) { | |||||
GPIO = 23; | |||||
GPIOIN = 24; | |||||
} | |||||
pinMode(GPIOIN, INPUT); | pinMode(GPIOIN, INPUT); | ||||
pinMode(GPIO, OUTPUT); | pinMode(GPIO, OUTPUT); | ||||
@@ -7,8 +7,8 @@ | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
const int GPIO = 24; //BCM 19 | |||||
const int GPIOIN = 25; //BCM 26; | |||||
int GPIO = 24; //BCM 19 | |||||
int GPIOIN = 25; //BCM 26; | |||||
const int ToggleValue = 4; | const int ToggleValue = 4; | ||||
@@ -21,6 +21,11 @@ int main (void) { | |||||
printf("wiringPiSetupGpioDevice failed\n\n"); | printf("wiringPiSetupGpioDevice failed\n\n"); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
if (!piBoard40Pin()) { | |||||
GPIO = 4; //BCM 23 | |||||
GPIOIN = 5; //BCM 24 | |||||
} | |||||
pinMode(GPIOIN, INPUT); | pinMode(GPIOIN, INPUT); | ||||
pinMode(GPIO, OUTPUT); | pinMode(GPIO, OUTPUT); | ||||
@@ -7,8 +7,8 @@ | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
const int GPIO = 35; //BCM 19 | |||||
const int GPIOIN = 37; //BCM 26; | |||||
int GPIO = 35; //BCM 19 | |||||
int GPIOIN = 37; //BCM 26; | |||||
const int ToggleValue = 4; | const int ToggleValue = 4; | ||||
@@ -21,6 +21,11 @@ int main (void) { | |||||
printf("wiringPiSetupGpioDevice failed\n\n"); | printf("wiringPiSetupGpioDevice failed\n\n"); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
if (!piBoard40Pin()) { | |||||
GPIO = 16; //BCM 23 | |||||
GPIOIN = 18; //BCM 24 | |||||
} | |||||
pinMode(GPIOIN, INPUT); | pinMode(GPIOIN, INPUT); | ||||
pinMode(GPIO, OUTPUT); | pinMode(GPIO, OUTPUT); | ||||
@@ -7,8 +7,8 @@ | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
const int GPIO = 19; | |||||
const int GPIOIN = 26; | |||||
int GPIO = 19; | |||||
int GPIOIN = 26; | |||||
const int ToggleValue = 4; | const int ToggleValue = 4; | ||||
int RaspberryPiModel = -1; | int RaspberryPiModel = -1; | ||||
@@ -58,6 +58,10 @@ int main (void) { | |||||
} else { | } else { | ||||
printf("Raspberry Pi with BCM GPIO found (not Pi 5)\n"); | printf("Raspberry Pi with BCM GPIO found (not Pi 5)\n"); | ||||
} | } | ||||
if (!piBoard40Pin()) { | |||||
GPIO = 23; | |||||
GPIOIN = 24; | |||||
} | |||||
enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN; | enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN; | ||||
@@ -8,8 +8,8 @@ | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
const int GPIO = 19; | |||||
const int GPIOIN = 26; | |||||
int GPIO = 19; | |||||
int GPIOIN = 26; | |||||
const int ToggleValue = 4; | const int ToggleValue = 4; | ||||
@@ -115,55 +115,61 @@ double DurationTime(int Enge, int OUTpin, int IRQpin) { | |||||
return fTime; | return fTime; | ||||
} | } | ||||
int main (void) { | int main (void) { | ||||
const int IRQpin = GPIOIN ; | |||||
const int OUTpin = GPIO ; | |||||
int major, minor; | |||||
wiringPiVersion(&major, &minor); | |||||
int major, minor; | |||||
wiringPiVersion(&major, &minor); | |||||
printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN); | printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN); | ||||
printf(" testing irq\n"); | printf(" testing irq\n"); | ||||
printf("\nISR test (WiringPi %d.%d)\n", major, minor); | |||||
wiringPiSetupGpio() ; | |||||
pinMode(IRQpin, INPUT); | |||||
pinMode(OUTpin, OUTPUT); | |||||
digitalWrite (OUTpin, LOW) ; | |||||
printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin); | |||||
wiringPiISR (IRQpin, INT_EDGE_RISING, &wfi) ; | |||||
sleep(1); | |||||
StartSequence (INT_EDGE_RISING, OUTpin); | |||||
printf("Testing close\n"); | |||||
wiringPiISRStop (IRQpin) ; | |||||
printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin); | |||||
wiringPiISR (IRQpin, INT_EDGE_FALLING, &wfi) ; | |||||
sleep(1); | |||||
StartSequence (INT_EDGE_FALLING, OUTpin); | |||||
printf("Testing close\n"); | |||||
wiringPiISRStop (IRQpin) ; | |||||
printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d both\n", IRQpin, OUTpin); | |||||
wiringPiISR (IRQpin, INT_EDGE_BOTH, &wfi) ; | |||||
sleep(1); | |||||
StartSequence (INT_EDGE_BOTH, OUTpin); | |||||
printf("Testing close\n"); | |||||
wiringPiISRStop (IRQpin) ; | |||||
for (int count=0; count<2; count++) { | |||||
printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin); | |||||
DurationTime(INT_EDGE_RISING, OUTpin, IRQpin); | |||||
printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin); | |||||
DurationTime(INT_EDGE_FALLING, OUTpin, IRQpin); | |||||
} | |||||
pinMode(OUTpin, INPUT); | |||||
return UnitTestState(); | |||||
printf("\nISR test (WiringPi %d.%d)\n", major, minor); | |||||
wiringPiSetupGpio() ; | |||||
if (!piBoard40Pin()) { | |||||
GPIO = 23; | |||||
GPIOIN = 24; | |||||
} | |||||
int IRQpin = GPIOIN ; | |||||
int OUTpin = GPIO ; | |||||
pinMode(IRQpin, INPUT); | |||||
pinMode(OUTpin, OUTPUT); | |||||
digitalWrite (OUTpin, LOW) ; | |||||
printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin); | |||||
wiringPiISR (IRQpin, INT_EDGE_RISING, &wfi) ; | |||||
sleep(1); | |||||
StartSequence (INT_EDGE_RISING, OUTpin); | |||||
printf("Testing close\n"); | |||||
wiringPiISRStop (IRQpin) ; | |||||
printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin); | |||||
wiringPiISR (IRQpin, INT_EDGE_FALLING, &wfi) ; | |||||
sleep(1); | |||||
StartSequence (INT_EDGE_FALLING, OUTpin); | |||||
printf("Testing close\n"); | |||||
wiringPiISRStop (IRQpin) ; | |||||
printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d both\n", IRQpin, OUTpin); | |||||
wiringPiISR (IRQpin, INT_EDGE_BOTH, &wfi) ; | |||||
sleep(1); | |||||
StartSequence (INT_EDGE_BOTH, OUTpin); | |||||
printf("Testing close\n"); | |||||
wiringPiISRStop (IRQpin) ; | |||||
for (int count=0; count<2; count++) { | |||||
printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin); | |||||
DurationTime(INT_EDGE_RISING, OUTpin, IRQpin); | |||||
printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin); | |||||
DurationTime(INT_EDGE_FALLING, OUTpin, IRQpin); | |||||
} | |||||
pinMode(OUTpin, INPUT); | |||||
return UnitTestState(); | |||||
} | } |
@@ -20,14 +20,14 @@ void CheckGPIO(int GPIO, int GPIOIN, int out) { | |||||
int in = out; | int in = out; | ||||
if (GPIOIN>=0) { | if (GPIOIN>=0) { | ||||
in = digitalRead(GPIOIN); | |||||
in = digitalRead(GPIOIN); | |||||
} | } | ||||
int readback = digitalRead(GPIO); | int readback = digitalRead(GPIO); | ||||
int pass = 0; | int pass = 0; | ||||
if (out==readback && in==out) { | |||||
pass = 1; | |||||
} | |||||
if (out==readback && in==out) { | |||||
pass = 1; | |||||
} | |||||
if (GPIOIN>=0) { | if (GPIOIN>=0) { | ||||
printf("set GPIO%02d = %d (readback %d), in GPIO%02d = %d ", GPIO, out, readback, GPIOIN, in); | printf("set GPIO%02d = %d (readback %d), in GPIO%02d = %d ", GPIO, out, readback, GPIOIN, in); | ||||
@@ -44,6 +44,11 @@ void CheckGPIO(int GPIO, int GPIOIN, int out) { | |||||
} | } | ||||
void CheckInversGPIO(int GPIO, int GPIOIN, int out) { | |||||
CheckGPIO(GPIO, GPIOIN, out==HIGH ? LOW : HIGH); | |||||
} | |||||
void digitalWriteEx(int GPIO, int GPIOIN, int mode) { | void digitalWriteEx(int GPIO, int GPIOIN, int mode) { | ||||
digitalWrite(GPIO, mode); | digitalWrite(GPIO, mode); | ||||
delayMicroseconds(5000); | delayMicroseconds(5000); | ||||
@@ -557,6 +557,27 @@ int piBoard() { | |||||
return RaspberryPiModel<0 ? 0 : 1; | return RaspberryPiModel<0 ? 0 : 1; | ||||
} | } | ||||
int piBoard40Pin() { | |||||
if (!piBoard()){ | |||||
// Board not detected | |||||
return -1; | |||||
} | |||||
switch(RaspberryPiModel){ | |||||
case PI_MODEL_A: | |||||
case PI_MODEL_B: | |||||
return 0; | |||||
// PI_MODEL_CM | |||||
// PI_MODEL_CM3 | |||||
// PI_MODEL_CM4 | |||||
// PI_MODEL_CM4S | |||||
// ? guess yes | |||||
default: | |||||
return 1; | |||||
} | |||||
} | |||||
int GetMaxPin() { | int GetMaxPin() { | ||||
return PI_MODEL_5 == RaspberryPiModel ? 27 : 63; | return PI_MODEL_5 == RaspberryPiModel ? 27 : 63; | ||||
} | } | ||||
@@ -268,6 +268,7 @@ extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio | |||||
extern int piGpioLayout (void) ; | extern int piGpioLayout (void) ; | ||||
extern int piBoardRev (void) ; // Deprecated, but does the same as piGpioLayout | extern int piBoardRev (void) ; // Deprecated, but does the same as piGpioLayout | ||||
extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; | extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; | ||||
extern int piBoard40Pin (void) ; // Interface V3.7 | |||||
extern int wpiPinToGpio (int wpiPin) ; | extern int wpiPinToGpio (int wpiPin) ; | ||||
extern int physPinToGpio (int physPin) ; | extern int physPinToGpio (int physPin) ; | ||||
extern void setPadDrive (int group, int value) ; | extern void setPadDrive (int group, int value) ; | ||||