first commit of GPIO expander

This commit is contained in:
Philippe G
2021-11-29 19:24:52 -08:00
parent 016bc1bb4d
commit 507c2c9755
11 changed files with 569 additions and 61 deletions

View File

@@ -482,6 +482,35 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
return &i2c;
}
/****************************************************************************************
* Get IO expander config structure from config string
*/
const gpio_exp_config_t* config_gpio_exp_get(void) {
char *nvs_item, *p;
static gpio_exp_config_t config = {
.intr = -1,
.count = 8,
};
config.phy.port = i2c_system_port;
nvs_item = config_alloc_get(NVS_TYPE_STR, "gpio_exp_config");
if (!nvs_item) return NULL;
if ((p = strcasestr(nvs_item, "addr")) != NULL) config.phy.addr = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(nvs_item, "intr")) != NULL) config.intr = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(nvs_item, "base")) != NULL) config.base = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(nvs_item, "count")) != NULL) config.count = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(nvs_item, "model")) != NULL) sscanf(p, "%*[^=]=%31[^,]", config.model);
if ((p = strcasestr(nvs_item, "port")) != NULL) {
char port[8] = "";
sscanf(p, "%*[^=]=%7[^,]", port);
if (strcasestr(port, "dac")) config.phy.port = 0;
}
free(nvs_item);
return &config;
}
/****************************************************************************************
*
*/