wiringpi2 2.0.0

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 (71) hide show
  1. data/ext/wiringpi/WiringPi/examples/blink.c +50 -0
  2. data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
  3. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  4. data/ext/wiringpi/WiringPi/examples/gertboard.c +94 -0
  5. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  6. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  7. data/ext/wiringpi/WiringPi/examples/isr.c +99 -0
  8. data/ext/wiringpi/WiringPi/examples/lcd.c +129 -0
  9. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  10. data/ext/wiringpi/WiringPi/examples/okLed.c +83 -0
  11. data/ext/wiringpi/WiringPi/examples/piface.c +74 -0
  12. data/ext/wiringpi/WiringPi/examples/pwm.c +93 -0
  13. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  14. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  15. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  16. data/ext/wiringpi/WiringPi/examples/speed.c +123 -0
  17. data/ext/wiringpi/WiringPi/examples/test1.c +111 -0
  18. data/ext/wiringpi/WiringPi/examples/test2.c +58 -0
  19. data/ext/wiringpi/WiringPi/examples/tone.c +59 -0
  20. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  21. data/ext/wiringpi/WiringPi/gpio/gpio.c +1371 -0
  22. data/ext/wiringpi/WiringPi/wiringPi/ds1302.c +239 -0
  23. data/ext/wiringpi/WiringPi/wiringPi/ds1302.h +44 -0
  24. data/ext/wiringpi/WiringPi/wiringPi/gertboard.c +166 -0
  25. data/ext/wiringpi/WiringPi/wiringPi/gertboard.h +40 -0
  26. data/ext/wiringpi/WiringPi/wiringPi/lcd.c +380 -0
  27. data/ext/wiringpi/WiringPi/wiringPi/lcd.h +46 -0
  28. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +155 -0
  29. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  30. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  31. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  32. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +195 -0
  33. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  34. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
  35. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  36. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  37. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  38. data/ext/wiringpi/WiringPi/wiringPi/piFace.c +179 -0
  39. data/ext/wiringpi/WiringPi/wiringPi/piFace.h +32 -0
  40. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +50 -0
  41. data/ext/wiringpi/WiringPi/wiringPi/piNes.c +113 -0
  42. data/ext/wiringpi/WiringPi/wiringPi/piNes.h +45 -0
  43. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  44. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +130 -0
  45. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +34 -0
  46. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  47. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  48. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +121 -0
  49. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +38 -0
  50. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +108 -0
  51. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +33 -0
  52. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +1664 -0
  53. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +168 -0
  54. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +227 -0
  55. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  56. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +119 -0
  57. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
  58. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +213 -0
  59. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  60. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
  61. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
  62. data/ext/wiringpi/extconf.rb +8 -0
  63. data/ext/wiringpi/wiringpi_wrap.c +4378 -0
  64. data/lib/wiringpi/event.rb +21 -0
  65. data/lib/wiringpi/gpio.rb +131 -0
  66. data/lib/wiringpi/i2c.rb +26 -0
  67. data/lib/wiringpi/mcp23x17.rb +31 -0
  68. data/lib/wiringpi/serial.rb +49 -0
  69. data/lib/wiringpi/spi.rb +15 -0
  70. data/lib/wiringpi2.rb +42 -0
  71. metadata +122 -0
