wiringpi-ruby 2.0.0 → 2.0.1

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 (156) 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. metadata +155 -1
@@ -0,0 +1,403 @@
1
+ /*
2
+ * readall.c:
3
+ * The readall functions - getting a bit big, so split them out.
4
+ * Copyright (c) 2012-2018 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
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <stdint.h>
28
+ #include <ctype.h>
29
+ #include <string.h>
30
+ #include <unistd.h>
31
+ #include <errno.h>
32
+ #include <fcntl.h>
33
+ #include <sys/types.h>
34
+ #include <sys/stat.h>
35
+
36
+ #include <wiringPi.h>
37
+
38
+ extern int wpMode ;
39
+
40
+ #ifndef TRUE
41
+ # define TRUE (1==1)
42
+ # define FALSE (1==2)
43
+ #endif
44
+
45
+ /*
46
+ * doReadallExternal:
47
+ * A relatively crude way to read the pins on an external device.
48
+ * We don't know the input/output mode of pins, but we can tell
49
+ * if it's an analog pin or a digital one...
50
+ *********************************************************************************
51
+ */
52
+
53
+ static void doReadallExternal (void)
54
+ {
55
+ int pin ;
56
+
57
+ printf ("+------+---------+--------+\n") ;
58
+ printf ("| Pin | Digital | Analog |\n") ;
59
+ printf ("+------+---------+--------+\n") ;
60
+
61
+ for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
62
+ printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
63
+
64
+ printf ("+------+---------+--------+\n") ;
65
+ }
66
+
67
+
68
+ /*
69
+ * doReadall:
70
+ * Read all the GPIO pins
71
+ * We also want to use this to read the state of pins on an externally
72
+ * connected device, so we need to do some fiddling with the internal
73
+ * wiringPi node structures - since the gpio command can only use
74
+ * one external device at a time, we'll use that to our advantage...
75
+ *********************************************************************************
76
+ */
77
+
78
+ static char *alts [] =
79
+ {
80
+ "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
81
+ } ;
82
+
83
+ static int physToWpi [64] =
84
+ {
85
+ -1, // 0
86
+ -1, -1, // 1, 2
87
+ 8, -1,
88
+ 9, -1,
89
+ 7, 15,
90
+ -1, 16,
91
+ 0, 1,
92
+ 2, -1,
93
+ 3, 4,
94
+ -1, 5,
95
+ 12, -1,
96
+ 13, 6,
97
+ 14, 10,
98
+ -1, 11, // 25, 26
99
+ 30, 31, // Actually I2C, but not used
100
+ 21, -1,
101
+ 22, 26,
102
+ 23, -1,
103
+ 24, 27,
104
+ 25, 28,
105
+ -1, 29,
106
+ -1, -1,
107
+ -1, -1,
108
+ -1, -1,
109
+ -1, -1,
110
+ -1, -1,
111
+ 17, 18,
112
+ 19, 20,
113
+ -1, -1, -1, -1, -1, -1, -1, -1, -1
114
+ } ;
115
+
116
+ static char *physNames [64] =
117
+ {
118
+ NULL,
119
+
120
+ " 3.3v", "5v ",
121
+ " SDA.1", "5v ",
122
+ " SCL.1", "0v ",
123
+ "GPIO. 7", "TxD ",
124
+ " 0v", "RxD ",
125
+ "GPIO. 0", "GPIO. 1",
126
+ "GPIO. 2", "0v ",
127
+ "GPIO. 3", "GPIO. 4",
128
+ " 3.3v", "GPIO. 5",
129
+ " MOSI", "0v ",
130
+ " MISO", "GPIO. 6",
131
+ " SCLK", "CE0 ",
132
+ " 0v", "CE1 ",
133
+ " SDA.0", "SCL.0 ",
134
+ "GPIO.21", "0v ",
135
+ "GPIO.22", "GPIO.26",
136
+ "GPIO.23", "0v ",
137
+ "GPIO.24", "GPIO.27",
138
+ "GPIO.25", "GPIO.28",
139
+ " 0v", "GPIO.29",
140
+ NULL, NULL,
141
+ NULL, NULL,
142
+ NULL, NULL,
143
+ NULL, NULL,
144
+ NULL, NULL,
145
+ "GPIO.17", "GPIO.18",
146
+ "GPIO.19", "GPIO.20",
147
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
148
+ } ;
149
+
150
+
151
+ /*
152
+ * readallPhys:
153
+ * Given a physical pin output the data on it and the next pin:
154
+ *| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM |
155
+ *********************************************************************************
156
+ */
157
+
158
+ static void readallPhys (int physPin)
159
+ {
160
+ int pin ;
161
+
162
+ if (physPinToGpio (physPin) == -1)
163
+ printf (" | | ") ;
164
+ else
165
+ printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
166
+
167
+ printf (" | %s", physNames [physPin]) ;
168
+
169
+ if (physToWpi [physPin] == -1)
170
+ printf (" | | ") ;
171
+ else
172
+ {
173
+ /**/ if (wpMode == WPI_MODE_GPIO)
174
+ pin = physPinToGpio (physPin) ;
175
+ else if (wpMode == WPI_MODE_PHYS)
176
+ pin = physPin ;
177
+ else
178
+ pin = physToWpi [physPin] ;
179
+
180
+ printf (" | %4s", alts [getAlt (pin)]) ;
181
+ printf (" | %d", digitalRead (pin)) ;
182
+ }
183
+
184
+ // Pin numbers:
185
+
186
+ printf (" | %2d", physPin) ;
187
+ ++physPin ;
188
+ printf (" || %-2d", physPin) ;
189
+
190
+ // Same, reversed
191
+
192
+ if (physToWpi [physPin] == -1)
193
+ printf (" | | ") ;
194
+ else
195
+ {
196
+ /**/ if (wpMode == WPI_MODE_GPIO)
197
+ pin = physPinToGpio (physPin) ;
198
+ else if (wpMode == WPI_MODE_PHYS)
199
+ pin = physPin ;
200
+ else
201
+ pin = physToWpi [physPin] ;
202
+
203
+ printf (" | %d", digitalRead (pin)) ;
204
+ printf (" | %-4s", alts [getAlt (pin)]) ;
205
+ }
206
+
207
+ printf (" | %-5s", physNames [physPin]) ;
208
+
209
+ if (physToWpi [physPin] == -1)
210
+ printf (" | | ") ;
211
+ else
212
+ printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
213
+
214
+ printf (" |\n") ;
215
+ }
216
+
217
+
218
+ /*
219
+ * allReadall:
220
+ * Read all the pins regardless of the model. Primarily of use for
221
+ * the compute module, but handy for other fiddling...
222
+ *********************************************************************************
223
+ */
224
+
225
+ static void allReadall (void)
226
+ {
227
+ int pin ;
228
+
229
+ printf ("+-----+------+-------+ +-----+------+-------+\n") ;
230
+ printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
231
+ printf ("+-----+------+-------+ +-----+------+-------+\n") ;
232
+
233
+ for (pin = 0 ; pin < 27 ; ++pin)
234
+ {
235
+ printf ("| %3d ", pin) ;
236
+ printf ("| %-4s ", alts [getAlt (pin)]) ;
237
+ printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
238
+ printf ("| ") ;
239
+ printf ("| %3d ", pin + 27) ;
240
+ printf ("| %-4s ", alts [getAlt (pin + 27)]) ;
241
+ printf ("| %s ", digitalRead (pin + 27) == HIGH ? "High" : "Low ") ;
242
+ printf ("|\n") ;
243
+ }
244
+
245
+ printf ("+-----+------+-------+ +-----+------+-------+\n") ;
246
+
247
+ }
248
+
249
+
250
+ /*
251
+ * abReadall:
252
+ * Read all the pins on the model A or B.
253
+ *********************************************************************************
254
+ */
255
+
256
+ void abReadall (int model, int rev)
257
+ {
258
+ int pin ;
259
+ char *type ;
260
+
261
+ if (model == PI_MODEL_A)
262
+ type = " A" ;
263
+ else
264
+ if (rev == PI_VERSION_2)
265
+ type = "B2" ;
266
+ else
267
+ type = "B1" ;
268
+
269
+ printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
270
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
271
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
272
+ for (pin = 1 ; pin <= 26 ; pin += 2)
273
+ readallPhys (pin) ;
274
+
275
+ if (rev == PI_VERSION_2) // B version 2
276
+ {
277
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
278
+ for (pin = 51 ; pin <= 54 ; pin += 2)
279
+ readallPhys (pin) ;
280
+ }
281
+
282
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
283
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
284
+ printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
285
+ }
286
+
287
+
288
+ /*
289
+ * piPlusReadall:
290
+ * Read all the pins on the model A+ or the B+ or actually, all 40-pin Pi's
291
+ *********************************************************************************
292
+ */
293
+
294
+ static void plus2header (int model)
295
+ {
296
+ /**/ if (model == PI_MODEL_AP)
297
+ printf (" +-----+-----+---------+------+---+---Pi A+--+---+------+---------+-----+-----+\n") ;
298
+ else if (model == PI_MODEL_BP)
299
+ printf (" +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+\n") ;
300
+ else if (model == PI_MODEL_ZERO)
301
+ printf (" +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+\n") ;
302
+ else if (model == PI_MODEL_ZERO_W)
303
+ printf (" +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+\n") ;
304
+ else if (model == PI_MODEL_2)
305
+ printf (" +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+\n") ;
306
+ else if (model == PI_MODEL_3B)
307
+ printf (" +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+\n") ;
308
+ else if (model == PI_MODEL_3BP)
309
+ printf (" +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+\n") ;
310
+ else if (model == PI_MODEL_3AP)
311
+ printf (" +-----+-----+---------+------+---+---Pi 3A+-+---+------+---------+-----+-----+\n") ;
312
+ else if (model == PI_MODEL_4B)
313
+ printf (" +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+\n") ;
314
+ else if (model == PI_MODEL_400)
315
+ printf (" +-----+-----+---------+------+---+---Pi 400-+---+------+---------+-----+-----+\n") ;
316
+ else
317
+ printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ;
318
+ }
319
+
320
+
321
+ static void piPlusReadall (int model)
322
+ {
323
+ int pin ;
324
+
325
+ plus2header (model) ;
326
+
327
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
328
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
329
+ for (pin = 1 ; pin <= 40 ; pin += 2)
330
+ readallPhys (pin) ;
331
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
332
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
333
+
334
+ plus2header (model) ;
335
+ }
336
+
337
+
338
+ /*
339
+ * doReadall:
340
+ * Generic read all pins called from main program. Works out the Pi type
341
+ * and calls the appropriate function.
342
+ *********************************************************************************
343
+ */
344
+
345
+ void doReadall (void)
346
+ {
347
+ int model, rev, mem, maker, overVolted ;
348
+
349
+ if (wiringPiNodes != NULL) // External readall
350
+ {
351
+ doReadallExternal () ;
352
+ return ;
353
+ }
354
+
355
+ piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
356
+
357
+ /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
358
+ abReadall (model, rev) ;
359
+ else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) ||
360
+ (model == PI_MODEL_2) ||
361
+ (model == PI_MODEL_3AP) ||
362
+ (model == PI_MODEL_3B) || (model == PI_MODEL_3BP) ||
363
+ (model == PI_MODEL_4B) || (model == PI_MODEL_400) ||
364
+ (model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W))
365
+ piPlusReadall (model) ;
366
+ else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3) || (model == PI_MODEL_CM3P) || (model == PI_MODEL_CM4))
367
+ allReadall () ;
368
+ else
369
+ printf ("Oops - unable to determine board type... model: %d\n", model) ;
370
+ }
371
+
372
+
373
+ /*
374
+ * doAllReadall:
375
+ * Force reading of all pins regardless of Pi model
376
+ *********************************************************************************
377
+ */
378
+
379
+ void doAllReadall (void)
380
+ {
381
+ allReadall () ;
382
+ }
383
+
384
+
385
+ /*
386
+ * doQmode:
387
+ * Query mode on a pin
388
+ *********************************************************************************
389
+ */
390
+
391
+ void doQmode (int argc, char *argv [])
392
+ {
393
+ int pin ;
394
+
395
+ if (argc != 3)
396
+ {
397
+ fprintf (stderr, "Usage: %s qmode pin\n", argv [0]) ;
398
+ exit (EXIT_FAILURE) ;
399
+ }
400
+
401
+ pin = atoi (argv [2]) ;
402
+ printf ("%s\n", alts [getAlt (pin)]) ;
403
+ }
@@ -0,0 +1,3 @@
1
+ #define VERSION "2.60"
2
+ #define VERSION_MAJOR 2
3
+ #define VERSION_MINOR 60
@@ -0,0 +1,293 @@
1
+ /*
2
+ * ads1115.c:
3
+ * Extend wiringPi with the ADS1115 I2C 16-bit ADC
4
+ * Copyright (c) 2016 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
+ *********************************************************************************
27
+ * We're going to work in a hybrid mode to fit in with the wiringPi way of
28
+ * doing things, so there will be 4 analog pin which read the 4 single-ended
29
+ * channels as usual, also some fake digitalOutputs - these are the control
30
+ * registers that allow the user to put it into single/diff mode, set the
31
+ * gain and data rates.
32
+ *********************************************************************************
33
+ */
34
+
35
+ #include <byteswap.h>
36
+ #include <stdio.h>
37
+ #include <stdint.h>
38
+
39
+ #include <wiringPi.h>
40
+ #include <wiringPiI2C.h>
41
+
42
+ #include "ads1115.h"
43
+
44
+ // Bits in the config register (it's a 16-bit register)
45
+
46
+ #define CONFIG_OS_MASK (0x8000) // Operational Status Register
47
+ #define CONFIG_OS_SINGLE (0x8000) // Write - Starts a single-conversion
48
+ // Read 1 = Conversion complete
49
+
50
+ // The multiplexor
51
+
52
+ #define CONFIG_MUX_MASK (0x7000)
53
+
54
+ // Differential modes
55
+
56
+ #define CONFIG_MUX_DIFF_0_1 (0x0000) // Pos = AIN0, Neg = AIN1 (default)
57
+ #define CONFIG_MUX_DIFF_0_3 (0x1000) // Pos = AIN0, Neg = AIN3
58
+ #define CONFIG_MUX_DIFF_1_3 (0x2000) // Pos = AIN1, Neg = AIN3
59
+ #define CONFIG_MUX_DIFF_2_3 (0x3000) // Pos = AIN2, Neg = AIN3 (2nd differential channel)
60
+
61
+ // Single-ended modes
62
+
63
+ #define CONFIG_MUX_SINGLE_0 (0x4000) // AIN0
64
+ #define CONFIG_MUX_SINGLE_1 (0x5000) // AIN1
65
+ #define CONFIG_MUX_SINGLE_2 (0x6000) // AIN2
66
+ #define CONFIG_MUX_SINGLE_3 (0x7000) // AIN3
67
+
68
+ // Programmable Gain Amplifier
69
+
70
+ #define CONFIG_PGA_MASK (0x0E00)
71
+ #define CONFIG_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3
72
+ #define CONFIG_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
73
+ #define CONFIG_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default)
74
+ #define CONFIG_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
75
+ #define CONFIG_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
76
+ #define CONFIG_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
77
+
78
+ #define CONFIG_MODE (0x0100) // 0 is continuous, 1 is single-shot (default)
79
+
80
+ // Data Rate
81
+
82
+ #define CONFIG_DR_MASK (0x00E0)
83
+ #define CONFIG_DR_8SPS (0x0000) // 8 samples per second
84
+ #define CONFIG_DR_16SPS (0x0020) // 16 samples per second
85
+ #define CONFIG_DR_32SPS (0x0040) // 32 samples per second
86
+ #define CONFIG_DR_64SPS (0x0060) // 64 samples per second
87
+ #define CONFIG_DR_128SPS (0x0080) // 128 samples per second (default)
88
+ #define CONFIG_DR_475SPS (0x00A0) // 475 samples per second
89
+ #define CONFIG_DR_860SPS (0x00C0) // 860 samples per second
90
+
91
+ // Comparator mode
92
+
93
+ #define CONFIG_CMODE_MASK (0x0010)
94
+ #define CONFIG_CMODE_TRAD (0x0000) // Traditional comparator with hysteresis (default)
95
+ #define CONFIG_CMODE_WINDOW (0x0010) // Window comparator
96
+
97
+ // Comparator polarity - the polarity of the output alert/rdy pin
98
+
99
+ #define CONFIG_CPOL_MASK (0x0008)
100
+ #define CONFIG_CPOL_ACTVLOW (0x0000) // Active low (default)
101
+ #define CONFIG_CPOL_ACTVHI (0x0008) // Active high
102
+
103
+ // Latching comparator - does the alert/rdy pin latch
104
+
105
+ #define CONFIG_CLAT_MASK (0x0004)
106
+ #define CONFIG_CLAT_NONLAT (0x0000) // Non-latching comparator (default)
107
+ #define CONFIG_CLAT_LATCH (0x0004) // Latching comparator
108
+
109
+ // Comparitor queue
110
+
111
+ #define CONFIG_CQUE_MASK (0x0003)
112
+ #define CONFIG_CQUE_1CONV (0x0000) // Assert after one conversions
113
+ #define CONFIG_CQUE_2CONV (0x0001) // Assert after two conversions
114
+ #define CONFIG_CQUE_4CONV (0x0002) // Assert after four conversions
115
+ #define CONFIG_CQUE_NONE (0x0003) // Disable the comparator (default)
116
+
117
+ #define CONFIG_DEFAULT (0x8583) // From the datasheet
118
+
119
+
120
+ static const uint16_t dataRates [8] =
121
+ {
122
+ CONFIG_DR_8SPS, CONFIG_DR_16SPS, CONFIG_DR_32SPS, CONFIG_DR_64SPS, CONFIG_DR_128SPS, CONFIG_DR_475SPS, CONFIG_DR_860SPS
123
+ } ;
124
+
125
+ static const uint16_t gains [6] =
126
+ {
127
+ CONFIG_PGA_6_144V, CONFIG_PGA_4_096V, CONFIG_PGA_2_048V, CONFIG_PGA_1_024V, CONFIG_PGA_0_512V, CONFIG_PGA_0_256V
128
+ } ;
129
+
130
+
131
+ /*
132
+ * analogRead:
133
+ * Pin is the channel to sample on the device.
134
+ * Channels 0-3 are single ended inputs,
135
+ * channels 4-7 are the various differential combinations.
136
+ *********************************************************************************
137
+ */
138
+
139
+ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
140
+ {
141
+ int chan = pin - node->pinBase ;
142
+ int16_t result ;
143
+ uint16_t config = CONFIG_DEFAULT ;
144
+
145
+ chan &= 7 ;
146
+
147
+ // Setup the configuration register
148
+
149
+ // Set PGA/voltage range
150
+
151
+ config &= ~CONFIG_PGA_MASK ;
152
+ config |= node->data0 ;
153
+
154
+ // Set sample speed
155
+
156
+ config &= ~CONFIG_DR_MASK ;
157
+ config |= node->data1 ;
158
+
159
+ // Set single-ended channel or differential mode
160
+
161
+ config &= ~CONFIG_MUX_MASK ;
162
+
163
+ switch (chan)
164
+ {
165
+ case 0: config |= CONFIG_MUX_SINGLE_0 ; break ;
166
+ case 1: config |= CONFIG_MUX_SINGLE_1 ; break ;
167
+ case 2: config |= CONFIG_MUX_SINGLE_2 ; break ;
168
+ case 3: config |= CONFIG_MUX_SINGLE_3 ; break ;
169
+
170
+ case 4: config |= CONFIG_MUX_DIFF_0_1 ; break ;
171
+ case 5: config |= CONFIG_MUX_DIFF_2_3 ; break ;
172
+ case 6: config |= CONFIG_MUX_DIFF_0_3 ; break ;
173
+ case 7: config |= CONFIG_MUX_DIFF_1_3 ; break ;
174
+ }
175
+
176
+ // Start a single conversion
177
+
178
+ config |= CONFIG_OS_SINGLE ;
179
+ config = __bswap_16 (config) ;
180
+ wiringPiI2CWriteReg16 (node->fd, 1, config) ;
181
+
182
+ // Wait for the conversion to complete
183
+
184
+ for (;;)
185
+ {
186
+ result = wiringPiI2CReadReg16 (node->fd, 1) ;
187
+ result = __bswap_16 (result) ;
188
+ if ((result & CONFIG_OS_MASK) != 0)
189
+ break ;
190
+ delayMicroseconds (100) ;
191
+ }
192
+
193
+ result = wiringPiI2CReadReg16 (node->fd, 0) ;
194
+ result = __bswap_16 (result) ;
195
+
196
+ // Sometimes with a 0v input on a single-ended channel the internal 0v reference
197
+ // can be higher than the input, so you get a negative result...
198
+
199
+ if ( (chan < 4) && (result < 0) )
200
+ return 0 ;
201
+ else
202
+ return (int)result ;
203
+ }
204
+
205
+
206
+ /*
207
+ * digitalWrite:
208
+ * It may seem odd to have a digital write here, but it's the best way
209
+ * to pass paramters into the chip in the wiringPi way of things.
210
+ * We have 2 digital registers:
211
+ * 0 is the gain control
212
+ * 1 is the data rate control
213
+ *********************************************************************************
214
+ */
215
+
216
+ static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int data)
217
+ {
218
+ int chan = pin - node->pinBase ;
219
+ chan &= 3 ;
220
+
221
+ if (chan == 0) // Gain Control
222
+ {
223
+ if ( (data < 0) || (data > 6) ) // Use default if out of range
224
+ data = 2 ;
225
+ node->data0 = gains [data] ;
226
+ }
227
+ else // Data rate control
228
+ {
229
+ if ( (data < 0) || (data > 7) ) // Use default if out of range
230
+ data = 4 ;
231
+ node->data1 = dataRates [data] ; // Bugfix 0-1 by "Eric de jong (gm)" <ericdejong@gmx.net> - Thanks.
232
+ }
233
+
234
+ }
235
+
236
+
237
+ /*
238
+ * analogWrite:
239
+ * We're using this to write to the 2 comparitor threshold registers.
240
+ * We could use a digitalWrite here but as it's an analog comparison
241
+ * then it feels better to do it this way.
242
+ *********************************************************************************
243
+ */
244
+
245
+ static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int data)
246
+ {
247
+ int chan = pin - node->pinBase ;
248
+ int reg ;
249
+ int16_t ndata ;
250
+
251
+ chan &= 3 ;
252
+
253
+ reg = chan + 2 ;
254
+
255
+ /**/ if (data < -32767)
256
+ ndata = -32767 ;
257
+ else if (data > 32767)
258
+ ndata = 32767 ;
259
+ else
260
+ ndata = (int16_t)data ;
261
+
262
+ ndata = __bswap_16 (ndata) ;
263
+ wiringPiI2CWriteReg16 (node->fd, reg, data) ;
264
+ }
265
+
266
+
267
+
268
+ /*
269
+ * ads1115Setup:
270
+ * Create a new wiringPi device node for an ads1115 on the Pi's
271
+ * I2C interface.
272
+ *********************************************************************************
273
+ */
274
+
275
+ int ads1115Setup (const int pinBase, int i2cAddr)
276
+ {
277
+ struct wiringPiNodeStruct *node ;
278
+ int fd ;
279
+
280
+ if ((fd = wiringPiI2CSetup (i2cAddr)) < 0)
281
+ return FALSE ;
282
+
283
+ node = wiringPiNewNode (pinBase, 8) ;
284
+
285
+ node->fd = fd ;
286
+ node->data0 = CONFIG_PGA_4_096V ; // Gain in data0
287
+ node->data1 = CONFIG_DR_128SPS ; // Samples/sec in data1
288
+ node->analogRead = myAnalogRead ;
289
+ node->analogWrite = myAnalogWrite ;
290
+ node->digitalWrite = myDigitalWrite ;
291
+
292
+ return TRUE ;
293
+ }