Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

wiringPi.h 8.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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://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. // 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
  42. #define WPI_MODE_PHYS 3
  43. #define WPI_MODE_PIFACE 4
  44. #define WPI_MODE_UNINITIALISED -1
  45. // Pin modes
  46. #define INPUT 0
  47. #define OUTPUT 1
  48. #define PWM_OUTPUT 2
  49. #define GPIO_CLOCK 3
  50. #define SOFT_PWM_OUTPUT 4
  51. #define SOFT_TONE_OUTPUT 5
  52. #define PWM_TONE_OUTPUT 6
  53. #define LOW 0
  54. #define HIGH 1
  55. // Pull up/down/none
  56. #define PUD_OFF 0
  57. #define PUD_DOWN 1
  58. #define PUD_UP 2
  59. // PWM
  60. #define PWM_MODE_MS 0
  61. #define PWM_MODE_BAL 1
  62. // Interrupt levels
  63. #define INT_EDGE_SETUP 0
  64. #define INT_EDGE_FALLING 1
  65. #define INT_EDGE_RISING 2
  66. #define INT_EDGE_BOTH 3
  67. // Pi model types and version numbers
  68. // Intended for the GPIO program Use at your own risk.
  69. #define PI_MODEL_A 0
  70. #define PI_MODEL_B 1
  71. #define PI_MODEL_AP 2
  72. #define PI_MODEL_BP 3
  73. #define PI_MODEL_2 4
  74. #define PI_ALPHA 5
  75. #define PI_MODEL_CM 6
  76. #define PI_MODEL_07 7
  77. #define PI_MODEL_3B 8
  78. #define PI_MODEL_ZERO 9
  79. #define PI_MODEL_CM3 10
  80. #define PI_MODEL_ZERO_W 12
  81. #define PI_MODEL_3BP 13
  82. #define PI_MODEL_3AP 14
  83. #define PI_MODEL_CM3P 16
  84. #define PI_MODEL_4B 17
  85. #define PI_MODEL_400 19
  86. #define PI_MODEL_CM4 20
  87. #define PI_VERSION_1 0
  88. #define PI_VERSION_1_1 1
  89. #define PI_VERSION_1_2 2
  90. #define PI_VERSION_2 3
  91. #define PI_MAKER_SONY 0
  92. #define PI_MAKER_EGOMAN 1
  93. #define PI_MAKER_EMBEST 2
  94. #define PI_MAKER_SONYJAPAN 3
  95. #define PI_MAKER_EMBEST4 4
  96. #define PI_MAKER_STADIUM 5
  97. extern const char *piModelNames [21] ;
  98. extern const char *piRevisionNames [21] ;
  99. extern const char *piMakerNames [16] ;
  100. extern const int piMemorySize [ 8] ;
  101. // Intended for the GPIO program Use at your own risk.
  102. // Threads
  103. #define PI_THREAD(X) void *X (UNU void *dummy)
  104. // Failure modes
  105. #define WPI_FATAL (1==1)
  106. #define WPI_ALMOST (1==2)
  107. // wiringPiNodeStruct:
  108. // This describes additional device nodes in the extended wiringPi
  109. // 2.0 scheme of things.
  110. // It's a simple linked list for now, but will hopefully migrate to
  111. // a binary tree for efficiency reasons - but then again, the chances
  112. // of more than 1 or 2 devices being added are fairly slim, so who
  113. // knows....
  114. struct wiringPiNodeStruct
  115. {
  116. int pinBase ;
  117. int pinMax ;
  118. int fd ; // Node specific
  119. unsigned int data0 ; // ditto
  120. unsigned int data1 ; // ditto
  121. unsigned int data2 ; // ditto
  122. unsigned int data3 ; // ditto
  123. void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  124. void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  125. int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
  126. //unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin) ;
  127. void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  128. // void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value) ;
  129. void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  130. int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
  131. void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  132. struct wiringPiNodeStruct *next ;
  133. } ;
  134. extern struct wiringPiNodeStruct *wiringPiNodes ;
  135. // Export variables for the hardware pointers
  136. extern volatile unsigned int *_wiringPiGpio ;
  137. extern volatile unsigned int *_wiringPiPwm ;
  138. extern volatile unsigned int *_wiringPiClk ;
  139. extern volatile unsigned int *_wiringPiPads ;
  140. extern volatile unsigned int *_wiringPiTimer ;
  141. extern volatile unsigned int *_wiringPiTimerIrqRaw ;
  142. // Function prototypes
  143. // c++ wrappers thanks to a comment by Nick Lott
  144. // (and others on the Raspberry Pi forums)
  145. #ifdef __cplusplus
  146. extern "C" {
  147. #endif
  148. // Data
  149. // Internal
  150. extern int wiringPiFailure (int fatal, const char *message, ...) ;
  151. // Core wiringPi functions
  152. extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
  153. extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
  154. extern void wiringPiVersion (int *major, int *minor) ;
  155. extern int wiringPiSetup (void) ;
  156. extern int wiringPiSetupSys (void) ;
  157. extern int wiringPiSetupGpio (void) ;
  158. extern int wiringPiSetupPhys (void) ;
  159. extern void pinModeAlt (int pin, int mode) ;
  160. extern void pinMode (int pin, int mode) ;
  161. extern void pullUpDnControl (int pin, int pud) ;
  162. extern int digitalRead (int pin) ;
  163. extern void digitalWrite (int pin, int value) ;
  164. extern unsigned int digitalRead8 (int pin) ;
  165. extern void digitalWrite8 (int pin, int value) ;
  166. extern void pwmWrite (int pin, int value) ;
  167. extern int analogRead (int pin) ;
  168. extern void analogWrite (int pin, int value) ;
  169. // PiFace specifics
  170. // (Deprecated)
  171. extern int wiringPiSetupPiFace (void) ;
  172. extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
  173. // On-Board Raspberry Pi hardware specific stuff
  174. extern int piGpioLayout (void) ;
  175. extern int piBoardRev (void) ; // Deprecated
  176. extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
  177. extern int wpiPinToGpio (int wpiPin) ;
  178. extern int physPinToGpio (int physPin) ;
  179. extern void setPadDrive (int group, int value) ;
  180. extern int getAlt (int pin) ;
  181. extern void pwmToneWrite (int pin, int freq) ;
  182. extern void pwmSetMode (int mode) ;
  183. extern void pwmSetRange (unsigned int range) ;
  184. extern void pwmSetClock (int divisor) ;
  185. extern void gpioClockSet (int pin, int freq) ;
  186. extern unsigned int digitalReadByte (void) ;
  187. extern unsigned int digitalReadByte2 (void) ;
  188. extern void digitalWriteByte (int value) ;
  189. extern void digitalWriteByte2 (int value) ;
  190. // Interrupts
  191. // (Also Pi hardware specific)
  192. extern int waitForInterrupt (int pin, int mS) ;
  193. extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
  194. // Threads
  195. extern int piThreadCreate (void *(*fn)(void *)) ;
  196. extern void piLock (int key) ;
  197. extern void piUnlock (int key) ;
  198. // Schedulling priority
  199. extern int piHiPri (const int pri) ;
  200. // Extras from arduino land
  201. extern void delay (unsigned int howLong) ;
  202. extern void delayMicroseconds (unsigned int howLong) ;
  203. extern unsigned int millis (void) ;
  204. extern unsigned int micros (void) ;
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208. #endif