mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-31 23:01:05 +03:00
add multi-expander
This commit is contained in:
@@ -485,24 +485,31 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
|
|||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* Get IO expander config structure from config string
|
* Get IO expander config structure from config string
|
||||||
*/
|
*/
|
||||||
const gpio_exp_config_t* config_gpio_exp_get(void) {
|
const gpio_exp_config_t* config_gpio_exp_get(int index) {
|
||||||
char *nvs_item, *p;
|
char *nvs_item, *item, *p;
|
||||||
static gpio_exp_config_t config = {
|
static gpio_exp_config_t config;
|
||||||
.intr = -1,
|
|
||||||
.count = 16,
|
// re-initialize config every time
|
||||||
.base = GPIO_NUM_MAX,
|
memset(&config, 0, sizeof(config));
|
||||||
};
|
config.intr = -1; config.count = 16; config.base = GPIO_NUM_MAX; config.phy.port = i2c_system_port;
|
||||||
config.phy.port = i2c_system_port;
|
|
||||||
|
|
||||||
nvs_item = config_alloc_get(NVS_TYPE_STR, "gpio_exp_config");
|
nvs_item = config_alloc_get(NVS_TYPE_STR, "gpio_exp_config");
|
||||||
if (!nvs_item || !*nvs_item) return NULL;
|
if (!nvs_item || !*nvs_item) return NULL;
|
||||||
|
|
||||||
if ((p = strcasestr(nvs_item, "addr")) != NULL) config.phy.addr = atoi(strchr(p, '=') + 1);
|
// search index items
|
||||||
if ((p = strcasestr(nvs_item, "intr")) != NULL) config.intr = atoi(strchr(p, '=') + 1);
|
for (item = strtok(nvs_item, ";"); index && item; index--) {
|
||||||
if ((p = strcasestr(nvs_item, "base")) != NULL) config.base = atoi(strchr(p, '=') + 1);
|
if ((item = strtok(NULL, ";")) == NULL) {
|
||||||
if ((p = strcasestr(nvs_item, "count")) != NULL) config.count = atoi(strchr(p, '=') + 1);
|
free(nvs_item);
|
||||||
if ((p = strcasestr(nvs_item, "model")) != NULL) sscanf(p, "%*[^=]=%31[^,]", config.model);
|
return NULL;
|
||||||
if ((p = strcasestr(nvs_item, "port")) != NULL) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((p = strcasestr(item, "addr")) != NULL) config.phy.addr = atoi(strchr(p, '=') + 1);
|
||||||
|
if ((p = strcasestr(item, "intr")) != NULL) config.intr = atoi(strchr(p, '=') + 1);
|
||||||
|
if ((p = strcasestr(item, "base")) != NULL) config.base = atoi(strchr(p, '=') + 1);
|
||||||
|
if ((p = strcasestr(item, "count")) != NULL) config.count = atoi(strchr(p, '=') + 1);
|
||||||
|
if ((p = strcasestr(item, "model")) != NULL) sscanf(p, "%*[^=]=%31[^,]", config.model);
|
||||||
|
if ((p = strcasestr(item, "port")) != NULL) {
|
||||||
char port[8] = "";
|
char port[8] = "";
|
||||||
sscanf(p, "%*[^=]=%7[^,]", port);
|
sscanf(p, "%*[^=]=%7[^,]", port);
|
||||||
if (strcasestr(port, "dac")) config.phy.port = 0;
|
if (strcasestr(port, "dac")) config.phy.port = 0;
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char *
|
|||||||
esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc);
|
esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc);
|
||||||
const i2c_config_t * config_i2c_get(int * i2c_port);
|
const i2c_config_t * config_i2c_get(int * i2c_port);
|
||||||
const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host);
|
const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host);
|
||||||
const gpio_exp_config_t * config_gpio_exp_get(void);
|
const gpio_exp_config_t * config_gpio_exp_get(int index);
|
||||||
void parse_set_GPIO(void (*cb)(int gpio, char *value));
|
void parse_set_GPIO(void (*cb)(int gpio, char *value));
|
||||||
const i2s_platform_config_t * config_dac_get();
|
const i2s_platform_config_t * config_dac_get();
|
||||||
const i2s_platform_config_t * config_spdif_get( );
|
const i2s_platform_config_t * config_spdif_get( );
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ void services_init(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// create GPIO expander
|
// create GPIO expanders
|
||||||
const gpio_exp_config_t * gpio_exp_config = config_gpio_exp_get();
|
const gpio_exp_config_t* gpio_exp_config;
|
||||||
if (gpio_exp_config) gpio_exp_create(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)
|
// set potential power GPIO (a GPIO-powered expander might be an issue)
|
||||||
parse_set_GPIO(set_power_gpio);
|
parse_set_GPIO(set_power_gpio);
|
||||||
|
|||||||
Reference in New Issue
Block a user