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.
- checksums.yaml +4 -4
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +238 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +177 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.c +430 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
- data/ext/wiringpi/WiringPi/examples/blink-thread.c +61 -0
- data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
- data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
- data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
- data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
- data/ext/wiringpi/WiringPi/examples/blink8-drcn.c +61 -0
- data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +102 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
- data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
- data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
- data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
- data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
- data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
- data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +86 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
- data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
- data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1538 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
- data/ext/wiringpi/WiringPi/version.h +3 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
- data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +188 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +125 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.c +95 -0
- data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
- data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +186 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2507 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
- data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
- data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
- data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
- data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
- metadata +155 -1
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* 23008.h:
|
3
|
+
* Extend wiringPi with the MCP 23008 I2C 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 mcp23008Setup (const int pinBase, const int i2cAddress) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,164 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23016.c:
|
3
|
+
* Extend wiringPi with the MCP 23016 I2C 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 <pthread.h>
|
27
|
+
|
28
|
+
#include "wiringPi.h"
|
29
|
+
#include "wiringPiI2C.h"
|
30
|
+
#include "mcp23016.h"
|
31
|
+
|
32
|
+
#include "mcp23016reg.h"
|
33
|
+
|
34
|
+
|
35
|
+
/*
|
36
|
+
* myPinMode:
|
37
|
+
*********************************************************************************
|
38
|
+
*/
|
39
|
+
|
40
|
+
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
|
41
|
+
{
|
42
|
+
int mask, old, reg ;
|
43
|
+
|
44
|
+
pin -= node->pinBase ;
|
45
|
+
|
46
|
+
if (pin < 8) // Bank A
|
47
|
+
reg = MCP23016_IODIR0 ;
|
48
|
+
else
|
49
|
+
{
|
50
|
+
reg = MCP23016_IODIR1 ;
|
51
|
+
pin &= 0x07 ;
|
52
|
+
}
|
53
|
+
|
54
|
+
mask = 1 << pin ;
|
55
|
+
old = wiringPiI2CReadReg8 (node->fd, reg) ;
|
56
|
+
|
57
|
+
if (mode == OUTPUT)
|
58
|
+
old &= (~mask) ;
|
59
|
+
else
|
60
|
+
old |= mask ;
|
61
|
+
|
62
|
+
wiringPiI2CWriteReg8 (node->fd, reg, old) ;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* myDigitalWrite:
|
68
|
+
*********************************************************************************
|
69
|
+
*/
|
70
|
+
|
71
|
+
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
72
|
+
{
|
73
|
+
int bit, old ;
|
74
|
+
|
75
|
+
pin -= node->pinBase ; // Pin now 0-15
|
76
|
+
|
77
|
+
bit = 1 << (pin & 7) ;
|
78
|
+
|
79
|
+
if (pin < 8) // Bank A
|
80
|
+
{
|
81
|
+
old = node->data2 ;
|
82
|
+
|
83
|
+
if (value == LOW)
|
84
|
+
old &= (~bit) ;
|
85
|
+
else
|
86
|
+
old |= bit ;
|
87
|
+
|
88
|
+
wiringPiI2CWriteReg8 (node->fd, MCP23016_GP0, old) ;
|
89
|
+
node->data2 = old ;
|
90
|
+
}
|
91
|
+
else // Bank B
|
92
|
+
{
|
93
|
+
old = node->data3 ;
|
94
|
+
|
95
|
+
if (value == LOW)
|
96
|
+
old &= (~bit) ;
|
97
|
+
else
|
98
|
+
old |= bit ;
|
99
|
+
|
100
|
+
wiringPiI2CWriteReg8 (node->fd, MCP23016_GP1, old) ;
|
101
|
+
node->data3 = old ;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
/*
|
107
|
+
* myDigitalRead:
|
108
|
+
*********************************************************************************
|
109
|
+
*/
|
110
|
+
|
111
|
+
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
112
|
+
{
|
113
|
+
int mask, value, gpio ;
|
114
|
+
|
115
|
+
pin -= node->pinBase ;
|
116
|
+
|
117
|
+
if (pin < 8) // Bank A
|
118
|
+
gpio = MCP23016_GP0 ;
|
119
|
+
else
|
120
|
+
{
|
121
|
+
gpio = MCP23016_GP1 ;
|
122
|
+
pin &= 0x07 ;
|
123
|
+
}
|
124
|
+
|
125
|
+
mask = 1 << pin ;
|
126
|
+
value = wiringPiI2CReadReg8 (node->fd, gpio) ;
|
127
|
+
|
128
|
+
if ((value & mask) == 0)
|
129
|
+
return LOW ;
|
130
|
+
else
|
131
|
+
return HIGH ;
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
/*
|
136
|
+
* mcp23016Setup:
|
137
|
+
* Create a new instance of an MCP23016 I2C GPIO interface. We know it
|
138
|
+
* has 16 pins, so all we need to know here is the I2C address and the
|
139
|
+
* user-defined pin base.
|
140
|
+
*********************************************************************************
|
141
|
+
*/
|
142
|
+
|
143
|
+
int mcp23016Setup (const int pinBase, const int i2cAddress)
|
144
|
+
{
|
145
|
+
int fd ;
|
146
|
+
struct wiringPiNodeStruct *node ;
|
147
|
+
|
148
|
+
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
149
|
+
return FALSE ;
|
150
|
+
|
151
|
+
wiringPiI2CWriteReg8 (fd, MCP23016_IOCON0, IOCON_INIT) ;
|
152
|
+
wiringPiI2CWriteReg8 (fd, MCP23016_IOCON1, IOCON_INIT) ;
|
153
|
+
|
154
|
+
node = wiringPiNewNode (pinBase, 16) ;
|
155
|
+
|
156
|
+
node->fd = fd ;
|
157
|
+
node->pinMode = myPinMode ;
|
158
|
+
node->digitalRead = myDigitalRead ;
|
159
|
+
node->digitalWrite = myDigitalWrite ;
|
160
|
+
node->data2 = wiringPiI2CReadReg8 (fd, MCP23016_OLAT0) ;
|
161
|
+
node->data3 = wiringPiI2CReadReg8 (fd, MCP23016_OLAT1) ;
|
162
|
+
|
163
|
+
return TRUE ;
|
164
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23016.h:
|
3
|
+
* Extend wiringPi with the MCP 23016 I2C 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 mcp23016Setup (const int pinBase, const int i2cAddress) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23016:
|
3
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
4
|
+
*
|
5
|
+
* Header file for code using the MCP23016 GPIO expander
|
6
|
+
* chip.
|
7
|
+
***********************************************************************
|
8
|
+
* This file is part of wiringPi:
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
10
|
+
*
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU Lesser General Public License as
|
13
|
+
* published by the Free Software Foundation, either version 3 of the
|
14
|
+
* License, or (at your option) any later version.
|
15
|
+
*
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU Lesser General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU Lesser General Public
|
22
|
+
* License along with wiringPi.
|
23
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
24
|
+
***********************************************************************
|
25
|
+
*/
|
26
|
+
|
27
|
+
// MCP23016 Registers
|
28
|
+
|
29
|
+
#define MCP23016_GP0 0x00
|
30
|
+
#define MCP23016_GP1 0x01
|
31
|
+
#define MCP23016_OLAT0 0x02
|
32
|
+
#define MCP23016_OLAT1 0x03
|
33
|
+
#define MCP23016_IPOL0 0x04
|
34
|
+
#define MCP23016_IPOL1 0x05
|
35
|
+
#define MCP23016_IODIR0 0x06
|
36
|
+
#define MCP23016_IODIR1 0x07
|
37
|
+
#define MCP23016_INTCAP0 0x08
|
38
|
+
#define MCP23016_INTCAP1 0x09
|
39
|
+
#define MCP23016_IOCON0 0x0A
|
40
|
+
#define MCP23016_IOCON1 0x0B
|
41
|
+
|
42
|
+
// Bits in the IOCON register
|
43
|
+
|
44
|
+
#define IOCON_IARES 0x01
|
45
|
+
|
46
|
+
// Default initialisation mode
|
47
|
+
|
48
|
+
#define IOCON_INIT 0
|
@@ -0,0 +1,195 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23017.c:
|
3
|
+
* Extend wiringPi with the MCP 23017 I2C 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 <pthread.h>
|
27
|
+
|
28
|
+
#include "wiringPi.h"
|
29
|
+
#include "wiringPiI2C.h"
|
30
|
+
#include "mcp23x0817.h"
|
31
|
+
|
32
|
+
#include "mcp23017.h"
|
33
|
+
|
34
|
+
|
35
|
+
/*
|
36
|
+
* myPinMode:
|
37
|
+
*********************************************************************************
|
38
|
+
*/
|
39
|
+
|
40
|
+
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
|
41
|
+
{
|
42
|
+
int mask, old, reg ;
|
43
|
+
|
44
|
+
pin -= node->pinBase ;
|
45
|
+
|
46
|
+
if (pin < 8) // Bank A
|
47
|
+
reg = MCP23x17_IODIRA ;
|
48
|
+
else
|
49
|
+
{
|
50
|
+
reg = MCP23x17_IODIRB ;
|
51
|
+
pin &= 0x07 ;
|
52
|
+
}
|
53
|
+
|
54
|
+
mask = 1 << pin ;
|
55
|
+
old = wiringPiI2CReadReg8 (node->fd, reg) ;
|
56
|
+
|
57
|
+
if (mode == OUTPUT)
|
58
|
+
old &= (~mask) ;
|
59
|
+
else
|
60
|
+
old |= mask ;
|
61
|
+
|
62
|
+
wiringPiI2CWriteReg8 (node->fd, reg, old) ;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* myPullUpDnControl:
|
68
|
+
*********************************************************************************
|
69
|
+
*/
|
70
|
+
|
71
|
+
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
|
72
|
+
{
|
73
|
+
int mask, old, reg ;
|
74
|
+
|
75
|
+
pin -= node->pinBase ;
|
76
|
+
|
77
|
+
if (pin < 8) // Bank A
|
78
|
+
reg = MCP23x17_GPPUA ;
|
79
|
+
else
|
80
|
+
{
|
81
|
+
reg = MCP23x17_GPPUB ;
|
82
|
+
pin &= 0x07 ;
|
83
|
+
}
|
84
|
+
|
85
|
+
mask = 1 << pin ;
|
86
|
+
old = wiringPiI2CReadReg8 (node->fd, reg) ;
|
87
|
+
|
88
|
+
if (mode == PUD_UP)
|
89
|
+
old |= mask ;
|
90
|
+
else
|
91
|
+
old &= (~mask) ;
|
92
|
+
|
93
|
+
wiringPiI2CWriteReg8 (node->fd, reg, old) ;
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
/*
|
98
|
+
* myDigitalWrite:
|
99
|
+
*********************************************************************************
|
100
|
+
*/
|
101
|
+
|
102
|
+
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
103
|
+
{
|
104
|
+
int bit, old ;
|
105
|
+
|
106
|
+
pin -= node->pinBase ; // Pin now 0-15
|
107
|
+
|
108
|
+
bit = 1 << (pin & 7) ;
|
109
|
+
|
110
|
+
if (pin < 8) // Bank A
|
111
|
+
{
|
112
|
+
old = node->data2 ;
|
113
|
+
|
114
|
+
if (value == LOW)
|
115
|
+
old &= (~bit) ;
|
116
|
+
else
|
117
|
+
old |= bit ;
|
118
|
+
|
119
|
+
wiringPiI2CWriteReg8 (node->fd, MCP23x17_GPIOA, old) ;
|
120
|
+
node->data2 = old ;
|
121
|
+
}
|
122
|
+
else // Bank B
|
123
|
+
{
|
124
|
+
old = node->data3 ;
|
125
|
+
|
126
|
+
if (value == LOW)
|
127
|
+
old &= (~bit) ;
|
128
|
+
else
|
129
|
+
old |= bit ;
|
130
|
+
|
131
|
+
wiringPiI2CWriteReg8 (node->fd, MCP23x17_GPIOB, old) ;
|
132
|
+
node->data3 = old ;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
/*
|
138
|
+
* myDigitalRead:
|
139
|
+
*********************************************************************************
|
140
|
+
*/
|
141
|
+
|
142
|
+
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
143
|
+
{
|
144
|
+
int mask, value, gpio ;
|
145
|
+
|
146
|
+
pin -= node->pinBase ;
|
147
|
+
|
148
|
+
if (pin < 8) // Bank A
|
149
|
+
gpio = MCP23x17_GPIOA ;
|
150
|
+
else
|
151
|
+
{
|
152
|
+
gpio = MCP23x17_GPIOB ;
|
153
|
+
pin &= 0x07 ;
|
154
|
+
}
|
155
|
+
|
156
|
+
mask = 1 << pin ;
|
157
|
+
value = wiringPiI2CReadReg8 (node->fd, gpio) ;
|
158
|
+
|
159
|
+
if ((value & mask) == 0)
|
160
|
+
return LOW ;
|
161
|
+
else
|
162
|
+
return HIGH ;
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
/*
|
167
|
+
* mcp23017Setup:
|
168
|
+
* Create a new instance of an MCP23017 I2C GPIO interface. We know it
|
169
|
+
* has 16 pins, so all we need to know here is the I2C address and the
|
170
|
+
* user-defined pin base.
|
171
|
+
*********************************************************************************
|
172
|
+
*/
|
173
|
+
|
174
|
+
int mcp23017Setup (const int pinBase, const int i2cAddress)
|
175
|
+
{
|
176
|
+
int fd ;
|
177
|
+
struct wiringPiNodeStruct *node ;
|
178
|
+
|
179
|
+
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
180
|
+
return FALSE ;
|
181
|
+
|
182
|
+
wiringPiI2CWriteReg8 (fd, MCP23x17_IOCON, IOCON_INIT) ;
|
183
|
+
|
184
|
+
node = wiringPiNewNode (pinBase, 16) ;
|
185
|
+
|
186
|
+
node->fd = fd ;
|
187
|
+
node->pinMode = myPinMode ;
|
188
|
+
node->pullUpDnControl = myPullUpDnControl ;
|
189
|
+
node->digitalRead = myDigitalRead ;
|
190
|
+
node->digitalWrite = myDigitalWrite ;
|
191
|
+
node->data2 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATA) ;
|
192
|
+
node->data3 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATB) ;
|
193
|
+
|
194
|
+
return TRUE ;
|
195
|
+
}
|