3030 * Static variables
3131 ****************************************************************/
3232static int fd_i2c_expander ;
33+ static unsigned int i2c_expander_addr ;
3334static char i2c0_sysfs_filename [] = "/dev/i2c-0" ;
3435
3536/****************************************************************
@@ -45,15 +46,32 @@ bool pcal6416a_init(void) {
4546 // ERROR HANDLING; you can check errno to see what went wrong
4647 return false;
4748 }
49+
50+ i2c_expander_addr = 0 ;
4851
49- if (ioctl (fd_i2c_expander ,I2C_SLAVE ,PCAL6416A_I2C_ADDR ) < 0 ) {
50- printf ("In pcal6416a_init - Failed to acquire bus access and/or talk to slave.\n" );
51- // ERROR HANDLING; you can check errno to see what went wrong
52- if (ioctl (fd_i2c_expander , I2C_SLAVE_FORCE , PCAL6416A_I2C_ADDR ) < 0 ) {
53- printf ("In pcal6416a_init - Failed to acquire FORCED bus access and/or talk to slave.\n" );
54- // ERROR HANDLING; you can check errno to see what went wrong
55- return false;
56- }
52+ /// Probing PCAL9539A chip
53+ if (ioctl (!i2c_expander_addr && 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" ,
55+ __func__ , PCAL9539A_I2C_ADDR );
56+ }
57+ else {
58+ DEBUG_PRINTF ("Found I2C gpio expander chip: PCAL9539A\n" );
59+ i2c_expander_addr = PCAL9539A_I2C_ADDR ;
60+ }
61+
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+
72+ /// GPIO expander chip found?
73+ if (!i2c_expander_addr ){
74+ printf ("In %s - Failed to acquire bus access and/or talk to slave, exit\n" );
5775 return false;
5876 }
5977
0 commit comments