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

Commit 254f91c

Browse files
committed
added support for PCAL9539A
1 parent e2b637f commit 254f91c

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

driver_pcal6416a.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Static variables
3131
****************************************************************/
3232
static int fd_i2c_expander;
33+
static unsigned int i2c_expander_addr;
3334
static 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

driver_pcal6416a.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
****************************************************************/
1313
// Chip physical address
1414
#define PCAL6416A_I2C_ADDR 0x20
15+
#define PCAL9539A_I2C_ADDR 0x76
1516

1617
// Chip registers adresses
1718
#define PCAL6416A_INPUT 0x00 /* Input port [RO] */

0 commit comments

Comments
 (0)