mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
Add set_GPIO, handle GPIO 36/39 bug
This commit is contained in:
@@ -17,6 +17,13 @@
|
||||
#include "driver/adc.h"
|
||||
#include "battery.h"
|
||||
|
||||
/*
|
||||
There is a bug in esp32 which causes a spurious interrupt on gpio 36/39 when
|
||||
using ADC, AMP and HALL sensor. Rather than making battery aware, we just ignore
|
||||
if as the interrupt lasts 80ns and should be debounced (and the ADC read does not
|
||||
happen very often)
|
||||
*/
|
||||
|
||||
#define BATTERY_TIMER (10*1000)
|
||||
|
||||
static const char *TAG = "battery";
|
||||
@@ -27,6 +34,13 @@ static struct {
|
||||
TimerHandle_t timer;
|
||||
} battery;
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
int battery_value_svc(void) {
|
||||
return battery.avg;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include "esp_task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "buttons.h"
|
||||
#include "globdefs.h"
|
||||
|
||||
bool gpio36_39_used;
|
||||
|
||||
static const char * TAG = "buttons";
|
||||
|
||||
@@ -208,7 +211,10 @@ void button_create(void *client, int gpio, int type, bool pull, int debounce, bu
|
||||
ESP_LOGW(TAG, "cannot set pull up/down for gpio %u", gpio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// nasty ESP32 bug: fire-up constantly INT on GPIO 36/39 if ADC1, AMP, Hall which WiFi when PS is activated
|
||||
if (gpio == 36 || gpio == 39) gpio36_39_used = true;
|
||||
|
||||
gpio_isr_handler_add(gpio, gpio_isr_handler, (void*) &buttons[n_buttons]);
|
||||
gpio_intr_enable(gpio);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#define I2C_SYSTEM_PORT 1
|
||||
extern int i2c_system_port;
|
||||
extern bool gpio36_39_used;
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define JACK_GPIO 34
|
||||
|
||||
@@ -26,3 +26,5 @@ extern bool jack_inserted_svc(void);
|
||||
extern void (*spkfault_handler_svc)(bool inserted);
|
||||
extern bool spkfault_svc(void);
|
||||
|
||||
extern int battery_value_svc(void);
|
||||
|
||||
|
||||
@@ -41,17 +41,19 @@ void services_init(void) {
|
||||
#endif
|
||||
|
||||
// set fixed gpio if any
|
||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "Vcc_GPIO")) != NULL) {
|
||||
char *p = nvs_item;
|
||||
while (p && *p) {
|
||||
int gpio = atoi(p);
|
||||
gpio_pad_select_gpio(gpio);
|
||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(gpio, 1);
|
||||
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, ',');
|
||||
ESP_LOGI(TAG, "set GPIO %u to Vcc", gpio);
|
||||
if (p) p++;
|
||||
}
|
||||
} while (p++);
|
||||
free(nvs_item);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user