mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +03:00
Add set_GPIO, handle GPIO 36/39 bug
This commit is contained in:
@@ -17,6 +17,13 @@
|
|||||||
#include "driver/adc.h"
|
#include "driver/adc.h"
|
||||||
#include "battery.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)
|
#define BATTERY_TIMER (10*1000)
|
||||||
|
|
||||||
static const char *TAG = "battery";
|
static const char *TAG = "battery";
|
||||||
@@ -27,6 +34,13 @@ static struct {
|
|||||||
TimerHandle_t timer;
|
TimerHandle_t timer;
|
||||||
} battery;
|
} battery;
|
||||||
|
|
||||||
|
/****************************************************************************************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int battery_value_svc(void) {
|
||||||
|
return battery.avg;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -31,6 +31,9 @@
|
|||||||
#include "esp_task.h"
|
#include "esp_task.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
|
#include "globdefs.h"
|
||||||
|
|
||||||
|
bool gpio36_39_used;
|
||||||
|
|
||||||
static const char * TAG = "buttons";
|
static const char * TAG = "buttons";
|
||||||
|
|
||||||
@@ -209,6 +212,9 @@ void button_create(void *client, int gpio, int type, bool pull, int debounce, bu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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_isr_handler_add(gpio, gpio_isr_handler, (void*) &buttons[n_buttons]);
|
||||||
gpio_intr_enable(gpio);
|
gpio_intr_enable(gpio);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#define I2C_SYSTEM_PORT 1
|
#define I2C_SYSTEM_PORT 1
|
||||||
extern int i2c_system_port;
|
extern int i2c_system_port;
|
||||||
|
extern bool gpio36_39_used;
|
||||||
|
|
||||||
#ifdef CONFIG_SQUEEZEAMP
|
#ifdef CONFIG_SQUEEZEAMP
|
||||||
#define JACK_GPIO 34
|
#define JACK_GPIO 34
|
||||||
|
|||||||
@@ -26,3 +26,5 @@ extern bool jack_inserted_svc(void);
|
|||||||
extern void (*spkfault_handler_svc)(bool inserted);
|
extern void (*spkfault_handler_svc)(bool inserted);
|
||||||
extern bool spkfault_svc(void);
|
extern bool spkfault_svc(void);
|
||||||
|
|
||||||
|
extern int battery_value_svc(void);
|
||||||
|
|
||||||
|
|||||||
@@ -41,17 +41,19 @@ void services_init(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set fixed gpio if any
|
// set fixed gpio if any
|
||||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "Vcc_GPIO")) != NULL) {
|
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) != NULL) {
|
||||||
char *p = nvs_item;
|
char *p = nvs_item, type[4];
|
||||||
while (p && *p) {
|
int gpio;
|
||||||
int gpio = atoi(p);
|
do {
|
||||||
gpio_pad_select_gpio(gpio);
|
if (sscanf(p, "%d=%3[^,]", &gpio, type) > 0) {
|
||||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
gpio_pad_select_gpio(gpio);
|
||||||
gpio_set_level(gpio, 1);
|
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, ',');
|
p = strchr(p, ',');
|
||||||
ESP_LOGI(TAG, "set GPIO %u to Vcc", gpio);
|
} while (p++);
|
||||||
if (p) p++;
|
|
||||||
}
|
|
||||||
free(nvs_item);
|
free(nvs_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,13 +57,12 @@ Contains the freeRTOS task and all necessary support
|
|||||||
#include "lwip/ip4_addr.h"
|
#include "lwip/ip4_addr.h"
|
||||||
#include "esp_ota_ops.h"
|
#include "esp_ota_ops.h"
|
||||||
#include "esp_app_format.h"
|
#include "esp_app_format.h"
|
||||||
#include "driver/gpio.h"
|
|
||||||
#include "driver/adc.h"
|
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "cmd_system.h"
|
#include "cmd_system.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
|
#include "globdefs.h"
|
||||||
|
|
||||||
#ifndef RECOVERY_APPLICATION
|
#ifndef RECOVERY_APPLICATION
|
||||||
#define RECOVERY_APPLICATION 0
|
#define RECOVERY_APPLICATION 0
|
||||||
@@ -270,6 +269,10 @@ void wifi_manager_init_wifi(){
|
|||||||
ESP_LOGD(TAG, "Initializing wifi. Setting WiFi mode to WIFI_MODE_NULL");
|
ESP_LOGD(TAG, "Initializing wifi. Setting WiFi mode to WIFI_MODE_NULL");
|
||||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
|
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
|
||||||
ESP_LOGD(TAG, "Initializing wifi. Starting wifi");
|
ESP_LOGD(TAG, "Initializing wifi. Starting wifi");
|
||||||
|
if (gpio36_39_used) {
|
||||||
|
ESP_LOGW(TAG, "GPIO 36 or 39 are in use, need to disable WiFi PowerSave!");
|
||||||
|
esp_wifi_set_ps(WIFI_PS_NONE);
|
||||||
|
}
|
||||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
ESP_LOGD(TAG, "Initializing wifi. done");
|
ESP_LOGD(TAG, "Initializing wifi. done");
|
||||||
@@ -453,7 +456,7 @@ cJSON * wifi_manager_get_basic_info(cJSON **old){
|
|||||||
cJSON_AddItemToObject(root, "ota_dsc", cJSON_CreateString(ota_get_status()));
|
cJSON_AddItemToObject(root, "ota_dsc", cJSON_CreateString(ota_get_status()));
|
||||||
cJSON_AddNumberToObject(root,"ota_pct", ota_get_pct_complete() );
|
cJSON_AddNumberToObject(root,"ota_pct", ota_get_pct_complete() );
|
||||||
cJSON_AddItemToObject(root, "Jack", cJSON_CreateString(jack_inserted_svc() ? "1" : "0"));
|
cJSON_AddItemToObject(root, "Jack", cJSON_CreateString(jack_inserted_svc() ? "1" : "0"));
|
||||||
cJSON_AddNumberToObject(root,"Voltage", adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1);
|
cJSON_AddNumberToObject(root,"Voltage", battery_value_svc());
|
||||||
cJSON_AddNumberToObject(root,"disconnect_count", num_disconnect );
|
cJSON_AddNumberToObject(root,"disconnect_count", num_disconnect );
|
||||||
cJSON_AddNumberToObject(root,"avg_conn_time", num_disconnect>0?(total_connected_time/num_disconnect):0 );
|
cJSON_AddNumberToObject(root,"avg_conn_time", num_disconnect>0?(total_connected_time/num_disconnect):0 );
|
||||||
|
|
||||||
|
|||||||
@@ -306,8 +306,8 @@ void register_default_nvs(){
|
|||||||
ESP_LOGD(TAG,"Registering default value for key %s", "i2c_config");
|
ESP_LOGD(TAG,"Registering default value for key %s", "i2c_config");
|
||||||
config_set_default(NVS_TYPE_STR, "i2c_config", "", 0);
|
config_set_default(NVS_TYPE_STR, "i2c_config", "", 0);
|
||||||
|
|
||||||
ESP_LOGD(TAG,"Registering default value for key %s", "Vcc_GPIO");
|
ESP_LOGD(TAG,"Registering default value for key %s", "set_GPIO");
|
||||||
config_set_default(NVS_TYPE_STR, "Vcc_GPIO", "", 0);
|
config_set_default(NVS_TYPE_STR, "set_GPIO", "", 0);
|
||||||
|
|
||||||
ESP_LOGD(TAG,"Registering default value for key %s", "metadata_config");
|
ESP_LOGD(TAG,"Registering default value for key %s", "metadata_config");
|
||||||
config_set_default(NVS_TYPE_STR, "metadata_config", "", 0);
|
config_set_default(NVS_TYPE_STR, "metadata_config", "", 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user