wiring_lmk 2.0.0
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 +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,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* extensions.h:
|
|
3
|
+
* Part of the GPIO program to test, peek, poke and otherwise
|
|
4
|
+
* noodle with the GPIO hardware on the Raspberry Pi.
|
|
5
|
+
* Copyright (c) 2012-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
|
+
extern int doExtension (char *progName, char *extensionData) ;
|
|
@@ -0,0 +1,1280 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* gpio.c:
|
|
3
|
+
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
|
|
4
|
+
* Pi's GPIO.
|
|
5
|
+
* Copyright (c) 2012-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
|
+
#include <stdio.h>
|
|
27
|
+
#include <stdlib.h>
|
|
28
|
+
#include <stdint.h>
|
|
29
|
+
#include <ctype.h>
|
|
30
|
+
#include <string.h>
|
|
31
|
+
#include <unistd.h>
|
|
32
|
+
#include <errno.h>
|
|
33
|
+
#include <fcntl.h>
|
|
34
|
+
#include <sys/types.h>
|
|
35
|
+
#include <sys/stat.h>
|
|
36
|
+
|
|
37
|
+
#include "wiringPi.h"
|
|
38
|
+
|
|
39
|
+
#include <gertboard.h>
|
|
40
|
+
#include <piFace.h>
|
|
41
|
+
|
|
42
|
+
#include "extensions.h"
|
|
43
|
+
|
|
44
|
+
extern int wiringPiDebug ;
|
|
45
|
+
|
|
46
|
+
// External functions I can't be bothered creating a separate .h file for:
|
|
47
|
+
|
|
48
|
+
extern void doReadall (void) ;
|
|
49
|
+
extern void doPins (void) ;
|
|
50
|
+
|
|
51
|
+
#ifndef TRUE
|
|
52
|
+
# define TRUE (1==1)
|
|
53
|
+
# define FALSE (1==2)
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
#define VERSION "2.20"
|
|
57
|
+
#define PI_USB_POWER_CONTROL 38
|
|
58
|
+
#define I2CDETECT "/usr/sbin/i2cdetect"
|
|
59
|
+
|
|
60
|
+
int wpMode ;
|
|
61
|
+
|
|
62
|
+
char *usage = "Usage: gpio -v\n"
|
|
63
|
+
" gpio -h\n"
|
|
64
|
+
" gpio [-g|-1] [-x extension:params] ...\n"
|
|
65
|
+
" gpio <read/write/aread/awritewb/pwm/mode> ...\n" /*modify for BananaPro by LeMaker team*/
|
|
66
|
+
" gpio readall/reset\n"
|
|
67
|
+
" gpio unexportall/exports\n"
|
|
68
|
+
" gpio export/edge/unexport ...\n"
|
|
69
|
+
" gpio pwm-bal/pwm-ms \n"
|
|
70
|
+
" gpio pwmr <range> \n"
|
|
71
|
+
" gpio pwmc <divider> \n"
|
|
72
|
+
" gpio load spi/i2c\n"
|
|
73
|
+
" gpio i2cd/i2cdetect\n"
|
|
74
|
+
" gpio usbp high/low\n"
|
|
75
|
+
;
|
|
76
|
+
|
|
77
|
+
#ifdef NOT_FOR_NOW
|
|
78
|
+
/*
|
|
79
|
+
* decodePin:
|
|
80
|
+
* Decode a pin "number" which can actually be a pin name to represent
|
|
81
|
+
* one of the Pi's on-board pins.
|
|
82
|
+
*********************************************************************************
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
static int decodePin (const char *str)
|
|
86
|
+
{
|
|
87
|
+
|
|
88
|
+
// The first case - see if it's a number:
|
|
89
|
+
|
|
90
|
+
if (isdigit (str [0]))
|
|
91
|
+
return atoi (str) ;
|
|
92
|
+
|
|
93
|
+
return 0 ;
|
|
94
|
+
}
|
|
95
|
+
#endif
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* changeOwner:
|
|
100
|
+
* Change the ownership of the file to the real userId of the calling
|
|
101
|
+
* program so we can access it.
|
|
102
|
+
*********************************************************************************
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
static void changeOwner (char *cmd, char *file)
|
|
106
|
+
{
|
|
107
|
+
uid_t uid = getuid () ;
|
|
108
|
+
uid_t gid = getgid () ;
|
|
109
|
+
|
|
110
|
+
if (chown (file, uid, gid) != 0)
|
|
111
|
+
{
|
|
112
|
+
if (errno == ENOENT) // Warn that it's not there
|
|
113
|
+
fprintf (stderr, "%s: Warning: File not present: %s\n", cmd, file) ;
|
|
114
|
+
else
|
|
115
|
+
{
|
|
116
|
+
fprintf (stderr, "%s: Unable to change ownership of %s: %s\n", cmd, file, strerror (errno)) ;
|
|
117
|
+
exit (1) ;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
* moduleLoaded:
|
|
125
|
+
* Return true/false if the supplied module is loaded
|
|
126
|
+
*********************************************************************************
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
static int moduleLoaded (char *modName)
|
|
130
|
+
{
|
|
131
|
+
int len = strlen (modName) ;
|
|
132
|
+
int found = FALSE ;
|
|
133
|
+
FILE *fd = fopen ("/proc/modules", "r") ;
|
|
134
|
+
char line [80] ;
|
|
135
|
+
|
|
136
|
+
if (fd == NULL)
|
|
137
|
+
{
|
|
138
|
+
fprintf (stderr, "gpio: Unable to check modules: %s\n", strerror (errno)) ;
|
|
139
|
+
exit (1) ;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//add for S500
|
|
143
|
+
if(strncmp (modName, "spi-owl", len) == 0)
|
|
144
|
+
{
|
|
145
|
+
modName = "spi_owl";
|
|
146
|
+
}
|
|
147
|
+
if(strncmp (modName, "i2c-owl", len) == 0)
|
|
148
|
+
{
|
|
149
|
+
modName = "i2c_owl";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/*add for BananaPro by LeMaker team*/
|
|
153
|
+
if(strncmp (modName, "spi-sun7i", len) == 0)
|
|
154
|
+
{
|
|
155
|
+
modName = "spi_sun7i";
|
|
156
|
+
}
|
|
157
|
+
if(strncmp (modName, "i2c-sunxi", len) == 0)
|
|
158
|
+
{
|
|
159
|
+
modName = "i2c_sunxi";
|
|
160
|
+
}
|
|
161
|
+
/*end 2014.08.19*/
|
|
162
|
+
|
|
163
|
+
while (fgets (line, 80, fd) != NULL)
|
|
164
|
+
{
|
|
165
|
+
if (strncmp (line, modName, len) != 0)
|
|
166
|
+
continue ;
|
|
167
|
+
|
|
168
|
+
found = TRUE ;
|
|
169
|
+
break ;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
fclose (fd) ;
|
|
173
|
+
|
|
174
|
+
return found ;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
/*
|
|
179
|
+
* doLoad:
|
|
180
|
+
* Load either the spi or i2c modules and change device ownerships, etc.
|
|
181
|
+
*********************************************************************************
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
static void _doLoadUsage (char *argv [])
|
|
185
|
+
{
|
|
186
|
+
fprintf (stderr, "Usage: %s load <spi/i2c> [SPI bufferSize in KB | I2C baudrate in Kb/sec]\n", argv [0]) ;
|
|
187
|
+
exit (1) ;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static void doLoad (int argc, char *argv [])
|
|
191
|
+
{
|
|
192
|
+
char *module1, *module2 ;
|
|
193
|
+
char cmd [80] ;
|
|
194
|
+
char *file1 = NULL;
|
|
195
|
+
char *file2 = NULL;
|
|
196
|
+
char args1 [32], args2 [32] ;
|
|
197
|
+
int ret = -1;
|
|
198
|
+
|
|
199
|
+
if (argc < 3)
|
|
200
|
+
_doLoadUsage (argv) ;
|
|
201
|
+
|
|
202
|
+
args1 [0] = args2 [0] = 0 ;
|
|
203
|
+
|
|
204
|
+
//add for S500
|
|
205
|
+
if(S500_REV == piBoardRev())
|
|
206
|
+
{
|
|
207
|
+
if (strcasecmp (argv [2], "spi") == 0)
|
|
208
|
+
{
|
|
209
|
+
module1 = "spidev" ;
|
|
210
|
+
module2 = "spi-owl" ;
|
|
211
|
+
file1 = "/dev/spidev0.0" ;
|
|
212
|
+
file2 = "/dev/spidev0.1" ;
|
|
213
|
+
if (argc == 4)
|
|
214
|
+
sprintf (args1, " bufsiz=%d", atoi (argv [3]) * 1024) ;
|
|
215
|
+
else if (argc > 4)
|
|
216
|
+
_doLoadUsage (argv) ;
|
|
217
|
+
}
|
|
218
|
+
else if (strcasecmp (argv [2], "i2c") == 0)
|
|
219
|
+
{
|
|
220
|
+
module1 = "i2c_dev" ;
|
|
221
|
+
module2 = "i2c-owl" ;
|
|
222
|
+
file1 = "/dev/i2c-2" ;
|
|
223
|
+
file2 = "/dev/i2c-2" ;
|
|
224
|
+
if (argc == 4)
|
|
225
|
+
sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ;
|
|
226
|
+
else if (argc > 4)
|
|
227
|
+
_doLoadUsage (argv) ;
|
|
228
|
+
}
|
|
229
|
+
else
|
|
230
|
+
_doLoadUsage (argv) ;
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
if (!moduleLoaded (module1))
|
|
234
|
+
{
|
|
235
|
+
sprintf (cmd, " %s%s", module1, args1) ;
|
|
236
|
+
ret = system (cmd) ;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
if (!moduleLoaded (module2))
|
|
241
|
+
{
|
|
242
|
+
sprintf (cmd, "modprobe %s%s", module2, args2) ;
|
|
243
|
+
ret = system (cmd) ;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (!moduleLoaded (module2))
|
|
247
|
+
{
|
|
248
|
+
fprintf (stderr, "%s: Unable to load %s\n", argv [0], module2) ;
|
|
249
|
+
exit (1) ;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/*add for BananaPro by LeMaker team*/
|
|
253
|
+
else if(BP_REV == piBoardRev())
|
|
254
|
+
{
|
|
255
|
+
/**/ if (strcasecmp (argv [2], "spi") == 0)
|
|
256
|
+
{
|
|
257
|
+
module1 = "spidev" ;
|
|
258
|
+
module2 = "spi-sun7i" ;
|
|
259
|
+
file1 = "/dev/spidev0.0" ;
|
|
260
|
+
file2 = "/dev/spidev0.1" ;
|
|
261
|
+
if (argc == 4)
|
|
262
|
+
sprintf (args1, " bufsiz=%d", atoi (argv [3]) * 1024) ;
|
|
263
|
+
else if (argc > 4)
|
|
264
|
+
_doLoadUsage (argv) ;
|
|
265
|
+
}
|
|
266
|
+
else if (strcasecmp (argv [2], "i2c") == 0)
|
|
267
|
+
{
|
|
268
|
+
module1 = "i2c_dev" ;
|
|
269
|
+
module2 = "i2c-sunxi" ;
|
|
270
|
+
file1 = "/dev/i2c-2" ;
|
|
271
|
+
file2 = "/dev/i2c-2" ;
|
|
272
|
+
if (argc == 4)
|
|
273
|
+
sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ;
|
|
274
|
+
else if (argc > 4)
|
|
275
|
+
_doLoadUsage (argv) ;
|
|
276
|
+
}
|
|
277
|
+
else
|
|
278
|
+
_doLoadUsage (argv) ;
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
if (!moduleLoaded (module1))
|
|
282
|
+
{
|
|
283
|
+
sprintf (cmd, " %s%s", module1, args1) ;
|
|
284
|
+
ret = system (cmd) ;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
if (!moduleLoaded (module2))
|
|
289
|
+
{
|
|
290
|
+
sprintf (cmd, "modprobe %s%s", module2, args2) ;
|
|
291
|
+
ret = system (cmd) ;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!moduleLoaded (module2))
|
|
295
|
+
{
|
|
296
|
+
fprintf (stderr, "%s: Unable to load %s\n", argv [0], module2) ;
|
|
297
|
+
exit (1) ;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else
|
|
301
|
+
{
|
|
302
|
+
|
|
303
|
+
}
|
|
304
|
+
/*end 2014.08.19*/
|
|
305
|
+
sleep (1) ; // To let things get settled
|
|
306
|
+
|
|
307
|
+
ret = ret;
|
|
308
|
+
|
|
309
|
+
changeOwner (argv [0], file1) ;
|
|
310
|
+
changeOwner (argv [0], file2) ;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
/*
|
|
315
|
+
* doI2Cdetect:
|
|
316
|
+
* Run the i2cdetect command with the right runes for this Pi revision
|
|
317
|
+
*********************************************************************************
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
static void doI2Cdetect (int argc, char *argv [])
|
|
321
|
+
{
|
|
322
|
+
char command [128] ;
|
|
323
|
+
struct stat statBuf ;
|
|
324
|
+
|
|
325
|
+
//add for S500
|
|
326
|
+
if( S500_REV == piBoardRev())
|
|
327
|
+
{
|
|
328
|
+
if (stat (I2CDETECT, &statBuf) < 0)
|
|
329
|
+
{
|
|
330
|
+
fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ;
|
|
331
|
+
return ;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (!moduleLoaded ("i2c-owl"))
|
|
335
|
+
{
|
|
336
|
+
fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
sprintf (command, "%s -y %d", I2CDETECT, 2) ;
|
|
340
|
+
if (system (command) < 0)
|
|
341
|
+
fprintf (stderr, "%s: Unable to run i2cdetect: %s\n", argv [0], strerror (errno)) ;
|
|
342
|
+
}
|
|
343
|
+
/*add for BananaPro by LeMaker team*/
|
|
344
|
+
else if(BP_REV == piBoardRev())
|
|
345
|
+
{
|
|
346
|
+
if (stat (I2CDETECT, &statBuf) < 0)
|
|
347
|
+
{
|
|
348
|
+
fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ;
|
|
349
|
+
return ;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (!moduleLoaded ("i2c-sunxi"))
|
|
353
|
+
{
|
|
354
|
+
fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
|
|
355
|
+
//return ;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
sprintf (command, "%s -y %d", I2CDETECT, 2) ;
|
|
359
|
+
if (system (command) < 0)
|
|
360
|
+
fprintf (stderr, "%s: Unable to run i2cdetect: %s\n", argv [0], strerror (errno)) ;
|
|
361
|
+
}
|
|
362
|
+
else
|
|
363
|
+
{
|
|
364
|
+
|
|
365
|
+
}
|
|
366
|
+
/*end 2014.08.19*/
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
/*
|
|
371
|
+
* doExports:
|
|
372
|
+
* List all GPIO exports
|
|
373
|
+
*********************************************************************************
|
|
374
|
+
*/
|
|
375
|
+
static int S500ValidGpio [132] =
|
|
376
|
+
{
|
|
377
|
+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //0-> 15
|
|
378
|
+
-1, -1, -1, -1, -1, -1, -1, -1, -1, 25, -1, 27, 28, -1, -1, 31, //16-> 31
|
|
379
|
+
32, 33, 34, -1, -1, -1, -1, -1, 40, 41, 42, -1, -1, 45, 46, 47, //32-> 47
|
|
380
|
+
48, -1, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //48-> 63
|
|
381
|
+
64, 65, -1, -1, 68, 69, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //64-> 79
|
|
382
|
+
-1, -1, -1, -1, -1, -1, 86, 87, 88, 89, 90, 91, -1, -1, -1, -1, //80-> 95
|
|
383
|
+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //96-> 111
|
|
384
|
+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //112-> 127
|
|
385
|
+
-1, -1, 130, 131 //128->131
|
|
386
|
+
} ;
|
|
387
|
+
|
|
388
|
+
static void doExports (int argc, char *argv [])
|
|
389
|
+
{
|
|
390
|
+
int fd ;
|
|
391
|
+
int i, l, first ;
|
|
392
|
+
char fName [128] ;
|
|
393
|
+
char buf [16] ;
|
|
394
|
+
|
|
395
|
+
for (first = 0, i = 0 ; i < 132 ; ++i) // Crude, but effective /*64->32 modify for BananaPro by lemaker team*/
|
|
396
|
+
{
|
|
397
|
+
//add for S500
|
|
398
|
+
if(S500ValidGpio[i] == -1)
|
|
399
|
+
{
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
// Try to read the direction
|
|
403
|
+
|
|
404
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/direction", i) ;
|
|
405
|
+
if ((fd = open (fName, O_RDONLY)) == -1)
|
|
406
|
+
continue ;
|
|
407
|
+
|
|
408
|
+
if (first == 0)
|
|
409
|
+
{
|
|
410
|
+
++first ;
|
|
411
|
+
printf ("GPIO Pins exported:\n") ;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
printf ("%4d: ", i) ;
|
|
415
|
+
|
|
416
|
+
if ((l = read (fd, buf, 16)) == 0)
|
|
417
|
+
sprintf (buf, "%s", "?") ;
|
|
418
|
+
|
|
419
|
+
buf [l] = 0 ;
|
|
420
|
+
if ((buf [strlen (buf) - 1]) == '\n')
|
|
421
|
+
buf [strlen (buf) - 1] = 0 ;
|
|
422
|
+
|
|
423
|
+
printf ("%-3s", buf) ;
|
|
424
|
+
|
|
425
|
+
close (fd) ;
|
|
426
|
+
|
|
427
|
+
// Try to Read the value
|
|
428
|
+
|
|
429
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/value", i) ;
|
|
430
|
+
if ((fd = open (fName, O_RDONLY)) == -1)
|
|
431
|
+
{
|
|
432
|
+
printf ("No Value file (huh?)\n") ;
|
|
433
|
+
continue ;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if ((l = read (fd, buf, 16)) == 0)
|
|
437
|
+
sprintf (buf, "%s", "?") ;
|
|
438
|
+
|
|
439
|
+
buf [l] = 0 ;
|
|
440
|
+
if ((buf [strlen (buf) - 1]) == '\n')
|
|
441
|
+
buf [strlen (buf) - 1] = 0 ;
|
|
442
|
+
|
|
443
|
+
printf (" %s", buf) ;
|
|
444
|
+
|
|
445
|
+
// Read any edge trigger file
|
|
446
|
+
|
|
447
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/edge", i) ;
|
|
448
|
+
if ((fd = open (fName, O_RDONLY)) == -1)
|
|
449
|
+
{
|
|
450
|
+
printf ("\n") ;
|
|
451
|
+
continue ;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if ((l = read (fd, buf, 16)) == 0)
|
|
455
|
+
sprintf (buf, "%s", "?") ;
|
|
456
|
+
|
|
457
|
+
buf [l] = 0 ;
|
|
458
|
+
if ((buf [strlen (buf) - 1]) == '\n')
|
|
459
|
+
buf [strlen (buf) - 1] = 0 ;
|
|
460
|
+
|
|
461
|
+
printf (" %-8s\n", buf) ;
|
|
462
|
+
|
|
463
|
+
close (fd) ;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
/*
|
|
469
|
+
* doExport:
|
|
470
|
+
* gpio export pin mode
|
|
471
|
+
* This uses the /sys/class/gpio device interface.
|
|
472
|
+
*********************************************************************************
|
|
473
|
+
*/
|
|
474
|
+
|
|
475
|
+
void doExport (int argc, char *argv [])
|
|
476
|
+
{
|
|
477
|
+
FILE *fd ;
|
|
478
|
+
int pin ;
|
|
479
|
+
char *mode ;
|
|
480
|
+
char fName [128] ;
|
|
481
|
+
|
|
482
|
+
if (argc != 4)
|
|
483
|
+
{
|
|
484
|
+
fprintf (stderr, "Usage: %s export pin mode\n", argv [0]) ;
|
|
485
|
+
exit (1) ;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
pin = atoi (argv [2]) ;
|
|
489
|
+
|
|
490
|
+
/*add for BananaPro by LeMaker team*/
|
|
491
|
+
if (pin == 0)
|
|
492
|
+
{
|
|
493
|
+
printf("%d is invalid pin,please check it over.\n", pin);
|
|
494
|
+
return ;
|
|
495
|
+
}
|
|
496
|
+
/*end 2014.08.19*/
|
|
497
|
+
|
|
498
|
+
mode = argv [3] ;
|
|
499
|
+
|
|
500
|
+
if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL)
|
|
501
|
+
{
|
|
502
|
+
fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
|
|
503
|
+
exit (1) ;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
fprintf (fd, "%d\n", pin) ;
|
|
507
|
+
fclose (fd) ;
|
|
508
|
+
|
|
509
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
|
|
510
|
+
if ((fd = fopen (fName, "w")) == NULL)
|
|
511
|
+
{
|
|
512
|
+
fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
|
|
513
|
+
exit (1) ;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**/ if ((strcasecmp (mode, "in") == 0) || (strcasecmp (mode, "input") == 0))
|
|
517
|
+
fprintf (fd, "in\n") ;
|
|
518
|
+
else if ((strcasecmp (mode, "out") == 0) || (strcasecmp (mode, "output") == 0))
|
|
519
|
+
fprintf (fd, "out\n") ;
|
|
520
|
+
else
|
|
521
|
+
{
|
|
522
|
+
fprintf (stderr, "%s: Invalid mode: %s. Should be in or out\n", argv [1], mode) ;
|
|
523
|
+
exit (1) ;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
fclose (fd) ;
|
|
527
|
+
|
|
528
|
+
// Change ownership so the current user can actually use it!
|
|
529
|
+
|
|
530
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
|
|
531
|
+
changeOwner (argv [0], fName) ;
|
|
532
|
+
|
|
533
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
|
|
534
|
+
changeOwner (argv [0], fName) ;
|
|
535
|
+
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
/*
|
|
540
|
+
* doEdge:
|
|
541
|
+
* gpio edge pin mode
|
|
542
|
+
* Easy access to changing the edge trigger on a GPIO pin
|
|
543
|
+
* This uses the /sys/class/gpio device interface.
|
|
544
|
+
*********************************************************************************
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
void doEdge (int argc, char *argv [])
|
|
548
|
+
{
|
|
549
|
+
FILE *fd ;
|
|
550
|
+
int pin ;
|
|
551
|
+
char *mode ;
|
|
552
|
+
char fName [128] ;
|
|
553
|
+
|
|
554
|
+
if (argc != 4)
|
|
555
|
+
{
|
|
556
|
+
fprintf (stderr, "Usage: %s edge pin mode\n", argv [0]) ;
|
|
557
|
+
exit (1) ;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
pin = atoi (argv [2]) ;
|
|
561
|
+
mode = argv [3] ;
|
|
562
|
+
|
|
563
|
+
/*add for BananaPro by LeMaker team*/
|
|
564
|
+
if (pin == 0)
|
|
565
|
+
{
|
|
566
|
+
printf("%d is invalid pin,please check it over.\n", pin);
|
|
567
|
+
return ;
|
|
568
|
+
}
|
|
569
|
+
/*end 2014.08.19*/
|
|
570
|
+
|
|
571
|
+
// Export the pin and set direction to input
|
|
572
|
+
|
|
573
|
+
if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL)
|
|
574
|
+
{
|
|
575
|
+
fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
|
|
576
|
+
exit (1) ;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
fprintf (fd, "%d\n", pin) ;
|
|
580
|
+
fclose (fd) ;
|
|
581
|
+
|
|
582
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
|
|
583
|
+
if ((fd = fopen (fName, "w")) == NULL)
|
|
584
|
+
{
|
|
585
|
+
fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
|
|
586
|
+
exit (1) ;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
fprintf (fd, "in\n") ;
|
|
590
|
+
fclose (fd) ;
|
|
591
|
+
|
|
592
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
|
|
593
|
+
if ((fd = fopen (fName, "w")) == NULL)
|
|
594
|
+
{
|
|
595
|
+
fprintf (stderr, "%s: Unable to open GPIO edge interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
|
|
596
|
+
exit (1) ;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (strcasecmp (mode, "none") == 0) fprintf (fd, "none\n") ;
|
|
600
|
+
else if (strcasecmp (mode, "rising") == 0) fprintf (fd, "rising\n") ;
|
|
601
|
+
else if (strcasecmp (mode, "falling") == 0) fprintf (fd, "falling\n") ;
|
|
602
|
+
else if (strcasecmp (mode, "both") == 0) fprintf (fd, "both\n") ;
|
|
603
|
+
else
|
|
604
|
+
{
|
|
605
|
+
fprintf (stderr, "%s: Invalid mode: %s. Should be none, rising, falling or both\n", argv [1], mode) ;
|
|
606
|
+
exit (1) ;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Change ownership of the value and edge files, so the current user can actually use it!
|
|
610
|
+
|
|
611
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
|
|
612
|
+
changeOwner (argv [0], fName) ;
|
|
613
|
+
|
|
614
|
+
sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
|
|
615
|
+
changeOwner (argv [0], fName) ;
|
|
616
|
+
|
|
617
|
+
fclose (fd) ;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
/*
|
|
622
|
+
* doUnexport:
|
|
623
|
+
* gpio unexport pin
|
|
624
|
+
* This uses the /sys/class/gpio device interface.
|
|
625
|
+
*********************************************************************************
|
|
626
|
+
*/
|
|
627
|
+
|
|
628
|
+
void doUnexport (int argc, char *argv [])
|
|
629
|
+
{
|
|
630
|
+
FILE *fd ;
|
|
631
|
+
int pin ;
|
|
632
|
+
|
|
633
|
+
if (argc != 3)
|
|
634
|
+
{
|
|
635
|
+
fprintf (stderr, "Usage: %s unexport pin\n", argv [0]) ;
|
|
636
|
+
exit (1) ;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
pin = atoi (argv [2]) ;
|
|
640
|
+
|
|
641
|
+
/*add for BananaPro by LeMaker team*/
|
|
642
|
+
if (pin == 0)
|
|
643
|
+
{
|
|
644
|
+
printf("%d is invalid pin,please check it over.\n", pin);
|
|
645
|
+
return ;
|
|
646
|
+
}
|
|
647
|
+
/*end 2014.08.19*/
|
|
648
|
+
|
|
649
|
+
if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL)
|
|
650
|
+
{
|
|
651
|
+
fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ;
|
|
652
|
+
exit (1) ;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
fprintf (fd, "%d\n", pin) ;
|
|
656
|
+
fclose (fd) ;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
/*
|
|
661
|
+
* doUnexportAll:
|
|
662
|
+
* gpio unexportall
|
|
663
|
+
* Un-Export all the GPIO pins.
|
|
664
|
+
* This uses the /sys/class/gpio device interface.
|
|
665
|
+
*********************************************************************************
|
|
666
|
+
*/
|
|
667
|
+
|
|
668
|
+
void doUnexportall (char *progName)
|
|
669
|
+
{
|
|
670
|
+
FILE *fd ;
|
|
671
|
+
int pin ;
|
|
672
|
+
|
|
673
|
+
for (pin = 1 ; pin < 132 ; ++pin) /*0->1 63->32 modify for BananaPro by LeMaker team*/
|
|
674
|
+
{
|
|
675
|
+
if(S500ValidGpio[pin] == -1)
|
|
676
|
+
{
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL)
|
|
681
|
+
{
|
|
682
|
+
fprintf (stderr, "%s: Unable to open GPIO export interface\n", progName) ;
|
|
683
|
+
exit (1) ;
|
|
684
|
+
}
|
|
685
|
+
fprintf (fd, "%d\n", pin) ;
|
|
686
|
+
fclose (fd) ;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
/*
|
|
692
|
+
* doResetExternal:
|
|
693
|
+
* Load readallExternal, we try to do this with an external device.
|
|
694
|
+
*********************************************************************************
|
|
695
|
+
*/
|
|
696
|
+
|
|
697
|
+
static void doResetExternal (void)
|
|
698
|
+
{
|
|
699
|
+
int pin ;
|
|
700
|
+
|
|
701
|
+
for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
|
|
702
|
+
{
|
|
703
|
+
pinMode (pin, INPUT) ;
|
|
704
|
+
pullUpDnControl (pin, PUD_OFF) ;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
/*
|
|
710
|
+
* doReset:
|
|
711
|
+
* Reset the GPIO pins - as much as we can do
|
|
712
|
+
*********************************************************************************
|
|
713
|
+
*/
|
|
714
|
+
|
|
715
|
+
static void doReset (char *progName)
|
|
716
|
+
{
|
|
717
|
+
printf ("GPIO Reset is dangerous and has been removed from the gpio command.\n") ;
|
|
718
|
+
printf (" - Please write a shell-script to reset the GPIO pins into the state\n") ;
|
|
719
|
+
printf (" that you need them in for your applications.\n") ;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
/*
|
|
724
|
+
* doMode:
|
|
725
|
+
* gpio mode pin mode ...
|
|
726
|
+
*********************************************************************************
|
|
727
|
+
*/
|
|
728
|
+
|
|
729
|
+
void doMode (int argc, char *argv [])
|
|
730
|
+
{
|
|
731
|
+
int pin ;
|
|
732
|
+
char *mode ;
|
|
733
|
+
|
|
734
|
+
if (argc != 4)
|
|
735
|
+
{
|
|
736
|
+
fprintf (stderr, "Usage: %s mode pin mode\n", argv [0]) ;
|
|
737
|
+
exit (1) ;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
pin = atoi (argv [2]) ;
|
|
741
|
+
|
|
742
|
+
mode = argv [3] ;
|
|
743
|
+
|
|
744
|
+
if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
|
|
745
|
+
else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ;
|
|
746
|
+
else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
|
|
747
|
+
else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ;
|
|
748
|
+
else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
|
|
749
|
+
else if (strcasecmp (mode, "pwmTone") == 0) pinMode (pin, PWM_TONE_OUTPUT) ;
|
|
750
|
+
else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
|
|
751
|
+
else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
|
|
752
|
+
else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
|
|
753
|
+
else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;
|
|
754
|
+
else
|
|
755
|
+
{
|
|
756
|
+
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
|
|
757
|
+
exit (1) ;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
/*
|
|
763
|
+
* doUsbP:
|
|
764
|
+
* Control USB Power - High (1.2A) or Low (600mA)
|
|
765
|
+
* gpio usbp high/low
|
|
766
|
+
*********************************************************************************
|
|
767
|
+
*/
|
|
768
|
+
|
|
769
|
+
static void doUsbP (int argc, char *argv [])
|
|
770
|
+
{
|
|
771
|
+
int model, rev, mem, maker, overVolted ;
|
|
772
|
+
|
|
773
|
+
if (argc != 3)
|
|
774
|
+
{
|
|
775
|
+
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
|
|
776
|
+
exit (1) ;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// Make sure we're on a B+
|
|
780
|
+
|
|
781
|
+
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
|
782
|
+
|
|
783
|
+
if (model != PI_MODEL_BP)
|
|
784
|
+
{
|
|
785
|
+
fprintf (stderr, "USB power contol is applicable to B+ boards only.\n") ;
|
|
786
|
+
exit (1) ;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// Need to force BCM_GPIO mode:
|
|
790
|
+
|
|
791
|
+
wiringPiSetupGpio () ;
|
|
792
|
+
|
|
793
|
+
if ((strcasecmp (argv [2], "high") == 0) || (strcasecmp (argv [2], "hi") == 0))
|
|
794
|
+
{
|
|
795
|
+
digitalWrite (PI_USB_POWER_CONTROL, 1) ;
|
|
796
|
+
pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
|
|
797
|
+
printf ("Switched to HIGH current USB (1.2A)\n") ;
|
|
798
|
+
return ;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if ((strcasecmp (argv [2], "low") == 0) || (strcasecmp (argv [2], "lo") == 0))
|
|
802
|
+
{
|
|
803
|
+
digitalWrite (PI_USB_POWER_CONTROL, 0) ;
|
|
804
|
+
pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
|
|
805
|
+
printf ("Switched to LOW current USB (600mA)\n") ;
|
|
806
|
+
return ;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
|
|
810
|
+
exit (1) ;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
/*
|
|
815
|
+
* doWrite:
|
|
816
|
+
* gpio write pin value
|
|
817
|
+
*********************************************************************************
|
|
818
|
+
*/
|
|
819
|
+
|
|
820
|
+
static void doWrite (int argc, char *argv [])
|
|
821
|
+
{
|
|
822
|
+
int pin, val ;
|
|
823
|
+
|
|
824
|
+
if (argc != 4)
|
|
825
|
+
{
|
|
826
|
+
fprintf (stderr, "Usage: %s write pin value\n", argv [0]) ;
|
|
827
|
+
exit (1) ;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
pin = atoi (argv [2]) ;
|
|
831
|
+
|
|
832
|
+
if ((strcasecmp (argv [3], "up") == 0) || (strcasecmp (argv [3], "on") == 0))
|
|
833
|
+
val = 1 ;
|
|
834
|
+
else if ((strcasecmp (argv [3], "down") == 0) || (strcasecmp (argv [3], "off") == 0))
|
|
835
|
+
val = 0 ;
|
|
836
|
+
else
|
|
837
|
+
val = atoi (argv [3]) ;
|
|
838
|
+
|
|
839
|
+
if (val == 0)
|
|
840
|
+
digitalWrite (pin, LOW) ;
|
|
841
|
+
else
|
|
842
|
+
digitalWrite (pin, HIGH) ;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
/*
|
|
847
|
+
* doAwriterite:
|
|
848
|
+
* gpio awrite pin value
|
|
849
|
+
*********************************************************************************
|
|
850
|
+
*/
|
|
851
|
+
|
|
852
|
+
static void doAwrite (int argc, char *argv [])
|
|
853
|
+
{
|
|
854
|
+
int pin, val ;
|
|
855
|
+
|
|
856
|
+
if (argc != 4)
|
|
857
|
+
{
|
|
858
|
+
fprintf (stderr, "Usage: %s awrite pin value\n", argv [0]) ;
|
|
859
|
+
exit (1) ;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
pin = atoi (argv [2]) ;
|
|
863
|
+
|
|
864
|
+
val = atoi (argv [3]) ;
|
|
865
|
+
|
|
866
|
+
analogWrite (pin, val) ;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
/*
|
|
871
|
+
* doWriteByte:
|
|
872
|
+
* gpio write value
|
|
873
|
+
*********************************************************************************
|
|
874
|
+
*/
|
|
875
|
+
|
|
876
|
+
static void doWriteByte (int argc, char *argv [])
|
|
877
|
+
{
|
|
878
|
+
int val ;
|
|
879
|
+
|
|
880
|
+
if (argc != 3)
|
|
881
|
+
{
|
|
882
|
+
fprintf (stderr, "Usage: %s wb value\n", argv [0]) ;
|
|
883
|
+
exit (1) ;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
val = (int)strtol (argv [2], NULL, 0) ;
|
|
887
|
+
|
|
888
|
+
digitalWriteByte (val) ;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
/*
|
|
893
|
+
* doRead:
|
|
894
|
+
* Read a pin and return the value
|
|
895
|
+
*********************************************************************************
|
|
896
|
+
*/
|
|
897
|
+
|
|
898
|
+
void doRead (int argc, char *argv [])
|
|
899
|
+
{
|
|
900
|
+
int pin, val ;
|
|
901
|
+
|
|
902
|
+
if (argc != 3)
|
|
903
|
+
{
|
|
904
|
+
fprintf (stderr, "Usage: %s read pin\n", argv [0]) ;
|
|
905
|
+
exit (1) ;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
pin = atoi (argv [2]) ;
|
|
909
|
+
val = digitalRead (pin) ;
|
|
910
|
+
|
|
911
|
+
printf ("%s\n", val == 0 ? "0" : "1") ;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
/*
|
|
916
|
+
* doAread:
|
|
917
|
+
* Read an analog pin and return the value
|
|
918
|
+
*********************************************************************************
|
|
919
|
+
*/
|
|
920
|
+
|
|
921
|
+
void doAread (int argc, char *argv [])
|
|
922
|
+
{
|
|
923
|
+
if (argc != 3)
|
|
924
|
+
{
|
|
925
|
+
fprintf (stderr, "Usage: %s aread pin\n", argv [0]) ;
|
|
926
|
+
exit (1) ;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
printf ("%d\n", analogRead (atoi (argv [2]))) ;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
/*
|
|
934
|
+
* doToggle:
|
|
935
|
+
* Toggle an IO pin
|
|
936
|
+
*********************************************************************************
|
|
937
|
+
*/
|
|
938
|
+
|
|
939
|
+
void doToggle (int argc, char *argv [])
|
|
940
|
+
{
|
|
941
|
+
int pin ;
|
|
942
|
+
|
|
943
|
+
if (argc != 3)
|
|
944
|
+
{
|
|
945
|
+
fprintf (stderr, "Usage: %s toggle pin\n", argv [0]) ;
|
|
946
|
+
exit (1) ;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
pin = atoi (argv [2]) ;
|
|
950
|
+
|
|
951
|
+
digitalWrite (pin, !digitalRead (pin)) ;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
/*
|
|
956
|
+
* doPwmTone:
|
|
957
|
+
* Output a tone in a PWM pin
|
|
958
|
+
*********************************************************************************
|
|
959
|
+
*/
|
|
960
|
+
|
|
961
|
+
void doPwmTone (int argc, char *argv [])
|
|
962
|
+
{
|
|
963
|
+
int pin, freq ;
|
|
964
|
+
|
|
965
|
+
if (argc != 4)
|
|
966
|
+
{
|
|
967
|
+
fprintf (stderr, "Usage: %s pwmTone <pin> <freq>\n", argv [0]) ;
|
|
968
|
+
exit (1) ;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
pin = atoi (argv [2]) ;
|
|
972
|
+
freq = atoi (argv [3]) ;
|
|
973
|
+
|
|
974
|
+
pwmToneWrite (pin, freq) ;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
/*
|
|
979
|
+
* doPwm:
|
|
980
|
+
* Output a PWM value on a pin
|
|
981
|
+
*********************************************************************************
|
|
982
|
+
*/
|
|
983
|
+
|
|
984
|
+
void doPwm (int argc, char *argv [])
|
|
985
|
+
{
|
|
986
|
+
int pin, val ;
|
|
987
|
+
|
|
988
|
+
if (argc != 4)
|
|
989
|
+
{
|
|
990
|
+
fprintf (stderr, "Usage: %s pwm <pin> <value>\n", argv [0]) ;
|
|
991
|
+
exit (1) ;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
pin = atoi (argv [2]) ;
|
|
995
|
+
|
|
996
|
+
val = atoi (argv [3]) ;
|
|
997
|
+
|
|
998
|
+
pwmWrite (pin, val) ;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
/*
|
|
1003
|
+
* doPwmMode: doPwmRange: doPwmClock:
|
|
1004
|
+
* Change the PWM mode, range and clock divider values
|
|
1005
|
+
*********************************************************************************
|
|
1006
|
+
*/
|
|
1007
|
+
|
|
1008
|
+
static void doPwmMode (int mode)
|
|
1009
|
+
{
|
|
1010
|
+
pwmSetMode (mode) ;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
static void doPwmRange (int argc, char *argv [])
|
|
1014
|
+
{
|
|
1015
|
+
unsigned int range ;
|
|
1016
|
+
|
|
1017
|
+
if (argc != 3)
|
|
1018
|
+
{
|
|
1019
|
+
fprintf (stderr, "Usage: %s pwmr <range>\n", argv [0]) ;
|
|
1020
|
+
exit (1) ;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
range = (unsigned int)strtoul (argv [2], NULL, 10) ;
|
|
1024
|
+
|
|
1025
|
+
if (range == 0)
|
|
1026
|
+
{
|
|
1027
|
+
fprintf (stderr, "%s: range must be > 0\n", argv [0]) ;
|
|
1028
|
+
exit (1) ;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
pwmSetRange (range) ;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
static void doPwmClock (int argc, char *argv [])
|
|
1035
|
+
{
|
|
1036
|
+
unsigned int clock ;
|
|
1037
|
+
|
|
1038
|
+
if (argc != 3)
|
|
1039
|
+
{
|
|
1040
|
+
fprintf (stderr, "Usage: %s pwmc <clock>\n", argv [0]) ;
|
|
1041
|
+
exit (1) ;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
clock = (unsigned int)strtoul (argv [2], NULL, 10) ;
|
|
1045
|
+
|
|
1046
|
+
if ((clock < 1) || (clock > 4095))
|
|
1047
|
+
{
|
|
1048
|
+
fprintf (stderr, "%s: clock must be between 0 and 4096\n", argv [0]) ;
|
|
1049
|
+
exit (1) ;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
pwmSetClock (clock) ;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
/*
|
|
1057
|
+
* main:
|
|
1058
|
+
* Start here
|
|
1059
|
+
*********************************************************************************
|
|
1060
|
+
*/
|
|
1061
|
+
|
|
1062
|
+
int main (int argc, char *argv [])
|
|
1063
|
+
{
|
|
1064
|
+
int i ;
|
|
1065
|
+
int model, rev, mem, maker, overVolted ;
|
|
1066
|
+
|
|
1067
|
+
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
|
1068
|
+
{
|
|
1069
|
+
printf ("gpio: wiringPi debug mode enabled\n") ;
|
|
1070
|
+
wiringPiDebug = TRUE ;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
if (argc == 1)
|
|
1074
|
+
{
|
|
1075
|
+
fprintf (stderr, "%s\n", usage) ;
|
|
1076
|
+
return 1 ;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// Help
|
|
1080
|
+
|
|
1081
|
+
if (strcasecmp (argv [1], "-h") == 0)
|
|
1082
|
+
{
|
|
1083
|
+
printf ("%s: %s\n", argv [0], usage) ;
|
|
1084
|
+
return 0 ;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// Sort of a special:
|
|
1088
|
+
|
|
1089
|
+
if (strcmp (argv [1], "-R") == 0)
|
|
1090
|
+
{
|
|
1091
|
+
printf ("%d\n", piBoardRev ()) ;
|
|
1092
|
+
return 0 ;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// Version & Warranty
|
|
1096
|
+
|
|
1097
|
+
if (strcmp (argv [1], "-V") == 0)
|
|
1098
|
+
{
|
|
1099
|
+
printf ("%d\n", piBoardRev ()) ;
|
|
1100
|
+
return 0 ;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
if (strcmp (argv [1], "-v") == 0)
|
|
1104
|
+
{
|
|
1105
|
+
printf ("gpio version: %s\n", VERSION) ;
|
|
1106
|
+
printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
|
|
1107
|
+
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
|
|
1108
|
+
printf ("For details type: %s -warranty\n", argv [0]) ;
|
|
1109
|
+
printf ("\n") ;
|
|
1110
|
+
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
|
1111
|
+
if (model == PI_MODEL_UNKNOWN)
|
|
1112
|
+
{
|
|
1113
|
+
printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ;
|
|
1114
|
+
printf (" projects@drogon.net\n") ;
|
|
1115
|
+
printf ("with a copy of your /proc/cpuinfo if possible\n") ;
|
|
1116
|
+
}
|
|
1117
|
+
else
|
|
1118
|
+
{
|
|
1119
|
+
printf ("Banana Pro Details:\n") ;
|
|
1120
|
+
printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
|
|
1121
|
+
piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ;
|
|
1122
|
+
}
|
|
1123
|
+
return 0 ;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
if (strcasecmp (argv [1], "-warranty") == 0)
|
|
1127
|
+
{
|
|
1128
|
+
printf ("gpio version: %s\n", VERSION) ;
|
|
1129
|
+
printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ;
|
|
1130
|
+
printf ("\n") ;
|
|
1131
|
+
printf (" This program is free software; you can redistribute it and/or modify\n") ;
|
|
1132
|
+
printf (" it under the terms of the GNU Leser General Public License as published\n") ;
|
|
1133
|
+
printf (" by the Free Software Foundation, either version 3 of the License, or\n") ;
|
|
1134
|
+
printf (" (at your option) any later version.\n") ;
|
|
1135
|
+
printf ("\n") ;
|
|
1136
|
+
printf (" This program is distributed in the hope that it will be useful,\n") ;
|
|
1137
|
+
printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ;
|
|
1138
|
+
printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ;
|
|
1139
|
+
printf (" GNU Lesser General Public License for more details.\n") ;
|
|
1140
|
+
printf ("\n") ;
|
|
1141
|
+
printf (" You should have received a copy of the GNU Lesser General Public License\n") ;
|
|
1142
|
+
printf (" along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ;
|
|
1143
|
+
printf ("\n") ;
|
|
1144
|
+
return 0 ;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
if (geteuid () != 0)
|
|
1148
|
+
{
|
|
1149
|
+
fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
|
|
1150
|
+
return 1 ;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
// Initial test for /sys/class/gpio operations:
|
|
1154
|
+
|
|
1155
|
+
/**/ if (strcasecmp (argv [1], "exports" ) == 0)
|
|
1156
|
+
{
|
|
1157
|
+
doExports (argc, argv) ;
|
|
1158
|
+
return 0 ;
|
|
1159
|
+
}
|
|
1160
|
+
else if (strcasecmp (argv [1], "export" ) == 0)
|
|
1161
|
+
{
|
|
1162
|
+
doExport (argc, argv) ;
|
|
1163
|
+
return 0 ;
|
|
1164
|
+
}
|
|
1165
|
+
else if (strcasecmp (argv [1], "edge" ) == 0)
|
|
1166
|
+
{
|
|
1167
|
+
doEdge (argc, argv) ;
|
|
1168
|
+
return 0 ;
|
|
1169
|
+
}
|
|
1170
|
+
else if (strcasecmp (argv [1], "unexport" ) == 0)
|
|
1171
|
+
{
|
|
1172
|
+
doUnexport (argc, argv) ;
|
|
1173
|
+
return 0 ;
|
|
1174
|
+
}
|
|
1175
|
+
else if (strcasecmp (argv [1], "unexportall") == 0)
|
|
1176
|
+
{
|
|
1177
|
+
doUnexportall (argv [0]) ;
|
|
1178
|
+
return 0 ;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// Check for load command:
|
|
1182
|
+
|
|
1183
|
+
if (strcasecmp (argv [1], "load" ) == 0)
|
|
1184
|
+
{
|
|
1185
|
+
doLoad (argc, argv) ;
|
|
1186
|
+
return 0 ;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
// Check for -g argument
|
|
1191
|
+
|
|
1192
|
+
if (strcasecmp (argv [1], "-g") == 0)
|
|
1193
|
+
{
|
|
1194
|
+
wiringPiSetupGpio () ;
|
|
1195
|
+
|
|
1196
|
+
for (i = 2 ; i < argc ; ++i)
|
|
1197
|
+
argv [i - 1] = argv [i] ;
|
|
1198
|
+
--argc ;
|
|
1199
|
+
wpMode = WPI_MODE_GPIO ;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
// Check for -1 argument
|
|
1203
|
+
|
|
1204
|
+
else if (strcasecmp (argv [1], "-1") == 0)
|
|
1205
|
+
{
|
|
1206
|
+
wiringPiSetupPhys () ;
|
|
1207
|
+
|
|
1208
|
+
for (i = 2 ; i < argc ; ++i)
|
|
1209
|
+
argv [i - 1] = argv [i] ;
|
|
1210
|
+
--argc ;
|
|
1211
|
+
wpMode = WPI_MODE_PHYS ;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// Default to wiringPi mode
|
|
1215
|
+
|
|
1216
|
+
else
|
|
1217
|
+
{
|
|
1218
|
+
wiringPiSetup () ;
|
|
1219
|
+
wpMode = WPI_MODE_PINS ;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
// Check for -x argument to load in a new extension
|
|
1223
|
+
|
|
1224
|
+
if (strcasecmp (argv [1], "-x") == 0)
|
|
1225
|
+
{
|
|
1226
|
+
if (argc < 3)
|
|
1227
|
+
{
|
|
1228
|
+
fprintf (stderr, "%s: -x missing extension specification.\n", argv [0]) ;
|
|
1229
|
+
exit (EXIT_FAILURE) ;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
if (!doExtension (argv [0], argv [2])) // Prints its own error messages
|
|
1233
|
+
exit (EXIT_FAILURE) ;
|
|
1234
|
+
|
|
1235
|
+
for (i = 3 ; i < argc ; ++i)
|
|
1236
|
+
argv [i - 2] = argv [i] ;
|
|
1237
|
+
argc -= 2 ;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
if (argc <= 1)
|
|
1241
|
+
{
|
|
1242
|
+
fprintf (stderr, "%s: no command given\n", argv [0]) ;
|
|
1243
|
+
exit (EXIT_FAILURE) ;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// Core wiringPi functions
|
|
1247
|
+
|
|
1248
|
+
/**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
|
|
1249
|
+
else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
|
|
1250
|
+
else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ;
|
|
1251
|
+
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
|
|
1252
|
+
else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite (argc, argv) ;
|
|
1253
|
+
else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ;
|
|
1254
|
+
|
|
1255
|
+
// GPIO Nicies
|
|
1256
|
+
|
|
1257
|
+
else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ;
|
|
1258
|
+
|
|
1259
|
+
// Pi Specifics
|
|
1260
|
+
|
|
1261
|
+
else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doPwmMode (PWM_MODE_BAL) ;
|
|
1262
|
+
else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ;
|
|
1263
|
+
else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ;
|
|
1264
|
+
else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ;
|
|
1265
|
+
else if (strcasecmp (argv [1], "pwmTone" ) == 0) doPwmTone (argc, argv) ;
|
|
1266
|
+
else if (strcasecmp (argv [1], "usbp" ) == 0) doUsbP (argc, argv) ;
|
|
1267
|
+
else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
|
|
1268
|
+
else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
|
|
1269
|
+
else if (strcasecmp (argv [1], "pins" ) == 0) doPins () ;
|
|
1270
|
+
else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ;
|
|
1271
|
+
else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ;
|
|
1272
|
+
else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ;
|
|
1273
|
+
else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ;
|
|
1274
|
+
else
|
|
1275
|
+
{
|
|
1276
|
+
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
|
|
1277
|
+
exit (EXIT_FAILURE) ;
|
|
1278
|
+
}
|
|
1279
|
+
return 0 ;
|
|
1280
|
+
}
|