wiringpi-ruby 2.0.0 → 2.1.3
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
- data/ext/wiringpi/wiringpi_wrap.c +636 -219
- data/lib/wiringpi.rb +25 -12
- data/lib/wiringpi/gpio.rb +90 -83
- data/lib/wiringpi/i2c.rb +29 -22
- data/lib/wiringpi/modules/mcp23017.rb +15 -0
- data/lib/wiringpi/modules/mcp23s17.rb +16 -0
- data/lib/wiringpi/scrollphat.rb +14 -14
- data/lib/wiringpi/serial.rb +8 -18
- data/lib/wiringpi/spi.rb +14 -11
- data/lib/wiringpi/watch.rb +24 -0
- metadata +160 -4
- data/lib/wiringpi/event.rb +0 -21
- data/lib/wiringpi/mcp23x17.rb +0 -31
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* 23s17.h:
|
3
|
+
* Extend wiringPi with the MCP 23s17 SPI GPIO expander chip
|
4
|
+
* Copyright (c) 2013 Gordon Henderson
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
12
|
+
* License, or (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
20
|
+
* License along with wiringPi.
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
22
|
+
***********************************************************************
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifdef __cplusplus
|
26
|
+
extern "C" {
|
27
|
+
#endif
|
28
|
+
|
29
|
+
extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23x17:
|
3
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
4
|
+
*
|
5
|
+
* Header file for code using the MCP23x17 GPIO expander chip.
|
6
|
+
* This comes in 2 flavours: MCP23017 which has an I2C interface,
|
7
|
+
* an the MXP23S17 which has an SPI interface.
|
8
|
+
***********************************************************************
|
9
|
+
* This file is part of wiringPi:
|
10
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
11
|
+
*
|
12
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
13
|
+
* it under the terms of the GNU Lesser General Public License as
|
14
|
+
* published by the Free Software Foundation, either version 3 of the
|
15
|
+
* License, or (at your option) any later version.
|
16
|
+
*
|
17
|
+
* wiringPi is distributed in the hope that it will be useful,
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
+
* GNU Lesser General Public License for more details.
|
21
|
+
*
|
22
|
+
* You should have received a copy of the GNU Lesser General Public
|
23
|
+
* License along with wiringPi.
|
24
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
25
|
+
***********************************************************************
|
26
|
+
*/
|
27
|
+
|
28
|
+
|
29
|
+
// MCP23x17 Registers
|
30
|
+
|
31
|
+
#define IODIRA 0x00
|
32
|
+
#define IPOLA 0x02
|
33
|
+
#define GPINTENA 0x04
|
34
|
+
#define DEFVALA 0x06
|
35
|
+
#define INTCONA 0x08
|
36
|
+
#define IOCON 0x0A
|
37
|
+
#define GPPUA 0x0C
|
38
|
+
#define INTFA 0x0E
|
39
|
+
#define INTCAPA 0x10
|
40
|
+
#define GPIOA 0x12
|
41
|
+
#define OLATA 0x14
|
42
|
+
|
43
|
+
#define IODIRB 0x01
|
44
|
+
#define IPOLB 0x03
|
45
|
+
#define GPINTENB 0x05
|
46
|
+
#define DEFVALB 0x07
|
47
|
+
#define INTCONB 0x09
|
48
|
+
#define IOCONB 0x0B
|
49
|
+
#define GPPUB 0x0D
|
50
|
+
#define INTFB 0x0F
|
51
|
+
#define INTCAPB 0x11
|
52
|
+
#define GPIOB 0x13
|
53
|
+
#define OLATB 0x15
|
54
|
+
|
55
|
+
// Bits in the IOCON register
|
56
|
+
|
57
|
+
#define IOCON_UNUSED 0x01
|
58
|
+
#define IOCON_INTPOL 0x02
|
59
|
+
#define IOCON_ODR 0x04
|
60
|
+
#define IOCON_HAEN 0x08
|
61
|
+
#define IOCON_DISSLW 0x10
|
62
|
+
#define IOCON_SEQOP 0x20
|
63
|
+
#define IOCON_MIRROR 0x40
|
64
|
+
#define IOCON_BANK_MODE 0x80
|
65
|
+
|
66
|
+
// Default initialisation mode
|
67
|
+
|
68
|
+
#define IOCON_INIT (IOCON_SEQOP)
|
69
|
+
|
70
|
+
// SPI Command codes
|
71
|
+
|
72
|
+
#define CMD_WRITE 0x40
|
73
|
+
#define CMD_READ 0x41
|
@@ -0,0 +1,87 @@
|
|
1
|
+
/*
|
2
|
+
* mcp23xxx:
|
3
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
4
|
+
*
|
5
|
+
* Header file for code using the MCP23x08 and 17 GPIO expander
|
6
|
+
* chips.
|
7
|
+
* This comes in 2 flavours: MCP230xx (08/17) which has an I2C
|
8
|
+
* interface, and the MXP23Sxx (08/17) which has an SPI interface.
|
9
|
+
***********************************************************************
|
10
|
+
* This file is part of wiringPi:
|
11
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
12
|
+
*
|
13
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
14
|
+
* it under the terms of the GNU Lesser General Public License as
|
15
|
+
* published by the Free Software Foundation, either version 3 of the
|
16
|
+
* License, or (at your option) any later version.
|
17
|
+
*
|
18
|
+
* wiringPi is distributed in the hope that it will be useful,
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
+
* GNU Lesser General Public License for more details.
|
22
|
+
*
|
23
|
+
* You should have received a copy of the GNU Lesser General Public
|
24
|
+
* License along with wiringPi.
|
25
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
***********************************************************************
|
27
|
+
*/
|
28
|
+
|
29
|
+
// MCP23x08 Registers
|
30
|
+
|
31
|
+
#define MCP23x08_IODIR 0x00
|
32
|
+
#define MCP23x08_IPOL 0x01
|
33
|
+
#define MCP23x08_GPINTEN 0x02
|
34
|
+
#define MCP23x08_DEFVAL 0x03
|
35
|
+
#define MCP23x08_INTCON 0x04
|
36
|
+
#define MCP23x08_IOCON 0x05
|
37
|
+
#define MCP23x08_GPPU 0x06
|
38
|
+
#define MCP23x08_INTF 0x07
|
39
|
+
#define MCP23x08_INTCAP 0x08
|
40
|
+
#define MCP23x08_GPIO 0x09
|
41
|
+
#define MCP23x08_OLAT 0x0A
|
42
|
+
|
43
|
+
// MCP23x17 Registers
|
44
|
+
|
45
|
+
#define MCP23x17_IODIRA 0x00
|
46
|
+
#define MCP23x17_IPOLA 0x02
|
47
|
+
#define MCP23x17_GPINTENA 0x04
|
48
|
+
#define MCP23x17_DEFVALA 0x06
|
49
|
+
#define MCP23x17_INTCONA 0x08
|
50
|
+
#define MCP23x17_IOCON 0x0A
|
51
|
+
#define MCP23x17_GPPUA 0x0C
|
52
|
+
#define MCP23x17_INTFA 0x0E
|
53
|
+
#define MCP23x17_INTCAPA 0x10
|
54
|
+
#define MCP23x17_GPIOA 0x12
|
55
|
+
#define MCP23x17_OLATA 0x14
|
56
|
+
|
57
|
+
#define MCP23x17_IODIRB 0x01
|
58
|
+
#define MCP23x17_IPOLB 0x03
|
59
|
+
#define MCP23x17_GPINTENB 0x05
|
60
|
+
#define MCP23x17_DEFVALB 0x07
|
61
|
+
#define MCP23x17_INTCONB 0x09
|
62
|
+
#define MCP23x17_IOCONB 0x0B
|
63
|
+
#define MCP23x17_GPPUB 0x0D
|
64
|
+
#define MCP23x17_INTFB 0x0F
|
65
|
+
#define MCP23x17_INTCAPB 0x11
|
66
|
+
#define MCP23x17_GPIOB 0x13
|
67
|
+
#define MCP23x17_OLATB 0x15
|
68
|
+
|
69
|
+
// Bits in the IOCON register
|
70
|
+
|
71
|
+
#define IOCON_UNUSED 0x01
|
72
|
+
#define IOCON_INTPOL 0x02
|
73
|
+
#define IOCON_ODR 0x04
|
74
|
+
#define IOCON_HAEN 0x08
|
75
|
+
#define IOCON_DISSLW 0x10
|
76
|
+
#define IOCON_SEQOP 0x20
|
77
|
+
#define IOCON_MIRROR 0x40
|
78
|
+
#define IOCON_BANK_MODE 0x80
|
79
|
+
|
80
|
+
// Default initialisation mode
|
81
|
+
|
82
|
+
#define IOCON_INIT (IOCON_SEQOP)
|
83
|
+
|
84
|
+
// SPI Command codes
|
85
|
+
|
86
|
+
#define CMD_WRITE 0x40
|
87
|
+
#define CMD_READ 0x41
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
* mcp3002.c:
|
3
|
+
* Extend wiringPi with the MCP3002 SPI Analog to Digital 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 "mcp3002.h"
|
29
|
+
|
30
|
+
/*
|
31
|
+
* myAnalogRead:
|
32
|
+
* Return the analog value of the given pin
|
33
|
+
*********************************************************************************
|
34
|
+
*/
|
35
|
+
|
36
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
37
|
+
{
|
38
|
+
unsigned char spiData [2] ;
|
39
|
+
unsigned char chanBits ;
|
40
|
+
int chan = pin - node->pinBase ;
|
41
|
+
|
42
|
+
if (chan == 0)
|
43
|
+
chanBits = 0b11010000 ;
|
44
|
+
else
|
45
|
+
chanBits = 0b11110000 ;
|
46
|
+
|
47
|
+
spiData [0] = chanBits ;
|
48
|
+
spiData [1] = 0 ;
|
49
|
+
|
50
|
+
wiringPiSPIDataRW (node->fd, spiData, 2) ;
|
51
|
+
|
52
|
+
return ((spiData [0] << 8) | (spiData [1] >> 1)) & 0x3FF ;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
/*
|
57
|
+
* mcp3002Setup:
|
58
|
+
* Create a new wiringPi device node for an mcp3002 on the Pi's
|
59
|
+
* SPI interface.
|
60
|
+
*********************************************************************************
|
61
|
+
*/
|
62
|
+
|
63
|
+
int mcp3002Setup (const int pinBase, int spiChannel)
|
64
|
+
{
|
65
|
+
struct wiringPiNodeStruct *node ;
|
66
|
+
|
67
|
+
if (wiringPiSPISetup (spiChannel, 1000000) < 0)
|
68
|
+
return FALSE ;
|
69
|
+
|
70
|
+
node = wiringPiNewNode (pinBase, 2) ;
|
71
|
+
|
72
|
+
node->fd = spiChannel ;
|
73
|
+
node->analogRead = myAnalogRead ;
|
74
|
+
|
75
|
+
return TRUE ;
|
76
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* mcp3002.c:
|
3
|
+
* Extend wiringPi with the MCP3002 SPI Analog to Digital 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 mcp3002Setup (int pinBase, int spiChannel) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
* mcp3004.c:
|
3
|
+
* Extend wiringPi with the MCP3004 SPI Analog to Digital convertor
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
5
|
+
*
|
6
|
+
* Thanks also to "ShorTie" on IRC for some remote debugging help!
|
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
|
+
#include <wiringPi.h>
|
28
|
+
#include <wiringPiSPI.h>
|
29
|
+
|
30
|
+
#include "mcp3004.h"
|
31
|
+
|
32
|
+
/*
|
33
|
+
* myAnalogRead:
|
34
|
+
* Return the analog value of the given pin
|
35
|
+
*********************************************************************************
|
36
|
+
*/
|
37
|
+
|
38
|
+
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
39
|
+
{
|
40
|
+
unsigned char spiData [3] ;
|
41
|
+
unsigned char chanBits ;
|
42
|
+
int chan = pin - node->pinBase ;
|
43
|
+
|
44
|
+
chanBits = 0b10000000 | (chan << 4) ;
|
45
|
+
|
46
|
+
spiData [0] = 1 ; // Start bit
|
47
|
+
spiData [1] = chanBits ;
|
48
|
+
spiData [2] = 0 ;
|
49
|
+
|
50
|
+
wiringPiSPIDataRW (node->fd, spiData, 3) ;
|
51
|
+
|
52
|
+
return ((spiData [1] << 8) | spiData [2]) & 0x3FF ;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
/*
|
57
|
+
* mcp3004Setup:
|
58
|
+
* Create a new wiringPi device node for an mcp3004 on the Pi's
|
59
|
+
* SPI interface.
|
60
|
+
*********************************************************************************
|
61
|
+
*/
|
62
|
+
|
63
|
+
int mcp3004Setup (const int pinBase, int spiChannel)
|
64
|
+
{
|
65
|
+
struct wiringPiNodeStruct *node ;
|
66
|
+
|
67
|
+
if (wiringPiSPISetup (spiChannel, 1000000) < 0)
|
68
|
+
return FALSE ;
|
69
|
+
|
70
|
+
node = wiringPiNewNode (pinBase, 8) ;
|
71
|
+
|
72
|
+
node->fd = spiChannel ;
|
73
|
+
node->analogRead = myAnalogRead ;
|
74
|
+
|
75
|
+
return TRUE ;
|
76
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* mcp3004.c:
|
3
|
+
* Extend wiringPi with the MCP3004 SPI Analog to Digital 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 mcp3004Setup (int pinBase, int spiChannel) ;
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
}
|
33
|
+
#endif
|
@@ -0,0 +1,125 @@
|
|
1
|
+
/*
|
2
|
+
* mcp3422.c:
|
3
|
+
* Extend wiringPi with the MCP3422/3/4 I2C ADC chip
|
4
|
+
* This code assumes single-ended mode only.
|
5
|
+
* Tested on actual hardware: 20th Feb 2016.
|
6
|
+
* Copyright (c) 2013-2016 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 <unistd.h>
|
30
|
+
#include <stdint.h>
|
31
|
+
#include <fcntl.h>
|
32
|
+
#include <sys/ioctl.h>
|
33
|
+
|
34
|
+
#include <wiringPi.h>
|
35
|
+
#include <wiringPiI2C.h>
|
36
|
+
|
37
|
+
#include "mcp3422.h"
|
38
|
+
|
39
|
+
|
40
|
+
/*
|
41
|
+
* waitForConversion:
|
42
|
+
* Common code to wait for the ADC to finish conversion
|
43
|
+
*********************************************************************************
|
44
|
+
*/
|
45
|
+
|
46
|
+
void waitForConversion (int fd, unsigned char *buffer, int n)
|
47
|
+
{
|
48
|
+
for (;;)
|
49
|
+
{
|
50
|
+
read (fd, buffer, n) ;
|
51
|
+
if ((buffer [n-1] & 0x80) == 0)
|
52
|
+
break ;
|
53
|
+
delay (1) ;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* myAnalogRead:
|
59
|
+
* Read a channel from the device
|
60
|
+
*********************************************************************************
|
61
|
+
*/
|
62
|
+
|
63
|
+
int myAnalogRead (struct wiringPiNodeStruct *node, int chan)
|
64
|
+
{
|
65
|
+
unsigned char config ;
|
66
|
+
unsigned char buffer [4] ;
|
67
|
+
int value = 0 ;
|
68
|
+
int realChan = (chan & 3) - node->pinBase ;
|
69
|
+
|
70
|
+
// One-shot mode, trigger plus the other configs.
|
71
|
+
|
72
|
+
config = 0x80 | (realChan << 5) | (node->data0 << 2) | (node->data1) ;
|
73
|
+
|
74
|
+
wiringPiI2CWrite (node->fd, config) ;
|
75
|
+
|
76
|
+
switch (node->data0) // Sample rate
|
77
|
+
{
|
78
|
+
case MCP3422_SR_3_75: // 18 bits
|
79
|
+
waitForConversion (node->fd, &buffer [0], 4) ;
|
80
|
+
value = ((buffer [0] & 3) << 16) | (buffer [1] << 8) | buffer [2] ;
|
81
|
+
break ;
|
82
|
+
|
83
|
+
case MCP3422_SR_15: // 16 bits
|
84
|
+
waitForConversion (node->fd, buffer, 3) ;
|
85
|
+
value = (buffer [0] << 8) | buffer [1] ;
|
86
|
+
break ;
|
87
|
+
|
88
|
+
case MCP3422_SR_60: // 14 bits
|
89
|
+
waitForConversion (node->fd, buffer, 3) ;
|
90
|
+
value = ((buffer [0] & 0x3F) << 8) | buffer [1] ;
|
91
|
+
break ;
|
92
|
+
|
93
|
+
case MCP3422_SR_240: // 12 bits - default
|
94
|
+
waitForConversion (node->fd, buffer, 3) ;
|
95
|
+
value = ((buffer [0] & 0x0F) << 8) | buffer [1] ;
|
96
|
+
break ;
|
97
|
+
}
|
98
|
+
|
99
|
+
return value ;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
/*
|
104
|
+
* mcp3422Setup:
|
105
|
+
* Create a new wiringPi device node for the mcp3422
|
106
|
+
*********************************************************************************
|
107
|
+
*/
|
108
|
+
|
109
|
+
int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain)
|
110
|
+
{
|
111
|
+
int fd ;
|
112
|
+
struct wiringPiNodeStruct *node ;
|
113
|
+
|
114
|
+
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
115
|
+
return FALSE ;
|
116
|
+
|
117
|
+
node = wiringPiNewNode (pinBase, 4) ;
|
118
|
+
|
119
|
+
node->fd = fd ;
|
120
|
+
node->data0 = sampleRate ;
|
121
|
+
node->data1 = gain ;
|
122
|
+
node->analogRead = myAnalogRead ;
|
123
|
+
|
124
|
+
return TRUE ;
|
125
|
+
}
|