@@ -0,0 +1,239 @@
1
+ /*
2
+ * ds1302.c:
3
+ * Real Time clock
4
+ *
5
+ * Copyright (c) 2013 Gordon Henderson.
6
+ ***********************************************************************
7
+ * This file is part of wiringPi:
8
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
9
+ *
10
+ * wiringPi is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * wiringPi is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <stdint.h>
28
+ #include <stdarg.h>
29
+
30
+ #include "wiringPi.h"
31
+ #include "ds1302.h"
32
+
33
+ // Register defines
34
+
35
+ #define RTC_SECS 0
36
+ #define RTC_MINS 1
37
+ #define RTC_HOURS 2
38
+ #define RTC_DATE 3
39
+ #define RTC_MONTH 4
40
+ #define RTC_DAY 5
41
+ #define RTC_YEAR 6
42
+ #define RTC_WP 7
43
+ #define RTC_TC 8
44
+ #define RTC_BM 31
45
+
46
+
47
+ // Locals
48
+
49
+ static int dPin, cPin, sPin ;
50
+
51
+ /*
52
+ * dsShiftIn:
53
+ * Shift a number in from the chip, LSB first. Note that the data is
54
+ * sampled on the trailing edge of the last clock, so it's valid immediately.
55
+ *********************************************************************************
56
+ */
57
+
58
+ unsigned int dsShiftIn (void)
59
+ {
60
+ uint8_t value = 0 ;
61
+ int i ;
62
+
63
+ pinMode (dPin, INPUT) ; delayMicroseconds (1) ;
64
+
65
+ for (i = 0 ; i < 8 ; ++i)
66
+ {
67
+ value |= (digitalRead (dPin) << i) ;
68
+ digitalWrite (cPin, HIGH) ; delayMicroseconds (1) ;
69
+ digitalWrite (cPin, LOW) ; delayMicroseconds (1) ;
70
+ }
71
+
72
+ return value;
73
+ }
74
+
75
+
76
+ /*
77
+ * dsShiftOut:
78
+ * A normal LSB-first shift-out, just slowed down a bit - the Pi is
79
+ * a bit faster than the chip can handle.
80
+ *********************************************************************************
81
+ */
82
+
83
+ void dsShiftOut (unsigned int data)
84
+ {
85
+ int i ;
86
+
87
+ pinMode (dPin, OUTPUT) ;
88
+
89
+ for (i = 0 ; i < 8 ; ++i)
90
+ {
91
+ digitalWrite (dPin, data & (1 << i)) ; delayMicroseconds (1) ;
92
+ digitalWrite (cPin, HIGH) ; delayMicroseconds (1) ;
93
+ digitalWrite (cPin, LOW) ; delayMicroseconds (1) ;
94
+ }
95
+ }
96
+
97
+
98
+ /*
99
+ * ds1302regRead: ds1302regWrite:
100
+ * Read/Write a value to an RTC Register or RAM location on the chip
101
+ *********************************************************************************
102
+ */
103
+
104
+ static unsigned int ds1302regRead (int reg)
105
+ {
106
+ unsigned int data ;
107
+
108
+ digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
109
+ dsShiftOut (reg) ;
110
+ data = dsShiftIn () ;
111
+ digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
112
+
113
+ return data ;
114
+ }
115
+
116
+ static void ds1302regWrite (int reg, unsigned int data)
117
+ {
118
+ digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
119
+ dsShiftOut (reg) ;
120
+ dsShiftOut (data) ;
121
+ digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
122
+ }
123
+
124
+
125
+ /*
126
+ * ds1302rtcWrite: ds1302rtcRead:
127
+ * Writes/Reads the data to/from the RTC register
128
+ *********************************************************************************
129
+ */
130
+
131
+ unsigned int ds1302rtcRead (int reg)
132
+ {
133
+ return ds1302regRead (0x81 | ((reg & 0x1F) << 1)) ;
134
+ }
135
+
136
+ void ds1302rtcWrite (int reg, unsigned int data)
137
+ {
138
+ ds1302regWrite (0x80 | ((reg & 0x1F) << 1), data) ;
139
+ }
140
+
141
+
142
+ /*
143
+ * ds1302ramWrite: ds1302ramRead:
144
+ * Writes/Reads the data to/from the RTC register
145
+ *********************************************************************************
146
+ */
147
+
148
+ unsigned int ds1302ramRead (int addr)
149
+ {
150
+ return ds1302regRead (0xC1 | ((addr & 0x1F) << 1)) ;
151
+ }
152
+
153
+ void ds1302ramWrite (int addr, unsigned int data)
154
+ {
155
+ ds1302regWrite ( 0xC0 | ((addr & 0x1F) << 1), data) ;
156
+ }
157
+
158
+ /*
159
+ * ds1302clockRead:
160
+ * Read all 8 bytes of the clock in a single operation
161
+ *********************************************************************************
162
+ */
163
+
164
+ void ds1302clockRead (int clockData [8])
165
+ {
166
+ int i ;
167
+ unsigned int regVal = 0x81 | ((RTC_BM & 0x1F) << 1) ;
168
+
169
+ digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
170
+
171
+ dsShiftOut (regVal) ;
172
+ for (i = 0 ; i < 8 ; ++i)
173
+ clockData [i] = dsShiftIn () ;
174
+
175
+ digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
176
+ }
177
+
178
+
179
+ /*
180
+ * ds1302clockWrite:
181
+ * Write all 8 bytes of the clock in a single operation
182
+ *********************************************************************************
183
+ */
184
+
185
+ void ds1302clockWrite (int clockData [8])
186
+ {
187
+ int i ;
188
+ unsigned int regVal = 0x80 | ((RTC_BM & 0x1F) << 1) ;
189
+
190
+ digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
191
+
192
+ dsShiftOut (regVal) ;
193
+ for (i = 0 ; i < 8 ; ++i)
194
+ dsShiftOut (clockData [i]) ;
195
+
196
+ digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
197
+ }
198
+
199
+
200
+ /*
201
+ * ds1302trickleCharge:
202
+ * Set the bits on the trickle charger.
203
+ * Probably best left alone...
204
+ *********************************************************************************
205
+ */
206
+
207
+ void ds1302trickleCharge (int diodes, int resistors)
208
+ {
209
+ if (diodes + resistors == 0)
210
+ ds1302rtcWrite (RTC_TC, 0x5C) ; // Disabled
211
+ else
212
+ ds1302rtcWrite (RTC_TC, 0xA0 | ((diodes & 3) << 2) | (resistors & 3)) ;
213
+ }
214
+
215
+
216
+
217
+
218
+ /*
219
+ * ds1302setup:
220
+ * Initialise the chip & remember the pins we're using
221
+ *********************************************************************************
222
+ */
223
+
224
+ void ds1302setup (int clockPin, int dataPin, int csPin)
225
+ {
226
+ dPin = dataPin ;
227
+ cPin = clockPin ;
228
+ sPin = csPin ;
229
+
230
+ digitalWrite (dPin, LOW) ;
231
+ digitalWrite (cPin, LOW) ;
232
+ digitalWrite (sPin, LOW) ;
233
+
234
+ pinMode (dPin, OUTPUT) ;
235
+ pinMode (cPin, OUTPUT) ;
236
+ pinMode (sPin, OUTPUT) ;
237
+
238
+ ds1302rtcWrite (RTC_WP, 0) ; // Remove write-protect
239
+ }
@@ -0,0 +1,44 @@
1
+ /*
2
+ * ds1302.h:
3
+ * Real Time clock
4
+ *
5
+ * Copyright (c) 2013 Gordon Henderson.
6
+ ***********************************************************************
7
+ * This file is part of wiringPi:
8
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
9
+ *
10
+ * wiringPi is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * wiringPi is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ extern unsigned int ds1302rtcRead (int reg) ;
30
+ extern void ds1302rtcWrite (int reg, unsigned int data) ;
31
+
32
+ extern unsigned int ds1302ramRead (int addr) ;
33
+ extern void ds1302ramWrite (int addr, unsigned int data) ;
34
+
35
+ extern void ds1302clockRead (int clockData [8]) ;
36
+ extern void ds1302clockWrite (int clockData [8]) ;
37
+
38
+ extern void ds1302trickleCharge (int diodes, int resistors) ;
39
+
40
+ extern void ds1302setup (int clockPin, int dataPin, int csPin) ;
41
+
42
+ #ifdef __cplusplus
43
+ }
44
+ #endif
@@ -0,0 +1,166 @@
1
+ /*
2
+ * gertboard.c:
3
+ * Access routines for the SPI devices on the Gertboard
4
+ * Copyright (c) 2012 Gordon Henderson
5
+ *
6
+ * The Gertboard has:
7
+ *
8
+ * An MCP3002 dual-channel A to D convertor connected
9
+ * to the SPI bus, selected by chip-select A, and:
10
+ *
11
+ * An MCP4802 dual-channel D to A convertor connected
12
+ * to the SPI bus, selected via chip-select B.
13
+ *
14
+ ***********************************************************************
15
+ * This file is part of wiringPi:
16
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
17
+ *
18
+ * wiringPi is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU Lesser General Public License as
20
+ * published by the Free Software Foundation, either version 3 of the
21
+ * License, or (at your option) any later version.
22
+ *
23
+ * wiringPi is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU Lesser General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU Lesser General Public
29
+ * License along with wiringPi.
30
+ * If not, see <http://www.gnu.org/licenses/>.
31
+ ***********************************************************************
32
+ */
33
+
34
+
35
+ #include <stdio.h>
36
+ #include <stdint.h>
37
+ #include <fcntl.h>
38
+ #include <sys/ioctl.h>
39
+ #include <linux/spi/spidev.h>
40
+
41
+ #include "wiringPi.h"
42
+ #include "wiringPiSPI.h"
43
+
44
+ #include "gertboard.h"
45
+
46
+ // The A-D convertor won't run at more than 1MHz @ 3.3v
47
+
48
+ #define SPI_ADC_SPEED 1000000
49
+ #define SPI_DAC_SPEED 1000000
50
+ #define SPI_A2D 0
51
+ #define SPI_D2A 1
52
+
53
+
54
+ /*
55
+ * gertboardAnalogWrite:
56
+ * Write an 8-bit data value to the MCP4802 Analog to digital
57
+ * convertor on the Gertboard.
58
+ *********************************************************************************
59
+ */
60
+
61
+ void gertboardAnalogWrite (int chan, int value)
62
+ {
63
+ uint8_t spiData [2] ;
64
+ uint8_t chanBits, dataBits ;
65
+
66
+ if (chan == 0)
67
+ chanBits = 0x30 ;
68
+ else
69
+ chanBits = 0xB0 ;
70
+
71
+ chanBits |= ((value >> 4) & 0x0F) ;
72
+ dataBits = ((value << 4) & 0xF0) ;
73
+
74
+ spiData [0] = chanBits ;
75
+ spiData [1] = dataBits ;
76
+
77
+ wiringPiSPIDataRW (SPI_D2A, spiData, 2) ;
78
+ }
79
+
80
+
81
+ /*
82
+ * gertboardAnalogRead:
83
+ * Return the analog value of the given channel (0/1).
84
+ * The A/D is a 10-bit device
85
+ *********************************************************************************
86
+ */
87
+
88
+ int gertboardAnalogRead (int chan)
89
+ {
90
+ uint8_t spiData [2] ;
91
+
92
+ uint8_t chanBits ;
93
+
94
+ if (chan == 0)
95
+ chanBits = 0b11010000 ;
96
+ else
97
+ chanBits = 0b11110000 ;
98
+
99
+ spiData [0] = chanBits ;
100
+ spiData [1] = 0 ;
101
+
102
+ wiringPiSPIDataRW (SPI_A2D, spiData, 2) ;
103
+
104
+ return ((spiData [0] << 7) | (spiData [1] >> 1)) & 0x3FF ;
105
+ }
106
+
107
+
108
+ /*
109
+ * gertboardSPISetup:
110
+ * Initialise the SPI bus, etc.
111
+ *********************************************************************************
112
+ */
113
+
114
+ int gertboardSPISetup (void)
115
+ {
116
+ if (wiringPiSPISetup (SPI_A2D, SPI_ADC_SPEED) < 0)
117
+ return -1 ;
118
+
119
+ if (wiringPiSPISetup (SPI_D2A, SPI_DAC_SPEED) < 0)
120
+ return -1 ;
121
+
122
+ return 0 ;
123
+ }
124
+
125
+
126
+ /*
127
+ * New wiringPi node extension methods.
128
+ *********************************************************************************
129
+ */
130
+
131
+ int gbWiringPiAnalogRead (struct wiringPiNodeStruct *node, int chan)
132
+ {
133
+ chan -= node->pinBase ;
134
+ return gertboardAnalogRead (chan) ;
135
+ }
136
+
137
+ void gbWiringPiAnalogWrite (struct wiringPiNodeStruct *node, int chan, int value)
138
+ {
139
+ chan -= node->pinBase ;
140
+ gertboardAnalogWrite (chan, value) ;
141
+ }
142
+
143
+
144
+ /*
145
+ * gertboardAnalogSetup:
146
+ * Create a new wiringPi device node for the analog devices on the
147
+ * Gertboard. We create one node with 2 pins - each pin being read
148
+ * and write - although the operations actually go to different
149
+ * hardware devices.
150
+ *********************************************************************************
151
+ */
152
+
153
+ int gertboardAnalogSetup (int pinBase)
154
+ {
155
+ struct wiringPiNodeStruct *node ;
156
+ int x ;
157
+
158
+ if (( x = gertboardSPISetup ()) != 0)
159
+ return x;
160
+
161
+ node = wiringPiNewNode (pinBase, 2) ;
162
+ node->analogRead = gbWiringPiAnalogRead ;
163
+ node->analogWrite = gbWiringPiAnalogWrite ;
164
+
165
+ return 0 ;
166
+ }