Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

187 рядки
5.3 KiB

  1. /*
  2. * wiringPi:
  3. * Arduino compatable (ish) Wiring library for the Raspberry Pi
  4. * Copyright (c) 2012 Gordon Henderson
  5. ***********************************************************************
  6. * This file is part of wiringPi:
  7. * https://projects.drogon.net/raspberry-pi/wiringpi/
  8. *
  9. * wiringPi is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * wiringPi is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  21. ***********************************************************************
  22. */
  23. #ifndef __WIRING_PI_H__
  24. #define __WIRING_PI_H__
  25. // Handy defines
  26. // Deprecated
  27. #define NUM_PINS 17
  28. #define WPI_MODE_PINS 0
  29. #define WPI_MODE_GPIO 1
  30. #define WPI_MODE_GPIO_SYS 2
  31. #define WPI_MODE_PHYS 3
  32. #define WPI_MODE_PIFACE 4
  33. #define WPI_MODE_UNINITIALISED -1
  34. // Pin modes
  35. #define INPUT 0
  36. #define OUTPUT 1
  37. #define PWM_OUTPUT 2
  38. #define GPIO_CLOCK 3
  39. #define LOW 0
  40. #define HIGH 1
  41. // Pull up/down/none
  42. #define PUD_OFF 0
  43. #define PUD_DOWN 1
  44. #define PUD_UP 2
  45. // PWM
  46. #define PWM_MODE_MS 0
  47. #define PWM_MODE_BAL 1
  48. // Interrupt levels
  49. #define INT_EDGE_SETUP 0
  50. #define INT_EDGE_FALLING 1
  51. #define INT_EDGE_RISING 2
  52. #define INT_EDGE_BOTH 3
  53. // Threads
  54. #define PI_THREAD(X) void *X (void *dummy)
  55. // Failure modes
  56. #define WPI_FATAL (1==1)
  57. #define WPI_ALMOST (1==2)
  58. // wiringPiNodeStruct:
  59. // This describes additional device nodes in the extended wiringPi
  60. // 2.0 scheme of things.
  61. // It's a simple linked list for now, but will hopefully migrate to
  62. // a binary tree for efficiency reasons - but then again, the chances
  63. // of more than 1 or 2 devices being added are fairly slim, so who
  64. // knows....
  65. struct wiringPiNodeStruct
  66. {
  67. int pinBase ;
  68. int pinMax ;
  69. int fd ; // Node specific
  70. unsigned int data0 ; // ditto
  71. unsigned int data1 ; // ditto
  72. unsigned int data2 ; // ditto
  73. unsigned int data3 ; // ditto
  74. void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  75. void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  76. int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
  77. void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  78. void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  79. int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
  80. void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  81. struct wiringPiNodeStruct *next ;
  82. } ;
  83. extern struct wiringPiNodeStruct *wiringPiNodes ;
  84. // Function prototypes
  85. // c++ wrappers thanks to a comment by Nick Lott
  86. // (and others on the Raspberry Pi forums)
  87. #ifdef __cplusplus
  88. extern "C" {
  89. #endif
  90. // Internal
  91. extern int wiringPiFailure (int fatal, const char *message, ...) ;
  92. // Core wiringPi functions
  93. extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
  94. extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
  95. extern int wiringPiSetup (void) ;
  96. extern int wiringPiSetupSys (void) ;
  97. extern int wiringPiSetupGpio (void) ;
  98. extern int wiringPiSetupPhys (void) ;
  99. extern void pinMode (int pin, int mode) ;
  100. extern void pullUpDnControl (int pin, int pud) ;
  101. extern int digitalRead (int pin) ;
  102. extern void digitalWrite (int pin, int value) ;
  103. extern void pwmWrite (int pin, int value) ;
  104. extern int analogRead (int pin) ;
  105. extern void analogWrite (int pin, int value) ;
  106. // PiFace specifics
  107. // (Deprecated)
  108. extern int wiringPiSetupPiFace (void) ;
  109. extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
  110. // On-Board Raspberry Pi hardware specific stuff
  111. extern int piBoardRev (void) ;
  112. extern int wpiPinToGpio (int wpiPin) ;
  113. extern int physPinToGpio (int physPin) ;
  114. extern void setPadDrive (int group, int value) ;
  115. extern int getAlt (int pin) ;
  116. extern void digitalWriteByte (int value) ;
  117. extern void pwmSetMode (int mode) ;
  118. extern void pwmSetRange (unsigned int range) ;
  119. extern void pwmSetClock (int divisor) ;
  120. extern void gpioClockSet (int pin, int freq) ;
  121. // Interrupts
  122. // (Also Pi hardware specific)
  123. extern int waitForInterrupt (int pin, int mS) ;
  124. extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
  125. // Threads
  126. extern int piThreadCreate (void *(*fn)(void *)) ;
  127. extern void piLock (int key) ;
  128. extern void piUnlock (int key) ;
  129. // Schedulling priority
  130. extern int piHiPri (const int pri) ;
  131. // Extras from arduino land
  132. extern void delay (unsigned int howLong) ;
  133. extern void delayMicroseconds (unsigned int howLong) ;
  134. extern unsigned int millis (void) ;
  135. extern unsigned int micros (void) ;
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif