From 8a4df6c9b136123e16c1e2c25780a3d232f783a3 Mon Sep 17 00:00:00 2001 From: charles Date: Mon, 17 Nov 2014 19:42:26 +0900 Subject: [PATCH 01/16] add odroid-c board. Change-Id: I7c2794670483ef944aa2f0480086e2520cff2ba1 --- gpio/gpio.c | 18 +- gpio/readall.c | 103 ++++++ wiringPi/wiringPi.c | 720 +++++++++++++++++++++++++++++++++-------- wiringPi/wiringPi.h | 38 +-- wiringPi/wiringPiI2C.c | 16 +- 5 files changed, 725 insertions(+), 170 deletions(-) mode change 100644 => 100755 gpio/gpio.c mode change 100644 => 100755 gpio/readall.c mode change 100644 => 100755 wiringPi/wiringPi.c mode change 100644 => 100755 wiringPi/wiringPi.h mode change 100644 => 100755 wiringPi/wiringPiI2C.c diff --git a/gpio/gpio.c b/gpio/gpio.c old mode 100644 new mode 100755 index 43e6934..96b751e --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -277,7 +277,8 @@ static void doExports (int argc, char *argv []) char fName [128] ; char buf [16] ; - for (first = 0, i = 0 ; i < 64 ; ++i) // Crude, but effective + // ODROIDC GPIO Max 128 + for (first = 0, i = 0 ; i < 128 ; ++i) // Crude, but effective { // Try to read the direction @@ -573,7 +574,8 @@ void doUnexportall (char *progName) FILE *fd ; int pin ; - for (pin = 0 ; pin < 63 ; ++pin) + // ODROIDC GPIO Max 128 + for (pin = 0 ; pin < 128 ; ++pin) { if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) { @@ -626,9 +628,9 @@ static void doReset (char *progName) piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B)) + /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B)) endPin = 16 ; - else if (model == PI_MODEL_BP) + else if ((model == PI_MODEL_BP) || (model == PI_MODEL_ODROIDC)) endPin = 39 ; else if (model == PI_MODEL_CM) { @@ -1194,11 +1196,17 @@ int main (int argc, char *argv []) printf (" projects@drogon.net\n") ; printf ("with a copy of your /proc/cpuinfo if possible\n") ; } + else if (model == PI_MODEL_ODROIDC) + { + printf ("Hardkernel ODROID Details:\n") ; + printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s\n", + piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker]) ; + } else { printf ("Raspberry Pi Details:\n") ; printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", - piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; + piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; } return 0 ; } diff --git a/gpio/readall.c b/gpio/readall.c old mode 100644 new mode 100755 index aba8de8..043944a --- a/gpio/readall.c +++ b/gpio/readall.c @@ -147,6 +147,36 @@ static char *physNames [64] = NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, } ; +static char *physNamesOdroidc [64] = +{ + NULL, + + " 3.3v", "5v ", + " SDA.1", "5V ", + " SCL.1", "0v ", + "GPIO. 83", "TxD1 ", + " 0v", "RxD1 ", + "GPIO. 88", "GPIO. 87", + "GPIO.116", "0v ", + "GPIO.115", "GPIO.104", + " 3.3v", "GPIO.102", + " MOSI", "0v ", + " MISO", "GPIO.103", + " SCLK", "CE0 ", + " 0v", "GPIO.118", + " SDA.2", "SCL.2 ", + "GPIO.101", "0v ", + "GPIO.100", "GPIO. 99", + "GPIO.108", "0v ", + "GPIO.97 ", "GPIO. 98", + " AIN.1", "1v8 ", + " 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, +} ; + /* * readallPhys: @@ -305,6 +335,77 @@ void piPlusReadall (int model) printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ; } +static void readallPhysOdroidC (int physPin) +{ + int pin ; + + if (physPinToGpio (physPin) == -1) + printf (" | | ") ; + else + printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ; + + printf (" | %s", physNamesOdroidc [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 (" | %-6s", physNamesOdroidc [physPin]) ; + + if (physPinToGpio (physPin) == -1) + printf (" | | ") ; + else + printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ; + + printf (" |\n") ; +} + +void ReadallOdroidC (void) +{ + int pin ; + char *type ; + + printf (" +------+-----+----------+------+- Model ODROID-C -+------+----------+-----+------+\n") ; + printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n") ; + printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; + for (pin = 1 ; pin <= 40 ; pin += 2) + readallPhysOdroidC (pin) ; + printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; +} void doReadall (void) { @@ -324,6 +425,8 @@ void doReadall (void) piPlusReadall (model) ; else if (model == PI_MODEL_CM) cmReadall () ; + else if (model == PI_MODEL_ODROIDC) + ReadallOdroidC (); else printf ("Oops - unable to determine board type... model: %d\n", model) ; } diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c old mode 100644 new mode 100755 index ba45f4d..b8d2012 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -51,7 +51,6 @@ // Added in the 2 UART pins // Change maxPins to numPins to more accurately reflect purpose - #include #include #include @@ -131,15 +130,15 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ; // Taken from Gert/Doms code. Some of this is not in the manual // that I can find )-: -#define BCM2708_PERI_BASE 0x20000000 -#define GPIO_PADS (BCM2708_PERI_BASE + 0x00100000) -#define CLOCK_BASE (BCM2708_PERI_BASE + 0x00101000) -#define GPIO_BASE (BCM2708_PERI_BASE + 0x00200000) -#define GPIO_TIMER (BCM2708_PERI_BASE + 0x0000B000) -#define GPIO_PWM (BCM2708_PERI_BASE + 0x0020C000) +#define BCM2708_PERI_BASE 0x20000000 +#define GPIO_PADS (BCM2708_PERI_BASE + 0x00100000) +#define CLOCK_BASE (BCM2708_PERI_BASE + 0x00101000) +#define GPIO_BASE (BCM2708_PERI_BASE + 0x00200000) +#define GPIO_TIMER (BCM2708_PERI_BASE + 0x0000B000) +#define GPIO_PWM (BCM2708_PERI_BASE + 0x0020C000) -#define PAGE_SIZE (4*1024) -#define BLOCK_SIZE (4*1024) +#define PAGE_SIZE (4*1024) +#define BLOCK_SIZE (4*1024) // PWM // Word offsets into the PWM control region @@ -175,15 +174,15 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ; // Timer // Word offsets -#define TIMER_LOAD (0x400 >> 2) -#define TIMER_VALUE (0x404 >> 2) -#define TIMER_CONTROL (0x408 >> 2) -#define TIMER_IRQ_CLR (0x40C >> 2) -#define TIMER_IRQ_RAW (0x410 >> 2) -#define TIMER_IRQ_MASK (0x414 >> 2) -#define TIMER_RELOAD (0x418 >> 2) -#define TIMER_PRE_DIV (0x41C >> 2) -#define TIMER_COUNTER (0x420 >> 2) +#define TIMER_LOAD (0x400 >> 2) +#define TIMER_VALUE (0x404 >> 2) +#define TIMER_CONTROL (0x408 >> 2) +#define TIMER_IRQ_CLR (0x40C >> 2) +#define TIMER_IRQ_RAW (0x410 >> 2) +#define TIMER_IRQ_MASK (0x414 >> 2) +#define TIMER_RELOAD (0x418 >> 2) +#define TIMER_PRE_DIV (0x41C >> 2) +#define TIMER_COUNTER (0x420 >> 2) // Locals to hold pointers to the hardware @@ -203,7 +202,7 @@ static volatile uint32_t *timerIrqRaw ; // and PI_VERSION_X defines in wiringPi.h // Only intended for the gpio command - use at your own risk! -const char *piModelNames [6] = +const char *piModelNames [7] = { "Unknown", "Model A", @@ -211,6 +210,7 @@ const char *piModelNames [6] = "Model B+", "Compute Module", "Model A+", + "ODROID-C" } ; const char *piRevisionNames [5] = @@ -222,12 +222,13 @@ const char *piRevisionNames [5] = "2", } ; -const char *piMakerNames [4] = +const char *piMakerNames [5] = { "Unknown", "Egoman", "Sony", "Qusda", + "Hardkernel", } ; @@ -565,6 +566,167 @@ static uint8_t gpioToClkDiv [] = -1, -1, -1, -1, -1, -1, -1, -1, // 56 -> 63 } ; +// +// For ODROID-C Board +// +#define ODROIDC_GPIO_MASK (0xFFFFFF80) + +#define ODROIDC_PERI_BASE 0xC1100000 +#define GPIO_REG_OFFSET 0x8000 +#define ODROID_GPIO_BASE (ODROIDC_PERI_BASE + GPIO_REG_OFFSET) + +#define GPIO_PIN_BASE 80 +#define GPIOY_PIN_START 80 +#define GPIOY_PIN_END 96 +#define GPIOX_PIN_START 97 +#define 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 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 + +static int piModel = PI_MODEL_UNKNOWN; + +#define piAinNode0 "/sys/class/saradc/saradc_ch0" +#define piAinNode1 "/sys/class/saradc/saradc_ch1" + +static int adcFds [2] = { + -1, -1, +} ; + +#define GPIO_IRQ_THREAD + +static int sysFdData [64] = { + -1, +}; + +static int sysFdIrqType [64] = { + 0, +}; + +// +// offset to the GPIO Set regsiter +// +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; + + return -1; +} + +// +// offset to the GPIO Input regsiter +// +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; + + return -1; +} + +// +// offset to the GPIO Pull up/down enable regsiter +// +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; + + return -1; +} + +// +// offset to the GPIO Pull up/down regsiter +// +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; + + return -1; +} + +// +// offset to the GPIO bit +// +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; + + return -1; +} + +// +// offset to the GPIO Function register +// +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; + + return -1; +} + +// +// pinToGpio: +// Take a Wiring pin (0 through X) and re-map it to the ODROID_GPIO pin +// +static int pinToGpioOdroidC [64] = { + 88, 87, 116, 115, 104, 102, 103, 83, // 0..7 + -1, -1, 117, 118, 107, 106, 105, -1, // 8..16 + -1, -1, -1, -1, -1, 101, 100, 108, // 16..23 + 97, -1, 99, 98, -1, -1, -1, -1, // 24..31 +// Padding: + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +// +// physToGpio: +// Take a physical pin (1 through 40) and re-map it to the ODROID_GPIO pin +// +static int physToGpioOdroidC [64] = +{ + -1, // 0 + -1, -1, // 1, 2 + -1, -1, + -1, -1, + 83, -1, + -1, -1, + 88, 87, + 116, -1, + 115, 104, + -1, 102, + 107, -1, + 106, 103, + 105, 117, + -1, 118, // 25, 26 + + -1, -1, + 101, -1, + 100, 99, + 108, -1, + 97, 98, + -1, -1, + -1, -1, // 39, 40 + +// Not used + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, +} ; + /* * Functions @@ -623,6 +785,9 @@ int wiringPiFailure (int fatal, const char *message, ...) * 0011 - Pi CM, Rev 1.2, 512MB, Sony * 0012 - Model A+ Rev 1.2, 256MB, Sony * + * added : + * 000c - Model ODROID C, Rev 1.0, 1024M, Hardkernel + * * A small thorn is the olde style overvolting - that will add in * 1000000 * @@ -703,10 +868,10 @@ int piBoardRev (void) if (wiringPiDebug) printf ("piboardRev: last4Chars are: \"%s\"\n", c) ; - if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0)) - boardRev = 1 ; + if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0) || (strcmp (c, "000c") == 0) ) + boardRev = 1; else - boardRev = 2 ; + boardRev = 2; if (wiringPiDebug) printf ("piBoardRev: Returning revision: %d\n", boardRev) ; @@ -787,7 +952,13 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; } else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; } else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; } - else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; } + else if (strcmp (c, "000a") == 0) { + *model = PI_MODEL_ODROIDC; *rev = PI_VERSION_1; *mem = 1024; *maker = PI_MAKER_HARDKERNEL; + } + else { + *model = 0; *rev = 0; *mem = 0; *maker = 0 ; + } + piModel = *model; } @@ -828,6 +999,11 @@ void setPadDrive (int group, int value) { uint32_t wrVal ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { if ((group < 0) || (group > 2)) @@ -856,7 +1032,10 @@ int getAlt (int pin) { int fSel, shift, alt ; - pin &= 63 ; + if ( piModel == PI_MODEL_ODROIDC ) + pin &= 0x7F; + else + pin &= 63 ; /**/ if (wiringPiMode == WPI_MODE_PINS) pin = pinToGpio [pin] ; @@ -865,12 +1044,20 @@ int getAlt (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return 0 ; - fSel = gpioToGPFSEL [pin] ; - shift = gpioToShift [pin] ; + if ( piModel == PI_MODEL_ODROIDC ) { + + if(pin < 0) return 2; // ALT - alt = (*(gpio + fSel) >> shift) & 7 ; + return (*(gpio + gpioToGPFSELReg(pin)) & (1 << gpioToShiftReg(pin))) ? 0 : 1; + } + else { + fSel = gpioToGPFSEL [pin] ; + shift = gpioToShift [pin] ; - return alt ; + alt = (*(gpio + fSel) >> shift) & 7 ; + + return alt ; + } } @@ -882,6 +1069,11 @@ int getAlt (int pin) void pwmSetMode (int mode) { + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { if (mode == PWM_MODE_MS) @@ -901,6 +1093,11 @@ void pwmSetMode (int mode) void pwmSetRange (unsigned int range) { + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { *(pwm + PWM0_RANGE) = range ; delayMicroseconds (10) ; @@ -922,6 +1119,11 @@ void pwmSetClock (int divisor) uint32_t pwm_control ; divisor &= 4095 ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { if (wiringPiDebug) @@ -967,6 +1169,11 @@ void gpioClockSet (int pin, int freq) { int divi, divr, divf ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + pin &= 63 ; /**/ if (wiringPiMode == WPI_MODE_PINS) @@ -1031,6 +1238,12 @@ struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) int pin ; struct wiringPiNodeStruct *node ; +// Minimum pin base is 128 (ODROID-C) + if ( piModel == PI_MODEL_ODROIDC ) { + if (pinBase < 128) + (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 128\n", pinBase) ; + } + // Minimum pin base is 64 if (pinBase < 64) @@ -1094,6 +1307,11 @@ void pinModeAlt (int pin, int mode) { int fSel, shift ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + if ((pin & PI_GPIO_MASK) == 0) // On-board pin { /**/ if (wiringPiMode == WPI_MODE_PINS) @@ -1122,8 +1340,11 @@ void pinMode (int pin, int mode) int fSel, shift, alt ; struct wiringPiNodeStruct *node = wiringPiNodes ; int origPin = pin ; + unsigned int gpio_mask = PI_GPIO_MASK; - if ((pin & PI_GPIO_MASK) == 0) // On-board pin + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + + if ((pin & gpio_mask) == 0) // On-board pin { /**/ if (wiringPiMode == WPI_MODE_PINS) pin = pinToGpio [pin] ; @@ -1138,23 +1359,39 @@ void pinMode (int pin, int mode) fSel = gpioToGPFSEL [pin] ; shift = gpioToShift [pin] ; - /**/ if (mode == INPUT) - *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) ; // Sets bits to zero = input - else if (mode == OUTPUT) - *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift) ; - else if (mode == SOFT_PWM_OUTPUT) - softPwmCreate (origPin, 0, 100) ; - else if (mode == SOFT_TONE_OUTPUT) - softToneCreate (origPin) ; + if (mode == INPUT) { + if ( piModel == PI_MODEL_ODROIDC ) + *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) | (1 << gpioToShiftReg(pin))); + else + *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)); // Sets bits to zero = input + } + else if (mode == OUTPUT) { + if ( piModel == PI_MODEL_ODROIDC ) + *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) & ~(1 << gpioToShiftReg(pin))); + else + *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift); + } + else if (mode == SOFT_PWM_OUTPUT) { + if ( piModel == PI_MODEL_ODROIDC ) softPwmCreate (pin, 0, 100); + else softPwmCreate (origPin, 0, 100); + } + else if (mode == SOFT_TONE_OUTPUT) { + if ( piModel == PI_MODEL_ODROIDC ) softToneCreate (pin); + else softToneCreate (origPin); + } else if (mode == PWM_TONE_OUTPUT) { + if ( piModel == PI_MODEL_ODROIDC ) return; + pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode pwmSetMode (PWM_MODE_MS) ; } else if (mode == PWM_OUTPUT) { + if ( piModel == PI_MODEL_ODROIDC ) return; + if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin - return ; + return ; // Set pin to PWM mode @@ -1167,8 +1404,10 @@ void pinMode (int pin, int mode) } else if (mode == GPIO_CLOCK) { + if ( piModel == PI_MODEL_ODROIDC ) return; + if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin - return ; + return ; // Set pin to GPIO_CLOCK mode and set the clock frequency to 100KHz @@ -1198,8 +1437,11 @@ void pinMode (int pin, int mode) void pullUpDnControl (int pin, int pud) { struct wiringPiNodeStruct *node = wiringPiNodes ; + unsigned int gpio_mask = PI_GPIO_MASK; + + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; - if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin + if ((pin & gpio_mask) == 0) // On-Board Pin { /**/ if (wiringPiMode == WPI_MODE_PINS) pin = pinToGpio [pin] ; @@ -1208,11 +1450,30 @@ void pullUpDnControl (int pin, int pud) else if (wiringPiMode != WPI_MODE_GPIO) return ; - *(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ; - *(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ; - - *(gpio + GPPUD) = 0 ; delayMicroseconds (5) ; - *(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ; + if( piModel == PI_MODEL_ODROIDC ) { + + // maybe pin mode is not gpio. + if(pin < 0) return; + + if(pud) { + // Enable Pull/Pull-down resister + *(gpio + gpioToPUENReg(pin)) = (*(gpio + gpioToPUENReg(pin)) | (1 << gpioToShiftReg(pin))); + + if(pud == PUD_UP) + *(gpio + gpioToPUPDReg(pin)) = (*(gpio + gpioToPUPDReg(pin)) | (1 << gpioToShiftReg(pin))); + else + *(gpio + gpioToPUPDReg(pin)) = (*(gpio + gpioToPUPDReg(pin)) & ~(1 << gpioToShiftReg(pin))); + } + else // Disable Pull/Pull-down resister + *(gpio + gpioToPUENReg(pin)) = (*(gpio + gpioToPUENReg(pin)) & ~(1 << gpioToShiftReg(pin))); + } + else { + *(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ; + *(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ; + + *(gpio + GPPUD) = 0 ; delayMicroseconds (5) ; + *(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ; + } } else // Extension module { @@ -1233,13 +1494,16 @@ int digitalRead (int pin) { char c ; struct wiringPiNodeStruct *node = wiringPiNodes ; + unsigned int gpio_mask = PI_GPIO_MASK; - if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + + if ((pin & gpio_mask) == 0) // On-Board Pin { /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode { if (sysFds [pin] == -1) - return LOW ; + return LOW ; lseek (sysFds [pin], 0L, SEEK_SET) ; read (sysFds [pin], &c, 1) ; @@ -1252,10 +1516,18 @@ int digitalRead (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return LOW ; - if ((*(gpio + gpioToGPLEV [pin]) & (1 << (pin & 31))) != 0) - return HIGH ; - else - return LOW ; + if ( piModel == PI_MODEL_ODROIDC ) { + if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0) + return HIGH ; + else + return LOW ; + } + else { + if ((*(gpio + gpioToGPLEV [pin]) & (1 << (pin & 31))) != 0) + return HIGH ; + else + return LOW ; + } } else { @@ -1275,17 +1547,20 @@ int digitalRead (int pin) void digitalWrite (int pin, int value) { struct wiringPiNodeStruct *node = wiringPiNodes ; + unsigned int gpio_mask = PI_GPIO_MASK; - if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + + if ((pin & gpio_mask) == 0) // On-Board Pin { /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode { if (sysFds [pin] != -1) { - if (value == LOW) - write (sysFds [pin], "0\n", 2) ; - else - write (sysFds [pin], "1\n", 2) ; + if (value == LOW) + write (sysFds [pin], "0\n", 2) ; + else + write (sysFds [pin], "1\n", 2) ; } return ; } @@ -1296,10 +1571,18 @@ void digitalWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - if (value == LOW) - *(gpio + gpioToGPCLR [pin]) = 1 << (pin & 31) ; - else - *(gpio + gpioToGPSET [pin]) = 1 << (pin & 31) ; + if ( piModel == PI_MODEL_ODROIDC ) { + if (value == LOW) + *(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin)); + else + *(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin)); + } + else { + if (value == LOW) + *(gpio + gpioToGPCLR [pin]) = 1 << (pin & 31) ; + else + *(gpio + gpioToGPSET [pin]) = 1 << (pin & 31) ; + } } else { @@ -1318,8 +1601,11 @@ void digitalWrite (int pin, int value) void pwmWrite (int pin, int value) { struct wiringPiNodeStruct *node = wiringPiNodes ; + unsigned int gpio_mask = PI_GPIO_MASK; + + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; - if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin + if ((pin & gpio_mask) == 0) // On-Board Pin { /**/ if (wiringPiMode == WPI_MODE_PINS) pin = pinToGpio [pin] ; @@ -1328,7 +1614,12 @@ void pwmWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - *(pwm + gpioToPwmPort [pin]) = value ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + else + *(pwm + gpioToPwmPort [pin]) = value ; } else { @@ -1349,6 +1640,17 @@ void pwmWrite (int pin, int value) int analogRead (int pin) { struct wiringPiNodeStruct *node = wiringPiNodes ; + unsigned char value[5] = {0,}; + + if ( piModel == PI_MODEL_ODROIDC ) { + if(pin < 2) { + if (adcFds [pin] == -1) + return 0; + lseek (adcFds [pin], 0L, SEEK_SET); + read (adcFds [pin], &value[0], 4); + return atoi(value); + } + } if ((node = wiringPiFindNode (pin)) == NULL) return 0 ; @@ -1387,6 +1689,11 @@ void pwmToneWrite (int pin, int freq) { int range ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + if (freq == 0) pwmWrite (pin, 0) ; // Off else @@ -1417,6 +1724,11 @@ void digitalWriteByte (int value) int mask = 1 ; int pin ; + if ( piModel == PI_MODEL_ODROIDC ) { + fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + exit (EXIT_FAILURE) ; + } + /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) { for (pin = 0 ; pin < 8 ; ++pin) @@ -1431,9 +1743,9 @@ void digitalWriteByte (int value) for (pin = 0 ; pin < 8 ; ++pin) { if ((value & mask) == 0) - pinClr |= (1 << pinToGpio [pin]) ; + pinClr |= (1 << pinToGpio [pin]) ; else - pinSet |= (1 << pinToGpio [pin]) ; + pinSet |= (1 << pinToGpio [pin]) ; mask <<= 1 ; } @@ -1454,27 +1766,48 @@ void digitalWriteByte (int value) ********************************************************************************* */ + int waitForInterrupt (int pin, int mS) { int fd, x ; uint8_t c ; struct pollfd polls ; + int fd_base; /**/ if (wiringPiMode == WPI_MODE_PINS) - pin = pinToGpio [pin] ; + pin = pinToGpio [pin & 63] ; else if (wiringPiMode == WPI_MODE_PHYS) - pin = physToGpio [pin] ; + pin = physToGpio [pin & 63] ; - if ((fd = sysFds [pin]) == -1) - return -2 ; + if ( piModel == PI_MODEL_ODROIDC ) { -// Setup poll structure + fd_base = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; - polls.fd = fd ; - polls.events = POLLPRI ; // Urgent data! + if ((fd = sysFds [fd_base & 63]) == -1) + return -2 ; -// Wait for it ... + // Setup poll structure + + polls.fd = fd ; + #if defined(GPIO_IRQ_THREAD) + polls.events = POLLIN ; // Normal data! + #else + polls.events = POLLPRI ; // Urgent data! + #endif + } + else { + if ((fd = sysFds [pin]) == -1) + return -2 ; + // Setup poll structure + + polls.fd = fd ; + polls.events = POLLPRI ; // Urgent data! + } + + +// Wait for it ... +wait: x = poll (&polls, 1, mS) ; // Do a dummy read to clear the interrupt @@ -1484,6 +1817,19 @@ int waitForInterrupt (int pin, int mS) (void)read (fd, &c, 1) ; lseek (fd, 0, SEEK_SET) ; +#if defined(GPIO_IRQ_THREAD) + if ( piModel == PI_MODEL_ODROIDC ) + { + if ( sysFdData[fd_base] != c ) { + sysFdData[fd_base] = c; + if (( sysFdIrqType[fd_base] == INT_EDGE_RISING ) && ( c == '1' )) return 1; + else if (( sysFdIrqType[fd_base] == INT_EDGE_FALLING ) && ( c == '0' )) return 1; + else if (( sysFdIrqType[fd_base] == INT_EDGE_BOTH ) ) return 1; + } + usleep(100); + goto wait; + } +#endif return x ; } @@ -1505,9 +1851,30 @@ static void *interruptHandler (void *arg) myPin = pinPass ; pinPass = -1 ; - for (;;) - if (waitForInterrupt (myPin, -1) > 0) - isrFunctions [myPin] () ; + if ( piModel == PI_MODEL_ODROIDC ) { + int gpioPin, fd_base; + + /**/ if (wiringPiMode == WPI_MODE_UNINITIALISED) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n") ; + else if (wiringPiMode == WPI_MODE_PINS) + gpioPin = pinToGpio [myPin & 63] ; + else if (wiringPiMode == WPI_MODE_PHYS) + gpioPin = physToGpio [myPin & 63] ; + else + gpioPin = myPin ; + + fd_base = gpioPin < GPIO_PIN_BASE ? 0 : gpioPin - GPIO_PIN_BASE; + + for (;;) + if (waitForInterrupt (myPin, -1) > 0) { + isrFunctions [fd_base] () ; + } + } + else { + for (;;) + if (waitForInterrupt (myPin, -1) > 0) + isrFunctions [myPin] () ; + } return NULL ; } @@ -1532,18 +1899,24 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) char c ; int bcmGpioPin ; - if ((pin < 0) || (pin > 63)) - return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-63 (%d)\n", pin) ; - /**/ if (wiringPiMode == WPI_MODE_UNINITIALISED) return wiringPiFailure (WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n") ; else if (wiringPiMode == WPI_MODE_PINS) - bcmGpioPin = pinToGpio [pin] ; + bcmGpioPin = pinToGpio [pin & 63] ; else if (wiringPiMode == WPI_MODE_PHYS) - bcmGpioPin = physToGpio [pin] ; + bcmGpioPin = physToGpio [pin & 63] ; else bcmGpioPin = pin ; + if ( piModel == PI_MODEL_ODROIDC ) { + if ((pin < 0) || (pin > 128)) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-128 (%d)\n", pin) ; + } + else { + if ((pin < 0) || (pin > 63)) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-63 (%d)\n", pin) ; + } + // Now export the pin and set the right edge // We're going to use the gpio program to do this, so it assumes // a full installation of wiringPi. It's a bit 'clunky', but it @@ -1568,16 +1941,16 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) { /**/ if (access ("/usr/local/bin/gpio", X_OK) == 0) { - execl ("/usr/local/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ; - return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ; + execl ("/usr/local/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ; + return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ; } else if (access ("/usr/bin/gpio", X_OK) == 0) { - execl ("/usr/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ; - return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ; + execl ("/usr/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ; + return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ; } else - return wiringPiFailure (WPI_FATAL, "wiringPiISR: Can't find gpio program\n") ; + return wiringPiFailure (WPI_FATAL, "wiringPiISR: Can't find gpio program\n") ; } else // Parent, wait wait (NULL) ; @@ -1586,20 +1959,42 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) // Now pre-open the /sys/class node - but it may already be open if // we are in Sys mode... - if (sysFds [bcmGpioPin] == -1) - { - sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; - if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0) - return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; + if ( piModel == PI_MODEL_ODROIDC ) { + int fd_base = bcmGpioPin < GPIO_PIN_BASE ? 0 : bcmGpioPin - GPIO_PIN_BASE; + + if (sysFds [fd_base] == -1) + { + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + if ((sysFds [fd_base] = open (fName, O_RDWR)) < 0) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; + sysFdIrqType [fd_base] = mode; + } + + // Clear any initial pending interrupt + + ioctl (sysFds [fd_base], FIONREAD, &count) ; + for (i = 0 ; i < count ; ++i) + read (sysFds [fd_base], &c, 1) ; + + sysFdData[fd_base] = c; + isrFunctions [fd_base] = function ; } + else { + if (sysFds [bcmGpioPin] == -1) + { + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; + } -// Clear any initial pending interrupt + // Clear any initial pending interrupt - ioctl (sysFds [bcmGpioPin], FIONREAD, &count) ; - for (i = 0 ; i < count ; ++i) - read (sysFds [bcmGpioPin], &c, 1) ; + ioctl (sysFds [bcmGpioPin], FIONREAD, &count) ; + for (i = 0 ; i < count ; ++i) + read (sysFds [bcmGpioPin], &c, 1) ; - isrFunctions [pin] = function ; + isrFunctions [pin] = function ; + } pthread_mutex_lock (&pinMutex) ; pinPass = pin ; @@ -1761,47 +2156,67 @@ int wiringPiSetup (void) if (wiringPiDebug) printf ("wiringPi: wiringPiSetup called\n") ; - boardRev = piBoardRev () ; - - /**/ if (boardRev == 1) // A, B, Rev 1, 1.1 - { - pinToGpio = pinToGpioR1 ; - physToGpio = physToGpioR1 ; - } - else // A, B, Rev 2, B+, CM - { - pinToGpio = pinToGpioR2 ; - physToGpio = physToGpioR2 ; - } + piBoardId (&model, &rev, &mem, &maker, &overVolted) ; // Open the master /dev/memory device if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; -// GPIO: + if ( model == PI_MODEL_ODROIDC ) { - gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ; - if ((int32_t)gpio == -1) - return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; + pinToGpio = pinToGpioOdroidC; + physToGpio = physToGpioOdroidC; -// PWM + // GPIO: - pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; - if ((int32_t)pwm == -1) - return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; - -// Clock control (needed for PWM) + gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, ODROID_GPIO_BASE) ; + if ((int32_t)gpio == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; - clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ; - if ((int32_t)clk == -1) - return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ; - -// The drive pads + // ADC + // ADC sysfs open (/sys/class/saradc/saradc_ch0, ch1) + adcFds [0] = open (piAinNode0, O_RDONLY) ; + adcFds [1] = open (piAinNode1, O_RDONLY) ; + + } + else { + // GPIO: + boardRev = piBoardRev () ; + + /**/ if (boardRev == 1) // A, B, Rev 1, 1.1 + { + pinToGpio = pinToGpioR1 ; + physToGpio = physToGpioR1 ; + } + else // A, B, Rev 2, B+, CM + { + pinToGpio = pinToGpioR2 ; + physToGpio = physToGpioR2 ; + } + + gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ; + if ((int32_t)gpio == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; + + // PWM + + pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; + if ((int32_t)pwm == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; + + // Clock control (needed for PWM) + + clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ; + if ((int32_t)clk == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ; - pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ; - if ((int32_t)pads == -1) - return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ; + // The drive pads + + pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ; + if ((int32_t)pads == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ; + } #ifdef USE_TIMER // The system timer @@ -1823,7 +2238,6 @@ int wiringPiSetup (void) // If we're running on a compute module, then wiringPi pin numbers don't really many anything... - piBoardId (&model, &rev, &mem, &maker, &overVolted) ; if (model == PI_MODEL_CM) wiringPiMode = WPI_MODE_GPIO ; else @@ -1889,6 +2303,7 @@ int wiringPiSetupPhys (void) int wiringPiSetupSys (void) { int boardRev ; + int model, rev, mem, maker, overVolted ; int pin ; char fName [128] ; @@ -1901,26 +2316,47 @@ int wiringPiSetupSys (void) if (wiringPiDebug) printf ("wiringPi: wiringPiSetupSys called\n") ; - boardRev = piBoardRev () ; + piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if (boardRev == 1) - { - pinToGpio = pinToGpioR1 ; - physToGpio = physToGpioR1 ; - } - else - { - pinToGpio = pinToGpioR2 ; - physToGpio = physToGpioR2 ; + if ( model == PI_MODEL_ODROIDC ) { + pinToGpio = pinToGpioOdroidC ; + physToGpio = physToGpioOdroidC ; + +// Open and scan the directory, looking for exported GPIOs, and pre-open +// the 'value' interface to speed things up for later + + for (pin = GPIO_PIN_BASE ; pin < GPIO_PIN_BASE + 64 ; ++pin) + { + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + sysFds [pin - GPIO_PIN_BASE] = open (fName, O_RDWR) ; + } + + // ADC sysfs open (/sys/class/saradc/saradc_ch0, ch1) + + adcFds [0] = open (piAinNode0, O_RDONLY) ; + adcFds [1] = open (piAinNode1, O_RDONLY) ; } + else { + boardRev = piBoardRev () ; + + if (boardRev == 1) + { + pinToGpio = pinToGpioR1 ; + physToGpio = physToGpioR1 ; + } + else + { + pinToGpio = pinToGpioR2 ; + physToGpio = physToGpioR2 ; + } // Open and scan the directory, looking for exported GPIOs, and pre-open // the 'value' interface to speed things up for later - - for (pin = 0 ; pin < 64 ; ++pin) - { - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; - sysFds [pin] = open (fName, O_RDWR) ; + for (pin = 0 ; pin < 64 ; ++pin) + { + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + sysFds [pin] = open (fName, O_RDWR) ; + } } initialiseEpoch () ; diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h old mode 100644 new mode 100755 index 42265fc..185b333 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -70,27 +70,29 @@ // Pi model types and version numbers // Intended for the GPIO program Use at your own risk. -#define PI_MODEL_UNKNOWN 0 -#define PI_MODEL_A 1 -#define PI_MODEL_B 2 -#define PI_MODEL_BP 3 -#define PI_MODEL_CM 4 -#define PI_MODEL_AP 5 +#define PI_MODEL_UNKNOWN 0 +#define PI_MODEL_A 1 +#define PI_MODEL_B 2 +#define PI_MODEL_BP 3 +#define PI_MODEL_CM 4 +#define PI_MODEL_AP 5 +#define PI_MODEL_ODROIDC 6 #define PI_VERSION_UNKNOWN 0 -#define PI_VERSION_1 1 -#define PI_VERSION_1_1 2 -#define PI_VERSION_1_2 3 -#define PI_VERSION_2 4 - -#define PI_MAKER_UNKNOWN 0 -#define PI_MAKER_EGOMAN 1 -#define PI_MAKER_SONY 2 -#define PI_MAKER_QISDA 3 - -extern const char *piModelNames [6] ; +#define PI_VERSION_1 1 +#define PI_VERSION_1_1 2 +#define PI_VERSION_1_2 3 +#define PI_VERSION_2 4 + +#define PI_MAKER_UNKNOWN 0 +#define PI_MAKER_EGOMAN 1 +#define PI_MAKER_SONY 2 +#define PI_MAKER_QISDA 3 +#define PI_MAKER_HARDKERNEL 4 + +extern const char *piModelNames [7] ; extern const char *piRevisionNames [5] ; -extern const char *piMakerNames [4] ; +extern const char *piMakerNames [5] ; // Intended for the GPIO program Use at your own risk. diff --git a/wiringPi/wiringPiI2C.c b/wiringPi/wiringPiI2C.c old mode 100644 new mode 100755 index c787bce..ab6938b --- a/wiringPi/wiringPiI2C.c +++ b/wiringPi/wiringPiI2C.c @@ -218,15 +218,21 @@ int wiringPiI2CSetupInterface (const char *device, int devId) int wiringPiI2CSetup (const int devId) { - int rev ; const char *device ; + int model, rev, mem, maker, overVolted ; - rev = piBoardRev () ; + piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if (rev == 1) - device = "/dev/i2c-0" ; - else + if ( model == PI_MODEL_ODROIDC ) device = "/dev/i2c-1" ; + else { + rev = piBoardRev () ; + + if (rev == 1) + device = "/dev/i2c-0" ; + else + device = "/dev/i2c-1" ; + } return wiringPiI2CSetupInterface (device, devId) ; } From ce4556c782d0df9dd8c9a83c50731aa1b745d207 Mon Sep 17 00:00:00 2001 From: Mauro Ribeiro Date: Wed, 7 Jan 2015 20:11:37 -0200 Subject: [PATCH 02/16] add a root makefile Change-Id: I93a82eb7c266ef1aefbdfb239ad53c11dbe757ec --- Makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a02d1a3 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +clean: + make -C wiringPi clean + make -C devLib clean + make -C gpio clean + make -C examples clean + make -C examples/Gertboard clean + make -C examples/PiFace clean + make -C examples/q2w clean + make -C examples/PiGlow clean + +install: + make -C wiringPi + make -C wiringPi install + make -C devLib + make -C devLib install + make -C gpio + make -C gpio install + mkdir -p /usr/share/wiringPi/examples/Gertboard + mkdir -p /usr/share/wiringPi/examples/PiFace + mkdir -p /usr/share/wiringPi/examples/PiGlow + mkdir -p /usr/share/wiringPi/examples/q2w + find examples -exec install -m 0644 -D -t /usr/share/wiringPi/examples {} \; From 8430615cc9a4a96d4cbc681cfa0f49461d97d35c Mon Sep 17 00:00:00 2001 From: Mauro Ribeiro Date: Wed, 7 Jan 2015 20:11:51 -0200 Subject: [PATCH 03/16] add postinstall file to show a message after the package is installed Change-Id: I568d0966fb95f457af3a58b711618af4468f542c --- postinstall-pak | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 postinstall-pak diff --git a/postinstall-pak b/postinstall-pak new file mode 100644 index 0000000..469eb47 --- /dev/null +++ b/postinstall-pak @@ -0,0 +1,7 @@ +#!/bin/bash +echo +echo "WiringPi for C1 is now installed" +echo "Please check the wiki: http://odroid.com/dokuwiki/doku.php?id=en:odroid-c1" +echo "For extra references:" +echo "Github: https://github.com/hardkernel/wiringPi" +echo "Examples folder is copied to /usr/share/wiringPi/examples" From ea706b8d7e96a20a9a63e33533e674c5b7b77f3b Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Sun, 26 Jul 2015 16:04:44 +0900 Subject: [PATCH 04/16] WiringPi : modified for ODROID-XU4 Shift-shield. support ODROID-C gpio interrupt on wiringPi Lib. Change-Id: I3717aeba737ab052bf87e5a984953ed864c65bd9 --- gpio/gpio.c | 88 ++++-- gpio/readall.c | 103 ++++++ wiringPi/wiringPi.c | 691 +++++++++++++++++++++++++++++++++++------ wiringPi/wiringPi.h | 3 +- wiringPi/wiringPiI2C.c | 4 +- 5 files changed, 775 insertions(+), 114 deletions(-) diff --git a/gpio/gpio.c b/gpio/gpio.c index 96b751e..9b14c0c 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -53,11 +53,12 @@ extern void doPins (void) ; # define FALSE (1==2) #endif -#define VERSION "2.21" +#define VERSION "2.30" #define PI_USB_POWER_CONTROL 38 #define I2CDETECT "/usr/sbin/i2cdetect" int wpMode ; +int piModel = PI_MODEL_UNKNOWN; char *usage = "Usage: gpio -v\n" " gpio -h\n" @@ -277,8 +278,8 @@ static void doExports (int argc, char *argv []) char fName [128] ; char buf [16] ; - // ODROIDC GPIO Max 128 - for (first = 0, i = 0 ; i < 128 ; ++i) // Crude, but effective + // ODROIDC GPIO Max 128, ODROIDXU_34 GPIO Max 256 + for (first = 0, i = 0 ; i < 256 ; ++i) // Crude, but effective { // Try to read the direction @@ -371,7 +372,12 @@ void doExport (int argc, char *argv []) mode = argv [3] ; - if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL) + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/%s/export", "aml_gpio"); + else + sprintf (fName, "/sys/class/%s/export", "gpio"); + + if ((fd = fopen (fName, "w")) == NULL) { fprintf (stderr, "%s: Unable to open GPIO export interface: %s\n", argv [0], strerror (errno)) ; exit (1) ; @@ -380,7 +386,11 @@ void doExport (int argc, char *argv []) fprintf (fd, "%d\n", pin) ; fclose (fd) ; - sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ; + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/direction", pin) ; + else + 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)) ; @@ -401,10 +411,18 @@ void doExport (int argc, char *argv []) // Change ownership so the current user can actually use it! - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin) ; + else + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + changeOwner (argv [0], fName) ; - sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ; + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/edge", pin) ; + else + sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ; + changeOwner (argv [0], fName) ; } @@ -471,6 +489,9 @@ void doEdge (int argc, char *argv []) char *mode ; char fName [128] ; + // Reset irq gpio + doUnexport(3, argv); // unexport argc == 3 + if (argc != 4) { fprintf (stderr, "Usage: %s edge pin mode\n", argv [0]) ; @@ -482,16 +503,24 @@ void doEdge (int argc, char *argv []) // Export the pin and set direction to input - if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL) + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/%s/export", "aml_gpio"); + else + sprintf (fName, "/sys/class/%s/export", "gpio"); + + if ((fd = fopen (fName, "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 (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/direction", pin); + else + 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)) ; @@ -501,7 +530,11 @@ void doEdge (int argc, char *argv []) fprintf (fd, "in\n") ; fclose (fd) ; - sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ; + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/edge", pin); + else + 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)) ; @@ -520,10 +553,18 @@ void doEdge (int argc, char *argv []) // 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) ; + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin); + else + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin); + changeOwner (argv [0], fName) ; - sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ; + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/aml_gpio/gpio%d/edge", pin); + else + sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin); + changeOwner (argv [0], fName) ; fclose (fd) ; @@ -541,6 +582,7 @@ void doUnexport (int argc, char *argv []) { FILE *fd ; int pin ; + char fName [128] ; if (argc != 3) { @@ -550,7 +592,12 @@ void doUnexport (int argc, char *argv []) pin = atoi (argv [2]) ; - if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) + if (piModel == PI_MODEL_ODROIDC) + sprintf (fName, "/sys/class/%s/unexport", "aml_gpio") ; + else + sprintf (fName, "/sys/class/%s/unexport", "gpio") ; + + if ((fd = fopen (fName, "w")) == NULL) { fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ; exit (1) ; @@ -574,8 +621,8 @@ void doUnexportall (char *progName) FILE *fd ; int pin ; - // ODROIDC GPIO Max 128 - for (pin = 0 ; pin < 128 ; ++pin) + // ODROIDC GPIO Max 128, ODROIDXU_34 GPIO Max 256 + for (pin = 0 ; pin < 256 ; ++pin) { if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) { @@ -630,7 +677,8 @@ static void doReset (char *progName) /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B)) endPin = 16 ; - else if ((model == PI_MODEL_BP) || (model == PI_MODEL_ODROIDC)) + else if ((model == PI_MODEL_BP) || (model == PI_MODEL_ODROIDC) + || (model == PI_MODEL_ODROIDXU_34)) endPin = 39 ; else if (model == PI_MODEL_CM) { @@ -1182,6 +1230,9 @@ int main (int argc, char *argv []) return 0 ; } + piBoardId (&model, &rev, &mem, &maker, &overVolted) ; + piModel = model; + if (strcmp (argv [1], "-v") == 0) { printf ("gpio version: %s\n", VERSION) ; @@ -1189,14 +1240,13 @@ int main (int argc, char *argv []) 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, &overVolted) ; if (model == PI_MODEL_UNKNOWN) { printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ; printf (" projects@drogon.net\n") ; printf ("with a copy of your /proc/cpuinfo if possible\n") ; } - else if (model == PI_MODEL_ODROIDC) + else if (model == PI_MODEL_ODROIDC || model == PI_MODEL_ODROIDXU_34) { printf ("Hardkernel ODROID Details:\n") ; printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s\n", diff --git a/gpio/readall.c b/gpio/readall.c index 043944a..052aa06 100755 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -177,6 +177,35 @@ static char *physNamesOdroidc [64] = NULL,NULL,NULL, } ; +static char *physNamesOdroidXU [64] = +{ + NULL, + + " 3.3v", "5v ", + "I2C1.SDA", "5V ", + "I2C1.SCL", "0v ", + "GPIO. 18", "UART0.TX", + " 0v", "UART0.RX", + "GPIO.174", "GPIO.173", + "GPIO. 21", "0v ", + "GPIO. 22", "GPIO. 19", + " 3.3v", "GPIO. 23", + " MOSI", "0v ", + " MISO", "GPIO. 24", + " SCLK", "CE0 ", + " 0v", "GPIO.190", + "I2C5.SDA", "I2C5.SCL", + "GPIO. 28", "0v ", + "GPIO. 30", "GPIO. 29", + "GPIO. 31", "0v ", + "POWER ON", "GPIO. 33", + " AIN.0", "1v8 ", + " 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, +} ; /* * readallPhys: @@ -407,6 +436,78 @@ void ReadallOdroidC (void) printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; } +static void readallPhysOdroidXU (int physPin) +{ + int pin ; + + if (physPinToGpio (physPin) == -1) + printf (" | | ") ; + else + printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ; + + printf (" | %s", physNamesOdroidXU [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 (" | %-6s", physNamesOdroidXU [physPin]) ; + + if (physPinToGpio (physPin) == -1) + printf (" | | ") ; + else + printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ; + + printf (" |\n") ; +} + +void ReadallOdroidXU (void) +{ + int pin ; + char *type ; + + printf (" +------+-----+----------+------ Model ODROID-XU3/4 ------+----------+-----+------+\n") ; + printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n") ; + printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; + for (pin = 1 ; pin <= 40 ; pin += 2) + readallPhysOdroidXU (pin) ; + printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; +} + void doReadall (void) { int model, rev, mem, maker, overVolted ; @@ -427,6 +528,8 @@ void doReadall (void) cmReadall () ; else if (model == PI_MODEL_ODROIDC) ReadallOdroidC (); + else if (model == PI_MODEL_ODROIDXU_34) + ReadallOdroidXU(); else printf ("Oops - unable to determine board type... model: %d\n", model) ; } diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index b8d2012..b3242b5 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -186,7 +186,7 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ; // Locals to hold pointers to the hardware -static volatile uint32_t *gpio ; +static volatile uint32_t *gpio, *gpio1; static volatile uint32_t *pwm ; static volatile uint32_t *clk ; static volatile uint32_t *pads ; @@ -202,7 +202,7 @@ static volatile uint32_t *timerIrqRaw ; // and PI_VERSION_X defines in wiringPi.h // Only intended for the gpio command - use at your own risk! -const char *piModelNames [7] = +const char *piModelNames [8] = { "Unknown", "Model A", @@ -210,7 +210,8 @@ const char *piModelNames [7] = "Model B+", "Compute Module", "Model A+", - "ODROID-C" + "ODROID-C", + "ODROID-XU3/4", } ; const char *piRevisionNames [5] = @@ -593,8 +594,6 @@ static uint8_t gpioToClkDiv [] = #define GPIOY_PUPD_REG_OFFSET 0x3D #define GPIOY_PUEN_REG_OFFSET 0x4B -static int piModel = PI_MODEL_UNKNOWN; - #define piAinNode0 "/sys/class/saradc/saradc_ch0" #define piAinNode1 "/sys/class/saradc/saradc_ch1" @@ -602,23 +601,126 @@ static int adcFds [2] = { -1, -1, } ; -#define GPIO_IRQ_THREAD +// +// For ODROID-XU3/4 Board +// +#define ODROIDXU_GPIO_MASK (0xFFFFFF00) + +#define ODROIDXU_GPX_BASE 0x13400000 // GPX0,1,2,3 +#define ODROIDXU_GPA_BASE 0x14010000 // GPA0,1,2, GPB0,1,2,3,4 + +#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_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_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_END 39 + +#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_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_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_END 214 + +#define piAinNode0_xu "/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw" +#define piAinNode1_xu "/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw" + +static int piModel = PI_MODEL_UNKNOWN; + +// Use ODROID-C Model +static int piThreadIrqMode = FALSE; static int sysFdData [64] = { - -1, + -1, -1, -1, -1, -1, -1, -1, -1, // 0...7 + -1, -1, -1, -1, -1, -1, -1, -1, // 8...15 + -1, -1, -1, -1, -1, -1, -1, -1, // 16...23 + -1, -1, -1, -1, -1, -1, -1, -1, // 24...31 + -1, -1, -1, -1, -1, -1, -1, -1, // 32...39 + -1, -1, -1, -1, -1, -1, -1, -1, // 40...47 + -1, -1, -1, -1, -1, -1, -1, -1, // 48...55 + -1, -1, -1, -1, -1, -1, -1, -1, // 56...63 }; static int sysFdIrqType [64] = { - 0, + -1, -1, -1, -1, -1, -1, -1, -1, // 0...7 + -1, -1, -1, -1, -1, -1, -1, -1, // 8...15 + -1, -1, -1, -1, -1, -1, -1, -1, // 16...23 + -1, -1, -1, -1, -1, -1, -1, -1, // 24...31 + -1, -1, -1, -1, -1, -1, -1, -1, // 32...39 + -1, -1, -1, -1, -1, -1, -1, -1, // 40...47 + -1, -1, -1, -1, -1, -1, -1, -1, // 48...55 + -1, -1, -1, -1, -1, -1, -1, -1, // 56...63 }; +// +// sysfs FD offset +// +static int gpioFdOffsetXU34(int pin) +{ + int offset = -1; + + switch(pin) { + case GPIO_X1_START...GPIO_X1_END: offset = GPIO_X1_START + 0; break; + case GPIO_X2_START...GPIO_X2_END: offset = GPIO_X2_START + 8; break; + case GPIO_X3_START...GPIO_X3_END: offset = GPIO_X3_START + 16; break; + case GPIO_A0_START...GPIO_A0_END: offset = GPIO_A0_START + 24; break; + case GPIO_A2_START...GPIO_A2_END: offset = GPIO_A2_START + 32; break; + case GPIO_B3_START...GPIO_B3_END: offset = GPIO_B3_START + 40; break; + default : offset = -1; break; + } + return offset; +} + // // offset to the GPIO Set regsiter // 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(piModel == PI_MODEL_ODROIDXU_34) { + 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); + default: + break; + } + } + else { + 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; + } return -1; } @@ -628,8 +730,28 @@ 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(piModel == PI_MODEL_ODROIDXU_34) { + 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); + default: + break; + } + } + else { + 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; + } return -1; } @@ -650,8 +772,28 @@ 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(piModel == PI_MODEL_ODROIDXU_34) { + 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); + default: + break; + } + } + else { + 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; + } return -1; } @@ -661,8 +803,28 @@ 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(piModel == PI_MODEL_ODROIDXU_34) { + 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); + default: + break; + } + } + else { + 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; + } return -1; } @@ -672,8 +834,28 @@ 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(piModel == PI_MODEL_ODROIDXU_34) { + 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); + default: + break; + } + } + else { + 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; + } return -1; } @@ -727,6 +909,68 @@ static int physToGpioOdroidC [64] = -1, -1, -1, -1, -1, -1, } ; +// +// pinToGpio: +// Take a Wiring pin (0 through X) and re-map it to the ODROIDXU_GPIO pin +// +static int pinToGpioOdroidXU [64] = { + 174, 173, // 0 | 1 : GPA0.3(UART_0.CTSN), GPA0.2(UART_0.RTSN) + 21, 22, // 2 | 3 : GPX1.5, GPX1.6 + 19, 23, // 4 | 5 : GPX1.3, GPX1.7 + 24, 18, // 6 | 7 : GPX2.0, GPX1.2 + + 209, 210, // 8 | 9 : GPB3.2(I2C_1.SDA), GPB3.3(I2C_1.SCL) + 190, 25, // 10 | 11 : GPA2.5(SPI_1.CSN), GPX2.1 + 192, 191, // 12 | 13 : GPA2.7(SPI_1.MOSI), GPA2.6(SPI_1.MISO) + 189, 172, // 14 | 15 : GPA2.4(SPI_1.SCLK), GPA0.1(UART_0.TXD) + 171, -1, // 16 | 17 : GPA0.0(UART_0.RXD), + -1, -1, // 18 | 19 + -1, 28, // 20 | 21 : , GPX2.4 + 30, 31, // 22 | 23 : GPX2.6, GPX2.7 + -1, -1, // 24 | 25 PWR_ON(INPUT), ADC_0.AIN0 + 29, 33, // 26 | 27 : GPX2.5, GPX3.1 + -1, -1, // 28 | 29 : REF1.8V OUT, ADC_0.AIN3 + 187, 188, // 30 | 31 : GPA2.2(I2C_5.SDA), GPA2.3(I2C_5.SCL) + + // Padding: + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32...47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 48...63 +}; + +// +// physToGpio: +// Take a physical pin (1 through 40) and re-map it to the ODROIDXU_GPIO pin +// +static int physToGpioOdroidXU [64] = +{ + -1, // 0 + -1, -1, // 1 | 2 : 3.3V, 5.0V + 209, -1, // 3 | 4 : GPB3.2(I2C_1.SDA), 5.0V + 210, -1, // 5 | 6 : GPB3.3(I2C_1.SCL), GND + 18, 172, // 7 | 8 : GPX1.2, GPA0.1(UART_0.TXD) + -1, 171, // 9 | 10 : GND, GPA0.0(UART_0.RXD) + 174, 173, // 11 | 12 : GPA0.3(UART_0.CTSN), GPA0.2(UART_0.RTSN) + 21, -1, // 13 | 14 : GPX1.5, GND + 22, 19, // 15 | 16 : GPX1.6, GPX1.3 + -1, 23, // 17 | 18 : 3.3V, GPX1.7 + 192, -1, // 19 | 20 : GPA2.7(SPI_1.MOSI), GND + 191, 24, // 21 | 22 : GPA2.6(SPI_1.MISO), GPX2.0 + 189, 190, // 23 | 24 : GPA2.4(SPI_1.SCLK), GPA2.5(SPI_1.CSN) + -1, 25, // 25 | 26 : GND, GPX2.1 + 187, 188, // 27 | 28 : GPA2.2(I2C_5.SDA), GPA2.4(I2C_5.SCL) + 28, -1, // 29 | 30 : GPX2.4, GND + 30, 29, // 31 | 32 : GPX2.6, GPX2.5 + 31, -1, // 33 | 34 : GPX2.7, GND + -1, 33, // 35 | 36 : PWR_ON(INPUT), GPX3.1 + -1, -1, // 37 | 38 : ADC_0.AIN0, 1.8V REF OUT + -1, -1, // 39 | 40 : GND, AADC_0.AIN3 + + // Not used + -1, -1, -1, -1, -1, -1, -1, -1, // 41...48 + -1, -1, -1, -1, -1, -1, -1, -1, // 49...56 + -1, -1, -1, -1, -1, -1, -1 // 57...63 +} ; + /* * Functions @@ -787,6 +1031,8 @@ int wiringPiFailure (int fatal, const char *message, ...) * * added : * 000c - Model ODROID C, Rev 1.0, 1024M, Hardkernel + * added : + * 0000 - Model ODROID XU3/4, Rev 1.0, 2048M, Hardkernel * * A small thorn is the olde style overvolting - that will add in * 1000000 @@ -868,7 +1114,8 @@ int piBoardRev (void) if (wiringPiDebug) printf ("piboardRev: last4Chars are: \"%s\"\n", c) ; - if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0) || (strcmp (c, "000c") == 0) ) + if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0) || + (strcmp (c, "000c") == 0) || (strcmp (c, "0000") == 0) ) boardRev = 1; else boardRev = 2; @@ -955,6 +1202,9 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) else if (strcmp (c, "000a") == 0) { *model = PI_MODEL_ODROIDC; *rev = PI_VERSION_1; *mem = 1024; *maker = PI_MAKER_HARDKERNEL; } + else if (strcmp (c, "0000") == 0) { + *model = PI_MODEL_ODROIDXU_34; *rev = PI_VERSION_1; *mem = 2048; *maker = PI_MAKER_HARDKERNEL; + } else { *model = 0; *rev = 0; *mem = 0; *maker = 0 ; } @@ -999,8 +1249,8 @@ void setPadDrive (int group, int value) { uint32_t wrVal ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1032,8 +1282,10 @@ int getAlt (int pin) { int fSel, shift, alt ; - if ( piModel == PI_MODEL_ODROIDC ) + if ( piModel == PI_MODEL_ODROIDC ) pin &= 0x7F; + else if( piModel == PI_MODEL_ODROIDXU_34 ) + pin &= 0xFF; else pin &= 63 ; @@ -1044,12 +1296,27 @@ int getAlt (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return 0 ; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC ) { if(pin < 0) return 2; // ALT return (*(gpio + gpioToGPFSELReg(pin)) & (1 << gpioToShiftReg(pin))) ? 0 : 1; } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + + if(pin < 0) return 2; // ALT + + shift = (gpioToShiftReg(pin) * 4); + + if(pin < 100) // GPX0,1,2,3 + fSel = (*(gpio + gpioToGPFSELReg(pin)) & (0xF << shift)); + else // GPA0,1,2, GPB0,1,2,3,4 + fSel = (*(gpio1 + gpioToGPFSELReg(pin)) & (0xF << shift)); + + if(fSel & (0xE << shift)) return 2; + + return (fSel & (0x1 << shift)) ? 1 : 0; + } else { fSel = gpioToGPFSEL [pin] ; shift = gpioToShift [pin] ; @@ -1069,8 +1336,8 @@ int getAlt (int pin) void pwmSetMode (int mode) { - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1093,8 +1360,8 @@ void pwmSetMode (int mode) void pwmSetRange (unsigned int range) { - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1119,8 +1386,8 @@ void pwmSetClock (int divisor) uint32_t pwm_control ; divisor &= 4095 ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1169,8 +1436,8 @@ void gpioClockSet (int pin, int freq) { int divi, divr, divf ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1238,19 +1505,23 @@ struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) int pin ; struct wiringPiNodeStruct *node ; -// Minimum pin base is 128 (ODROID-C) - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC ) { + // Minimum pin base is 128 if (pinBase < 128) - (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 128\n", pinBase) ; + (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 128\n", pinBase) ; + } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + // Minimum pin base is 256 + if (pinBase < 256) + (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 256\n", pinBase) ; + } + else { + // Minimum pin base is 64 + if (pinBase < 64) + (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 64\n", pinBase) ; } - -// Minimum pin base is 64 - - if (pinBase < 64) - (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 64\n", pinBase) ; // Check all pins in-case there is overlap: - for (pin = pinBase ; pin < (pinBase + numPins) ; ++pin) if (wiringPiFindNode (pin) != NULL) (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: Pin %d overlaps with existing definition\n", pin) ; @@ -1307,8 +1578,8 @@ void pinModeAlt (int pin, int mode) { int fSel, shift ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1342,7 +1613,8 @@ void pinMode (int pin, int mode) int origPin = pin ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-board pin { @@ -1360,35 +1632,59 @@ void pinMode (int pin, int mode) shift = gpioToShift [pin] ; if (mode == INPUT) { - if ( piModel == PI_MODEL_ODROIDC ) - *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) | (1 << gpioToShiftReg(pin))); + if ( piModel == PI_MODEL_ODROIDC ) + *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) | (1 << gpioToShiftReg(pin))); + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + shift = (gpioToShiftReg(pin) * 4); + if(pin < 100) + *(gpio + gpioToGPFSELReg(pin)) &= ~(0xF << shift); + else + *(gpio1 + gpioToGPFSELReg(pin)) &= ~(0xF << shift); + } else *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)); // Sets bits to zero = input } else if (mode == OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC ) + if ( piModel == PI_MODEL_ODROIDC ) *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) & ~(1 << gpioToShiftReg(pin))); + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + shift = (gpioToShiftReg(pin) * 4); + if(pin < 100) { + *(gpio + gpioToGPFSELReg(pin)) &= ~(0xF << shift); + *(gpio + gpioToGPFSELReg(pin)) |= (0x1 << shift); + } + else { + *(gpio1 + gpioToGPFSELReg(pin)) &= ~(0xF << shift); + *(gpio1 + gpioToGPFSELReg(pin)) |= (0x1 << shift); + } + } else *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift); } else if (mode == SOFT_PWM_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC ) softPwmCreate (pin, 0, 100); - else softPwmCreate (origPin, 0, 100); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + softPwmCreate (pin, 0, 100); + else + softPwmCreate (origPin, 0, 100); } else if (mode == SOFT_TONE_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC ) softToneCreate (pin); - else softToneCreate (origPin); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + softToneCreate (pin); + else + softToneCreate (origPin); } else if (mode == PWM_TONE_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC ) return; + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + return; pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode pwmSetMode (PWM_MODE_MS) ; } else if (mode == PWM_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC ) return; + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + return; if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin return ; @@ -1404,7 +1700,8 @@ void pinMode (int pin, int mode) } else if (mode == GPIO_CLOCK) { - if ( piModel == PI_MODEL_ODROIDC ) return; + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + return; if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin return ; @@ -1439,7 +1736,8 @@ void pullUpDnControl (int pin, int pud) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin { @@ -1467,15 +1765,47 @@ void pullUpDnControl (int pin, int pud) else // Disable Pull/Pull-down resister *(gpio + gpioToPUENReg(pin)) = (*(gpio + gpioToPUENReg(pin)) & ~(1 << gpioToShiftReg(pin))); } + else if ( piModel == PI_MODEL_ODROIDXU_34) { + int shift = 0; + + // maybe pin mode is not gpio. + if(pin < 0) return; + + shift = (gpioToShiftReg(pin) * 2); + + if(pud) { + if(pin < 100) { + *(gpio + gpioToPUPDReg(pin)) &= ~(0x3 << shift); + if(pud == PUD_UP) + *(gpio + gpioToPUPDReg(pin)) |= (0x3 << shift); + else + *(gpio + gpioToPUPDReg(pin)) |= (0x1 << shift); + } + else { + *(gpio1 + gpioToPUPDReg(pin)) &= ~(0x3 << shift); + if(pud == PUD_UP) + *(gpio1 + gpioToPUPDReg(pin)) |= (0x3 << shift); + else + *(gpio1 + gpioToPUPDReg(pin)) |= (0x1 << shift); + } + } + else { + // Disable Pull/Pull-down resister + if(pin < 100) + *(gpio + gpioToPUPDReg(pin)) &= ~(0x3 << shift); + else + *(gpio1 + gpioToPUPDReg(pin)) &= ~(0x3 << shift); + } + } else { - *(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ; + *(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ; *(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ; *(gpio + GPPUD) = 0 ; delayMicroseconds (5) ; *(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ; } } - else // Extension module + else // Extension module { if ((node = wiringPiFindNode (pin)) != NULL) node->pullUpDnControl (node, pin, pud) ; @@ -1496,17 +1826,36 @@ int digitalRead (int pin) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin { /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode { - if (sysFds [pin] == -1) + int fd_pos = 0; + + if ( piModel == PI_MODEL_ODROIDC ) { + fd_pos = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + int offset = 0; + + offset = gpioFdOffsetXU34(pin); + + if(offset != -1) + fd_pos = pin - offset; + else + fd_pos = 63; + } + else + fd_pos = pin; + + if ( sysFds [fd_pos] == -1) return LOW ; - lseek (sysFds [pin], 0L, SEEK_SET) ; - read (sysFds [pin], &c, 1) ; + lseek (sysFds [fd_pos], 0L, SEEK_SET) ; + read (sysFds [fd_pos], &c, 1) ; return (c == '0') ? LOW : HIGH ; } else if (wiringPiMode == WPI_MODE_PINS) @@ -1516,12 +1865,18 @@ int digitalRead (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return LOW ; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC ) { if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0) return HIGH ; else return LOW ; } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + if (pin < 100) + return *(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW; + else + return *(gpio1 + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW; + } else { if ((*(gpio + gpioToGPLEV [pin]) & (1 << (pin & 31))) != 0) return HIGH ; @@ -1549,18 +1904,37 @@ void digitalWrite (int pin, int value) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin { /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode { - if (sysFds [pin] != -1) + int fd_pos = 0; + + if ( piModel == PI_MODEL_ODROIDC ) { + fd_pos = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + int offset = 0; + + offset = gpioFdOffsetXU34(pin); + + if(offset != -1) + fd_pos = pin - offset; + else + fd_pos = 63; + } + else + fd_pos = pin; + + if (sysFds [fd_pos] != -1) { if (value == LOW) - write (sysFds [pin], "0\n", 2) ; + write (sysFds [fd_pos], "0\n", 2) ; else - write (sysFds [pin], "1\n", 2) ; + write (sysFds [fd_pos], "1\n", 2) ; } return ; } @@ -1571,23 +1945,31 @@ void digitalWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC ) { if (value == LOW) *(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin)); else *(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin)); } - else { - if (value == LOW) - *(gpio + gpioToGPCLR [pin]) = 1 << (pin & 31) ; - else - *(gpio + gpioToGPSET [pin]) = 1 << (pin & 31) ; + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + if (pin < 100) { + if (value == LOW) + *(gpio + gpioToGPLEVReg(pin)) &= ~(1 << gpioToShiftReg(pin)); + else + *(gpio + gpioToGPLEVReg(pin)) |= (1 << gpioToShiftReg(pin)); + } + else { + if (value == LOW) + *(gpio1 + gpioToGPLEVReg(pin)) &= ~(1 << gpioToShiftReg(pin)); + else + *(gpio1 + gpioToGPLEVReg(pin)) |= (1 << gpioToShiftReg(pin)); + } } } else { if ((node = wiringPiFindNode (pin)) != NULL) - node->digitalWrite (node, pin, value) ; + node->digitalWrite (node, pin, value) ; } } @@ -1603,7 +1985,8 @@ void pwmWrite (int pin, int value) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin { @@ -1614,8 +1997,8 @@ void pwmWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } else @@ -1642,7 +2025,7 @@ int analogRead (int pin) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned char value[5] = {0,}; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) { if(pin < 2) { if (adcFds [pin] == -1) return 0; @@ -1689,8 +2072,8 @@ void pwmToneWrite (int pin, int freq) { int range ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1724,8 +2107,8 @@ void digitalWriteByte (int value) int mask = 1 ; int pin ; - if ( piModel == PI_MODEL_ODROIDC ) { - fprintf (stderr, "%s : Unsupport function on ODROID-C model\n", __func__); + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) { + fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); exit (EXIT_FAILURE) ; } @@ -1790,11 +2173,27 @@ int waitForInterrupt (int pin, int mS) polls.fd = fd ; - #if defined(GPIO_IRQ_THREAD) - polls.events = POLLIN ; // Normal data! - #else + if(piThreadIrqMode) + polls.events = POLLIN ; // Normal data! + else polls.events = POLLPRI ; // Urgent data! - #endif + } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + int offset = 0; + + offset = gpioFdOffsetXU34(pin); + + if(offset != -1) + fd_base = pin - offset; + else + fd_base = 63; + + if ((fd = sysFds [fd_base & 63]) == -1) + return -2 ; + + // Setup poll structure + polls.fd = fd ; + polls.events = POLLPRI ; // Urgent data! } else { if ((fd = sysFds [pin]) == -1) @@ -1817,8 +2216,7 @@ int waitForInterrupt (int pin, int mS) (void)read (fd, &c, 1) ; lseek (fd, 0, SEEK_SET) ; -#if defined(GPIO_IRQ_THREAD) - if ( piModel == PI_MODEL_ODROIDC ) + if ( piModel == PI_MODEL_ODROIDC && piThreadIrqMode) { if ( sysFdData[fd_base] != c ) { sysFdData[fd_base] = c; @@ -1829,7 +2227,7 @@ int waitForInterrupt (int pin, int mS) usleep(100); goto wait; } -#endif + return x ; } @@ -1851,7 +2249,7 @@ static void *interruptHandler (void *arg) myPin = pinPass ; pinPass = -1 ; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) { int gpioPin, fd_base; /**/ if (wiringPiMode == WPI_MODE_UNINITIALISED) @@ -1863,7 +2261,18 @@ static void *interruptHandler (void *arg) else gpioPin = myPin ; - fd_base = gpioPin < GPIO_PIN_BASE ? 0 : gpioPin - GPIO_PIN_BASE; + if ( piModel == PI_MODEL_ODROIDC ) + fd_base = gpioPin < GPIO_PIN_BASE ? 0 : gpioPin - GPIO_PIN_BASE; + else { + int offset = 0; + + offset = gpioFdOffsetXU34(gpioPin); + + if(offset != -1) + fd_base = gpioPin - offset; + else + fd_base = 63; + } for (;;) if (waitForInterrupt (myPin, -1) > 0) { @@ -1912,6 +2321,10 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) if ((pin < 0) || (pin > 128)) return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-128 (%d)\n", pin) ; } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + if ((pin < 0) || (pin > 256)) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-256 (%d)\n", pin) ; + } else { if ((pin < 0) || (pin > 63)) return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-63 (%d)\n", pin) ; @@ -1959,17 +2372,48 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) // Now pre-open the /sys/class node - but it may already be open if // we are in Sys mode... - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC ) { int fd_base = bcmGpioPin < GPIO_PIN_BASE ? 0 : bcmGpioPin - GPIO_PIN_BASE; if (sysFds [fd_base] == -1) { - sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + if(piThreadIrqMode) + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + else + sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", bcmGpioPin) ; + if ((sysFds [fd_base] = open (fName, O_RDWR)) < 0) return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; sysFdIrqType [fd_base] = mode; } + // Clear any initial pending interrupt + + ioctl (sysFds [fd_base], FIONREAD, &count) ; + for (i = 0 ; i < count ; ++i) + read (sysFds [fd_base], &c, 1) ; + + sysFdData[fd_base] = c; + isrFunctions [fd_base] = function ; + } + else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + int fd_base = 0, offset = 0; + + offset = gpioFdOffsetXU34(bcmGpioPin); + + if(offset != -1) + fd_base = bcmGpioPin - offset; + else + fd_base = 63; + + if (sysFds [fd_base] == -1) + { + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + + if ((sysFds [fd_base] = open (fName, O_RDWR)) < 0) + return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; + } + // Clear any initial pending interrupt ioctl (sysFds [fd_base], FIONREAD, &count) ; @@ -2179,6 +2623,34 @@ int wiringPiSetup (void) adcFds [0] = open (piAinNode0, O_RDONLY) ; adcFds [1] = open (piAinNode1, O_RDONLY) ; + // Check aml_gpio directory for gpio irq + { + struct stat s; + + if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; + else piThreadIrqMode = FALSE; + } + } + else if ( model == PI_MODEL_ODROIDXU_34 ) { + pinToGpio = pinToGpioOdroidXU; + physToGpio = physToGpioOdroidXU; + + // GPIO: + //#define ODROIDXU_GPX_BASE 0x13400000 // GPX0,1,2,3 + gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, ODROIDXU_GPX_BASE) ; + if ((int32_t)gpio == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; + + //#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, ODROIDXU_GPA_BASE) ; + if ((int32_t)gpio1 == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; + + // ADC + // ADC Fds[0] = ("/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw") + // ADC Fds[1] = ("/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw") + adcFds [0] = open (piAinNode0_xu, O_RDONLY) ; + adcFds [1] = open (piAinNode1_xu, O_RDONLY) ; } else { // GPIO: @@ -2304,7 +2776,7 @@ int wiringPiSetupSys (void) { int boardRev ; int model, rev, mem, maker, overVolted ; - int pin ; + int pin, offset; char fName [128] ; if (getenv (ENV_DEBUG) != NULL) @@ -2325,9 +2797,21 @@ int wiringPiSetupSys (void) // Open and scan the directory, looking for exported GPIOs, and pre-open // the 'value' interface to speed things up for later + // Check aml_gpio directory for gpio irq + { + struct stat s; + + if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; + else piThreadIrqMode = FALSE; + } + for (pin = GPIO_PIN_BASE ; pin < GPIO_PIN_BASE + 64 ; ++pin) { - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + if(piThreadIrqMode) + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + else + sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin) ; + sysFds [pin - GPIO_PIN_BASE] = open (fName, O_RDWR) ; } @@ -2336,6 +2820,27 @@ int wiringPiSetupSys (void) adcFds [0] = open (piAinNode0, O_RDONLY) ; adcFds [1] = open (piAinNode1, O_RDONLY) ; } + else if ( model == PI_MODEL_ODROIDXU_34 ) { + pinToGpio = pinToGpioOdroidXU ; + physToGpio = physToGpioOdroidXU ; + +// Open and scan the directory, looking for exported GPIOs, and pre-open +// the 'value' interface to speed things up for later + for (pin = 0; pin < 255; pin++) { + + offset = gpioFdOffsetXU34(pin); + + if(offset != -1) { + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin); + sysFds[pin - offset] = open (fName, O_RDWR); + } + } + // ADC + // ADC Fds[0] = ("/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw") + // ADC Fds[1] = ("/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw") + adcFds [0] = open (piAinNode0, O_RDONLY) ; + adcFds [1] = open (piAinNode1, O_RDONLY) ; + } else { boardRev = piBoardRev () ; diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 185b333..786ff7e 100755 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -77,6 +77,7 @@ #define PI_MODEL_CM 4 #define PI_MODEL_AP 5 #define PI_MODEL_ODROIDC 6 +#define PI_MODEL_ODROIDXU_34 7 #define PI_VERSION_UNKNOWN 0 #define PI_VERSION_1 1 @@ -90,7 +91,7 @@ #define PI_MAKER_QISDA 3 #define PI_MAKER_HARDKERNEL 4 -extern const char *piModelNames [7] ; +extern const char *piModelNames [8] ; extern const char *piRevisionNames [5] ; extern const char *piMakerNames [5] ; diff --git a/wiringPi/wiringPiI2C.c b/wiringPi/wiringPiI2C.c index ab6938b..b8493ac 100755 --- a/wiringPi/wiringPiI2C.c +++ b/wiringPi/wiringPiI2C.c @@ -223,8 +223,10 @@ int wiringPiI2CSetup (const int devId) piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if ( model == PI_MODEL_ODROIDC ) + if ( model == PI_MODEL_ODROIDC ) device = "/dev/i2c-1" ; + else if ( model == PI_MODEL_ODROIDXU_34 ) + device = "/dev/i2c-3" ; else { rev = piBoardRev () ; From 84e3776c519fb90de6fe31f143f3d6ade730698e Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Mon, 10 Aug 2015 19:28:09 +0900 Subject: [PATCH 05/16] wiringPi : i2c/spi module load fix. Change-Id: I5496cb9aee274ce9c81331a35572d6aec7356b0c --- gpio/gpio.c | 112 ++++++++++++++++++++++++++++++++++------- wiringPi/wiringPi.c | 10 ++-- wiringPi/wiringPiSPI.c | 24 ++++++++- 3 files changed, 121 insertions(+), 25 deletions(-) mode change 100644 => 100755 wiringPi/wiringPiSPI.c diff --git a/gpio/gpio.c b/gpio/gpio.c index 9b14c0c..cc5a1aa 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -209,28 +209,104 @@ static void doLoad (int argc, char *argv []) else _doLoadUsage (argv) ; - if (!moduleLoaded (module1)) - { - sprintf (cmd, "modprobe %s%s", module1, args1) ; - system (cmd) ; - } - - if (!moduleLoaded (module2)) - { - sprintf (cmd, "modprobe %s%s", module2, args2) ; - system (cmd) ; + if (piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + if (strcasecmp (argv [2], "i2c") == 0) { + if (piModel == PI_MODEL_ODROIDC) { + module1 = "aml-i2c"; + file1 = "/dev/i2c-1"; + + if (!moduleLoaded(module1)) { + sprintf (cmd, "modprobe %s", module1) ; + system (cmd) ; + } + } + else + file1 = "/dev/i2c-3"; + + sleep (1) ; // To let things get settled + changeOwner (argv [0], file1) ; + } + else { + if (piModel == PI_MODEL_ODROIDC) { + file1 = "/dev/spidev0.0"; + module1 = "spidev"; + module2 = "spicc"; + if (!moduleLoaded(module1)) { + sprintf (cmd, "modprobe %s%s", module1, args1) ; + system (cmd) ; + } + if (!moduleLoaded(module2)) { + sprintf (cmd, "modprobe %s", module2) ; + 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) ; + } + else { + module1 = "spidev"; + file1 = "/dev/spidev1.0"; + + if (!moduleLoaded (module1)) + { + fprintf (stderr, "%s: Unable to load %s\n", argv [0], module1) ; + fprintf (stderr, "\nYou need modified dtb file for spidev.\n"); + fprintf (stderr, "\nstep 1)\n"); + fprintf (stderr, " - install device-tree-compiler.\n"); + fprintf (stderr, " sudo apt-get install device-tree-compiler\n"); + fprintf (stderr, "\nstep 2)\n"); + fprintf (stderr, " - modified dtb file.\n"); + fprintf (stderr, " sudo -s\n"); + fprintf (stderr, " fdtput -c /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev\n"); + fprintf (stderr, " fdtput -t s /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev compatible \"spidev\"\n"); + fprintf (stderr, " fdtput -t x /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev reg 0\n"); + fprintf (stderr, " fdtput -t i /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev spi-max-frequency 20000000\n"); + fprintf (stderr, " fdtput -c /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev/controller-data\n"); + fprintf (stderr, " fdtput -t x /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev/controller-data cs-gpio 0x44, 0x5, 0x0\n"); + fprintf (stderr, " fdtput -t x /media/boot/exynos5422-odroidxu3.dtb /spi@12d30000/spidev/controller-data samsung,spi-feedback-delay 0\n"); + fprintf (stderr, "\nstep 3)\n"); + fprintf (stderr, " - reboot system.\n"); + fprintf (stderr, " sudo reboot\n"); + fprintf (stderr, "\nstep 4)\n"); + fprintf (stderr, " - check your SPI node.\n"); + fprintf (stderr, " ls /dev/spidev1.0\n"); + // fdtput + exit (1) ; + } + + sleep (1) ; // To let things get settled + changeOwner (argv [0], file1) ; + } + } } + else { + if (!moduleLoaded (module1)) + { + sprintf (cmd, "modprobe %s%s", module1, args1) ; + system (cmd) ; + } - if (!moduleLoaded (module2)) - { - fprintf (stderr, "%s: Unable to load %s\n", argv [0], module2) ; - exit (1) ; - } + if (!moduleLoaded (module2)) + { + sprintf (cmd, "modprobe %s%s", module2, args2) ; + system (cmd) ; + } - sleep (1) ; // To let things get settled + 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) ; + changeOwner (argv [0], file1) ; + changeOwner (argv [0], file2) ; + } } diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index b3242b5..b7e3cd7 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -210,7 +210,7 @@ const char *piModelNames [8] = "Model B+", "Compute Module", "Model A+", - "ODROID-C", + "ODROID-C1/C1+", "ODROID-XU3/4", } ; @@ -1030,9 +1030,9 @@ int wiringPiFailure (int fatal, const char *message, ...) * 0012 - Model A+ Rev 1.2, 256MB, Sony * * added : - * 000c - Model ODROID C, Rev 1.0, 1024M, Hardkernel + * 000a - Model ODROID C1/C1+, Rev 1.0, 1024M, Hardkernel * added : - * 0000 - Model ODROID XU3/4, Rev 1.0, 2048M, Hardkernel + * 0100 - Model ODROID XU3/4, Rev 1.0, 2048M, Hardkernel * * A small thorn is the olde style overvolting - that will add in * 1000000 @@ -1115,7 +1115,7 @@ int piBoardRev (void) printf ("piboardRev: last4Chars are: \"%s\"\n", c) ; if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0) || - (strcmp (c, "000c") == 0) || (strcmp (c, "0000") == 0) ) + (strcmp (c, "000a") == 0) || (strcmp (c, "0100") == 0) ) boardRev = 1; else boardRev = 2; @@ -1202,7 +1202,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) else if (strcmp (c, "000a") == 0) { *model = PI_MODEL_ODROIDC; *rev = PI_VERSION_1; *mem = 1024; *maker = PI_MAKER_HARDKERNEL; } - else if (strcmp (c, "0000") == 0) { + else if (strcmp (c, "0100") == 0) { *model = PI_MODEL_ODROIDXU_34; *rev = PI_VERSION_1; *mem = 2048; *maker = PI_MAKER_HARDKERNEL; } else { diff --git a/wiringPi/wiringPiSPI.c b/wiringPi/wiringPiSPI.c old mode 100644 new mode 100755 index 215a027..575cd04 --- a/wiringPi/wiringPiSPI.c +++ b/wiringPi/wiringPiSPI.c @@ -40,6 +40,7 @@ const static char *spiDev0 = "/dev/spidev0.0" ; const static char *spiDev1 = "/dev/spidev0.1" ; +const static char *spiDev0_XU = "/dev/spidev1.0"; const static uint8_t spiMode = 0 ; const static uint8_t spiBPW = 8 ; const static uint16_t spiDelay = 0 ; @@ -95,11 +96,30 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len) int wiringPiSPISetup (int channel, int speed) { int fd ; + int model, rev, mem, maker, overVolted ; + + piBoardId (&model, &rev, &mem, &maker, &overVolted) ; channel &= 1 ; - if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0) - return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; + if (model == PI_MODEL_ODROIDXU_34) { + if (channel) + return wiringPiFailure (WPI_ALMOST, "ODROID-XU3/4 cannot support spi-channel 1.\n") ; + + if ((fd = open (spiDev0_XU, O_RDWR)) < 0) + return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; + } + else if (model == PI_MODEL_ODROIDC) { + if (channel) + return wiringPiFailure (WPI_ALMOST, "ODROID-C1/C1+ cannot support spi-channel 1.\n") ; + + if ((fd = open (spiDev0, O_RDWR)) < 0) + return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; + } + else { + if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0) + return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; + } spiSpeeds [channel] = speed ; spiFds [channel] = fd ; From 06f3dc41672edc69d36da59321809b7cfe98beb1 Mon Sep 17 00:00:00 2001 From: bwall Date: Wed, 24 Feb 2016 09:32:51 -0800 Subject: [PATCH 06/16] Force path environmental variable before calling modprobe --- gpio/gpio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gpio/gpio.c b/gpio/gpio.c index cc5a1aa..58aacd6 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -216,7 +216,7 @@ static void doLoad (int argc, char *argv []) file1 = "/dev/i2c-1"; if (!moduleLoaded(module1)) { - sprintf (cmd, "modprobe %s", module1) ; + sprintf (cmd, "PATH=/bin:/usr/bin:/sbin:/usr/local/bin modprobe %s", module1) ; system (cmd) ; } } @@ -232,11 +232,11 @@ static void doLoad (int argc, char *argv []) module1 = "spidev"; module2 = "spicc"; if (!moduleLoaded(module1)) { - sprintf (cmd, "modprobe %s%s", module1, args1) ; + sprintf (cmd, "PATH=/bin:/usr/bin:/sbin:/usr/local/bin modprobe %s%s", module1, args1) ; system (cmd) ; } if (!moduleLoaded(module2)) { - sprintf (cmd, "modprobe %s", module2) ; + sprintf (cmd, "PATH=/bin:/usr/bin:/sbin:/usr/local/bin modprobe %s", module2) ; system (cmd) ; } if (!moduleLoaded (module2)) @@ -287,13 +287,13 @@ static void doLoad (int argc, char *argv []) else { if (!moduleLoaded (module1)) { - sprintf (cmd, "modprobe %s%s", module1, args1) ; + sprintf (cmd, "PATH=/bin:/usr/bin:/sbin:/usr/local/bin modprobe %s%s", module1, args1) ; system (cmd) ; } if (!moduleLoaded (module2)) { - sprintf (cmd, "modprobe %s%s", module2, args2) ; + sprintf (cmd, "PATH=/bin:/usr/bin:/sbin:/usr/local/bin modprobe %s%s", module2, args2) ; system (cmd) ; } From dea9b07927d43ed7a1a6aecd35955ae5979222d5 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Thu, 25 Feb 2016 15:21:46 +0900 Subject: [PATCH 07/16] wiringPi : modified for ODROID-C2 support. --- devLib/piFaceOld.c | 178 -------------- gpio/gpio.c | 30 ++- gpio/readall.c | 112 ++++++++- wiringPi/wiringPi.c | 522 +++++++++++++++++++++++++++++++++-------- wiringPi/wiringPi.h | 3 +- wiringPi/wiringPiI2C.c | 4 +- wiringPi/wiringPiSPI.c | 3 + 7 files changed, 559 insertions(+), 293 deletions(-) delete mode 100644 devLib/piFaceOld.c diff --git a/devLib/piFaceOld.c b/devLib/piFaceOld.c deleted file mode 100644 index 1b1c0dd..0000000 --- a/devLib/piFaceOld.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * piFace.: - * Arduino compatable (ish) Wiring library for the Raspberry Pi - * Copyright (c) 2012-2013 Gordon Henderson - * - * This file to interface with the PiFace peripheral device which - * has an MCP23S17 GPIO device connected via the SPI bus. - *********************************************************************** - * 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 "../wiringPi/mcp23x0817.h" - -#include "piFace.h" - -#define PIFACE_SPEED 4000000 -#define PIFACE_DEVNO 0 - - - -/* - * writeByte: - * Write a byte to a register on the MCP23S17 on the SPI bus. - ********************************************************************************* - */ - -static void writeByte (uint8_t reg, uint8_t data) -{ - uint8_t spiData [4] ; - - spiData [0] = CMD_WRITE ; - spiData [1] = reg ; - spiData [2] = data ; - - wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ; -} - -/* - * readByte: - * Read a byte from a register on the MCP23S17 on the SPI bus. - ********************************************************************************* - */ - -static uint8_t readByte (uint8_t reg) -{ - uint8_t spiData [4] ; - - spiData [0] = CMD_READ ; - spiData [1] = reg ; - - wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ; - - return spiData [2] ; -} - - -/* - * myDigitalWrite: - * Perform the digitalWrite function on the PiFace board - ********************************************************************************* - */ - -void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value) -{ - uint8_t mask, old ; - - pin -= node->pinBase ; - mask = 1 << pin ; - old = readByte (MCP23x17_GPIOA) ; - - if (value == 0) - old &= (~mask) ; - else - old |= mask ; - - writeByte (MCP23x17_GPIOA, old) ; -} - - -/* - * myDigitalRead: - * Perform the digitalRead function on the PiFace board - ********************************************************************************* - */ - -int myDigitalRead (struct wiringPiNodeStruct *node, int pin) -{ - uint8_t mask, reg ; - - mask = 1 << ((pin - node->pinBase) & 7) ; - - if (pin < 8) - reg = MCP23x17_GPIOB ; // Input regsiter - else - reg = MCP23x17_OLATA ; // Output latch regsiter - - if ((readByte (reg) & mask) != 0) - return HIGH ; - else - return LOW ; -} - - -/* - * myPullUpDnControl: - * Perform the pullUpDnControl function on the PiFace board - ********************************************************************************* - */ - -void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud) -{ - uint8_t mask, old ; - - mask = 1 << (pin - node->pinBase) ; - old = readByte (MCP23x17_GPPUB) ; - - if (pud == 0) - old &= (~mask) ; - else - old |= mask ; - - writeByte (MCP23x17_GPPUB, old) ; -} - - -/* - * piFaceSetup - * Setup the SPI interface and initialise the MCP23S17 chip - * We create one node with 16 pins - each if the first 8 pins being read - * and write - although the operations actually go to different - * hardware ports. The top 8 let you read the state of the output register. - ********************************************************************************* - */ - -int piFaceSetup (const int pinBase) -{ - int x ; - struct wiringPiNodeStruct *node ; - - if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0) - return x ; - -// Setup the MCP23S17 - - writeByte (MCP23x17_IOCON, IOCON_INIT) ; - writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs - writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs - - node = wiringPiNewNode (pinBase, 16) ; - node->digitalRead = myDigitalRead ; - node->digitalWrite = myDigitalWrite ; - node->pullUpDnControl = myPullUpDnControl ; - - return 0 ; -} diff --git a/gpio/gpio.c b/gpio/gpio.c index cc5a1aa..bab4662 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -53,7 +53,7 @@ extern void doPins (void) ; # define FALSE (1==2) #endif -#define VERSION "2.30" +#define VERSION "2.31" #define PI_USB_POWER_CONTROL 38 #define I2CDETECT "/usr/sbin/i2cdetect" @@ -209,24 +209,34 @@ static void doLoad (int argc, char *argv []) else _doLoadUsage (argv) ; - if (piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { + if (piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { if (strcasecmp (argv [2], "i2c") == 0) { - if (piModel == PI_MODEL_ODROIDC) { + if (piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2) { module1 = "aml-i2c"; file1 = "/dev/i2c-1"; + file2 = "/dev/i2c-2"; if (!moduleLoaded(module1)) { sprintf (cmd, "modprobe %s", module1) ; system (cmd) ; } } - else - file1 = "/dev/i2c-3"; + else { + file1 = "/dev/i2c-4"; /* i2c smbus : 0x12c70000 */ + file2 = "/dev/i2c-1"; /* hsi2c : 0x12cb0000 */ + } sleep (1) ; // To let things get settled changeOwner (argv [0], file1) ; + changeOwner (argv [0], file2) ; } else { + if (piModel == PI_MODEL_ODROIDC2) { + fprintf (stderr, "ODROID-C2 : H/W SPI not support!\n") ; + return; + } if (piModel == PI_MODEL_ODROIDC) { file1 = "/dev/spidev0.0"; module1 = "spidev"; @@ -753,8 +763,10 @@ static void doReset (char *progName) /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B)) endPin = 16 ; - else if ((model == PI_MODEL_BP) || (model == PI_MODEL_ODROIDC) - || (model == PI_MODEL_ODROIDXU_34)) + else if ((model == PI_MODEL_BP) || + (model == PI_MODEL_ODROIDC) || + (model == PI_MODEL_ODROIDC2) || + (model == PI_MODEL_ODROIDXU_34)) endPin = 39 ; else if (model == PI_MODEL_CM) { @@ -1322,7 +1334,9 @@ int main (int argc, char *argv []) printf (" projects@drogon.net\n") ; printf ("with a copy of your /proc/cpuinfo if possible\n") ; } - else if (model == PI_MODEL_ODROIDC || model == PI_MODEL_ODROIDXU_34) + else if ( model == PI_MODEL_ODROIDC || + model == PI_MODEL_ODROIDXU_34 || + model == PI_MODEL_ODROIDC2 ) { printf ("Hardkernel ODROID Details:\n") ; printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s\n", diff --git a/gpio/readall.c b/gpio/readall.c index 052aa06..fa3cfe0 100755 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -177,6 +177,66 @@ static char *physNamesOdroidc [64] = NULL,NULL,NULL, } ; +static char *physNamesOdroidc2_Rev1_1 [64] = +{ + NULL, + + " 3.3v", "5v ", + " SDA.1", "5V ", + " SCL.1", "0v ", + "GPIO.249", "TxD1 ", + " 0v", "RxD1 ", + "GPIO.247", "GPIO.238", + "GPIO.239", "0v ", + "GPIO.237", "GPIO.236", + " 3.3v", "GPIO.233", + "GPIO.235", "0v ", + "GPIO.232", "GPIO.231", + "GPIO.230", "GPIO.229", + " 0v", "GPIO.225", + " SDA.2", "SCL.2 ", + "GPIO.228", "0v ", + "GPIO.219", "GPIO.224", + "GPIO.234", "0v ", + "GPIO.214", "GPIO.218", + " AIN.1", "1v8 ", + " 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 char *physNamesOdroidc2_Rev1_0 [64] = +{ + NULL, + + " 3.3v", "5v ", + " SDA.1", "5V ", + " SCL.1", "0v ", + "GPIO.214", "--------", + " 0v", "--------", + "GPIO.219", "GPIO.218", + "GPIO.247", "0v ", + "--------", "GPIO.235", + " 3.3v", "GPIO.233", + "GPIO.238", "0v ", + "GPIO.237", "GPIO.234", + "GPIO.236", "GPIO.248", + " 0v", "GPIO.249", + " SDA.2", "SCL.2 ", + "GPIO.232", "0v ", + "GPIO.231", "GPIO.230", + "GPIO.239", "0v ", + "GPIO.228", "GPIO.229", + " AIN.1", "1v8 ", + " 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 char *physNamesOdroidXU [64] = { NULL, @@ -364,7 +424,7 @@ void piPlusReadall (int model) printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ; } -static void readallPhysOdroidC (int physPin) +static void readallPhysOdroidC (int physPin, int model, int rev) { int pin ; @@ -373,7 +433,14 @@ static void readallPhysOdroidC (int physPin) else printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ; - printf (" | %s", physNamesOdroidc [physPin]) ; + if (model == PI_MODEL_ODROIDC) + printf (" | %s", physNamesOdroidc [physPin]) ; + else { + if (rev == PI_VERSION_1) + printf (" | %s", physNamesOdroidc2_Rev1_0 [physPin]) ; + else + printf (" | %s", physNamesOdroidc2_Rev1_1 [physPin]) ; + } if (physToWpi [physPin] == -1) printf (" | | ") ; @@ -386,8 +453,13 @@ static void readallPhysOdroidC (int physPin) else pin = physToWpi [physPin] ; - printf (" | %4s", alts [getAlt (pin)]) ; - printf (" | %d", digitalRead (pin)) ; + if( physPinToGpio (physPin) == -1 ) { + printf (" | | ") ; + } + else { + printf (" | %4s", alts [getAlt (pin)]) ; + printf (" | %d", digitalRead (pin)) ; + } } // Pin numbers: @@ -409,11 +481,23 @@ static void readallPhysOdroidC (int physPin) else pin = physToWpi [physPin] ; - printf (" | %d", digitalRead (pin)) ; - printf (" | %-4s", alts [getAlt (pin)]) ; + if (physPinToGpio (physPin) == -1) { + printf (" | | ") ; + } + else { + printf (" | %d", digitalRead (pin)) ; + printf (" | %-4s", alts [getAlt (pin)]) ; + } } - printf (" | %-6s", physNamesOdroidc [physPin]) ; + if (model == PI_MODEL_ODROIDC) + printf (" | %-6s", physNamesOdroidc [physPin]) ; + else { + if (rev == PI_VERSION_1) + printf (" | %-6s", physNamesOdroidc2_Rev1_0 [physPin]) ; + else + printf (" | %-6s", physNamesOdroidc2_Rev1_1 [physPin]) ; + } if (physPinToGpio (physPin) == -1) printf (" | | ") ; @@ -423,16 +507,20 @@ static void readallPhysOdroidC (int physPin) printf (" |\n") ; } -void ReadallOdroidC (void) +void ReadallOdroidC (int model, int rev) { int pin ; char *type ; - printf (" +------+-----+----------+------+- Model ODROID-C -+------+----------+-----+------+\n") ; + if(model == PI_MODEL_ODROIDC2) + printf (" +------+-----+----------+------+ Model ODROID-C2 +------+----------+-----+------+\n") ; + else + printf (" +------+-----+----------+------+- Model ODROID-C -+------+----------+-----+------+\n") ; + printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n") ; printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; for (pin = 1 ; pin <= 40 ; pin += 2) - readallPhysOdroidC (pin) ; + readallPhysOdroidC (pin, model, rev) ; printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n") ; } @@ -526,8 +614,8 @@ void doReadall (void) piPlusReadall (model) ; else if (model == PI_MODEL_CM) cmReadall () ; - else if (model == PI_MODEL_ODROIDC) - ReadallOdroidC (); + else if (model == PI_MODEL_ODROIDC || model == PI_MODEL_ODROIDC2) + ReadallOdroidC (model, rev); else if (model == PI_MODEL_ODROIDXU_34) ReadallOdroidXU(); else diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index b7e3cd7..d0f45f2 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -202,7 +202,7 @@ static volatile uint32_t *timerIrqRaw ; // and PI_VERSION_X defines in wiringPi.h // Only intended for the gpio command - use at your own risk! -const char *piModelNames [8] = +const char *piModelNames [9] = { "Unknown", "Model A", @@ -212,6 +212,7 @@ const char *piModelNames [8] = "Model A+", "ODROID-C1/C1+", "ODROID-XU3/4", + "ODROID-C2", } ; const char *piRevisionNames [5] = @@ -601,6 +602,33 @@ static int adcFds [2] = { -1, -1, } ; +// +// For ODROID-C2 Board +// +#define ODROIDC2_GPIO_MASK (0xFFFFFF00) +#define ODROIDC2_GPIO_BASE 0xC8834000 + +#define C2_GPIO_PIN_BASE 136 +#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 +#define C2_GPIOX_INP_REG_OFFSET 0x11A +#define C2_GPIOX_PUPD_REG_OFFSET 0x13E +#define C2_GPIOX_PUEN_REG_OFFSET 0x14C + +#define C2_GPIOY_FSEL_REG_OFFSET 0x10F +#define C2_GPIOY_OUTP_REG_OFFSET 0x110 +#define C2_GPIOY_INP_REG_OFFSET 0x111 +#define C2_GPIOY_PUPD_REG_OFFSET 0x13B +#define C2_GPIOY_PUEN_REG_OFFSET 0x149 + +#define C2_piAinNode0 "/sys/class/saradc/ch0" +#define C2_piAinNode1 "/sys/class/saradc/ch1" + // // For ODROID-XU3/4 Board // @@ -683,13 +711,13 @@ static int gpioFdOffsetXU34(int pin) int offset = -1; switch(pin) { - case GPIO_X1_START...GPIO_X1_END: offset = GPIO_X1_START + 0; break; - case GPIO_X2_START...GPIO_X2_END: offset = GPIO_X2_START + 8; break; - case GPIO_X3_START...GPIO_X3_END: offset = GPIO_X3_START + 16; break; - case GPIO_A0_START...GPIO_A0_END: offset = GPIO_A0_START + 24; break; - case GPIO_A2_START...GPIO_A2_END: offset = GPIO_A2_START + 32; break; - case GPIO_B3_START...GPIO_B3_END: offset = GPIO_B3_START + 40; break; - default : offset = -1; break; + case GPIO_X1_START...GPIO_X1_END: offset = (pin - GPIO_X1_START) + 0; break; + case GPIO_X2_START...GPIO_X2_END: offset = (pin - GPIO_X2_START) + 8; break; + case GPIO_X3_START...GPIO_X3_END: offset = (pin - GPIO_X3_START) + 16; break; + case GPIO_A0_START...GPIO_A0_END: offset = (pin - GPIO_A0_START) + 24; break; + case GPIO_A2_START...GPIO_A2_END: offset = (pin - GPIO_A2_START) + 32; break; + case GPIO_B3_START...GPIO_B3_END: offset = (pin - GPIO_B3_START) + 40; break; + default : offset = -1; break; } return offset; } @@ -717,9 +745,17 @@ static int gpioToGPSETReg (int pin) break; } } + else if (piModel == PI_MODEL_ODROIDC2) { + if(pin >= C2_GPIOX_PIN_START && pin <= C2_GPIOX_PIN_END) + return C2_GPIOX_OUTP_REG_OFFSET; + if(pin >= C2_GPIOY_PIN_START && pin <= C2_GPIOY_PIN_END) + return C2_GPIOY_OUTP_REG_OFFSET; + } else { - 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 >= 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; } return -1; @@ -748,9 +784,17 @@ static int gpioToGPLEVReg (int pin) break; } } + else if (piModel == PI_MODEL_ODROIDC2) { + if(pin >= C2_GPIOX_PIN_START && pin <= C2_GPIOX_PIN_END) + return C2_GPIOX_INP_REG_OFFSET; + if(pin >= C2_GPIOY_PIN_START && pin <= C2_GPIOY_PIN_END) + return C2_GPIOY_INP_REG_OFFSET; + } else { - 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 >= 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; } return -1; @@ -761,8 +805,18 @@ 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(piModel == PI_MODEL_ODROIDC2) { + if(pin >= C2_GPIOX_PIN_START && pin <= C2_GPIOX_PIN_END) + return C2_GPIOX_PUEN_REG_OFFSET; + if(pin >= C2_GPIOY_PIN_START && pin <= C2_GPIOY_PIN_END) + return C2_GPIOY_PUEN_REG_OFFSET; + } + else { + 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; + } return -1; } @@ -790,9 +844,17 @@ static int gpioToPUPDReg (int pin) break; } } + else if (piModel == PI_MODEL_ODROIDC2) { + if(pin >= C2_GPIOX_PIN_START && pin <= C2_GPIOX_PIN_END) + return C2_GPIOX_PUPD_REG_OFFSET; + if(pin >= C2_GPIOY_PIN_START && pin <= C2_GPIOY_PIN_END) + return C2_GPIOY_PUPD_REG_OFFSET; + } else { - 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 >= 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; } return -1; @@ -821,9 +883,17 @@ static int gpioToShiftReg (int pin) break; } } + else if (piModel == PI_MODEL_ODROIDC2) { + if(pin >= C2_GPIOX_PIN_START && pin <= C2_GPIOX_PIN_END) + return pin - C2_GPIOX_PIN_START; + if(pin >= C2_GPIOY_PIN_START && pin <= C2_GPIOY_PIN_END) + return pin - C2_GPIOY_PIN_START; + } else { - 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 >= 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; } return -1; @@ -852,9 +922,17 @@ static int gpioToGPFSELReg (int pin) break; } } + else if (piModel == PI_MODEL_ODROIDC2) { + if(pin >= C2_GPIOX_PIN_START && pin <= C2_GPIOX_PIN_END) + return C2_GPIOX_FSEL_REG_OFFSET; + if(pin >= C2_GPIOY_PIN_START && pin <= C2_GPIOY_PIN_END) + return C2_GPIOY_FSEL_REG_OFFSET; + } else { - 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 >= 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; } return -1; @@ -909,6 +987,98 @@ static int physToGpioOdroidC [64] = -1, -1, -1, -1, -1, -1, } ; +// +// pinToGpio: +// Take a Wiring pin (0 through X) and re-map it to the ODROIDC2_GPIO pin +// +static int pinToGpioOdroidC2_Rev1_1 [64] = { + 247, 238, 239, 237, 236, 233, 231, 249, // 0..7 + -1, -1, 229, 225, 235, 232, 230, -1, // 8..15 + -1, -1, -1, -1, -1, 228, 219, 234, // 16..23 + 214, -1, 224, 218, -1, -1, -1, -1, // 24..31 +// Padding: + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + + +static int pinToGpioOdroidC2_Rev1_0 [64] = { + 219, 218, 247, -1, 235, 233, 234, 214, // 0..7 + -1, -1, 248, 249, 238, 237, 236, -1, // 8..15 + -1, -1, -1, -1, -1, 232, 231, 239, // 16..23 + 228, -1, 230, 229, -1, -1, -1, -1, // 24..31 +// Padding: + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +// +// physToGpio: +// Take a physical pin (1 through 40) and re-map it to the ODROIDC2_GPIO pin +// +static int physToGpioOdroidC2_Rev1_1 [64] = +{ + -1, // 0 + -1, -1, // 1, 2 + -1, -1, + -1, -1, + 249, -1, + -1, -1, + 247, 238, + 239, -1, + 237, 236, + -1, 233, + 235, -1, + 232, 231, + 230, 229, + -1, 225, // 25, 26 + + -1, -1, + 228, -1, + 219, 224, + 234, -1, + 214, 218, + -1, -1, + -1, -1, // 39, 40 + +// Not used + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, +} ; + + +static int physToGpioOdroidC2_Rev1_0 [64] = +{ + -1, // 0 + -1, -1, // 1, 2 + -1, -1, + -1, -1, + 214, -1, + -1, -1, + 219, 218, + 247, -1, + -1, 235, + -1, 233, + 238, -1, + 237, 234, + 236, 248, + -1, 249, // 25, 26 + + -1, -1, + 232, -1, + 231, 230, + 239, -1, + 228, 229, + -1, -1, + -1, -1, // 39, 40 + +// Not used + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, +} ; + // // pinToGpio: // Take a Wiring pin (0 through X) and re-map it to the ODROIDXU_GPIO pin @@ -1033,6 +1203,10 @@ int wiringPiFailure (int fatal, const char *message, ...) * 000a - Model ODROID C1/C1+, Rev 1.0, 1024M, Hardkernel * added : * 0100 - Model ODROID XU3/4, Rev 1.0, 2048M, Hardkernel + * added : + * 020b - Model ODROID C2, 2048M, Hardkernel + * Rev 1.0 : /sys/class/odroid/boardrev value is 0 (Dev board) + * Rev 1.1 : /sys/class/odroid/boardrev value is 1 (Mass board) * * A small thorn is the olde style overvolting - that will add in * 1000000 @@ -1120,6 +1294,21 @@ int piBoardRev (void) else boardRev = 2; + if (strcmp (c, "020b") == 0) { + int fd = 0; + char buf[2]; + + if ((fd = open ("/sys/class/odroid/boardrev", O_RDONLY)) < 0) { + printf ("ERROR : file not found.(boardrev)\n"); + boardRev = 1; + } + else { + read (fd, buf, sizeof(buf)); + close(fd); + boardRev = atoi(buf) + 1; + } + } + if (wiringPiDebug) printf ("piBoardRev: Returning revision: %d\n", boardRev) ; @@ -1205,12 +1394,15 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) else if (strcmp (c, "0100") == 0) { *model = PI_MODEL_ODROIDXU_34; *rev = PI_VERSION_1; *mem = 2048; *maker = PI_MAKER_HARDKERNEL; } + else if (strcmp (c, "020b") == 0) { + *model = PI_MODEL_ODROIDC2; *mem = 2048; *maker = PI_MAKER_HARDKERNEL; + *rev = piBoardRev (); + } else { *model = 0; *rev = 0; *mem = 0; *maker = 0 ; } piModel = *model; } - /* @@ -1249,9 +1441,12 @@ void setPadDrive (int group, int value) { uint32_t wrVal ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) @@ -1284,7 +1479,7 @@ int getAlt (int pin) if ( piModel == PI_MODEL_ODROIDC ) pin &= 0x7F; - else if( piModel == PI_MODEL_ODROIDXU_34 ) + else if( piModel == PI_MODEL_ODROIDXU_34 || piModel == PI_MODEL_ODROIDC2 ) pin &= 0xFF; else pin &= 63 ; @@ -1296,7 +1491,7 @@ int getAlt (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return 0 ; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { if(pin < 0) return 2; // ALT @@ -1336,9 +1531,12 @@ int getAlt (int pin) void pwmSetMode (int mode) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) @@ -1360,9 +1558,12 @@ void pwmSetMode (int mode) void pwmSetRange (unsigned int range) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) @@ -1386,15 +1587,18 @@ void pwmSetClock (int divisor) uint32_t pwm_control ; divisor &= 4095 ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) { if (wiringPiDebug) - printf ("Setting to: %d. Current: 0x%08X\n", divisor, *(clk + PWMCLK_DIV)) ; + printf ("Setting to: %d. Current: 0x%08X\n", divisor, *(clk + PWMCLK_DIV)); pwm_control = *(pwm + PWM_CONTROL) ; // preserve PWM_CONTROL @@ -1421,7 +1625,7 @@ void pwmSetClock (int divisor) *(pwm + PWM_CONTROL) = pwm_control ; // restore PWM_CONTROL if (wiringPiDebug) - printf ("Set to: %d. Now : 0x%08X\n", divisor, *(clk + PWMCLK_DIV)) ; + printf ("Set to: %d. Now : 0x%08X\n", divisor, *(clk + PWMCLK_DIV)); } } @@ -1436,9 +1640,12 @@ void gpioClockSet (int pin, int freq) { int divi, divr, divf ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } pin &= 63 ; @@ -1510,7 +1717,7 @@ struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) if (pinBase < 128) (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 128\n", pinBase) ; } - else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + else if ( piModel == PI_MODEL_ODROIDXU_34 || piModel == PI_MODEL_ODROIDC2 ) { // Minimum pin base is 256 if (pinBase < 256) (void)wiringPiFailure (WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 256\n", pinBase) ; @@ -1578,9 +1785,12 @@ void pinModeAlt (int pin, int mode) { int fSel, shift ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } if ((pin & PI_GPIO_MASK) == 0) // On-board pin @@ -1613,7 +1823,8 @@ void pinMode (int pin, int mode) int origPin = pin ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC2 ) gpio_mask = ODROIDC2_GPIO_MASK; if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-board pin @@ -1625,6 +1836,11 @@ void pinMode (int pin, int mode) else if (wiringPiMode != WPI_MODE_GPIO) return ; + // maybe pin is not gpio. + if ( pin < 0 ) { + printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); + return; + } softPwmStop (origPin) ; softToneStop (origPin) ; @@ -1632,7 +1848,7 @@ void pinMode (int pin, int mode) shift = gpioToShift [pin] ; if (mode == INPUT) { - if ( piModel == PI_MODEL_ODROIDC ) + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) | (1 << gpioToShiftReg(pin))); else if ( piModel == PI_MODEL_ODROIDXU_34 ) { shift = (gpioToShiftReg(pin) * 4); @@ -1645,7 +1861,7 @@ void pinMode (int pin, int mode) *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)); // Sets bits to zero = input } else if (mode == OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC ) + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) *(gpio + gpioToGPFSELReg(pin)) = (*(gpio + gpioToGPFSELReg(pin)) & ~(1 << gpioToShiftReg(pin))); else if ( piModel == PI_MODEL_ODROIDXU_34 ) { shift = (gpioToShiftReg(pin) * 4); @@ -1662,20 +1878,26 @@ void pinMode (int pin, int mode) *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift); } else if (mode == SOFT_PWM_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + if (piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) softPwmCreate (pin, 0, 100); else softPwmCreate (origPin, 0, 100); } else if (mode == SOFT_TONE_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + if (piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) softToneCreate (pin); else softToneCreate (origPin); } else if (mode == PWM_TONE_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + if (piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) return; pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode @@ -1683,7 +1905,9 @@ void pinMode (int pin, int mode) } else if (mode == PWM_OUTPUT) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + if (piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) return; if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin @@ -1700,7 +1924,9 @@ void pinMode (int pin, int mode) } else if (mode == GPIO_CLOCK) { - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) + if (piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) return; if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin @@ -1735,8 +1961,10 @@ void pullUpDnControl (int pin, int pud) { struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; + int origPin = pin; if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC2 ) gpio_mask = ODROIDC2_GPIO_MASK; if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin @@ -1748,10 +1976,13 @@ void pullUpDnControl (int pin, int pud) else if (wiringPiMode != WPI_MODE_GPIO) return ; - if( piModel == PI_MODEL_ODROIDC ) { + // maybe pin is not gpio. + if ( pin < 0 ) { + printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); + return; + } - // maybe pin mode is not gpio. - if(pin < 0) return; + if( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { if(pud) { // Enable Pull/Pull-down resister @@ -1768,9 +1999,6 @@ void pullUpDnControl (int pin, int pud) else if ( piModel == PI_MODEL_ODROIDXU_34) { int shift = 0; - // maybe pin mode is not gpio. - if(pin < 0) return; - shift = (gpioToShiftReg(pin) * 2); if(pud) { @@ -1798,11 +2026,11 @@ void pullUpDnControl (int pin, int pud) } } else { - *(gpio + GPPUD) = pud & 3 ; delayMicroseconds (5) ; - *(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31) ; delayMicroseconds (5) ; + *(gpio + GPPUD) = pud & 3; delayMicroseconds (5) ; + *(gpio + gpioToPUDCLK [pin]) = 1 << (pin & 31); delayMicroseconds (5) ; - *(gpio + GPPUD) = 0 ; delayMicroseconds (5) ; - *(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ; + *(gpio + GPPUD) = 0 ; delayMicroseconds (5) ; + *(gpio + gpioToPUDCLK [pin]) = 0 ; delayMicroseconds (5) ; } } else // Extension module @@ -1825,8 +2053,10 @@ int digitalRead (int pin) char c ; struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; + int origPin = pin; if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC2 ) gpio_mask = ODROIDC2_GPIO_MASK; if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin @@ -1836,7 +2066,10 @@ int digitalRead (int pin) int fd_pos = 0; if ( piModel == PI_MODEL_ODROIDC ) { - fd_pos = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + fd_pos = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + } + else if ( piModel == PI_MODEL_ODROIDC2 ) { + fd_pos = pin < C2_GPIOY_PIN_START ? 63 : pin - C2_GPIOY_PIN_START; } else if ( piModel == PI_MODEL_ODROIDXU_34 ) { int offset = 0; @@ -1865,7 +2098,13 @@ int digitalRead (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return LOW ; - if ( piModel == PI_MODEL_ODROIDC ) { + // maybe pin is not gpio. + if ( pin < 0 ) { + printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); + return; + } + + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0) return HIGH ; else @@ -1903,8 +2142,10 @@ void digitalWrite (int pin, int value) { struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; + int origPin = pin; if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC2 ) gpio_mask = ODROIDC2_GPIO_MASK; if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; if ((pin & gpio_mask) == 0) // On-Board Pin @@ -1914,7 +2155,10 @@ void digitalWrite (int pin, int value) int fd_pos = 0; if ( piModel == PI_MODEL_ODROIDC ) { - fd_pos = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + fd_pos = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + } + else if ( piModel == PI_MODEL_ODROIDC2 ) { + fd_pos = pin < C2_GPIOY_PIN_START ? 63 : pin - C2_GPIOY_PIN_START; } else if ( piModel == PI_MODEL_ODROIDXU_34 ) { int offset = 0; @@ -1945,7 +2189,13 @@ void digitalWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - if ( piModel == PI_MODEL_ODROIDC ) { + // maybe pin is not gpio. + if ( pin < 0 ) { + printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); + return; + } + + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { if (value == LOW) *(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin)); else @@ -1985,8 +2235,13 @@ void pwmWrite (int pin, int value) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned int gpio_mask = PI_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDC ) gpio_mask = ODROIDC_GPIO_MASK; - if ( piModel == PI_MODEL_ODROIDXU_34 ) gpio_mask = ODROIDXU_GPIO_MASK; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; + } if ((pin & gpio_mask) == 0) // On-Board Pin { @@ -1997,12 +2252,7 @@ void pwmWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; - } - else - *(pwm + gpioToPwmPort [pin]) = value ; + *(pwm + gpioToPwmPort [pin]) = value ; } else { @@ -2025,7 +2275,9 @@ int analogRead (int pin) struct wiringPiNodeStruct *node = wiringPiNodes ; unsigned char value[5] = {0,}; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) { + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) { if(pin < 2) { if (adcFds [pin] == -1) return 0; @@ -2072,9 +2324,12 @@ void pwmToneWrite (int pin, int freq) { int range ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } if (freq == 0) @@ -2107,9 +2362,12 @@ void digitalWriteByte (int value) int mask = 1 ; int pin ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) { - fprintf (stderr, "%s : Unsupport function on %s model\n", __func__, piModelNames [piModel]); - exit (EXIT_FAILURE) ; + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34) { + fprintf (stderr, "%s : Unsupport function on %s model\n", + __func__, piModelNames [piModel]); + exit (EXIT_FAILURE) ; } /**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) @@ -2162,9 +2420,14 @@ int waitForInterrupt (int pin, int mS) else if (wiringPiMode == WPI_MODE_PHYS) pin = physToGpio [pin & 63] ; - if ( piModel == PI_MODEL_ODROIDC ) { + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { - fd_base = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + if ( piModel == PI_MODEL_ODROIDC2 ) { + fd_base = pin < C2_GPIOY_PIN_START ? 63: pin - C2_GPIOY_PIN_START; + } + else { + fd_base = pin < GPIO_PIN_BASE ? 0: pin - GPIO_PIN_BASE; + } if ((fd = sysFds [fd_base & 63]) == -1) return -2 ; @@ -2216,7 +2479,8 @@ int waitForInterrupt (int pin, int mS) (void)read (fd, &c, 1) ; lseek (fd, 0, SEEK_SET) ; - if ( piModel == PI_MODEL_ODROIDC && piThreadIrqMode) + if ( (piModel == PI_MODEL_ODROIDC && piThreadIrqMode) || + (piModel == PI_MODEL_ODROIDC2 && piThreadIrqMode) ) { if ( sysFdData[fd_base] != c ) { sysFdData[fd_base] = c; @@ -2249,7 +2513,9 @@ static void *interruptHandler (void *arg) myPin = pinPass ; pinPass = -1 ; - if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDXU_34 ) { + if ( piModel == PI_MODEL_ODROIDC || + piModel == PI_MODEL_ODROIDC2 || + piModel == PI_MODEL_ODROIDXU_34 ) { int gpioPin, fd_base; /**/ if (wiringPiMode == WPI_MODE_UNINITIALISED) @@ -2261,8 +2527,10 @@ static void *interruptHandler (void *arg) else gpioPin = myPin ; - if ( piModel == PI_MODEL_ODROIDC ) - fd_base = gpioPin < GPIO_PIN_BASE ? 0 : gpioPin - GPIO_PIN_BASE; + if ( piModel == PI_MODEL_ODROIDC ) + fd_base = gpioPin < GPIO_PIN_BASE ? 0 : gpioPin - GPIO_PIN_BASE; + else if ( piModel == PI_MODEL_ODROIDC2 ) + fd_base = gpioPin < C2_GPIOY_PIN_START ? 63: gpioPin - C2_GPIOY_PIN_START; else { int offset = 0; @@ -2321,7 +2589,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) if ((pin < 0) || (pin > 128)) return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-128 (%d)\n", pin) ; } - else if ( piModel == PI_MODEL_ODROIDXU_34 ) { + else if ( piModel == PI_MODEL_ODROIDXU_34 || piModel == PI_MODEL_ODROIDC2 ) { if ((pin < 0) || (pin > 256)) return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-256 (%d)\n", pin) ; } @@ -2372,8 +2640,13 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) // Now pre-open the /sys/class node - but it may already be open if // we are in Sys mode... - if ( piModel == PI_MODEL_ODROIDC ) { - int fd_base = bcmGpioPin < GPIO_PIN_BASE ? 0 : bcmGpioPin - GPIO_PIN_BASE; + if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { + int fd_base = 0; + + if (piModel == PI_MODEL_ODROIDC2 ) + fd_base = bcmGpioPin < C2_GPIOY_PIN_START ? 63: bcmGpioPin - C2_GPIOY_PIN_START; + else + fd_base = bcmGpioPin < GPIO_PIN_BASE ? 0 : bcmGpioPin - GPIO_PIN_BASE; if (sysFds [fd_base] == -1) { @@ -2631,6 +2904,35 @@ int wiringPiSetup (void) else piThreadIrqMode = FALSE; } } + else if ( model == PI_MODEL_ODROIDC2 ) { + + if(rev == PI_VERSION_1) { + pinToGpio = pinToGpioOdroidC2_Rev1_0; + physToGpio = physToGpioOdroidC2_Rev1_0; + } + else { + pinToGpio = pinToGpioOdroidC2_Rev1_1; + physToGpio = physToGpioOdroidC2_Rev1_1; + } + + // GPIO: + gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, ODROIDC2_GPIO_BASE) ; + if ((int32_t)gpio == -1) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; + + // ADC + // ADC sysfs open (/sys/class/saradc/saradc_ch0, ch1) + adcFds [0] = open (C2_piAinNode0, O_RDONLY) ; + adcFds [1] = open (C2_piAinNode1, O_RDONLY) ; + + // Check aml_gpio directory for gpio irq + { + struct stat s; + + if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; + else piThreadIrqMode = FALSE; + } + } else if ( model == PI_MODEL_ODROIDXU_34 ) { pinToGpio = pinToGpioOdroidXU; physToGpio = physToGpioOdroidXU; @@ -2820,6 +3122,42 @@ int wiringPiSetupSys (void) adcFds [0] = open (piAinNode0, O_RDONLY) ; adcFds [1] = open (piAinNode1, O_RDONLY) ; } + else if ( model == PI_MODEL_ODROIDC2 ) { + if(rev == PI_VERSION_1) { + pinToGpio = pinToGpioOdroidC2_Rev1_0; + physToGpio = physToGpioOdroidC2_Rev1_0; + } + else { + pinToGpio = pinToGpioOdroidC2_Rev1_1; + physToGpio = physToGpioOdroidC2_Rev1_1; + } + +// Open and scan the directory, looking for exported GPIOs, and pre-open +// the 'value' interface to speed things up for later + + // Check aml_gpio directory for gpio irq + { + struct stat s; + + if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; + else piThreadIrqMode = FALSE; + } + + for (pin = C2_GPIOY_PIN_START ; pin < C2_GPIOY_PIN_START + 64 ; ++pin) + { + if(piThreadIrqMode) + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + else + sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin) ; + + sysFds [pin - C2_GPIOY_PIN_START] = open (fName, O_RDWR) ; + } + + // ADC sysfs open (/sys/class/saradc/saradc_ch0, ch1) + + adcFds [0] = open (C2_piAinNode0, O_RDONLY) ; + adcFds [1] = open (C2_piAinNode1, O_RDONLY) ; + } else if ( model == PI_MODEL_ODROIDXU_34 ) { pinToGpio = pinToGpioOdroidXU ; physToGpio = physToGpioOdroidXU ; @@ -2838,8 +3176,8 @@ int wiringPiSetupSys (void) // ADC // ADC Fds[0] = ("/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw") // ADC Fds[1] = ("/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw") - adcFds [0] = open (piAinNode0, O_RDONLY) ; - adcFds [1] = open (piAinNode1, O_RDONLY) ; + adcFds [0] = open (piAinNode0_xu, O_RDONLY) ; + adcFds [1] = open (piAinNode1_xu, O_RDONLY) ; } else { boardRev = piBoardRev () ; diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 786ff7e..6346154 100755 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -78,6 +78,7 @@ #define PI_MODEL_AP 5 #define PI_MODEL_ODROIDC 6 #define PI_MODEL_ODROIDXU_34 7 +#define PI_MODEL_ODROIDC2 8 #define PI_VERSION_UNKNOWN 0 #define PI_VERSION_1 1 @@ -91,7 +92,7 @@ #define PI_MAKER_QISDA 3 #define PI_MAKER_HARDKERNEL 4 -extern const char *piModelNames [8] ; +extern const char *piModelNames [9] ; extern const char *piRevisionNames [5] ; extern const char *piMakerNames [5] ; diff --git a/wiringPi/wiringPiI2C.c b/wiringPi/wiringPiI2C.c index b8493ac..2a12116 100755 --- a/wiringPi/wiringPiI2C.c +++ b/wiringPi/wiringPiI2C.c @@ -223,10 +223,10 @@ int wiringPiI2CSetup (const int devId) piBoardId (&model, &rev, &mem, &maker, &overVolted) ; - if ( model == PI_MODEL_ODROIDC ) + if ( model == PI_MODEL_ODROIDC || model == PI_MODEL_ODROIDC2 ) device = "/dev/i2c-1" ; else if ( model == PI_MODEL_ODROIDXU_34 ) - device = "/dev/i2c-3" ; + device = "/dev/i2c-4" ; /* update 2016/feb/12 Linux */ else { rev = piBoardRev () ; diff --git a/wiringPi/wiringPiSPI.c b/wiringPi/wiringPiSPI.c index 575cd04..749045c 100755 --- a/wiringPi/wiringPiSPI.c +++ b/wiringPi/wiringPiSPI.c @@ -116,6 +116,9 @@ int wiringPiSPISetup (int channel, int speed) if ((fd = open (spiDev0, O_RDWR)) < 0) return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; } + else if (model == PI_MODEL_ODROIDC2) { + return wiringPiFailure (WPI_ALMOST, "ODROID-C2 cannot support spi-channel\n") ; + } else { if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0) return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; From 886e2deacc812a5869266acf83108aec6c911ee5 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Sat, 27 Feb 2016 13:09:54 +0900 Subject: [PATCH 08/16] wiringPi : gpio check function & debug message added. --- wiringPi/wiringPi.c | 61 ++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index d0f45f2..9e89990 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1172,6 +1172,42 @@ int wiringPiFailure (int fatal, const char *message, ...) return 0 ; } +const char wpi_mode_str[4][20] = { + "WPI_MODE_PINS", + "WPI_MODE_GPIO", + "WPI_MODE_GPIO_SYS", + "WPI_MODE_PHYS", +}; + +void wiringPiGpioCheck (const char *call_func, int origPin, int pin) +{ + if (wiringPiMode == WPI_MODE_PINS || wiringPiMode == WPI_MODE_PHYS) + { + // maybe pin is not gpio. + if ( pin < 0 ) { + (void)wiringPiFailure (WPI_FATAL, + "\n**************** %s ****************\n" \ + "\nCall Function = %s, wiringPiMode = %s\n" \ + "\nError gpio control (OrigPin = %d, pin = %d)\n\n", + __func__, call_func, wpi_mode_str[wiringPiMode], + origPin, pin); + } + } + else { + int i; + for(i = 0; i < 64; i++) { + if (origPin == pinToGpio[i]) break; + } + if (i == 64) { + (void)wiringPiFailure (WPI_FATAL, + "\n**************** %s ****************\n" \ + "\nCall Function = %s, wiringPiMode = %s\n" \ + "\nCannot found gpio pin! (OrigPin = %d)\n\n", + __func__, call_func, wpi_mode_str[wiringPiMode], + origPin); + } + } +} /* * piBoardRev: @@ -1836,11 +1872,8 @@ void pinMode (int pin, int mode) else if (wiringPiMode != WPI_MODE_GPIO) return ; - // maybe pin is not gpio. - if ( pin < 0 ) { - printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); - return; - } + wiringPiGpioCheck (__func__, origPin, pin); + softPwmStop (origPin) ; softToneStop (origPin) ; @@ -1976,11 +2009,7 @@ void pullUpDnControl (int pin, int pud) else if (wiringPiMode != WPI_MODE_GPIO) return ; - // maybe pin is not gpio. - if ( pin < 0 ) { - printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); - return; - } + wiringPiGpioCheck (__func__, origPin, pin); if( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { @@ -2098,11 +2127,7 @@ int digitalRead (int pin) else if (wiringPiMode != WPI_MODE_GPIO) return LOW ; - // maybe pin is not gpio. - if ( pin < 0 ) { - printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); - return; - } + wiringPiGpioCheck (__func__, origPin, pin); if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0) @@ -2189,11 +2214,7 @@ void digitalWrite (int pin, int value) else if (wiringPiMode != WPI_MODE_GPIO) return ; - // maybe pin is not gpio. - if ( pin < 0 ) { - printf("%s : Pin control error! (OrigPin = %d, pin = %d)\n", __func__, origPin, pin); - return; - } + wiringPiGpioCheck (__func__, origPin, pin); if ( piModel == PI_MODEL_ODROIDC || piModel == PI_MODEL_ODROIDC2 ) { if (value == LOW) From 700d3fea85f99405aeb0ce7f67a9ad5ceb1b42f4 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Tue, 8 Mar 2016 17:35:50 +0900 Subject: [PATCH 09/16] wiringPi : gpio readall error fix. (ODROID-XU3/4) --- gpio/readall.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/gpio/readall.c b/gpio/readall.c index fa3cfe0..f05b298 100755 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -253,7 +253,7 @@ static char *physNamesOdroidXU [64] = " MOSI", "0v ", " MISO", "GPIO. 24", " SCLK", "CE0 ", - " 0v", "GPIO.190", + " 0v", "GPIO. 25", "I2C5.SDA", "I2C5.SCL", "GPIO. 28", "0v ", "GPIO. 30", "GPIO. 29", @@ -428,10 +428,12 @@ static void readallPhysOdroidC (int physPin, int model, int rev) { int pin ; - if (physPinToGpio (physPin) == -1) - printf (" | | ") ; + if ((physPinToGpio (physPin) == -1) && (physToWpi [physPin] == -1)) + printf (" | | "); + else if (physPinToGpio (physPin) != -1) + printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]); else - printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ; + printf (" | | %3d", physToWpi [physPin]); if (model == PI_MODEL_ODROIDC) printf (" | %s", physNamesOdroidc [physPin]) ; @@ -442,8 +444,8 @@ static void readallPhysOdroidC (int physPin, int model, int rev) printf (" | %s", physNamesOdroidc2_Rev1_1 [physPin]) ; } - if (physToWpi [physPin] == -1) - printf (" | | ") ; + if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1)) + printf (" | | "); else { /**/ if (wpMode == WPI_MODE_GPIO) @@ -470,8 +472,8 @@ static void readallPhysOdroidC (int physPin, int model, int rev) // Same, reversed - if (physToWpi [physPin] == -1) - printf (" | | ") ; + if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1)) + printf (" | | "); else { /**/ if (wpMode == WPI_MODE_GPIO) @@ -499,10 +501,12 @@ static void readallPhysOdroidC (int physPin, int model, int rev) printf (" | %-6s", physNamesOdroidc2_Rev1_1 [physPin]) ; } - if (physPinToGpio (physPin) == -1) - printf (" | | ") ; + if ((physPinToGpio (physPin) == -1) && (physToWpi [physPin] == -1)) + printf (" | | "); + else if (physPinToGpio (physPin) != -1) + printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)); else - printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ; + printf (" | %-3d | ", physToWpi [physPin]); printf (" |\n") ; } @@ -510,7 +514,6 @@ static void readallPhysOdroidC (int physPin, int model, int rev) void ReadallOdroidC (int model, int rev) { int pin ; - char *type ; if(model == PI_MODEL_ODROIDC2) printf (" +------+-----+----------+------+ Model ODROID-C2 +------+----------+-----+------+\n") ; @@ -528,14 +531,16 @@ static void readallPhysOdroidXU (int physPin) { int pin ; - if (physPinToGpio (physPin) == -1) + if ((physPinToGpio (physPin) == -1) && (physToWpi [physPin] == -1)) printf (" | | ") ; + else if (physPinToGpio (physPin) != -1) + printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]); else - printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ; + printf (" | | %3d", physToWpi [physPin]); printf (" | %s", physNamesOdroidXU [physPin]) ; - if (physToWpi [physPin] == -1) + if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1)) printf (" | | ") ; else { @@ -558,7 +563,7 @@ static void readallPhysOdroidXU (int physPin) // Same, reversed - if (physToWpi [physPin] == -1) + if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1)) printf (" | | ") ; else { @@ -575,10 +580,12 @@ static void readallPhysOdroidXU (int physPin) printf (" | %-6s", physNamesOdroidXU [physPin]) ; - if (physPinToGpio (physPin) == -1) + if ((physPinToGpio (physPin) == -1) && (physToWpi [physPin] == -1)) printf (" | | ") ; + else if (physPinToGpio (physPin) != -1) + printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)); else - printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ; + printf (" | %-3d | ", physToWpi [physPin]); printf (" |\n") ; } @@ -586,7 +593,6 @@ static void readallPhysOdroidXU (int physPin) void ReadallOdroidXU (void) { int pin ; - char *type ; printf (" +------+-----+----------+------ Model ODROID-XU3/4 ------+----------+-----+------+\n") ; printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n") ; From ed5f083f84c7ebcfdb67c3a7521aabb136d9bfb6 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Tue, 12 Apr 2016 11:44:03 +0900 Subject: [PATCH 10/16] wiringPi : ODROID-C2 gpio irq implement. --- wiringPi/wiringPi.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 9e89990..752e39d 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -2671,10 +2671,14 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) if (sysFds [fd_base] == -1) { - if(piThreadIrqMode) - sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + if (piModel == PI_MODEL_ODROIDC) { + if(piThreadIrqMode) + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + else + sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", bcmGpioPin) ; + } else - sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", bcmGpioPin) ; + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; if ((sysFds [fd_base] = open (fName, O_RDWR)) < 0) return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; @@ -2945,14 +2949,6 @@ int wiringPiSetup (void) // ADC sysfs open (/sys/class/saradc/saradc_ch0, ch1) adcFds [0] = open (C2_piAinNode0, O_RDONLY) ; adcFds [1] = open (C2_piAinNode1, O_RDONLY) ; - - // Check aml_gpio directory for gpio irq - { - struct stat s; - - if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; - else piThreadIrqMode = FALSE; - } } else if ( model == PI_MODEL_ODROIDXU_34 ) { pinToGpio = pinToGpioOdroidXU; @@ -3155,15 +3151,6 @@ int wiringPiSetupSys (void) // Open and scan the directory, looking for exported GPIOs, and pre-open // the 'value' interface to speed things up for later - - // Check aml_gpio directory for gpio irq - { - struct stat s; - - if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; - else piThreadIrqMode = FALSE; - } - for (pin = C2_GPIOY_PIN_START ; pin < C2_GPIOY_PIN_START + 64 ; ++pin) { if(piThreadIrqMode) From 6f349b06e54b7fdbc90a58ab038999cf17062091 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Thu, 14 Apr 2016 12:30:36 +0900 Subject: [PATCH 11/16] wiringPi : ODROID-C1 gpio sysfs irq change(aml_gpio to gpio) --- gpio/gpio.c | 6 ++++- wiringPi/wiringPi.c | 66 +++++---------------------------------------- 2 files changed, 12 insertions(+), 60 deletions(-) diff --git a/gpio/gpio.c b/gpio/gpio.c index fcab54e..c51aed1 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -53,7 +53,11 @@ extern void doPins (void) ; # define FALSE (1==2) #endif -#define VERSION "2.31" +/* + 2.31 : ODROID-C1/ODROID-C2 wiringPi support + 2.33 : ODROID-C1/ODROID-C2 GPIO sysfs irq support +*/ +#define VERSION "2.33" #define PI_USB_POWER_CONTROL 38 #define I2CDETECT "/usr/sbin/i2cdetect" diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 752e39d..ba6a52a 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -678,9 +678,6 @@ static int adcFds [2] = { static int piModel = PI_MODEL_UNKNOWN; -// Use ODROID-C Model -static int piThreadIrqMode = FALSE; - static int sysFdData [64] = { -1, -1, -1, -1, -1, -1, -1, -1, // 0...7 -1, -1, -1, -1, -1, -1, -1, -1, // 8...15 @@ -2453,14 +2450,10 @@ int waitForInterrupt (int pin, int mS) if ((fd = sysFds [fd_base & 63]) == -1) return -2 ; - // Setup poll structure - + // Setup poll structure polls.fd = fd ; - if(piThreadIrqMode) - polls.events = POLLIN ; // Normal data! - else - polls.events = POLLPRI ; // Urgent data! + polls.events = POLLPRI ; // Urgent data! } else if ( piModel == PI_MODEL_ODROIDXU_34 ) { int offset = 0; @@ -2475,15 +2468,15 @@ int waitForInterrupt (int pin, int mS) if ((fd = sysFds [fd_base & 63]) == -1) return -2 ; - // Setup poll structure + // Setup poll structure polls.fd = fd ; polls.events = POLLPRI ; // Urgent data! } else { if ((fd = sysFds [pin]) == -1) return -2 ; - // Setup poll structure + // Setup poll structure polls.fd = fd ; polls.events = POLLPRI ; // Urgent data! } @@ -2500,19 +2493,6 @@ int waitForInterrupt (int pin, int mS) (void)read (fd, &c, 1) ; lseek (fd, 0, SEEK_SET) ; - if ( (piModel == PI_MODEL_ODROIDC && piThreadIrqMode) || - (piModel == PI_MODEL_ODROIDC2 && piThreadIrqMode) ) - { - if ( sysFdData[fd_base] != c ) { - sysFdData[fd_base] = c; - if (( sysFdIrqType[fd_base] == INT_EDGE_RISING ) && ( c == '1' )) return 1; - else if (( sysFdIrqType[fd_base] == INT_EDGE_FALLING ) && ( c == '0' )) return 1; - else if (( sysFdIrqType[fd_base] == INT_EDGE_BOTH ) ) return 1; - } - usleep(100); - goto wait; - } - return x ; } @@ -2671,14 +2651,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) if (sysFds [fd_base] == -1) { - if (piModel == PI_MODEL_ODROIDC) { - if(piThreadIrqMode) - sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; - else - sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", bcmGpioPin) ; - } - else - sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; + sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; if ((sysFds [fd_base] = open (fName, O_RDWR)) < 0) return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; @@ -2920,14 +2893,6 @@ int wiringPiSetup (void) // ADC sysfs open (/sys/class/saradc/saradc_ch0, ch1) adcFds [0] = open (piAinNode0, O_RDONLY) ; adcFds [1] = open (piAinNode1, O_RDONLY) ; - - // Check aml_gpio directory for gpio irq - { - struct stat s; - - if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; - else piThreadIrqMode = FALSE; - } } else if ( model == PI_MODEL_ODROIDC2 ) { @@ -3115,22 +3080,9 @@ int wiringPiSetupSys (void) // Open and scan the directory, looking for exported GPIOs, and pre-open // the 'value' interface to speed things up for later - - // Check aml_gpio directory for gpio irq - { - struct stat s; - - if(-1 == stat("/sys/class/aml_gpio", &s)) piThreadIrqMode = TRUE; - else piThreadIrqMode = FALSE; - } - for (pin = GPIO_PIN_BASE ; pin < GPIO_PIN_BASE + 64 ; ++pin) { - if(piThreadIrqMode) - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; - else - sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin) ; - + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; sysFds [pin - GPIO_PIN_BASE] = open (fName, O_RDWR) ; } @@ -3153,11 +3105,7 @@ int wiringPiSetupSys (void) // the 'value' interface to speed things up for later for (pin = C2_GPIOY_PIN_START ; pin < C2_GPIOY_PIN_START + 64 ; ++pin) { - if(piThreadIrqMode) - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; - else - sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin) ; - + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; sysFds [pin - C2_GPIOY_PIN_START] = open (fName, O_RDWR) ; } From 889d2594387cb6c2d78583fe31780a518ebe80cf Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Thu, 14 Apr 2016 16:07:12 +0900 Subject: [PATCH 12/16] wiringPi : gpio sysfs dir change(aml_gpio to gpio) --- gpio/gpio.c | 50 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/gpio/gpio.c b/gpio/gpio.c index c51aed1..8567e77 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -462,10 +462,7 @@ void doExport (int argc, char *argv []) mode = argv [3] ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/%s/export", "aml_gpio"); - else - sprintf (fName, "/sys/class/%s/export", "gpio"); + sprintf (fName, "/sys/class/%s/export", "gpio"); if ((fd = fopen (fName, "w")) == NULL) { @@ -476,10 +473,7 @@ void doExport (int argc, char *argv []) fprintf (fd, "%d\n", pin) ; fclose (fd) ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/direction", pin) ; - else - sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ; + sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin) ; if ((fd = fopen (fName, "w")) == NULL) { @@ -501,17 +495,11 @@ void doExport (int argc, char *argv []) // Change ownership so the current user can actually use it! - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin) ; - else - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ; changeOwner (argv [0], fName) ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/edge", pin) ; - else - sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ; + sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin) ; changeOwner (argv [0], fName) ; @@ -593,10 +581,7 @@ void doEdge (int argc, char *argv []) // Export the pin and set direction to input - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/%s/export", "aml_gpio"); - else - sprintf (fName, "/sys/class/%s/export", "gpio"); + sprintf (fName, "/sys/class/%s/export", "gpio"); if ((fd = fopen (fName, "w")) == NULL) { @@ -606,10 +591,7 @@ void doEdge (int argc, char *argv []) fprintf (fd, "%d\n", pin) ; fclose (fd) ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/direction", pin); - else - sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin); + sprintf (fName, "/sys/class/gpio/gpio%d/direction", pin); if ((fd = fopen (fName, "w")) == NULL) { @@ -620,10 +602,7 @@ void doEdge (int argc, char *argv []) fprintf (fd, "in\n") ; fclose (fd) ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/edge", pin); - else - sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin); + sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin); if ((fd = fopen (fName, "w")) == NULL) { @@ -643,17 +622,11 @@ void doEdge (int argc, char *argv []) // Change ownership of the value and edge files, so the current user can actually use it! - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/value", pin); - else - sprintf (fName, "/sys/class/gpio/gpio%d/value", pin); + sprintf (fName, "/sys/class/gpio/gpio%d/value", pin); changeOwner (argv [0], fName) ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/aml_gpio/gpio%d/edge", pin); - else - sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin); + sprintf (fName, "/sys/class/gpio/gpio%d/edge", pin); changeOwner (argv [0], fName) ; @@ -682,10 +655,7 @@ void doUnexport (int argc, char *argv []) pin = atoi (argv [2]) ; - if (piModel == PI_MODEL_ODROIDC) - sprintf (fName, "/sys/class/%s/unexport", "aml_gpio") ; - else - sprintf (fName, "/sys/class/%s/unexport", "gpio") ; + sprintf (fName, "/sys/class/%s/unexport", "gpio") ; if ((fd = fopen (fName, "w")) == NULL) { From ece2e9117d7ce73915b03f215ad8778ead779687 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Wed, 6 Jul 2016 16:50:52 +0900 Subject: [PATCH 13/16] wiringPi : modified board id check for odroid-c2. --- wiringPi/wiringPi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index ba6a52a..229007a 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1237,7 +1237,7 @@ void wiringPiGpioCheck (const char *call_func, int origPin, int pin) * added : * 0100 - Model ODROID XU3/4, Rev 1.0, 2048M, Hardkernel * added : - * 020b - Model ODROID C2, 2048M, Hardkernel + * 02xx - Model ODROID C2, 2048M, Hardkernel * Rev 1.0 : /sys/class/odroid/boardrev value is 0 (Dev board) * Rev 1.1 : /sys/class/odroid/boardrev value is 1 (Mass board) * @@ -1327,7 +1327,7 @@ int piBoardRev (void) else boardRev = 2; - if (strcmp (c, "020b") == 0) { + if (strncmp (c, "02", 2) == 0) { int fd = 0; char buf[2]; @@ -1427,7 +1427,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) else if (strcmp (c, "0100") == 0) { *model = PI_MODEL_ODROIDXU_34; *rev = PI_VERSION_1; *mem = 2048; *maker = PI_MAKER_HARDKERNEL; } - else if (strcmp (c, "020b") == 0) { + else if (strncmp (c, "02", 2) == 0) { *model = PI_MODEL_ODROIDC2; *mem = 2048; *maker = PI_MAKER_HARDKERNEL; *rev = piBoardRev (); } From 16e5cae21313e7cd5f47f5cb34d62172ab4350f6 Mon Sep 17 00:00:00 2001 From: "charles.park" Date: Tue, 10 Jan 2017 18:10:56 +0900 Subject: [PATCH 14/16] wiringPi : support rootless user GPIO access(/dev/gpiomem) --- wiringPi/wiringPi.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 229007a..3f6bcff 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -2865,19 +2865,24 @@ int wiringPiSetup (void) if (getenv (ENV_CODES) != NULL) wiringPiReturnCodes = TRUE ; - if (geteuid () != 0) - (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ; + // Open the master /dev/memory device + if (access("/dev/gpiomem",0) == 0) { + if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ; + } + else { + if (geteuid () != 0) + (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ; + + if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) + return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; + } if (wiringPiDebug) printf ("wiringPi: wiringPiSetup called\n") ; piBoardId (&model, &rev, &mem, &maker, &overVolted) ; -// Open the master /dev/memory device - - if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) - return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; - if ( model == PI_MODEL_ODROIDC ) { pinToGpio = pinToGpioOdroidC; From 5d98c31830ba49952ca0978da74b54e0b5655a8f Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Thu, 9 Feb 2017 17:41:07 +0900 Subject: [PATCH 15/16] wiringPi : support adc file for 4.9.x kernel --- wiringPi/wiringPi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 3f6bcff..3b01469 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -68,6 +68,7 @@ #include #include #include +#include #include "softPwm.h" #include "softTone.h" @@ -673,8 +674,13 @@ static int adcFds [2] = { #define GPIO_B3_PUD_OFFSET 0x00C8 #define GPIO_B3_END 214 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) +#define piAinNode0_xu "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage0_raw" +#define piAinNode1_xu "/sys/devices/platform/soc:/12d10000.adc:/iio:device0/in_voltage3_raw" +#else #define piAinNode0_xu "/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw" #define piAinNode1_xu "/sys/devices/12d10000.adc/iio:device0/in_voltage3_raw" +#endif static int piModel = PI_MODEL_UNKNOWN; From c0ea501eecd3c2adcb09eca1766d4bee0a6fd4b1 Mon Sep 17 00:00:00 2001 From: Robert Savage Date: Sun, 6 Aug 2017 12:11:15 -0400 Subject: [PATCH 16/16] updated SPI API & impl to match current WiringPi version --- wiringPi/wiringPiSPI.c | 44 ++++++++++++++++++++++++++++-------------- wiringPi/wiringPiSPI.h | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/wiringPi/wiringPiSPI.c b/wiringPi/wiringPiSPI.c index 749045c..91d4b83 100755 --- a/wiringPi/wiringPiSPI.c +++ b/wiringPi/wiringPiSPI.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "wiringPi.h" @@ -38,12 +39,11 @@ // The SPI bus parameters // Variables as they need to be passed as pointers later on -const static char *spiDev0 = "/dev/spidev0.0" ; -const static char *spiDev1 = "/dev/spidev0.1" ; -const static char *spiDev0_XU = "/dev/spidev1.0"; -const static uint8_t spiMode = 0 ; -const static uint8_t spiBPW = 8 ; -const static uint16_t spiDelay = 0 ; +static const char *spiDev0 = "/dev/spidev0.0" ; +static const char *spiDev1 = "/dev/spidev0.1" ; +static const char *spiDev0_XU = "/dev/spidev1.0"; +static const uint8_t spiBPW = 8 ; +static const uint16_t spiDelay = 0 ; static uint32_t spiSpeeds [2] ; static int spiFds [2] ; @@ -76,6 +76,11 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len) channel &= 1 ; +// Mentioned in spidev.h but not used in the original kernel documentation +// test program )-: + + memset (&spi, 0, sizeof (spi)) ; + spi.tx_buf = (unsigned long)data ; spi.rx_buf = (unsigned long)data ; spi.len = len ; @@ -88,12 +93,12 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len) /* - * wiringPiSPISetup: - * Open the SPI device, and set it up, etc. + * wiringPiSPISetupMode: + * Open the SPI device, and set it up, with the mode, etc. ********************************************************************************* */ -int wiringPiSPISetup (int channel, int speed) +int wiringPiSPISetupMode (int channel, int speed, int mode) { int fd ; int model, rev, mem, maker, overVolted ; @@ -127,13 +132,10 @@ int wiringPiSPISetup (int channel, int speed) spiSpeeds [channel] = speed ; spiFds [channel] = fd ; -// Set SPI parameters. -// Why are we reading it afterwriting it? I've no idea, but for now I'm blindly -// copying example code I've seen online... - - if (ioctl (fd, SPI_IOC_WR_MODE, &spiMode) < 0) + // Set SPI parameters. + if (ioctl (fd, SPI_IOC_WR_MODE, &mode) < 0) return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ; - + if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0) return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ; @@ -142,3 +144,15 @@ int wiringPiSPISetup (int channel, int speed) return fd ; } + + +/* + * wiringPiSPISetup: + * Open the SPI device, and set it up, etc. in the default MODE 0 + ********************************************************************************* + */ + +int wiringPiSPISetup (int channel, int speed) +{ + return wiringPiSPISetupMode (channel, speed, 0) ; +} diff --git a/wiringPi/wiringPiSPI.h b/wiringPi/wiringPiSPI.h index f53697d..48cb7be 100644 --- a/wiringPi/wiringPiSPI.h +++ b/wiringPi/wiringPiSPI.h @@ -28,6 +28,7 @@ extern "C" { 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