diff options
author | JohSchneider <JohSchneider@googlemail.com> | 2022-10-14 01:03:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 18:03:32 -0700 |
commit | 3fffa51554556edc9ca53bc04ef45abe87d3d3c9 (patch) | |
tree | 56275b9d72b09f1fc6918c7748b3b03c51acef84 /drivers/gpio | |
parent | f4f638c160d32b6fd0a12a7ffd7a32b276763be9 (diff) |
mcp23018: add return status to init (#18178)
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/mcp23018.c | 14 | ||||
-rw-r--r-- | drivers/gpio/mcp23018.h | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/drivers/gpio/mcp23018.c b/drivers/gpio/mcp23018.c index 41cbfe087e..b4fbf296f8 100644 --- a/drivers/gpio/mcp23018.c +++ b/drivers/gpio/mcp23018.c @@ -18,14 +18,20 @@ enum { CMD_GPIOB = 0x13, }; -void mcp23018_init(uint8_t addr) { +bool mcp23018_init(uint8_t slave_addr) { static uint8_t s_init = 0; - if (!s_init) { + uint8_t addr = SLAVE_TO_ADDR(slave_addr); + if (0 == s_init) { i2c_init(); - wait_ms(1000); + wait_ms(100); - s_init = 1; + // probe that the expander is actually connected by reading from it + uint8_t data = 0; + if (I2C_STATUS_SUCCESS == i2c_readReg(addr, 0, &data, sizeof(data), 150)) { + s_init = 1; + } } + return (s_init > 0); } bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf) { diff --git a/drivers/gpio/mcp23018.h b/drivers/gpio/mcp23018.h index e7c2730dd1..081fdb24e3 100644 --- a/drivers/gpio/mcp23018.h +++ b/drivers/gpio/mcp23018.h @@ -33,7 +33,7 @@ enum { /** * Init expander and any other dependent drivers */ -void mcp23018_init(uint8_t slave_addr); +bool mcp23018_init(uint8_t slave_addr); /** * Configure input/output to a given port |