Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

288 rindas
9.0 KiB

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