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>
42 * A relatively crude way to read the pins on an external device.
43 * We don't know the input/output mode of pins, but we can tell
44 * if it's an analog pin or a digital one...
45 *********************************************************************************
48 static void doReadallExternal (void)
52 printf ("+------+---------+--------+\n") ;
53 printf ("| Pin | Digital | Analog |\n") ;
54 printf ("+------+---------+--------+\n") ;
56 for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
57 printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
59 printf ("+------+---------+--------+\n") ;
65 * Read all the GPIO pins
66 * We also want to use this to read the state of pins on an externally
67 * connected device, so we need to do some fiddling with the internal
68 * wiringPi node structures - since the gpio command can only use
69 * one external device at a time, we'll use that to our advantage...
70 *********************************************************************************
73 static char *pinNames [] =
75 "GPIO 0", "GPIO 1", "GPIO 2", "GPIO 3", "GPIO 4", "GPIO 5", "GPIO 6", "GPIO 7",
77 "CE0 ", "CE1 ", "MOSI ", "MISO ", "SCLK ",
79 "GPIO 8", "GPIO 9", "GPIO10", "GPIO11",
82 static char *alts [] =
84 "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
87 static int wpiToPhys [64] =
89 11, 12, 13, 15, 16, 18, 22, 7, // 0...7
91 24, 26, 19, 21, 23, // 10..14
94 0,0,0,0,0,0,0,0,0,0,0, // 20..31
95 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 32..47
96 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 47..63
99 // The other mappings needed are in wiringPi.c
101 static int physToWpi [64] =
120 -1, -1, -1, -1, -1, // ... 31
121 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
122 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
125 static char *physNames [64] =
143 NULL,NULL,NULL,NULL,NULL,
144 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
145 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
148 static void readallPhys (int physPin)
152 /**/ if (wpMode == WPI_MODE_GPIO)
154 if (physPinToGpio (physPin) == -1)
157 printf (" | %3d", physPinToGpio (physPin)) ;
159 else if (wpMode != WPI_MODE_PHYS)
161 if (physToWpi [physPin] == -1)
164 printf (" | %3d", physToWpi [physPin]) ;
167 printf (" | %5s", physNames [physPin]) ;
169 if (physToWpi [physPin] == -1)
173 /**/ if (wpMode == WPI_MODE_GPIO)
174 pin = physPinToGpio (physPin) ;
175 else if (wpMode == WPI_MODE_PHYS)
178 pin = physToWpi [physPin] ;
180 printf (" | %4s", alts [getAlt (pin)]) ;
181 printf (" | %s", (digitalRead (pin) == 0) ? "Hi" : "Lo") ;
186 printf (" | %2d", physPin) ;
188 printf (" || %-2d", physPin) ;
192 if (physToWpi [physPin] == -1)
196 /**/ if (wpMode == WPI_MODE_GPIO)
197 pin = physPinToGpio (physPin) ;
198 else if (wpMode == WPI_MODE_PHYS)
201 pin = physToWpi [physPin] ;
203 printf (" | %s", (digitalRead (pin) == 0) ? "Hi" : "Lo") ;
204 printf (" | %-4s", alts [getAlt (pin)]) ;
207 printf (" | %-5s", physNames [physPin]) ;
209 /**/ if (wpMode == WPI_MODE_GPIO)
211 if (physPinToGpio (physPin) == -1)
214 printf (" | %-3d", physPinToGpio (physPin)) ;
216 else if (wpMode != WPI_MODE_PHYS)
218 if (physToWpi [physPin] == -1)
221 printf (" | %-3d", physToWpi [physPin]) ;
228 void doReadall (void)
232 if (wiringPiNodes != NULL) // External readall
234 doReadallExternal () ;
238 /**/ if (wpMode == WPI_MODE_GPIO)
240 printf (" +-----+-------+------+----+-Rev%d-----+----+------+-------+-----+\n", piBoardRev ()) ;
241 printf (" | BCM | Name | Mode | Val| Physical |Val | Mode | Name | BCM |\n") ;
242 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
243 for (pin = 1 ; pin <= 26 ; pin += 2)
245 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
247 else if (wpMode == WPI_MODE_PHYS)
249 printf (" +-------+------+----+-Rev%d-----+----+------+-------+\n", piBoardRev ()) ;
250 printf (" | Name | Mode | Val| Physical |Val | Mode | Name |\n") ;
251 printf (" +-------+------+----+----++----+----+------+-------+\n") ;
252 for (pin = 1 ; pin <= 26 ; pin += 2)
254 printf (" +-------+------+----+----++----+----+------+-------+\n") ;
258 printf (" +-----+-------+------+----+-Rev%d-----+----+------+-------+-----+\n", piBoardRev ()) ;
259 printf (" | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi |\n") ;
260 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
261 for (pin = 1 ; pin <= 26 ; pin += 2)
263 printf (" +-----+-------+------+----+----++----+----+------+-------+-----+\n") ;
268 void doReadallOld (void)
272 if (wiringPiNodes != NULL) // External readall
274 doReadallExternal () ;
278 printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ;
279 printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ;
280 printf ("+----------+------+------+--------+------+-------+\n") ;
282 for (pin = 0 ; pin < 64 ; ++pin) // Crude, but effective
284 if (wpiPinToGpio (pin) == -1)
287 printf ("| %6d | %3d | %3d | %s | %-4s | %-4s |\n",
288 pin, wpiPinToGpio (pin), wpiToPhys [pin],
291 digitalRead (pin) == HIGH ? "High" : "Low ") ;
294 printf ("+----------+------+------+--------+------+-------+\n") ;