Skip to content

Commit

Permalink
ODROID C1: Enable I2C pins when the I2C module isn't loaded
Browse files Browse the repository at this point in the history
Change-Id: I1b581fc1335b59bcb8565d96490d9c6fccada9ae
  • Loading branch information
joshua-yang committed May 10, 2018
1 parent efb5151 commit eb609f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
43 changes: 33 additions & 10 deletions wiringPi/odroidc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static const int pinToGpio[64] = {
116, 115, // 2 | 3 : GPIOX.19, GPIOX.18
104, 102, // 4 | 5 : GPIOX.7, GPIOX.5
103, 83, // 6 | 7 : GPIOX.6, GPIOY.3
-1, -1, // 8 | 9 : GPIODV.24(I2CA_SDA), GPIODV.25(I2CA_SCL)
74, 75, // 8 | 9 : GPIODV.24(I2CA_SDA), GPIODV.25(I2CA_SCL)
117, 118, // 10 | 11 : GPIOX.20(SPI_CE0), GPIOX.21(SPI_CE1)
107, 106, // 12 | 13 : GPIOX.10(SPI_MOSI), GPIOX.9(SPI_MISO)
105, -1, // 14 | 15 : GPIOX.8(SPI_SCLK), GPIOX.16(UART_TX_B)
Expand All @@ -52,8 +52,8 @@ static const int phyToGpio[64] = {
// physical header pin number to native gpio number
-1, // 0
-1, -1, // 1 | 2 : 3.3V, 5.0V
-1, -1, // 3 | 4 : GPIODV.24(I2CA_SDA), 5.0V
-1, -1, // 5 | 6 : GPIODV.25(I2CA_SCL), GND
74, -1, // 3 | 4 : GPIODV.24(I2CA_SDA), 5.0V
75, -1, // 5 | 6 : GPIODV.25(I2CA_SCL), GND
83, -1, // 7 | 8 : GPIOY.3, GPIOX.16(UART_TX_B)
-1, -1, // 9 | 10 : GND, GPIOX.17(UART_RX_B)
88, 87, // 11 | 12 : GPIOY.8, GPIOY.7
Expand Down Expand Up @@ -135,6 +135,8 @@ static int gpioToGPSETReg (int pin)
return GPIOX_OUTP_REG_OFFSET;
if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
return GPIOY_OUTP_REG_OFFSET;
if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
return GPIODV_OUTP_REG_OFFSET;
return -1;
}

Expand All @@ -149,6 +151,8 @@ static int gpioToGPLEVReg (int pin)
return GPIOX_INP_REG_OFFSET;
if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
return GPIOY_INP_REG_OFFSET;
if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
return GPIODV_INP_REG_OFFSET;
return -1;
}

Expand All @@ -163,6 +167,8 @@ static int gpioToPUENReg (int pin)
return GPIOX_PUEN_REG_OFFSET;
if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
return GPIOY_PUEN_REG_OFFSET;
if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
return GPIODV_PUEN_REG_OFFSET;
return -1;
}

Expand All @@ -177,6 +183,8 @@ static int gpioToPUPDReg (int pin)
return GPIOX_PUPD_REG_OFFSET;
if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
return GPIOY_PUPD_REG_OFFSET;
if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
return GPIODV_PUPD_REG_OFFSET;
return -1;
}

Expand All @@ -191,6 +199,8 @@ static int gpioToShiftReg (int pin)
return pin - GPIOX_PIN_START;
if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
return pin - GPIOY_PIN_START;
if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
return pin - GPIODV_PIN_START;
return -1;
}

Expand All @@ -205,29 +215,42 @@ static int gpioToGPFSELReg (int pin)
return GPIOX_FSEL_REG_OFFSET;
if (pin >= GPIOY_PIN_START && pin <= GPIOY_PIN_END)
return GPIOY_FSEL_REG_OFFSET;
if (pin >= GPIODV_PIN_START && pin <= GPIODV_PIN_END)
return GPIODV_FSEL_REG_OFFSET;
return -1;
}
/*----------------------------------------------------------------------------*/
static int getModeToGpio (int mode, int pin)
{
int retPin = -1;

switch (mode) {
/* Native gpio number */
case MODE_GPIO:
return pin;
retPin = pin;
break;
/* Native gpio number for sysfs */
case MODE_GPIO_SYS:
return lib->sysFds[pin] != -1 ? pin : -1;
retPin = lib->sysFds[pin] != -1 ? pin : -1;
break;
/* wiringPi number */
case MODE_PINS:
return pin < 64 ? pinToGpio[pin] : -1;
retPin = pin < 64 ? pinToGpio[pin] : -1;
break;
/* header pin number */
case MODE_PHYS:
return pin < 64 ? phyToGpio[pin] : -1;
default :
retPin = pin < 64 ? phyToGpio[pin] : -1;
break;
default :
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
return -1;
}
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
return -1;

/* To check I2C module loaded */
if (moduleLoaded(AML_MODULE_I2C) && (retPin == 74 || retPin == 75))
return -1;
else
return retPin;
}

/*----------------------------------------------------------------------------*/
Expand Down
11 changes: 10 additions & 1 deletion wiringPi/odroidc1.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#define ODROIDC_GPIO_MASK (0xFFFFFF80)
#define ODROIDC1_GPIO_BASE 0xC1108000

#define GPIO_PIN_BASE 80
#define GPIO_PIN_BASE 0

#define GPIODV_PIN_START 50
#define GPIODV_PIN_END 79
#define GPIOY_PIN_START 80
#define GPIOY_PIN_END 96
#define GPIOX_PIN_START 97
Expand All @@ -30,6 +33,12 @@
#define GPIOY_PUPD_REG_OFFSET 0x3D
#define GPIOY_PUEN_REG_OFFSET 0x4B

#define GPIODV_FSEL_REG_OFFSET 0x12
#define GPIODV_OUTP_REG_OFFSET 0x13
#define GPIODV_INP_REG_OFFSET 0x14
#define GPIODV_PUPD_REG_OFFSET 0x3A
#define GPIODV_PUEN_REG_OFFSET 0x48

#ifdef __cplusplus
extern "C" {
#endif
Expand Down

0 comments on commit eb609f8

Please sign in to comment.