您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

6 个月前
7 个月前
10 个月前
8 个月前
10 个月前
8 个月前
6 个月前
6 个月前
8 个月前
6 个月前
6 个月前
8 个月前
8 个月前
8 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * wiringPi.h:
  3. * Arduino like Wiring library for the Raspberry Pi.
  4. * Copyright (c) 2012-2017 Gordon Henderson
  5. ***********************************************************************
  6. * This file is part of wiringPi:
  7. * https://github.com/WiringPi/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. // C doesn't have true/false by default and I can never remember which
  26. // way round they are, so ...
  27. // (and yes, I know about stdbool.h but I like capitals for these and I'm old)
  28. #ifndef TRUE
  29. # define TRUE (1==1)
  30. # define FALSE (!TRUE)
  31. #endif
  32. // GCC warning suppressor
  33. #define UNU __attribute__((unused))
  34. // Mask for the bottom 64 pins which belong to the Raspberry Pi
  35. // The others are available for the other devices
  36. #define PI_GPIO_MASK (0xFFFFFFC0)
  37. // Handy defines
  38. // wiringPi modes
  39. #define WPI_MODE_PINS 0
  40. #define WPI_MODE_GPIO 1
  41. #define WPI_MODE_GPIO_SYS 2 // deprecated since 3.2
  42. #define WPI_MODE_PHYS 3
  43. #define WPI_MODE_PIFACE 4
  44. #define WPI_MODE_GPIO_DEVICE_BCM 5 // BCM pin numbers like WPI_MODE_GPIO
  45. #define WPI_MODE_GPIO_DEVICE_WPI 6 // WiringPi pin numbers like WPI_MODE_PINS
  46. #define WPI_MODE_GPIO_DEVICE_PHYS 7 // Physic pin numbers like WPI_MODE_PHYS
  47. #define WPI_MODE_UNINITIALISED -1
  48. // Pin modes
  49. #define INPUT 0
  50. #define OUTPUT 1
  51. #define PWM_OUTPUT 2
  52. #define GPIO_CLOCK 3
  53. #define SOFT_PWM_OUTPUT 4
  54. #define SOFT_TONE_OUTPUT 5
  55. #define PWM_TONE_OUTPUT 6
  56. #define PM_OFF 7 // to input / release line
  57. #define LOW 0
  58. #define HIGH 1
  59. // Pull up/down/none
  60. #define PUD_OFF 0
  61. #define PUD_DOWN 1
  62. #define PUD_UP 2
  63. // PWM
  64. #define PWM_MODE_MS 0
  65. #define PWM_MODE_BAL 1
  66. // Interrupt levels
  67. #define INT_EDGE_SETUP 0
  68. #define INT_EDGE_FALLING 1
  69. #define INT_EDGE_RISING 2
  70. #define INT_EDGE_BOTH 3
  71. // Pi model types and version numbers
  72. // Intended for the GPIO program Use at your own risk.
  73. // https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes
  74. #define PI_MODEL_A 0
  75. #define PI_MODEL_B 1
  76. #define PI_MODEL_AP 2
  77. #define PI_MODEL_BP 3
  78. #define PI_MODEL_2 4
  79. #define PI_ALPHA 5
  80. #define PI_MODEL_CM 6
  81. #define PI_MODEL_07 7
  82. #define PI_MODEL_3B 8
  83. #define PI_MODEL_ZERO 9
  84. #define PI_MODEL_CM3 10
  85. #define PI_MODEL_ZERO_W 12
  86. #define PI_MODEL_3BP 13
  87. #define PI_MODEL_3AP 14
  88. #define PI_MODEL_CM3P 16
  89. #define PI_MODEL_4B 17
  90. #define PI_MODEL_ZERO_2W 18
  91. #define PI_MODEL_400 19
  92. #define PI_MODEL_CM4 20
  93. #define PI_MODEL_CM4S 21
  94. #define PI_MODEL_5 23
  95. #define PI_VERSION_1 0
  96. #define PI_VERSION_1_1 1
  97. #define PI_VERSION_1_2 2
  98. #define PI_VERSION_2 3
  99. #define PI_MAKER_SONY 0
  100. #define PI_MAKER_EGOMAN 1
  101. #define PI_MAKER_EMBEST 2
  102. #define PI_MAKER_UNKNOWN 3
  103. #define GPIO_LAYOUT_PI1_REV1 1 //Pi 1 A/B Revision 1, 1.1, CM
  104. #define GPIO_LAYOUT_DEFAULT 2
  105. extern const char *piModelNames [24] ;
  106. extern const char *piProcessor [ 5] ;
  107. extern const char *piRevisionNames [16] ;
  108. extern const char *piMakerNames [16] ;
  109. extern const int piMemorySize [ 8] ;
  110. // Intended for the GPIO program Use at your own risk.
  111. // Threads
  112. #define PI_THREAD(X) void *X (UNU void *dummy)
  113. // Failure modes
  114. #define WPI_FATAL (1==1)
  115. #define WPI_ALMOST (1==2)
  116. // wiringPiNodeStruct:
  117. // This describes additional device nodes in the extended wiringPi
  118. // 2.0 scheme of things.
  119. // It's a simple linked list for now, but will hopefully migrate to
  120. // a binary tree for efficiency reasons - but then again, the chances
  121. // of more than 1 or 2 devices being added are fairly slim, so who
  122. // knows....
  123. struct wiringPiNodeStruct
  124. {
  125. int pinBase ;
  126. int pinMax ;
  127. int fd ; // Node specific
  128. unsigned int data0 ; // ditto
  129. unsigned int data1 ; // ditto
  130. unsigned int data2 ; // ditto
  131. unsigned int data3 ; // ditto
  132. void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  133. void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  134. int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
  135. //unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin) ;
  136. void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  137. // void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value) ;
  138. void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  139. int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
  140. void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  141. struct wiringPiNodeStruct *next ;
  142. } ;
  143. extern struct wiringPiNodeStruct *wiringPiNodes ;
  144. // Export variables for the hardware pointers
  145. extern volatile unsigned int *_wiringPiGpio ;
  146. extern volatile unsigned int *_wiringPiPwm ;
  147. extern volatile unsigned int *_wiringPiClk ;
  148. extern volatile unsigned int *_wiringPiPads ;
  149. extern volatile unsigned int *_wiringPiTimer ;
  150. extern volatile unsigned int *_wiringPiTimerIrqRaw ;
  151. // Function prototypes
  152. // c++ wrappers thanks to a comment by Nick Lott
  153. // (and others on the Raspberry Pi forums)
  154. #ifdef __cplusplus
  155. extern "C" {
  156. #endif
  157. // Data
  158. // Internal
  159. extern void piGpioLayoutOops (const char *why);
  160. extern int wiringPiFailure (int fatal, const char *message, ...) ;
  161. // Core wiringPi functions
  162. extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
  163. extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
  164. enum WPIPinType {
  165. WPI_PIN_BCM = 1,
  166. WPI_PIN_WPI,
  167. WPI_PIN_PHYS,
  168. };
  169. extern void wiringPiVersion (int *major, int *minor) ;
  170. extern int wiringPiGlobalMemoryAccess(void); //Interface V3.3
  171. extern int wiringPiUserLevelAccess (void) ;
  172. extern int wiringPiSetup (void) ;
  173. extern int wiringPiSetupSys (void) ;
  174. extern int wiringPiSetupGpio (void) ;
  175. extern int wiringPiSetupPhys (void) ;
  176. extern int wiringPiSetupPinType (enum WPIPinType pinType); //Interface V3.3
  177. extern int wiringPiSetupGpioDevice(enum WPIPinType pinType); //Interface V3.3
  178. extern int wiringPiGpioDeviceGetFd(); //Interface V3.3
  179. extern void pinModeAlt (int pin, int mode) ;
  180. extern void pinMode (int pin, int mode) ;
  181. extern void pullUpDnControl (int pin, int pud) ;
  182. extern int digitalRead (int pin) ;
  183. extern void digitalWrite (int pin, int value) ;
  184. extern unsigned int digitalRead8 (int pin) ;
  185. extern void digitalWrite8 (int pin, int value) ;
  186. extern void pwmWrite (int pin, int value) ;
  187. extern int analogRead (int pin) ;
  188. extern void analogWrite (int pin, int value) ;
  189. // PiFace specifics
  190. // (Deprecated)
  191. extern int wiringPiSetupPiFace (void) ;
  192. extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
  193. // On-Board Raspberry Pi hardware specific stuff
  194. extern int piGpioLayout (void) ;
  195. extern int piBoardRev (void) ; // Deprecated, but does the same as piGpioLayout
  196. extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
  197. extern int wpiPinToGpio (int wpiPin) ;
  198. extern int physPinToGpio (int physPin) ;
  199. extern void setPadDrive (int group, int value) ;
  200. extern void setPadDrivePin (int pin, int value); // Interface V3.0
  201. extern int getAlt (int pin) ;
  202. extern void pwmToneWrite (int pin, int freq) ;
  203. extern void pwmSetMode (int mode) ;
  204. extern void pwmSetRange (unsigned int range) ;
  205. extern void pwmSetClock (int divisor) ;
  206. extern void gpioClockSet (int pin, int freq) ;
  207. extern unsigned int digitalReadByte (void) ;
  208. extern unsigned int digitalReadByte2 (void) ;
  209. extern void digitalWriteByte (int value) ;
  210. extern void digitalWriteByte2 (int value) ;
  211. // Interrupts
  212. // (Also Pi hardware specific)
  213. extern int waitForInterrupt (int pin, int mS) ;
  214. extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
  215. extern int wiringPiISRStop (int pin) ; //V3.2
  216. extern int waitForInterruptClose(int pin) ; //V3.2
  217. // Threads
  218. extern int piThreadCreate (void *(*fn)(void *)) ;
  219. extern void piLock (int key) ;
  220. extern void piUnlock (int key) ;
  221. // Schedulling priority
  222. extern int piHiPri (const int pri) ;
  223. // Extras from arduino land
  224. extern void delay (unsigned int howLong) ;
  225. extern void delayMicroseconds (unsigned int howLong) ;
  226. extern unsigned int millis (void) ;
  227. extern unsigned int micros (void) ;
  228. #ifdef __cplusplus
  229. }
  230. #endif
  231. #endif