@@ -173,40 +173,6 @@ static void changeOwner (char *cmd, char *file) | |||||
/* | /* | ||||
* moduleLoaded: | |||||
* Return true/false if the supplied module is loaded | |||||
********************************************************************************* | |||||
*/ | |||||
static int moduleLoaded (char *modName) | |||||
{ | |||||
int len = strlen (modName) ; | |||||
int found = FALSE ; | |||||
FILE *fd = fopen ("/proc/modules", "r") ; | |||||
char line [80] ; | |||||
if (fd == NULL) | |||||
{ | |||||
fprintf (stderr, "gpio: Unable to check /proc/modules: %s\n", strerror (errno)) ; | |||||
exit (1) ; | |||||
} | |||||
while (fgets (line, 80, fd) != NULL) | |||||
{ | |||||
if (strncmp (line, modName, len) != 0) | |||||
continue ; | |||||
found = TRUE ; | |||||
break ; | |||||
} | |||||
fclose (fd) ; | |||||
return found ; | |||||
} | |||||
/* | |||||
* doLoad: | * doLoad: | ||||
* Load either the spi or i2c modules and change device ownerships, etc. | * Load either the spi or i2c modules and change device ownerships, etc. | ||||
********************************************************************************* | ********************************************************************************* | ||||
@@ -812,6 +778,7 @@ static void doPadDrive (int argc, char *argv []) | |||||
static void doUsbP (int argc, char *argv []) | static void doUsbP (int argc, char *argv []) | ||||
{ | { | ||||
/* | |||||
int model, rev, mem, maker, overVolted ; | int model, rev, mem, maker, overVolted ; | ||||
if (argc != 3) | if (argc != 3) | ||||
@@ -852,6 +819,8 @@ static void doUsbP (int argc, char *argv []) | |||||
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ; | fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ; | ||||
exit (1) ; | exit (1) ; | ||||
*/ | |||||
return; | |||||
} | } | ||||
@@ -1417,7 +1386,7 @@ int main (int argc, char *argv []) | |||||
for (i = 2 ; i < argc ; ++i) | for (i = 2 ; i < argc ; ++i) | ||||
argv [i - 1] = argv [i] ; | argv [i - 1] = argv [i] ; | ||||
--argc ; | --argc ; | ||||
wpMode = WPI_MODE_GPIO ; | |||||
wpMode = MODE_GPIO ; | |||||
} | } | ||||
// Check for -1 argument | // Check for -1 argument | ||||
@@ -1429,7 +1398,7 @@ int main (int argc, char *argv []) | |||||
for (i = 2 ; i < argc ; ++i) | for (i = 2 ; i < argc ; ++i) | ||||
argv [i - 1] = argv [i] ; | argv [i - 1] = argv [i] ; | ||||
--argc ; | --argc ; | ||||
wpMode = WPI_MODE_PHYS ; | |||||
wpMode = MODE_PHYS ; | |||||
} | } | ||||
// Check for -p argument for PiFace | // Check for -p argument for PiFace | ||||
@@ -1441,7 +1410,7 @@ int main (int argc, char *argv []) | |||||
for (i = 2 ; i < argc ; ++i) | for (i = 2 ; i < argc ; ++i) | ||||
argv [i - 1] = argv [i] ; | argv [i - 1] = argv [i] ; | ||||
--argc ; | --argc ; | ||||
wpMode = WPI_MODE_PIFACE ; | |||||
wpMode = MODE_PIFACE ; | |||||
} | } | ||||
// Check for -z argument so we don't actually initialise wiringPi | // Check for -z argument so we don't actually initialise wiringPi | ||||
@@ -1451,7 +1420,7 @@ int main (int argc, char *argv []) | |||||
for (i = 2 ; i < argc ; ++i) | for (i = 2 ; i < argc ; ++i) | ||||
argv [i - 1] = argv [i] ; | argv [i - 1] = argv [i] ; | ||||
--argc ; | --argc ; | ||||
wpMode = WPI_MODE_UNINITIALISED ; | |||||
wpMode = MODE_UNINITIALISED ; | |||||
} | } | ||||
// Default to wiringPi mode | // Default to wiringPi mode | ||||
@@ -1459,7 +1428,7 @@ int main (int argc, char *argv []) | |||||
else | else | ||||
{ | { | ||||
wiringPiSetup () ; | wiringPiSetup () ; | ||||
wpMode = WPI_MODE_PINS ; | |||||
wpMode = MODE_PINS ; | |||||
} | } | ||||
// Check for -x argument to load in a new extension | // Check for -x argument to load in a new extension | ||||
@@ -77,9 +77,14 @@ static void doReadallExternal (void) | |||||
static char *alts [] = | static char *alts [] = | ||||
{ | { | ||||
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3" | |||||
"IN", "OUT", "ALT0", "ALT1", "ALT2", "ALT3", "ALT4", "ALT5" | |||||
} ; | } ; | ||||
static const char *pupd [] = | |||||
{ | |||||
"DSBLD", "P/U", "P/D" | |||||
}; | |||||
static int physToWpi [64] = | static int physToWpi [64] = | ||||
{ | { | ||||
-1, // 0 | -1, // 0 | ||||
@@ -113,283 +118,249 @@ static int physToWpi [64] = | |||||
-1, -1, -1, -1, -1, -1, -1, -1, -1 | -1, -1, -1, -1, -1, -1, -1, -1, -1 | ||||
} ; | } ; | ||||
static char *physNames [64] = | |||||
/*------------------------------------------------------------------------------------------*/ | |||||
static const char *physNamesKhadasVim1[64] = { | |||||
NULL, | |||||
" 5V","GND ", | |||||
" 5V","PIN.DV25", | |||||
" HUB_DM1","PIN.DV24", | |||||
" HUB_DP1","GND ", | |||||
" GND","PIN.DV27", | |||||
" 5V","PIN.DV26", | |||||
" HUB_DM2","3.3V ", | |||||
" HUB_DP2","GND ", | |||||
" GND","PIN.H7 ", | |||||
" ADC.CH0","PIN.H6 ", | |||||
" GND","PIN.H9 ", | |||||
" ADC.CH2","PIN.H8 ", | |||||
" SPDIF","PIN.AO6 ", | |||||
" GND","GND ", | |||||
" PIN.AO5","PIN.AO3 ", | |||||
" PIN.AO4","RTC_CLK ", | |||||
" GND","PIN.H5 ", | |||||
" PIN.AO1","PWR_EN ", | |||||
" PIN.AO2","PWM_F ", | |||||
" 3.3V","GND ", | |||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||||
NULL,NULL,NULL, | |||||
}; | |||||
static const char *physNamesKhadasVim2[64] = { | |||||
NULL, | |||||
" 5V","GND ", | |||||
" 5v","PIN.DV25", | |||||
" USB_DM","PIN.DV24", | |||||
" USB_DP","GND ", | |||||
" GND","PIN.DV27", | |||||
"PIN.DV21","PIN.DV26", | |||||
"PIN.DV22","3.3V ", | |||||
"PIN.DV23","GND ", | |||||
" GND","PIN.H7 ", | |||||
" ADC0","PIN.H6 ", | |||||
" 1.8V","PIN.H9 ", | |||||
" ADC1","PIN.H8 ", | |||||
" SPDIF","PIN.AO6 ", | |||||
" GND","GND ", | |||||
" PIN.AO5","PIN.DV29", | |||||
" PIN.AO4","RTC_CLK ", | |||||
" GND","PIN.H5 ", | |||||
" PIN.AO1","EXP_INT ", | |||||
" PIN.AO0","PIN.DV13", | |||||
" 3.3v","GND ", | |||||
//Not used | |||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||||
NULL,NULL,NULL, | |||||
}; | |||||
static const char *physNamesKhadasVim3[64] = { | |||||
NULL, | |||||
" 5V","GND ", | |||||
" 5V","PIN.A15 ", | |||||
" USB_DM","PIN.A14 ", | |||||
" USB_DP","GND ", | |||||
" GND","PIN.AO2 ", | |||||
" MCU3V3","PIN.AO3 ", | |||||
" MCUNRST","3V3 ", | |||||
" MCUSWIM","GND ", | |||||
" GND","PIN.A1 ", | |||||
" ADC0","PIN.A0 ", | |||||
" 1V8","PIN.A3 ", | |||||
" ADC1","PIN.A2 ", | |||||
" SPDIF","PIN.A4 ", | |||||
" GND3","GND ", | |||||
" PIN.H6","PWM-F ", | |||||
" PIN.H7","RTC ", | |||||
" GND","PIN.H4 ", | |||||
" PIN.AO1","MCU-FA1 ", | |||||
" PIN.AO0","PIN.Z15 ", | |||||
" 3V3","GND ", | |||||
//Not used | |||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||||
NULL,NULL,NULL, | |||||
}; | |||||
static void readallPhysKhadas (int model, int rev, int physPin, const char *physNames[]) | |||||
{ | { | ||||
NULL, | |||||
" 3.3v", "5v ", | |||||
" SDA.1", "5v ", | |||||
" SCL.1", "0v ", | |||||
"GPIO. 7", "TxD ", | |||||
" 0v", "RxD ", | |||||
"GPIO. 0", "GPIO. 1", | |||||
"GPIO. 2", "0v ", | |||||
"GPIO. 3", "GPIO. 4", | |||||
" 3.3v", "GPIO. 5", | |||||
" MOSI", "0v ", | |||||
" MISO", "GPIO. 6", | |||||
" SCLK", "CE0 ", | |||||
" 0v", "CE1 ", | |||||
" SDA.0", "SCL.0 ", | |||||
"GPIO.21", "0v ", | |||||
"GPIO.22", "GPIO.26", | |||||
"GPIO.23", "0v ", | |||||
"GPIO.24", "GPIO.27", | |||||
"GPIO.25", "GPIO.28", | |||||
" 0v", "GPIO.29", | |||||
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, | |||||
} ; | |||||
/* | |||||
* readallPhys: | |||||
* Given a physical pin output the data on it and the next pin: | |||||
*| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM | | |||||
********************************************************************************* | |||||
*/ | |||||
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)) ; | |||||
} | |||||
// Pin numbers: | |||||
printf (" | %2d", physPin) ; | |||||
++physPin ; | |||||
printf (" || %-2d", physPin) ; | |||||
// Same, reversed | |||||
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") ; | |||||
int pin; | |||||
//GPIO, wPi pin number | |||||
if ((physPinToGpio (physPin) == -1) && (physToWpi [physPin] == -1)) | |||||
printf (" | | ") ; | |||||
else if (physPinToGpio (physPin) != -1) | |||||
printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]); | |||||
else | |||||
printf (" | | %3d", physToWpi [physPin]); | |||||
// GPIO pin name | |||||
printf (" | %s", physNames [physPin]); | |||||
// GPIO pin mode, value, drive strength, pupd | |||||
if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1)){ | |||||
printf (" | | | | ") ; | |||||
} | |||||
else { | |||||
if (wpMode == MODE_GPIO) | |||||
pin = physPinToGpio (physPin); | |||||
else if(wpMode == MODE_PHYS) | |||||
pin = physPin; | |||||
else{ | |||||
pin = physToWpi [physPin]; | |||||
} | |||||
printf (" | %4s", alts [getAlt (pin)]); | |||||
printf (" | %d", digitalRead (pin)); | |||||
switch(model) { | |||||
case MODEL_KHADAS_VIM1: | |||||
case MODEL_KHADAS_VIM2: | |||||
case MODEL_KHADAS_VIM3: | |||||
printf (" | | %5s", pupd[getPUPD(pin)]); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
// Physical pin number | |||||
printf (" | %2d", physPin); | |||||
++physPin; | |||||
printf (" || %-2d", physPin); | |||||
// GPIO pin mode, value, drive strength, pupd | |||||
if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1)) | |||||
printf (" | | | | "); | |||||
else { | |||||
if(wpMode == MODE_GPIO) | |||||
pin = physPinToGpio (physPin); | |||||
else if(wpMode == MODE_PHYS) | |||||
pin = physPin; | |||||
else | |||||
pin = physToWpi [physPin]; | |||||
switch(model){ | |||||
case MODEL_KHADAS_VIM1: | |||||
case MODEL_KHADAS_VIM2: | |||||
case MODEL_KHADAS_VIM3: | |||||
printf (" | %-5s | ", pupd[getPUPD(pin)]); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
printf (" | %d", digitalRead (pin)); | |||||
printf (" | %-4s", alts [getAlt (pin)]); | |||||
} | |||||
// GPIO pin name | |||||
printf (" | %-6s", physNames [physPin]); | |||||
//GPIO, wPi pin number | |||||
if ((physPinToGpio (physPin) == -1) && (physToWpi [physPin] == -1)) | |||||
printf (" | | ") ; | |||||
else if(physPinToGpio (physPin) != -1) | |||||
printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)); | |||||
else | |||||
printf (" | %-3d | ", physToWpi [physPin]); | |||||
printf (" |\n") ; | |||||
} | } | ||||
/* | |||||
* allReadall: | |||||
* Read all the pins regardless of the model. Primarily of use for | |||||
* the compute module, but handy for other fiddling... | |||||
********************************************************************************* | |||||
*/ | |||||
static void allReadall (void) | |||||
/*--------------------------------------------------------------------------------------*/ | |||||
void ReadallKhadas(int model, int rev, const char *physNames[]) | |||||
{ | { | ||||
int pin ; | |||||
printf ("+-----+------+-------+ +-----+------+-------+\n") ; | |||||
printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ; | |||||
printf ("+-----+------+-------+ +-----+------+-------+\n") ; | |||||
for (pin = 0 ; pin < 27 ; ++pin) | |||||
{ | |||||
printf ("| %3d ", pin) ; | |||||
printf ("| %-4s ", alts [getAlt (pin)]) ; | |||||
printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ; | |||||
printf ("| ") ; | |||||
printf ("| %3d ", pin + 27) ; | |||||
printf ("| %-4s ", alts [getAlt (pin + 27)]) ; | |||||
printf ("| %s ", digitalRead (pin + 27) == HIGH ? "High" : "Low ") ; | |||||
printf ("|\n") ; | |||||
} | |||||
printf ("+-----+------+-------+ +-----+------+-------+\n") ; | |||||
int pin; | |||||
printf (" | GPIO | wPi | Name | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode | Name | wPi | GPIO |\n"); | |||||
printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n"); | |||||
for (pin = 1 ; pin <= 40 ; pin += 2) | |||||
readallPhysKhadas (model, rev, pin, physNames); | |||||
printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n"); | |||||
} | } | ||||
/* | |||||
* abReadall: | |||||
* Read all the pins on the model A or B. | |||||
********************************************************************************* | |||||
*/ | |||||
void abReadall (int model, int rev) | |||||
/*--------------------------------------------------------------------------------------*/ | |||||
/* doReadall */ | |||||
/* Read all the GPIO pins */ | |||||
/* We also want to use this to read the state of pins on an externally */ | |||||
/* connected device, so we need to do some fiddling with the internal */ | |||||
/* wiringPi node structures - since the gpio command can only use */ | |||||
/* one external device at a time, we'll use that to our advantage... */ | |||||
/*--------------------------------------------------------------------------------------*/ | |||||
void doReadall(void) | |||||
{ | { | ||||
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) // B 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) ; | |||||
int model, rev, mem, maker, overVolted; | |||||
const char **physNames; | |||||
// External readall | |||||
if (wiringPiNodes != NULL) { | |||||
doReadallExternal (); | |||||
return; | |||||
} | |||||
piBoardId(&model, &rev, &mem, &maker, &overVolted); | |||||
switch(model){ | |||||
case MODEL_KHADAS_VIM1: | |||||
printf (" +------+-----+----------+------+---+----+---- Model KDADAS-VIM1---+----+---+------+----------+-----+------+\n") ; | |||||
physNames = physNamesKhadasVim1; | |||||
break; | |||||
case MODEL_KHADAS_VIM2: | |||||
printf (" +------+-----+----------+------+---+----+---- Model KDADAS-VIM2---+----+---+------+----------+-----+------+\n") ; | |||||
physNames = physNamesKhadasVim2; | |||||
break; | |||||
case MODEL_KHADAS_VIM3: | |||||
printf (" +------+-----+----------+------+---+----+---- Model KDADAS-VIM3---+----+---+------+----------+-----+------+\n") ; | |||||
physNames = physNamesKhadasVim3; | |||||
break; | |||||
default: | |||||
printf ("Oops - unable to determine board type... model: %d\n", model); | |||||
return; | |||||
} | |||||
ReadallKhadas(model, rev, physNames); | |||||
} | } | ||||
/* | |||||
* piPlusReadall: | |||||
* Read all the pins on the model A+ or the B+ or actually, all 40-pin Pi's | |||||
********************************************************************************* | |||||
*/ | |||||
static void plus2header (int model) | |||||
/*--------------------------------------------------------------------------------------*/ | |||||
/* doAllReadall */ | |||||
/* Force reading of all pins regardless of Pi model */ | |||||
/*--------------------------------------------------------------------------------------*/ | |||||
void doAllReadall(void) | |||||
{ | { | ||||
/**/ if (model == PI_MODEL_AP) | |||||
printf (" +-----+-----+---------+------+---+---Pi A+--+---+------+---------+-----+-----+\n") ; | |||||
else if (model == PI_MODEL_BP) | |||||
printf (" +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+\n") ; | |||||
else if (model == PI_MODEL_ZERO) | |||||
printf (" +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+\n") ; | |||||
else if (model == PI_MODEL_ZERO_W) | |||||
printf (" +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+\n") ; | |||||
else if (model == PI_MODEL_2) | |||||
printf (" +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+\n") ; | |||||
else if (model == PI_MODEL_3) | |||||
printf (" +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+\n") ; | |||||
else if (model == PI_MODEL_3P) | |||||
printf (" +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+\n") ; | |||||
else | |||||
printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ; | |||||
doReadall(); | |||||
} | } | ||||
static void piPlusReadall (int model) | |||||
/*--------------------------------------------------------------------------------------*/ | |||||
void doQmode(int argc, char *argv[]) | |||||
{ | { | ||||
int pin ; | |||||
plus2header (model) ; | |||||
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") ; | |||||
plus2header (model) ; | |||||
} | |||||
/* | |||||
* doReadall: | |||||
* Generic read all pins called from main program. Works out the Pi type | |||||
* and calls the appropriate function. | |||||
********************************************************************************* | |||||
*/ | |||||
void doReadall (void) | |||||
{ | |||||
int model, rev, mem, maker, overVolted ; | |||||
if (wiringPiNodes != NULL) // External readall | |||||
{ | |||||
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) || (model == PI_MODEL_AP) || | |||||
(model == PI_MODEL_2) || | |||||
(model == PI_MODEL_3) || (model == PI_MODEL_3P) || | |||||
(model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W)) | |||||
piPlusReadall (model) ; | |||||
else if ((model == PI_MODEL_CM) || (model == PI_MODEL_CM3)) | |||||
allReadall () ; | |||||
else | |||||
printf ("Oops - unable to determine board type... model: %d\n", model) ; | |||||
} | |||||
/* | |||||
* doAllReadall: | |||||
* Force reading of all pins regardless of Pi model | |||||
********************************************************************************* | |||||
*/ | |||||
void doAllReadall (void) | |||||
{ | |||||
allReadall () ; | |||||
} | |||||
/* | |||||
* doQmode: | |||||
* Query mode on a pin | |||||
********************************************************************************* | |||||
*/ | |||||
void doQmode (int argc, char *argv []) | |||||
{ | |||||
int pin ; | |||||
if (argc != 3) | |||||
{ | |||||
fprintf (stderr, "Usage: %s qmode pin\n", argv [0]) ; | |||||
exit (EXIT_FAILURE) ; | |||||
} | |||||
pin = atoi (argv [2]) ; | |||||
printf ("%s\n", alts [getAlt (pin)]) ; | |||||
int pin; | |||||
if(argc != 3){ | |||||
fprintf (stderr, "Usage: %s qmode pin\n", argv [0]) ; | |||||
exit(EXIT_FAILURE); | |||||
} | |||||
pin = atoi(argv[2]); | |||||
printf("%s\n", alts[getAlt(pin)]); | |||||
} | } | ||||
/*--------------------------------------------------------------------------------------*/ | |||||
/*--------------------------------------------------------------------------------------*/ |
@@ -61,7 +61,10 @@ SRC = wiringPi.c \ | |||||
bmp180.c htu21d.c ds18b20.c rht03.c \ | bmp180.c htu21d.c ds18b20.c rht03.c \ | ||||
drcSerial.c drcNet.c \ | drcSerial.c drcNet.c \ | ||||
pseudoPins.c \ | pseudoPins.c \ | ||||
wpiExtensions.c | |||||
wpiExtensions.c \ | |||||
khadas_vim1.c \ | |||||
khadas_vim2.c \ | |||||
khadas_vim3.c | |||||
HEADERS = $(shell ls *.h) | HEADERS = $(shell ls *.h) | ||||
@@ -128,6 +131,11 @@ depend: | |||||
# DO NOT DELETE | # DO NOT DELETE | ||||
#KHADAS Boards | |||||
khadas_vim1.o : wiringPi.h khadas_vim1.h | |||||
khadas_vim2.o : wiringPi.h khadas_vim2.h | |||||
khadas_vim3.o : wiringPi.h khadas_vim3.h | |||||
wiringPi.o: softPwm.h softTone.h wiringPi.h ../version.h | wiringPi.o: softPwm.h softTone.h wiringPi.h ../version.h | ||||
wiringSerial.o: wiringSerial.h | wiringSerial.o: wiringSerial.h | ||||
wiringShift.o: wiringPi.h wiringShift.h | wiringShift.o: wiringPi.h wiringShift.h | ||||
@@ -238,8 +238,8 @@ int rht03Setup (const int pinBase, const int piPin) | |||||
{ | { | ||||
struct wiringPiNodeStruct *node ; | struct wiringPiNodeStruct *node ; | ||||
if ((piPin & PI_GPIO_MASK) != 0) // Must be an on-board pin | |||||
return FALSE ; | |||||
//if ((piPin & PI_GPIO_MASK) != 0) // Must be an on-board pin | |||||
// return FALSE ; | |||||
// 2 pins - temperature and humidity | // 2 pins - temperature and humidity | ||||
@@ -24,34 +24,43 @@ | |||||
#ifndef __WIRING_PI_H__ | #ifndef __WIRING_PI_H__ | ||||
#define __WIRING_PI_H__ | #define __WIRING_PI_H__ | ||||
// C doesn't have true/false by default and I can never remember which | |||||
// way round they are, so ... | |||||
// (and yes, I know about stdbool.h but I like capitals for these and I'm old) | |||||
#include <stdio.h> | |||||
#include <stdarg.h> | |||||
#include <stdint.h> | |||||
#include <stdlib.h> | |||||
#ifndef TRUE | #ifndef TRUE | ||||
# define TRUE (1==1) | # define TRUE (1==1) | ||||
# define FALSE (!TRUE) | # define FALSE (!TRUE) | ||||
#endif | #endif | ||||
// GCC warning suppressor | |||||
#define PIN_NUM_CALC_SYSFD(x) (x>225 ? x - libwiring.pinBase : x) | |||||
// GCC warning suppressor | |||||
#define UNU __attribute__((unused)) | #define UNU __attribute__((unused)) | ||||
// Mask for the bottom 64 pins which belong to the Raspberry Pi | |||||
// The others are available for the other devices | |||||
#define ENV_DEBUG "WIRINGPI_DEBUG" | |||||
#define ENV_CODES "WIRINGPI_CODES" | |||||
#define ENV_GPIOMEM "WIRINGPI_GPIOMEM" | |||||
#define PI_GPIO_MASK (0xFFFFFFC0) | |||||
#define MODEL_UNKNOWN 0 | |||||
#define MODEL_KHADAS_VIM1 1 | |||||
#define MODEL_KHADAS_VIM2 2 | |||||
#define MODEL_KHADAS_VIM3 3 | |||||
// Handy defines | |||||
#define MAKER_UNKNOWN 0 | |||||
#define MAKER_AMLOGIC 1 | |||||
#define MAKER_ROCKCHIP 2 | |||||
// wiringPi modes | // wiringPi modes | ||||
#define WPI_MODE_PINS 0 | |||||
#define WPI_MODE_GPIO 1 | |||||
#define WPI_MODE_GPIO_SYS 2 | |||||
#define WPI_MODE_PHYS 3 | |||||
#define WPI_MODE_PIFACE 4 | |||||
#define WPI_MODE_UNINITIALISED -1 | |||||
#define MODE_PINS 0 | |||||
#define MODE_GPIO 1 | |||||
#define MODE_GPIO_SYS 2 | |||||
#define MODE_PHYS 3 | |||||
#define MODE_PIFACE 4 | |||||
#define MODE_UNINITIALISED -1 | |||||
// Pin modes | // Pin modes | ||||
@@ -84,32 +93,8 @@ | |||||
#define INT_EDGE_RISING 2 | #define INT_EDGE_RISING 2 | ||||
#define INT_EDGE_BOTH 3 | #define INT_EDGE_BOTH 3 | ||||
// Pi model types and version numbers | |||||
// Intended for the GPIO program Use at your own risk. | |||||
#define PI_MODEL_A 0 | |||||
#define PI_MODEL_B 1 | |||||
#define PI_MODEL_AP 2 | |||||
#define PI_MODEL_BP 3 | |||||
#define PI_MODEL_2 4 | |||||
#define PI_ALPHA 5 | |||||
#define PI_MODEL_CM 6 | |||||
#define PI_MODEL_07 7 | |||||
#define PI_MODEL_3 8 | |||||
#define PI_MODEL_ZERO 9 | |||||
#define PI_MODEL_CM3 10 | |||||
#define PI_MODEL_ZERO_W 12 | |||||
#define PI_MODEL_3P 13 | |||||
#define PI_VERSION_1 0 | |||||
#define PI_VERSION_1_1 1 | |||||
#define PI_VERSION_1_2 2 | |||||
#define PI_VERSION_2 3 | |||||
#define PI_MAKER_SONY 0 | |||||
#define PI_MAKER_EGOMAN 1 | |||||
#define PI_MAKER_EMBEST 2 | |||||
#define PI_MAKER_UNKNOWN 3 | |||||
//Module names | |||||
#define AML_MODULE_I2C "aml_i2c" | |||||
extern const char *piModelNames [16] ; | extern const char *piModelNames [16] ; | ||||
extern const char *piRevisionNames [16] ; | extern const char *piRevisionNames [16] ; | ||||
@@ -128,6 +113,87 @@ extern const int piMemorySize [ 8] ; | |||||
#define WPI_FATAL (1==1) | #define WPI_FATAL (1==1) | ||||
#define WPI_ALMOST (1==2) | #define WPI_ALMOST (1==2) | ||||
#define PAGE_SIZE (4*1024) | |||||
#define BLOCK_SIZE (4*1024) | |||||
#define MSG_ERR -1 | |||||
#define MSG_WARN -2 | |||||
struct libkhadas | |||||
{ | |||||
/* H/W model info */ | |||||
int model, rev, mem, maker; | |||||
/* wiringPi init mode */ | |||||
int mode; | |||||
/* wiringPi core func */ | |||||
int (*getModeToGpio) (int mode, int pin); | |||||
void (*setPadDrive) (int pin, int value); | |||||
int (*getPadDrive) (int pin); | |||||
void (*pinMode) (int pin, int mode); | |||||
int (*getAlt) (int pin); | |||||
int (*getPUPD) (int pin); | |||||
void (*pullUpDnControl) (int pin, int pud); | |||||
int (*digitalRead) (int pin); | |||||
void (*digitalWrite) (int pin, int value); | |||||
int (*analogRead) (int pin); | |||||
void (*digitalWriteByte) (const int value); | |||||
unsigned int (*digitalReadByte) (void); | |||||
/* ISR Function pointer */ | |||||
void (*isrFunctions[256])(void); | |||||
/* GPIO sysfs file discripter */ | |||||
int sysFds[256]; | |||||
/* GPIO pin base number */ | |||||
int pinBase; | |||||
// Time for easy calculations | |||||
uint64_t epochMilli, epochMicro ; | |||||
}; | |||||
union reg_bitfield { | |||||
unsigned int wvalue; | |||||
struct { | |||||
unsigned int bit0 : 1; | |||||
unsigned int bit1 : 1; | |||||
unsigned int bit2 : 1; | |||||
unsigned int bit3 : 1; | |||||
unsigned int bit4 : 1; | |||||
unsigned int bit5 : 1; | |||||
unsigned int bit6 : 1; | |||||
unsigned int bit7 : 1; | |||||
unsigned int bit8 : 1; | |||||
unsigned int bit9 : 1; | |||||
unsigned int bit10 : 1; | |||||
unsigned int bit11 : 1; | |||||
unsigned int bit12 : 1; | |||||
unsigned int bit13 : 1; | |||||
unsigned int bit14 : 1; | |||||
unsigned int bit15 : 1; | |||||
unsigned int bit16 : 1; | |||||
unsigned int bit17 : 1; | |||||
unsigned int bit18 : 1; | |||||
unsigned int bit19 : 1; | |||||
unsigned int bit20 : 1; | |||||
unsigned int bit21 : 1; | |||||
unsigned int bit22 : 1; | |||||
unsigned int bit23 : 1; | |||||
unsigned int bit24 : 1; | |||||
unsigned int bit25 : 1; | |||||
unsigned int bit26 : 1; | |||||
unsigned int bit27 : 1; | |||||
unsigned int bit28 : 1; | |||||
unsigned int bit29 : 1; | |||||
unsigned int bit30 : 1; | |||||
unsigned int bit31 : 1; | |||||
} bits; | |||||
}; | |||||
// wiringPiNodeStruct: | // wiringPiNodeStruct: | ||||
// This describes additional device nodes in the extended wiringPi | // This describes additional device nodes in the extended wiringPi | ||||
@@ -165,12 +231,12 @@ extern struct wiringPiNodeStruct *wiringPiNodes ; | |||||
// Export variables for the hardware pointers | // Export variables for the hardware pointers | ||||
extern volatile unsigned int *_wiringPiGpio ; | |||||
extern volatile unsigned int *_wiringPiPwm ; | |||||
extern volatile unsigned int *_wiringPiClk ; | |||||
extern volatile unsigned int *_wiringPiPads ; | |||||
extern volatile unsigned int *_wiringPiTimer ; | |||||
extern volatile unsigned int *_wiringPiTimerIrqRaw ; | |||||
//extern volatile unsigned int *_wiringPiGpio ; | |||||
//extern volatile unsigned int *_wiringPiPwm ; | |||||
//extern volatile unsigned int *_wiringPiClk ; | |||||
//extern volatile unsigned int *_wiringPiPads ; | |||||
//extern volatile unsigned int *_wiringPiTimer ; | |||||
//extern volatile unsigned int *_wiringPiTimerIrqRaw ; | |||||
// Function prototypes | // Function prototypes | ||||
@@ -183,9 +249,11 @@ extern "C" { | |||||
// Data | // Data | ||||
// Internal | |||||
// Internal WiringPi functions | |||||
extern int wiringPiFailure (int fatal, const char *message, ...) ; | extern int wiringPiFailure (int fatal, const char *message, ...) ; | ||||
extern int msg (int type, const char *message, ...); | |||||
extern int moduleLoaded (char *); | |||||
// Core wiringPi functions | // Core wiringPi functions | ||||
@@ -198,67 +266,60 @@ extern int wiringPiSetupSys (void) ; | |||||
extern int wiringPiSetupGpio (void) ; | extern int wiringPiSetupGpio (void) ; | ||||
extern int wiringPiSetupPhys (void) ; | extern int wiringPiSetupPhys (void) ; | ||||
extern void pinModeAlt (int pin, int mode) ; | |||||
extern void pinMode (int pin, int mode) ; | |||||
extern void pullUpDnControl (int pin, int pud) ; | |||||
extern int digitalRead (int pin) ; | |||||
extern void digitalWrite (int pin, int value) ; | |||||
extern unsigned int digitalRead8 (int pin) ; | |||||
extern void digitalWrite8 (int pin, int value) ; | |||||
extern void pwmWrite (int pin, int value) ; | |||||
extern int analogRead (int pin) ; | |||||
extern void analogWrite (int pin, int value) ; | |||||
// PiFace specifics | |||||
// (Deprecated) | |||||
extern int wiringPiSetupPiFace (void) ; | |||||
extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only | |||||
// On-Board Raspberry Pi hardware specific stuff | |||||
extern int piGpioLayout (void) ; | |||||
extern int piBoardRev (void) ; // Deprecated | |||||
extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; | |||||
extern int wpiPinToGpio (int wpiPin) ; | |||||
extern int physPinToGpio (int physPin) ; | |||||
extern void setPadDrive (int group, int value) ; | |||||
extern int getAlt (int pin) ; | |||||
extern void pwmToneWrite (int pin, int freq) ; | |||||
extern void pwmSetMode (int mode) ; | |||||
extern void pwmSetRange (unsigned int range) ; | |||||
extern void pwmSetClock (int divisor) ; | |||||
extern void gpioClockSet (int pin, int freq) ; | |||||
extern unsigned int digitalReadByte (void) ; | |||||
extern unsigned int digitalReadByte2 (void) ; | |||||
extern void digitalWriteByte (int value) ; | |||||
extern void digitalWriteByte2 (int value) ; | |||||
// Interrupts | |||||
// (Also Pi hardware specific) | |||||
extern int waitForInterrupt (int pin, int mS) ; | |||||
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ; | |||||
// Threads | |||||
extern int piThreadCreate (void *(*fn)(void *)) ; | |||||
extern void piLock (int key) ; | |||||
extern void piUnlock (int key) ; | |||||
// Schedulling priority | |||||
extern int piHiPri (const int pri) ; | |||||
// Extras from arduino land | |||||
extern void delay (unsigned int howLong) ; | |||||
extern void delayMicroseconds (unsigned int howLong) ; | |||||
extern unsigned int millis (void) ; | |||||
extern unsigned int micros (void) ; | |||||
extern int getModeToGpio (int wpiPin); | |||||
extern void setPadDrive (int pin, int value); | |||||
extern int getPadDrive (int pin); | |||||
extern int getAlt (int pin); | |||||
extern int getPUPD (int pin); | |||||
extern void pinMode (int pin,int mode); | |||||
extern void pullUpDnControl (int pin, int pud); | |||||
extern int digitalRead (int pin); | |||||
extern void digitalWrite (int pin, int value); | |||||
extern unsigned int digitalReadByte (void); | |||||
extern void digitalWriteByte (const int vaule); | |||||
extern void pwmWrite (int pin, int value); | |||||
extern int analogRead (int pin); | |||||
//Hardware Specific stuffs | |||||
extern int piGpioLayout (void); | |||||
extern int piBoardRev (void); | |||||
extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty); | |||||
extern int wpiPinToGpio (int wpiPin); | |||||
extern int physPinToGpio (int physPin); | |||||
//Unsupported | |||||
extern void pinModeAlt (int pin, int mode); | |||||
extern void analogWrite (int pin, int value); | |||||
extern void pwmToneWrite (int pin, int freq); | |||||
extern void pwmSetMode (int mode); | |||||
extern void pwmSetRange (unsigned int range); | |||||
extern void pwmSetClock (int divisor); | |||||
extern void gpioClockSet (int pin, int freq); | |||||
extern unsigned int digitalReadByte (void); | |||||
extern unsigned int digitalReadByte2 (void); | |||||
extern void digitalWriteByte (int value); | |||||
extern void digitalWriteByte2 (int value); | |||||
//Interrupt | |||||
extern int waitForInterrupt (int pin, int mS); | |||||
extern int wiringPiISR (int pin, int mode, void (*function)(void)); | |||||
//Threads | |||||
extern int piThreadCreate (void *(*fn)(void *)); | |||||
extern void piLock (int key); | |||||
extern void piUnlock (int key); | |||||
//Schedulling priority | |||||
//extern void piHiPri (unsigned int howLong); | |||||
//From Arduino land | |||||
extern void delay (unsigned int howLang); | |||||
extern void delayMicroseconds (unsigned int howLang); | |||||
extern unsigned int millis (void); | |||||
extern unsigned int micros (void); | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif | ||||
#endif | |||||
#endif /* __WIRING_H__ */ |
@@ -0,0 +1,264 @@ | |||||
/* | |||||
* wiringPi.h: | |||||
* Arduino like Wiring library for the Raspberry Pi. | |||||
* Copyright (c) 2012-2017 Gordon Henderson | |||||
*********************************************************************** | |||||
* This file is part of wiringPi: | |||||
* https://projects.drogon.net/raspberry-pi/wiringpi/ | |||||
* | |||||
* wiringPi is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU Lesser General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* wiringPi is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU Lesser General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public License | |||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>. | |||||
*********************************************************************** | |||||
*/ | |||||
#ifndef __WIRING_PI_H__ | |||||
#define __WIRING_PI_H__ | |||||
// C doesn't have true/false by default and I can never remember which | |||||
// way round they are, so ... | |||||
// (and yes, I know about stdbool.h but I like capitals for these and I'm old) | |||||
#ifndef TRUE | |||||
# define TRUE (1==1) | |||||
# define FALSE (!TRUE) | |||||
#endif | |||||
// GCC warning suppressor | |||||
#define UNU __attribute__((unused)) | |||||
// Mask for the bottom 64 pins which belong to the Raspberry Pi | |||||
// The others are available for the other devices | |||||
#define PI_GPIO_MASK (0xFFFFFFC0) | |||||
// Handy defines | |||||
// wiringPi modes | |||||
#define WPI_MODE_PINS 0 | |||||
#define WPI_MODE_GPIO 1 | |||||
#define WPI_MODE_GPIO_SYS 2 | |||||
#define WPI_MODE_PHYS 3 | |||||
#define WPI_MODE_PIFACE 4 | |||||
#define WPI_MODE_UNINITIALISED -1 | |||||
// Pin modes | |||||
#define INPUT 0 | |||||
#define OUTPUT 1 | |||||
#define PWM_OUTPUT 2 | |||||
#define GPIO_CLOCK 3 | |||||
#define SOFT_PWM_OUTPUT 4 | |||||
#define SOFT_TONE_OUTPUT 5 | |||||
#define PWM_TONE_OUTPUT 6 | |||||
#define LOW 0 | |||||
#define HIGH 1 | |||||
// Pull up/down/none | |||||
#define PUD_OFF 0 | |||||
#define PUD_DOWN 1 | |||||
#define PUD_UP 2 | |||||
// PWM | |||||
#define PWM_MODE_MS 0 | |||||
#define PWM_MODE_BAL 1 | |||||
// Interrupt levels | |||||
#define INT_EDGE_SETUP 0 | |||||
#define INT_EDGE_FALLING 1 | |||||
#define INT_EDGE_RISING 2 | |||||
#define INT_EDGE_BOTH 3 | |||||
// Pi model types and version numbers | |||||
// Intended for the GPIO program Use at your own risk. | |||||
#define PI_MODEL_A 0 | |||||
#define PI_MODEL_B 1 | |||||
#define PI_MODEL_AP 2 | |||||
#define PI_MODEL_BP 3 | |||||
#define PI_MODEL_2 4 | |||||
#define PI_ALPHA 5 | |||||
#define PI_MODEL_CM 6 | |||||
#define PI_MODEL_07 7 | |||||
#define PI_MODEL_3 8 | |||||
#define PI_MODEL_ZERO 9 | |||||
#define PI_MODEL_CM3 10 | |||||
#define PI_MODEL_ZERO_W 12 | |||||
#define PI_MODEL_3P 13 | |||||
#define PI_VERSION_1 0 | |||||
#define PI_VERSION_1_1 1 | |||||
#define PI_VERSION_1_2 2 | |||||
#define PI_VERSION_2 3 | |||||
#define PI_MAKER_SONY 0 | |||||
#define PI_MAKER_EGOMAN 1 | |||||
#define PI_MAKER_EMBEST 2 | |||||
#define PI_MAKER_UNKNOWN 3 | |||||
extern const char *piModelNames [16] ; | |||||
extern const char *piRevisionNames [16] ; | |||||
extern const char *piMakerNames [16] ; | |||||
extern const int piMemorySize [ 8] ; | |||||
// Intended for the GPIO program Use at your own risk. | |||||
// Threads | |||||
#define PI_THREAD(X) void *X (UNU void *dummy) | |||||
// Failure modes | |||||
#define WPI_FATAL (1==1) | |||||
#define WPI_ALMOST (1==2) | |||||
// wiringPiNodeStruct: | |||||
// This describes additional device nodes in the extended wiringPi | |||||
// 2.0 scheme of things. | |||||
// It's a simple linked list for now, but will hopefully migrate to | |||||
// a binary tree for efficiency reasons - but then again, the chances | |||||
// of more than 1 or 2 devices being added are fairly slim, so who | |||||
// knows.... | |||||
struct wiringPiNodeStruct | |||||
{ | |||||
int pinBase ; | |||||
int pinMax ; | |||||
int fd ; // Node specific | |||||
unsigned int data0 ; // ditto | |||||
unsigned int data1 ; // ditto | |||||
unsigned int data2 ; // ditto | |||||
unsigned int data3 ; // ditto | |||||
void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ; | |||||
void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ; | |||||
int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ; | |||||
//unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin) ; | |||||
void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ; | |||||
// void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value) ; | |||||
void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ; | |||||
int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ; | |||||
void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ; | |||||
struct wiringPiNodeStruct *next ; | |||||
} ; | |||||
extern struct wiringPiNodeStruct *wiringPiNodes ; | |||||
// Export variables for the hardware pointers | |||||
extern volatile unsigned int *_wiringPiGpio ; | |||||
extern volatile unsigned int *_wiringPiPwm ; | |||||
extern volatile unsigned int *_wiringPiClk ; | |||||
extern volatile unsigned int *_wiringPiPads ; | |||||
extern volatile unsigned int *_wiringPiTimer ; | |||||
extern volatile unsigned int *_wiringPiTimerIrqRaw ; | |||||
// Function prototypes | |||||
// c++ wrappers thanks to a comment by Nick Lott | |||||
// (and others on the Raspberry Pi forums) | |||||
#ifdef __cplusplus | |||||
extern "C" { | |||||
#endif | |||||
// Data | |||||
// Internal | |||||
extern int wiringPiFailure (int fatal, const char *message, ...) ; | |||||
// Core wiringPi functions | |||||
extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ; | |||||
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ; | |||||
extern void wiringPiVersion (int *major, int *minor) ; | |||||
extern int wiringPiSetup (void) ; | |||||
extern int wiringPiSetupSys (void) ; | |||||
extern int wiringPiSetupGpio (void) ; | |||||
extern int wiringPiSetupPhys (void) ; | |||||
extern void pinModeAlt (int pin, int mode) ; | |||||
extern void pinMode (int pin, int mode) ; | |||||
extern void pullUpDnControl (int pin, int pud) ; | |||||
extern int digitalRead (int pin) ; | |||||
extern void digitalWrite (int pin, int value) ; | |||||
extern unsigned int digitalRead8 (int pin) ; | |||||
extern void digitalWrite8 (int pin, int value) ; | |||||
extern void pwmWrite (int pin, int value) ; | |||||
extern int analogRead (int pin) ; | |||||
extern void analogWrite (int pin, int value) ; | |||||
// PiFace specifics | |||||
// (Deprecated) | |||||
extern int wiringPiSetupPiFace (void) ; | |||||
extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only | |||||
// On-Board Raspberry Pi hardware specific stuff | |||||
extern int piGpioLayout (void) ; | |||||
extern int piBoardRev (void) ; // Deprecated | |||||
extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; | |||||
extern int wpiPinToGpio (int wpiPin) ; | |||||
extern int physPinToGpio (int physPin) ; | |||||
extern void setPadDrive (int group, int value) ; | |||||
extern int getAlt (int pin) ; | |||||
extern void pwmToneWrite (int pin, int freq) ; | |||||
extern void pwmSetMode (int mode) ; | |||||
extern void pwmSetRange (unsigned int range) ; | |||||
extern void pwmSetClock (int divisor) ; | |||||
extern void gpioClockSet (int pin, int freq) ; | |||||
extern unsigned int digitalReadByte (void) ; | |||||
extern unsigned int digitalReadByte2 (void) ; | |||||
extern void digitalWriteByte (int value) ; | |||||
extern void digitalWriteByte2 (int value) ; | |||||
// Interrupts | |||||
// (Also Pi hardware specific) | |||||
extern int waitForInterrupt (int pin, int mS) ; | |||||
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ; | |||||
// Threads | |||||
extern int piThreadCreate (void *(*fn)(void *)) ; | |||||
extern void piLock (int key) ; | |||||
extern void piUnlock (int key) ; | |||||
// Schedulling priority | |||||
extern int piHiPri (const int pri) ; | |||||
// Extras from arduino land | |||||
extern void delay (unsigned int howLong) ; | |||||
extern void delayMicroseconds (unsigned int howLong) ; | |||||
extern unsigned int millis (void) ; | |||||
extern unsigned int micros (void) ; | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif |