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,33 @@
1
+ /*
2
+ * 23s08.h:
3
+ * Extend wiringPi with the MCP 23s08 SPI GPIO expander chip
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
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ extern int mcp23s08Setup (int pinBase, int spiPort, int devId) ;
30
+
31
+ #ifdef __cplusplus
32
+ }
33
+ #endif
@@ -0,0 +1,236 @@
1
+ /*
2
+ * mcp23s17.c:
3
+ * Extend wiringPi with the MCP 23s17 SPI GPIO expander chip
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
+ #include <stdio.h>
26
+ #include <stdint.h>
27
+
28
+ #include "wiringPi.h"
29
+ #include "wiringPiSPI.h"
30
+ #include "mcp23x0817.h"
31
+
32
+ #include "mcp23s17.h"
33
+
34
+ #define MCP_SPEED 4000000
35
+
36
+
37
+
38
+ /*
39
+ * writeByte:
40
+ * Write a byte to a register on the MCP23s17 on the SPI bus.
41
+ *********************************************************************************
42
+ */
43
+
44
+ static void writeByte (uint8_t spiPort, uint8_t devId, uint8_t reg, uint8_t data)
45
+ {
46
+ uint8_t spiData [4] ;
47
+
48
+ spiData [0] = CMD_WRITE | ((devId & 7) << 1) ;
49
+ spiData [1] = reg ;
50
+ spiData [2] = data ;
51
+
52
+ wiringPiSPIDataRW (spiPort, spiData, 3) ;
53
+ }
54
+
55
+ /*
56
+ * readByte:
57
+ * Read a byte from a register on the MCP23s17 on the SPI bus.
58
+ *********************************************************************************
59
+ */
60
+
61
+ static uint8_t readByte (uint8_t spiPort, uint8_t devId, uint8_t reg)
62
+ {
63
+ uint8_t spiData [4] ;
64
+
65
+ spiData [0] = CMD_READ | ((devId & 7) << 1) ;
66
+ spiData [1] = reg ;
67
+
68
+ wiringPiSPIDataRW (spiPort, spiData, 3) ;
69
+
70
+ return spiData [2] ;
71
+ }
72
+
73
+
74
+ /*
75
+ * myPinMode:
76
+ *********************************************************************************
77
+ */
78
+
79
+ static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
80
+ {
81
+ int mask, old, ddr ;
82
+
83
+ pin -= node->pinBase ;
84
+
85
+ if (pin < 8) // Bank A
86
+ ddr = MCP23x17_IODIRA ;
87
+ else
88
+ {
89
+ ddr = MCP23x17_IODIRB ;
90
+ pin &= 0x07 ;
91
+ }
92
+
93
+ mask = 1 << pin ;
94
+ old = readByte (node->data0, node->data1, ddr) ;
95
+
96
+ if (mode == OUTPUT)
97
+ old &= (~mask) ;
98
+ else
99
+ old |= mask ;
100
+
101
+ writeByte (node->data0, node->data1, ddr, old) ;
102
+ }
103
+
104
+
105
+ /*
106
+ * myPullUpDnControl:
107
+ *********************************************************************************
108
+ */
109
+
110
+ static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
111
+ {
112
+ int mask, old, pud ;
113
+
114
+ pin -= node->pinBase ;
115
+
116
+ if (pin < 8) // Bank A
117
+ pud = MCP23x17_GPPUA ;
118
+ else
119
+ {
120
+ pud = MCP23x17_GPPUB ;
121
+ pin &= 0x07 ;
122
+ }
123
+
124
+ mask = 1 << pin ;
125
+ old = readByte (node->data0, node->data1, pud) ;
126
+
127
+ if (mode == PUD_UP)
128
+ old |= mask ;
129
+ else
130
+ old &= (~mask) ;
131
+
132
+ writeByte (node->data0, node->data1, pud, old) ;
133
+ }
134
+
135
+
136
+ /*
137
+ * myDigitalWrite:
138
+ *********************************************************************************
139
+ */
140
+
141
+ static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
142
+ {
143
+ int bit, old ;
144
+
145
+ pin -= node->pinBase ; // Pin now 0-15
146
+
147
+ bit = 1 << (pin & 7) ;
148
+
149
+ if (pin < 8) // Bank A
150
+ {
151
+ old = node->data2 ;
152
+
153
+ if (value == LOW)
154
+ old &= (~bit) ;
155
+ else
156
+ old |= bit ;
157
+
158
+ writeByte (node->data0, node->data1, MCP23x17_GPIOA, old) ;
159
+ node->data2 = old ;
160
+ }
161
+ else // Bank B
162
+ {
163
+ old = node->data3 ;
164
+
165
+ if (value == LOW)
166
+ old &= (~bit) ;
167
+ else
168
+ old |= bit ;
169
+
170
+ writeByte (node->data0, node->data1, MCP23x17_GPIOB, old) ;
171
+ node->data3 = old ;
172
+ }
173
+ }
174
+
175
+
176
+ /*
177
+ * myDigitalRead:
178
+ *********************************************************************************
179
+ */
180
+
181
+ static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
182
+ {
183
+ int mask, value, gpio ;
184
+
185
+ pin -= node->pinBase ;
186
+
187
+ if (pin < 8) // Bank A
188
+ gpio = MCP23x17_GPIOA ;
189
+ else
190
+ {
191
+ gpio = MCP23x17_GPIOB ;
192
+ pin &= 0x07 ;
193
+ }
194
+
195
+ mask = 1 << pin ;
196
+ value = readByte (node->data0, node->data1, gpio) ;
197
+
198
+ if ((value & mask) == 0)
199
+ return LOW ;
200
+ else
201
+ return HIGH ;
202
+ }
203
+
204
+
205
+ /*
206
+ * mcp23s17Setup:
207
+ * Create a new instance of an MCP23s17 SPI GPIO interface. We know it
208
+ * has 16 pins, so all we need to know here is the SPI address and the
209
+ * user-defined pin base.
210
+ *********************************************************************************
211
+ */
212
+
213
+ int mcp23s17Setup (int pinBase, int spiPort, int devId)
214
+ {
215
+ int x ;
216
+ struct wiringPiNodeStruct *node ;
217
+
218
+ if ((x = wiringPiSPISetup (spiPort, MCP_SPEED)) < 0)
219
+ return x ;
220
+
221
+ writeByte (spiPort, devId, MCP23x17_IOCON, IOCON_INIT | IOCON_HAEN) ;
222
+ writeByte (spiPort, devId, MCP23x17_IOCONB, IOCON_INIT | IOCON_HAEN) ;
223
+
224
+ node = wiringPiNewNode (pinBase, 16) ;
225
+
226
+ node->data0 = spiPort ;
227
+ node->data1 = devId ;
228
+ node->pinMode = myPinMode ;
229
+ node->pullUpDnControl = myPullUpDnControl ;
230
+ node->digitalRead = myDigitalRead ;
231
+ node->digitalWrite = myDigitalWrite ;
232
+ node->data2 = readByte (spiPort, devId, MCP23x17_OLATA) ;
233
+ node->data3 = readByte (spiPort, devId, MCP23x17_OLATB) ;
234
+
235
+ return 0 ;
236
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ * 23s17.h:
3
+ * Extend wiringPi with the MCP 23s17 SPI GPIO expander chip
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
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ;
30
+
31
+ #ifdef __cplusplus
32
+ }
33
+ #endif
@@ -0,0 +1,73 @@
1
+ /*
2
+ * mcp23x17:
3
+ * Copyright (c) 2012-2013 Gordon Henderson
4
+ *
5
+ * Header file for code using the MCP23x17 GPIO expander chip.
6
+ * This comes in 2 flavours: MCP23017 which has an I2C interface,
7
+ * an the MXP23S17 which has an SPI interface.
8
+ ***********************************************************************
9
+ * This file is part of wiringPi:
10
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
11
+ *
12
+ * wiringPi is free software: you can redistribute it and/or modify
13
+ * it under the terms of the GNU Lesser General Public License as
14
+ * published by the Free Software Foundation, either version 3 of the
15
+ * License, or (at your option) any later version.
16
+ *
17
+ * wiringPi is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ * GNU Lesser General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU Lesser General Public
23
+ * License along with wiringPi.
24
+ * If not, see <http://www.gnu.org/licenses/>.
25
+ ***********************************************************************
26
+ */
27
+
28
+
29
+ // MCP23x17 Registers
30
+
31
+ #define IODIRA 0x00
32
+ #define IPOLA 0x02
33
+ #define GPINTENA 0x04
34
+ #define DEFVALA 0x06
35
+ #define INTCONA 0x08
36
+ #define IOCON 0x0A
37
+ #define GPPUA 0x0C
38
+ #define INTFA 0x0E
39
+ #define INTCAPA 0x10
40
+ #define GPIOA 0x12
41
+ #define OLATA 0x14
42
+
43
+ #define IODIRB 0x01
44
+ #define IPOLB 0x03
45
+ #define GPINTENB 0x05
46
+ #define DEFVALB 0x07
47
+ #define INTCONB 0x09
48
+ #define IOCONB 0x0B
49
+ #define GPPUB 0x0D
50
+ #define INTFB 0x0F
51
+ #define INTCAPB 0x11
52
+ #define GPIOB 0x13
53
+ #define OLATB 0x15
54
+
55
+ // Bits in the IOCON register
56
+
57
+ #define IOCON_UNUSED 0x01
58
+ #define IOCON_INTPOL 0x02
59
+ #define IOCON_ODR 0x04
60
+ #define IOCON_HAEN 0x08
61
+ #define IOCON_DISSLW 0x10
62
+ #define IOCON_SEQOP 0x20
63
+ #define IOCON_MIRROR 0x40
64
+ #define IOCON_BANK_MODE 0x80
65
+
66
+ // Default initialisation mode
67
+
68
+ #define IOCON_INIT (IOCON_SEQOP)
69
+
70
+ // SPI Command codes
71
+
72
+ #define CMD_WRITE 0x40
73
+ #define CMD_READ 0x41
@@ -0,0 +1,87 @@
1
+ /*
2
+ * mcp23xxx:
3
+ * Copyright (c) 2012-2013 Gordon Henderson
4
+ *
5
+ * Header file for code using the MCP23x08 and 17 GPIO expander
6
+ * chips.
7
+ * This comes in 2 flavours: MCP230xx (08/17) which has an I2C
8
+ * interface, and the MXP23Sxx (08/17) which has an SPI interface.
9
+ ***********************************************************************
10
+ * This file is part of wiringPi:
11
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
12
+ *
13
+ * wiringPi is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU Lesser General Public License as
15
+ * published by the Free Software Foundation, either version 3 of the
16
+ * License, or (at your option) any later version.
17
+ *
18
+ * wiringPi is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU Lesser General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU Lesser General Public
24
+ * License along with wiringPi.
25
+ * If not, see <http://www.gnu.org/licenses/>.
26
+ ***********************************************************************
27
+ */
28
+
29
+ // MCP23x08 Registers
30
+
31
+ #define MCP23x08_IODIR 0x00
32
+ #define MCP23x08_IPOL 0x01
33
+ #define MCP23x08_GPINTEN 0x02
34
+ #define MCP23x08_DEFVAL 0x03
35
+ #define MCP23x08_INTCON 0x04
36
+ #define MCP23x08_IOCON 0x05
37
+ #define MCP23x08_GPPU 0x06
38
+ #define MCP23x08_INTF 0x07
39
+ #define MCP23x08_INTCAP 0x08
40
+ #define MCP23x08_GPIO 0x09
41
+ #define MCP23x08_OLAT 0x0A
42
+
43
+ // MCP23x17 Registers
44
+
45
+ #define MCP23x17_IODIRA 0x00
46
+ #define MCP23x17_IPOLA 0x02
47
+ #define MCP23x17_GPINTENA 0x04
48
+ #define MCP23x17_DEFVALA 0x06
49
+ #define MCP23x17_INTCONA 0x08
50
+ #define MCP23x17_IOCON 0x0A
51
+ #define MCP23x17_GPPUA 0x0C
52
+ #define MCP23x17_INTFA 0x0E
53
+ #define MCP23x17_INTCAPA 0x10
54
+ #define MCP23x17_GPIOA 0x12
55
+ #define MCP23x17_OLATA 0x14
56
+
57
+ #define MCP23x17_IODIRB 0x01
58
+ #define MCP23x17_IPOLB 0x03
59
+ #define MCP23x17_GPINTENB 0x05
60
+ #define MCP23x17_DEFVALB 0x07
61
+ #define MCP23x17_INTCONB 0x09
62
+ #define MCP23x17_IOCONB 0x0B
63
+ #define MCP23x17_GPPUB 0x0D
64
+ #define MCP23x17_INTFB 0x0F
65
+ #define MCP23x17_INTCAPB 0x11
66
+ #define MCP23x17_GPIOB 0x13
67
+ #define MCP23x17_OLATB 0x15
68
+
69
+ // Bits in the IOCON register
70
+
71
+ #define IOCON_UNUSED 0x01
72
+ #define IOCON_INTPOL 0x02
73
+ #define IOCON_ODR 0x04
74
+ #define IOCON_HAEN 0x08
75
+ #define IOCON_DISSLW 0x10
76
+ #define IOCON_SEQOP 0x20
77
+ #define IOCON_MIRROR 0x40
78
+ #define IOCON_BANK_MODE 0x80
79
+
80
+ // Default initialisation mode
81
+
82
+ #define IOCON_INIT (IOCON_SEQOP)
83
+
84
+ // SPI Command codes
85
+
86
+ #define CMD_WRITE 0x40
87
+ #define CMD_READ 0x41