added support for PCAL9539A

This commit is contained in:
Vincent-FK 2021-03-15 23:16:09 +01:00
parent e2b637f3bd
commit 254f91c2b3
2 changed files with 27 additions and 8 deletions

View File

@ -30,6 +30,7 @@
* Static variables * Static variables
****************************************************************/ ****************************************************************/
static int fd_i2c_expander; static int fd_i2c_expander;
static unsigned int i2c_expander_addr;
static char i2c0_sysfs_filename[] = "/dev/i2c-0"; static char i2c0_sysfs_filename[] = "/dev/i2c-0";
/**************************************************************** /****************************************************************
@ -46,14 +47,31 @@ bool pcal6416a_init(void) {
return false; return false;
} }
if (ioctl(fd_i2c_expander,I2C_SLAVE,PCAL6416A_I2C_ADDR) < 0) { i2c_expander_addr = 0;
printf("In pcal6416a_init - Failed to acquire bus access and/or talk to slave.\n");
// ERROR HANDLING; you can check errno to see what went wrong /// Probing PCAL9539A chip
if (ioctl(fd_i2c_expander, I2C_SLAVE_FORCE, PCAL6416A_I2C_ADDR) < 0) { if (ioctl(!i2c_expander_addr && fd_i2c_expander, I2C_SLAVE_FORCE, PCAL9539A_I2C_ADDR) < 0) {
printf("In pcal6416a_init - Failed to acquire FORCED bus access and/or talk to slave.\n"); printf("In %s - Failed to acquire bus access and/or talk to slave PCAL9539A_I2C_ADDR 0x%02X.\n",
// ERROR HANDLING; you can check errno to see what went wrong __func__, PCAL9539A_I2C_ADDR);
return false; }
} 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");
return false; return false;
} }

View File

@ -12,6 +12,7 @@
****************************************************************/ ****************************************************************/
// Chip physical address // Chip physical address
#define PCAL6416A_I2C_ADDR 0x20 #define PCAL6416A_I2C_ADDR 0x20
#define PCAL9539A_I2C_ADDR 0x76
// Chip registers adresses // Chip registers adresses
#define PCAL6416A_INPUT 0x00 /* Input port [RO] */ #define PCAL6416A_INPUT 0x00 /* Input port [RO] */