From a2351ba0d51412c43c2a9699fee1d445af5f28ff Mon Sep 17 00:00:00 2001 From: Stefan Krupop Date: Thu, 25 Jul 2024 01:13:14 +0200 Subject: [PATCH 1/3] Add support for AW9523 port expander --- components/services/gpio_exp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/components/services/gpio_exp.c b/components/services/gpio_exp.c index 2f86ff337..126b7b270 100644 --- a/components/services/gpio_exp.c +++ b/components/services/gpio_exp.c @@ -83,6 +83,10 @@ static void mcp23s17_set_direction(gpio_exp_t* self); static uint32_t mcp23s17_read(gpio_exp_t* self); static void mcp23s17_write(gpio_exp_t* self); +static void aw9523_set_direction(gpio_exp_t* self); +static uint32_t aw9523_read(gpio_exp_t* self); +static void aw9523_write(gpio_exp_t* self); + static void service_handler(void *arg); static void debounce_handler( TimerHandle_t xTimer ); @@ -130,6 +134,11 @@ static const struct gpio_exp_model_s { .set_pull_mode = mcp23s17_set_pull_mode, .read = mcp23s17_read, .write = mcp23s17_write, }, + { .model = "aw9523", + .trigger = GPIO_INTR_LOW_LEVEL, + .set_direction = aw9523_set_direction, + .read = aw9523_read, + .write = aw9523_write, }, }; static EXT_RAM_ATTR uint8_t n_expanders; @@ -671,6 +680,22 @@ static void mcp23s17_write(gpio_exp_t* self) { spi_write(self->spi_handle, self->phy.addr, 0x12, self->shadow, 2); } +/**************************************************************************************** + * AW9523 family : direction, read and write + */ +static void aw9523_set_direction(gpio_exp_t* self) { + i2c_write(self->phy.port, self->phy.addr, 0x04, self->r_mask, 2); + i2c_write(self->phy.port, self->phy.addr, 0x06, ~self->r_mask, 2); +} + +static uint32_t aw9523_read(gpio_exp_t* self) { + return i2c_read(self->phy.port, self->phy.addr, 0x00, 2); +} + +static void aw9523_write(gpio_exp_t* self) { + i2c_write(self->phy.port, self->phy.addr, 0x02, self->shadow, 2); +} + /*************************************************************************************** I2C low level ***************************************************************************************/ From 672aca8258a569732e2f5957162ba8ce22d65873 Mon Sep 17 00:00:00 2001 From: Stefan Krupop Date: Fri, 26 Jul 2024 20:18:55 +0200 Subject: [PATCH 2/3] Fixed resetting interrupt --- components/services/gpio_exp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/services/gpio_exp.c b/components/services/gpio_exp.c index 126b7b270..a284e7744 100644 --- a/components/services/gpio_exp.c +++ b/components/services/gpio_exp.c @@ -689,7 +689,9 @@ static void aw9523_set_direction(gpio_exp_t* self) { } static uint32_t aw9523_read(gpio_exp_t* self) { - return i2c_read(self->phy.port, self->phy.addr, 0x00, 2); + // Reading both registers in one go does not seem to reset IRQ correctly + uint8_t port1 = i2c_read(self->phy.port, self->phy.addr, 0x00, 1); + return (i2c_read(self->phy.port, self->phy.addr, 0x01, 1) << 8) | port1; } static void aw9523_write(gpio_exp_t* self) { @@ -818,4 +820,4 @@ static uint32_t spi_read(spi_device_handle_t handle, uint8_t addr, uint8_t reg, free(transaction); return data; -} \ No newline at end of file +} From 9d71b8ee267278ba38ba7e2677e0ca736d54f3e5 Mon Sep 17 00:00:00 2001 From: Stefan Krupop Date: Fri, 26 Jul 2024 21:01:10 +0200 Subject: [PATCH 3/3] Added "aw9523" to list of possible expanders --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b62620c8..907ae8c2f 100644 --- a/README.md +++ b/README.md @@ -308,7 +308,7 @@ The parameter "gpio_exp_config" is a semicolon (;) separated list with following ``` model=,addr=,[,port=system|dac][,base=][,count=][,intr=][,cs=][,speed=] ``` -- model: pca9535, pca85xx, mcp23017 and mcp23s17 (SPI version) +- model: pca9535, pca85xx, mcp23017, aw9523 and mcp23s17 (SPI version) - addr: chip i2c/spi address (decimal) - port (I2C): use either "system" port (shared with display for example) or "dac" port (system is default) - cs (SPI): gpio used for Chip Select