3 * The readall functions - getting a bit big, so split them out.
4 * Copyright (c) 2012-2013 Gordon Henderson
5 ***********************************************************************
6 * This file is part of wiringPi:
7 * https://projects.drogon.net/raspberry-pi/wiringpi/
9 * wiringPi is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
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.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
21 ***********************************************************************
33 #include <sys/types.h>
47 * A relatively crude way to read the pins on an external device.
48 * We don't know the input/output mode of pins, but we can tell
49 * if it's an analog pin or a digital one...
50 *********************************************************************************
53 static void doReadallExternal (void)
57 printf ("+------+---------+--------+\n") ;
58 printf ("| Pin | Digital | Analog |\n") ;
59 printf ("+------+---------+--------+\n") ;
61 for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
62 printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
64 printf ("+------+---------+--------+\n") ;
70 * Read all the GPIO pins
71 * We also want to use this to read the state of pins on an externally
72 * connected device, so we need to do some fiddling with the internal
73 * wiringPi node structures - since the gpio command can only use
74 * one external device at a time, we'll use that to our advantage...
75 *********************************************************************************
78 static char *pinNames [] =
80 "GPIO 0", "GPIO 1", "GPIO 2", "GPIO 3", "GPIO 4", "GPIO 5", "GPIO 6", "GPIO 7",
82 "CE0 ", "CE1 ", "MOSI ", "MISO ", "SCLK ",
84 "GPIO 8", "GPIO 9", "GPIO10", "GPIO11",
87 static char *alts [] =
89 "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
92 static int wpiToPhys [64] =
94 11, 12, 13, 15, 16, 18, 22, 7, // 0...7
96 24, 26, 19, 21, 23, // 10..14
98 53, 54, 55, 56, // 17..20
99 0,0,0,0,0,0,0,0,0,0,0, // 20..31
100 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 32..47
101 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 47..63
104 // The other mappings needed are in wiringPi.c
106 static int physToWpi [64] =
123 -1, -1, -1, -1, -1, // ... 31
124 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
125 -1, -1, -1, -1, -1, // ... 52
126 28, 29, 30, 31, // ... 53, 54, 55, 56 - P5
127 -1, -1, -1, -1, -1, -1, -1, // ... 63
130 static char *physNames [64] =
148 NULL,NULL,NULL,NULL,NULL, // ... 31
149 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, // ... 47
150 NULL,NULL,NULL,NULL,NULL, // ... 52
151 "GPIO8", "GPIO9", "GPIO10", "GPIO11", // ... 53, 54, 55, 56 - P5
152 NULL,NULL,NULL,NULL,NULL,NULL, // ... 63
155 static void readallPhys (int physPin)
159 /**/ if (wpMode == WPI_MODE_GPIO)
161 if (physPinToGpio (physPin) == -1)
164 printf (" | %3d", physPinToGpio (physPin)) ;
166 else if (wpMode != WPI_MODE_PHYS)
168 if (physToWpi [physPin] == -1)
171 printf (" | %3d", physToWpi [physPin]) ;
174 printf (" | %5s", physNames [physPin]) ;
176 if (physToWpi [physPin] == -1)
180 /**/ if (wpMode == WPI_MODE_GPIO)
181 pin = physPinToGpio (physPin) ;
182 else if (wpMode == WPI_MODE_PHYS)
185 pin = physToWpi [physPin] ;
187 printf (" | %4s", alts [getAlt (pin)]) ;
188 printf (" | %s", (digitalRead (pin) == LOW) ? "Lo" : "Hi") ;
193 printf (" | %2d", physPin) ;
195 printf (" || %-2d", physPin) ;
199 if (physToWpi [physPin] == -1)
203 /**/ if (wpMode == WPI_MODE_GPIO)
204 pin = physPinToGpio (physPin) ;
205 else if (wpMode == WPI_MODE_PHYS)
208 pin = physToWpi [physPin] ;
210 printf (" | %s", (digitalRead (pin) == LOW) ? "Lo" : "Hi") ;
211 printf (" | %-4s", alts [getAlt (pin)]) ;
214 printf (" | %-5s", physNames [physPin]) ;
216 /**/ if (wpMode == WPI_MODE_GPIO)
218 if (physPinToGpio (physPin) == -1)
221 printf (" | %-3d", physPinToGpio (physPin)) ;
223 else if (wpMode != WPI_MODE_PHYS)
225 if (physToWpi [physPin] == -1)
228 printf (" | %-3d", physToWpi [physPin]) ;
237 int model, rev, mem ;
241 piBoardId (&model, &rev, &mem, &maker) ;
242 if (model != PI_MODEL_CM)
245 printf ("+-----+------+-------+ +-----+------+-------+\n") ;
246 printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
247 printf ("+-----+------+-------+ +-----+------+-------+\n") ;
249 for (pin = 0 ; pin < 28 ; ++pin)
251 printf ("| %3d ", pin) ;
252 printf ("| %-4s ", alts [getAlt (pin)]) ;
253 printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
255 printf ("| %3d ", pin + 28) ;
256 printf ("| %-4s ", alts [getAlt (pin + 28)]) ;
257 printf ("| %s ", digitalRead (pin + 28) == HIGH ? "High" : "Low ") ;
261 printf ("+-----+------+-------+ +-----+------+-------+\n") ;
267 void doReadall (void)
271 if (wiringPiNodes != NULL) // External readall
273 doReadallExternal () ;
280 /**/ if (wpMode == WPI_MODE_GPIO)
282 printf (" +-----+-------+------+----+-Rev%d-----+----+------+-------+-----+\n", piBoardRev ()) ;
283 printf (" | BCM | Name | Mode | Val| Physical |Val | Mode | Name | BCM |\n") ;
284 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
285 for (pin = 1 ; pin <= 26 ; pin += 2)
287 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
289 else if (wpMode == WPI_MODE_PHYS)
291 printf (" +-------+------+----+-Rev%d-----+----+------+-------+\n", piBoardRev ()) ;
292 printf (" | Name | Mode | Val| Physical |Val | Mode | Name |\n") ;
293 printf (" +-------+------+----+----++----+----+------+-------+\n") ;
294 for (pin = 1 ; pin <= 26 ; pin += 2)
296 printf (" +-------+------+----+----++----+----+------+-------+\n") ;
300 printf (" +-----+-------+------+----+-Rev%d-----+----+------+-------+-----+\n", piBoardRev ()) ;
301 printf (" | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi |\n") ;
302 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
303 for (pin = 1 ; pin <= 26 ; pin += 2)
305 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
310 void doReadallOld (void)
314 if (wiringPiNodes != NULL) // External readall
316 doReadallExternal () ;
323 printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ;
324 printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ;
325 printf ("+----------+------+------+--------+------+-------+\n") ;
327 for (pin = 0 ; pin < 64 ; ++pin) // Crude, but effective
329 if (wpiPinToGpio (pin) == -1)
332 printf ("| %6d | %3d | %3d | %s | %-4s | %-4s |\n",
333 pin, wpiPinToGpio (pin), wpiToPhys [pin],
336 digitalRead (pin) == HIGH ? "High" : "Low ") ;
339 printf ("+----------+------+------+--------+------+-------+\n") ;