diff --git a/gpio/Makefile b/gpio/Makefile
index 0b43204..1e8f10e 100755
--- a/gpio/Makefile
+++ b/gpio/Makefile
@@ -30,9 +30,6 @@ ifneq ($V,1)
Q ?= @
endif
-# BRAND_NAME = Pi
-BRAND_NAME = Odroid
-
#DEBUG = -g -O0
DEBUG = -O2
CC = gcc
@@ -44,16 +41,8 @@ LIBS = -lwiringPi -lwiringPiDev -lpthread -lrt -lm -lcrypt
# May not need to alter anything below this line
###############################################################################
-ifeq ($(BRAND_NAME), Odroid)
-
-SRC = gpio_odroid.c readall_odroid.c pins.c
-
-else
-
SRC = gpio.c readall.c pins.c
-endif
-
OBJ = $(SRC:.c=.o)
all: gpio
diff --git a/gpio/gpio.c b/gpio/gpio.c
old mode 100644
new mode 100755
index 6fd71f8..b28fe4f
--- a/gpio/gpio.c
+++ b/gpio/gpio.c
@@ -21,8 +21,6 @@
* along with wiringPi. If not, see .
***********************************************************************
*/
-
-
#include
#include
#include
@@ -49,6 +47,7 @@ extern int wiringPiDebug ;
extern void doReadall (void) ;
extern void doAllReadall (void) ;
extern void doPins (void) ;
+extern void doUnexport (int argc, char *agrv []);
#ifndef TRUE
# define TRUE (1==1)
@@ -56,36 +55,36 @@ extern void doPins (void) ;
#endif
#define PI_USB_POWER_CONTROL 38
-#define I2CDETECT "/usr/sbin/i2cdetect"
-#define MODPROBE "/sbin/modprobe"
-#define RMMOD "/sbin/rmmod"
+#define I2CDETECT "i2cdetect"
+#define MODPROBE "modprobe"
+#define RMMOD "rmmod"
int wpMode ;
char *usage = "Usage: gpio -v\n"
- " gpio -h\n"
- " gpio [-g|-1] ...\n"
- " gpio [-d] ...\n"
- " [-x extension:params] [[ -x ...]] ...\n"
- " gpio [-p] ...\n"
- " gpio ...\n"
- " gpio \n"
- " gpio readall/reset\n"
- " gpio unexportall/exports\n"
- " gpio export/edge/unexport ...\n"
- " gpio wfi \n"
- " gpio drive \n"
- " gpio pwm-bal/pwm-ms \n"
- " gpio pwmr \n"
- " gpio pwmc \n"
- " gpio load spi/i2c\n"
- " gpio unload spi/i2c\n"
- " gpio i2cd/i2cdetect\n"
- " gpio rbx/rbd\n"
- " gpio wb \n"
- " gpio usbp high/low\n"
- " gpio gbr \n"
- " gpio gbw " ; // No trailing newline needed here.
+ " gpio -h\n"
+ " gpio [-g|-1] ...\n"
+ " gpio [-d] ...\n"
+ " [-x extension:params] [[ -x ...]] ...\n"
+ " gpio [-p] ...\n"
+ " gpio ...\n"
+ " gpio \n"
+ " gpio readall/reset\n"
+ " gpio unexportall/exports\n"
+ " gpio export/edge/unexport ...\n"
+ " gpio wfi \n"
+ " gpio drive \n"
+ " gpio pwm-bal/pwm-ms \n"
+ " gpio pwmr \n"
+ " gpio pwmc \n"
+ " gpio load spi/i2c\n"
+ " gpio unload spi/i2c\n"
+ " gpio i2cd/i2cdetect\n"
+ " gpio rbx/rbd\n"
+ " gpio wb \n"
+ " gpio usbp high/low\n"
+ " gpio gbr \n"
+ " gpio gbw " ; // No trailing newline needed here.
#ifdef NOT_FOR_NOW
@@ -95,16 +94,13 @@ char *usage = "Usage: gpio -v\n"
* one of the Pi's on-board pins.
*********************************************************************************
*/
-
static int decodePin (const char *str)
{
+ // The first case - see if it's a number:
+ if (isdigit (str [0]))
+ return atoi (str) ;
-// The first case - see if it's a number:
-
- if (isdigit (str [0]))
- return atoi (str) ;
-
- return 0 ;
+ return 0 ;
}
#endif
@@ -117,34 +113,31 @@ static int decodePin (const char *str)
* which may be a security issue when this program is run a set-uid-root.
*********************************************************************************
*/
-
static const char *searchPath [] =
{
- "/sbin",
- "/usr/sbin",
- "/bin",
- "/usr/bin",
- NULL,
+ "/sbin",
+ "/usr/sbin",
+ "/bin",
+ "/usr/bin",
+ NULL,
} ;
static char *findExecutable (const char *progName)
{
- static char *path = NULL ;
- int len = strlen (progName) ;
- int i = 0 ;
- struct stat statBuf ;
+ static char *path = NULL ;
+ int len = strlen (progName) ;
+ int i = 0 ;
+ struct stat statBuf ;
- for (i = 0 ; searchPath [i] != NULL ; ++i)
- {
- path = malloc (strlen (searchPath [i]) + len + 2) ;
- sprintf (path, "%s/%s", searchPath [i], progName) ;
+ for (i = 0 ; searchPath [i] != NULL ; ++i) {
+ path = malloc (strlen (searchPath [i]) + len + 2) ;
+ sprintf (path, "%s/%s", searchPath [i], progName) ;
- if (stat (path, &statBuf) == 0)
- return path ;
- free (path) ;
- }
-
- return NULL ;
+ if (stat (path, &statBuf) == 0)
+ return path ;
+ free (path) ;
+ }
+ return NULL ;
}
@@ -154,153 +147,45 @@ static char *findExecutable (const char *progName)
* program so we can access it.
*********************************************************************************
*/
-
static void changeOwner (char *cmd, char *file)
{
- uid_t uid = getuid () ;
- uid_t gid = getgid () ;
+ uid_t uid = getuid () ;
+ uid_t gid = getgid () ;
- if (chown (file, uid, gid) != 0)
- {
-
-// Removed (ignoring) the check for not existing as I'm fed-up with morons telling me that
-// the warning message is an error.
-
- if (errno != ENOENT)
- fprintf (stderr, "%s: Unable to change ownership of %s: %s\n", cmd, file, strerror (errno)) ;
- }
+ if (chown (file, uid, gid) != 0) {
+ // Removed (ignoring) the check for not existing as I'm fed-up with morons telling me that
+ // the warning message is an error.
+ if (errno != ENOENT)
+ fprintf (stderr, "%s: Unable to change ownership of %s: %s\n",
+ cmd, file, strerror (errno)) ;
+ }
}
-
-/*
- * 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:
* Load either the spi or i2c modules and change device ownerships, etc.
*********************************************************************************
*/
-
static void checkDevTree (char *argv [])
{
- struct stat statBuf ;
+ struct stat statBuf ;
- if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ...
- {
- fprintf (stderr,
-"%s: Unable to load/unload modules as this Pi has the device tree enabled.\n"
-" You need to run the raspi-config program (as root) and select the\n"
-" modules (SPI or I2C) that you wish to load/unload there and reboot.\n"
-" There is more information here:\n"
-" https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314\n", argv [0]) ;
- exit (1) ;
- }
-}
-
-static void _doLoadUsage (char *argv [])
-{
- fprintf (stderr, "Usage: %s load [I2C baudrate in Kb/sec]\n", argv [0]) ;
- exit (1) ;
+ // We're on a devtree system ...
+ if (stat ("/proc/device-tree", &statBuf) == 0) {
+ fprintf (stderr,
+ "%s: Unable to load/unload modules as this kernel has the device tree enabled.\n"
+ " You need to edit /etc/modprobe.d/blacklist-odroid.conf or update /media/models.dts file.\n"
+ " If you want to use SPI, you should find out spidev module line at the blacklist-odroid.conf\n"
+ " and uncomment that. Then reboot to enable the module.\n\n"
+ " Please refer to our wiki page:\n"
+ " https://wiki.odroid.com/start\n", argv [0]) ;
+ exit (1) ;
+ }
}
static void doLoad (int argc, char *argv [])
{
- char *module1, *module2 ;
- char cmd [80] ;
- char *file1, *file2 ;
- char args1 [32], args2 [32] ;
-
- checkDevTree (argv) ;
-
- if (argc < 3)
- _doLoadUsage (argv) ;
-
- args1 [0] = args2 [0] = 0 ;
-
- /**/ if (strcasecmp (argv [2], "spi") == 0)
- {
- module1 = "spidev" ;
- module2 = "spi_bcm2708" ;
- file1 = "/dev/spidev0.0" ;
- file2 = "/dev/spidev0.1" ;
- if (argc == 4)
- {
- fprintf (stderr, "%s: Unable to set the buffer size now. Load aborted. Please see the man page.\n", argv [0]) ;
- exit (1) ;
- }
- else if (argc > 4)
- _doLoadUsage (argv) ;
- }
- else if (strcasecmp (argv [2], "i2c") == 0)
- {
- module1 = "i2c_dev" ;
- module2 = "i2c_bcm2708" ;
- file1 = "/dev/i2c-0" ;
- file2 = "/dev/i2c-1" ;
- if (argc == 4)
- sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ;
- else if (argc > 4)
- _doLoadUsage (argv) ;
- }
- else
- _doLoadUsage (argv) ;
-
- if (findExecutable ("modprobe") == NULL)
- printf ("No found\n") ;
-
- if (!moduleLoaded (module1))
- {
- sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module1, args1) ;
- system (cmd) ;
- }
-
- if (!moduleLoaded (module2))
- {
- sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module2, args2) ;
- system (cmd) ;
- }
-
- if (!moduleLoaded (module2))
- {
- fprintf (stderr, "%s: Unable to load %s\n", argv [0], module2) ;
- exit (1) ;
- }
-
- sleep (1) ; // To let things get settled
-
- changeOwner (argv [0], file1) ;
- changeOwner (argv [0], file2) ;
+ checkDevTree (argv) ;
}
@@ -309,47 +194,9 @@ static void doLoad (int argc, char *argv [])
* Un-Load either the spi or i2c modules and change device ownerships, etc.
*********************************************************************************
*/
-
-static void _doUnLoadUsage (char *argv [])
-{
- fprintf (stderr, "Usage: %s unload \n", argv [0]) ;
- exit (1) ;
-}
-
static void doUnLoad (int argc, char *argv [])
{
- char *module1, *module2 ;
- char cmd [80] ;
-
- checkDevTree (argv) ;
-
- if (argc != 3)
- _doUnLoadUsage (argv) ;
-
- /**/ if (strcasecmp (argv [2], "spi") == 0)
- {
- module1 = "spidev" ;
- module2 = "spi_bcm2708" ;
- }
- else if (strcasecmp (argv [2], "i2c") == 0)
- {
- module1 = "i2c_dev" ;
- module2 = "i2c_bcm2708" ;
- }
- else
- _doUnLoadUsage (argv) ;
-
- if (moduleLoaded (module1))
- {
- sprintf (cmd, "%s %s", findExecutable (RMMOD), module1) ;
- system (cmd) ;
- }
-
- if (moduleLoaded (module2))
- {
- sprintf (cmd, "%s %s", findExecutable (RMMOD), module2) ;
- system (cmd) ;
- }
+ checkDevTree (argv) ;
}
@@ -358,29 +205,50 @@ static void doUnLoad (int argc, char *argv [])
* Run the i2cdetect command with the right runes for this Pi revision
*********************************************************************************
*/
-
static void doI2Cdetect (UNU int argc, char *argv [])
{
- int port = piGpioLayout () == 1 ? 0 : 1 ;
- char *c, *command ;
+ int model, rev, mem, maker, overVolted, port;
+ const char *device = NULL;
+ char *c, *command ;
- if ((c = findExecutable (I2CDETECT)) == NULL)
- {
- fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ;
- return ;
- }
+ piBoardId(&model, &rev, &mem, &maker, &overVolted);
- if (!moduleLoaded ("i2c_dev"))
- {
- fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
- return ;
- }
+ switch (model) {
+ case MODEL_ODROID_C1: case MODEL_ODROID_C2:
+ case MODEL_ODROID_XU3:
+ device = "/dev/i2c-1";
+ port = 1;
+ break;
+ case MODEL_ODROID_N1:
+ device = "/dev/i2c-4";
+ port = 4;
+ break;
+ case MODEL_ODROID_N2:
+ device = "/dev/i2c-3";
+ port = 3;
+ default:
+ break;
+ }
- command = malloc (strlen (c) + 16) ;
- sprintf (command, "%s -y %d", c, port) ;
- if (system (command) < 0)
- fprintf (stderr, "%s: Unable to run i2cdetect: %s\n", argv [0], strerror (errno)) ;
+ if ((c = findExecutable (I2CDETECT)) == NULL) {
+ fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ;
+ return ;
+ }
+ switch (maker) {
+ case MAKER_AMLOGIC:
+ if (!moduleLoaded (AML_MODULE_I2C)) {
+ fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
+ return ;
+ }
+ default:
+ break;
+ }
+
+ command = malloc (strlen (c) + 16) ;
+ sprintf (command, "%s -y %d", c, port) ;
+ if (system (command) < 0)
+ fprintf (stderr, "%s: Unable to run i2cdetect: %s\n", argv [0], strerror (errno)) ;
}
@@ -389,80 +257,67 @@ static void doI2Cdetect (UNU int argc, char *argv [])
* List all GPIO exports
*********************************************************************************
*/
-
static void doExports (UNU int argc, UNU char *argv [])
{
- int fd ;
- int i, l, first ;
- char fName [128] ;
- char buf [16] ;
+ int fd ;
+ int i, l, first ;
+ char fName [128] ;
+ char buf [16] ;
- for (first = 0, i = 0 ; i < 64 ; ++i) // Crude, but effective
- {
+ // Crude, but effective
+ for (first = 0, i = 0 ; i < 256 ; ++i) {
+ // Try to read the direction
+ sprintf (fName, "/sys/class/gpio/gpio%d/direction", i) ;
+ if ((fd = open (fName, O_RDONLY)) == -1)
+ continue ;
-// Try to read the direction
+ if (first == 0) {
+ ++first ;
+ printf ("GPIO Pins exported:\n") ;
+ }
+ printf ("%4d: ", i) ;
- sprintf (fName, "/sys/class/gpio/gpio%d/direction", i) ;
- if ((fd = open (fName, O_RDONLY)) == -1)
- continue ;
-
- if (first == 0)
- {
- ++first ;
- printf ("GPIO Pins exported:\n") ;
- }
-
- printf ("%4d: ", i) ;
-
- if ((l = read (fd, buf, 16)) == 0)
- sprintf (buf, "%s", "?") ;
+ if ((l = read (fd, buf, 16)) == 0)
+ sprintf (buf, "%s", "?") ;
- buf [l] = 0 ;
- if ((buf [strlen (buf) - 1]) == '\n')
- buf [strlen (buf) - 1] = 0 ;
+ buf [l] = 0 ;
+ if ((buf [strlen (buf) - 1]) == '\n')
+ buf [strlen (buf) - 1] = 0 ;
+ printf ("%-3s", buf) ;
+ close (fd) ;
- printf ("%-3s", buf) ;
+ // Try to Read the value
+ sprintf (fName, "/sys/class/gpio/gpio%d/value", i) ;
+ if ((fd = open (fName, O_RDONLY)) == -1) {
+ printf ("No Value file (huh?)\n") ;
+ continue ;
+ }
- close (fd) ;
+ if ((l = read (fd, buf, 16)) == 0)
+ sprintf (buf, "%s", "?") ;
-// Try to Read the value
+ buf [l] = 0 ;
+ if ((buf [strlen (buf) - 1]) == '\n')
+ buf [strlen (buf) - 1] = 0 ;
+ printf (" %s", buf) ;
+ close (fd) ;
- sprintf (fName, "/sys/class/gpio/gpio%d/value", i) ;
- if ((fd = open (fName, O_RDONLY)) == -1)
- {
- printf ("No Value file (huh?)\n") ;
- continue ;
- }
+ // Read any edge trigger file
+ sprintf (fName, "/sys/class/gpio/gpio%d/edge", i) ;
+ if ((fd = open (fName, O_RDONLY)) == -1) {
+ printf ("\n") ;
+ continue ;
+ }
- if ((l = read (fd, buf, 16)) == 0)
- sprintf (buf, "%s", "?") ;
+ if ((l = read (fd, buf, 16)) == 0)
+ sprintf (buf, "%s", "?") ;
- buf [l] = 0 ;
- if ((buf [strlen (buf) - 1]) == '\n')
- buf [strlen (buf) - 1] = 0 ;
-
- printf (" %s", buf) ;
-
-// Read any edge trigger file
-
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", i) ;
- if ((fd = open (fName, O_RDONLY)) == -1)
- {
- printf ("\n") ;
- continue ;
- }
-
- if ((l = read (fd, buf, 16)) == 0)
- sprintf (buf, "%s", "?") ;
-
- buf [l] = 0 ;
- if ((buf [strlen (buf) - 1]) == '\n')
- buf [strlen (buf) - 1] = 0 ;
-
- printf (" %-8s\n", buf) ;
-
- close (fd) ;
- }
+ buf [l] = 0 ;
+ if ((buf [strlen (buf) - 1]) == '\n')
+ buf [strlen (buf) - 1] = 0 ;
+ printf (" %-8s\n", buf) ;
+ close (fd) ;
+ }
}
@@ -472,64 +327,55 @@ static void doExports (UNU int argc, UNU char *argv [])
* This uses the /sys/class/gpio device interface.
*********************************************************************************
*/
-
void doExport (int argc, char *argv [])
{
- FILE *fd ;
- int pin ;
- char *mode ;
- char fName [128] ;
+ FILE *fd ;
+ int pin ;
+ char *mode ;
+ char fName [128] ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s export pin mode\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s export pin mode\n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
+ pin = atoi (argv [2]) ;
+ mode = argv [3] ;
- mode = argv [3] ;
+ if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
+ exit (1) ;
+ }
- if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
- exit (1) ;
- }
+ fprintf (fd, "%d\n", pin) ;
+ fclose (fd) ;
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
+ sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
+ if ((fd = fopen (fName, "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
+ exit (1) ;
+ }
- sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
- if ((fd = fopen (fName, "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
- exit (1) ;
- }
+ if ((strcasecmp (mode, "in") == 0) || (strcasecmp (mode, "input") == 0))
+ fprintf (fd, "in\n") ;
+ else if ((strcasecmp (mode, "out") == 0) || (strcasecmp (mode, "output") == 0))
+ fprintf (fd, "out\n") ;
+ else if ((strcasecmp (mode, "high") == 0) || (strcasecmp (mode, "up") == 0))
+ fprintf (fd, "high\n") ;
+ else if ((strcasecmp (mode, "low") == 0) || (strcasecmp (mode, "down") == 0))
+ fprintf (fd, "low\n") ;
+ else {
+ fprintf (stderr, "%s: Invalid mode: %s. Should be in, out, high or low\n", argv [1], mode) ;
+ exit (1) ;
+ }
+ fclose (fd) ;
- /**/ if ((strcasecmp (mode, "in") == 0) || (strcasecmp (mode, "input") == 0))
- fprintf (fd, "in\n") ;
- else if ((strcasecmp (mode, "out") == 0) || (strcasecmp (mode, "output") == 0))
- fprintf (fd, "out\n") ;
- else if ((strcasecmp (mode, "high") == 0) || (strcasecmp (mode, "up") == 0))
- fprintf (fd, "high\n") ;
- else if ((strcasecmp (mode, "low") == 0) || (strcasecmp (mode, "down") == 0))
- fprintf (fd, "low\n") ;
- else
- {
- fprintf (stderr, "%s: Invalid mode: %s. Should be in, out, high or low\n", argv [1], mode) ;
- exit (1) ;
- }
-
- fclose (fd) ;
-
-// Change ownership so the current user can actually use it
-
- sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
- changeOwner (argv [0], fName) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
- changeOwner (argv [0], fName) ;
+ // Change ownership so the current user can actually use it
+ sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
+ changeOwner (argv [0], fName) ;
+ sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
+ changeOwner (argv [0], fName) ;
}
@@ -542,43 +388,37 @@ void doExport (int argc, char *argv [])
* to exit the program. Crude but effective.
*********************************************************************************
*/
-
-static void wfi (void)
- { exit (0) ; }
+static void wfi (void) { exit (0) ; }
void doWfi (int argc, char *argv [])
{
- int pin, mode ;
+ int pin, mode ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s wfi pin mode\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s wfi pin mode\n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
+ pin = atoi (argv [2]) ;
- /**/ if (strcasecmp (argv [3], "rising") == 0) mode = INT_EDGE_RISING ;
- else if (strcasecmp (argv [3], "falling") == 0) mode = INT_EDGE_FALLING ;
- else if (strcasecmp (argv [3], "both") == 0) mode = INT_EDGE_BOTH ;
- else
- {
- fprintf (stderr, "%s: wfi: Invalid mode: %s. Should be rising, falling or both\n", argv [1], argv [3]) ;
- exit (1) ;
- }
+ if (strcasecmp (argv [3], "rising") == 0) mode = INT_EDGE_RISING ;
+ else if (strcasecmp (argv [3], "falling") == 0) mode = INT_EDGE_FALLING ;
+ else if (strcasecmp (argv [3], "both") == 0) mode = INT_EDGE_BOTH ;
+ else {
+ fprintf (stderr, "%s: wfi: Invalid mode: %s. Should be rising, falling or both\n", argv [1], argv [3]) ;
+ exit (1) ;
+ }
- if (wiringPiISR (pin, mode, &wfi) < 0)
- {
- fprintf (stderr, "%s: wfi: Unable to setup ISR: %s\n", argv [1], strerror (errno)) ;
- exit (1) ;
- }
+ if (wiringPiISR (pin, mode, &wfi) < 0) {
+ fprintf (stderr, "%s: wfi: Unable to setup ISR: %s\n", argv [1], strerror (errno)) ;
+ exit (1) ;
+ }
- for (;;)
- delay (9999) ;
+ for (;;)
+ delay (9999) ;
}
-
/*
* doEdge:
* gpio edge pin mode
@@ -589,67 +429,61 @@ void doWfi (int argc, char *argv [])
void doEdge (int argc, char *argv [])
{
- FILE *fd ;
- int pin ;
- char *mode ;
- char fName [128] ;
+ FILE *fd ;
+ int pin ;
+ char *mode ;
+ char fName [128] ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s edge pin mode\n", argv [0]) ;
- exit (1) ;
- }
+ // Reset gpio sysfs
+ doUnexport(3, argv);
- pin = atoi (argv [2]) ;
- mode = argv [3] ;
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s edge pin mode\n", argv [0]) ;
+ exit (1) ;
+ }
-// Export the pin and set direction to input
+ pin = atoi (argv [2]) ;
+ mode = argv [3] ;
- if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
- exit (1) ;
- }
+ // Export the pin and set direction to input
+ if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
+ exit (1) ;
+ }
+ fprintf (fd, "%d\n", pin) ;
+ fclose (fd) ;
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
+ sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
+ if ((fd = fopen (fName, "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
+ exit (1) ;
+ }
+ fprintf (fd, "in\n") ;
+ fclose (fd) ;
- sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
- if ((fd = fopen (fName, "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
- exit (1) ;
- }
+ sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
+ if ((fd = fopen (fName, "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO edge interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
+ exit (1) ;
+ }
- fprintf (fd, "in\n") ;
- fclose (fd) ;
+ if (strcasecmp (mode, "none") == 0) fprintf (fd, "none\n") ;
+ else if (strcasecmp (mode, "rising") == 0) fprintf (fd, "rising\n") ;
+ else if (strcasecmp (mode, "falling") == 0) fprintf (fd, "falling\n") ;
+ else if (strcasecmp (mode, "both") == 0) fprintf (fd, "both\n") ;
+ else {
+ fprintf (stderr, "%s: Invalid mode: %s. Should be none, rising, falling or both\n", argv [1], mode) ;
+ exit (1) ;
+ }
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
- if ((fd = fopen (fName, "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO edge interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
- exit (1) ;
- }
+ // Change ownership of the value and edge files, so the current user can actually use it!
+ sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
+ changeOwner (argv [0], fName) ;
- /**/ if (strcasecmp (mode, "none") == 0) fprintf (fd, "none\n") ;
- else if (strcasecmp (mode, "rising") == 0) fprintf (fd, "rising\n") ;
- else if (strcasecmp (mode, "falling") == 0) fprintf (fd, "falling\n") ;
- else if (strcasecmp (mode, "both") == 0) fprintf (fd, "both\n") ;
- else
- {
- fprintf (stderr, "%s: Invalid mode: %s. Should be none, rising, falling or both\n", argv [1], mode) ;
- exit (1) ;
- }
+ sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
+ changeOwner (argv [0], fName) ;
-// Change ownership of the value and edge files, so the current user can actually use it!
-
- sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
- changeOwner (argv [0], fName) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
- changeOwner (argv [0], fName) ;
-
- fclose (fd) ;
+ fclose (fd) ;
}
@@ -662,25 +496,23 @@ void doEdge (int argc, char *argv [])
void doUnexport (int argc, char *argv [])
{
- FILE *fd ;
- int pin ;
+ FILE *fd ;
+ int pin ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s unexport pin\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s unexport pin\n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
+ pin = atoi (argv [2]) ;
- if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ;
- exit (1) ;
- }
+ if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ;
+ exit (1) ;
+ }
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
+ fprintf (fd, "%d\n", pin) ;
+ fclose (fd) ;
}
@@ -694,19 +526,17 @@ void doUnexport (int argc, char *argv [])
void doUnexportall (char *progName)
{
- FILE *fd ;
- int pin ;
+ FILE *fd ;
+ int pin ;
- for (pin = 0 ; pin < 63 ; ++pin)
- {
- if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL)
- {
- fprintf (stderr, "%s: Unable to open GPIO export interface\n", progName) ;
- exit (1) ;
- }
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
- }
+ for (pin = 0 ; pin < 256 ; ++pin) {
+ if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) {
+ fprintf (stderr, "%s: Unable to open GPIO export interface\n", progName) ;
+ exit (1) ;
+ }
+ fprintf (fd, "%d\n", pin) ;
+ fclose (fd) ;
+ }
}
@@ -718,9 +548,9 @@ void doUnexportall (char *progName)
static void doReset (UNU char *progName)
{
- printf ("GPIO Reset is dangerous and has been removed from the gpio command.\n") ;
- printf (" - Please write a shell-script to reset the GPIO pins into the state\n") ;
- printf (" that you need them in for your applications.\n") ;
+ printf ("GPIO Reset is dangerous and has been removed from the gpio command.\n") ;
+ printf (" - Please write a shell-script to reset the GPIO pins into the state\n") ;
+ printf (" that you need them in for your applications.\n") ;
}
@@ -732,128 +562,60 @@ static void doReset (UNU char *progName)
void doMode (int argc, char *argv [])
{
- int pin ;
- char *mode ;
+ int pin ;
+ char *mode ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s mode pin mode\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s mode pin mode\n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
+ pin = atoi (argv [2]) ;
+ mode = argv [3] ;
- mode = argv [3] ;
-
- /**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
- else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ;
- else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
- else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ;
- else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
- else if (strcasecmp (mode, "pwmTone") == 0) pinMode (pin, PWM_TONE_OUTPUT) ;
- else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ;
- else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
- else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
- else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
- else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;
- else if (strcasecmp (mode, "alt0") == 0) pinModeAlt (pin, 0b100) ;
- else if (strcasecmp (mode, "alt1") == 0) pinModeAlt (pin, 0b101) ;
- else if (strcasecmp (mode, "alt2") == 0) pinModeAlt (pin, 0b110) ;
- else if (strcasecmp (mode, "alt3") == 0) pinModeAlt (pin, 0b111) ;
- else if (strcasecmp (mode, "alt4") == 0) pinModeAlt (pin, 0b011) ;
- else if (strcasecmp (mode, "alt5") == 0) pinModeAlt (pin, 0b010) ;
- else
- {
- fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
- exit (1) ;
- }
+ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
+ else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ;
+ else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
+ else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ;
+ else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
+ else if (strcasecmp (mode, "pwmTone") == 0) pinMode (pin, PWM_TONE_OUTPUT) ;
+ else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ;
+ else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
+ else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
+ else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
+ else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;
+ else if (strcasecmp (mode, "alt0") == 0) pinModeAlt (pin, 0b100) ;
+ else if (strcasecmp (mode, "alt1") == 0) pinModeAlt (pin, 0b101) ;
+ else if (strcasecmp (mode, "alt2") == 0) pinModeAlt (pin, 0b110) ;
+ else if (strcasecmp (mode, "alt3") == 0) pinModeAlt (pin, 0b111) ;
+ else if (strcasecmp (mode, "alt4") == 0) pinModeAlt (pin, 0b011) ;
+ else if (strcasecmp (mode, "alt5") == 0) pinModeAlt (pin, 0b010) ;
+ else {
+ fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
+ exit (1) ;
+ }
}
/*
* doPadDrive:
- * gpio drive group value
+ * gpio drive pin value for ODROIDs since it depends on the SoC
*********************************************************************************
*/
static void doPadDrive (int argc, char *argv [])
{
- int group, val ;
+ int pin, val;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s drive group value\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s drive pin value\n", argv [0]) ;
+ exit (1) ;
+ }
- group = atoi (argv [2]) ;
- val = atoi (argv [3]) ;
+ pin = atoi (argv [2]) ;
+ val = atoi (argv [3]) ;
- if ((group < 0) || (group > 2))
- {
- fprintf (stderr, "%s: drive group not 0, 1 or 2: %d\n", argv [0], group) ;
- exit (1) ;
- }
-
- if ((val < 0) || (val > 7))
- {
- fprintf (stderr, "%s: drive value not 0-7: %d\n", argv [0], val) ;
- exit (1) ;
- }
-
- setPadDrive (group, val) ;
-}
-
-
-/*
- * doUsbP:
- * Control USB Power - High (1.2A) or Low (600mA)
- * gpio usbp high/low
- *********************************************************************************
- */
-
-static void doUsbP (int argc, char *argv [])
-{
- int model, rev, mem, maker, overVolted ;
-
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
- exit (1) ;
- }
-
-// Make sure we're on a B+
-
- piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
-
- if (!((model == PI_MODEL_BP) || (model == PI_MODEL_2)))
- {
- fprintf (stderr, "USB power contol is applicable to B+ and v2 boards only.\n") ;
- exit (1) ;
- }
-
-// Make sure we start in BCM_GPIO mode
-
- wiringPiSetupGpio () ;
-
- if ((strcasecmp (argv [2], "high") == 0) || (strcasecmp (argv [2], "hi") == 0))
- {
- digitalWrite (PI_USB_POWER_CONTROL, 1) ;
- pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
- printf ("Switched to HIGH current USB (1.2A)\n") ;
- return ;
- }
-
- if ((strcasecmp (argv [2], "low") == 0) || (strcasecmp (argv [2], "lo") == 0))
- {
- digitalWrite (PI_USB_POWER_CONTROL, 0) ;
- pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
- printf ("Switched to LOW current USB (600mA)\n") ;
- return ;
- }
-
- fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
- exit (1) ;
+ setPadDrive (pin, val) ;
}
@@ -866,36 +628,32 @@ static void doUsbP (int argc, char *argv [])
static void doGbw (int argc, char *argv [])
{
- int channel, value ;
+ int channel, value ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s gbw \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s gbw \n", argv [0]) ;
+ exit (1) ;
+ }
- channel = atoi (argv [2]) ;
- value = atoi (argv [3]) ;
+ channel = atoi (argv [2]) ;
+ value = atoi (argv [3]) ;
- if ((channel < 0) || (channel > 1))
- {
- fprintf (stderr, "%s: gbw: Channel number must be 0 or 1\n", argv [0]) ;
- exit (1) ;
- }
+ if ((channel < 0) || (channel > 1)) {
+ fprintf (stderr, "%s: gbw: Channel number must be 0 or 1\n", argv [0]) ;
+ exit (1) ;
+ }
- if ((value < 0) || (value > 255))
- {
- fprintf (stderr, "%s: gbw: Value must be from 0 to 255\n", argv [0]) ;
- exit (1) ;
- }
+ if ((value < 0) || (value > 255)) {
+ fprintf (stderr, "%s: gbw: Value must be from 0 to 255\n", argv [0]) ;
+ exit (1) ;
+ }
- if (gertboardAnalogSetup (64) < 0)
- {
- fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
- exit (1) ;
- }
+ if (gertboardAnalogSetup (64) < 0) {
+ fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
+ exit (1) ;
+ }
- analogWrite (64 + channel, value) ;
+ analogWrite (64 + channel, value) ;
}
@@ -905,32 +663,28 @@ static void doGbw (int argc, char *argv [])
* From the analog input
*********************************************************************************
*/
-
static void doGbr (int argc, char *argv [])
{
- int channel ;
+ int channel ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s gbr \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s gbr \n", argv [0]) ;
+ exit (1) ;
+ }
- channel = atoi (argv [2]) ;
+ channel = atoi (argv [2]) ;
- if ((channel < 0) || (channel > 1))
- {
- fprintf (stderr, "%s: gbr: Channel number must be 0 or 1\n", argv [0]) ;
- exit (1) ;
- }
+ if ((channel < 0) || (channel > 1)) {
+ fprintf (stderr, "%s: gbr: Channel number must be 0 or 1\n", argv [0]) ;
+ exit (1) ;
+ }
- if (gertboardAnalogSetup (64) < 0)
- {
- fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
- exit (1) ;
- }
+ if (gertboardAnalogSetup (64) < 0) {
+ fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
+ exit (1) ;
+ }
- printf ("%d\n", analogRead (64 + channel)) ;
+ printf ("%d\n", analogRead (64 + channel)) ;
}
@@ -942,27 +696,26 @@ static void doGbr (int argc, char *argv [])
static void doWrite (int argc, char *argv [])
{
- int pin, val ;
+ int pin, val ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s write pin value\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s write pin value\n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
+ pin = atoi (argv [2]) ;
- /**/ if ((strcasecmp (argv [3], "up") == 0) || (strcasecmp (argv [3], "on") == 0))
- val = 1 ;
- else if ((strcasecmp (argv [3], "down") == 0) || (strcasecmp (argv [3], "off") == 0))
- val = 0 ;
- else
- val = atoi (argv [3]) ;
+ if ((strcasecmp (argv [3], "up") == 0) || (strcasecmp (argv [3], "on") == 0))
+ val = 1 ;
+ else if ((strcasecmp (argv [3], "down") == 0) || (strcasecmp (argv [3], "off") == 0))
+ val = 0 ;
+ else
+ val = atoi (argv [3]) ;
- /**/ if (val == 0)
- digitalWrite (pin, LOW) ;
- else
- digitalWrite (pin, HIGH) ;
+ if (val == 0)
+ digitalWrite (pin, LOW) ;
+ else
+ digitalWrite (pin, HIGH) ;
}
@@ -974,19 +727,16 @@ static void doWrite (int argc, char *argv [])
static void doAwrite (int argc, char *argv [])
{
- int pin, val ;
+ int pin, val ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s awrite pin value\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s awrite pin value\n", argv [0]) ;
+ exit (1) ;
+ }
+ pin = atoi (argv [2]) ;
+ val = atoi (argv [3]) ;
- pin = atoi (argv [2]) ;
-
- val = atoi (argv [3]) ;
-
- analogWrite (pin, val) ;
+ analogWrite (pin, val) ;
}
@@ -998,17 +748,15 @@ static void doAwrite (int argc, char *argv [])
static void doWriteByte (int argc, char *argv [])
{
- int val ;
+ int val ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s wb value\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s wb value\n", argv [0]) ;
+ exit (1) ;
+ }
+ val = (int)strtol (argv [2], NULL, 0) ;
- val = (int)strtol (argv [2], NULL, 0) ;
-
- digitalWriteByte (val) ;
+ digitalWriteByte (val) ;
}
@@ -1020,19 +768,18 @@ static void doWriteByte (int argc, char *argv [])
static void doReadByte (int argc, char *argv [], int printHex)
{
- int val ;
+ int val ;
- if (argc != 2)
- {
- fprintf (stderr, "Usage: %s rbx|rbd\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 2) {
+ fprintf (stderr, "Usage: %s rbx|rbd\n", argv [0]) ;
+ exit (1) ;
+ }
- val = digitalReadByte () ;
- if (printHex)
- printf ("%02X\n", val) ;
- else
- printf ("%d\n", val) ;
+ val = digitalReadByte () ;
+ if (printHex)
+ printf ("%02X\n", val) ;
+ else
+ printf ("%d\n", val) ;
}
@@ -1044,18 +791,16 @@ static void doReadByte (int argc, char *argv [], int printHex)
void doRead (int argc, char *argv [])
{
- int pin, val ;
+ int pin, val ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s read pin\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s read pin\n", argv [0]) ;
+ exit (1) ;
+ }
+ pin = atoi (argv [2]) ;
+ val = digitalRead (pin) ;
- pin = atoi (argv [2]) ;
- val = digitalRead (pin) ;
-
- printf ("%s\n", val == 0 ? "0" : "1") ;
+ printf ("%s\n", val == 0 ? "0" : "1") ;
}
@@ -1067,13 +812,11 @@ void doRead (int argc, char *argv [])
void doAread (int argc, char *argv [])
{
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s aread pin\n", argv [0]) ;
- exit (1) ;
- }
-
- printf ("%d\n", analogRead (atoi (argv [2]))) ;
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s aread pin\n", argv [0]) ;
+ exit (1) ;
+ }
+ printf ("%d\n", analogRead (atoi (argv [2]))) ;
}
@@ -1085,17 +828,15 @@ void doAread (int argc, char *argv [])
void doToggle (int argc, char *argv [])
{
- int pin ;
+ int pin ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s toggle pin\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s toggle pin\n", argv [0]) ;
+ exit (1) ;
+ }
+ pin = atoi (argv [2]) ;
- pin = atoi (argv [2]) ;
-
- digitalWrite (pin, !digitalRead (pin)) ;
+ digitalWrite (pin, !digitalRead (pin)) ;
}
@@ -1107,23 +848,20 @@ void doToggle (int argc, char *argv [])
void doBlink (int argc, char *argv [])
{
- int pin ;
+ int pin ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s blink pin\n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s blink pin\n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
-
- pinMode (pin, OUTPUT) ;
- for (;;)
- {
- digitalWrite (pin, !digitalRead (pin)) ;
- delay (500) ;
- }
+ pin = atoi (argv [2]) ;
+ pinMode (pin, OUTPUT) ;
+ for (;;) {
+ digitalWrite (pin, !digitalRead (pin)) ;
+ delay (500) ;
+ }
}
@@ -1135,18 +873,17 @@ void doBlink (int argc, char *argv [])
void doPwmTone (int argc, char *argv [])
{
- int pin, freq ;
+ int pin, freq ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s pwmTone \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s pwmTone \n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
- freq = atoi (argv [3]) ;
+ pin = atoi (argv [2]) ;
+ freq = atoi (argv [3]) ;
- pwmToneWrite (pin, freq) ;
+ pwmToneWrite (pin, freq) ;
}
@@ -1158,19 +895,18 @@ void doPwmTone (int argc, char *argv [])
void doClock (int argc, char *argv [])
{
- int pin, freq ;
+ int pin, freq ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s clock \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s clock \n", argv [0]) ;
+ exit (1) ;
+ }
- pin = atoi (argv [2]) ;
+ pin = atoi (argv [2]) ;
- freq = atoi (argv [3]) ;
+ freq = atoi (argv [3]) ;
- gpioClockSet (pin, freq) ;
+ gpioClockSet (pin, freq) ;
}
@@ -1182,19 +918,16 @@ void doClock (int argc, char *argv [])
void doPwm (int argc, char *argv [])
{
- int pin, val ;
+ int pin, val ;
- if (argc != 4)
- {
- fprintf (stderr, "Usage: %s pwm \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 4) {
+ fprintf (stderr, "Usage: %s pwm \n", argv [0]) ;
+ exit (1) ;
+ }
+ pin = atoi (argv [2]) ;
+ val = atoi (argv [3]) ;
- pin = atoi (argv [2]) ;
-
- val = atoi (argv [3]) ;
-
- pwmWrite (pin, val) ;
+ pwmWrite (pin, val) ;
}
@@ -1206,51 +939,55 @@ void doPwm (int argc, char *argv [])
static void doPwmMode (int mode)
{
- pwmSetMode (mode) ;
+ pwmSetMode (mode) ;
}
static void doPwmRange (int argc, char *argv [])
{
- unsigned int range ;
+ unsigned int range ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s pwmr \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s pwmr \n", argv [0]) ;
+ exit (1) ;
+ }
- range = (unsigned int)strtoul (argv [2], NULL, 10) ;
+ range = (unsigned int)strtoul (argv [2], NULL, 10) ;
- if (range == 0)
- {
- fprintf (stderr, "%s: range must be > 0\n", argv [0]) ;
- exit (1) ;
- }
-
- pwmSetRange (range) ;
+ if (range == 0) {
+ fprintf (stderr, "%s: range must be > 0\n", argv [0]) ;
+ exit (1) ;
+ }
+ pwmSetRange (range) ;
}
static void doPwmClock (int argc, char *argv [])
{
- unsigned int clock ;
+ unsigned int clock ;
- if (argc != 3)
- {
- fprintf (stderr, "Usage: %s pwmc \n", argv [0]) ;
- exit (1) ;
- }
+ if (argc != 3) {
+ fprintf (stderr, "Usage: %s pwmc \n", argv [0]) ;
+ exit (1) ;
+ }
- clock = (unsigned int)strtoul (argv [2], NULL, 10) ;
+ clock = (unsigned int)strtoul (argv [2], NULL, 10) ;
- if ((clock < 1) || (clock > 4095))
- {
- fprintf (stderr, "%s: clock must be between 0 and 4096\n", argv [0]) ;
- exit (1) ;
- }
-
- pwmSetClock (clock) ;
+ if ((clock < 1) || (clock > 4095)) {
+ fprintf (stderr, "%s: clock must be between 0 and 4096\n", argv [0]) ;
+ exit (1) ;
+ }
+ pwmSetClock (clock) ;
}
+/*
+ * doNothing:
+ * function is not support by ODROID Board.
+ *********************************************************************************
+ */
+static void doNothing (int argc, char *argv [])
+{
+ fprintf(stderr, "warn : (%s) : This function is not supported by ODROID Board.\n",
+ argv[1]);
+}
/*
* doVersion:
@@ -1258,47 +995,50 @@ static void doPwmClock (int argc, char *argv [])
* some usefull information.
*********************************************************************************
*/
-
static void doVersion (char *argv [])
{
- int model, rev, mem, maker, warranty ;
- struct stat statBuf ;
- char name [80] ;
- FILE *fd ;
+ int model, rev, mem, maker, warranty ;
+ struct stat statBuf ;
+ char name [80] ;
+ FILE *fd ;
- int vMaj, vMin ;
+ int vMaj, vMin ;
- wiringPiVersion (&vMaj, &vMin) ;
- printf ("gpio version: %d.%d\n", vMaj, vMin) ;
- printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
- printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
- printf ("For details type: %s -warranty\n", argv [0]) ;
- printf ("\n") ;
- piBoardId (&model, &rev, &mem, &maker, &warranty) ;
+ wiringPiVersion (&vMaj, &vMin) ;
+ printf ("gpio version: %d.%d\n", vMaj, vMin) ;
+ printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
+ printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
+ printf ("For details type: %s -warranty\n", argv [0]) ;
+ printf ("\n") ;
+ piBoardId (&model, &rev, &mem, &maker, &warranty) ;
- printf ("Raspberry Pi Details:\n") ;
- printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
- piModelNames [model], piRevisionNames [rev], piMemorySize [mem], piMakerNames [maker], warranty ? "[Out of Warranty]" : "") ;
+ printf ("ODROID Board Details:\n") ;
+ printf (" Type: %s, Revision: %s, Memory: %dMB\n" \
+ " Maker: %s, Chip-Vendor: %s\n",
+ piModelNames [model],
+ piRevisionNames [rev],
+ piMemorySize [mem],
+ "Hardkernel",
+ piMakerNames [maker]);
-// Check for device tree
+ // Check for device tree
+ if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ...
+ printf (" * Device tree is enabled.\n") ;
- if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ...
- printf (" * Device tree is enabled.\n") ;
+ // Output Kernel idea of board type
+ if (stat ("/proc/device-tree/model", &statBuf) == 0) {
+ if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL) {
+ fgets (name, 80, fd) ;
+ fclose (fd) ;
+ printf (" *--> %s\n", name) ;
+ }
+ }
- if (stat ("/proc/device-tree/model", &statBuf) == 0) // Output Kernel idea of board type
- {
- if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL)
- {
- fgets (name, 80, fd) ;
- fclose (fd) ;
- printf (" *--> %s\n", name) ;
- }
- }
-
- if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO
- printf (" * This Raspberry Pi supports user-level GPIO access.\n") ;
- else
- printf (" * Root or sudo required for GPIO access.\n") ;
+ // User level GPIO is GO
+ if (stat ("/dev/gpiomem", &statBuf) == 0)
+ printf (" * Supports user-level GPIO access.\n") ;
+ else
+ printf (" * Root or sudo required for GPIO access.\n") ;
}
@@ -1310,226 +1050,177 @@ static void doVersion (char *argv [])
int main (int argc, char *argv [])
{
- int i ;
+ int i ;
- if (getenv ("WIRINGPI_DEBUG") != NULL)
- {
- printf ("gpio: wiringPi debug mode enabled\n") ;
- wiringPiDebug = TRUE ;
- }
+ if (getenv ("WIRINGPI_DEBUG") != NULL) {
+ printf ("gpio: wiringPi debug mode enabled\n") ;
+ wiringPiDebug = TRUE ;
+ }
- if (argc == 1)
- {
- fprintf (stderr, "%s\n", usage) ;
- return 1 ;
- }
+ if (argc == 1) {
+ fprintf (stderr, "%s\n", usage) ;
+ return 1 ;
+ }
-// Help
+ // Help
+ if (strcasecmp (argv [1], "-h") == 0) {
+ printf ("%s: %s\n", argv [0], usage) ;
+ return 0 ;
+ }
- if (strcasecmp (argv [1], "-h") == 0)
- {
- printf ("%s: %s\n", argv [0], usage) ;
- return 0 ;
- }
+ // Version & Warranty
+ // Wish I could remember why I have both -R and -V ...
+ if ((strcmp (argv [1], "-R") == 0) || (strcmp (argv [1], "-V") == 0)) {
+ printf ("%d\n", piGpioLayout ()) ;
+ return 0 ;
+ }
-// Version & Warranty
-// Wish I could remember why I have both -R and -V ...
+ // Version and information
+ if (strcmp (argv [1], "-v") == 0) {
+ doVersion (argv) ;
+ return 0 ;
+ }
- if ((strcmp (argv [1], "-R") == 0) || (strcmp (argv [1], "-V") == 0))
- {
- printf ("%d\n", piGpioLayout ()) ;
- return 0 ;
- }
+ if (strcasecmp (argv [1], "-warranty") == 0) {
+ printf ("gpio version: %s\n", VERSION) ;
+ printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
+ printf ("\n") ;
+ printf (" This program is free software; you can redistribute it and/or modify\n") ;
+ printf (" it under the terms of the GNU Leser General Public License as published\n") ;
+ printf (" by the Free Software Foundation, either version 3 of the License, or\n") ;
+ printf (" (at your option) any later version.\n") ;
+ printf ("\n") ;
+ printf (" This program is distributed in the hope that it will be useful,\n") ;
+ printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ;
+ printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ;
+ printf (" GNU Lesser General Public License for more details.\n") ;
+ printf ("\n") ;
+ printf (" You should have received a copy of the GNU Lesser General Public License\n") ;
+ printf (" along with this program. If not, see .\n") ;
+ printf ("\n") ;
+ return 0 ;
+ }
-// Version and information
+ if (geteuid () != 0) {
+ fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
+ return 1 ;
+ }
- if (strcmp (argv [1], "-v") == 0)
- {
- doVersion (argv) ;
- return 0 ;
- }
+ // Initial test for /sys/class/gpio operations:
+ if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; }
+ else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; }
+ else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; }
+ else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; }
+ else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argv [0]) ; return 0 ; }
- if (strcasecmp (argv [1], "-warranty") == 0)
- {
- printf ("gpio version: %s\n", VERSION) ;
- printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
- printf ("\n") ;
- printf (" This program is free software; you can redistribute it and/or modify\n") ;
- printf (" it under the terms of the GNU Leser General Public License as published\n") ;
- printf (" by the Free Software Foundation, either version 3 of the License, or\n") ;
- printf (" (at your option) any later version.\n") ;
- printf ("\n") ;
- printf (" This program is distributed in the hope that it will be useful,\n") ;
- printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ;
- printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ;
- printf (" GNU Lesser General Public License for more details.\n") ;
- printf ("\n") ;
- printf (" You should have received a copy of the GNU Lesser General Public License\n") ;
- printf (" along with this program. If not, see .\n") ;
- printf ("\n") ;
- return 0 ;
- }
+ // Check for load command:
+ if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
+ if (strcasecmp (argv [1], "unload" ) == 0) { doUnLoad (argc, argv) ; return 0 ; }
- if (geteuid () != 0)
- {
- fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
- return 1 ;
- }
+ // Check for usb power command
+ if (strcasecmp (argv [1], "usbp" ) == 0) { doNothing(argc, argv) ; return 0 ; }
-// Initial test for /sys/class/gpio operations:
+ // Gertboard commands
+ if (strcasecmp (argv [1], "gbr" ) == 0) { doGbr (argc, argv) ; return 0 ; }
+ if (strcasecmp (argv [1], "gbw" ) == 0) { doGbw (argc, argv) ; return 0 ; }
- /**/ if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argv [0]) ; return 0 ; }
+ // Check for allreadall command, force Gpio mode
+ if (strcasecmp (argv [1], "allreadall") == 0) {
+ wiringPiSetupGpio () ;
+ doAllReadall () ;
+ return 0 ;
+ }
-// Check for load command:
+ if (strcasecmp (argv [1], "-g") == 0) { // Check for -g argument
+ wiringPiSetupGpio () ;
- if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
- if (strcasecmp (argv [1], "unload" ) == 0) { doUnLoad (argc, argv) ; return 0 ; }
+ for (i = 2 ; i < argc ; ++i)
+ argv [i - 1] = argv [i] ;
+ --argc ;
+ wpMode = MODE_GPIO ;
+ } else if (strcasecmp (argv [1], "-1") == 0) { // Check for -1 argument
+ wiringPiSetupPhys () ;
-// Check for usb power command
+ for (i = 2 ; i < argc ; ++i)
+ argv [i - 1] = argv [i] ;
+ --argc ;
+ wpMode = MODE_PHYS ;
+ } else if (strcasecmp (argv [1], "-p") == 0) { // Check for -p argument for PiFace
+ piFaceSetup (200) ;
- if (strcasecmp (argv [1], "usbp" ) == 0) { doUsbP (argc, argv) ; return 0 ; }
+ for (i = 2 ; i < argc ; ++i)
+ argv [i - 1] = argv [i] ;
+ --argc ;
+ wpMode = MODE_PIFACE ;
+ } else if (strcasecmp (argv [1], "-z") == 0) { // Check for -z argument so we don't actually initialise wiringPi
+ for (i = 2 ; i < argc ; ++i)
+ argv [i - 1] = argv [i] ;
+ --argc ;
+ wpMode = MODE_UNINITIALISED ;
+ } else { // Default to wiringPi mode
+ wiringPiSetup () ;
+ wpMode = MODE_PINS ;
+ }
-// Gertboard commands
+ // Check for -x argument to load in a new extension
+ // -x extension:base:args
+ // Can load many modules, but unless daemon mode we can only send one
+ // command at a time.
+ while (strcasecmp (argv [1], "-x") == 0) {
+ if (argc < 3) {
+ fprintf (stderr, "%s: -x missing extension command.\n", argv [0]) ;
+ exit (EXIT_FAILURE) ;
+ }
- if (strcasecmp (argv [1], "gbr" ) == 0) { doGbr (argc, argv) ; return 0 ; }
- if (strcasecmp (argv [1], "gbw" ) == 0) { doGbw (argc, argv) ; return 0 ; }
+ if (!loadWPiExtension (argv [0], argv [2], TRUE)) {
+ fprintf (stderr, "%s: Extension load failed: %s\n", argv [0], strerror (errno)) ;
+ exit (EXIT_FAILURE) ;
+ }
-// Check for allreadall command, force Gpio mode
+ // Shift args down by 2
+ for (i = 3 ; i < argc ; ++i)
+ argv [i - 2] = argv [i] ;
+ argc -= 2 ;
+ }
- if (strcasecmp (argv [1], "allreadall") == 0)
- {
- wiringPiSetupGpio () ;
- doAllReadall () ;
- return 0 ;
- }
+ if (argc <= 1) {
+ fprintf (stderr, "%s: no command given\n", argv [0]) ;
+ exit (EXIT_FAILURE) ;
+ }
-// Check for -g argument
+ // Core wiringPi functions
+ /**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
+ else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
+ else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ;
+ else if (strcasecmp (argv [1], "pwm" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "awrite" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ;
- /**/ if (strcasecmp (argv [1], "-g") == 0)
- {
- wiringPiSetupGpio () ;
+ // GPIO Nicies
+ else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ;
+ else if (strcasecmp (argv [1], "blink" ) == 0) doBlink (argc, argv) ;
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = WPI_MODE_GPIO ;
- }
-
-// Check for -1 argument
-
- else if (strcasecmp (argv [1], "-1") == 0)
- {
- wiringPiSetupPhys () ;
-
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = WPI_MODE_PHYS ;
- }
-
-// Check for -p argument for PiFace
-
- else if (strcasecmp (argv [1], "-p") == 0)
- {
- piFaceSetup (200) ;
-
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = WPI_MODE_PIFACE ;
- }
-
-// Check for -z argument so we don't actually initialise wiringPi
-
- else if (strcasecmp (argv [1], "-z") == 0)
- {
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = WPI_MODE_UNINITIALISED ;
- }
-
-// Default to wiringPi mode
-
- else
- {
- wiringPiSetup () ;
- wpMode = WPI_MODE_PINS ;
- }
-
-// Check for -x argument to load in a new extension
-// -x extension:base:args
-// Can load many modules, but unless daemon mode we can only send one
-// command at a time.
-
- while (strcasecmp (argv [1], "-x") == 0)
- {
- if (argc < 3)
- {
- fprintf (stderr, "%s: -x missing extension command.\n", argv [0]) ;
- exit (EXIT_FAILURE) ;
- }
-
- if (!loadWPiExtension (argv [0], argv [2], TRUE))
- {
- fprintf (stderr, "%s: Extension load failed: %s\n", argv [0], strerror (errno)) ;
- exit (EXIT_FAILURE) ;
- }
-
-// Shift args down by 2
-
- for (i = 3 ; i < argc ; ++i)
- argv [i - 2] = argv [i] ;
- argc -= 2 ;
- }
-
- if (argc <= 1)
- {
- fprintf (stderr, "%s: no command given\n", argv [0]) ;
- exit (EXIT_FAILURE) ;
- }
-
-// Core wiringPi functions
-
- /**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
- else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
- else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ;
- else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
- else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite (argc, argv) ;
- else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ;
-
-// GPIO Nicies
-
- else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ;
- else if (strcasecmp (argv [1], "blink" ) == 0) doBlink (argc, argv) ;
-
-// Pi Specifics
-
- else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doPwmMode (PWM_MODE_BAL) ;
- else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ;
- else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ;
- else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ;
- else if (strcasecmp (argv [1], "pwmTone" ) == 0) doPwmTone (argc, argv) ;
- else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
- else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
- else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
- else if (strcasecmp (argv [1], "pins" ) == 0) doPins () ;
- else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ;
- else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ;
- else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ;
- else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ;
- else if (strcasecmp (argv [1], "rbx" ) == 0) doReadByte (argc, argv, TRUE) ;
- else if (strcasecmp (argv [1], "rbd" ) == 0) doReadByte (argc, argv, FALSE) ;
- else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ;
- else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ;
- else
- {
- fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
- exit (EXIT_FAILURE) ;
- }
- return 0 ;
+ // Pi Specifics
+ else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "pwmr" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "pwmc" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "pwmTone" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
+ else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
+ else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
+ else if (strcasecmp (argv [1], "pins" ) == 0) doPins () ;
+ else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ;
+ else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ;
+ else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ;
+ else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ;
+ else if (strcasecmp (argv [1], "rbx" ) == 0) doReadByte (argc, argv, TRUE) ;
+ else if (strcasecmp (argv [1], "rbd" ) == 0) doReadByte (argc, argv, FALSE) ;
+ else if (strcasecmp (argv [1], "clock" ) == 0) doNothing (argc, argv) ;
+ else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ;
+ else {
+ fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
+ exit (EXIT_FAILURE) ;
+ }
+ return 0 ;
}
diff --git a/gpio/gpio_odroid.c b/gpio/gpio_odroid.c
deleted file mode 100755
index 916dbfa..0000000
--- a/gpio/gpio_odroid.c
+++ /dev/null
@@ -1,1225 +0,0 @@
-/*
- * gpio.c:
- * Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
- * Pi's GPIO.
- * 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 .
- ***********************************************************************
- */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-
-#include "../version.h"
-
-extern int wiringPiDebug ;
-
-// External functions I can't be bothered creating a separate .h file for:
-
-extern void doReadall (void) ;
-extern void doAllReadall (void) ;
-extern void doPins (void) ;
-
-#ifndef TRUE
-# define TRUE (1==1)
-# define FALSE (1==2)
-#endif
-
-#define PI_USB_POWER_CONTROL 38
-#define I2CDETECT "i2cdetect"
-#define MODPROBE "modprobe"
-#define RMMOD "rmmod"
-
-int wpMode ;
-
-char *usage = "Usage: gpio -v\n"
- " gpio -h\n"
- " gpio [-g|-1] ...\n"
- " gpio [-d] ...\n"
- " [-x extension:params] [[ -x ...]] ...\n"
- " gpio [-p] ...\n"
- " gpio ...\n"
- " gpio \n"
- " gpio readall/reset\n"
- " gpio unexportall/exports\n"
- " gpio export/edge/unexport ...\n"
- " gpio wfi \n"
- " gpio drive \n"
- " gpio pwm-bal/pwm-ms \n"
- " gpio pwmr \n"
- " gpio pwmc \n"
- " gpio load spi/i2c\n"
- " gpio unload spi/i2c\n"
- " gpio i2cd/i2cdetect\n"
- " gpio rbx/rbd\n"
- " gpio wb \n"
- " gpio usbp high/low\n"
- " gpio gbr \n"
- " gpio gbw " ; // No trailing newline needed here.
-
-
-#ifdef NOT_FOR_NOW
-/*
- * decodePin:
- * Decode a pin "number" which can actually be a pin name to represent
- * one of the Pi's on-board pins.
- *********************************************************************************
- */
-static int decodePin (const char *str)
-{
- // The first case - see if it's a number:
- if (isdigit (str [0]))
- return atoi (str) ;
-
- return 0 ;
-}
-#endif
-
-
-/*
- * findExecutable:
- * Code to locate the path to the given executable. We have a fixed list
- * of locations to try which completely overrides any $PATH environment.
- * This may be detrimental, however it avoids the reliance on $PATH
- * which may be a security issue when this program is run a set-uid-root.
- *********************************************************************************
- */
-static const char *searchPath [] =
-{
- "/sbin",
- "/usr/sbin",
- "/bin",
- "/usr/bin",
- NULL,
-} ;
-
-static char *findExecutable (const char *progName)
-{
- static char *path = NULL ;
- int len = strlen (progName) ;
- int i = 0 ;
- struct stat statBuf ;
-
- for (i = 0 ; searchPath [i] != NULL ; ++i) {
- path = malloc (strlen (searchPath [i]) + len + 2) ;
- sprintf (path, "%s/%s", searchPath [i], progName) ;
-
- if (stat (path, &statBuf) == 0)
- return path ;
- free (path) ;
- }
- return NULL ;
-}
-
-
-/*
- * changeOwner:
- * Change the ownership of the file to the real userId of the calling
- * program so we can access it.
- *********************************************************************************
- */
-static void changeOwner (char *cmd, char *file)
-{
- uid_t uid = getuid () ;
- uid_t gid = getgid () ;
-
- if (chown (file, uid, gid) != 0) {
- // Removed (ignoring) the check for not existing as I'm fed-up with morons telling me that
- // the warning message is an error.
- if (errno != ENOENT)
- fprintf (stderr, "%s: Unable to change ownership of %s: %s\n",
- cmd, file, strerror (errno)) ;
- }
-}
-
-/*
- * doLoad:
- * Load either the spi or i2c modules and change device ownerships, etc.
- *********************************************************************************
- */
-static void checkDevTree (char *argv [])
-{
- struct stat statBuf ;
-
- // We're on a devtree system ...
- if (stat ("/proc/device-tree", &statBuf) == 0) {
- fprintf (stderr,
- "%s: Unable to load/unload modules as this kernel has the device tree enabled.\n"
- " You need to edit /etc/modprobe.d/blacklist-odroid.conf or update /media/models.dts file.\n"
- " If you want to use SPI, you should find out spidev module line at the blacklist-odroid.conf\n"
- " and uncomment that. Then reboot to enable the module.\n\n"
- " Please refer to our wiki page:\n"
- " https://wiki.odroid.com/start\n", argv [0]) ;
- exit (1) ;
- }
-}
-
-static void doLoad (int argc, char *argv [])
-{
- checkDevTree (argv) ;
-}
-
-
-/*
- * doUnLoad:
- * Un-Load either the spi or i2c modules and change device ownerships, etc.
- *********************************************************************************
- */
-static void doUnLoad (int argc, char *argv [])
-{
- checkDevTree (argv) ;
-}
-
-
-/*
- * doI2Cdetect:
- * Run the i2cdetect command with the right runes for this Pi revision
- *********************************************************************************
- */
-static void doI2Cdetect (UNU int argc, char *argv [])
-{
- int model, rev, mem, maker, overVolted, port;
- const char *device = NULL;
- char *c, *command ;
-
- piBoardId(&model, &rev, &mem, &maker, &overVolted);
-
- switch (model) {
- case MODEL_ODROID_C1: case MODEL_ODROID_C2:
- case MODEL_ODROID_XU3:
- device = "/dev/i2c-1";
- port = 1;
- break;
- case MODEL_ODROID_N1:
- device = "/dev/i2c-4";
- port = 4;
- break;
- case MODEL_ODROID_N2:
- device = "/dev/i2c-3";
- port = 3;
- default:
- break;
- }
-
- if ((c = findExecutable (I2CDETECT)) == NULL) {
- fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ;
- return ;
- }
-
- switch (maker) {
- case MAKER_AMLOGIC:
- if (!moduleLoaded (AML_MODULE_I2C)) {
- fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
- return ;
- }
- default:
- break;
- }
-
- command = malloc (strlen (c) + 16) ;
- sprintf (command, "%s -y %d", c, port) ;
- if (system (command) < 0)
- fprintf (stderr, "%s: Unable to run i2cdetect: %s\n", argv [0], strerror (errno)) ;
-}
-
-
-/*
- * doExports:
- * List all GPIO exports
- *********************************************************************************
- */
-static void doExports (UNU int argc, UNU char *argv [])
-{
- int fd ;
- int i, l, first ;
- char fName [128] ;
- char buf [16] ;
-
- // Crude, but effective
- for (first = 0, i = 0 ; i < 256 ; ++i) {
- // Try to read the direction
- sprintf (fName, "/sys/class/gpio/gpio%d/direction", i) ;
- if ((fd = open (fName, O_RDONLY)) == -1)
- continue ;
-
- if (first == 0) {
- ++first ;
- printf ("GPIO Pins exported:\n") ;
- }
- printf ("%4d: ", i) ;
-
- if ((l = read (fd, buf, 16)) == 0)
- sprintf (buf, "%s", "?") ;
-
- buf [l] = 0 ;
- if ((buf [strlen (buf) - 1]) == '\n')
- buf [strlen (buf) - 1] = 0 ;
- printf ("%-3s", buf) ;
- close (fd) ;
-
- // Try to Read the value
- sprintf (fName, "/sys/class/gpio/gpio%d/value", i) ;
- if ((fd = open (fName, O_RDONLY)) == -1) {
- printf ("No Value file (huh?)\n") ;
- continue ;
- }
-
- if ((l = read (fd, buf, 16)) == 0)
- sprintf (buf, "%s", "?") ;
-
- buf [l] = 0 ;
- if ((buf [strlen (buf) - 1]) == '\n')
- buf [strlen (buf) - 1] = 0 ;
- printf (" %s", buf) ;
- close (fd) ;
-
- // Read any edge trigger file
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", i) ;
- if ((fd = open (fName, O_RDONLY)) == -1) {
- printf ("\n") ;
- continue ;
- }
-
- if ((l = read (fd, buf, 16)) == 0)
- sprintf (buf, "%s", "?") ;
-
- buf [l] = 0 ;
- if ((buf [strlen (buf) - 1]) == '\n')
- buf [strlen (buf) - 1] = 0 ;
- printf (" %-8s\n", buf) ;
- close (fd) ;
- }
-}
-
-
-/*
- * doExport:
- * gpio export pin mode
- * This uses the /sys/class/gpio device interface.
- *********************************************************************************
- */
-void doExport (int argc, char *argv [])
-{
- FILE *fd ;
- int pin ;
- char *mode ;
- char fName [128] ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s export pin mode\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
- mode = argv [3] ;
-
- if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
- exit (1) ;
- }
-
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
- if ((fd = fopen (fName, "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
- exit (1) ;
- }
-
- if ((strcasecmp (mode, "in") == 0) || (strcasecmp (mode, "input") == 0))
- fprintf (fd, "in\n") ;
- else if ((strcasecmp (mode, "out") == 0) || (strcasecmp (mode, "output") == 0))
- fprintf (fd, "out\n") ;
- else if ((strcasecmp (mode, "high") == 0) || (strcasecmp (mode, "up") == 0))
- fprintf (fd, "high\n") ;
- else if ((strcasecmp (mode, "low") == 0) || (strcasecmp (mode, "down") == 0))
- fprintf (fd, "low\n") ;
- else {
- fprintf (stderr, "%s: Invalid mode: %s. Should be in, out, high or low\n", argv [1], mode) ;
- exit (1) ;
- }
- fclose (fd) ;
-
- // Change ownership so the current user can actually use it
- sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
- changeOwner (argv [0], fName) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
- changeOwner (argv [0], fName) ;
-}
-
-
-/*
- * doWfi:
- * gpio wfi pin mode
- * Wait for Interrupt on a given pin.
- * Slight cheat here - it's easier to actually use ISR now (which calls
- * gpio to set the pin modes!) then we simply sleep, and expect the thread
- * to exit the program. Crude but effective.
- *********************************************************************************
- */
-static void wfi (void) { exit (0) ; }
-
-void doWfi (int argc, char *argv [])
-{
- int pin, mode ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s wfi pin mode\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
-
- if (strcasecmp (argv [3], "rising") == 0) mode = INT_EDGE_RISING ;
- else if (strcasecmp (argv [3], "falling") == 0) mode = INT_EDGE_FALLING ;
- else if (strcasecmp (argv [3], "both") == 0) mode = INT_EDGE_BOTH ;
- else {
- fprintf (stderr, "%s: wfi: Invalid mode: %s. Should be rising, falling or both\n", argv [1], argv [3]) ;
- exit (1) ;
- }
-
- if (wiringPiISR (pin, mode, &wfi) < 0) {
- fprintf (stderr, "%s: wfi: Unable to setup ISR: %s\n", argv [1], strerror (errno)) ;
- exit (1) ;
- }
-
- for (;;)
- delay (9999) ;
-}
-
-
-/*
- * doEdge:
- * gpio edge pin mode
- * Easy access to changing the edge trigger on a GPIO pin
- * This uses the /sys/class/gpio device interface.
- *********************************************************************************
- */
-
-void doEdge (int argc, char *argv [])
-{
- FILE *fd ;
- int pin ;
- char *mode ;
- char fName [128] ;
-
- // Reset gpio sysfs
- doUnexport(3, argv);
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s edge pin mode\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
- mode = argv [3] ;
-
- // Export the pin and set direction to input
- if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ;
- exit (1) ;
- }
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ;
- if ((fd = fopen (fName, "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO direction interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
- exit (1) ;
- }
- fprintf (fd, "in\n") ;
- fclose (fd) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
- if ((fd = fopen (fName, "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO edge interface for pin %d: %s\n", argv [0], pin, strerror (errno)) ;
- exit (1) ;
- }
-
- if (strcasecmp (mode, "none") == 0) fprintf (fd, "none\n") ;
- else if (strcasecmp (mode, "rising") == 0) fprintf (fd, "rising\n") ;
- else if (strcasecmp (mode, "falling") == 0) fprintf (fd, "falling\n") ;
- else if (strcasecmp (mode, "both") == 0) fprintf (fd, "both\n") ;
- else {
- fprintf (stderr, "%s: Invalid mode: %s. Should be none, rising, falling or both\n", argv [1], mode) ;
- exit (1) ;
- }
-
- // Change ownership of the value and edge files, so the current user can actually use it!
- sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
- changeOwner (argv [0], fName) ;
-
- sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ;
- changeOwner (argv [0], fName) ;
-
- fclose (fd) ;
-}
-
-
-/*
- * doUnexport:
- * gpio unexport pin
- * This uses the /sys/class/gpio device interface.
- *********************************************************************************
- */
-
-void doUnexport (int argc, char *argv [])
-{
- FILE *fd ;
- int pin ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s unexport pin\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
-
- if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ;
- exit (1) ;
- }
-
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
-}
-
-
-/*
- * doUnexportAll:
- * gpio unexportall
- * Un-Export all the GPIO pins.
- * This uses the /sys/class/gpio device interface.
- *********************************************************************************
- */
-
-void doUnexportall (char *progName)
-{
- FILE *fd ;
- int pin ;
-
- for (pin = 0 ; pin < 256 ; ++pin) {
- if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) {
- fprintf (stderr, "%s: Unable to open GPIO export interface\n", progName) ;
- exit (1) ;
- }
- fprintf (fd, "%d\n", pin) ;
- fclose (fd) ;
- }
-}
-
-
-/*
- * doReset:
- * Reset the GPIO pins - as much as we can do
- *********************************************************************************
- */
-
-static void doReset (UNU char *progName)
-{
- printf ("GPIO Reset is dangerous and has been removed from the gpio command.\n") ;
- printf (" - Please write a shell-script to reset the GPIO pins into the state\n") ;
- printf (" that you need them in for your applications.\n") ;
-}
-
-
-/*
- * doMode:
- * gpio mode pin mode ...
- *********************************************************************************
- */
-
-void doMode (int argc, char *argv [])
-{
- int pin ;
- char *mode ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s mode pin mode\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
- mode = argv [3] ;
-
- if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
- else if (strcasecmp (mode, "input") == 0) pinMode (pin, INPUT) ;
- else if (strcasecmp (mode, "out") == 0) pinMode (pin, OUTPUT) ;
- else if (strcasecmp (mode, "output") == 0) pinMode (pin, OUTPUT) ;
- else if (strcasecmp (mode, "pwm") == 0) pinMode (pin, PWM_OUTPUT) ;
- else if (strcasecmp (mode, "pwmTone") == 0) pinMode (pin, PWM_TONE_OUTPUT) ;
- else if (strcasecmp (mode, "clock") == 0) pinMode (pin, GPIO_CLOCK) ;
- else if (strcasecmp (mode, "up") == 0) pullUpDnControl (pin, PUD_UP) ;
- else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
- else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
- else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;
- else if (strcasecmp (mode, "alt0") == 0) pinModeAlt (pin, 0b100) ;
- else if (strcasecmp (mode, "alt1") == 0) pinModeAlt (pin, 0b101) ;
- else if (strcasecmp (mode, "alt2") == 0) pinModeAlt (pin, 0b110) ;
- else if (strcasecmp (mode, "alt3") == 0) pinModeAlt (pin, 0b111) ;
- else if (strcasecmp (mode, "alt4") == 0) pinModeAlt (pin, 0b011) ;
- else if (strcasecmp (mode, "alt5") == 0) pinModeAlt (pin, 0b010) ;
- else {
- fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;
- exit (1) ;
- }
-}
-
-
-/*
- * doPadDrive:
- * gpio drive pin value for ODROIDs since it depends on the SoC
- *********************************************************************************
- */
-
-static void doPadDrive (int argc, char *argv [])
-{
- int pin, val;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s drive pin value\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
- val = atoi (argv [3]) ;
-
- setPadDrive (pin, val) ;
-}
-
-
-/*
- * doGbw:
- * gpio gbw channel value
- * Gertboard Write - To the Analog output
- *********************************************************************************
- */
-
-static void doGbw (int argc, char *argv [])
-{
- int channel, value ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s gbw \n", argv [0]) ;
- exit (1) ;
- }
-
- channel = atoi (argv [2]) ;
- value = atoi (argv [3]) ;
-
- if ((channel < 0) || (channel > 1)) {
- fprintf (stderr, "%s: gbw: Channel number must be 0 or 1\n", argv [0]) ;
- exit (1) ;
- }
-
- if ((value < 0) || (value > 255)) {
- fprintf (stderr, "%s: gbw: Value must be from 0 to 255\n", argv [0]) ;
- exit (1) ;
- }
-
- if (gertboardAnalogSetup (64) < 0) {
- fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
- exit (1) ;
- }
-
- analogWrite (64 + channel, value) ;
-}
-
-
-/*
- * doGbr:
- * gpio gbr channel
- * From the analog input
- *********************************************************************************
- */
-static void doGbr (int argc, char *argv [])
-{
- int channel ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s gbr \n", argv [0]) ;
- exit (1) ;
- }
-
- channel = atoi (argv [2]) ;
-
- if ((channel < 0) || (channel > 1)) {
- fprintf (stderr, "%s: gbr: Channel number must be 0 or 1\n", argv [0]) ;
- exit (1) ;
- }
-
- if (gertboardAnalogSetup (64) < 0) {
- fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
- exit (1) ;
- }
-
- printf ("%d\n", analogRead (64 + channel)) ;
-}
-
-
-/*
- * doWrite:
- * gpio write pin value
- *********************************************************************************
- */
-
-static void doWrite (int argc, char *argv [])
-{
- int pin, val ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s write pin value\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
-
- if ((strcasecmp (argv [3], "up") == 0) || (strcasecmp (argv [3], "on") == 0))
- val = 1 ;
- else if ((strcasecmp (argv [3], "down") == 0) || (strcasecmp (argv [3], "off") == 0))
- val = 0 ;
- else
- val = atoi (argv [3]) ;
-
- if (val == 0)
- digitalWrite (pin, LOW) ;
- else
- digitalWrite (pin, HIGH) ;
-}
-
-
-/*
- * doAwriterite:
- * gpio awrite pin value
- *********************************************************************************
- */
-
-static void doAwrite (int argc, char *argv [])
-{
- int pin, val ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s awrite pin value\n", argv [0]) ;
- exit (1) ;
- }
- pin = atoi (argv [2]) ;
- val = atoi (argv [3]) ;
-
- analogWrite (pin, val) ;
-}
-
-
-/*
- * doWriteByte:
- * gpio wb value
- *********************************************************************************
- */
-
-static void doWriteByte (int argc, char *argv [])
-{
- int val ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s wb value\n", argv [0]) ;
- exit (1) ;
- }
- val = (int)strtol (argv [2], NULL, 0) ;
-
- digitalWriteByte (val) ;
-}
-
-
-/*
- * doReadByte:
- * gpio rbx|rbd value
- *********************************************************************************
- */
-
-static void doReadByte (int argc, char *argv [], int printHex)
-{
- int val ;
-
- if (argc != 2) {
- fprintf (stderr, "Usage: %s rbx|rbd\n", argv [0]) ;
- exit (1) ;
- }
-
- val = digitalReadByte () ;
- if (printHex)
- printf ("%02X\n", val) ;
- else
- printf ("%d\n", val) ;
-}
-
-
-/*
- * doRead:
- * Read a pin and return the value
- *********************************************************************************
- */
-
-void doRead (int argc, char *argv [])
-{
- int pin, val ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s read pin\n", argv [0]) ;
- exit (1) ;
- }
- pin = atoi (argv [2]) ;
- val = digitalRead (pin) ;
-
- printf ("%s\n", val == 0 ? "0" : "1") ;
-}
-
-
-/*
- * doAread:
- * Read an analog pin and return the value
- *********************************************************************************
- */
-
-void doAread (int argc, char *argv [])
-{
- if (argc != 3) {
- fprintf (stderr, "Usage: %s aread pin\n", argv [0]) ;
- exit (1) ;
- }
- printf ("%d\n", analogRead (atoi (argv [2]))) ;
-}
-
-
-/*
- * doToggle:
- * Toggle an IO pin
- *********************************************************************************
- */
-
-void doToggle (int argc, char *argv [])
-{
- int pin ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s toggle pin\n", argv [0]) ;
- exit (1) ;
- }
- pin = atoi (argv [2]) ;
-
- digitalWrite (pin, !digitalRead (pin)) ;
-}
-
-
-/*
- * doBlink:
- * Blink an IO pin
- *********************************************************************************
- */
-
-void doBlink (int argc, char *argv [])
-{
- int pin ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s blink pin\n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
-
- pinMode (pin, OUTPUT) ;
- for (;;) {
- digitalWrite (pin, !digitalRead (pin)) ;
- delay (500) ;
- }
-}
-
-
-/*
- * doPwmTone:
- * Output a tone in a PWM pin
- *********************************************************************************
- */
-
-void doPwmTone (int argc, char *argv [])
-{
- int pin, freq ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s pwmTone \n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
- freq = atoi (argv [3]) ;
-
- pwmToneWrite (pin, freq) ;
-}
-
-
-/*
- * doClock:
- * Output a clock on a pin
- *********************************************************************************
- */
-
-void doClock (int argc, char *argv [])
-{
- int pin, freq ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s clock \n", argv [0]) ;
- exit (1) ;
- }
-
- pin = atoi (argv [2]) ;
-
- freq = atoi (argv [3]) ;
-
- gpioClockSet (pin, freq) ;
-}
-
-
-/*
- * doPwm:
- * Output a PWM value on a pin
- *********************************************************************************
- */
-
-void doPwm (int argc, char *argv [])
-{
- int pin, val ;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s pwm \n", argv [0]) ;
- exit (1) ;
- }
- pin = atoi (argv [2]) ;
- val = atoi (argv [3]) ;
-
- pwmWrite (pin, val) ;
-}
-
-
-/*
- * doPwmMode: doPwmRange: doPwmClock:
- * Change the PWM mode, range and clock divider values
- *********************************************************************************
- */
-
-static void doPwmMode (int mode)
-{
- pwmSetMode (mode) ;
-}
-
-static void doPwmRange (int argc, char *argv [])
-{
- unsigned int range ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s pwmr \n", argv [0]) ;
- exit (1) ;
- }
-
- range = (unsigned int)strtoul (argv [2], NULL, 10) ;
-
- if (range == 0) {
- fprintf (stderr, "%s: range must be > 0\n", argv [0]) ;
- exit (1) ;
- }
- pwmSetRange (range) ;
-}
-
-static void doPwmClock (int argc, char *argv [])
-{
- unsigned int clock ;
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s pwmc \n", argv [0]) ;
- exit (1) ;
- }
-
- clock = (unsigned int)strtoul (argv [2], NULL, 10) ;
-
- if ((clock < 1) || (clock > 4095)) {
- fprintf (stderr, "%s: clock must be between 0 and 4096\n", argv [0]) ;
- exit (1) ;
- }
- pwmSetClock (clock) ;
-}
-
-/*
- * doNothing:
- * function is not support by ODROID Board.
- *********************************************************************************
- */
-static void doNothing (int argc, char *argv [])
-{
- fprintf(stderr, "warn : (%s) : This function is not supported by ODROID Board.\n",
- argv[1]);
-}
-
-/*
- * doVersion:
- * Handle the ever more complicated version command and print out
- * some usefull information.
- *********************************************************************************
- */
-static void doVersion (char *argv [])
-{
- int model, rev, mem, maker, warranty ;
- struct stat statBuf ;
- char name [80] ;
- FILE *fd ;
-
- int vMaj, vMin ;
-
- wiringPiVersion (&vMaj, &vMin) ;
- printf ("gpio version: %d.%d\n", vMaj, vMin) ;
- printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
- printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
- printf ("For details type: %s -warranty\n", argv [0]) ;
- printf ("\n") ;
- piBoardId (&model, &rev, &mem, &maker, &warranty) ;
-
- printf ("ODROID Board Details:\n") ;
- printf (" Type: %s, Revision: %s, Memory: %dMB\n" \
- " Maker: %s, Chip-Vendor: %s\n",
- piModelNames [model],
- piRevisionNames [rev],
- piMemorySize [mem],
- "Hardkernel",
- piMakerNames [maker]);
-
- // Check for device tree
- if (stat ("/proc/device-tree", &statBuf) == 0) // We're on a devtree system ...
- printf (" * Device tree is enabled.\n") ;
-
- // Output Kernel idea of board type
- if (stat ("/proc/device-tree/model", &statBuf) == 0) {
- if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL) {
- fgets (name, 80, fd) ;
- fclose (fd) ;
- printf (" *--> %s\n", name) ;
- }
- }
-
- // User level GPIO is GO
- if (stat ("/dev/gpiomem", &statBuf) == 0)
- printf (" * Supports user-level GPIO access.\n") ;
- else
- printf (" * Root or sudo required for GPIO access.\n") ;
-}
-
-
-/*
- * main:
- * Start here
- *********************************************************************************
- */
-
-int main (int argc, char *argv [])
-{
- int i ;
-
- if (getenv ("WIRINGPI_DEBUG") != NULL) {
- printf ("gpio: wiringPi debug mode enabled\n") ;
- wiringPiDebug = TRUE ;
- }
-
- if (argc == 1) {
- fprintf (stderr, "%s\n", usage) ;
- return 1 ;
- }
-
- // Help
- if (strcasecmp (argv [1], "-h") == 0) {
- printf ("%s: %s\n", argv [0], usage) ;
- return 0 ;
- }
-
- // Version & Warranty
- // Wish I could remember why I have both -R and -V ...
- if ((strcmp (argv [1], "-R") == 0) || (strcmp (argv [1], "-V") == 0)) {
- printf ("%d\n", piGpioLayout ()) ;
- return 0 ;
- }
-
- // Version and information
- if (strcmp (argv [1], "-v") == 0) {
- doVersion (argv) ;
- return 0 ;
- }
-
- if (strcasecmp (argv [1], "-warranty") == 0) {
- printf ("gpio version: %s\n", VERSION) ;
- printf ("Copyright (c) 2012-2017 Gordon Henderson\n") ;
- printf ("\n") ;
- printf (" This program is free software; you can redistribute it and/or modify\n") ;
- printf (" it under the terms of the GNU Leser General Public License as published\n") ;
- printf (" by the Free Software Foundation, either version 3 of the License, or\n") ;
- printf (" (at your option) any later version.\n") ;
- printf ("\n") ;
- printf (" This program is distributed in the hope that it will be useful,\n") ;
- printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ;
- printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ;
- printf (" GNU Lesser General Public License for more details.\n") ;
- printf ("\n") ;
- printf (" You should have received a copy of the GNU Lesser General Public License\n") ;
- printf (" along with this program. If not, see .\n") ;
- printf ("\n") ;
- return 0 ;
- }
-
- if (geteuid () != 0) {
- fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ;
- return 1 ;
- }
-
- // Initial test for /sys/class/gpio operations:
- if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; }
- else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argv [0]) ; return 0 ; }
-
- // Check for load command:
- if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
- if (strcasecmp (argv [1], "unload" ) == 0) { doUnLoad (argc, argv) ; return 0 ; }
-
- // Check for usb power command
- if (strcasecmp (argv [1], "usbp" ) == 0) { doNothing(argc, argv) ; return 0 ; }
-
- // Gertboard commands
- if (strcasecmp (argv [1], "gbr" ) == 0) { doGbr (argc, argv) ; return 0 ; }
- if (strcasecmp (argv [1], "gbw" ) == 0) { doGbw (argc, argv) ; return 0 ; }
-
- // Check for allreadall command, force Gpio mode
- if (strcasecmp (argv [1], "allreadall") == 0) {
- wiringPiSetupGpio () ;
- doAllReadall () ;
- return 0 ;
- }
-
- if (strcasecmp (argv [1], "-g") == 0) { // Check for -g argument
- wiringPiSetupGpio () ;
-
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = MODE_GPIO ;
- } else if (strcasecmp (argv [1], "-1") == 0) { // Check for -1 argument
- wiringPiSetupPhys () ;
-
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = MODE_PHYS ;
- } else if (strcasecmp (argv [1], "-p") == 0) { // Check for -p argument for PiFace
- piFaceSetup (200) ;
-
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = MODE_PIFACE ;
- } else if (strcasecmp (argv [1], "-z") == 0) { // Check for -z argument so we don't actually initialise wiringPi
- for (i = 2 ; i < argc ; ++i)
- argv [i - 1] = argv [i] ;
- --argc ;
- wpMode = MODE_UNINITIALISED ;
- } else { // Default to wiringPi mode
- wiringPiSetup () ;
- wpMode = MODE_PINS ;
- }
-
- // Check for -x argument to load in a new extension
- // -x extension:base:args
- // Can load many modules, but unless daemon mode we can only send one
- // command at a time.
- while (strcasecmp (argv [1], "-x") == 0) {
- if (argc < 3) {
- fprintf (stderr, "%s: -x missing extension command.\n", argv [0]) ;
- exit (EXIT_FAILURE) ;
- }
-
- if (!loadWPiExtension (argv [0], argv [2], TRUE)) {
- fprintf (stderr, "%s: Extension load failed: %s\n", argv [0], strerror (errno)) ;
- exit (EXIT_FAILURE) ;
- }
-
- // Shift args down by 2
- for (i = 3 ; i < argc ; ++i)
- argv [i - 2] = argv [i] ;
- argc -= 2 ;
- }
-
- if (argc <= 1) {
- fprintf (stderr, "%s: no command given\n", argv [0]) ;
- exit (EXIT_FAILURE) ;
- }
-
- // Core wiringPi functions
- /**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
- else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
- else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ;
- else if (strcasecmp (argv [1], "pwm" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "awrite" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ;
-
- // GPIO Nicies
- else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ;
- else if (strcasecmp (argv [1], "blink" ) == 0) doBlink (argc, argv) ;
-
- // Pi Specifics
- else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "pwmr" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "pwmc" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "pwmTone" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
- else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
- else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ;
- else if (strcasecmp (argv [1], "pins" ) == 0) doPins () ;
- else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ;
- else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ;
- else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ;
- else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ;
- else if (strcasecmp (argv [1], "rbx" ) == 0) doReadByte (argc, argv, TRUE) ;
- else if (strcasecmp (argv [1], "rbd" ) == 0) doReadByte (argc, argv, FALSE) ;
- else if (strcasecmp (argv [1], "clock" ) == 0) doNothing (argc, argv) ;
- else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ;
- else {
- fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
- exit (EXIT_FAILURE) ;
- }
- return 0 ;
-}
diff --git a/gpio/readall.c b/gpio/readall.c
old mode 100644
new mode 100755
index 18f836f..ba64ec4
--- a/gpio/readall.c
+++ b/gpio/readall.c
@@ -20,8 +20,6 @@
* along with wiringPi. If not, see .
***********************************************************************
*/
-
-
#include
#include
#include
@@ -34,37 +32,377 @@
#include
#include
+/*----------------------------------------------------------------------------*/
extern int wpMode ;
+/*----------------------------------------------------------------------------*/
#ifndef TRUE
-# define TRUE (1==1)
-# define FALSE (1==2)
+# define TRUE (1==1)
+# define FALSE (1==2)
#endif
+/*----------------------------------------------------------------------------*/
/*
* doReadallExternal:
* A relatively crude way to read the pins on an external device.
* We don't know the input/output mode of pins, but we can tell
* if it's an analog pin or a digital one...
- *********************************************************************************
*/
-
+/*----------------------------------------------------------------------------*/
static void doReadallExternal (void)
{
- int pin ;
+ int pin ;
- printf ("+------+---------+--------+\n") ;
- printf ("| Pin | Digital | Analog |\n") ;
- printf ("+------+---------+--------+\n") ;
+ 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)) ;
+ for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
+ printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
- printf ("+------+---------+--------+\n") ;
+ printf ("+------+---------+--------+\n") ;
}
+/*----------------------------------------------------------------------------*/
+static const char *alts [] =
+{
+ "IN", "OUT", "ALT1", "ALT2", "ALT3", "ALT4", "ALT5", "ALT6", "ALT7"
+} ;
+static const char *pupd [] =
+{
+ "DSBLD", "P/U", "P/D"
+} ;
+
+/*----------------------------------------------------------------------------*/
+static const int physToWpi [64] =
+{
+ -1, // 0
+ -1, -1, // 1, 2
+ 8, -1,
+ 9, -1,
+ 7, 15,
+ -1, 16,
+ 0, 1,
+ 2, -1,
+ 3, 4,
+ -1, 5,
+ 12, -1,
+ 13, 6,
+ 14, 10,
+ -1, 11, // 25, 26
+ 30, 31, // Actually I2C, but not used
+ 21, -1,
+ 22, 26,
+ 23, -1,
+ 24, 27,
+ 25, 28,
+ -1, 29,
+ -1, -1,
+ -1, -1,
+ -1, -1,
+ -1, -1,
+ -1, -1,
+ 17, 18,
+ 19, 20,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1
+} ;
+
+/*----------------------------------------------------------------------------*/
+static const char *physNamesOdroidC1 [64] =
+{
+ NULL,
+
+ " 3.3V", "5V ",
+ " SDA.1", "5V ",
+ " SCL.1", "GND(0V) ",
+ "GPIO. 83", "TxD1 ",
+ " GND(0V)", "RxD1 ",
+ "GPIO. 88", "GPIO. 87",
+ "GPIO.116", "GND(0V) ",
+ "GPIO.115", "GPIO.104",
+ " 3.3V", "GPIO.102",
+ " MOSI", "GND(0V) ",
+ " MISO", "GPIO.103",
+ " SCLK", "CE0 ",
+ " GND(0V)", "GPIO.118",
+ " SDA.2", "SCL.2 ",
+ "GPIO.101", "GND(0V) ",
+ "GPIO.100", "GPIO. 99",
+ "GPIO.108", "GND(0V) ",
+ "GPIO.97 ", "GPIO. 98",
+ " AIN.1", "1V8 ",
+ " GND(0V)", "AIN.0 ",
+
+ 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 *physNamesOdroidC2_Rev2 [64] =
+{
+ NULL,
+
+ " 3.3V", "5V ",
+ " SDA.1", "5V ",
+ " SCL.1", "GND(0V) ",
+ "GPIO.249", "TxD1 ",
+ " GND(0V)", "RxD1 ",
+ "GPIO.247", "GPIO.238",
+ "GPIO.239", "GND(0V) ",
+ "GPIO.237", "GPIO.236",
+ " 3.3V", "GPIO.233",
+ "GPIO.235", "GND(0V) ",
+ "GPIO.232", "GPIO.231",
+ "GPIO.230", "GPIO.229",
+ " GND(0V)", "GPIO.225",
+ " SDA.2", "SCL.2 ",
+ "GPIO.228", "GND(0V) ",
+ "GPIO.219", "GPIO.224",
+ "GPIO.234", "GND(0V) ",
+ "GPIO.214", "GPIO.218",
+ " AIN.1", "1V8 ",
+ " GND(0V)", "AIN.0 ",
+
+ 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 *physNamesOdroidC2_Rev1 [64] =
+{
+ NULL,
+
+ " 3.3V", "5V ",
+ " SDA.1", "5V ",
+ " SCL.1", "GND(0V) ",
+ "GPIO.214", "--------",
+ " GND(0V)", "--------",
+ "GPIO.219", "GPIO.218",
+ "GPIO.247", "GND(0V) ",
+ "--------", "GPIO.235",
+ " 3.3V", "GPIO.233",
+ "GPIO.238", "GND(0V) ",
+ "GPIO.237", "GPIO.234",
+ "GPIO.236", "GPIO.248",
+ " GND(0V)", "GPIO.249",
+ " SDA.2", "SCL.2 ",
+ "GPIO.232", "GND(0V) ",
+ "GPIO.231", "GPIO.230",
+ "GPIO.239", "GND(0V) ",
+ "GPIO.228", "GPIO.229",
+ " AIN.1", "1V8 ",
+ " GND(0V)", "AIN.0 ",
+
+ 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 *physNamesOdroidXU3 [64] =
+{
+ NULL,
+
+ " 3.3V", "5V ",
+ "I2C1.SDA", "5V ",
+ "I2C1.SCL", "GND(0V) ",
+ "GPIO. 18", "UART0.TX",
+ " GND(0V)", "UART0.RX",
+ "GPIO.174", "GPIO.173",
+ "GPIO. 21", "GND(0V) ",
+ "GPIO. 22", "GPIO. 19",
+ " 3.3V", "GPIO. 23",
+ " MOSI", "GND(0V) ",
+ " MISO", "GPIO. 24",
+ " SCLK", "CE0 ",
+ " GND(0V)", "GPIO. 25",
+ "I2C5.SDA", "I2C5.SCL",
+ "GPIO. 28", "GND(0V) ",
+ "GPIO. 30", "GPIO. 29",
+ "GPIO. 31", "GND(0V) ",
+ "POWER ON", "GPIO. 33",
+ " AIN.0", "1V8 ",
+ " GND(0V)", "AIN.3 ",
+
+ 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 *physNamesOdroidN1 [64] =
+{
+ NULL,
+
+ " 3.0V", "5V ",
+ "I2C4_SDA", "5V ",
+ "I2C4_SCL", "GND(0V) ",
+ "GPIO1A.0", "UART0_TX",
+ " GND(0V)", "UART0_RX",
+ "GPIO1A.1", "GPIO1A.2",
+ "GPIO1A.3", "GND(0V) ",
+ "GPIO1A.4", "GPIO1B.5",
+ " 3.0V", "GPIO1C.2",
+ "SPI1_TXD", "GND(0V) ",
+ "SPI1_RXD", "GPIO1D.0",
+ "SPI1_CLK", "SPI1_CSN",
+ " GND(0V)", "GPIO1C.6",
+ "I2C8_SDA", "I2C8_SCL",
+ "SPDIF_TX", "GND(0V) ",
+ " PWM1", "GPIO4D.4",
+ "GPIO4D.0", "GND(0V) ",
+ "GPIO4D.5", "GPIO4D.6",
+ "ADC.AIN1", "1V8 ",
+ " GND(0V)", "ADC.AIN0",
+
+ 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 *physNamesOdroidN2 [64] =
+{
+ NULL,
+
+ " 3.3V", "5V ",
+ " SDA.2", "5V ",
+ " SCL.2", "GND(0V) ",
+ "GPIO.473", "TxD1 ",
+ " GND(0V)", "RxD1 ",
+ "GPIO.479", "GPIO.492",
+ "GPIO.480", "GND(0V) ",
+ "GPIO.483", "GPIO.476",
+ " 3.3V", "GPIO.477",
+ " MOSI", "GND(0V) ",
+ " MISO", "GPIO.478",
+ " SCLK", "CE0 ",
+ " GND(0V)", "GPIO.464",
+ " SDA.3", "SCL.3 ",
+ "GPIO.490", "GND(0V) ",
+ "GPIO.491", "GPIO.472",
+ "GPIO.481", "GND(0V) ",
+ "GPIO.482", "GPIO.495",
+ " AIN.3", "1V8 ",
+ " GND(0V)", "AIN.2 ",
+
+ 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 readallPhysOdroid (int model, int rev, int physPin, const char *physNames[])
+{
+ 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_ODROID_N1:
+ printf (" | | ");
+ break;
+ case MODEL_ODROID_C1:
+ case MODEL_ODROID_C2:
+ printf (" | | %5s", pupd[getPUPD(pin)]);
+ break;
+ case MODEL_ODROID_XU3:
+ case MODEL_ODROID_N2:
+ printf (" | %2d | %5s", getPadDrive(pin), 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_ODROID_N1:
+ printf (" | | ");
+ break;
+ case MODEL_ODROID_C1:
+ case MODEL_ODROID_C2:
+ printf (" | %-5s | ", pupd[getPUPD(pin)]);
+ break;
+ case MODEL_ODROID_XU3:
+ case MODEL_ODROID_N2:
+ printf (" | %-5s | %-2d", pupd[getPUPD(pin)], getPadDrive(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") ;
+}
+
+/*----------------------------------------------------------------------------*/
+void ReadallOdroid (int model, int rev, const char *physNames[])
+{
+ 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)
+ readallPhysOdroid (model, rev, pin, physNames) ;
+ printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n") ;
+}
+
+/*----------------------------------------------------------------------------*/
/*
* doReadall:
* Read all the GPIO pins
@@ -72,297 +410,62 @@ static void doReadallExternal (void)
* 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...
- *********************************************************************************
*/
-
-static char *alts [] =
-{
- "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
-} ;
-
-static int physToWpi [64] =
-{
- -1, // 0
- -1, -1, // 1, 2
- 8, -1,
- 9, -1,
- 7, 15,
- -1, 16,
- 0, 1,
- 2, -1,
- 3, 4,
- -1, 5,
- 12, -1,
- 13, 6,
- 14, 10,
- -1, 11, // 25, 26
- 30, 31, // Actually I2C, but not used
- 21, -1,
- 22, 26,
- 23, -1,
- 24, 27,
- 25, 28,
- -1, 29,
- -1, -1,
- -1, -1,
- -1, -1,
- -1, -1,
- -1, -1,
- 17, 18,
- 19, 20,
- -1, -1, -1, -1, -1, -1, -1, -1, -1
-} ;
-
-static char *physNames [64] =
-{
- 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") ;
-}
-
-
-/*
- * 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)
-{
- 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") ;
-
-}
-
-
-/*
- * abReadall:
- * Read all the pins on the model A or B.
- *********************************************************************************
- */
-
-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) // 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) ;
-}
-
-
-/*
- * piPlusReadall:
- * Read all the pins on the model A+ or the B+
- *********************************************************************************
- */
-
-static void plus2header (int model)
-{
- /**/ if (model == PI_MODEL_AP)
- printf (" +-----+-----+---------+------+---+--A Plus--+---+------+---------+-----+-----+\n") ;
- else if (model == PI_MODEL_BP)
- printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\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
- printf (" +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+\n") ;
-}
-
-
-static void piPlusReadall (int model)
-{
- 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 ;
+ int model, rev, mem, maker, overVolted;
+ const char (*physNames)[];
- if (wiringPiNodes != NULL) // External readall
- {
- doReadallExternal () ;
- return ;
- }
+ // External readall
+ if (wiringPiNodes != NULL) {
+ doReadallExternal ();
+ return ;
+ }
- piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
+ 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_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) ;
+ switch (model) {
+ case MODEL_ODROID_C1:
+ printf (" +------+-----+----------+------+---+----+---- Model ODROID-C1 ----+----+---+------+----------+-----+------+\n") ;
+ physNames = physNamesOdroidC1;
+ break;
+ case MODEL_ODROID_C2:
+ printf (" +------+-----+----------+------+---+----+---- Model ODROID-C2 ----+----+---+------+----------+-----+------+\n") ;
+ if (rev == 1)
+ physNames = physNamesOdroidC2_Rev1;
+ else
+ physNames = physNamesOdroidC2_Rev2;
+ break;
+ case MODEL_ODROID_XU3:
+ printf (" +------+-----+----------+------+---+----+--- Model ODROID-XU3/4 ---+----+---+------+----------+-----+------+\n") ;
+ physNames = physNamesOdroidXU3;
+ break;
+ case MODEL_ODROID_N1:
+ printf (" +------+-----+----------+------+---+----+---- Model ODROID-N1 ----+----+---+------+----------+-----+------+\n") ;
+ physNames = physNamesOdroidN1;
+ break;
+ case MODEL_ODROID_N2:
+ printf (" +------+-----+----------+------+---+----+---- Model ODROID-N2 ----+----+---+------+----------+-----+------+\n") ;
+ physNames = physNamesOdroidN2;
+ break;
+ default:
+ printf ("Oops - unable to determine board type... model: %d\n", model) ;
+ return;
+ }
+ ReadallOdroid(model, rev, physNames);
}
+/*----------------------------------------------------------------------------*/
/*
* doAllReadall:
* Force reading of all pins regardless of Pi model
- *********************************************************************************
*/
-
+/*----------------------------------------------------------------------------*/
void doAllReadall (void)
{
- allReadall () ;
+ doReadall();
}
+
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
diff --git a/gpio/readall_odroid.c b/gpio/readall_odroid.c
deleted file mode 100755
index ba64ec4..0000000
--- a/gpio/readall_odroid.c
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * readall.c:
- * The readall functions - getting a bit big, so split them out.
- * 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 .
- ***********************************************************************
- */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-/*----------------------------------------------------------------------------*/
-
-extern int wpMode ;
-
-/*----------------------------------------------------------------------------*/
-#ifndef TRUE
-# define TRUE (1==1)
-# define FALSE (1==2)
-#endif
-
-/*----------------------------------------------------------------------------*/
-/*
- * doReadallExternal:
- * A relatively crude way to read the pins on an external device.
- * We don't know the input/output mode of pins, but we can tell
- * if it's an analog pin or a digital one...
- */
-/*----------------------------------------------------------------------------*/
-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 const char *alts [] =
-{
- "IN", "OUT", "ALT1", "ALT2", "ALT3", "ALT4", "ALT5", "ALT6", "ALT7"
-} ;
-
-static const char *pupd [] =
-{
- "DSBLD", "P/U", "P/D"
-} ;
-
-/*----------------------------------------------------------------------------*/
-static const int physToWpi [64] =
-{
- -1, // 0
- -1, -1, // 1, 2
- 8, -1,
- 9, -1,
- 7, 15,
- -1, 16,
- 0, 1,
- 2, -1,
- 3, 4,
- -1, 5,
- 12, -1,
- 13, 6,
- 14, 10,
- -1, 11, // 25, 26
- 30, 31, // Actually I2C, but not used
- 21, -1,
- 22, 26,
- 23, -1,
- 24, 27,
- 25, 28,
- -1, 29,
- -1, -1,
- -1, -1,
- -1, -1,
- -1, -1,
- -1, -1,
- 17, 18,
- 19, 20,
- -1, -1, -1, -1, -1, -1, -1, -1, -1
-} ;
-
-/*----------------------------------------------------------------------------*/
-static const char *physNamesOdroidC1 [64] =
-{
- NULL,
-
- " 3.3V", "5V ",
- " SDA.1", "5V ",
- " SCL.1", "GND(0V) ",
- "GPIO. 83", "TxD1 ",
- " GND(0V)", "RxD1 ",
- "GPIO. 88", "GPIO. 87",
- "GPIO.116", "GND(0V) ",
- "GPIO.115", "GPIO.104",
- " 3.3V", "GPIO.102",
- " MOSI", "GND(0V) ",
- " MISO", "GPIO.103",
- " SCLK", "CE0 ",
- " GND(0V)", "GPIO.118",
- " SDA.2", "SCL.2 ",
- "GPIO.101", "GND(0V) ",
- "GPIO.100", "GPIO. 99",
- "GPIO.108", "GND(0V) ",
- "GPIO.97 ", "GPIO. 98",
- " AIN.1", "1V8 ",
- " GND(0V)", "AIN.0 ",
-
- 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 *physNamesOdroidC2_Rev2 [64] =
-{
- NULL,
-
- " 3.3V", "5V ",
- " SDA.1", "5V ",
- " SCL.1", "GND(0V) ",
- "GPIO.249", "TxD1 ",
- " GND(0V)", "RxD1 ",
- "GPIO.247", "GPIO.238",
- "GPIO.239", "GND(0V) ",
- "GPIO.237", "GPIO.236",
- " 3.3V", "GPIO.233",
- "GPIO.235", "GND(0V) ",
- "GPIO.232", "GPIO.231",
- "GPIO.230", "GPIO.229",
- " GND(0V)", "GPIO.225",
- " SDA.2", "SCL.2 ",
- "GPIO.228", "GND(0V) ",
- "GPIO.219", "GPIO.224",
- "GPIO.234", "GND(0V) ",
- "GPIO.214", "GPIO.218",
- " AIN.1", "1V8 ",
- " GND(0V)", "AIN.0 ",
-
- 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 *physNamesOdroidC2_Rev1 [64] =
-{
- NULL,
-
- " 3.3V", "5V ",
- " SDA.1", "5V ",
- " SCL.1", "GND(0V) ",
- "GPIO.214", "--------",
- " GND(0V)", "--------",
- "GPIO.219", "GPIO.218",
- "GPIO.247", "GND(0V) ",
- "--------", "GPIO.235",
- " 3.3V", "GPIO.233",
- "GPIO.238", "GND(0V) ",
- "GPIO.237", "GPIO.234",
- "GPIO.236", "GPIO.248",
- " GND(0V)", "GPIO.249",
- " SDA.2", "SCL.2 ",
- "GPIO.232", "GND(0V) ",
- "GPIO.231", "GPIO.230",
- "GPIO.239", "GND(0V) ",
- "GPIO.228", "GPIO.229",
- " AIN.1", "1V8 ",
- " GND(0V)", "AIN.0 ",
-
- 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 *physNamesOdroidXU3 [64] =
-{
- NULL,
-
- " 3.3V", "5V ",
- "I2C1.SDA", "5V ",
- "I2C1.SCL", "GND(0V) ",
- "GPIO. 18", "UART0.TX",
- " GND(0V)", "UART0.RX",
- "GPIO.174", "GPIO.173",
- "GPIO. 21", "GND(0V) ",
- "GPIO. 22", "GPIO. 19",
- " 3.3V", "GPIO. 23",
- " MOSI", "GND(0V) ",
- " MISO", "GPIO. 24",
- " SCLK", "CE0 ",
- " GND(0V)", "GPIO. 25",
- "I2C5.SDA", "I2C5.SCL",
- "GPIO. 28", "GND(0V) ",
- "GPIO. 30", "GPIO. 29",
- "GPIO. 31", "GND(0V) ",
- "POWER ON", "GPIO. 33",
- " AIN.0", "1V8 ",
- " GND(0V)", "AIN.3 ",
-
- 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 *physNamesOdroidN1 [64] =
-{
- NULL,
-
- " 3.0V", "5V ",
- "I2C4_SDA", "5V ",
- "I2C4_SCL", "GND(0V) ",
- "GPIO1A.0", "UART0_TX",
- " GND(0V)", "UART0_RX",
- "GPIO1A.1", "GPIO1A.2",
- "GPIO1A.3", "GND(0V) ",
- "GPIO1A.4", "GPIO1B.5",
- " 3.0V", "GPIO1C.2",
- "SPI1_TXD", "GND(0V) ",
- "SPI1_RXD", "GPIO1D.0",
- "SPI1_CLK", "SPI1_CSN",
- " GND(0V)", "GPIO1C.6",
- "I2C8_SDA", "I2C8_SCL",
- "SPDIF_TX", "GND(0V) ",
- " PWM1", "GPIO4D.4",
- "GPIO4D.0", "GND(0V) ",
- "GPIO4D.5", "GPIO4D.6",
- "ADC.AIN1", "1V8 ",
- " GND(0V)", "ADC.AIN0",
-
- 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 *physNamesOdroidN2 [64] =
-{
- NULL,
-
- " 3.3V", "5V ",
- " SDA.2", "5V ",
- " SCL.2", "GND(0V) ",
- "GPIO.473", "TxD1 ",
- " GND(0V)", "RxD1 ",
- "GPIO.479", "GPIO.492",
- "GPIO.480", "GND(0V) ",
- "GPIO.483", "GPIO.476",
- " 3.3V", "GPIO.477",
- " MOSI", "GND(0V) ",
- " MISO", "GPIO.478",
- " SCLK", "CE0 ",
- " GND(0V)", "GPIO.464",
- " SDA.3", "SCL.3 ",
- "GPIO.490", "GND(0V) ",
- "GPIO.491", "GPIO.472",
- "GPIO.481", "GND(0V) ",
- "GPIO.482", "GPIO.495",
- " AIN.3", "1V8 ",
- " GND(0V)", "AIN.2 ",
-
- 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 readallPhysOdroid (int model, int rev, int physPin, const char *physNames[])
-{
- 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_ODROID_N1:
- printf (" | | ");
- break;
- case MODEL_ODROID_C1:
- case MODEL_ODROID_C2:
- printf (" | | %5s", pupd[getPUPD(pin)]);
- break;
- case MODEL_ODROID_XU3:
- case MODEL_ODROID_N2:
- printf (" | %2d | %5s", getPadDrive(pin), 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_ODROID_N1:
- printf (" | | ");
- break;
- case MODEL_ODROID_C1:
- case MODEL_ODROID_C2:
- printf (" | %-5s | ", pupd[getPUPD(pin)]);
- break;
- case MODEL_ODROID_XU3:
- case MODEL_ODROID_N2:
- printf (" | %-5s | %-2d", pupd[getPUPD(pin)], getPadDrive(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") ;
-}
-
-/*----------------------------------------------------------------------------*/
-void ReadallOdroid (int model, int rev, const char *physNames[])
-{
- 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)
- readallPhysOdroid (model, rev, pin, physNames) ;
- printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n") ;
-}
-
-/*----------------------------------------------------------------------------*/
-/*
- * 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 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_ODROID_C1:
- printf (" +------+-----+----------+------+---+----+---- Model ODROID-C1 ----+----+---+------+----------+-----+------+\n") ;
- physNames = physNamesOdroidC1;
- break;
- case MODEL_ODROID_C2:
- printf (" +------+-----+----------+------+---+----+---- Model ODROID-C2 ----+----+---+------+----------+-----+------+\n") ;
- if (rev == 1)
- physNames = physNamesOdroidC2_Rev1;
- else
- physNames = physNamesOdroidC2_Rev2;
- break;
- case MODEL_ODROID_XU3:
- printf (" +------+-----+----------+------+---+----+--- Model ODROID-XU3/4 ---+----+---+------+----------+-----+------+\n") ;
- physNames = physNamesOdroidXU3;
- break;
- case MODEL_ODROID_N1:
- printf (" +------+-----+----------+------+---+----+---- Model ODROID-N1 ----+----+---+------+----------+-----+------+\n") ;
- physNames = physNamesOdroidN1;
- break;
- case MODEL_ODROID_N2:
- printf (" +------+-----+----------+------+---+----+---- Model ODROID-N2 ----+----+---+------+----------+-----+------+\n") ;
- physNames = physNamesOdroidN2;
- break;
- default:
- printf ("Oops - unable to determine board type... model: %d\n", model) ;
- return;
- }
- ReadallOdroid(model, rev, physNames);
-}
-
-/*----------------------------------------------------------------------------*/
-/*
- * doAllReadall:
- * Force reading of all pins regardless of Pi model
- */
-/*----------------------------------------------------------------------------*/
-void doAllReadall (void)
-{
- doReadall();
-}
-
-/*----------------------------------------------------------------------------*/
-/*----------------------------------------------------------------------------*/
diff --git a/wiringPi/Makefile b/wiringPi/Makefile
index d06fc17..dcae986 100755
--- a/wiringPi/Makefile
+++ b/wiringPi/Makefile
@@ -27,9 +27,6 @@ PREFIX?=/local
LDCONFIG?=ldconfig
-# BRAND_NAME = Pi
-BRAND_NAME = Odroid
-
ifneq ($V,1)
Q ?= @
endif
@@ -48,11 +45,11 @@ LIBS = -lm -lpthread -lrt -lcrypt
###############################################################################
-SRC = wiring${BRAND_NAME}.c \
+SRC = wiringPi.c \
wiringSerial.c wiringShift.c \
piHiPri.c piThread.c \
- wiring${BRAND_NAME}SPI.c \
- wiring${BRAND_NAME}I2C.c \
+ wiringPiSPI.c \
+ wiringPiI2C.c \
softPwm.c softTone.c \
mcp23008.c mcp23016.c mcp23017.c \
mcp23s08.c mcp23s17.c \
@@ -64,15 +61,12 @@ SRC = wiring${BRAND_NAME}.c \
bmp180.c htu21d.c ds18b20.c \
drcSerial.c drcNet.c \
pseudoPins.c \
- wpiExtensions.c
-
-ifeq ($(BRAND_NAME), Odroid)
- SRC += odroidc1.c \
- odroidc2.c \
- odroidxu3.c \
- odroidn1.c \
- odroidn2.c
-endif
+ wpiExtensions.c \
+ odroidc1.c \
+ odroidc2.c \
+ odroidxu3.c \
+ odroidn1.c \
+ odroidn2.c
HEADERS = $(shell ls *.h)
@@ -152,17 +146,14 @@ depend:
# DO NOT DELETE
-ifeq ($(BRAND_NAME), Odroid)
- wiringOdroid.o: softPwm.h softTone.h wiringPi.h wiringOdroid.h ../version.h
- odroidc1.c : wiringPi.h wiringOdroid.h odroidc1.h
- odroidc2.c : wiringPi.h wiringOdroid.h odroidc2.h
- odroidxu3.c : wiringPi.h wiringOdroid.h odroidxu3.h
- odroidn1.c : wiringPi.h wiringOdroid.h odroidn1.h
- odroidn2.c : wiringPi.h wiringOdroid.h odroidn2.h
-else
- wiringPi.o: softPwm.h softTone.h wiringPi.h ../version.h
-endif
+# ODROID Boards
+odroidc1.o : wiringPi.h odroidc1.h
+odroidc2.o : wiringPi.h odroidc2.h
+odroidxu3.o : wiringPi.h odroidxu3.h
+odroidn1.o : wiringPi.h odroidn1.h
+odroidn2.o : wiringPi.h odroidn2.h
+wiringPi.o: softPwm.h softTone.h wiringPi.h ../version.h
wiringSerial.o: wiringSerial.h
wiringShift.o: wiringPi.h wiringShift.h
piHiPri.o: wiringPi.h
diff --git a/wiringPi/odroid_template.c b/wiringPi/odroid_template.c
index 8fd82f5..4706e0a 100755
--- a/wiringPi/odroid_template.c
+++ b/wiringPi/odroid_template.c
@@ -18,7 +18,11 @@
#include
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "softPwm.h"
+#include "softTone.h"
+
+/*----------------------------------------------------------------------------*/
+#include "wiringPi.h"
#include "odroid???.h"
/*----------------------------------------------------------------------------*/
@@ -101,17 +105,17 @@ static int gpioToShiftReg (int pin);
static int gpioToGPFSELReg (int pin);
/*----------------------------------------------------------------------------*/
-// wiringPi core function
+// wiringPi core function
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin);
-static void pinMode (int pin, int mode);
-static int getAlt (int pin);
-static void pullUpDnControl (int pin, int pud);
-static int digitalRead (int pin);
-static void digitalWrite (int pin, int value);
-static int analogRead (int pin);
-static void digitalWriteByte(const int value);
-static unsigned int digitalReadByte (void);
+static int _getModeToGpio (int mode, int pin);
+static void _pinMode (int pin, int mode);
+static int _getAlt (int pin);
+static void _pullUpDnControl (int pin, int pud);
+static int _digitalRead (int pin);
+static void _digitalWrite (int pin, int value);
+static int _analogRead (int pin);
+static void _digitalWriteByte (const int value);
+static unsigned int _digitalReadByte (void);
/*----------------------------------------------------------------------------*/
// board init function
@@ -182,50 +186,50 @@ static int gpioToGPFSELReg (int pin)
return -1;
}
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin)
+static int _getModeToGpio (int mode, int pin)
{
return -1;
}
/*----------------------------------------------------------------------------*/
-static void pinMode (int pin, int mode)
+static void _pinMode (int pin, int mode)
{
}
/*----------------------------------------------------------------------------*/
-static int getAlt (int pin)
+static int _getAlt (int pin)
{
return -1;
}
/*----------------------------------------------------------------------------*/
-static void pullUpDnControl (int pin, int pud)
+static void _pullUpDnControl (int pin, int pud)
{
}
/*----------------------------------------------------------------------------*/
-static int digitalRead (int pin)
+static int _digitalRead (int pin)
{
}
/*----------------------------------------------------------------------------*/
-static void digitalWrite (int pin, int value)
+static void _digitalWrite (int pin, int value)
{
}
/*----------------------------------------------------------------------------*/
-static int analogRead (int pin)
+static int _analogRead (int pin)
{
return -1;
}
/*----------------------------------------------------------------------------*/
-static void digitalWriteByte (const int value)
+static void _digitalWriteByte (const int value)
{
}
/*----------------------------------------------------------------------------*/
-static unsigned int digitalReadByte (void)
+static unsigned int _digitalReadByte (void)
{
return -1;
}
@@ -248,15 +252,15 @@ void init_odroid??? (struct libodroid *libwiring)
init_adc_fds();
/* wiringPi Core function initialize */
- libwiring->getModeToGpio = getModeToGpio;
- libwiring->pinMode = pinMode;
- libwiring->getAlt = getAlt;
- libwiring->pullUpDnControl = pullUpDnControl;
- libwiring->digitalRead = digitalRead;
- libwiring->digitalWrite = digitalWrite;
- libwiring->analogRead = analogRead;
- libwiring->digitalWriteByte = digitalWriteByte;
- libwiring->digitalReadByte = digitalReadByte;
+ libwiring->getModeToGpio = _getModeToGpio;
+ libwiring->pinMode = _pinMode;
+ libwiring->getAlt = _getAlt;
+ libwiring->pullUpDnControl = _pullUpDnControl;
+ libwiring->digitalRead = _digitalRead;
+ libwiring->digitalWrite = _digitalWrite;
+ libwiring->analogRead = _analogRead;
+ libwiring->digitalWriteByte = _digitalWriteByte;
+ libwiring->digitalReadByte = _digitalReadByte;
/* global variable setup */
lib = libwiring;
diff --git a/wiringPi/odroidc1.c b/wiringPi/odroidc1.c
index f060f38..73637b6 100755
--- a/wiringPi/odroidc1.c
+++ b/wiringPi/odroidc1.c
@@ -18,7 +18,11 @@
#include
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "softPwm.h"
+#include "softTone.h"
+
+/*----------------------------------------------------------------------------*/
+#include "wiringPi.h"
#include "odroidc1.h"
/*----------------------------------------------------------------------------*/
@@ -103,18 +107,18 @@ static int gpioToShiftReg (int pin);
static int gpioToGPFSELReg (int pin);
/*----------------------------------------------------------------------------*/
-// wiringPi core function
+// wiringPi core function
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin);
-static void pinMode (int pin, int mode);
-static int getAlt (int pin);
-static int getPUPD (int pin);
-static void pullUpDnControl (int pin, int pud);
-static int digitalRead (int pin);
-static void digitalWrite (int pin, int value);
-static int analogRead (int pin);
-static void digitalWriteByte(const int value);
-static unsigned int digitalReadByte (void);
+static int _getModeToGpio (int mode, int pin);
+static void _pinMode (int pin, int mode);
+static int _getAlt (int pin);
+static int _getPUPD (int pin);
+static void _pullUpDnControl (int pin, int pud);
+static int _digitalRead (int pin);
+static void _digitalWrite (int pin, int value);
+static int _analogRead (int pin);
+static void _digitalWriteByte (const int value);
+static unsigned int _digitalReadByte (void);
/*----------------------------------------------------------------------------*/
// board init function
@@ -132,12 +136,12 @@ static void init_adc_fds (void);
/*----------------------------------------------------------------------------*/
static int gpioToGPSETReg (int pin)
{
- if (pin >= GPIOX_PIN_START && pin <= GPIOX_PIN_END)
- return GPIOX_OUTP_REG_OFFSET;
- if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
- return GPIOY_OUTP_REG_OFFSET;
- if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
- return GPIODV_OUTP_REG_OFFSET;
+ if (pin >= C1_GPIOX_PIN_START && pin <= C1_GPIOX_PIN_END)
+ return C1_GPIOX_OUTP_REG_OFFSET;
+ if (pin >= C1_GPIOY_PIN_START && pin <= C1_GPIOY_PIN_END)
+ return C1_GPIOY_OUTP_REG_OFFSET;
+ if (pin >= C1_GPIODV_PIN_START && pin <= C1_GPIODV_PIN_END)
+ return C1_GPIODV_OUTP_REG_OFFSET;
return -1;
}
@@ -148,12 +152,12 @@ static int gpioToGPSETReg (int pin)
/*----------------------------------------------------------------------------*/
static int gpioToGPLEVReg (int pin)
{
- if (pin >= GPIOX_PIN_START && pin <= GPIOX_PIN_END)
- return GPIOX_INP_REG_OFFSET;
- if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
- return GPIOY_INP_REG_OFFSET;
- if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
- return GPIODV_INP_REG_OFFSET;
+ if (pin >= C1_GPIOX_PIN_START && pin <= C1_GPIOX_PIN_END)
+ return C1_GPIOX_INP_REG_OFFSET;
+ if (pin >= C1_GPIOY_PIN_START && pin <= C1_GPIOY_PIN_END)
+ return C1_GPIOY_INP_REG_OFFSET;
+ if (pin >= C1_GPIODV_PIN_START && pin <= C1_GPIODV_PIN_END)
+ return C1_GPIODV_INP_REG_OFFSET;
return -1;
}
@@ -164,12 +168,12 @@ static int gpioToGPLEVReg (int pin)
/*----------------------------------------------------------------------------*/
static int gpioToPUENReg (int pin)
{
- if (pin >= GPIOX_PIN_START && pin <= GPIOX_PIN_END)
- return GPIOX_PUEN_REG_OFFSET;
- if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
- return GPIOY_PUEN_REG_OFFSET;
- if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
- return GPIODV_PUEN_REG_OFFSET;
+ if (pin >= C1_GPIOX_PIN_START && pin <= C1_GPIOX_PIN_END)
+ return C1_GPIOX_PUEN_REG_OFFSET;
+ if (pin >= C1_GPIOY_PIN_START && pin <= C1_GPIOY_PIN_END)
+ return C1_GPIOY_PUEN_REG_OFFSET;
+ if (pin >= C1_GPIODV_PIN_START && pin <= C1_GPIODV_PIN_END)
+ return C1_GPIODV_PUEN_REG_OFFSET;
return -1;
}
@@ -180,12 +184,12 @@ static int gpioToPUENReg (int pin)
/*----------------------------------------------------------------------------*/
static int gpioToPUPDReg (int pin)
{
- if (pin >= GPIOX_PIN_START && pin <= GPIOX_PIN_END)
- return GPIOX_PUPD_REG_OFFSET;
- if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
- return GPIOY_PUPD_REG_OFFSET;
- if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
- return GPIODV_PUPD_REG_OFFSET;
+ if (pin >= C1_GPIOX_PIN_START && pin <= C1_GPIOX_PIN_END)
+ return C1_GPIOX_PUPD_REG_OFFSET;
+ if (pin >= C1_GPIOY_PIN_START && pin <= C1_GPIOY_PIN_END)
+ return C1_GPIOY_PUPD_REG_OFFSET;
+ if (pin >= C1_GPIODV_PIN_START && pin <= C1_GPIODV_PIN_END)
+ return C1_GPIODV_PUPD_REG_OFFSET;
return -1;
}
@@ -196,12 +200,12 @@ static int gpioToPUPDReg (int pin)
/*----------------------------------------------------------------------------*/
static int gpioToShiftReg (int pin)
{
- if (pin >= GPIOX_PIN_START && pin <= GPIOX_PIN_END)
- return pin - GPIOX_PIN_START;
- if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
- return pin - GPIOY_PIN_START;
- if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
- return pin - GPIODV_PIN_START;
+ if (pin >= C1_GPIOX_PIN_START && pin <= C1_GPIOX_PIN_END)
+ return pin - C1_GPIOX_PIN_START;
+ if (pin >= C1_GPIOY_PIN_START && pin <= C1_GPIOY_PIN_END)
+ return pin - C1_GPIOY_PIN_START;
+ if (pin >= C1_GPIODV_PIN_START && pin <= C1_GPIODV_PIN_END)
+ return pin - C1_GPIODV_PIN_START;
return -1;
}
@@ -212,17 +216,17 @@ static int gpioToShiftReg (int pin)
/*----------------------------------------------------------------------------*/
static int gpioToGPFSELReg (int pin)
{
- if (pin >= GPIOX_PIN_START && pin <= GPIOX_PIN_END)
- return GPIOX_FSEL_REG_OFFSET;
- if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
- return GPIOY_FSEL_REG_OFFSET;
- if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
- return GPIODV_FSEL_REG_OFFSET;
+ if (pin >= C1_GPIOX_PIN_START && pin <= C1_GPIOX_PIN_END)
+ return C1_GPIOX_FSEL_REG_OFFSET;
+ if (pin >= C1_GPIOY_PIN_START && pin <= C1_GPIOY_PIN_END)
+ return C1_GPIOY_FSEL_REG_OFFSET;
+ if (pin >= C1_GPIODV_PIN_START && pin <= C1_GPIODV_PIN_END)
+ return C1_GPIODV_FSEL_REG_OFFSET;
return -1;
}
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin)
+static int _getModeToGpio (int mode, int pin)
{
int retPin = -1;
@@ -258,14 +262,14 @@ static int getModeToGpio (int mode, int pin)
}
/*----------------------------------------------------------------------------*/
-static void pinMode (int pin, int mode)
+static void _pinMode (int pin, int mode)
{
int fsel, shift, origPin = pin;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
softPwmStop (origPin);
@@ -294,7 +298,7 @@ static void pinMode (int pin, int mode)
}
/*----------------------------------------------------------------------------*/
-static int getAlt (int pin)
+static int _getAlt (int pin)
{
int fsel, shift;
int mode = 0;
@@ -302,169 +306,169 @@ static int getAlt (int pin)
if (lib->mode == MODE_GPIO_SYS)
return 0;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 2;
fsel = gpioToGPFSELReg(pin);
shift = gpioToShiftReg(pin);
switch (pin) {
- case GPIOX_PIN_START ...GPIOX_PIN_END:
+ case C1_GPIOX_PIN_START ...C1_GPIOX_PIN_END:
switch (shift) {
case 0:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 5)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 14)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_8_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 14)) mode = 2; break;
break;
case 1:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 4)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 13)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_8_OFFSET) & (1 << 4)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 13)) mode = 2; break;
break;
case 2:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 3)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 13)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_8_OFFSET) & (1 << 3)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 13)) mode = 2; break;
break;
case 3:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 2)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 13)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_8_OFFSET) & (1 << 2)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 13)) mode = 2; break;
break;
case 4:
- if ((*(gpio + MUX_REG_5_OFFSET) & (1 << 29)) &&
- (*(gpio + MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 30)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 17)) mode = 3; break;
+ if ((*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 29)) &&
+ (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 30)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 17)) mode = 3; break;
break;
case 5:
- if ((*(gpio + MUX_REG_5_OFFSET) & (1 << 28)) &&
- (*(gpio + MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 29)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 16)) mode = 3; break;
+ if ((*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 28)) &&
+ (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 29)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 16)) mode = 3; break;
break;
case 6:
- if ((*(gpio + MUX_REG_5_OFFSET) & (1 << 28)) &&
- (*(gpio + MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 27)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 15)) mode = 3; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 9)) mode = 4; break;
+ if ((*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 28)) &&
+ (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 27)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 15)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 9)) mode = 4; break;
break;
case 7:
- if ((*(gpio + MUX_REG_5_OFFSET) & (1 << 28)) &&
- (*(gpio + MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 27)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 14)) mode = 3; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 8)) mode = 4; break;
+ if ((*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 28)) &&
+ (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 12))) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 27)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 14)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 8)) mode = 4; break;
break;
case 8:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 1)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 11)) mode = 2; break;
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 19)) mode = 3; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 22)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 6)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_8_OFFSET) & (1 << 1)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 11)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 19)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 22)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 6)) mode = 5; break;
break;
case 9:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 0)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 10)) mode = 2; break;
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 18)) mode = 3; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 24)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 6)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_8_OFFSET) & (1 << 0)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 10)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 18)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 24)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 6)) mode = 5; break;
break;
case 10:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 22)) mode = 1; break;
- if ((*(gpio + MUX_REG_7_OFFSET) & (1 << 31)) &&
- (*(gpio + MUX_REG_9_OFFSET) & (1 << 19))) mode = 2; break;
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 17)) mode = 3; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 23)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 8)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 22)) mode = 1; break;
+ if ((*(gpio + C1_MUX_REG_7_OFFSET) & (1 << 31)) &&
+ (*(gpio + C1_MUX_REG_9_OFFSET) & (1 << 19))) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 17)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 23)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 8)) mode = 5; break;
break;
case 11:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 20)) mode = 1; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 30)) mode = 2; break;
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 3)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 20)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_7_OFFSET) & (1 << 30)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_2_OFFSET) & (1 << 3)) mode = 5; break;
break;
case 16:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 9)) mode = 1; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 21)) mode = 4; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 5)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 9)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 21)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 5)) mode = 5; break;
break;
case 17:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 8)) mode = 1; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 20)) mode = 4; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 4)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 8)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 20)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 4)) mode = 5; break;
break;
case 18:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 7)) mode = 1; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 19)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 7)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 19)) mode = 4; break;
break;
case 19:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 6)) mode = 1; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 18)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 6)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 18)) mode = 4; break;
break;
case 20:
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 16)) mode = 3; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 25)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 9)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 16)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_4_OFFSET) & (1 << 25)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 9)) mode = 5; break;
break;
}
break;
- case GPIOY_PIN_START ...GPIOY_PIN_END:
+ case C1_GPIOY_PIN_START ...C1_GPIOY_PIN_END:
switch (shift) {
case 0:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 2)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 2)) mode = 1; break;
break;
case 1:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 1)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 1)) mode = 1; break;
break;
case 3:
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 7)) mode = 2; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 18)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_1_OFFSET) & (1 << 7)) mode = 2; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 18)) mode = 3; break;
break;
case 6:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
break;
case 7:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
break;
case 8:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 0)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 0)) mode = 1; break;
break;
case 9:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 4)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 4)) mode = 1; break;
break;
case 10:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
break;
case 11:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
break;
case 12:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
break;
case 13:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 7)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 7)) mode = 3; break;
break;
case 14:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 6)) mode = 3; break;
+ if (*(gpio + C1_MUX_REG_3_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C1_MUX_REG_5_OFFSET) & (1 << 6)) mode = 3; break;
break;
}
break;
- case GPIODV_PIN_START...GPIODV_PIN_END:
+ case C1_GPIODV_PIN_START...C1_GPIODV_PIN_END:
switch (shift) {
case 24:
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 23)) mode = 4; break;
- if (*(gpio + MUX_REG_9_OFFSET) & (1 << 31)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 23)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_9_OFFSET) & (1 << 31)) mode = 5; break;
break;
case 25:
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 22)) mode = 4; break;
- if (*(gpio + MUX_REG_9_OFFSET) & (1 << 30)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 22)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_9_OFFSET) & (1 << 30)) mode = 5; break;
break;
case 26:
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 21)) mode = 4; break;
- if (*(gpio + MUX_REG_9_OFFSET) & (1 << 29)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 21)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_9_OFFSET) & (1 << 29)) mode = 5; break;
break;
case 27:
- if (*(gpio + MUX_REG_6_OFFSET) & (1 << 20)) mode = 4; break;
- if (*(gpio + MUX_REG_9_OFFSET) & (1 << 28)) mode = 5; break;
+ if (*(gpio + C1_MUX_REG_6_OFFSET) & (1 << 20)) mode = 4; break;
+ if (*(gpio + C1_MUX_REG_9_OFFSET) & (1 << 28)) mode = 5; break;
break;
}
break;
@@ -476,14 +480,14 @@ static int getAlt (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getPUPD (int pin)
+static int _getPUPD (int pin)
{
int puen, pupd, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
puen = gpioToPUENReg(pin);
@@ -497,14 +501,14 @@ static int getPUPD (int pin)
}
/*----------------------------------------------------------------------------*/
-static void pullUpDnControl (int pin, int pud)
+static void _pullUpDnControl (int pin, int pud)
{
int shift = 0;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
shift = gpioToShiftReg(pin);
@@ -526,7 +530,7 @@ static void pullUpDnControl (int pin, int pud)
}
/*----------------------------------------------------------------------------*/
-static int digitalRead (int pin)
+static int _digitalRead (int pin)
{
char c ;
@@ -540,7 +544,7 @@ static int digitalRead (int pin)
return (c == '0') ? LOW : HIGH;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 0;
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
@@ -550,7 +554,7 @@ static int digitalRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWrite (int pin, int value)
+static void _digitalWrite (int pin, int value)
{
if (lib->mode == MODE_GPIO_SYS) {
if (lib->sysFds[pin] != -1) {
@@ -562,7 +566,7 @@ static void digitalWrite (int pin, int value)
return;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
if (value == LOW)
@@ -572,7 +576,7 @@ static void digitalWrite (int pin, int value)
}
/*----------------------------------------------------------------------------*/
-static int analogRead (int pin)
+static int _analogRead (int pin)
{
unsigned char value[5] = {0,};
@@ -600,12 +604,12 @@ static int analogRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWriteByte (const int value)
+static void _digitalWriteByte (const int value)
{
union reg_bitfield gpiox, gpioy;
- gpiox.wvalue = *(gpio + GPIOX_INP_REG_OFFSET);
- gpioy.wvalue = *(gpio + GPIOY_INP_REG_OFFSET);
+ gpiox.wvalue = *(gpio + C1_GPIOX_INP_REG_OFFSET);
+ gpioy.wvalue = *(gpio + C1_GPIOY_INP_REG_OFFSET);
/* Wiring PI GPIO0 = C1 GPIOY.8 */
gpioy.bits.bit8 = (value & 0x01);
@@ -624,18 +628,18 @@ static void digitalWriteByte (const int value)
/* Wiring PI GPIO7 = C1 GPIOY.3 */
gpioy.bits.bit3 = (value & 0x80);
- *(gpio + GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
- *(gpio + GPIOY_OUTP_REG_OFFSET) = gpioy.wvalue;
+ *(gpio + C1_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
+ *(gpio + C1_GPIOY_OUTP_REG_OFFSET) = gpioy.wvalue;
}
/*----------------------------------------------------------------------------*/
-static unsigned int digitalReadByte (void)
+static unsigned int _digitalReadByte (void)
{
union reg_bitfield gpiox, gpioy;
unsigned int value = 0;
- gpiox.wvalue = *(gpio + GPIOX_INP_REG_OFFSET);
- gpioy.wvalue = *(gpio + GPIOY_INP_REG_OFFSET);
+ gpiox.wvalue = *(gpio + C1_GPIOX_INP_REG_OFFSET);
+ gpioy.wvalue = *(gpio + C1_GPIOY_INP_REG_OFFSET);
/* Wiring PI GPIO0 = C1 GPIOY.8 */
if (gpioy.bits.bit8)
@@ -686,9 +690,9 @@ static void init_gpio_mmap (void)
"wiringPiSetup: Unable to open /dev/mem: %s\n",
strerror (errno)) ;
}
- //#define ODROIDXU_GPX_BASE 0xC1108000
+ // #define C1_GPIO_BASE 0xC1108000
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, ODROIDC1_GPIO_BASE) ;
+ MAP_SHARED, fd, C1_GPIO_BASE) ;
if ((int32_t)gpio == -1)
return msg (MSG_ERR,
@@ -717,19 +721,19 @@ void init_odroidc1 (struct libodroid *libwiring)
init_adc_fds();
/* wiringPi Core function initialize */
- libwiring->getModeToGpio = getModeToGpio;
- libwiring->pinMode = pinMode;
- libwiring->getAlt = getAlt;
- libwiring->getPUPD = getPUPD;
- libwiring->pullUpDnControl = pullUpDnControl;
- libwiring->digitalRead = digitalRead;
- libwiring->digitalWrite = digitalWrite;
- libwiring->analogRead = analogRead;
- libwiring->digitalWriteByte = digitalWriteByte;
- libwiring->digitalReadByte = digitalReadByte;
+ libwiring->getModeToGpio = _getModeToGpio;
+ libwiring->pinMode = _pinMode;
+ libwiring->getAlt = _getAlt;
+ libwiring->getPUPD = _getPUPD;
+ libwiring->pullUpDnControl = _pullUpDnControl;
+ libwiring->digitalRead = _digitalRead;
+ libwiring->digitalWrite = _digitalWrite;
+ libwiring->analogRead = _analogRead;
+ libwiring->digitalWriteByte = _digitalWriteByte;
+ libwiring->digitalReadByte = _digitalReadByte;
/* specify pin base number */
- libwiring->pinBase = GPIO_PIN_BASE;
+ libwiring->pinBase = C1_GPIO_PIN_BASE;
/* global variable setup */
lib = libwiring;
diff --git a/wiringPi/odroidc1.h b/wiringPi/odroidc1.h
index bbdbc3d..23f9126 100755
--- a/wiringPi/odroidc1.h
+++ b/wiringPi/odroidc1.h
@@ -9,45 +9,45 @@
#define __ODROID_C1_H__
/*----------------------------------------------------------------------------*/
-#define ODROIDC_GPIO_MASK (0xFFFFFF80)
-#define ODROIDC1_GPIO_BASE 0xC1108000
+#define C1_GPIO_MASK (0xFFFFFF80)
+#define C1_GPIO_BASE 0xC1108000
-#define GPIO_PIN_BASE 0
+#define C1_GPIO_PIN_BASE 0
-#define GPIODV_PIN_START 50
-#define GPIODV_PIN_END 79
-#define GPIOY_PIN_START 80
-#define GPIOY_PIN_END 96
-#define GPIOX_PIN_START 97
-#define GPIOX_PIN_END 118
+#define C1_GPIODV_PIN_START 50
+#define C1_GPIODV_PIN_END 79
+#define C1_GPIOY_PIN_START 80
+#define C1_GPIOY_PIN_END 96
+#define C1_GPIOX_PIN_START 97
+#define C1_GPIOX_PIN_END 118
-#define GPIOX_FSEL_REG_OFFSET 0x0C
-#define GPIOX_OUTP_REG_OFFSET 0x0D
-#define GPIOX_INP_REG_OFFSET 0x0E
-#define GPIOX_PUPD_REG_OFFSET 0x3E
-#define GPIOX_PUEN_REG_OFFSET 0x4C
+#define C1_GPIOX_FSEL_REG_OFFSET 0x0C
+#define C1_GPIOX_OUTP_REG_OFFSET 0x0D
+#define C1_GPIOX_INP_REG_OFFSET 0x0E
+#define C1_GPIOX_PUPD_REG_OFFSET 0x3E
+#define C1_GPIOX_PUEN_REG_OFFSET 0x4C
-#define GPIOY_FSEL_REG_OFFSET 0x0F
-#define GPIOY_OUTP_REG_OFFSET 0x10
-#define GPIOY_INP_REG_OFFSET 0x11
-#define GPIOY_PUPD_REG_OFFSET 0x3D
-#define GPIOY_PUEN_REG_OFFSET 0x4B
+#define C1_GPIOY_FSEL_REG_OFFSET 0x0F
+#define C1_GPIOY_OUTP_REG_OFFSET 0x10
+#define C1_GPIOY_INP_REG_OFFSET 0x11
+#define C1_GPIOY_PUPD_REG_OFFSET 0x3D
+#define C1_GPIOY_PUEN_REG_OFFSET 0x4B
-#define GPIODV_FSEL_REG_OFFSET 0x12
-#define GPIODV_OUTP_REG_OFFSET 0x13
-#define GPIODV_INP_REG_OFFSET 0x14
-#define GPIODV_PUPD_REG_OFFSET 0x3A
-#define GPIODV_PUEN_REG_OFFSET 0x48
+#define C1_GPIODV_FSEL_REG_OFFSET 0x12
+#define C1_GPIODV_OUTP_REG_OFFSET 0x13
+#define C1_GPIODV_INP_REG_OFFSET 0x14
+#define C1_GPIODV_PUPD_REG_OFFSET 0x3A
+#define C1_GPIODV_PUEN_REG_OFFSET 0x48
-#define MUX_REG_1_OFFSET 0x2D
-#define MUX_REG_2_OFFSET 0x2E
-#define MUX_REG_3_OFFSET 0x2F
-#define MUX_REG_4_OFFSET 0x30
-#define MUX_REG_5_OFFSET 0x31
-#define MUX_REG_6_OFFSET 0x32
-#define MUX_REG_7_OFFSET 0x33
-#define MUX_REG_8_OFFSET 0x34
-#define MUX_REG_9_OFFSET 0x35
+#define C1_MUX_REG_1_OFFSET 0x2D
+#define C1_MUX_REG_2_OFFSET 0x2E
+#define C1_MUX_REG_3_OFFSET 0x2F
+#define C1_MUX_REG_4_OFFSET 0x30
+#define C1_MUX_REG_5_OFFSET 0x31
+#define C1_MUX_REG_6_OFFSET 0x32
+#define C1_MUX_REG_7_OFFSET 0x33
+#define C1_MUX_REG_8_OFFSET 0x34
+#define C1_MUX_REG_9_OFFSET 0x35
#ifdef __cplusplus
extern "C" {
diff --git a/wiringPi/odroidc2.c b/wiringPi/odroidc2.c
index 97b2b11..b39bc8b 100755
--- a/wiringPi/odroidc2.c
+++ b/wiringPi/odroidc2.c
@@ -18,7 +18,11 @@
#include
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "softPwm.h"
+#include "softTone.h"
+
+/*----------------------------------------------------------------------------*/
+#include "wiringPi.h"
#include "odroidc2.h"
/*----------------------------------------------------------------------------*/
@@ -158,18 +162,18 @@ static int gpioToShiftReg (int pin);
static int gpioToGPFSELReg (int pin);
/*----------------------------------------------------------------------------*/
-// wiringPi core function
+// wiringPi core function
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin);
-static void pinMode (int pin, int mode);
-static int getAlt (int pin);
-static int getPUPD (int pin);
-static void pullUpDnControl (int pin, int pud);
-static int digitalRead (int pin);
-static void digitalWrite (int pin, int value);
-static int analogRead (int pin);
-static void digitalWriteByte(const int value);
-static unsigned int digitalReadByte (void);
+static int _getModeToGpio (int mode, int pin);
+static void _pinMode (int pin, int mode);
+static int _getAlt (int pin);
+static int _getPUPD (int pin);
+static void _pullUpDnControl (int pin, int pud);
+static int _digitalRead (int pin);
+static void _digitalWrite (int pin, int value);
+static int _analogRead (int pin);
+static void _digitalWriteByte (const int value);
+static unsigned int _digitalReadByte (void);
/*----------------------------------------------------------------------------*/
// board init function
@@ -276,7 +280,7 @@ static int gpioToGPFSELReg (int pin)
return -1;
}
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin)
+static int _getModeToGpio (int mode, int pin)
{
int retPin = -1;
@@ -312,14 +316,14 @@ static int getModeToGpio (int mode, int pin)
}
/*----------------------------------------------------------------------------*/
-static void pinMode (int pin, int mode)
+static void _pinMode (int pin, int mode)
{
int fsel, shift, origPin = pin;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
softPwmStop (origPin);
@@ -348,7 +352,7 @@ static void pinMode (int pin, int mode)
}
/*----------------------------------------------------------------------------*/
-static int getAlt (int pin)
+static int _getAlt (int pin)
{
int fsel, shift;
int mode = 0;
@@ -356,7 +360,7 @@ static int getAlt (int pin)
if (lib->mode == MODE_GPIO_SYS)
return 0;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 2;
fsel = gpioToGPFSELReg(pin);
@@ -366,191 +370,191 @@ static int getAlt (int pin)
case C2_GPIOX_PIN_START ...C2_GPIOX_PIN_END:
switch (shift) {
case 0:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 5)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 5)) mode = 1; break;
break;
case 1:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 4)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 4)) mode = 1; break;
break;
case 2:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 3)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 3)) mode = 1; break;
break;
case 3:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 2)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 2)) mode = 1; break;
break;
case 4:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 1)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 1)) mode = 1; break;
break;
case 5:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 0)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 0)) mode = 1; break;
break;
case 6:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 9)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 17)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 9)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 17)) mode = 5; break;
break;
case 7:
- if (*(gpio + MUX_REG_8_OFFSET) & (1 << 11)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 8)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 18)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_8_OFFSET) & (1 << 11)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 8)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 18)) mode = 5; break;
break;
case 8:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 7)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 30)) mode = 3; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 10)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 7)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 30)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 10)) mode = 4; break;
break;
case 9:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 6)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 29)) mode = 3; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 7)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 6)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 29)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 7)) mode = 4; break;
break;
case 10:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 28)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 28)) mode = 3; break;
break;
case 11:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 27)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 27)) mode = 3; break;
break;
case 12:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 13)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 17)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 13)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 17)) mode = 3; break;
break;
case 13:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 12)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 16)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 12)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 16)) mode = 3; break;
break;
case 14:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 11)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 15)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 11)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 15)) mode = 3; break;
break;
case 15:
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 10)) mode = 2; break;
- if (*(gpio + MUX_REG_4_OFFSET) & (1 << 14)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 10)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_4_OFFSET) & (1 << 14)) mode = 3; break;
break;
case 19:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 22)) mode = 2; break;
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 30)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 22)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 30)) mode = 5; break;
break;
}
break;
case C2_GPIOY_PIN_START ...C2_GPIOY_PIN_END:
switch (shift) {
case 0:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 19)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 2)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 0)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 19)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 2)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 0)) mode = 5; break;
break;
case 1:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 18)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 1)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 1)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 18)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 1)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 1)) mode = 5; break;
break;
case 2:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 17)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 0)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 17)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 0)) mode = 2; break;
break;
case 3:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 4)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 2)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 4)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 2)) mode = 5; break;
break;
case 4:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 12)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 12)) mode = 4; break;
break;
case 5:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 13)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 13)) mode = 4; break;
break;
case 6:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 3)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 3)) mode = 5; break;
break;
case 7:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 4)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 4)) mode = 5; break;
break;
case 8:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 5)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 5)) mode = 5; break;
break;
case 9:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 6)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 6)) mode = 5; break;
break;
case 10:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 7)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 16)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 5)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 7)) mode = 5; break;
break;
case 11:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 3)) mode = 2; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 19)) mode = 3; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 8)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 3)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 19)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 8)) mode = 5; break;
break;
case 12:
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 18)) mode = 3; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 9)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 18)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 9)) mode = 5; break;
break;
case 13:
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 17)) mode = 3; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 10)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 17)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 10)) mode = 5; break;
break;
case 14:
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 16)) mode = 3; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 11)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 16)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 11)) mode = 5; break;
break;
case 15:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 20)) mode = 1; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 20)) mode = 4; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 22)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 20)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 20)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 22)) mode = 5; break;
break;
case 16:
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 21)) mode = 1; break;
- if (*(gpio + MUX_REG_1_OFFSET) & (1 << 21)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 21)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_1_OFFSET) & (1 << 21)) mode = 4; break;
break;
}
break;
case C2_GPIODV_PIN_START...C2_GPIODV_PIN_END:
switch (shift) {
case 24:
- if (*(gpio + MUX_REG_0_OFFSET) & (1 << 7)) mode = 1; break;
- if (*(gpio + MUX_REG_0_OFFSET) & (1 << 12)) mode = 2; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 12)) mode = 3; break;
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 29)) mode = 5; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 26)) mode = 6; break;
+ if (*(gpio + C2_MUX_REG_0_OFFSET) & (1 << 7)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_0_OFFSET) & (1 << 12)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_5_OFFSET) & (1 << 12)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 29)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_7_OFFSET) & (1 << 26)) mode = 6; break;
break;
case 25:
- if (*(gpio + MUX_REG_0_OFFSET) & (1 << 6)) mode = 1; break;
- if (*(gpio + MUX_REG_0_OFFSET) & (1 << 11)) mode = 2; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 11)) mode = 3; break;
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 28)) mode = 5; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 27)) mode = 6; break;
+ if (*(gpio + C2_MUX_REG_0_OFFSET) & (1 << 6)) mode = 1; break;
+ if (*(gpio + C2_MUX_REG_0_OFFSET) & (1 << 11)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_5_OFFSET) & (1 << 11)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 28)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_7_OFFSET) & (1 << 27)) mode = 6; break;
break;
case 26:
- if (*(gpio + MUX_REG_0_OFFSET) & (1 << 10)) mode = 2; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 10)) mode = 3; break;
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 27)) mode = 5; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 24)) mode = 6; break;
+ if (*(gpio + C2_MUX_REG_0_OFFSET) & (1 << 10)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_5_OFFSET) & (1 << 10)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 27)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_7_OFFSET) & (1 << 24)) mode = 6; break;
break;
case 27:
- if (*(gpio + MUX_REG_0_OFFSET) & (1 << 9)) mode = 2; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 9)) mode = 3; break;
- if (*(gpio + MUX_REG_5_OFFSET) & (1 << 8)) mode = 4; break;
- if (*(gpio + MUX_REG_2_OFFSET) & (1 << 26)) mode = 5; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 25)) mode = 6; break;
+ if (*(gpio + C2_MUX_REG_0_OFFSET) & (1 << 9)) mode = 2; break;
+ if (*(gpio + C2_MUX_REG_5_OFFSET) & (1 << 9)) mode = 3; break;
+ if (*(gpio + C2_MUX_REG_5_OFFSET) & (1 << 8)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_2_OFFSET) & (1 << 26)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_7_OFFSET) & (1 << 25)) mode = 6; break;
break;
case 28:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 20)) mode = 5; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 22)) mode = 6; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 20)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_7_OFFSET) & (1 << 22)) mode = 6; break;
break;
case 29:
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 22)) mode = 4; break;
- if (*(gpio + MUX_REG_3_OFFSET) & (1 << 21)) mode = 5; break;
- if (*(gpio + MUX_REG_7_OFFSET) & (1 << 23)) mode = 6; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 22)) mode = 4; break;
+ if (*(gpio + C2_MUX_REG_3_OFFSET) & (1 << 21)) mode = 5; break;
+ if (*(gpio + C2_MUX_REG_7_OFFSET) & (1 << 23)) mode = 6; break;
break;
}
break;
@@ -562,14 +566,14 @@ static int getAlt (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getPUPD (int pin)
+static int _getPUPD (int pin)
{
int puen, pupd, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
puen = gpioToPUENReg(pin);
@@ -583,14 +587,14 @@ static int getPUPD (int pin)
}
/*----------------------------------------------------------------------------*/
-static void pullUpDnControl (int pin, int pud)
+static void _pullUpDnControl (int pin, int pud)
{
int shift = 0;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
shift = gpioToShiftReg(pin);
@@ -612,7 +616,7 @@ static void pullUpDnControl (int pin, int pud)
}
/*----------------------------------------------------------------------------*/
-static int digitalRead (int pin)
+static int _digitalRead (int pin)
{
char c ;
@@ -626,7 +630,7 @@ static int digitalRead (int pin)
return (c == '0') ? LOW : HIGH;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 0;
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
@@ -636,7 +640,7 @@ static int digitalRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWrite (int pin, int value)
+static void _digitalWrite (int pin, int value)
{
if (lib->mode == MODE_GPIO_SYS) {
if (lib->sysFds[pin] != -1) {
@@ -648,7 +652,7 @@ static void digitalWrite (int pin, int value)
return;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
if (value == LOW)
@@ -658,7 +662,7 @@ static void digitalWrite (int pin, int value)
}
/*----------------------------------------------------------------------------*/
-static int analogRead (int pin)
+static int _analogRead (int pin)
{
unsigned char value[5] = {0,};
@@ -686,7 +690,7 @@ static int analogRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWriteByte (const int value)
+static void _digitalWriteByte (const int value)
{
union reg_bitfield gpiox;
@@ -713,7 +717,7 @@ static void digitalWriteByte (const int value)
}
/*----------------------------------------------------------------------------*/
-static unsigned int digitalReadByte (void)
+static unsigned int _digitalReadByte (void)
{
return -1;
}
@@ -739,9 +743,9 @@ static void init_gpio_mmap (void)
"wiringPiSetup: Unable to open /dev/mem: %s\n",
strerror (errno)) ;
}
- //#define ODROIDC2_GPIO_BASE 0xC8834000
+ //#define C2_GPIO_BASE 0xC8834000
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, ODROIDC2_GPIO_BASE) ;
+ MAP_SHARED, fd, C2_GPIO_BASE) ;
if ((int32_t)gpio == -1)
return msg (MSG_ERR,
@@ -778,19 +782,19 @@ void init_odroidc2 (struct libodroid *libwiring)
}
/* wiringPi Core function initialize */
- libwiring->getModeToGpio = getModeToGpio;
- libwiring->pinMode = pinMode;
- libwiring->getAlt = getAlt;
- libwiring->getPUPD = getPUPD;
- libwiring->pullUpDnControl = pullUpDnControl;
- libwiring->digitalRead = digitalRead;
- libwiring->digitalWrite = digitalWrite;
- libwiring->analogRead = analogRead;
- libwiring->digitalWriteByte = digitalWriteByte;
- libwiring->digitalReadByte = digitalReadByte;
+ libwiring->getModeToGpio = _getModeToGpio;
+ libwiring->pinMode = _pinMode;
+ libwiring->getAlt = _getAlt;
+ libwiring->getPUPD = _getPUPD;
+ libwiring->pullUpDnControl = _pullUpDnControl;
+ libwiring->digitalRead = _digitalRead;
+ libwiring->digitalWrite = _digitalWrite;
+ libwiring->analogRead = _analogRead;
+ libwiring->digitalWriteByte = _digitalWriteByte;
+ libwiring->digitalReadByte = _digitalReadByte;
/* specify pin base number */
- libwiring->pinBase = GPIO_PIN_BASE;
+ libwiring->pinBase = C2_GPIO_PIN_BASE;
/* global variable setup */
lib = libwiring;
diff --git a/wiringPi/odroidc2.h b/wiringPi/odroidc2.h
index b52351a..037a107 100755
--- a/wiringPi/odroidc2.h
+++ b/wiringPi/odroidc2.h
@@ -9,17 +9,17 @@
#define __ODROID_C2_H__
/*----------------------------------------------------------------------------*/
-#define ODROIDC2_GPIO_MASK (0xFFFFFF00)
-#define ODROIDC2_GPIO_BASE 0xC8834000
+#define C2_GPIO_MASK (0xFFFFFF00)
+#define C2_GPIO_BASE 0xC8834000
-#define GPIO_PIN_BASE 136
+#define C2_GPIO_PIN_BASE 136
-#define C2_GPIODV_PIN_START (GPIO_PIN_BASE + 45)
-#define C2_GPIODV_PIN_END (GPIO_PIN_BASE + 74)
-#define C2_GPIOY_PIN_START (GPIO_PIN_BASE + 75)
-#define C2_GPIOY_PIN_END (GPIO_PIN_BASE + 91)
-#define C2_GPIOX_PIN_START (GPIO_PIN_BASE + 92)
-#define C2_GPIOX_PIN_END (GPIO_PIN_BASE + 114)
+#define C2_GPIODV_PIN_START (C2_GPIO_PIN_BASE + 45)
+#define C2_GPIODV_PIN_END (C2_GPIO_PIN_BASE + 74)
+#define C2_GPIOY_PIN_START (C2_GPIO_PIN_BASE + 75)
+#define C2_GPIOY_PIN_END (C2_GPIO_PIN_BASE + 91)
+#define C2_GPIOX_PIN_START (C2_GPIO_PIN_BASE + 92)
+#define C2_GPIOX_PIN_END (C2_GPIO_PIN_BASE + 114)
#define C2_GPIOX_FSEL_REG_OFFSET 0x118
#define C2_GPIOX_OUTP_REG_OFFSET 0x119
@@ -39,14 +39,14 @@
#define C2_GPIODV_PUPD_REG_OFFSET 0x148
#define C2_GPIODV_PUEN_REG_OFFSET 0x13A
-#define MUX_REG_0_OFFSET 0x12C
-#define MUX_REG_1_OFFSET 0x12D
-#define MUX_REG_2_OFFSET 0x12E
-#define MUX_REG_3_OFFSET 0x12F
-#define MUX_REG_4_OFFSET 0x130
-#define MUX_REG_5_OFFSET 0x131
-#define MUX_REG_7_OFFSET 0x133
-#define MUX_REG_8_OFFSET 0x134
+#define C2_MUX_REG_0_OFFSET 0x12C
+#define C2_MUX_REG_1_OFFSET 0x12D
+#define C2_MUX_REG_2_OFFSET 0x12E
+#define C2_MUX_REG_3_OFFSET 0x12F
+#define C2_MUX_REG_4_OFFSET 0x130
+#define C2_MUX_REG_5_OFFSET 0x131
+#define C2_MUX_REG_7_OFFSET 0x133
+#define C2_MUX_REG_8_OFFSET 0x134
#ifdef __cplusplus
extern "C" {
diff --git a/wiringPi/odroidn1.c b/wiringPi/odroidn1.c
index 6af7dd9..d4f4b23 100755
--- a/wiringPi/odroidn1.c
+++ b/wiringPi/odroidn1.c
@@ -18,7 +18,11 @@
#include
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "softPwm.h"
+#include "softTone.h"
+
+/*----------------------------------------------------------------------------*/
+#include "wiringPi.h"
#include "odroidn1.h"
/*----------------------------------------------------------------------------*/
@@ -107,17 +111,17 @@ static void setClkState (int pin, int state);
static void setIomuxMode (int pin, int mode);
/*----------------------------------------------------------------------------*/
-// wiringPi core function
+// wiringPi core function
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin);
-static void pinMode (int pin, int mode);
-static int getAlt (int pin);
-static void pullUpDnControl (int pin, int pud);
-static int digitalRead (int pin);
-static void digitalWrite (int pin, int value);
-static int analogRead (int pin);
-static void digitalWriteByte(const int value);
-static unsigned int digitalReadByte (void);
+static int _getModeToGpio (int mode, int pin);
+static void _pinMode (int pin, int mode);
+static int _getAlt (int pin);
+static void _pullUpDnControl (int pin, int pud);
+static int _digitalRead (int pin);
+static void _digitalWrite (int pin, int value);
+static int _analogRead (int pin);
+static void _digitalWriteByte (const int value);
+static unsigned int _digitalReadByte (void);
/*----------------------------------------------------------------------------*/
// board init function
@@ -149,7 +153,7 @@ static int gpioToShiftGReg (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin)
+static int _getModeToGpio (int mode, int pin)
{
if (pin > 255)
return msg(MSG_ERR, "%s : Invalid pin number %d\n", __func__, pin);
@@ -187,26 +191,26 @@ static void setClkState (int pin, int state)
target |= (1 << (shift + 16));
switch (state) {
- case CLK_ENABLE:
+ case N1_CLK_ENABLE:
if (bank < 2) {
- target |= *(cru[0] + (PMUCRU_GPIO_CLK_OFFSET >> 2));
+ target |= *(cru[0] + (N1_PMUCRU_GPIO_CLK_OFFSET >> 2));
target &= ~(1 << shift);
- *(cru[0] + (PMUCRU_GPIO_CLK_OFFSET >> 2)) = target;
+ *(cru[0] + (N1_PMUCRU_GPIO_CLK_OFFSET >> 2)) = target;
} else {
- target |= *(cru[1] + (CRU_GPIO_CLK_OFFSET >> 2));
+ target |= *(cru[1] + (N1_CRU_GPIO_CLK_OFFSET >> 2));
target &= ~(1 << shift);
- *(cru[1] + (CRU_GPIO_CLK_OFFSET >> 2)) = target;
+ *(cru[1] + (N1_CRU_GPIO_CLK_OFFSET >> 2)) = target;
}
break;
- case CLK_DISABLE:
+ case N1_CLK_DISABLE:
if (bank < 2) {
- target |= *(cru[0] + (PMUCRU_GPIO_CLK_OFFSET >> 2));
+ target |= *(cru[0] + (N1_PMUCRU_GPIO_CLK_OFFSET >> 2));
target |= (1 << shift);
- *(cru[0] + (PMUCRU_GPIO_CLK_OFFSET >> 2)) = target;
+ *(cru[0] + (N1_PMUCRU_GPIO_CLK_OFFSET >> 2)) = target;
} else {
- target |= *(cru[1] + (CRU_GPIO_CLK_OFFSET >> 2));
+ target |= *(cru[1] + (N1_CRU_GPIO_CLK_OFFSET >> 2));
target |= (1 << shift);
- *(cru[1] + (CRU_GPIO_CLK_OFFSET >> 2)) = target;
+ *(cru[1] + (N1_CRU_GPIO_CLK_OFFSET >> 2)) = target;
}
break;
default:
@@ -233,10 +237,10 @@ static void setIomuxMode (int pin, int mode)
target |= (1 << (gpioToShiftGReg(pin) * 2 + 16));
switch (mode) {
- case FUNC_GPIO:
+ case N1_FUNC_GPIO:
// Common IOMUX Funtion 1 : GPIO (0b00)
if (bank < 2) {
- offset += PMUGRF_IOMUX_OFFSET;
+ offset += N1_PMUGRF_IOMUX_OFFSET;
target |= *(grf[0] + (offset >> 2));
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1));
@@ -244,7 +248,7 @@ static void setIomuxMode (int pin, int mode)
*(grf[0] + (offset >> 2)) = target;
} else {
- offset += GRF_IOMUX_OFFSET;
+ offset += N1_GRF_IOMUX_OFFSET;
target |= *(grf[1] + (offset >> 2));
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1));
@@ -259,7 +263,7 @@ static void setIomuxMode (int pin, int mode)
}
/*----------------------------------------------------------------------------*/
-static void pinMode (int pin, int mode)
+static void _pinMode (int pin, int mode)
{
int origPin, bank;
unsigned long flags;
@@ -267,7 +271,7 @@ static void pinMode (int pin, int mode)
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
origPin = pin;
@@ -276,15 +280,15 @@ static void pinMode (int pin, int mode)
softPwmStop (origPin);
softToneStop(origPin);
- setClkState (pin, CLK_ENABLE);
- setIomuxMode(pin, FUNC_GPIO);
+ setClkState (pin, N1_CLK_ENABLE);
+ setIomuxMode(pin, N1_FUNC_GPIO);
switch (mode) {
case INPUT:
- *(gpio[bank] + (GPIO_CON_OFFSET >> 2)) &= ~(1 << gpioToShiftReg(pin));
+ *(gpio[bank] + (N1_GPIO_CON_OFFSET >> 2)) &= ~(1 << gpioToShiftReg(pin));
break;
case OUTPUT:
- *(gpio[bank] + (GPIO_CON_OFFSET >> 2)) |= (1 << gpioToShiftReg(pin));
+ *(gpio[bank] + (N1_GPIO_CON_OFFSET >> 2)) |= (1 << gpioToShiftReg(pin));
break;
case SOFT_PWM_OUTPUT:
softPwmCreate (pin, 0, 100);
@@ -297,11 +301,11 @@ static void pinMode (int pin, int mode)
break;
}
- setClkState (pin, CLK_DISABLE);
+ setClkState (pin, N1_CLK_DISABLE);
}
/*----------------------------------------------------------------------------*/
-static int getAlt (int pin)
+static int _getAlt (int pin)
{
uint32_t offset;
uint8_t bank, group, shift;
@@ -310,7 +314,7 @@ static int getAlt (int pin)
if (lib->mode == MODE_GPIO_SYS)
return 0;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 2;
bank = pin / 32;
@@ -318,32 +322,32 @@ static int getAlt (int pin)
offset = 0x10 * (bank > 1 ? bank - 2 : bank) + 0x4 * group;
shift = gpioToShiftGReg(pin) << 1;
- setClkState(pin, CLK_ENABLE);
+ setClkState(pin, N1_CLK_ENABLE);
// Check if the pin is GPIO mode on GRF register
if (bank < 2) {
- offset += PMUGRF_IOMUX_OFFSET;
+ offset += N1_PMUGRF_IOMUX_OFFSET;
ret = (*(grf[0] + (offset >> 2)) >> shift) & 0b11;
} else {
- offset += GRF_IOMUX_OFFSET;
+ offset += N1_GRF_IOMUX_OFFSET;
ret = (*(grf[1] + (offset >> 2)) >> shift) & 0b11;
}
// If it is GPIO mode, check it's direction
if (ret == 0)
- ret = *(gpio[bank] + (GPIO_CON_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? 1 : 0;
+ ret = *(gpio[bank] + (N1_GPIO_CON_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? 1 : 0;
else {
// ALT1 is GPIO mode(0b00) on this SoC
ret++;
}
- setClkState(pin, CLK_DISABLE);
+ setClkState(pin, N1_CLK_DISABLE);
return ret;
}
/*----------------------------------------------------------------------------*/
-static void pullUpDnControl (int pin, int pud)
+static void _pullUpDnControl (int pin, int pud)
{
uint32_t offset, target;
uint8_t bank, group;
@@ -351,7 +355,7 @@ static void pullUpDnControl (int pin, int pud)
if (lib->mode == MODE_GPIO_SYS)
return 0;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 2;
bank = pin / 32;
@@ -362,12 +366,12 @@ static void pullUpDnControl (int pin, int pud)
target |= (1 << (gpioToShiftGReg(pin) * 2 + 17));
target |= (1 << (gpioToShiftGReg(pin) * 2 + 16));
- setClkState(pin, CLK_ENABLE);
+ setClkState(pin, N1_CLK_ENABLE);
switch (pud) {
case PUD_UP:
if (bank < 2) {
- offset += PMUGRF_PUPD_OFFSET;
+ offset += N1_PMUGRF_PUPD_OFFSET;
target |= *(grf[0] + (offset >> 2));
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1));
@@ -375,7 +379,7 @@ static void pullUpDnControl (int pin, int pud)
*(grf[0] + (offset >> 2)) = target;
} else {
- offset += GRF_PUPD_OFFSET;
+ offset += N1_GRF_PUPD_OFFSET;
target |= *(grf[1] + (offset >> 2));
if (bank == 2 && group >= 2) {
@@ -391,7 +395,7 @@ static void pullUpDnControl (int pin, int pud)
break;
case PUD_DOWN:
if (bank < 2) {
- offset += PMUGRF_PUPD_OFFSET;
+ offset += N1_PMUGRF_PUPD_OFFSET;
target |= *(grf[0] + (offset >> 2));
target |= (1 << (gpioToShiftGReg(pin) * 2 + 1));
@@ -399,7 +403,7 @@ static void pullUpDnControl (int pin, int pud)
*(grf[0] + (offset >> 2)) = target;
} else {
- offset += GRF_PUPD_OFFSET;
+ offset += N1_GRF_PUPD_OFFSET;
target |= *(grf[1] + (offset >> 2));
if (bank == 2 && group >= 2) {
@@ -415,7 +419,7 @@ static void pullUpDnControl (int pin, int pud)
break;
case PUD_OFF:
if (bank < 2) {
- offset += PMUGRF_PUPD_OFFSET;
+ offset += N1_PMUGRF_PUPD_OFFSET;
target |= *(grf[0] + (offset >> 2));
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1));
@@ -423,7 +427,7 @@ static void pullUpDnControl (int pin, int pud)
*(grf[0] + (offset >> 2)) = target;
} else {
- offset += GRF_PUPD_OFFSET;
+ offset += N1_GRF_PUPD_OFFSET;
target |= *(grf[1] + (offset >> 2));
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1));
@@ -436,11 +440,11 @@ static void pullUpDnControl (int pin, int pud)
break;
}
- setClkState(pin, CLK_DISABLE);
+ setClkState(pin, N1_CLK_DISABLE);
}
/*----------------------------------------------------------------------------*/
-static int digitalRead (int pin)
+static int _digitalRead (int pin)
{
int bank, ret;
char c;
@@ -455,20 +459,20 @@ static int digitalRead (int pin)
return (c == '0') ? LOW : HIGH;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 0;
bank = pin / 32;
- setClkState(pin, CLK_ENABLE);
+ setClkState(pin, N1_CLK_ENABLE);
- ret = *(gpio[bank] + (GPIO_GET_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW;
+ ret = *(gpio[bank] + (N1_GPIO_GET_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW;
- setClkState(pin, CLK_DISABLE);
+ setClkState(pin, N1_CLK_DISABLE);
return ret;
}
/*----------------------------------------------------------------------------*/
-static void digitalWrite (int pin, int value)
+static void _digitalWrite (int pin, int value)
{
int bank;
@@ -478,39 +482,39 @@ static void digitalWrite (int pin, int value)
if (write (lib->sysFds[pin], "0\n", 2) < 0)
msg(MSG_ERR,
"%s : %s\nEdit direction file to output mode for\n\t/sys/class/gpio/gpio%d/direction\n",
- __func__, strerror(errno), pin + GPIO_PIN_BASE);
+ __func__, strerror(errno), pin + N1_GPIO_PIN_BASE);
} else {
if (write (lib->sysFds[pin], "1\n", 2) < 0)
msg(MSG_ERR,
"%s : %s\nEdit direction file to output mode for\n\t/sys/class/gpio/gpio%d/direction\n",
- __func__, strerror(errno), pin + GPIO_PIN_BASE);
+ __func__, strerror(errno), pin + N1_GPIO_PIN_BASE);
}
}
return;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
bank = pin / 32;
- setClkState(pin, CLK_ENABLE);
+ setClkState(pin, N1_CLK_ENABLE);
switch (value) {
case LOW:
- *(gpio[bank] + (GPIO_SET_OFFSET >> 2)) &= ~(1 << gpioToShiftReg(pin));
+ *(gpio[bank] + (N1_GPIO_SET_OFFSET >> 2)) &= ~(1 << gpioToShiftReg(pin));
break;
case HIGH:
- *(gpio[bank] + (GPIO_SET_OFFSET >> 2)) |= (1 << gpioToShiftReg(pin));
+ *(gpio[bank] + (N1_GPIO_SET_OFFSET >> 2)) |= (1 << gpioToShiftReg(pin));
break;
default:
break;
}
- setClkState(pin, CLK_DISABLE);
+ setClkState(pin, N1_CLK_DISABLE);
}
/*----------------------------------------------------------------------------*/
-static int analogRead (int pin)
+static int _analogRead (int pin)
{
unsigned char value[5] = {0,};
@@ -538,7 +542,7 @@ static int analogRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWriteByte (const int value)
+static void _digitalWriteByte (const int value)
{
union reg_bitfield gpioBits1;
@@ -547,10 +551,10 @@ static void digitalWriteByte (const int value)
}
// Enable clock for GPIO 1 bank
- setClkState(32, CLK_ENABLE);
+ setClkState(32, N1_CLK_ENABLE);
/* Read data register */
- gpioBits1.wvalue = *(gpio[1] + (GPIO_GET_OFFSET >> 2));
+ gpioBits1.wvalue = *(gpio[1] + (N1_GPIO_GET_OFFSET >> 2));
/* Wiring PI GPIO0 = N1 GPIO1_A.1 */
gpioBits1.bits.bit1 = (value & 0x01);
@@ -570,13 +574,13 @@ static void digitalWriteByte (const int value)
gpioBits1.bits.bit0 = (value & 0x80);
/* Update data register */
- *(gpio[1] + (GPIO_SET_OFFSET >> 2)) = gpioBits1.wvalue;
+ *(gpio[1] + (N1_GPIO_SET_OFFSET >> 2)) = gpioBits1.wvalue;
- setClkState(32, CLK_DISABLE);
+ setClkState(32, N1_CLK_DISABLE);
}
/*----------------------------------------------------------------------------*/
-static unsigned int digitalReadByte (void)
+static unsigned int _digitalReadByte (void)
{
union reg_bitfield gpioBits1;
unsigned int value = 0;
@@ -586,12 +590,12 @@ static unsigned int digitalReadByte (void)
}
// Enable clock for GPIO 1 bank
- setClkState(32, CLK_ENABLE);
+ setClkState(32, N1_CLK_ENABLE);
/* Read data register */
- gpioBits1.wvalue = *(gpio[1] + (GPIO_GET_OFFSET >> 2));
+ gpioBits1.wvalue = *(gpio[1] + (N1_GPIO_GET_OFFSET >> 2));
- setClkState(32, CLK_DISABLE);
+ setClkState(32, N1_CLK_DISABLE);
/* Wiring PI GPIO0 = N1 GPIO1_A.1 */
if (gpioBits1.bits.bit1)
@@ -645,22 +649,22 @@ static void init_gpio_mmap (void)
// GPIO{0, 1}
//#define ODROIDN1_PMUCRU_BASE 0xFF750000
cru[0] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, PMUCRU_BASE) ;
+ MAP_SHARED, fd, N1_PMUCRU_BASE) ;
// GPIO{2, 3, 4}
//#define ODROIDN1_CRU_BASE 0xFF760000
cru[1] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, CRU_BASE) ;
+ MAP_SHARED, fd, N1_CRU_BASE) ;
// GPIO{0, 1}
//#define ODROIDN1_PMU_BASE 0xFF320000
- grf[0] = (uint32_t *)mmap(0, GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, PMUGRF_BASE) ;
+ grf[0] = (uint32_t *)mmap(0, N1_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd, N1_PMUGRF_BASE) ;
// GPIO{2, 3, 4}
//#define ODROIDN1_GRF_BASE 0xFF770000
- grf[1] = (uint32_t *)mmap(0, GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, GRF_BASE) ;
+ grf[1] = (uint32_t *)mmap(0, N1_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd, N1_GRF_BASE) ;
// GPIO1_A. 0,1,2,3,4,7
// GPIO1_B. 0,1,2,3,4,5
@@ -668,24 +672,24 @@ static void init_gpio_mmap (void)
// GPIO1_D. 0
//#define ODROIDN1_GPIO1_BASE 0xFF730000
gpio[1] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, GPIO_1_BASE) ;
+ MAP_SHARED, fd, N1_GPIO_1_BASE) ;
// GPIO2_C. 0_B,1_B
//#define ODROIDN1_GPIO2_BASE 0xFF780000
gpio[2] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, GPIO_2_BASE) ;
+ MAP_SHARED, fd, N1_GPIO_2_BASE) ;
// GPIO4_C. 5,6
// GPIO4_D. 0,4,5,6
//#define ODROIDN1_GPIO4_BASE 0xFF790000
gpio[4] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, GPIO_4_BASE) ;
+ MAP_SHARED, fd, N1_GPIO_4_BASE) ;
// Reserved
gpio[0] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, GPIO_0_BASE) ;
+ MAP_SHARED, fd, N1_GPIO_0_BASE) ;
gpio[3] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, GPIO_3_BASE) ;
+ MAP_SHARED, fd, N1_GPIO_3_BASE) ;
if (((int32_t)cru[0] == -1) || ((int32_t)cru[1] == -1)) {
return msg (MSG_ERR,
@@ -734,18 +738,18 @@ void init_odroidn1 (struct libodroid *libwiring)
init_adc_fds();
/* wiringPi Core function initialize */
- libwiring->getModeToGpio = getModeToGpio;
- libwiring->pinMode = pinMode;
- libwiring->getAlt = getAlt;
- libwiring->pullUpDnControl = pullUpDnControl;
- libwiring->digitalRead = digitalRead;
- libwiring->digitalWrite = digitalWrite;
- libwiring->analogRead = analogRead;
- libwiring->digitalWriteByte = digitalWriteByte;
- libwiring->digitalReadByte = digitalReadByte;
+ libwiring->getModeToGpio = _getModeToGpio;
+ libwiring->pinMode = _pinMode;
+ libwiring->getAlt = _getAlt;
+ libwiring->pullUpDnControl = _pullUpDnControl;
+ libwiring->digitalRead = _digitalRead;
+ libwiring->digitalWrite = _digitalWrite;
+ libwiring->analogRead = _analogRead;
+ libwiring->digitalWriteByte = _digitalWriteByte;
+ libwiring->digitalReadByte = _digitalReadByte;
/* specify pin base number */
- libwiring->pinBase = GPIO_PIN_BASE;
+ libwiring->pinBase = N1_GPIO_PIN_BASE;
/* global variable setup */
lib = libwiring;
diff --git a/wiringPi/odroidn1.h b/wiringPi/odroidn1.h
index 46771ce..7c03854 100755
--- a/wiringPi/odroidn1.h
+++ b/wiringPi/odroidn1.h
@@ -10,56 +10,56 @@
/*----------------------------------------------------------------------------*/
// Common mmap block size for ODROID-N1 GRF register
-#define GRF_BLOCK_SIZE 0xF000
+#define N1_GRF_BLOCK_SIZE 0xF000
// Common offset for GPIO registers from each GPIO bank's base address
-#define GPIO_CON_OFFSET 0x04 // GPIO_SWPORTA_DDR
-#define GPIO_SET_OFFSET 0x00 // GPIO_SWPORTA_DR
-#define GPIO_GET_OFFSET 0x50 // GPIO_EXT_PORTA
+#define N1_GPIO_CON_OFFSET 0x04 // GPIO_SWPORTA_DDR
+#define N1_GPIO_SET_OFFSET 0x00 // GPIO_SWPORTA_DR
+#define N1_GPIO_GET_OFFSET 0x50 // GPIO_EXT_PORTA
-#define FUNC_GPIO 0b00 // Bit for IOMUX GPIO mode
+#define N1_FUNC_GPIO 0b00 // Bit for IOMUX GPIO mode
// GPIO{0, 1}
-#define PMUGRF_BASE 0xFF320000
-#define PMUGRF_IOMUX_OFFSET 0x0000 // GRF_GPIO0A_IOMUX
-#define PMUGRF_PUPD_OFFSET 0x0040 // PMUGRF_GPIO0A_P
+#define N1_PMUGRF_BASE 0xFF320000
+#define N1_PMUGRF_IOMUX_OFFSET 0x0000 // GRF_GPIO0A_IOMUX
+#define N1_PMUGRF_PUPD_OFFSET 0x0040 // PMUGRF_GPIO0A_P
// GPIO{2, 3, 4}
-#define GRF_BASE 0xFF770000
-#define GRF_IOMUX_OFFSET 0xE000 // GRF_GPIO2A_IOMUX
-#define GRF_PUPD_OFFSET 0xE040 // GRF_GPIO2A_P
+#define N1_GRF_BASE 0xFF770000
+#define N1_GRF_IOMUX_OFFSET 0xE000 // GRF_GPIO2A_IOMUX
+#define N1_GRF_PUPD_OFFSET 0xE040 // GRF_GPIO2A_P
// Offset to control GPIO clock
// Make 31:16 bit HIGH to enable the writing corresponding bit
-#define PMUCRU_BASE 0xFF750000
-#define PMUCRU_GPIO_CLK_OFFSET 0x0104 // PMUCRU_CLKGATE_CON1
+#define N1_PMUCRU_BASE 0xFF750000
+#define N1_PMUCRU_GPIO_CLK_OFFSET 0x0104 // PMUCRU_CLKGATE_CON1
-#define CRU_BASE 0xFF760000
-#define CRU_GPIO_CLK_OFFSET 0x037C // CRU_CLKGATE_CON31
+#define N1_CRU_BASE 0xFF760000
+#define N1_CRU_GPIO_CLK_OFFSET 0x037C // CRU_CLKGATE_CON31
-#define CLK_ENABLE 0b0
-#define CLK_DISABLE 0b1
+#define N1_CLK_ENABLE 0b0
+#define N1_CLK_DISABLE 0b1
// Only for Linux kernel for now. Edit to 0 for Android
-#define GPIO_PIN_BASE 1000
+#define N1_GPIO_PIN_BASE 1000
// GPIO1_A. 0,1,2,3,4,7
// GPIO1_B. 0,1,2,3,4,5
// GPIO1_C. 2,4,5,6
// GPIO1_D. 0
-#define GPIO_1_BASE 0xFF730000
+#define N1_GPIO_1_BASE 0xFF730000
// GPIO2_C. 0_B,1_B
-#define GPIO_2_BASE 0xFF780000
+#define N1_GPIO_2_BASE 0xFF780000
// GPIO4_C. 5,6
// GPIO4_D. 0,4,5,6
-#define GPIO_4_BASE 0xFF790000
+#define N1_GPIO_4_BASE 0xFF790000
// Reserved
// GPIO{0, 3}
-#define GPIO_0_BASE 0xFF720000
-#define GPIO_3_BASE 0xFF788000
+#define N1_GPIO_0_BASE 0xFF720000
+#define N1_GPIO_3_BASE 0xFF788000
#ifdef __cplusplus
extern "C" {
diff --git a/wiringPi/odroidn2.c b/wiringPi/odroidn2.c
index 713b00a..c940f28 100755
--- a/wiringPi/odroidn2.c
+++ b/wiringPi/odroidn2.c
@@ -21,7 +21,11 @@
#include "softTone.h"
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "softPwm.h"
+#include "softTone.h"
+
+/*----------------------------------------------------------------------------*/
+#include "wiringPi.h"
#include "odroidn2.h"
/*----------------------------------------------------------------------------*/
@@ -112,18 +116,18 @@ static int gpioToMuxReg (int pin);
/*----------------------------------------------------------------------------*/
// wiringPi core function
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin);
-static void setPadDrive (int pin, int value);
-static int getPadDrive (int pin);
-static void pinMode (int pin, int mode);
-static int getAlt (int pin);
-static int getPUPD (int pin);
-static void pullUpDnControl (int pin, int pud);
-static int digitalRead (int pin);
-static void digitalWrite (int pin, int value);
-static int analogRead (int pin);
-static void digitalWriteByte(const int value);
-static unsigned int digitalReadByte (void);
+static int _getModeToGpio (int mode, int pin);
+static void _setPadDrive (int pin, int value);
+static int _getPadDrive (int pin);
+static void _pinMode (int pin, int mode);
+static int _getAlt (int pin);
+static int _getPUPD (int pin);
+static void _pullUpDnControl (int pin, int pud);
+static int _digitalRead (int pin);
+static void _digitalWrite (int pin, int value);
+static int _analogRead (int pin);
+static void _digitalWriteByte (const int value);
+static unsigned int _digitalReadByte (void);
/*----------------------------------------------------------------------------*/
// board init function
@@ -258,7 +262,7 @@ static int gpioToMuxReg (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin)
+static int _getModeToGpio (int mode, int pin)
{
int retPin = -1;
@@ -288,14 +292,14 @@ static int getModeToGpio (int mode, int pin)
}
/*----------------------------------------------------------------------------*/
-static void setPadDrive (int pin, int value)
+static void _setPadDrive (int pin, int value)
{
int ds, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
if (value < 0 || value > 3) {
@@ -312,14 +316,14 @@ static void setPadDrive (int pin, int value)
}
/*----------------------------------------------------------------------------*/
-static int getPadDrive (int pin)
+static int _getPadDrive (int pin)
{
int ds, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
ds = gpioToDSReg(pin);
@@ -330,14 +334,14 @@ static int getPadDrive (int pin)
}
/*----------------------------------------------------------------------------*/
-static void pinMode (int pin, int mode)
+static void _pinMode (int pin, int mode)
{
int fsel, shift, origPin = pin;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
softPwmStop (origPin);
@@ -366,14 +370,14 @@ static void pinMode (int pin, int mode)
}
/*----------------------------------------------------------------------------*/
-static int getAlt (int pin)
+static int _getAlt (int pin)
{
int fsel, mux, shift, target, mode;
if (lib->mode == MODE_GPIO_SYS)
return 0;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 2;
fsel = gpioToGPFSELReg(pin);
@@ -389,14 +393,14 @@ static int getAlt (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getPUPD (int pin)
+static int _getPUPD (int pin)
{
int puen, pupd, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
puen = gpioToPUENReg(pin);
@@ -410,14 +414,14 @@ static int getPUPD (int pin)
}
/*----------------------------------------------------------------------------*/
-static void pullUpDnControl (int pin, int pud)
+static void _pullUpDnControl (int pin, int pud)
{
int shift = 0;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
shift = gpioToShiftReg(pin);
@@ -439,7 +443,7 @@ static void pullUpDnControl (int pin, int pud)
}
/*----------------------------------------------------------------------------*/
-static int digitalRead (int pin)
+static int _digitalRead (int pin)
{
char c ;
@@ -453,7 +457,7 @@ static int digitalRead (int pin)
return (c == '0') ? LOW : HIGH;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 0;
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
@@ -463,7 +467,7 @@ static int digitalRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWrite (int pin, int value)
+static void _digitalWrite (int pin, int value)
{
if (lib->mode == MODE_GPIO_SYS) {
if (lib->sysFds[pin] != -1) {
@@ -475,7 +479,7 @@ static void digitalWrite (int pin, int value)
return;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
if (value == LOW)
@@ -485,7 +489,7 @@ static void digitalWrite (int pin, int value)
}
/*----------------------------------------------------------------------------*/
-static int analogRead (int pin)
+static int _analogRead (int pin)
{
unsigned char value[5] = {0,};
@@ -513,7 +517,7 @@ static int analogRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWriteByte (const int value)
+static void _digitalWriteByte (const int value)
{
union reg_bitfield gpiox;
union reg_bitfield gpioa;
@@ -543,7 +547,7 @@ static void digitalWriteByte (const int value)
}
/*----------------------------------------------------------------------------*/
-static unsigned int digitalReadByte (void)
+static unsigned int _digitalReadByte (void)
{
return -1;
}
@@ -569,9 +573,9 @@ static void init_gpio_mmap (void)
"wiringPiSetup: Unable to open /dev/mem: %s\n",
strerror (errno)) ;
}
- //#define ODROIDN2_GPIO_BASE 0xff634000
+ //#define N2_GPIO_BASE 0xff634000
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, ODROIDN2_GPIO_BASE) ;
+ MAP_SHARED, fd, N2_GPIO_BASE) ;
if ((int32_t)gpio == -1)
return msg (MSG_ERR,
@@ -603,21 +607,21 @@ void init_odroidn2 (struct libodroid *libwiring)
phyToGpio = phyToGpio_rev1;
/* wiringPi Core function initialize */
- libwiring->getModeToGpio = getModeToGpio;
- libwiring->setPadDrive = setPadDrive;
- libwiring->getPadDrive = getPadDrive;
- libwiring->pinMode = pinMode;
- libwiring->getAlt = getAlt;
- libwiring->getPUPD = getPUPD;
- libwiring->pullUpDnControl = pullUpDnControl;
- libwiring->digitalRead = digitalRead;
- libwiring->digitalWrite = digitalWrite;
- libwiring->analogRead = analogRead;
- libwiring->digitalWriteByte = digitalWriteByte;
- libwiring->digitalReadByte = digitalReadByte;
+ libwiring->getModeToGpio = _getModeToGpio;
+ libwiring->setPadDrive = _setPadDrive;
+ libwiring->getPadDrive = _getPadDrive;
+ libwiring->pinMode = _pinMode;
+ libwiring->getAlt = _getAlt;
+ libwiring->getPUPD = _getPUPD;
+ libwiring->pullUpDnControl = _pullUpDnControl;
+ libwiring->digitalRead = _digitalRead;
+ libwiring->digitalWrite = _digitalWrite;
+ libwiring->analogRead = _analogRead;
+ libwiring->digitalWriteByte = _digitalWriteByte;
+ libwiring->digitalReadByte = _digitalReadByte;
/* specify pin base number */
- libwiring->pinBase = GPIO_PIN_BASE;
+ libwiring->pinBase = N2_GPIO_PIN_BASE;
/* global variable setup */
lib = libwiring;
diff --git a/wiringPi/odroidn2.h b/wiringPi/odroidn2.h
index a6cff9c..c584092 100755
--- a/wiringPi/odroidn2.h
+++ b/wiringPi/odroidn2.h
@@ -9,16 +9,16 @@
#define __ODROID_N2_H__
/*----------------------------------------------------------------------------*/
-#define ODROIDN2_GPIO_MASK (0xFFFFFF00)
-#define ODROIDN2_GPIO_BASE 0xff634000
+#define N2_GPIO_MASK (0xFFFFFF00)
+#define N2_GPIO_BASE 0xff634000
-#define GPIO_PIN_BASE 410
+#define N2_GPIO_PIN_BASE 410
-#define N2_GPIOA_PIN_START (GPIO_PIN_BASE + 50) // GPIOA_0
-#define N2_GPIOA_PIN_END (GPIO_PIN_BASE + 65) // GPIOA_15
-#define N2_GPIOX_PIN_START (GPIO_PIN_BASE + 66) // GPIOX_0
-#define N2_GPIOX_PIN_MID (GPIO_PIN_BASE + 81) // GPIOX_15
-#define N2_GPIOX_PIN_END (GPIO_PIN_BASE + 85) // GPIOX_19
+#define N2_GPIOA_PIN_START (N2_GPIO_PIN_BASE + 50) // GPIOA_0
+#define N2_GPIOA_PIN_END (N2_GPIO_PIN_BASE + 65) // GPIOA_15
+#define N2_GPIOX_PIN_START (N2_GPIO_PIN_BASE + 66) // GPIOX_0
+#define N2_GPIOX_PIN_MID (N2_GPIO_PIN_BASE + 81) // GPIOX_15
+#define N2_GPIOX_PIN_END (N2_GPIO_PIN_BASE + 85) // GPIOX_19
#define N2_GPIOX_FSEL_REG_OFFSET 0x116
#define N2_GPIOX_OUTP_REG_OFFSET 0x117
diff --git a/wiringPi/odroidxu3.c b/wiringPi/odroidxu3.c
index 9ba92af..1b6bf5e 100755
--- a/wiringPi/odroidxu3.c
+++ b/wiringPi/odroidxu3.c
@@ -18,7 +18,11 @@
#include
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "softPwm.h"
+#include "softTone.h"
+
+/*----------------------------------------------------------------------------*/
+#include "wiringPi.h"
#include "odroidxu3.h"
/*----------------------------------------------------------------------------*/
@@ -103,20 +107,20 @@ static int gpioToGPFSELReg (int pin);
static int gpioToDSReg (int pin);
/*----------------------------------------------------------------------------*/
-// wiringPi core function
+// wiringPi core function
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin);
-static void setPadDrive (int pin, int value);
-static int getPadDrive (int pin);
-static void pinMode (int pin, int mode);
-static int getAlt (int pin);
-static int getPUPD (int pin);
-static void pullUpDnControl (int pin, int pud);
-static int digitalRead (int pin);
-static void digitalWrite (int pin, int value);
-static int analogRead (int pin);
-static void digitalWriteByte(const int value);
-static unsigned int digitalReadByte (void);
+static int _getModeToGpio (int mode, int pin);
+static void _setPadDrive (int pin, int value);
+static int _getPadDrive (int pin);
+static void _pinMode (int pin, int mode);
+static int _getAlt (int pin);
+static int _getPUPD (int pin);
+static void _pullUpDnControl (int pin, int pud);
+static int _digitalRead (int pin);
+static void _digitalWrite (int pin, int value);
+static int _analogRead (int pin);
+static void _digitalWriteByte (const int value);
+static unsigned int _digitalReadByte (void);
/*----------------------------------------------------------------------------*/
// board init function
@@ -134,18 +138,18 @@ static void init_adc_fds (void);
static int gpioToGPSETReg (int pin)
{
switch (pin) {
- case GPIO_X1_START...GPIO_X1_END:
- return (GPIO_X1_DAT_OFFSET >> 2);
- case GPIO_X2_START...GPIO_X2_END:
- return (GPIO_X2_DAT_OFFSET >> 2);
- case GPIO_X3_START...GPIO_X3_END:
- return (GPIO_X3_DAT_OFFSET >> 2);
- case GPIO_A0_START...GPIO_A0_END:
- return (GPIO_A0_DAT_OFFSET >> 2);
- case GPIO_A2_START...GPIO_A2_END:
- return (GPIO_A2_DAT_OFFSET >> 2);
- case GPIO_B3_START...GPIO_B3_END:
- return (GPIO_B3_DAT_OFFSET >> 2);
+ case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
+ return (XU3_GPIO_X1_DAT_OFFSET >> 2);
+ case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
+ return (XU3_GPIO_X2_DAT_OFFSET >> 2);
+ case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
+ return (XU3_GPIO_X3_DAT_OFFSET >> 2);
+ case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
+ return (XU3_GPIO_A0_DAT_OFFSET >> 2);
+ case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
+ return (XU3_GPIO_A2_DAT_OFFSET >> 2);
+ case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
+ return (XU3_GPIO_B3_DAT_OFFSET >> 2);
default:
break;
}
@@ -160,18 +164,18 @@ static int gpioToGPSETReg (int pin)
static int gpioToGPLEVReg (int pin)
{
switch (pin) {
- case GPIO_X1_START...GPIO_X1_END:
- return (GPIO_X1_DAT_OFFSET >> 2);
- case GPIO_X2_START...GPIO_X2_END:
- return (GPIO_X2_DAT_OFFSET >> 2);
- case GPIO_X3_START...GPIO_X3_END:
- return (GPIO_X3_DAT_OFFSET >> 2);
- case GPIO_A0_START...GPIO_A0_END:
- return (GPIO_A0_DAT_OFFSET >> 2);
- case GPIO_A2_START...GPIO_A2_END:
- return (GPIO_A2_DAT_OFFSET >> 2);
- case GPIO_B3_START...GPIO_B3_END:
- return (GPIO_B3_DAT_OFFSET >> 2);
+ case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
+ return (XU3_GPIO_X1_DAT_OFFSET >> 2);
+ case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
+ return (XU3_GPIO_X2_DAT_OFFSET >> 2);
+ case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
+ return (XU3_GPIO_X3_DAT_OFFSET >> 2);
+ case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
+ return (XU3_GPIO_A0_DAT_OFFSET >> 2);
+ case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
+ return (XU3_GPIO_A2_DAT_OFFSET >> 2);
+ case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
+ return (XU3_GPIO_B3_DAT_OFFSET >> 2);
default:
break;
}
@@ -186,18 +190,18 @@ static int gpioToGPLEVReg (int pin)
static int gpioToPUPDReg (int pin)
{
switch (pin) {
- case GPIO_X1_START...GPIO_X1_END:
- return (GPIO_X1_PUD_OFFSET >> 2);
- case GPIO_X2_START...GPIO_X2_END:
- return (GPIO_X2_PUD_OFFSET >> 2);
- case GPIO_X3_START...GPIO_X3_END:
- return (GPIO_X3_PUD_OFFSET >> 2);
- case GPIO_A0_START...GPIO_A0_END:
- return (GPIO_A0_PUD_OFFSET >> 2);
- case GPIO_A2_START...GPIO_A2_END:
- return (GPIO_A2_PUD_OFFSET >> 2);
- case GPIO_B3_START...GPIO_B3_END:
- return (GPIO_B3_PUD_OFFSET >> 2);
+ case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
+ return (XU3_GPIO_X1_PUD_OFFSET >> 2);
+ case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
+ return (XU3_GPIO_X2_PUD_OFFSET >> 2);
+ case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
+ return (XU3_GPIO_X3_PUD_OFFSET >> 2);
+ case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
+ return (XU3_GPIO_A0_PUD_OFFSET >> 2);
+ case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
+ return (XU3_GPIO_A2_PUD_OFFSET >> 2);
+ case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
+ return (XU3_GPIO_B3_PUD_OFFSET >> 2);
default:
break;
}
@@ -212,18 +216,18 @@ static int gpioToPUPDReg (int pin)
static int gpioToShiftReg (int pin)
{
switch (pin) {
- case GPIO_X1_START...GPIO_X1_END:
- return (pin - GPIO_X1_START);
- case GPIO_X2_START...GPIO_X2_END:
- return (pin - GPIO_X2_START);
- case GPIO_X3_START...GPIO_X3_END:
- return (pin - GPIO_X3_START);
- case GPIO_A0_START...GPIO_A0_END:
- return (pin - GPIO_A0_START);
- case GPIO_A2_START...GPIO_A2_END:
- return (pin - GPIO_A2_START);
- case GPIO_B3_START...GPIO_B3_END:
- return (pin - GPIO_B3_START);
+ case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
+ return (pin - XU3_GPIO_X1_START);
+ case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
+ return (pin - XU3_GPIO_X2_START);
+ case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
+ return (pin - XU3_GPIO_X3_START);
+ case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
+ return (pin - XU3_GPIO_A0_START);
+ case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
+ return (pin - XU3_GPIO_A2_START);
+ case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
+ return (pin - XU3_GPIO_B3_START);
default:
break;
}
@@ -238,18 +242,18 @@ static int gpioToShiftReg (int pin)
static int gpioToGPFSELReg (int pin)
{
switch (pin) {
- case GPIO_X1_START...GPIO_X1_END:
- return (GPIO_X1_CON_OFFSET >> 2);
- case GPIO_X2_START...GPIO_X2_END:
- return (GPIO_X2_CON_OFFSET >> 2);
- case GPIO_X3_START...GPIO_X3_END:
- return (GPIO_X3_CON_OFFSET >> 2);
- case GPIO_A0_START...GPIO_A0_END:
- return (GPIO_A0_CON_OFFSET >> 2);
- case GPIO_A2_START...GPIO_A2_END:
- return (GPIO_A2_CON_OFFSET >> 2);
- case GPIO_B3_START...GPIO_B3_END:
- return (GPIO_B3_CON_OFFSET >> 2);
+ case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
+ return (XU3_GPIO_X1_CON_OFFSET >> 2);
+ case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
+ return (XU3_GPIO_X2_CON_OFFSET >> 2);
+ case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
+ return (XU3_GPIO_X3_CON_OFFSET >> 2);
+ case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
+ return (XU3_GPIO_A0_CON_OFFSET >> 2);
+ case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
+ return (XU3_GPIO_A2_CON_OFFSET >> 2);
+ case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
+ return (XU3_GPIO_B3_CON_OFFSET >> 2);
default:
break;
}
@@ -264,18 +268,18 @@ static int gpioToGPFSELReg (int pin)
static int gpioToDSReg (int pin)
{
switch (pin) {
- case GPIO_X1_START...GPIO_X1_END:
- return (GPIO_X1_DRV_OFFSET >> 2);
- case GPIO_X2_START...GPIO_X2_END:
- return (GPIO_X2_DRV_OFFSET >> 2);
- case GPIO_X3_START...GPIO_X3_END:
- return (GPIO_X3_DRV_OFFSET >> 2);
- case GPIO_A0_START...GPIO_A0_END:
- return (GPIO_A0_DRV_OFFSET >> 2);
- case GPIO_A2_START...GPIO_A2_END:
- return (GPIO_A2_DRV_OFFSET >> 2);
- case GPIO_B3_START...GPIO_B3_END:
- return (GPIO_B3_DRV_OFFSET >> 2);
+ case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
+ return (XU3_GPIO_X1_DRV_OFFSET >> 2);
+ case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
+ return (XU3_GPIO_X2_DRV_OFFSET >> 2);
+ case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
+ return (XU3_GPIO_X3_DRV_OFFSET >> 2);
+ case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
+ return (XU3_GPIO_A0_DRV_OFFSET >> 2);
+ case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
+ return (XU3_GPIO_A2_DRV_OFFSET >> 2);
+ case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
+ return (XU3_GPIO_B3_DRV_OFFSET >> 2);
default:
break;
}
@@ -283,7 +287,7 @@ static int gpioToDSReg (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getModeToGpio (int mode, int pin)
+static int _getModeToGpio (int mode, int pin)
{
switch (mode) {
/* Native gpio number */
@@ -306,14 +310,14 @@ static int getModeToGpio (int mode, int pin)
}
/*----------------------------------------------------------------------------*/
-static void setPadDrive (int pin, int value)
+static void _setPadDrive (int pin, int value)
{
int ds, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
if (value < 0 || value > 3) {
@@ -334,14 +338,14 @@ static void setPadDrive (int pin, int value)
}
/*----------------------------------------------------------------------------*/
-static int getPadDrive (int pin)
+static int _getPadDrive (int pin)
{
int ds, shift;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
ds = gpioToDSReg(pin);
@@ -354,14 +358,14 @@ static int getPadDrive (int pin)
}
/*----------------------------------------------------------------------------*/
-static void pinMode (int pin, int mode)
+static void _pinMode (int pin, int mode)
{
int fsel, shift, origPin = pin;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
softPwmStop (origPin);
@@ -399,14 +403,14 @@ static void pinMode (int pin, int mode)
}
/*----------------------------------------------------------------------------*/
-static int getAlt (int pin)
+static int _getAlt (int pin)
{
int fsel, shift, mode;
if (lib->mode == MODE_GPIO_SYS)
return 0;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 2;
fsel = gpioToGPFSELReg(pin);
@@ -422,14 +426,14 @@ static int getAlt (int pin)
}
/*----------------------------------------------------------------------------*/
-static int getPUPD (int pin)
+static int _getPUPD (int pin)
{
int pupd, shift, pull;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
pupd = gpioToPUPDReg(pin);
@@ -445,14 +449,14 @@ static int getPUPD (int pin)
}
/*----------------------------------------------------------------------------*/
-static void pullUpDnControl (int pin, int pud)
+static void _pullUpDnControl (int pin, int pud)
{
int shift = 0;
if (lib->mode == MODE_GPIO_SYS)
return;
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
shift = gpioToShiftReg(pin) << 1;
@@ -481,7 +485,7 @@ static void pullUpDnControl (int pin, int pud)
}
/*----------------------------------------------------------------------------*/
-static int digitalRead (int pin)
+static int _digitalRead (int pin)
{
char c ;
@@ -495,7 +499,7 @@ static int digitalRead (int pin)
return (c == '0') ? LOW : HIGH;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return 0;
if (pin < 100)
@@ -505,7 +509,7 @@ static int digitalRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWrite (int pin, int value)
+static void _digitalWrite (int pin, int value)
{
if (lib->mode == MODE_GPIO_SYS) {
if (lib->sysFds[pin] != -1) {
@@ -517,7 +521,7 @@ static void digitalWrite (int pin, int value)
return;
}
- if ((pin = getModeToGpio(lib->mode, pin)) < 0)
+ if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
return;
if (pin < 100) {
@@ -534,7 +538,7 @@ static void digitalWrite (int pin, int value)
}
/*----------------------------------------------------------------------------*/
-static int analogRead (int pin)
+static int _analogRead (int pin)
{
unsigned char value[5] = {0,};
@@ -562,7 +566,7 @@ static int analogRead (int pin)
}
/*----------------------------------------------------------------------------*/
-static void digitalWriteByte (const int value)
+static void _digitalWriteByte (const int value)
{
union reg_bitfield gpx1, gpx2, gpa0;
@@ -570,9 +574,9 @@ static void digitalWriteByte (const int value)
return;
}
/* Read data register */
- gpx1.wvalue = *(gpio + (GPIO_X1_DAT_OFFSET >> 2));
- gpx2.wvalue = *(gpio + (GPIO_X2_DAT_OFFSET >> 2));
- gpa0.wvalue = *(gpio1 + (GPIO_A0_DAT_OFFSET >> 2));
+ gpx1.wvalue = *(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2));
+ gpx2.wvalue = *(gpio + (XU3_GPIO_X2_DAT_OFFSET >> 2));
+ gpa0.wvalue = *(gpio1 + (XU3_GPIO_A0_DAT_OFFSET >> 2));
/* Wiring PI GPIO0 = XU3/4 GPA0.3 */
gpa0.bits.bit3 = (value & 0x01);
@@ -592,13 +596,13 @@ static void digitalWriteByte (const int value)
gpx1.bits.bit2 = (value & 0x80);
/* update data register */
- *(gpio + (GPIO_X1_DAT_OFFSET >> 2)) = gpx1.wvalue;
- *(gpio + (GPIO_X2_DAT_OFFSET >> 2)) = gpx2.wvalue;
- *(gpio1 + (GPIO_A0_DAT_OFFSET >> 2)) = gpa0.wvalue;
+ *(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2)) = gpx1.wvalue;
+ *(gpio + (XU3_GPIO_X2_DAT_OFFSET >> 2)) = gpx2.wvalue;
+ *(gpio1 + (XU3_GPIO_A0_DAT_OFFSET >> 2)) = gpa0.wvalue;
}
/*----------------------------------------------------------------------------*/
-static unsigned int digitalReadByte (void)
+static unsigned int _digitalReadByte (void)
{
union reg_bitfield gpx1, gpx2, gpa0;
unsigned int value = 0;
@@ -607,9 +611,9 @@ static unsigned int digitalReadByte (void)
return -1;
}
/* Read data register */
- gpx1.wvalue = *(gpio + (GPIO_X1_DAT_OFFSET >> 2));
- gpx2.wvalue = *(gpio + (GPIO_X2_DAT_OFFSET >> 2));
- gpa0.wvalue = *(gpio1 + (GPIO_A0_DAT_OFFSET >> 2));
+ gpx1.wvalue = *(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2));
+ gpx2.wvalue = *(gpio + (XU3_GPIO_X2_DAT_OFFSET >> 2));
+ gpa0.wvalue = *(gpio1 + (XU3_GPIO_A0_DAT_OFFSET >> 2));
/* Wiring PI GPIO0 = XU3/4 GPA0.3 */
if (gpa0.bits.bit3)
@@ -662,10 +666,10 @@ static void init_gpio_mmap (void)
}
//#define ODROIDXU_GPX_BASE 0x13400000 // GPX0,1,2,3
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, ODROIDXU3_GPX_BASE) ;
+ MAP_SHARED, fd, XU3_GPX_BASE) ;
//#define ODROIDXU_GPA_BASE 0x14010000 // GPA0,1,2, GPB0,1,2,3,4
gpio1 = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, ODROIDXU3_GPA_BASE) ;
+ MAP_SHARED, fd, XU3_GPA_BASE) ;
if (((int32_t)gpio == -1) || ((int32_t)gpio1 == -1))
return msg (MSG_ERR,
"wiringPiSetup: mmap (GPIO) failed: %s\n",
@@ -702,21 +706,21 @@ void init_odroidxu3 (struct libodroid *libwiring)
init_adc_fds();
/* wiringPi Core function initialize */
- libwiring->getModeToGpio = getModeToGpio;
- libwiring->setPadDrive = setPadDrive;
- libwiring->getPadDrive = getPadDrive;
- libwiring->pinMode = pinMode;
- libwiring->getAlt = getAlt;
- libwiring->getPUPD = getPUPD;
- libwiring->pullUpDnControl = pullUpDnControl;
- libwiring->digitalRead = digitalRead;
- libwiring->digitalWrite = digitalWrite;
- libwiring->analogRead = analogRead;
- libwiring->digitalWriteByte = digitalWriteByte;
- libwiring->digitalReadByte = digitalReadByte;
+ libwiring->getModeToGpio = _getModeToGpio;
+ libwiring->setPadDrive = _setPadDrive;
+ libwiring->getPadDrive = _getPadDrive;
+ libwiring->pinMode = _pinMode;
+ libwiring->getAlt = _getAlt;
+ libwiring->getPUPD = _getPUPD;
+ libwiring->pullUpDnControl = _pullUpDnControl;
+ libwiring->digitalRead = _digitalRead;
+ libwiring->digitalWrite = _digitalWrite;
+ libwiring->analogRead = _analogRead;
+ libwiring->digitalWriteByte = _digitalWriteByte;
+ libwiring->digitalReadByte = _digitalReadByte;
/* specify pin base number */
- libwiring->pinBase = GPIO_PIN_BASE;
+ libwiring->pinBase = XU3_GPIO_PIN_BASE;
/* global variable setup */
lib = libwiring;
diff --git a/wiringPi/odroidxu3.h b/wiringPi/odroidxu3.h
index 020e774..a5b52e4 100755
--- a/wiringPi/odroidxu3.h
+++ b/wiringPi/odroidxu3.h
@@ -9,57 +9,57 @@
#define __ODROID_XU3_H__
/*----------------------------------------------------------------------------*/
-#define ODROIDXU3_GPIO_MASK (0xFFFFFF00)
+#define XU3_GPIO_MASK (0xFFFFFF00)
-#define GPIO_PIN_BASE 0
+#define XU3_GPIO_PIN_BASE 0
// GPX0,1,2,3
-#define ODROIDXU3_GPX_BASE 0x13400000
+#define XU3_GPX_BASE 0x13400000
-#define GPIO_X1_START 16
-#define GPIO_X1_CON_OFFSET 0x0C20
-#define GPIO_X1_DAT_OFFSET 0x0C24
-#define GPIO_X1_PUD_OFFSET 0x0C28
-#define GPIO_X1_DRV_OFFSET 0x0C2C
-#define GPIO_X1_END 23
+#define XU3_GPIO_X1_START 16
+#define XU3_GPIO_X1_CON_OFFSET 0x0C20
+#define XU3_GPIO_X1_DAT_OFFSET 0x0C24
+#define XU3_GPIO_X1_PUD_OFFSET 0x0C28
+#define XU3_GPIO_X1_DRV_OFFSET 0x0C2C
+#define XU3_GPIO_X1_END 23
-#define GPIO_X2_START 24
-#define GPIO_X2_CON_OFFSET 0x0C40
-#define GPIO_X2_DAT_OFFSET 0x0C44
-#define GPIO_X2_PUD_OFFSET 0x0C48
-#define GPIO_X2_DRV_OFFSET 0x0C4C
-#define GPIO_X2_END 31
+#define XU3_GPIO_X2_START 24
+#define XU3_GPIO_X2_CON_OFFSET 0x0C40
+#define XU3_GPIO_X2_DAT_OFFSET 0x0C44
+#define XU3_GPIO_X2_PUD_OFFSET 0x0C48
+#define XU3_GPIO_X2_DRV_OFFSET 0x0C4C
+#define XU3_GPIO_X2_END 31
-#define GPIO_X3_START 32
-#define GPIO_X3_CON_OFFSET 0x0C60
-#define GPIO_X3_DAT_OFFSET 0x0C64
-#define GPIO_X3_PUD_OFFSET 0x0C68
-#define GPIO_X3_DRV_OFFSET 0x0C6C
-#define GPIO_X3_END 39
+#define XU3_GPIO_X3_START 32
+#define XU3_GPIO_X3_CON_OFFSET 0x0C60
+#define XU3_GPIO_X3_DAT_OFFSET 0x0C64
+#define XU3_GPIO_X3_PUD_OFFSET 0x0C68
+#define XU3_GPIO_X3_DRV_OFFSET 0x0C6C
+#define XU3_GPIO_X3_END 39
// GPA0,1,2, GPB0,1,2,3,4
-#define ODROIDXU3_GPA_BASE 0x14010000
+#define XU3_GPA_BASE 0x14010000
-#define GPIO_A0_START 171
-#define GPIO_A0_CON_OFFSET 0x0000
-#define GPIO_A0_DAT_OFFSET 0x0004
-#define GPIO_A0_PUD_OFFSET 0x0008
-#define GPIO_A0_DRV_OFFSET 0x000C
-#define GPIO_A0_END 178
+#define XU3_GPIO_A0_START 171
+#define XU3_GPIO_A0_CON_OFFSET 0x0000
+#define XU3_GPIO_A0_DAT_OFFSET 0x0004
+#define XU3_GPIO_A0_PUD_OFFSET 0x0008
+#define XU3_GPIO_A0_DRV_OFFSET 0x000C
+#define XU3_GPIO_A0_END 178
-#define GPIO_A2_START 185
-#define GPIO_A2_CON_OFFSET 0x0040
-#define GPIO_A2_DAT_OFFSET 0x0044
-#define GPIO_A2_PUD_OFFSET 0x0048
-#define GPIO_A2_DRV_OFFSET 0x004C
-#define GPIO_A2_END 192
+#define XU3_GPIO_A2_START 185
+#define XU3_GPIO_A2_CON_OFFSET 0x0040
+#define XU3_GPIO_A2_DAT_OFFSET 0x0044
+#define XU3_GPIO_A2_PUD_OFFSET 0x0048
+#define XU3_GPIO_A2_DRV_OFFSET 0x004C
+#define XU3_GPIO_A2_END 192
-#define GPIO_B3_START 207
-#define GPIO_B3_CON_OFFSET 0x00C0
-#define GPIO_B3_DAT_OFFSET 0x00C4
-#define GPIO_B3_PUD_OFFSET 0x00C8
-#define GPIO_B3_DRV_OFFSET 0x00CC
-#define GPIO_B3_END 214
+#define XU3_GPIO_B3_START 207
+#define XU3_GPIO_B3_CON_OFFSET 0x00C0
+#define XU3_GPIO_B3_DAT_OFFSET 0x00C4
+#define XU3_GPIO_B3_PUD_OFFSET 0x00C8
+#define XU3_GPIO_B3_DRV_OFFSET 0x00CC
+#define XU3_GPIO_B3_END 214
#ifdef __cplusplus
extern "C" {
diff --git a/wiringPi/wiringOdroid.h b/wiringPi/wiringOdroid.h
deleted file mode 100755
index 7797f25..0000000
--- a/wiringPi/wiringOdroid.h
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * 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 .
- ***********************************************************************
- */
-/*----------------------------------------------------------------------------*/
-#ifndef __WIRING_ODROID_H__
-#define __WIRING_ODROID_H__
-
-/*----------------------------------------------------------------------------*/
-#include
-#include
-#include
-#include
-
-/*----------------------------------------------------------------------------*/
-
-#ifndef TRUE
-#define TRUE (1==1)
-#define FALSE (!TRUE)
-#endif
-
-#define PIN_NUM_CALC_SYSFD(X) (X > 255 ? X - libwiring.pinBase : X)
-
-#define UNU __attribute__((unused))
-
-#define ENV_DEBUG "WIRINGPI_DEBUG"
-#define ENV_CODES "WIRINGPI_CODES"
-#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
-
-#define MODEL_UNKNOWN 0
-#define MODEL_ODROID_C1 1
-#define MODEL_ODROID_C2 2
-#define MODEL_ODROID_XU3 3
-#define MODEL_ODROID_N1 4
-#define MODEL_ODROID_N2 5
-
-#define MAKER_UNKNOWN 0
-#define MAKER_AMLOGIC 1
-#define MAKER_SAMSUNG 2
-#define MAKER_ROCKCHIP 3
-
-#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
-#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
-
-// Interrupt levels
-#define INT_EDGE_SETUP 0
-#define INT_EDGE_FALLING 1
-#define INT_EDGE_RISING 2
-#define INT_EDGE_BOTH 3
-
-// Module names
-#define AML_MODULE_I2C "aml_i2c"
-
-// Threads
-#define PI_THREAD(X) void *X (UNU void *dummy)
-
-// Failure modes
-#define WPI_FATAL (1==1)
-#define WPI_ALMOST (1==2)
-
-extern const char *piModelNames [16];
-extern const char *piRevisionNames [16];
-extern const char *piMakerNames [16];
-extern const int piMemorySize [ 8];
-
-/*----------------------------------------------------------------------------*/
-#define PAGE_SIZE (4*1024)
-#define BLOCK_SIZE (4*1024)
-
-/*----------------------------------------------------------------------------*/
-/* Debug message display function */
-/*----------------------------------------------------------------------------*/
-#define MSG_ERR -1
-#define MSG_WARN -2
-
-/*----------------------------------------------------------------------------*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*----------------------------------------------------------------------------*/
-// Export function define
-/*----------------------------------------------------------------------------*/
-extern int msg (int type, const char *message, ...);
-extern int moduleLoaded(char *);
-
-#ifdef __cplusplus
-}
-#endif
-
-/*----------------------------------------------------------------------------*/
-// 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;
-extern struct wiringPiNodeStruct *wiringPiFindNode (int pin);
-extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins);
-
-extern int wiringPiFailure (int fatal, const char *message, ...) ;
-
-/*----------------------------------------------------------------------------*/
-struct libodroid
-{
- /* 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;
-};
-
-/*----------------------------------------------------------------------------*/
-#endif /* __WIRING_ODROID_H__ */
-/*----------------------------------------------------------------------------*/
-/*----------------------------------------------------------------------------*/
diff --git a/wiringPi/wiringOdroidI2C.h b/wiringPi/wiringOdroidI2C.h
deleted file mode 100644
index 6db8c68..0000000
--- a/wiringPi/wiringOdroidI2C.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * wiringPiI2C.h:
- * Simplified I2C access routines
- * Copyright (c) 2013 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 .
- ***********************************************************************
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int wiringPiI2CRead (int fd) ;
-extern int wiringPiI2CReadReg8 (int fd, int reg) ;
-extern int wiringPiI2CReadReg16 (int fd, int reg) ;
-
-extern int wiringPiI2CWrite (int fd, int data) ;
-extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
-extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
-
-extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
-extern int wiringPiI2CSetup (const int devId) ;
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/wiringPi/wiringOdroidSPI.h b/wiringPi/wiringOdroidSPI.h
deleted file mode 100644
index 3980321..0000000
--- a/wiringPi/wiringOdroidSPI.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * wiringPiSPI.h:
- * Simplified SPI access routines
- * Copyright (c) 2012-2015 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 .
- ***********************************************************************
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int wiringPiSPIGetFd (int channel) ;
-int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
-int wiringPiSPISetupMode (int channel, int speed, int mode) ;
-int wiringPiSPISetup (int channel, int speed) ;
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/wiringPi/wiringOdroid.c b/wiringPi/wiringPi.c
similarity index 99%
rename from wiringPi/wiringOdroid.c
rename to wiringPi/wiringPi.c
index a985d01..759d2ad 100755
--- a/wiringPi/wiringOdroid.c
+++ b/wiringPi/wiringPi.c
@@ -29,7 +29,7 @@
#include "softTone.h"
/*----------------------------------------------------------------------------*/
-#include "wiringOdroid.h"
+#include "wiringPi.h"
#include "../version.h"
#include "odroidc1.h"
diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h
deleted file mode 120000
index ef688ed..0000000
--- a/wiringPi/wiringPi.h
+++ /dev/null
@@ -1 +0,0 @@
-wiringOdroid.h
\ No newline at end of file
diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h
new file mode 100755
index 0000000..26e4415
--- /dev/null
+++ b/wiringPi/wiringPi.h
@@ -0,0 +1,307 @@
+/*
+ * 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 .
+ ***********************************************************************
+ */
+/*----------------------------------------------------------------------------*/
+#ifndef __WIRING_H__
+#define __WIRING_H__
+
+/*----------------------------------------------------------------------------*/
+#include
+#include
+#include
+#include
+
+/*----------------------------------------------------------------------------*/
+
+#ifndef TRUE
+#define TRUE (1==1)
+#define FALSE (!TRUE)
+#endif
+
+#define PIN_NUM_CALC_SYSFD(X) (X > 255 ? X - libwiring.pinBase : X)
+
+#define UNU __attribute__((unused))
+
+#define ENV_DEBUG "WIRINGPI_DEBUG"
+#define ENV_CODES "WIRINGPI_CODES"
+#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
+
+#define MODEL_UNKNOWN 0
+#define MODEL_ODROID_C1 1
+#define MODEL_ODROID_C2 2
+#define MODEL_ODROID_XU3 3
+#define MODEL_ODROID_N1 4
+#define MODEL_ODROID_N2 5
+
+#define MAKER_UNKNOWN 0
+#define MAKER_AMLOGIC 1
+#define MAKER_SAMSUNG 2
+#define MAKER_ROCKCHIP 3
+
+#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
+#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
+
+// Interrupt levels
+#define INT_EDGE_SETUP 0
+#define INT_EDGE_FALLING 1
+#define INT_EDGE_RISING 2
+#define INT_EDGE_BOTH 3
+
+// Module names
+#define AML_MODULE_I2C "aml_i2c"
+
+// Threads
+#define PI_THREAD(X) void *X (UNU void *dummy)
+
+// Failure modes
+#define WPI_FATAL (1==1)
+#define WPI_ALMOST (1==2)
+
+extern const char *piModelNames [16];
+extern const char *piRevisionNames [16];
+extern const char *piMakerNames [16];
+extern const int piMemorySize [ 8];
+
+/*----------------------------------------------------------------------------*/
+#define PAGE_SIZE (4*1024)
+#define BLOCK_SIZE (4*1024)
+
+/*----------------------------------------------------------------------------*/
+/* Debug message display function */
+/*----------------------------------------------------------------------------*/
+#define MSG_ERR -1
+#define MSG_WARN -2
+
+/*----------------------------------------------------------------------------*/
+struct libodroid
+{
+ /* 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:
+// 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;
+
+/*----------------------------------------------------------------------------*/
+// Function prototypes
+// c++ wrappers thanks to a comment by Nick Lott
+// (and others on the Raspberry Pi forums)
+/*----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct wiringPiNodeStruct *wiringPiFindNode (int pin);
+extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins);
+
+// Internal WiringPi functions
+extern int wiringPiFailure (int fatal, const char *message, ...);
+extern int msg (int type, const char *message, ...);
+extern int moduleLoaded (char *);
+
+// Core WiringPi functions
+extern void wiringPiVersion (int *major, int *minor);
+extern int wiringPiSetup (void);
+extern int wiringPiSetupSys (void);
+extern int wiringPiSetupGpio (void);
+extern int wiringPiSetupPhys (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 value);
+extern void pwmWrite (int pin, int value);
+extern int analogRead (int pin);
+
+// Hardware specific stuffs
+extern int piGpioLayout (void);
+extern int piBoardRev (void); // Deprecated
+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 int piHiPri (const int pri);
+
+// 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 /* __WIRING_H__ */
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
diff --git a/wiringPi/wiringOdroidI2C.c b/wiringPi/wiringPiI2C.c
similarity index 100%
rename from wiringPi/wiringOdroidI2C.c
rename to wiringPi/wiringPiI2C.c
diff --git a/wiringPi/wiringPiI2C.h b/wiringPi/wiringPiI2C.h
deleted file mode 120000
index 0c09f32..0000000
--- a/wiringPi/wiringPiI2C.h
+++ /dev/null
@@ -1 +0,0 @@
-wiringOdroidI2C.h
\ No newline at end of file
diff --git a/wiringPi/wiringPiI2C.h b/wiringPi/wiringPiI2C.h
new file mode 100644
index 0000000..6db8c68
--- /dev/null
+++ b/wiringPi/wiringPiI2C.h
@@ -0,0 +1,42 @@
+/*
+ * wiringPiI2C.h:
+ * Simplified I2C access routines
+ * Copyright (c) 2013 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 .
+ ***********************************************************************
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int wiringPiI2CRead (int fd) ;
+extern int wiringPiI2CReadReg8 (int fd, int reg) ;
+extern int wiringPiI2CReadReg16 (int fd, int reg) ;
+
+extern int wiringPiI2CWrite (int fd, int data) ;
+extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
+extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
+
+extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
+extern int wiringPiI2CSetup (const int devId) ;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/wiringPi/wiringOdroidSPI.c b/wiringPi/wiringPiSPI.c
similarity index 100%
rename from wiringPi/wiringOdroidSPI.c
rename to wiringPi/wiringPiSPI.c
diff --git a/wiringPi/wiringPiSPI.h b/wiringPi/wiringPiSPI.h
deleted file mode 120000
index 92c384f..0000000
--- a/wiringPi/wiringPiSPI.h
+++ /dev/null
@@ -1 +0,0 @@
-wiringOdroidSPI.h
\ No newline at end of file
diff --git a/wiringPi/wiringPiSPI.h b/wiringPi/wiringPiSPI.h
new file mode 100644
index 0000000..3980321
--- /dev/null
+++ b/wiringPi/wiringPiSPI.h
@@ -0,0 +1,36 @@
+/*
+ * wiringPiSPI.h:
+ * Simplified SPI access routines
+ * Copyright (c) 2012-2015 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 .
+ ***********************************************************************
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int wiringPiSPIGetFd (int channel) ;
+int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
+int wiringPiSPISetupMode (int channel, int speed, int mode) ;
+int wiringPiSPISetup (int channel, int speed) ;
+
+#ifdef __cplusplus
+}
+#endif