wiringPi.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 SOFT_PWM_OUTPUT 4
  40. #define SOFT_TONE_OUTPUT 5
  41. #define PWM_TONE_OUTPUT 6
  42. #define LOW 0
  43. #define HIGH 1
  44. // Pull up/down/none
  45. #define PUD_OFF 0
  46. #define PUD_DOWN 1
  47. #define PUD_UP 2
  48. // PWM
  49. #define PWM_MODE_MS 0
  50. #define PWM_MODE_BAL 1
  51. // Interrupt levels
  52. #define INT_EDGE_SETUP 0
  53. #define INT_EDGE_FALLING 1
  54. #define INT_EDGE_RISING 2
  55. #define INT_EDGE_BOTH 3
  56. // Pi model types and version numbers
  57. // Intended for the GPIO program Use at your own risk.
  58. #define PI_MODEL_UNKNOWN 0
  59. #define PI_MODEL_A 1
  60. #define PI_MODEL_B 2
  61. #define PI_MODEL_BP 3
  62. #define PI_MODEL_CM 4
  63. #define PI_MODEL_AP 5
  64. #define PI_MODEL_2 6
  65. #define PI_VERSION_UNKNOWN 0
  66. #define PI_VERSION_1 1
  67. #define PI_VERSION_1_1 2
  68. #define PI_VERSION_1_2 3
  69. #define PI_VERSION_2 4
  70. #define PI_MAKER_UNKNOWN 0
  71. #define PI_MAKER_EGOMAN 1
  72. #define PI_MAKER_SONY 2
  73. #define PI_MAKER_QISDA 3
  74. #define PI_MAKER_MBEST 4
  75. extern const char *piModelNames [7] ;
  76. extern const char *piRevisionNames [5] ;
  77. extern const char *piMakerNames [5] ;
  78. // Intended for the GPIO program Use at your own risk.
  79. // Threads
  80. #define PI_THREAD(X) void *X (void *dummy)
  81. // Failure modes
  82. #define WPI_FATAL (1==1)
  83. #define WPI_ALMOST (1==2)
  84. // wiringPiNodeStruct:
  85. // This describes additional device nodes in the extended wiringPi
  86. // 2.0 scheme of things.
  87. // It's a simple linked list for now, but will hopefully migrate to
  88. // a binary tree for efficiency reasons - but then again, the chances
  89. // of more than 1 or 2 devices being added are fairly slim, so who
  90. // knows....
  91. struct wiringPiNodeStruct
  92. {
  93. int pinBase ;
  94. int pinMax ;
  95. int fd ; // Node specific
  96. unsigned int data0 ; // ditto
  97. unsigned int data1 ; // ditto
  98. unsigned int data2 ; // ditto
  99. unsigned int data3 ; // ditto
  100. void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  101. void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
  102. int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
  103. void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  104. void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  105. int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
  106. void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
  107. struct wiringPiNodeStruct *next ;
  108. } ;
  109. extern struct wiringPiNodeStruct *wiringPiNodes ;
  110. // Function prototypes
  111. // c++ wrappers thanks to a comment by Nick Lott
  112. // (and others on the Raspberry Pi forums)
  113. #ifdef __cplusplus
  114. extern "C" {
  115. #endif
  116. // Data
  117. // Internal
  118. extern int wiringPiFailure (int fatal, const char *message, ...) ;
  119. // Core wiringPi functions
  120. extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
  121. extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
  122. extern int wiringPiSetup (void) ;
  123. extern int wiringPiSetupSys (void) ;
  124. extern int wiringPiSetupGpio (void) ;
  125. extern int wiringPiSetupPhys (void) ;
  126. extern void pinModeAlt (int pin, int mode) ;
  127. extern void pinMode (int pin, int mode) ;
  128. extern void pullUpDnControl (int pin, int pud) ;
  129. extern int digitalRead (int pin) ;
  130. extern void digitalWrite (int pin, int value) ;
  131. extern void pwmWrite (int pin, int value) ;
  132. extern int analogRead (int pin) ;
  133. extern void analogWrite (int pin, int value) ;
  134. // PiFace specifics
  135. // (Deprecated)
  136. extern int wiringPiSetupPiFace (void) ;
  137. extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
  138. // On-Board Raspberry Pi hardware specific stuff
  139. extern int piBoardRev (void) ;
  140. extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
  141. extern int wpiPinToGpio (int wpiPin) ;
  142. extern int physPinToGpio (int physPin) ;
  143. extern void setPadDrive (int group, int value) ;
  144. extern int getAlt (int pin) ;
  145. extern void pwmToneWrite (int pin, int freq) ;
  146. extern void digitalWriteByte (int value) ;
  147. extern void pwmSetMode (int mode) ;
  148. extern void pwmSetRange (unsigned int range) ;
  149. extern void pwmSetClock (int divisor) ;
  150. extern void gpioClockSet (int pin, int freq) ;
  151. // Interrupts
  152. // (Also Pi hardware specific)
  153. extern int waitForInterrupt (int pin, int mS) ;
  154. extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
  155. // Threads
  156. extern int piThreadCreate (void *(*fn)(void *)) ;
  157. extern void piLock (int key) ;
  158. extern void piUnlock (int key) ;
  159. // Schedulling priority
  160. extern int piHiPri (const int pri) ;
  161. // Extras from arduino land
  162. extern void delay (unsigned int howLong) ;
  163. extern void delayMicroseconds (unsigned int howLong) ;
  164. extern unsigned int millis (void) ;
  165. extern unsigned int micros (void) ;
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif