From 16ba8e9e1fc111c3c992eea672b8d0b96b5a62b0 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Sat, 4 Dec 2021 19:32:52 -0800 Subject: [PATCH] small correction for MCP23017 that now works! --- components/services/gpio_exp.c | 6 +++--- components/services/services.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/services/gpio_exp.c b/components/services/gpio_exp.c index 48f99b72..5eabbd0e 100644 --- a/components/services/gpio_exp.c +++ b/components/services/gpio_exp.c @@ -187,7 +187,7 @@ gpio_exp_t* gpio_exp_create(const gpio_exp_config_t *config) { gpio_intr_enable(config->intr); } - ESP_LOGI(TAG, "Create GPIO expander at base %u with INT %u at @%x on port %d", config->base, config->intr, config->phy.addr, config->phy.port); + ESP_LOGI(TAG, "Create GPIO expander %s at base %u with INT %u at @%x on port %d", config->model, config->base, config->intr, config->phy.addr, config->phy.port); return expander; } @@ -241,7 +241,7 @@ esp_err_t gpio_exp_set_direction(int gpio, gpio_mode_t mode, gpio_exp_t *expande ESP_LOGE(TAG, "GPIO %d on expander base %u can't be r/w", gpio, expander->first); return ESP_ERR_INVALID_ARG; } - + // most expanders want unconfigured GPIO to be set to output if (expander->model->set_direction) expander->model->set_direction(expander); @@ -382,7 +382,7 @@ static gpio_exp_t* find_expander(gpio_exp_t *expander, int *gpio) { } // normalize GPIO number - if (expander && *gpio >= expanders->first) *gpio -= expanders->first; + if (expander && *gpio >= expander->first) *gpio -= expander->first; return expander; } diff --git a/components/services/services.c b/components/services/services.c index e3b1eff2..2b84f0c5 100644 --- a/components/services/services.c +++ b/components/services/services.c @@ -70,13 +70,6 @@ void services_init(void) { } #endif - // create GPIO expanders - const gpio_exp_config_t* gpio_exp_config; - for (int count = 0; (gpio_exp_config = config_gpio_exp_get(count)); count++) gpio_exp_create(gpio_exp_config); - - // set potential power GPIO (a GPIO-powered expander might be an issue) - parse_set_GPIO(set_power_gpio); - // shared I2C bus const i2c_config_t * i2c_config = config_i2c_get(&i2c_system_port); ESP_LOGI(TAG,"Configuring I2C sda:%d scl:%d port:%u speed:%u", i2c_config->sda_io_num, i2c_config->scl_io_num, i2c_system_port, i2c_config->master.clk_speed); @@ -89,6 +82,13 @@ void services_init(void) { ESP_LOGW(TAG, "no I2C configured"); } + // create GPIO expanders + const gpio_exp_config_t* gpio_exp_config; + for (int count = 0; (gpio_exp_config = config_gpio_exp_get(count)); count++) gpio_exp_create(gpio_exp_config); + + // set potential power GPIO (a GPIO-powered expander might be an issue) + parse_set_GPIO(set_power_gpio); + const spi_bus_config_t * spi_config = config_spi_get((spi_host_device_t*) &spi_system_host); ESP_LOGI(TAG,"Configuring SPI data:%d clk:%d host:%u dc:%d", spi_config->mosi_io_num, spi_config->sclk_io_num, spi_system_host, spi_system_dc_gpio);