Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.

Commit 44035d4

Browse files
committed
fix multi I2C GPIO expander detection
Signed-off-by: Michel-FK <[email protected]>
1 parent 66fc9ce commit 44035d4

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
###################
55
*.o
66
funkey_gpio_management
7+
termfix

driver_pcal6416a.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,25 @@ bool pcal6416a_init(void) {
5050
i2c_expander_addr = 0;
5151

5252
/// Probing PCAL9539A chip
53-
if (!i2c_expander_addr && ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL9539A_I2C_ADDR) < 0) {
54-
printf("In %s - Failed to acquire bus access and/or talk to slave PCAL9539A_I2C_ADDR 0x%02X.\n",
53+
if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL9539A_I2C_ADDR) < 0 ||
54+
pcal6416a_read_mask_interrupts() < 0) {
55+
printf("In %s - Failed to acquire bus access and/or talk to slave PCAL9539A_I2C_ADDR 0x%02X.\n",
5556
__func__, PCAL9539A_I2C_ADDR);
56-
}
57-
else{
57+
58+
/// Probing PCAL6416A chip
59+
if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL6416A_I2C_ADDR) < 0 ||
60+
pcal6416a_read_mask_interrupts() < 0) {
61+
printf("In %s - Failed to acquire bus access and/or talk to slave PCAL6416A_I2C_ADDR 0x%02X.\n",
62+
__func__, PCAL6416A_I2C_ADDR);
63+
} else {
64+
DEBUG_PRINTF("Found I2C gpio expander chip: PCAL6416A\n");
65+
i2c_expander_addr = PCAL6416A_I2C_ADDR;
66+
}
67+
} else{
5868
DEBUG_PRINTF("Found I2C gpio expander chip: PCAL9539A\n");
5969
i2c_expander_addr = PCAL9539A_I2C_ADDR;
6070
}
6171

62-
/// Probing PCAL6416A chip
63-
if (!i2c_expander_addr && ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL6416A_I2C_ADDR) < 0) {
64-
printf("In %s - Failed to acquire bus access and/or talk to slave PCAL6416A_I2C_ADDR 0x%02X.\n",
65-
__func__, PCAL6416A_I2C_ADDR);
66-
}
67-
else{
68-
DEBUG_PRINTF("Found I2C gpio expander chip: PCAL6416A\n");
69-
i2c_expander_addr = PCAL6416A_I2C_ADDR;
70-
}
71-
7272
/// GPIO expander chip found?
7373
if(!i2c_expander_addr){
7474
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){
119119
val = 0xFFFF-val;
120120
DEBUG_PRINTF("READ PCAL6416A_INPUT (active GPIOs) : 0x%04X\n",val);
121121
return (int) val;
122-
}
122+
}

gpio_mapping.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,3 @@ int listen_gpios_interrupts(void)
491491

492492
return 0;
493493
}
494-

0 commit comments

Comments
 (0)