25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

110 satır
2.8 KiB

  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. int GPIO = 19;
  8. 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. if (!piBoard40Pin()) {
  51. GPIO = 23;
  52. GPIOIN = 24;
  53. }
  54. enum WPIPinAlt AltGpio = WPI_ALT_UNKNOWN;
  55. AltGpio = getPinModeAlt(23);
  56. CheckSame("Pin mode default", AltGpio, PI_MODEL_5 == RaspberryPiModel ? WPI_NONE : WPI_ALT_INPUT);
  57. SetAndCheckMode(GPIOIN, INPUT);
  58. SetAndCheckMode(GPIO, OUTPUT);
  59. printf("toggle %d times ...\n", ToggleValue);
  60. for (int loop=1; loop<ToggleValue; loop++) {
  61. digitalWriteEx(GPIO, GPIOIN, LOW);
  62. delayMicroseconds(600000);
  63. digitalWriteEx(GPIO, GPIOIN, HIGH);
  64. delayMicroseconds(600000);
  65. }
  66. digitalWrite(GPIO, LOW);
  67. printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input))\n", GPIO, GPIOIN);
  68. pullUpDnControl (GPIO, PUD_UP);
  69. SetAndCheckMode(GPIO, INPUT);
  70. delayMicroseconds(3000000);
  71. pullUpDnControl (GPIOIN, PUD_OFF);
  72. for (int loop=1; loop<ToggleValue; loop++) {
  73. pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
  74. delayMicroseconds(600000);
  75. pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
  76. delayMicroseconds(600000);
  77. }
  78. //Error wrong direction - only for fun
  79. digitalWrite(GPIO, LOW);
  80. SetAndCheckMode(GPIO, OUTPUT);
  81. SetAndCheckMode(GPIO, PM_OFF);
  82. //pinModeAlt (GPIO, 0x1F);
  83. //AltGpio = getPinModeAlt(GPIO);
  84. //CheckSame("Pin mode off(default)", AltGpio, 0x1F);
  85. return UnitTestState();
  86. }