mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
merge misc GPIO options into set_GPIO
This commit is contained in:
@@ -58,3 +58,22 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
|
||||
if(i2c_port) *i2c_port=i2c_system_port;
|
||||
return &i2c;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void parse_set_GPIO(void (*cb)(int gpio, char *value)) {
|
||||
char *nvs_item, *p, type[4];
|
||||
int gpio;
|
||||
|
||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) == NULL) return;
|
||||
|
||||
p = nvs_item;
|
||||
|
||||
do {
|
||||
if (sscanf(p, "%d=%3[^,]", &gpio, type) > 0) cb(gpio, type);
|
||||
p = strchr(p, ',');
|
||||
} while (p++);
|
||||
|
||||
free(nvs_item);
|
||||
}
|
||||
@@ -13,3 +13,4 @@
|
||||
|
||||
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
|
||||
const i2c_config_t * config_i2c_get(int * i2c_port);
|
||||
void parse_set_GPIO(void (*cb)(int gpio, char *value));
|
||||
|
||||
@@ -164,7 +164,7 @@ static bool set_font(int num, enum display_font_e font, int space) {
|
||||
lines[0].y = lines[0].space;
|
||||
for (int i = 1; i <= num; i++) lines[i].y = lines[i-1].y + lines[i-1].font->Height + lines[i].space;
|
||||
|
||||
ESP_LOGI(TAG, "adding line %u at %d (height:%u)", num + 1, lines[num].y, lines[num].font->Height);
|
||||
ESP_LOGI(TAG, "Adding line %u at %d (height:%u)", num + 1, lines[num].y, lines[num].font->Height);
|
||||
|
||||
if (lines[num].y + lines[num].font->Height > Display.Height) {
|
||||
ESP_LOGW(TAG, "line does not fit display");
|
||||
|
||||
@@ -84,18 +84,31 @@ bool spkfault_svc (void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void set_jack_gpio(int gpio, char *value) {
|
||||
if (!strcasecmp(value, "jack")) {
|
||||
ESP_LOGI(TAG,"Adding jack detection gpio %d", gpio);
|
||||
|
||||
gpio_pad_select_gpio(JACK_GPIO);
|
||||
gpio_set_direction(JACK_GPIO, GPIO_MODE_INPUT);
|
||||
|
||||
// re-use button management for jack handler, it's a GPIO after all
|
||||
button_create(NULL, JACK_GPIO, BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void monitor_svc_init(void) {
|
||||
ESP_LOGI(TAG, "Initializing monitoring");
|
||||
|
||||
#if defined(JACK_GPIO) && JACK_GPIO != -1
|
||||
gpio_pad_select_gpio(JACK_GPIO);
|
||||
gpio_set_direction(JACK_GPIO, GPIO_MODE_INPUT);
|
||||
|
||||
// re-use button management for jack handler, it's a GPIO after all
|
||||
button_create(NULL, JACK_GPIO, BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
|
||||
#if !defined(JACK_GPIO) || JACK_GPIO == -1
|
||||
parse_set_GPIO(set_jack_gpio);
|
||||
#else
|
||||
set_jack_gpio(JACK_GPIO, "jack");
|
||||
#endif
|
||||
|
||||
#ifdef SPKFAULT_GPIO
|
||||
|
||||
@@ -25,6 +25,25 @@ int i2c_system_port = I2C_SYSTEM_PORT;
|
||||
|
||||
static const char *TAG = "services";
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void set_power_gpio(int gpio, char *value) {
|
||||
bool parsed = true;
|
||||
|
||||
if (!strcasecmp(value, "vcc") ) {
|
||||
gpio_pad_select_gpio(gpio);
|
||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(gpio, 1);
|
||||
} else if (!strcasecmp(value, "gnd")) {
|
||||
gpio_pad_select_gpio(gpio);
|
||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(gpio, 0);
|
||||
} else parsed = false ;
|
||||
|
||||
if (parsed) ESP_LOGI(TAG, "set GPIO %u to %s", gpio, value);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -40,22 +59,8 @@ void services_init(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// set fixed gpio if any
|
||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) != NULL) {
|
||||
char *p = nvs_item, type[4];
|
||||
int gpio;
|
||||
do {
|
||||
if (sscanf(p, "%d=%3[^,]", &gpio, type) > 0) {
|
||||
gpio_pad_select_gpio(gpio);
|
||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
||||
if (!strcasecmp(type, "vcc")) gpio_set_level(gpio, 1);
|
||||
else if (!strcasecmp(type, "gnd")) gpio_set_level(gpio, 0);
|
||||
ESP_LOGI(TAG, "set GPIO %u to %s", gpio, type);
|
||||
}
|
||||
p = strchr(p, ',');
|
||||
} while (p++);
|
||||
free(nvs_item);
|
||||
}
|
||||
// set potential power GPIO
|
||||
parse_set_GPIO(set_power_gpio);
|
||||
|
||||
const i2c_config_t * i2c_config = config_i2c_get(&i2c_system_port);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user