mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 04:57:06 +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;
|
if(i2c_port) *i2c_port=i2c_system_port;
|
||||||
return &i2c;
|
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);
|
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
|
||||||
const i2c_config_t * config_i2c_get(int * i2c_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;
|
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;
|
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) {
|
if (lines[num].y + lines[num].font->Height > Display.Height) {
|
||||||
ESP_LOGW(TAG, "line does not fit display");
|
ESP_LOGW(TAG, "line does not fit display");
|
||||||
|
|||||||
@@ -84,18 +84,31 @@ bool spkfault_svc (void) {
|
|||||||
#endif
|
#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) {
|
void monitor_svc_init(void) {
|
||||||
ESP_LOGI(TAG, "Initializing monitoring");
|
ESP_LOGI(TAG, "Initializing monitoring");
|
||||||
|
|
||||||
#if defined(JACK_GPIO) && JACK_GPIO != -1
|
#if !defined(JACK_GPIO) || JACK_GPIO == -1
|
||||||
gpio_pad_select_gpio(JACK_GPIO);
|
parse_set_GPIO(set_jack_gpio);
|
||||||
gpio_set_direction(JACK_GPIO, GPIO_MODE_INPUT);
|
#else
|
||||||
|
set_jack_gpio(JACK_GPIO, "jack");
|
||||||
// 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);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SPKFAULT_GPIO
|
#ifdef SPKFAULT_GPIO
|
||||||
|
|||||||
@@ -25,6 +25,25 @@ int i2c_system_port = I2C_SYSTEM_PORT;
|
|||||||
|
|
||||||
static const char *TAG = "services";
|
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
|
#endif
|
||||||
|
|
||||||
// set fixed gpio if any
|
// set potential power GPIO
|
||||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) != NULL) {
|
parse_set_GPIO(set_power_gpio);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
const i2c_config_t * i2c_config = config_i2c_get(&i2c_system_port);
|
const i2c_config_t * i2c_config = config_i2c_get(&i2c_system_port);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ sure that using rate_delay would fix that
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "accessors.h"
|
||||||
|
|
||||||
#define LOCK mutex_lock(outputbuf->mutex)
|
#define LOCK mutex_lock(outputbuf->mutex)
|
||||||
#define UNLOCK mutex_unlock(outputbuf->mutex)
|
#define UNLOCK mutex_unlock(outputbuf->mutex)
|
||||||
@@ -151,6 +152,21 @@ static void jack_handler(bool inserted) {
|
|||||||
if (jack_handler_chain) (jack_handler_chain)(inserted);
|
if (jack_handler_chain) (jack_handler_chain)(inserted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************
|
||||||
|
* amp GPIO
|
||||||
|
*/
|
||||||
|
void set_amp_gpio(int gpio, char *value) {
|
||||||
|
if (!strcasecmp(value, "amp")) {
|
||||||
|
amp_gpio = gpio;
|
||||||
|
|
||||||
|
gpio_pad_select_gpio(amp_gpio);
|
||||||
|
gpio_set_direction(amp_gpio, GPIO_MODE_OUTPUT);
|
||||||
|
gpio_set_level(amp_gpio, 0);
|
||||||
|
|
||||||
|
LOG_INFO("setting amplifier GPIO %d", amp_gpio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* Initialize the DAC output
|
* Initialize the DAC output
|
||||||
*/
|
*/
|
||||||
@@ -258,16 +274,8 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
|||||||
if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false);
|
if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false);
|
||||||
else adac->speaker(true);
|
else adac->speaker(true);
|
||||||
|
|
||||||
p = config_alloc_get_default(NVS_TYPE_STR, "amp_GPIO", NULL, 0);
|
parse_set_GPIO(set_amp_gpio);
|
||||||
if (p && *p) {
|
|
||||||
amp_gpio = atoi(p);
|
|
||||||
gpio_pad_select_gpio(amp_gpio);
|
|
||||||
gpio_set_direction(amp_gpio, GPIO_MODE_OUTPUT);
|
|
||||||
gpio_set_level(amp_gpio, 0);
|
|
||||||
LOG_INFO("setting amplifier GPIO %d", amp_gpio);
|
|
||||||
}
|
|
||||||
free(p);
|
|
||||||
|
|
||||||
esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
|
esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
|
||||||
|
|
||||||
cfg.thread_name= "output_i2s";
|
cfg.thread_name= "output_i2s";
|
||||||
|
|||||||
@@ -325,9 +325,6 @@ void register_default_nvs(){
|
|||||||
ESP_LOGD(TAG,"Registering default value for key %s", "stats");
|
ESP_LOGD(TAG,"Registering default value for key %s", "stats");
|
||||||
config_set_default(NVS_TYPE_STR, "stats", "n", 0);
|
config_set_default(NVS_TYPE_STR, "stats", "n", 0);
|
||||||
|
|
||||||
ESP_LOGD(TAG,"Registering default value for key %s", "amp_GPIO");
|
|
||||||
config_set_default(NVS_TYPE_STR, "amp_GPIO", "", 0);
|
|
||||||
|
|
||||||
ESP_LOGD(TAG,"Done setting default values in nvs.");
|
ESP_LOGD(TAG,"Done setting default values in nvs.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user