Browse Source

fix multi I2C GPIO expander detection

Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
Michel-FK 3 years ago
parent
commit
44035d48c2
3 changed files with 16 additions and 16 deletions
  1. 1 0
      .gitignore
  2. 15 15
      driver_pcal6416a.c
  3. 0 1
      gpio_mapping.c

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@
 ###################
 *.o
 funkey_gpio_management
+termfix

+ 15 - 15
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;
-}
+}

+ 0 - 1
gpio_mapping.c

@@ -491,4 +491,3 @@ int listen_gpios_interrupts(void)
 
 	return 0;
 }
-