wiringpi-ruby 2.0.0 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
  3. data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
  4. data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
  5. data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
  6. data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
  7. data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +238 -0
  12. data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
  13. data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
  14. data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
  15. data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +177 -0
  16. data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
  17. data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
  18. data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/devLib/scrollPhat.c +430 -0
  21. data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
  22. data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  27. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  28. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  29. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  33. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  34. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  35. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  36. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  37. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  38. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  39. data/ext/wiringpi/WiringPi/examples/blink-thread.c +61 -0
  40. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  41. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  42. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  43. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  44. data/ext/wiringpi/WiringPi/examples/blink8-drcn.c +61 -0
  45. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  46. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  47. data/ext/wiringpi/WiringPi/examples/delayTest.c +102 -0
  48. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  49. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  50. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  51. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  52. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  53. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  54. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  55. data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
  56. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  57. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  58. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  59. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  60. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  61. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  62. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  63. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  64. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  65. data/ext/wiringpi/WiringPi/examples/rht03.c +86 -0
  66. data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
  67. data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
  68. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  69. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  70. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  71. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  72. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  73. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  74. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  75. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  76. data/ext/wiringpi/WiringPi/gpio/gpio.c +1538 -0
  77. data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
  78. data/ext/wiringpi/WiringPi/version.h +3 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +188 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +125 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  121. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  122. data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.c +95 -0
  123. data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
  124. data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
  125. data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  127. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  128. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +186 -0
  129. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  130. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  131. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  132. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  133. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  134. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  135. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  136. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2507 -0
  137. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
  138. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
  139. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  140. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
  141. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  142. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
  143. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  144. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
  145. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
  146. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
  147. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  148. data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
  149. data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
  150. data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
  151. data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
  152. data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
  153. data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
  154. data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
  155. data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
  156. data/ext/wiringpi/wiringpi_wrap.c +636 -219
  157. data/lib/wiringpi.rb +25 -12
  158. data/lib/wiringpi/gpio.rb +90 -83
  159. data/lib/wiringpi/i2c.rb +29 -22
  160. data/lib/wiringpi/modules/mcp23017.rb +15 -0
  161. data/lib/wiringpi/modules/mcp23s17.rb +16 -0
  162. data/lib/wiringpi/scrollphat.rb +14 -14
  163. data/lib/wiringpi/serial.rb +8 -18
  164. data/lib/wiringpi/spi.rb +14 -11
  165. data/lib/wiringpi/watch.rb +24 -0
  166. metadata +160 -4
  167. data/lib/wiringpi/event.rb +0 -21
  168. data/lib/wiringpi/mcp23x17.rb +0 -31
