You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wiringpi_test5_default.c 2.8 KiB

7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
6 months ago
7 months ago
6 months ago
7 months ago
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
7 months ago
6 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // WiringPi test program: Kernel char device interface / sysfs successor
  2. // Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi
  3. #include "wpi_test.h"
  4. #include <signal.h>
  5. #include <time.h>
  6. #include <sys/time.h>
  7. const int GPIO = 19;
  8. const int GPIOIN = 26;
  9. const int ToggleValue = 4;
  10. int RaspberryPiModel = -1;
  11. void SetAndCheckMode(int pin, int mode) {
  12. enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN;
  13. switch(mode) {
  14. case INPUT:
  15. pinMode(pin, INPUT);
  16. AltGpio = getPinModeAlt(pin);
  17. CheckSame("Pin mode input", AltGpio, WPI_ALT_INPUT);
  18. break;
  19. case OUTPUT:
  20. pinMode(pin, OUTPUT);
  21. AltGpio = getPinModeAlt(pin);
  22. CheckSame("Pin mode output", AltGpio, WPI_ALT_OUTPUT);
  23. break;
  24. case PM_OFF:
  25. pinMode(pin, PM_OFF);
  26. AltGpio = getPinModeAlt(pin);
  27. CheckSame("Pin mode off(input)", AltGpio, (PI_MODEL_5 == RaspberryPiModel) ? WPI_NONE : WPI_ALT_INPUT);
  28. break;
  29. default:
  30. pinMode(pin, mode);
  31. printf("pinmode %d of pin %d not checked", mode, pin);
  32. break;
  33. }
  34. }
  35. int main (void) {
  36. printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN);
  37. printf(" testing digitalWrite, digitalRead and pullUpDnControl\n");
  38. if (wiringPiSetupGpio() == -1) {
  39. printf("wiringPiSetupGpio failed\n\n");
  40. exit(EXIT_FAILURE);
  41. }
  42. int rev, mem, maker, overVolted;
  43. piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
  44. CheckNotSame("Model: ", RaspberryPiModel, -1);
  45. if (PI_MODEL_5 == RaspberryPiModel) {
  46. printf("Raspberry Pi 5 with RP1 found\n");
  47. } else {
  48. printf("Raspberry Pi with BCM GPIO found (not Pi 5)\n");
  49. }
  50. enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN;
  51. AltGpio = getPinModeAlt(23);
  52. CheckSame("Pin mode default", AltGpio, PI_MODEL_5 == RaspberryPiModel ? WPI_NONE : WPI_ALT_INPUT);
  53. SetAndCheckMode(GPIOIN, INPUT);
  54. SetAndCheckMode(GPIO, OUTPUT);
  55. printf("toggle %d times ...\n", ToggleValue);
  56. for (int loop=1; loop<ToggleValue; loop++) {
  57. digitalWriteEx(GPIO, GPIOIN, LOW);
  58. delayMicroseconds(600000);
  59. digitalWriteEx(GPIO, GPIOIN, HIGH);
  60. delayMicroseconds(600000);
  61. }
  62. digitalWrite(GPIO, LOW);
  63. printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input))\n", GPIO, GPIOIN);
  64. pullUpDnControl (GPIO, PUD_UP);
  65. SetAndCheckMode(GPIO, INPUT);
  66. delayMicroseconds(3000000);
  67. pullUpDnControl (GPIOIN, PUD_OFF);
  68. for (int loop=1; loop<ToggleValue; loop++) {
  69. pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
  70. delayMicroseconds(600000);
  71. pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
  72. delayMicroseconds(600000);
  73. }
  74. //Error wrong direction - only for fun
  75. digitalWrite(GPIO, LOW);
  76. SetAndCheckMode(GPIO, OUTPUT);
  77. SetAndCheckMode(GPIO, PM_OFF);
  78. //pinModeAlt (GPIO, 0x1F);
  79. //AltGpio = getPinModeAlt(GPIO);
  80. //CheckSame("Pin mode off(default)", AltGpio, 0x1F);
  81. return UnitTestState();
  82. }