wiring_lmk 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 +254 -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 +507 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +684 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +167 -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 +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 +117 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/gpio/extensions.c +700 -0
- data/ext/wiringpi/WiringPi/gpio/extensions.h +26 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1280 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +337 -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 +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 +189 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +234 -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 +113 -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 +92 -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 +168 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +247 -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 +113 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +3688 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +229 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +121 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +253 -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/extconf.rb +8 -0
- data/ext/wiringpi/wiringpi_wrap.c +4396 -0
- data/lib/wiring_lmk.rb +42 -0
- data/lib/wiring_lmk/event.rb +21 -0
- data/lib/wiring_lmk/gpio.rb +139 -0
- data/lib/wiring_lmk/i2c.rb +26 -0
- data/lib/wiring_lmk/mcp23x17.rb +31 -0
- data/lib/wiring_lmk/serial.rb +49 -0
- data/lib/wiring_lmk/spi.rb +15 -0
- metadata +136 -0
@@ -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,167 @@
|
|
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) ;
|
104
|
+
delay (10) ;
|
105
|
+
digitalWrite (pin, 1) ;
|
106
|
+
delayMicroseconds (40) ;
|
107
|
+
pinMode (pin, INPUT) ;
|
108
|
+
|
109
|
+
// Now wait for sensor to pull pin low
|
110
|
+
|
111
|
+
maxDetectLowHighWait (pin) ;
|
112
|
+
|
113
|
+
// and read in 5 bytes (40 bits)
|
114
|
+
|
115
|
+
for (i = 0 ; i < 5 ; ++i)
|
116
|
+
localBuf [i] = maxDetectClockByte (pin) ;
|
117
|
+
|
118
|
+
checksum = 0 ;
|
119
|
+
for (i = 0 ; i < 4 ; ++i)
|
120
|
+
{
|
121
|
+
buffer [i] = localBuf [i] ;
|
122
|
+
checksum += localBuf [i] ;
|
123
|
+
}
|
124
|
+
checksum &= 0xFF ;
|
125
|
+
|
126
|
+
return checksum == localBuf [4] ;
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
/*
|
131
|
+
* readRHT03:
|
132
|
+
* Read the Temperature & Humidity from an RHT03 sensor
|
133
|
+
*********************************************************************************
|
134
|
+
*/
|
135
|
+
|
136
|
+
int readRHT03 (const int pin, int *temp, int *rh)
|
137
|
+
{
|
138
|
+
static unsigned int nextTime = 0 ;
|
139
|
+
static int lastTemp = 0 ;
|
140
|
+
static int lastRh = 0 ;
|
141
|
+
static int lastResult = TRUE ;
|
142
|
+
|
143
|
+
unsigned char buffer [4] ;
|
144
|
+
|
145
|
+
// Don't read more than once a second
|
146
|
+
|
147
|
+
if (millis () < nextTime)
|
148
|
+
{
|
149
|
+
*temp = lastTemp ;
|
150
|
+
*rh = lastRh ;
|
151
|
+
return lastResult ;
|
152
|
+
}
|
153
|
+
|
154
|
+
lastResult = maxDetectRead (pin, buffer) ;
|
155
|
+
|
156
|
+
if (lastResult)
|
157
|
+
{
|
158
|
+
*temp = lastTemp = (buffer [2] * 256 + buffer [3]) ;
|
159
|
+
*rh = lastRh = (buffer [0] * 256 + buffer [1]) ;
|
160
|
+
nextTime = millis () + 2000 ;
|
161
|
+
return TRUE ;
|
162
|
+
}
|
163
|
+
else
|
164
|
+
{
|
165
|
+
return FALSE ;
|
166
|
+
}
|
167
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* maxdetect.h:
|
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
|
+
|
26
|
+
#ifdef __cplusplus
|
27
|
+
extern "C" {
|
28
|
+
#endif
|
29
|
+
|
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) ;
|
37
|
+
|
38
|
+
#ifdef __cplusplus
|
39
|
+
}
|
40
|
+
#endif
|
@@ -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
|
+
}
|