@@ -0,0 +1,269 @@
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
+
24
+ #ifndef __WIRING_PI_H__
25
+ #define __WIRING_PI_H__
26
+
27
+ // C doesn't have true/false by default and I can never remember which
28
+ // way round they are, so ...
29
+ // (and yes, I know about stdbool.h but I like capitals for these and I'm old)
30
+
31
+ #ifndef TRUE
32
+ # define TRUE (1==1)
33
+ # define FALSE (!TRUE)
34
+ #endif
35
+
36
+ // GCC warning suppressor
37
+
38
+ #define UNU __attribute__((unused))
39
+
40
+ // Mask for the bottom 64 pins which belong to the Raspberry Pi
41
+ // The others are available for the other devices
42
+
43
+ #define PI_GPIO_MASK (0xFFFFFFC0)
44
+
45
+ // Handy defines
46
+
47
+ // wiringPi modes
48
+
49
+ #define WPI_MODE_PINS 0
50
+ #define WPI_MODE_GPIO 1
51
+ #define WPI_MODE_GPIO_SYS 2
52
+ #define WPI_MODE_PHYS 3
53
+ #define WPI_MODE_PIFACE 4
54
+ #define WPI_MODE_UNINITIALISED -1
55
+
56
+ // Pin modes
57
+
58
+ #define INPUT 0
59
+ #define OUTPUT 1
60
+ #define PWM_OUTPUT 2
61
+ #define GPIO_CLOCK 3
62
+ #define SOFT_PWM_OUTPUT 4
63
+ #define SOFT_TONE_OUTPUT 5
64
+ #define PWM_TONE_OUTPUT 6
65
+
66
+ #define LOW 0
67
+ #define HIGH 1
68
+
69
+ // Pull up/down/none
70
+
71
+ #define PUD_OFF 0
72
+ #define PUD_DOWN 1
73
+ #define PUD_UP 2
74
+
75
+ // PWM
76
+
77
+ #define PWM_MODE_MS 0
78
+ #define PWM_MODE_BAL 1
79
+
80
+ // Interrupt levels
81
+
82
+ #define INT_EDGE_SETUP 0
83
+ #define INT_EDGE_FALLING 1
84
+ #define INT_EDGE_RISING 2
85
+ #define INT_EDGE_BOTH 3
86
+
87
+ // Pi model types and version numbers
88
+ // Intended for the GPIO program Use at your own risk.
89
+
90
+ #define PI_MODEL_A 0
91
+ #define PI_MODEL_B 1
92
+ #define PI_MODEL_AP 2
93
+ #define PI_MODEL_BP 3
94
+ #define PI_MODEL_2 4
95
+ #define PI_ALPHA 5
96
+ #define PI_MODEL_CM 6
97
+ #define PI_MODEL_07 7
98
+ #define PI_MODEL_3B 8
99
+ #define PI_MODEL_ZERO 9
100
+ #define PI_MODEL_CM3 10
101
+ #define PI_MODEL_ZERO_W 12
102
+ #define PI_MODEL_3BP 13
103
+ #define PI_MODEL_3AP 14
104
+ #define PI_MODEL_CM3P 16
105
+ #define PI_MODEL_4B 17
106
+ #define PI_MODEL_400 19
107
+ #define PI_MODEL_CM4 20
108
+
109
+ #define PI_VERSION_1 0
110
+ #define PI_VERSION_1_1 1
111
+ #define PI_VERSION_1_2 2
112
+ #define PI_VERSION_2 3
113
+
114
+ #define PI_MAKER_SONY 0
115
+ #define PI_MAKER_EGOMAN 1
116
+ #define PI_MAKER_EMBEST 2
117
+ #define PI_MAKER_UNKNOWN 3
118
+
119
+ extern const char *piModelNames [21] ;
120
+ extern const char *piRevisionNames [16] ;
121
+ extern const char *piMakerNames [16] ;
122
+ extern const int piMemorySize [ 8] ;
123
+
124
+
125
+ // Intended for the GPIO program Use at your own risk.
126
+
127
+ // Threads
128
+
129
+ #define PI_THREAD(X) void *X (UNU void *dummy)
130
+
131
+ // Failure modes
132
+
133
+ #define WPI_FATAL (1==1)
134
+ #define WPI_ALMOST (1==2)
135
+
136
+
137
+ // wiringPiNodeStruct:
138
+ // This describes additional device nodes in the extended wiringPi
139
+ // 2.0 scheme of things.
140
+ // It's a simple linked list for now, but will hopefully migrate to
141
+ // a binary tree for efficiency reasons - but then again, the chances
142
+ // of more than 1 or 2 devices being added are fairly slim, so who
143
+ // knows....
144
+
145
+ struct wiringPiNodeStruct
146
+ {
147
+ int pinBase ;
148
+ int pinMax ;
149
+
150
+ int fd ; // Node specific
151
+ unsigned int data0 ; // ditto
152
+ unsigned int data1 ; // ditto
153
+ unsigned int data2 ; // ditto
154
+ unsigned int data3 ; // ditto
155
+
156
+ void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
157
+ void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
158
+ int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
159
+ //unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin) ;
160
+ void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
161
+ // void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value) ;
162
+ void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
163
+ int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
164
+ void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
165
+
166
+ struct wiringPiNodeStruct *next ;
167
+ } ;
168
+
169
+ extern struct wiringPiNodeStruct *wiringPiNodes ;
170
+
171
+ // Export variables for the hardware pointers
172
+
173
+ extern volatile unsigned int *_wiringPiGpio ;
174
+ extern volatile unsigned int *_wiringPiPwm ;
175
+ extern volatile unsigned int *_wiringPiClk ;
176
+ extern volatile unsigned int *_wiringPiPads ;
177
+ extern volatile unsigned int *_wiringPiTimer ;
178
+ extern volatile unsigned int *_wiringPiTimerIrqRaw ;
179
+
180
+
181
+ // Function prototypes
182
+ // c++ wrappers thanks to a comment by Nick Lott
183
+ // (and others on the Raspberry Pi forums)
184
+
185
+ #ifdef __cplusplus
186
+ extern "C" {
187
+ #endif
188
+
189
+ // Data
190
+
191
+ // Internal
192
+
193
+ extern int wiringPiFailure (int fatal, const char *message, ...) ;
194
+
195
+ // Core wiringPi functions
196
+
197
+ extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
198
+ extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
199
+
200
+ extern void wiringPiVersion (int *major, int *minor) ;
201
+ extern int wiringPiSetup (void) ;
202
+ extern int wiringPiSetupSys (void) ;
203
+ extern int wiringPiSetupGpio (void) ;
204
+ extern int wiringPiSetupPhys (void) ;
205
+
206
+ extern void pinModeAlt (int pin, int mode) ;
207
+ extern void pinMode (int pin, int mode) ;
208
+ extern void pullUpDnControl (int pin, int pud) ;
209
+ extern int digitalRead (int pin) ;
210
+ extern void digitalWrite (int pin, int value) ;
211
+ extern unsigned int digitalRead8 (int pin) ;
212
+ extern void digitalWrite8 (int pin, int value) ;
213
+ extern void pwmWrite (int pin, int value) ;
214
+ extern int analogRead (int pin) ;
215
+ extern void analogWrite (int pin, int value) ;
216
+
217
+ // PiFace specifics
218
+ // (Deprecated)
219
+
220
+ extern int wiringPiSetupPiFace (void) ;
221
+ extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
222
+
223
+ // On-Board Raspberry Pi hardware specific stuff
224
+
225
+ extern int piGpioLayout (void) ;
226
+ extern int piBoardRev (void) ; // Deprecated
227
+ extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
228
+ extern int wpiPinToGpio (int wpiPin) ;
229
+ extern int physPinToGpio (int physPin) ;
230
+ extern void setPadDrive (int group, int value) ;
231
+ extern int getAlt (int pin) ;
232
+ extern void pwmToneWrite (int pin, int freq) ;
233
+ extern void pwmSetMode (int mode) ;
234
+ extern void pwmSetRange (unsigned int range) ;
235
+ extern void pwmSetClock (int divisor) ;
236
+ extern void gpioClockSet (int pin, int freq) ;
237
+ extern unsigned int digitalReadByte (void) ;
238
+ extern unsigned int digitalReadByte2 (void) ;
239
+ extern void digitalWriteByte (int value) ;
240
+ extern void digitalWriteByte2 (int value) ;
241
+
242
+ // Interrupts
243
+ // (Also Pi hardware specific)
244
+
245
+ extern int waitForInterrupt (int pin, int mS) ;
246
+ extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
247
+
248
+ // Threads
249
+
250
+ extern int piThreadCreate (void *(*fn)(void *)) ;
251
+ extern void piLock (int key) ;
252
+ extern void piUnlock (int key) ;
253
+
254
+ // Schedulling priority
255
+
256
+ extern int piHiPri (const int pri) ;
257
+
258
+ // Extras from arduino land
259
+
260
+ extern void delay (unsigned int howLong) ;
261
+ extern void delayMicroseconds (unsigned int howLong) ;
262
+ extern unsigned int millis (void) ;
263
+ extern unsigned int micros (void) ;
264
+
265
+ #ifdef __cplusplus
266
+ }
267
+ #endif
268
+
269
+ #endif
@@ -0,0 +1,233 @@
1
+ /*
2
+ * wiringPiI2C.c:
3
+ * Simplified I2C access routines
4
+ * Copyright (c) 2013 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
11
+ * published by the Free Software Foundation, either version 3 of the
12
+ * License, or (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
20
+ * License along with wiringPi.
21
+ * If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ /*
26
+ * Notes:
27
+ * The Linux I2C code is actually the same (almost) as the SMBus code.
28
+ * SMBus is System Management Bus - and in essentially I2C with some
29
+ * additional functionality added, and stricter controls on the electrical
30
+ * specifications, etc. however I2C does work well with it and the
31
+ * protocols work over both.
32
+ *
33
+ * I'm directly including the SMBus functions here as some Linux distros
34
+ * lack the correct header files, and also some header files are GPLv2
35
+ * rather than the LGPL that wiringPi is released under - presumably because
36
+ * originally no-one expected I2C/SMBus to be used outside the kernel -
37
+ * however enter the Raspberry Pi with people now taking directly to I2C
38
+ * devices without going via the kernel...
39
+ *
40
+ * This may ultimately reduce the flexibility of this code, but it won't be
41
+ * hard to maintain it and keep it current, should things change.
42
+ *
43
+ * Information here gained from: kernel/Documentation/i2c/dev-interface
44
+ * as well as other online resources.
45
+ *********************************************************************************
46
+ */
47
+
48
+ #include <stdio.h>
49
+ #include <stdlib.h>
50
+ #include <stdint.h>
51
+ #include <errno.h>
52
+ #include <string.h>
53
+ #include <fcntl.h>
54
+ #include <sys/ioctl.h>
55
+ #include <asm/ioctl.h>
56
+
57
+ #include "wiringPi.h"
58
+ #include "wiringPiI2C.h"
59
+
60
+ // I2C definitions
61
+
62
+ #define I2C_SLAVE 0x0703
63
+ #define I2C_SMBUS 0x0720 /* SMBus-level access */
64
+
65
+ #define I2C_SMBUS_READ 1
66
+ #define I2C_SMBUS_WRITE 0
67
+
68
+ // SMBus transaction types
69
+
70
+ #define I2C_SMBUS_QUICK 0
71
+ #define I2C_SMBUS_BYTE 1
72
+ #define I2C_SMBUS_BYTE_DATA 2
73
+ #define I2C_SMBUS_WORD_DATA 3
74
+ #define I2C_SMBUS_PROC_CALL 4
75
+ #define I2C_SMBUS_BLOCK_DATA 5
76
+ #define I2C_SMBUS_I2C_BLOCK_BROKEN 6
77
+ #define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
78
+ #define I2C_SMBUS_I2C_BLOCK_DATA 8
79
+
80
+ // SMBus messages
81
+
82
+ #define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
83
+ #define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
84
+
85
+ // Structures used in the ioctl() calls
86
+
87
+ union i2c_smbus_data
88
+ {
89
+ uint8_t byte ;
90
+ uint16_t word ;
91
+ uint8_t block [I2C_SMBUS_BLOCK_MAX + 2] ; // block [0] is used for length + one more for PEC
92
+ } ;
93
+
94
+ struct i2c_smbus_ioctl_data
95
+ {
96
+ char read_write ;
97
+ uint8_t command ;
98
+ int size ;
99
+ union i2c_smbus_data *data ;
100
+ } ;
101
+
102
+ static inline int i2c_smbus_access (int fd, char rw, uint8_t command, int size, union i2c_smbus_data *data)
103
+ {
104
+ struct i2c_smbus_ioctl_data args ;
105
+
106
+ args.read_write = rw ;
107
+ args.command = command ;
108
+ args.size = size ;
109
+ args.data = data ;
110
+ return ioctl (fd, I2C_SMBUS, &args) ;
111
+ }
112
+
113
+
114
+ /*
115
+ * wiringPiI2CRead:
116
+ * Simple device read
117
+ *********************************************************************************
118
+ */
119
+
120
+ int wiringPiI2CRead (int fd)
121
+ {
122
+ union i2c_smbus_data data ;
123
+
124
+ if (i2c_smbus_access (fd, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data))
125
+ return -1 ;
126
+ else
127
+ return data.byte & 0xFF ;
128
+ }
129
+
130
+
131
+ /*
132
+ * wiringPiI2CReadReg8: wiringPiI2CReadReg16:
133
+ * Read an 8 or 16-bit value from a regsiter on the device
134
+ *********************************************************************************
135
+ */
136
+
137
+ int wiringPiI2CReadReg8 (int fd, int reg)
138
+ {
139
+ union i2c_smbus_data data;
140
+
141
+ if (i2c_smbus_access (fd, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, &data))
142
+ return -1 ;
143
+ else
144
+ return data.byte & 0xFF ;
145
+ }
146
+
147
+ int wiringPiI2CReadReg16 (int fd, int reg)
148
+ {
149
+ union i2c_smbus_data data;
150
+
151
+ if (i2c_smbus_access (fd, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, &data))
152
+ return -1 ;
153
+ else
154
+ return data.word & 0xFFFF ;
155
+ }
156
+
157
+
158
+ /*
159
+ * wiringPiI2CWrite:
160
+ * Simple device write
161
+ *********************************************************************************
162
+ */
163
+
164
+ int wiringPiI2CWrite (int fd, int data)
165
+ {
166
+ return i2c_smbus_access (fd, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) ;
167
+ }
168
+
169
+
170
+ /*
171
+ * wiringPiI2CWriteReg8: wiringPiI2CWriteReg16:
172
+ * Write an 8 or 16-bit value to the given register
173
+ *********************************************************************************
174
+ */
175
+
176
+ int wiringPiI2CWriteReg8 (int fd, int reg, int value)
177
+ {
178
+ union i2c_smbus_data data ;
179
+
180
+ data.byte = value ;
181
+ return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, &data) ;
182
+ }
183
+
184
+ int wiringPiI2CWriteReg16 (int fd, int reg, int value)
185
+ {
186
+ union i2c_smbus_data data ;
187
+
188
+ data.word = value ;
189
+ return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, &data) ;
190
+ }
191
+
192
+
193
+ /*
194
+ * wiringPiI2CSetupInterface:
195
+ * Undocumented access to set the interface explicitly - might be used
196
+ * for the Pi's 2nd I2C interface...
197
+ *********************************************************************************
198
+ */
199
+
200
+ int wiringPiI2CSetupInterface (const char *device, int devId)
201
+ {
202
+ int fd ;
203
+
204
+ if ((fd = open (device, O_RDWR)) < 0)
205
+ return wiringPiFailure (WPI_ALMOST, "Unable to open I2C device: %s\n", strerror (errno)) ;
206
+
207
+ if (ioctl (fd, I2C_SLAVE, devId) < 0)
208
+ return wiringPiFailure (WPI_ALMOST, "Unable to select I2C device: %s\n", strerror (errno)) ;
209
+
210
+ return fd ;
211
+ }
212
+
213
+
214
+ /*
215
+ * wiringPiI2CSetup:
216
+ * Open the I2C device, and regsiter the target device
217
+ *********************************************************************************
218
+ */
219
+
220
+ int wiringPiI2CSetup (const int devId)
221
+ {
222
+ int rev ;
223
+ const char *device ;
224
+
225
+ rev = piGpioLayout () ;
226
+
227
+ if (rev == 1)
228
+ device = "/dev/i2c-0" ;
229
+ else
230
+ device = "/dev/i2c-1" ;
231
+
232
+ return wiringPiI2CSetupInterface (device, devId) ;
233
+ }