diff --git a/.gitignore b/.gitignore index ac19925..73994dc 100755 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ ################### *.o funkey_gpio_management +termfix diff --git a/driver_pcal6416a.c b/driver_pcal6416a.c index 90bd8cd..4b2c3e1 100755 --- a/driver_pcal6416a.c +++ b/driver_pcal6416a.c @@ -50,25 +50,25 @@ bool pcal6416a_init(void) { i2c_expander_addr = 0; /// Probing PCAL9539A chip - if (!i2c_expander_addr && ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL9539A_I2C_ADDR) < 0) { - printf("In %s - Failed to acquire bus access and/or talk to slave PCAL9539A_I2C_ADDR 0x%02X.\n", + if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL9539A_I2C_ADDR) < 0 || + pcal6416a_read_mask_interrupts() < 0) { + printf("In %s - Failed to acquire bus access and/or talk to slave PCAL9539A_I2C_ADDR 0x%02X.\n", __func__, PCAL9539A_I2C_ADDR); - } - else{ + + /// Probing PCAL6416A chip + if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL6416A_I2C_ADDR) < 0 || + pcal6416a_read_mask_interrupts() < 0) { + printf("In %s - Failed to acquire bus access and/or talk to slave PCAL6416A_I2C_ADDR 0x%02X.\n", + __func__, PCAL6416A_I2C_ADDR); + } else { + DEBUG_PRINTF("Found I2C gpio expander chip: PCAL6416A\n"); + i2c_expander_addr = PCAL6416A_I2C_ADDR; + } + } else{ DEBUG_PRINTF("Found I2C gpio expander chip: PCAL9539A\n"); i2c_expander_addr = PCAL9539A_I2C_ADDR; } - /// Probing PCAL6416A chip - if (!i2c_expander_addr && ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL6416A_I2C_ADDR) < 0) { - printf("In %s - Failed to acquire bus access and/or talk to slave PCAL6416A_I2C_ADDR 0x%02X.\n", - __func__, PCAL6416A_I2C_ADDR); - } - else{ - DEBUG_PRINTF("Found I2C gpio expander chip: PCAL6416A\n"); - i2c_expander_addr = PCAL6416A_I2C_ADDR; - } - /// GPIO expander chip found? if(!i2c_expander_addr){ printf("In %s - Failed to acquire bus access and/or talk to slave, exit\n", __func__); @@ -119,4 +119,4 @@ int pcal6416a_read_mask_active_GPIOs(void){ val = 0xFFFF-val; DEBUG_PRINTF("READ PCAL6416A_INPUT (active GPIOs) : 0x%04X\n",val); return (int) val; -} \ No newline at end of file +} diff --git a/gpio_mapping.c b/gpio_mapping.c index 9774f29..c99a995 100755 --- a/gpio_mapping.c +++ b/gpio_mapping.c @@ -491,4 +491,3 @@ int listen_gpios_interrupts(void) return 0; } -