diff --git a/wiringPi/test/wiringpi_test1_device.c b/wiringPi/test/wiringpi_test1_device.c new file mode 100644 index 0000000..e8d6ce1 --- /dev/null +++ b/wiringPi/test/wiringpi_test1_device.c @@ -0,0 +1,83 @@ +// WiringPi test program: Kernel char device interface / sysfs successor +// Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi + +#include +#include +#include +#include +#include +#include +#include + + +//const int GPIO = 24; //LED +const int GPIO = 19; +const int GPIOIN = 26; +const int ToggleValue = 4; + +void CheckGPIO(int out) { + int in = digitalRead(GPIOIN); + int read = digitalRead(GPIO); + + int pass = 0; + if (out==in && in==read) { + pass = 1; + } + printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" ); +} + +void digitalWriteEx(int pin, int mode) { + digitalWrite(pin, mode); + printf("out = %d ", mode); + delayMicroseconds(5000); + CheckGPIO(mode); +} + +void pullUpDnControlEx (int pin ,int mode) { + pullUpDnControl (pin, mode); + int out = mode==PUD_UP ? 1:0; + printf("in = %4s ", mode==PUD_UP ? "up":"down"); + delayMicroseconds(5000); + CheckGPIO(out); +} + +int main (void) { + + printf("WiringPi GPIO test program (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN); + + if (wiringPiSetupSys() == -1) { + printf("wiringPiSetupGpioDevice failed\n\n"); + exit(EXIT_FAILURE); + } + pinMode(GPIOIN, INPUT); + pinMode(GPIO, OUTPUT); + + printf("toggle %d times ...\n", ToggleValue); + for (int loop=1; loop