#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <wiringPi.h>
extern int wpMode ;
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
static void doReadallExternal (void)
{
int pin ;
printf ("+------+---------+--------+\n") ;
printf ("| Pin | Digital | Analog |\n") ;
printf ("+------+---------+--------+\n") ;
for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
printf ("+------+---------+--------+\n") ;
}
static char *alts [] =
{
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
} ;
static int physToWpi [64] =
{
-1, -1, -1, -1, -1, -1, -1, 6, -1, -1, -1, -1, 1, -1, -1, -1, 4, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, -1, 8, 9, 10, -1, 12, 13, 14, 15, -1, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } ;
static char *physNames [64] =
{
NULL,
" 3.3v", "5v ",
" SDA.0", "5V ",
" SCL.0", "0v ",
"IO6 PA06", "TxD3 ",
" 0v", "RxD3 ",
" RxD2", "IO1 PD14",
" TxD2", "0v ",
" CTS2", "IO4 PC04",
" 3.3v", "IO5 PC07",
" MOSI", "0v ",
" MISO", "RTS2 ",
" SCLK", "SPI-CE0 ",
" 0v", "CE1 ",
" SDA.1", "SCL.1 ",
" IO7 PA7", "0v ",
" IO8 PA8", "IO9 PG08",
"IO10 PA9", "0v ",
"IO12PA10", "IO13PG09",
"IO14PA20", "IO15PG06",
" 0v", "IO16PG07",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
"GPIO.17", "GPIO.18",
"GPIO.19", "GPIO.20",
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
} ;
static void readallPhys (int physPin)
{
int pin ;
if (physPinToGpio (physPin) == -1)
printf (" | | ") ;
else
printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
printf (" | %s", physNames [physPin]) ;
if (physToWpi [physPin] == -1)
printf (" | | ") ;
else
{
if (wpMode == WPI_MODE_GPIO)
pin = physPinToGpio (physPin) ;
else if (wpMode == WPI_MODE_PHYS)
pin = physPin ;
else
pin = physToWpi [physPin] ;
printf (" | %4s", alts [getAlt (pin)]) ;
printf (" | %d", digitalRead (pin)) ;
}
printf (" | %2d", physPin) ;
++physPin ;
printf (" || %-2d", physPin) ;
if (physToWpi [physPin] == -1)
printf (" | | ") ;
else
{
if (wpMode == WPI_MODE_GPIO)
pin = physPinToGpio (physPin) ;
else if (wpMode == WPI_MODE_PHYS)
pin = physPin ;
else
pin = physToWpi [physPin] ;
printf (" | %d", digitalRead (pin)) ;
printf (" | %-4s", alts [getAlt (pin)]) ;
}
printf (" | %-5s", physNames [physPin]) ;
if (physToWpi [physPin] == -1)
printf (" | | ") ;
else
printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
printf (" |\n") ;
}
void cmReadall (void)
{
int pin ;
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
for (pin = 0 ; pin < 28 ; ++pin)
{
printf ("| %3d ", pin) ;
printf ("| %-4s ", alts [getAlt (pin)]) ;
printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
printf ("| ") ;
printf ("| %3d ", pin + 28) ;
printf ("| %-4s ", alts [getAlt (pin + 28)]) ;
printf ("| %s ", digitalRead (pin + 28) == HIGH ? "High" : "Low ") ;
printf ("|\n") ;
}
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
}
void abReadall (int model, int rev)
{
int pin ;
char *type ;
if (model == PI_MODEL_A)
type = " A" ;
else
if (rev == PI_VERSION_2)
type = "B2" ;
else
type = "B1" ;
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 26 ; pin += 2)
readallPhys (pin) ;
if (rev == PI_VERSION_2) {
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 51 ; pin <= 54 ; pin += 2)
readallPhys (pin) ;
}
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
}
void bPlusReadall (void)
{
int pin ;
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
}
void BPReadAll(void)
{
int pin ;
printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
}
void OrangePiReadAll(void)
{
int pin ;
printf (" +-----+-----+----------+------+---+--OrangePiPC--+---+------+---------+-----+--+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+--OrangePIPC--+------+----------+-----+-----+\n") ;
}
void doReadall (void)
{
int model, rev, mem, maker, overVolted ;
if (wiringPiNodes != NULL) {
doReadallExternal () ;
return ;
}
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
abReadall (model, rev) ;
else if (model == PI_MODEL_BP)
bPlusReadall () ;
else if (model == PI_MODEL_CM)
cmReadall () ;
else if (model == PI_MODEL_BPR) OrangePiReadAll(); else
printf ("Oops - unable to determine board type... model: %d\n", model) ;
}