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,33 @@
|
|
1
|
+
/*
|
2
|
+
* drcSerial.h:
|
3
|
+
* Extend wiringPi with the DRC Serial protocol (e.g. to Arduino)
|
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 drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,99 @@
|
|
1
|
+
/*
|
2
|
+
* max31855.c:
|
3
|
+
* Extend wiringPi with the max31855 SPI Analog to Digital convertor
|
4
|
+
* Copyright (c) 2012-2015 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 <byteswap.h>
|
26
|
+
#include <stdint.h>
|
27
|
+
|
28
|
+
#include "wiringPi.h"
|
29
|
+
#include "wiringPiSPI.h"
|
30
|
+
|
31
|
+
#include "max31855.h"
|
32
|
+
|
33
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
34
|
+
{
|
35
|
+
uint32_t spiData ;
|
36
|
+
int temp ;
|
37
|
+
int chan = pin - node->pinBase ;
|
38
|
+
|
39
|
+
wiringPiSPIDataRW (node->fd, (unsigned char *)&spiData, 4) ;
|
40
|
+
|
41
|
+
spiData = __bswap_32(spiData) ;
|
42
|
+
|
43
|
+
switch (chan)
|
44
|
+
{
|
45
|
+
case 0: // Existing read - return raw value * 4
|
46
|
+
spiData >>= 18 ;
|
47
|
+
temp = spiData & 0x1FFF ; // Bottom 13 bits
|
48
|
+
if ((spiData & 0x2000) != 0) // Negative
|
49
|
+
temp = -temp ;
|
50
|
+
|
51
|
+
return temp ;
|
52
|
+
|
53
|
+
case 1: // Return error bits
|
54
|
+
return spiData & 0x7 ;
|
55
|
+
|
56
|
+
case 2: // Return temp in C * 10
|
57
|
+
spiData >>= 18 ;
|
58
|
+
temp = spiData & 0x1FFF ; // Bottom 13 bits
|
59
|
+
if ((spiData & 0x2000) != 0) // Negative
|
60
|
+
temp = -temp ;
|
61
|
+
|
62
|
+
return (int)((((double)temp * 25) + 0.5) / 10.0) ;
|
63
|
+
|
64
|
+
case 3: // Return temp in F * 10
|
65
|
+
spiData >>= 18 ;
|
66
|
+
temp = spiData & 0x1FFF ; // Bottom 13 bits
|
67
|
+
if ((spiData & 0x2000) != 0) // Negative
|
68
|
+
temp = -temp ;
|
69
|
+
|
70
|
+
return (int)((((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 100.0) + 0.5) / 10.0) ;
|
71
|
+
|
72
|
+
default: // Who knows...
|
73
|
+
return 0 ;
|
74
|
+
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
/*
|
80
|
+
* max31855Setup:
|
81
|
+
* Create a new wiringPi device node for an max31855 on the Pi's
|
82
|
+
* SPI interface.
|
83
|
+
*********************************************************************************
|
84
|
+
*/
|
85
|
+
|
86
|
+
int max31855Setup (const int pinBase, int spiChannel)
|
87
|
+
{
|
88
|
+
struct wiringPiNodeStruct *node ;
|
89
|
+
|
90
|
+
if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi
|
91
|
+
return -1 ;
|
92
|
+
|
93
|
+
node = wiringPiNewNode (pinBase, 2) ;
|
94
|
+
|
95
|
+
node->fd = spiChannel ;
|
96
|
+
node->analogRead = myAnalogRead ;
|
97
|
+
|
98
|
+
return 0 ;
|
99
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* max31855.c:
|
3
|
+
* Extend wiringPi with the MAX31855 SPI Thermocouple driver
|
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
|
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 max31855Setup (int pinBase, int spiChannel) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
* max5322.c:
|
3
|
+
* Extend wiringPi with the MAX5322 SPI Digital to Analog convertor
|
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
|
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 "wiringPi.h"
|
26
|
+
#include "wiringPiSPI.h"
|
27
|
+
|
28
|
+
#include "max5322.h"
|
29
|
+
|
30
|
+
/*
|
31
|
+
* myAnalogWrite:
|
32
|
+
* Write analog value on the given pin
|
33
|
+
*********************************************************************************
|
34
|
+
*/
|
35
|
+
|
36
|
+
static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
37
|
+
{
|
38
|
+
unsigned char spiData [2] ;
|
39
|
+
unsigned char chanBits, dataBits ;
|
40
|
+
int chan = pin - node->pinBase ;
|
41
|
+
|
42
|
+
if (chan == 0)
|
43
|
+
chanBits = 0b01000000 ;
|
44
|
+
else
|
45
|
+
chanBits = 0b01010000 ;
|
46
|
+
|
47
|
+
chanBits |= ((value >> 12) & 0x0F) ;
|
48
|
+
dataBits = ((value ) & 0xFF) ;
|
49
|
+
|
50
|
+
spiData [0] = chanBits ;
|
51
|
+
spiData [1] = dataBits ;
|
52
|
+
|
53
|
+
wiringPiSPIDataRW (node->fd, spiData, 2) ;
|
54
|
+
}
|
55
|
+
|
56
|
+
/*
|
57
|
+
* max5322Setup:
|
58
|
+
* Create a new wiringPi device node for an max5322 on the Pi's
|
59
|
+
* SPI interface.
|
60
|
+
*********************************************************************************
|
61
|
+
*/
|
62
|
+
|
63
|
+
int max5322Setup (const int pinBase, int spiChannel)
|
64
|
+
{
|
65
|
+
struct wiringPiNodeStruct *node ;
|
66
|
+
unsigned char spiData [2] ;
|
67
|
+
|
68
|
+
if (wiringPiSPISetup (spiChannel, 8000000) < 0) // 10MHz Max
|
69
|
+
return -1 ;
|
70
|
+
|
71
|
+
node = wiringPiNewNode (pinBase, 2) ;
|
72
|
+
|
73
|
+
node->fd = spiChannel ;
|
74
|
+
node->analogWrite = myAnalogWrite ;
|
75
|
+
|
76
|
+
// Enable both DACs
|
77
|
+
|
78
|
+
spiData [0] = 0b11100000 ;
|
79
|
+
spiData [1] = 0 ;
|
80
|
+
|
81
|
+
wiringPiSPIDataRW (node->fd, spiData, 2) ;
|
82
|
+
|
83
|
+
return 0 ;
|
84
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* max5322.h:
|
3
|
+
* Extend wiringPi with the MAX5322 SPI Digital to Analog convertor
|
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
|
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 max5322Setup (int pinBase, int spiChannel) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,149 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23008.c:
|
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
|
+
#include <stdio.h>
|
26
|
+
#include <pthread.h>
|
27
|
+
|
28
|
+
#include "wiringPi.h"
|
29
|
+
#include "wiringPiI2C.h"
|
30
|
+
#include "mcp23x0817.h"
|
31
|
+
|
32
|
+
#include "mcp23008.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
|
+
reg = MCP23x08_IODIR ;
|
45
|
+
mask = 1 << (pin - node->pinBase) ;
|
46
|
+
old = wiringPiI2CReadReg8 (node->fd, reg) ;
|
47
|
+
|
48
|
+
if (mode == OUTPUT)
|
49
|
+
old &= (~mask) ;
|
50
|
+
else
|
51
|
+
old |= mask ;
|
52
|
+
|
53
|
+
wiringPiI2CWriteReg8 (node->fd, reg, old) ;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
/*
|
58
|
+
* myPullUpDnControl:
|
59
|
+
*********************************************************************************
|
60
|
+
*/
|
61
|
+
|
62
|
+
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
|
63
|
+
{
|
64
|
+
int mask, old, reg ;
|
65
|
+
|
66
|
+
reg = MCP23x08_GPPU ;
|
67
|
+
mask = 1 << (pin - node->pinBase) ;
|
68
|
+
|
69
|
+
old = wiringPiI2CReadReg8 (node->fd, reg) ;
|
70
|
+
|
71
|
+
if (mode == PUD_UP)
|
72
|
+
old |= mask ;
|
73
|
+
else
|
74
|
+
old &= (~mask) ;
|
75
|
+
|
76
|
+
wiringPiI2CWriteReg8 (node->fd, reg, old) ;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
/*
|
81
|
+
* myDigitalWrite:
|
82
|
+
*********************************************************************************
|
83
|
+
*/
|
84
|
+
|
85
|
+
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
86
|
+
{
|
87
|
+
int bit, old ;
|
88
|
+
|
89
|
+
bit = 1 << ((pin - node->pinBase) & 7) ;
|
90
|
+
|
91
|
+
old = node->data2 ;
|
92
|
+
if (value == LOW)
|
93
|
+
old &= (~bit) ;
|
94
|
+
else
|
95
|
+
old |= bit ;
|
96
|
+
|
97
|
+
wiringPiI2CWriteReg8 (node->fd, MCP23x08_GPIO, old) ;
|
98
|
+
node->data2 = old ;
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
/*
|
103
|
+
* myDigitalRead:
|
104
|
+
*********************************************************************************
|
105
|
+
*/
|
106
|
+
|
107
|
+
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
108
|
+
{
|
109
|
+
int mask, value ;
|
110
|
+
|
111
|
+
mask = 1 << ((pin - node->pinBase) & 7) ;
|
112
|
+
value = wiringPiI2CReadReg8 (node->fd, MCP23x08_GPIO) ;
|
113
|
+
|
114
|
+
if ((value & mask) == 0)
|
115
|
+
return LOW ;
|
116
|
+
else
|
117
|
+
return HIGH ;
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
/*
|
122
|
+
* mcp23008Setup:
|
123
|
+
* Create a new instance of an MCP23008 I2C GPIO interface. We know it
|
124
|
+
* has 8 pins, so all we need to know here is the I2C address and the
|
125
|
+
* user-defined pin base.
|
126
|
+
*********************************************************************************
|
127
|
+
*/
|
128
|
+
|
129
|
+
int mcp23008Setup (const int pinBase, const int i2cAddress)
|
130
|
+
{
|
131
|
+
int fd ;
|
132
|
+
struct wiringPiNodeStruct *node ;
|
133
|
+
|
134
|
+
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
135
|
+
return fd ;
|
136
|
+
|
137
|
+
wiringPiI2CWriteReg8 (fd, MCP23x08_IOCON, IOCON_INIT) ;
|
138
|
+
|
139
|
+
node = wiringPiNewNode (pinBase, 8) ;
|
140
|
+
|
141
|
+
node->fd = fd ;
|
142
|
+
node->pinMode = myPinMode ;
|
143
|
+
node->pullUpDnControl = myPullUpDnControl ;
|
144
|
+
node->digitalRead = myDigitalRead ;
|
145
|
+
node->digitalWrite = myDigitalWrite ;
|
146
|
+
node->data2 = wiringPiI2CReadReg8 (fd, MCP23x08_OLAT) ;
|
147
|
+
|
148
|
+
return 0 ;
|
149
|
+
}
|
@@ -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
|