wiringpi 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- 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 +165 -0
- data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
- 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 +178 -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/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.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.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -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/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 +69 -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 +1351 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -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 +189 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -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 +110 -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/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -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 +2007 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
- data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/extconf.rb +7 -1
- data/ext/wiringpi/wiringpi_wrap.c +1741 -218
- data/lib/wiringpi.rb +24 -222
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +139 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- metadata +146 -22
- data/ext/wiringpi/wiringPi.c +0 -729
- data/ext/wiringpi/wiringPi.h +0 -69
@@ -0,0 +1,39 @@
|
|
1
|
+
/*
|
2
|
+
* lcd128x64.h:
|
3
|
+
*
|
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 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
|
+
extern void lcd128x64setOrigin (int x, int y) ;
|
25
|
+
extern void lcd128x64setOrientation (int orientation) ;
|
26
|
+
extern void lcd128x64orientCoordinates (int *x, int *y) ;
|
27
|
+
extern void lcd128x64getScreenSize (int *x, int *y) ;
|
28
|
+
extern void lcd128x64point (int x, int y, int colour) ;
|
29
|
+
extern void lcd128x64line (int x0, int y0, int x1, int y1, int colour) ;
|
30
|
+
extern void lcd128x64lineTo (int x, int y, int colour) ;
|
31
|
+
extern void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled) ;
|
32
|
+
extern void lcd128x64circle (int x, int y, int r, int colour, int filled) ;
|
33
|
+
extern void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled) ;
|
34
|
+
extern void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol) ;
|
35
|
+
extern void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol) ;
|
36
|
+
extern void lcd128x64update (void) ;
|
37
|
+
extern void lcd128x64clear (int colour) ;
|
38
|
+
|
39
|
+
extern int lcd128x64setup (void) ;
|
@@ -0,0 +1,165 @@
|
|
1
|
+
/*
|
2
|
+
* maxdetect.c:
|
3
|
+
* Driver for the MaxDetect series sensors
|
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 <unistd.h>
|
28
|
+
|
29
|
+
#include <wiringPi.h>
|
30
|
+
|
31
|
+
#include "maxdetect.h"
|
32
|
+
|
33
|
+
#ifndef TRUE
|
34
|
+
# define TRUE (1==1)
|
35
|
+
# define FALSE (1==2)
|
36
|
+
#endif
|
37
|
+
|
38
|
+
|
39
|
+
/*
|
40
|
+
* maxDetectLowHighWait:
|
41
|
+
* Wait for a transition from high to low on the bus
|
42
|
+
*********************************************************************************
|
43
|
+
*/
|
44
|
+
|
45
|
+
static void maxDetectLowHighWait (const int pin)
|
46
|
+
{
|
47
|
+
unsigned int timeOut = millis () + 2000 ;
|
48
|
+
|
49
|
+
while (digitalRead (pin) == HIGH)
|
50
|
+
if (millis () > timeOut)
|
51
|
+
return ;
|
52
|
+
|
53
|
+
while (digitalRead (pin) == LOW)
|
54
|
+
if (millis () > timeOut)
|
55
|
+
return ;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/*
|
60
|
+
* maxDetectClockByte:
|
61
|
+
* Read in a single byte from the MaxDetect bus
|
62
|
+
*********************************************************************************
|
63
|
+
*/
|
64
|
+
|
65
|
+
static unsigned int maxDetectClockByte (const int pin)
|
66
|
+
{
|
67
|
+
unsigned int byte = 0 ;
|
68
|
+
int bit ;
|
69
|
+
|
70
|
+
for (bit = 0 ; bit < 8 ; ++bit)
|
71
|
+
{
|
72
|
+
maxDetectLowHighWait (pin) ;
|
73
|
+
|
74
|
+
// bit starting now - we need to time it.
|
75
|
+
|
76
|
+
delayMicroseconds (30) ;
|
77
|
+
byte <<= 1 ;
|
78
|
+
if (digitalRead (pin) == HIGH) // It's a 1
|
79
|
+
byte |= 1 ;
|
80
|
+
}
|
81
|
+
|
82
|
+
return byte ;
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
/*
|
87
|
+
* maxDetectRead:
|
88
|
+
* Read in and return the 4 data bytes from the MaxDetect sensor.
|
89
|
+
* Return TRUE/FALSE depending on the checksum validity
|
90
|
+
*********************************************************************************
|
91
|
+
*/
|
92
|
+
|
93
|
+
int maxDetectRead (const int pin, unsigned char buffer [4])
|
94
|
+
{
|
95
|
+
int i ;
|
96
|
+
unsigned int checksum ;
|
97
|
+
unsigned char localBuf [5] ;
|
98
|
+
|
99
|
+
// Wake up the RHT03 by pulling the data line low, then high
|
100
|
+
// Low for 10mS, high for 40uS.
|
101
|
+
|
102
|
+
pinMode (pin, OUTPUT) ;
|
103
|
+
digitalWrite (pin, 0) ; delay (10) ;
|
104
|
+
digitalWrite (pin, 1) ; delayMicroseconds (40) ;
|
105
|
+
pinMode (pin, INPUT) ;
|
106
|
+
|
107
|
+
// Now wait for sensor to pull pin low
|
108
|
+
|
109
|
+
maxDetectLowHighWait (pin) ;
|
110
|
+
|
111
|
+
// and read in 5 bytes (40 bits)
|
112
|
+
|
113
|
+
for (i = 0 ; i < 5 ; ++i)
|
114
|
+
localBuf [i] = maxDetectClockByte (pin) ;
|
115
|
+
|
116
|
+
checksum = 0 ;
|
117
|
+
for (i = 0 ; i < 4 ; ++i)
|
118
|
+
{
|
119
|
+
buffer [i] = localBuf [i] ;
|
120
|
+
checksum += localBuf [i] ;
|
121
|
+
}
|
122
|
+
checksum &= 0xFF ;
|
123
|
+
|
124
|
+
return checksum == localBuf [4] ;
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
/*
|
129
|
+
* readRHT03:
|
130
|
+
* Read the Temperature & Humidity from an RHT03 sensor
|
131
|
+
*********************************************************************************
|
132
|
+
*/
|
133
|
+
|
134
|
+
int readRHT03 (const int pin, int *temp, int *rh)
|
135
|
+
{
|
136
|
+
static unsigned int nextTime = 0 ;
|
137
|
+
static int lastTemp = 0 ;
|
138
|
+
static int lastRh = 0 ;
|
139
|
+
static int lastResult = TRUE ;
|
140
|
+
|
141
|
+
unsigned char buffer [4] ;
|
142
|
+
|
143
|
+
// Don't read more than once a second
|
144
|
+
|
145
|
+
if (millis () < nextTime)
|
146
|
+
{
|
147
|
+
*temp = lastTemp ;
|
148
|
+
*rh = lastRh ;
|
149
|
+
return lastResult ;
|
150
|
+
}
|
151
|
+
|
152
|
+
lastResult = maxDetectRead (pin, buffer) ;
|
153
|
+
|
154
|
+
if (lastResult)
|
155
|
+
{
|
156
|
+
*temp = lastTemp = (buffer [2] * 256 + buffer [3]) ;
|
157
|
+
*rh = lastRh = (buffer [0] * 256 + buffer [1]) ;
|
158
|
+
nextTime = millis () + 2000 ;
|
159
|
+
return TRUE ;
|
160
|
+
}
|
161
|
+
else
|
162
|
+
{
|
163
|
+
return FALSE ;
|
164
|
+
}
|
165
|
+
}
|
@@ -1,40 +1,39 @@
|
|
1
1
|
/*
|
2
|
-
*
|
3
|
-
*
|
2
|
+
* maxdetect.h:
|
3
|
+
* Driver for the MaxDetect series sensors
|
4
|
+
*
|
5
|
+
* Copyright (c) 2013 Gordon Henderson.
|
4
6
|
***********************************************************************
|
5
7
|
* This file is part of wiringPi:
|
6
8
|
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
7
9
|
*
|
8
10
|
* wiringPi is free software: you can redistribute it and/or modify
|
9
|
-
* it under the terms of the GNU General Public License as published by
|
11
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
10
12
|
* the Free Software Foundation, either version 3 of the License, or
|
11
13
|
* (at your option) any later version.
|
12
14
|
*
|
13
15
|
* wiringPi is distributed in the hope that it will be useful,
|
14
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
* GNU General Public License for more details.
|
18
|
+
* GNU Lesser General Public License for more details.
|
17
19
|
*
|
18
|
-
* You should have received a copy of the GNU General Public License
|
20
|
+
* You should have received a copy of the GNU Lesser General Public License
|
19
21
|
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
20
22
|
***********************************************************************
|
21
23
|
*/
|
22
24
|
|
23
|
-
#ifndef _STDINT_H
|
24
|
-
# include <stdint.h>
|
25
|
-
#endif
|
26
25
|
|
27
26
|
#ifdef __cplusplus
|
28
27
|
extern "C" {
|
29
28
|
#endif
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
// Main generic function
|
31
|
+
|
32
|
+
int maxDetectRead (const int pin, unsigned char buffer [4]) ;
|
33
|
+
|
34
|
+
// Individual sensors
|
35
|
+
|
36
|
+
int readRHT03 (const int pin, int *temp, int *rh) ;
|
38
37
|
|
39
38
|
#ifdef __cplusplus
|
40
39
|
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/*
|
2
|
+
* piFace.:
|
3
|
+
* This file to interface with the PiFace peripheral device which
|
4
|
+
* has an MCP23S17 GPIO device connected via the SPI bus.
|
5
|
+
*
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
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
|
+
|
28
|
+
#include <stdio.h>
|
29
|
+
#include <stdint.h>
|
30
|
+
|
31
|
+
#include <wiringPi.h>
|
32
|
+
#include <mcp23s17.h>
|
33
|
+
|
34
|
+
#include "piFace.h"
|
35
|
+
|
36
|
+
|
37
|
+
/*
|
38
|
+
* myDigitalWrite:
|
39
|
+
* Perform the digitalWrite function on the PiFace board
|
40
|
+
*********************************************************************************
|
41
|
+
*/
|
42
|
+
|
43
|
+
void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
44
|
+
{
|
45
|
+
digitalWrite (pin + 16, value) ;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
/*
|
50
|
+
* myDigitalRead:
|
51
|
+
* Perform the digitalRead function on the PiFace board
|
52
|
+
* With a slight twist - if we read from base + 8, then we
|
53
|
+
* read from the output latch...
|
54
|
+
*********************************************************************************
|
55
|
+
*/
|
56
|
+
|
57
|
+
int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
58
|
+
{
|
59
|
+
if ((pin - node->pinBase) >= 8)
|
60
|
+
return digitalRead (pin + 8) ;
|
61
|
+
else
|
62
|
+
return digitalRead (pin + 16 + 8) ;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* myPullUpDnControl:
|
68
|
+
* Perform the pullUpDnControl function on the PiFace board
|
69
|
+
*********************************************************************************
|
70
|
+
*/
|
71
|
+
|
72
|
+
void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
|
73
|
+
{
|
74
|
+
pullUpDnControl (pin + 16 + 8, pud) ;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/*
|
79
|
+
* piFaceSetup
|
80
|
+
* We're going to create an instance of the mcp23s17 here, then
|
81
|
+
* provide our own read/write routines on-top of it...
|
82
|
+
* The supplied PiFace code (in Pithon) treats it as an 8-bit device
|
83
|
+
* where you write the output ports and read the input port using the
|
84
|
+
* same pin numbers, however I have had a request to be able to read
|
85
|
+
* the output port, so reading 8..15 will read the output latch.
|
86
|
+
*********************************************************************************
|
87
|
+
*/
|
88
|
+
|
89
|
+
int piFaceSetup (const int pinBase)
|
90
|
+
{
|
91
|
+
int i ;
|
92
|
+
struct wiringPiNodeStruct *node ;
|
93
|
+
|
94
|
+
// Create an mcp23s17 instance:
|
95
|
+
|
96
|
+
mcp23s17Setup (pinBase + 16, 0, 0) ;
|
97
|
+
|
98
|
+
// Set the direction bits
|
99
|
+
|
100
|
+
for (i = 0 ; i < 8 ; ++i)
|
101
|
+
{
|
102
|
+
pinMode (pinBase + 16 + i, OUTPUT) ; // Port A is the outputs
|
103
|
+
pinMode (pinBase + 16 + 8 + i, INPUT) ; // Port B inputs.
|
104
|
+
}
|
105
|
+
|
106
|
+
node = wiringPiNewNode (pinBase, 16) ;
|
107
|
+
node->digitalRead = myDigitalRead ;
|
108
|
+
node->digitalWrite = myDigitalWrite ;
|
109
|
+
node->pullUpDnControl = myPullUpDnControl ;
|
110
|
+
|
111
|
+
return 0 ;
|
112
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
* piFace.h:
|
3
|
+
* Control the PiFace Interface board for the Raspberry Pi
|
4
|
+
* Copyright (c) 2012-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 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
|
+
#ifdef __cplusplus
|
25
|
+
extern "C" {
|
26
|
+
#endif
|
27
|
+
|
28
|
+
extern int piFaceSetup (const int pinBase) ;
|
29
|
+
|
30
|
+
#ifdef __cplusplus
|
31
|
+
}
|
32
|
+
#endif
|
@@ -0,0 +1,178 @@
|
|
1
|
+
/*
|
2
|
+
* piFace.:
|
3
|
+
* Arduino compatable (ish) Wiring library for the Raspberry Pi
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
5
|
+
*
|
6
|
+
* This file to interface with the PiFace peripheral device which
|
7
|
+
* has an MCP23S17 GPIO device connected via the SPI bus.
|
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
|
+
#include <stdio.h>
|
30
|
+
#include <stdint.h>
|
31
|
+
|
32
|
+
#include <wiringPi.h>
|
33
|
+
#include <wiringPiSPI.h>
|
34
|
+
|
35
|
+
#include "../wiringPi/mcp23x0817.h"
|
36
|
+
|
37
|
+
#include "piFace.h"
|
38
|
+
|
39
|
+
#define PIFACE_SPEED 4000000
|
40
|
+
#define PIFACE_DEVNO 0
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
/*
|
45
|
+
* writeByte:
|
46
|
+
* Write a byte to a register on the MCP23S17 on the SPI bus.
|
47
|
+
*********************************************************************************
|
48
|
+
*/
|
49
|
+
|
50
|
+
static void writeByte (uint8_t reg, uint8_t data)
|
51
|
+
{
|
52
|
+
uint8_t spiData [4] ;
|
53
|
+
|
54
|
+
spiData [0] = CMD_WRITE ;
|
55
|
+
spiData [1] = reg ;
|
56
|
+
spiData [2] = data ;
|
57
|
+
|
58
|
+
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
|
59
|
+
}
|
60
|
+
|
61
|
+
/*
|
62
|
+
* readByte:
|
63
|
+
* Read a byte from a register on the MCP23S17 on the SPI bus.
|
64
|
+
*********************************************************************************
|
65
|
+
*/
|
66
|
+
|
67
|
+
static uint8_t readByte (uint8_t reg)
|
68
|
+
{
|
69
|
+
uint8_t spiData [4] ;
|
70
|
+
|
71
|
+
spiData [0] = CMD_READ ;
|
72
|
+
spiData [1] = reg ;
|
73
|
+
|
74
|
+
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
|
75
|
+
|
76
|
+
return spiData [2] ;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
/*
|
81
|
+
* myDigitalWrite:
|
82
|
+
* Perform the digitalWrite function on the PiFace board
|
83
|
+
*********************************************************************************
|
84
|
+
*/
|
85
|
+
|
86
|
+
void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
87
|
+
{
|
88
|
+
uint8_t mask, old ;
|
89
|
+
|
90
|
+
pin -= node->pinBase ;
|
91
|
+
mask = 1 << pin ;
|
92
|
+
old = readByte (MCP23x17_GPIOA) ;
|
93
|
+
|
94
|
+
if (value == 0)
|
95
|
+
old &= (~mask) ;
|
96
|
+
else
|
97
|
+
old |= mask ;
|
98
|
+
|
99
|
+
writeByte (MCP23x17_GPIOA, old) ;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
/*
|
104
|
+
* myDigitalRead:
|
105
|
+
* Perform the digitalRead function on the PiFace board
|
106
|
+
*********************************************************************************
|
107
|
+
*/
|
108
|
+
|
109
|
+
int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
110
|
+
{
|
111
|
+
uint8_t mask, reg ;
|
112
|
+
|
113
|
+
mask = 1 << ((pin - node->pinBase) & 7) ;
|
114
|
+
|
115
|
+
if (pin < 8)
|
116
|
+
reg = MCP23x17_GPIOB ; // Input regsiter
|
117
|
+
else
|
118
|
+
reg = MCP23x17_OLATA ; // Output latch regsiter
|
119
|
+
|
120
|
+
if ((readByte (reg) & mask) != 0)
|
121
|
+
return HIGH ;
|
122
|
+
else
|
123
|
+
return LOW ;
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
/*
|
128
|
+
* myPullUpDnControl:
|
129
|
+
* Perform the pullUpDnControl function on the PiFace board
|
130
|
+
*********************************************************************************
|
131
|
+
*/
|
132
|
+
|
133
|
+
void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
|
134
|
+
{
|
135
|
+
uint8_t mask, old ;
|
136
|
+
|
137
|
+
mask = 1 << (pin - node->pinBase) ;
|
138
|
+
old = readByte (MCP23x17_GPPUB) ;
|
139
|
+
|
140
|
+
if (pud == 0)
|
141
|
+
old &= (~mask) ;
|
142
|
+
else
|
143
|
+
old |= mask ;
|
144
|
+
|
145
|
+
writeByte (MCP23x17_GPPUB, old) ;
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
/*
|
150
|
+
* piFaceSetup
|
151
|
+
* Setup the SPI interface and initialise the MCP23S17 chip
|
152
|
+
* We create one node with 16 pins - each if the first 8 pins being read
|
153
|
+
* and write - although the operations actually go to different
|
154
|
+
* hardware ports. The top 8 let you read the state of the output register.
|
155
|
+
*********************************************************************************
|
156
|
+
*/
|
157
|
+
|
158
|
+
int piFaceSetup (const int pinBase)
|
159
|
+
{
|
160
|
+
int x ;
|
161
|
+
struct wiringPiNodeStruct *node ;
|
162
|
+
|
163
|
+
if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0)
|
164
|
+
return x ;
|
165
|
+
|
166
|
+
// Setup the MCP23S17
|
167
|
+
|
168
|
+
writeByte (MCP23x17_IOCON, IOCON_INIT) ;
|
169
|
+
writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs
|
170
|
+
writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs
|
171
|
+
|
172
|
+
node = wiringPiNewNode (pinBase, 16) ;
|
173
|
+
node->digitalRead = myDigitalRead ;
|
174
|
+
node->digitalWrite = myDigitalWrite ;
|
175
|
+
node->pullUpDnControl = myPullUpDnControl ;
|
176
|
+
|
177
|
+
return 0 ;
|
178
|
+
}
|