3 * The readall functions - getting a bit big, so split them out.
4 * Copyright (c) 2012-2015 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 *alts [] =
80 "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
83 static int physToWpi [64] =
99 30, 31, // Actually I2C, but not used
113 -1, -1, -1, -1, -1, -1, -1, -1, -1
116 static char *physNames [64] =
125 "GPIO. 0", "GPIO. 1",
127 "GPIO. 3", "GPIO. 4",
135 "GPIO.22", "GPIO.26",
137 "GPIO.24", "GPIO.27",
138 "GPIO.25", "GPIO.28",
145 "GPIO.17", "GPIO.18",
146 "GPIO.19", "GPIO.20",
147 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
153 * Given a physical pin output the data on it and the next pin:
154 *| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM |
155 *********************************************************************************
158 static void readallPhys (int physPin)
162 if (physPinToGpio (physPin) == -1)
165 printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
167 printf (" | %s", 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 (" | %d", digitalRead (pin)) ;
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 (" | %d", digitalRead (pin)) ;
204 printf (" | %-4s", alts [getAlt (pin)]) ;
207 printf (" | %-5s", physNames [physPin]) ;
209 if (physToWpi [physPin] == -1)
212 printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
218 void cmReadall (void)
222 printf ("+-----+------+-------+ +-----+------+-------+\n") ;
223 printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
224 printf ("+-----+------+-------+ +-----+------+-------+\n") ;
226 for (pin = 0 ; pin < 28 ; ++pin)
228 printf ("| %3d ", pin) ;
229 printf ("| %-4s ", alts [getAlt (pin)]) ;
230 printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
232 printf ("| %3d ", pin + 28) ;
233 printf ("| %-4s ", alts [getAlt (pin + 28)]) ;
234 printf ("| %s ", digitalRead (pin + 28) == HIGH ? "High" : "Low ") ;
238 printf ("+-----+------+-------+ +-----+------+-------+\n") ;
244 * Read all the pins on the model A or B.
245 *********************************************************************************
248 void abReadall (int model, int rev)
253 if (model == PI_MODEL_A)
256 if (rev == PI_VERSION_2)
261 printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
262 printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
263 printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
264 for (pin = 1 ; pin <= 26 ; pin += 2)
267 if (rev == PI_VERSION_2) // B version 2
269 printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
270 for (pin = 51 ; pin <= 54 ; pin += 2)
274 printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
275 printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
276 printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
282 * Read all the pins on the model A+ or the B+
283 *********************************************************************************
286 static void plus2header (int model)
288 /**/ if (model == PI_MODEL_AP)
289 printf (" +-----+-----+---------+------+---+--A Plus--+---+------+---------+-----+-----+\n") ;
290 else if (model == PI_MODEL_BP)
291 printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
293 printf (" +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+\n") ;
297 void piPlusReadall (int model)
301 plus2header (model) ;
303 printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
304 printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
305 for (pin = 1 ; pin <= 40 ; pin += 2)
307 printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
308 printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
310 plus2header (model) ;
314 void doReadall (void)
316 int model, rev, mem, maker, overVolted ;
318 if (wiringPiNodes != NULL) // External readall
320 doReadallExternal () ;
324 piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
326 /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
327 abReadall (model, rev) ;
328 else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) || (model == PI_MODEL_2))
329 piPlusReadall (model) ;
330 else if (model == PI_MODEL_CM)
333 printf ("Oops - unable to determine board type... model: %d\n", model) ;