@@ -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+ }
0 commit comments