Start of 5.X work

This commit is contained in:
Sebastien L
2025-03-18 17:38:34 -04:00
parent c0ddf0a997
commit 73bd096f37
442 changed files with 227862 additions and 21075 deletions

View File

@@ -26,26 +26,7 @@ menu "Squeezelite-ESP32"
help
Set logging level info|debug|sdebug
endmenu
config AMP_LOCKED
bool
config JACK_LOCKED
bool
config BAT_LOCKED
bool
config I2C_LOCKED
bool
config SPDIF_LOCKED
bool
config LED_LOCKED
bool
config SPKFAULT_LOCKED
bool
config MUTE_GPIO_LEVEL
int
default 0
config TARGET_LOCKED
bool
default n
menu "Target"
choice OUTPUT_TYPE
prompt "Main system"
@@ -54,25 +35,14 @@ menu "Squeezelite-ESP32"
Type of hardware platform
config SQUEEZEAMP
bool "SqueezeAMP"
select JACK_LOCKED
select BAT_LOCKED
select I2C_LOCKED
select LED_LOCKED
select SPKFAULT_LOCKED
select TARGET_LOCKED
config MUSE
bool "Muse"
select JACK_LOCKED
select BAT_LOCKED
select I2C_LOCKED
select AMP_LOCKED
select TARGET_LOCKED
config SQUEEZEIO
bool "SqueezeIO"
config BASIC_I2C_BT
bool "Generic I2S & Bluetooth"
config TWATCH2020
bool "T-WATCH2020 by LilyGo"
select I2C_LOCKED
select TARGET_LOCKED
endchoice
config WITH_CONFIG_UI
bool "Enable config UI"
@@ -101,90 +71,18 @@ menu "Squeezelite-ESP32"
default "SqueezeAMP" if SQUEEZEAMP
default "Squeezelite-TWATCH" if TWATCH2020
default "Muse" if MUSE
default "SqueezeIO" if SQUEEZEIO
default "Squeezelite-ESP32"
config FW_PLATFORM_NAME
string
default "SqueezeAmp" if SQUEEZEAMP
default "TWATCH" if TWATCH2020
default "Muse" if MUSE
default "SqueezeIO" if SQUEEZEIO
default "ESP32"
# AGGREGATES - begin
# these parameters are "aggregates" that take precedence. They must have a default value
config DAC_CONFIG
string
default "model=TAS57xx,bck=33,ws=25,do=32,sda=27,scl=26,mute=14:0" if SQUEEZEAMP
default "model=I2S,bck=26,ws=25,do=33,i2c=53,sda=21,scl=22" if TWATCH2020
default "model=I2S,bck=5,ws=25,do=26,di=35,i2c=16,sda=18,scl=23,mck" if MUSE
default ""
config SPDIF_CONFIG
string
default "bck=33,ws=25,do=15" if SQUEEZEAMP
default ""
config GPIO_EXP_CONFIG
string
default ""
config SPI_CONFIG
string
default "dc=27,data=19,clk=18" if TWATCH2020
default "mosi=15,miso=2,clk=14" if MUSE
default ""
config DISPLAY_CONFIG
string
default "SPI,driver=ST7789,width=240,height=240,cs=5,back=12,speed=16000000,HFlip,VFlip" if TWATCH2020
default ""
config ETH_CONFIG
string
default ""
# AGGREGATES - end
config DAC_CONTROLSET
string
default "{ \"init\": [ {\"reg\":41, \"val\":128}, {\"reg\":18, \"val\":255} ], \"poweron\": [ {\"reg\":18, \"val\":64, \"mode\":\"or\"} ], \"poweroff\": [ {\"reg\":18, \"val\":191, \"mode\":\"and\"} ] }" if TWATCH2020
default "{\"init\":[ {\"reg\":0,\"val\":128}, {\"reg\":0,\"val\":0}, {\"reg\":25,\"val\":4}, {\"reg\":1,\"val\":80}, {\"reg\":2,\"val\":0}, {\"reg\":8,\"val\":0}, {\"reg\":4,\"val\":192}, {\"reg\":0,\"val\":18}, {\"reg\":1,\"val\":0}, {\"reg\":23,\"val\":24}, {\"reg\":24,\"val\":2}, {\"reg\":38,\"val\":9}, {\"reg\":39,\"val\":144}, {\"reg\":42,\"val\":144}, {\"reg\":43,\"val\":128}, {\"reg\":45,\"val\":128}, {\"reg\":27,\"val\":0}, {\"reg\":26,\"val\":0}, {\"reg\":2,\"val\":240}, {\"reg\":2,\"val\":0}, {\"reg\":29,\"val\":28}, {\"reg\":4,\"val\":48}, {\"reg\":25,\"val\":0}, {\"reg\":46,\"val\":33}, {\"reg\":47,\"val\":33} ]}" if MUSE
default ""
config AUDIO_CONTROLS
string
default "[{\"gpio\":32, \"pull\":true, \"long_press\":1000, \"normal\":{\"pressed\":\"ACTRLS_VOLDOWN\"}, \"longpress\":{\"pressed\":\"ACTRLS_PREV\"}}, {\"gpio\":19, \"pull\":true, \"long_press\":1000, \"normal\":{\"pressed\":\"ACTRLS_VOLUP\"}, \"longpress\":{\"pressed\":\"ACTRLS_NEXT\"}}, {\"gpio\":12, \"pull\":true, \"long_press\":1000, \"normal\":{\"pressed\":\"ACTRLS_TOGGLE\"},\"longpress\":{\"pressed\":\"ACTRLS_POWER\"}}]" if MUSE
default ""
config BAT_CONFIG
string
default "channel=7,scale=20.24,atten=0" if SQUEEZEAMP
default "channel=5,scale=7.00,atten=3,cells=1" if MUSE
default ""
config TARGET
string
default "muse" if MUSE
default ""
config AMP_GPIO
int
default 21 if MUSE
default -1
config POWER_GPIO
int
default -1
config JACK_GPIO
int
default 34 if SQUEEZEAMP || MUSE
default -1
config SPKFAULT_GPIO
int
default 2 if SQUEEZEAMP
default -1
config BAT_CHANNEL
int
default 7 if SQUEEZEAMP
default -1
config LED_GREEN_GPIO
int
default 12 if SQUEEZEAMP
default -1
config LED_RED_GPIO
int
default 13 if SQUEEZEAMP
default -1
config SET_GPIO
string
default "0=ir" if SQUEEZEAMP
default "" if TWATCH2020
endmenu
menu "Audio settings"
@@ -239,10 +137,6 @@ menu "Squeezelite-ESP32"
default -1
help
GPIO used to mute DAC (not used mostly, leave it to -1).
config MUTE_GPIO_LEVEL
int "Mute GPIO active level"
depends on MUTE_GPIO != -1
default 1
endmenu
menu "SPDIF settings"
@@ -407,7 +301,6 @@ menu "Squeezelite-ESP32"
endmenu
menu "Audio JACK"
visible if !TARGET_LOCKED
config JACK_GPIO
int "Jack insertion GPIO"
help
@@ -419,7 +312,6 @@ menu "Squeezelite-ESP32"
endmenu
menu "External amplifier control"
visible if !AMP_LOCKED
config AMP_GPIO
int "Amplifier GPIO"
help
@@ -430,31 +322,8 @@ menu "Squeezelite-ESP32"
default 1
endmenu
menu "Power on/off status"
config POWER_GPIO
int "Power on/off GPIO"
help
GPIO that is switched when LMS turns player one. Set to -1 to disable
config POWER_GPIO_LEVEL
depends on POWER_GPIO != -1
int "Active level(0/1)"
default 1
endmenu
menu "Speaker Fault"
visible if !TARGET_LOCKED
config SPKFAULT_GPIO
int "Speaker fault GPIO"
help
GPIO to detect speaker fault condition. Set to -1 for no detection.
config SPKFAULT_GPIO_LEVEL
depends on SPKFAULT_GPIO != -1
int "Level when fault (0/1)"
default 0
endmenu
menu "Battery measure"
visible if !TARGET_LOCKED
config BAT_CONFIG
string "Battery acquisition configuration"
help

View File

@@ -1,12 +0,0 @@
#
# Component Makefile
#
# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default,
# this will take the sources in the src/ directory, compile them and link them into
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the SDK documents if you need to do this.
#
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_INFO -DMODEL_NAME=SqueezeESP32
LDFLAGS += -s
COMPONENT_EMBED_TXTFILES := ${PROJECT_PATH}/server_certs/github.pem
COMPONENT_ADD_INCLUDEDIRS := .

View File

@@ -1,4 +1,4 @@
/*
/*
* Squeezelite for esp32
*
* (c) Sebastien 2019
@@ -9,330 +9,209 @@
*
*/
#include "platform_esp32.h"
#include "Config.h"
#include "accessors.h"
#include "audio_controls.h"
#include "cmd_system.h"
#include "display.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "gds_draw.h"
#include "gds_font.h"
#include "gds_text.h"
#include "led.h"
#include "led_vu.h"
#include "mdns.h"
#include "messaging.h"
#include "network_manager.h"
#include "platform_esp32.h"
#include "squeezelite-ota.h"
#include "telnet.h"
#include "tools.h"
#include "trace.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/task.h"
#include "esp_spi_flash.h"
#include "esp_wifi.h"
#include <esp_event.h>
#include "esp_log.h"
#include "freertos/event_groups.h"
#include "mdns.h"
#include "lwip/api.h"
#include "lwip/err.h"
#include "lwip/netdb.h"
#include "trace.h"
#include "network_manager.h"
#include "squeezelite-ota.h"
#include <math.h>
#include "audio_controls.h"
#include "Configurator.h"
#include "telnet.h"
#include "messaging.h"
#include "gds.h"
#include "gds_default_if.h"
#include "gds_draw.h"
#include "gds_text.h"
#include "gds_font.h"
#include "led_vu.h"
#include "display.h"
#include "accessors.h"
#include "cmd_system.h"
#include "tools.h"
#include "bootstate.h"
#include "platform_console.h"
#include "system_time.h"
#if defined(CONFIG_WITH_METRICS)
#include "Metrics.h"
#endif
#ifdef CONFIG_HEAP_TRACING
#include "esp_heap_trace.h"
#endif
const char unknown_string_placeholder[] = "unknown";
const char null_string_placeholder[] = "null";
EventGroupHandle_t network_event_group;
bool bypass_network_manager=false;
const int CONNECTED_BIT = BIT0;
#define JOIN_TIMEOUT_MS (10000)
#define LOCAL_MAC_SIZE 20
static const char TAG[] = "esp_app_main";
#define DEFAULT_HOST_NAME "squeezelite"
RTC_NOINIT_ATTR uint32_t RebootCounter ;
RTC_NOINIT_ATTR uint32_t RecoveryRebootCounter ;
RTC_NOINIT_ATTR uint16_t ColdBootIndicatorFlag;
bool cold_boot=true;
#ifdef CONFIG_IDF_TARGET_ESP32S3
extern const char _ctype_[];
const char* __ctype_ptr__ = _ctype_;
#endif
static bool bNetworkConnected=false;
// as an exception _init function don't need include
extern void services_init(void);
extern void services_ports_init(void);
extern void services_gpio_init(void);
extern void services_sleep_init(void);
extern void display_init(char *welcome);
extern void display_init(char* welcome);
extern void led_vu_init(void);
extern void target_init(char *target);
extern void target_init(char* target);
extern void start_squeezelite();
const char * str_or_unknown(const char * str) { return (str?str:unknown_string_placeholder); }
const char * str_or_null(const char * str) { return (str?str:null_string_placeholder); }
bool is_recovery_running;
bool is_network_connected(){
return bNetworkConnected;
}
void cb_connection_got_ip(nm_state_t new_state, int sub_state){
const char *hostname;
static ip4_addr_t ip;
tcpip_adapter_ip_info_t ipInfo;
network_get_ip_info(&ipInfo);
if (ip.addr && ipInfo.ip.addr != ip.addr) {
ESP_LOGW(TAG, "IP change, need to reboot");
if(!configurator_waitcommit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
esp_restart();
}
// initializing mDNS
network_get_hostname(&hostname);
void cb_connection_got_ip(nm_state_t new_state, int sub_state) {
const char* hostname;
static ip4_addr_t ip;
tcpip_adapter_ip_info_t ipInfo;
network_get_ip_info(&ipInfo);
if (ip.addr && ipInfo.ip.addr != ip.addr) {
config_raise_changed(false);
ESP_LOGW(TAG, "IP change, need to reboot");
simple_restart();
}
system_time_init();
// initializing mDNS
network_get_hostname(&hostname);
mdns_init();
mdns_hostname_set(hostname);
ESP_LOGI(TAG, "Network connected and mDNS initialized with %s", hostname);
messaging_post_message(MESSAGING_INFO,MESSAGING_CLASS_SYSTEM,"Network connected");
xEventGroupSetBits(network_event_group, CONNECTED_BIT);
bNetworkConnected=true;
ESP_LOGI(TAG, "Network connected and mDNS initialized with %s", hostname);
messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_SYSTEM, "Network connected");
led_unpush(LED_GREEN);
if(is_recovery_running){
// when running in recovery, send a LMS discovery message
// to find a running instance. This is to enable using
// the plugin's proxy mode for FW download and avoid
// expired certificate issues.
discover_ota_server(5);
}
}
void cb_connection_sta_disconnected(nm_state_t new_state, int sub_state){
led_blink_pushed(LED_GREEN, 250, 250);
messaging_post_message(MESSAGING_WARNING,MESSAGING_CLASS_SYSTEM,"Wifi disconnected");
bNetworkConnected=false;
xEventGroupClearBits(network_event_group, CONNECTED_BIT);
}
bool wait_for_wifi(){
bool connected=(xEventGroupGetBits(network_event_group) & CONNECTED_BIT)!=0;
if(!connected){
ESP_LOGD(TAG,"Waiting for Network...");
connected = (xEventGroupWaitBits(network_event_group, CONNECTED_BIT,
pdFALSE, pdTRUE, JOIN_TIMEOUT_MS / portTICK_PERIOD_MS)& CONNECTED_BIT)!=0;
if(!connected){
ESP_LOGW(TAG,"Network timeout.");
}
else
{
ESP_LOGI(TAG,"Network Connected!");
}
}
return connected;
}
esp_log_level_t get_log_level_from_char(char * level){
if(!strcasecmp(level, "NONE" )) { return ESP_LOG_NONE ;}
if(!strcasecmp(level, "ERROR" )) { return ESP_LOG_ERROR ;}
if(!strcasecmp(level, "WARN" )) { return ESP_LOG_WARN ;}
if(!strcasecmp(level, "INFO" )) { return ESP_LOG_INFO ;}
if(!strcasecmp(level, "DEBUG" )) { return ESP_LOG_DEBUG ;}
if(!strcasecmp(level, "VERBOSE" )) { return ESP_LOG_VERBOSE;}
return ESP_LOG_WARN;
}
void set_log_level(char * tag, char * level){
esp_log_level_set(tag, get_log_level_from_char(level));
}
uint32_t halSTORAGE_RebootCounterRead(void) { return RebootCounter ; }
uint32_t halSTORAGE_RebootCounterUpdate(int32_t xValue) {
if(RebootCounter >100) {
RebootCounter = 0;
RecoveryRebootCounter = 0;
}
RebootCounter = (xValue != 0) ? (RebootCounter + xValue) : 0;
RecoveryRebootCounter = (xValue != 0) && is_recovery_running ? (RecoveryRebootCounter + xValue) : 0;
return RebootCounter ;
}
void handle_ap_connect(nm_state_t new_state, int sub_state){
start_telnet(NULL);
}
void handle_network_up(nm_state_t new_state, int sub_state){
halSTORAGE_RebootCounterUpdate(0);
}
esp_reset_reason_t xReason=ESP_RST_UNKNOWN;
void app_main()
{
if(ColdBootIndicatorFlag != 0xFACE ){
ESP_LOGI(TAG, "System is booting from power on.");
cold_boot = true;
ColdBootIndicatorFlag = 0xFACE;
led_unpush(LED_GREEN);
if (is_recovery_running) {
// when running in recovery, send a LMS discovery message
// to find a running instance. This is to enable using
// the plugin's proxy mode for FW download and avoid
// expired certificate issues.
discover_ota_server(5);
}
else {
cold_boot = false;
}
const esp_partition_t *running = esp_ota_get_running_partition();
is_recovery_running = (running->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY);
xReason = esp_reset_reason();
ESP_LOGI(TAG,"Reset reason is: %u. Running from partition %s type %s ",
xReason,
running->label,
running->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY?"Factory":"Application");
if(!is_recovery_running ) {
/* unscheduled restart (HW, Watchdog or similar) thus increment dynamic
* counter then log current boot statistics as a warning */
uint32_t Counter = halSTORAGE_RebootCounterUpdate(1) ; // increment counter
ESP_LOGI(TAG,"Reboot counter=%u\n", Counter) ;
if (Counter == 5) {
guided_factory();
}
}
else {
uint32_t Counter = halSTORAGE_RebootCounterUpdate(1) ; // increment counter
if(RecoveryRebootCounter==1 && Counter>=5){
// First time we are rebooting in recovery after crashing
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"System was forced into recovery mode after crash likely caused by some bad configuration\n");
}
ESP_LOGI(TAG,"Recovery Reboot counter=%u\n", Counter) ;
if (RecoveryRebootCounter == 5) {
ESP_LOGW(TAG,"System rebooted too many times. This could be an indication that configuration is corrupted. Erasing config.");
// TODO: Add support for the commented code
// erase_settings_partition();
// reboot one more time
#pragma message("Add support for erasing the configuration")
guided_factory();
}
if (RecoveryRebootCounter >5){
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"System was forced into recovery mode after crash likely caused by some bad configuration. Configuration was reset to factory.\n");
}
}
MEMTRACE_PRINT_DELTA();
ESP_LOGI(TAG,"Starting app_main");
init_spiffs();
listFiles("/");
ESP_LOGI(TAG,"Setting up config subsystem.");
configurator_load();
MEMTRACE_PRINT_DELTA();
#if defined(CONFIG_WITH_METRICS)
ESP_LOGI(TAG,"Setting up metrics.");
metrics_init();
MEMTRACE_PRINT_DELTA();
#endif
ESP_LOGI(TAG,"Setting up telnet.");
init_telnet(); // align on 32 bits boundaries
MEMTRACE_PRINT_DELTA();
ESP_LOGD(TAG,"Creating event group for wifi");
network_event_group = xEventGroupCreate();
ESP_LOGD(TAG,"Clearing CONNECTED_BIT from wifi group");
xEventGroupClearBits(network_event_group, CONNECTED_BIT);
MEMTRACE_PRINT_DELTA();
ESP_LOGI(TAG,"Configuring services");
services_init();
MEMTRACE_PRINT_DELTA();
ESP_LOGI(TAG,"Initializing display");
display_init("SqueezeESP32");
MEMTRACE_PRINT_DELTA();
if(strlen(platform->target)>0){
target_init(platform->target);
}
ESP_LOGI(TAG,"Initializing led_vu");
led_vu_init();
if(is_recovery_running) {
ESP_LOGI(TAG,"Turning on display");
if (display) {
GDS_ClearExt(display, true);
GDS_SetFont(display, Font_line_2 );
GDS_TextPos(display, GDS_FONT_DEFAULT, GDS_TEXT_CENTERED, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "RECOVERY");
}
if(led_display) {
led_vu_color_yellow(LED_VU_BRIGHT);
}
}
#if defined(CONFIG_WITH_METRICS)
metrics_event_boot(is_recovery_running?"recovery":"ota");
#endif
if(!is_recovery_running){
#pragma message("Add audio controls support")
// ESP_LOGD(TAG,"Getting audio control mapping ");
// if(platform->has_dev && platform->dev.buttons_count >0){
// ESP_LOGD(TAG,"Initializing audio control buttons");
// }
// char *actrls_config = config_alloc_get_default(NVS_TYPE_STR, "actrls_config", "", 0);
// if (actrls_init(actrls_config) == ESP_OK) {
// } else {
// ESP_LOGD(TAG,"No audio control buttons");
// }
// if (actrls_config) free(actrls_config);
// TODO: Add support for the commented code
}
/* start the wifi manager */
ESP_LOGD(TAG,"Blinking led");
led_blink_pushed(LED_GREEN, 250, 250);
MEMTRACE_PRINT_DELTA();
if(bypass_network_manager){
ESP_LOGW(TAG,"Network manager is disabled. Use command line for wifi control.");
}
else {
ESP_LOGI(TAG,"Starting Network Manager");
network_start();
MEMTRACE_PRINT_DELTA();
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE,WIFI_CONNECTED_STATE, "cb_connection_got_ip", &cb_connection_got_ip);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE,ETH_ACTIVE_CONNECTED_STATE, "cb_connection_got_ip",&cb_connection_got_ip);
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE,WIFI_LOST_CONNECTION_STATE, "cb_connection_sta_disconnected",&cb_connection_sta_disconnected);
/* Start the telnet service after we are certain that the network stack has been properly initialized.
* This can be either after we're started the AP mode, or after we've started the STA mode */
network_register_state_callback(NETWORK_INITIALIZING_STATE,-1, "handle_ap_connect", &handle_ap_connect);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE,ETH_ACTIVE_LINKDOWN_STATE, "handle_network_up", &handle_network_up);
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE,WIFI_INITIALIZING_STATE, "handle_network_up", &handle_network_up);
MEMTRACE_PRINT_DELTA();
}
if(!is_recovery_running){
MEMTRACE_PRINT_DELTA_MESSAGE("Launching Squeezelite");
start_squeezelite();
MEMTRACE_PRINT_DELTA_MESSAGE("Squeezelite Started");
}
MEMTRACE_PRINT_DELTA_MESSAGE("Starting Console");
console_start();
MEMTRACE_PRINT_DELTA_MESSAGE("Console started");
if(sys_state && sys_state->ota_url && strlen(sys_state->ota_url)){
ESP_LOGD(TAG,"Found OTA URL %s",sys_state->ota_url);
if(is_recovery_running){
while(!bNetworkConnected){
wait_for_wifi();
taskYIELD();
}
ESP_LOGI(TAG,"Updating firmware from link: %s",sys_state->ota_url);
#if defined(CONFIG_WITH_METRICS)
metrics_event("fw_update");
#endif
start_ota(sys_state->ota_url, NULL, 0);
}
else {
ESP_LOGE(TAG,"Restarted to application partition. We're not going to perform OTA!");
}
}
services_sleep_init();
messaging_post_message(MESSAGING_INFO,MESSAGING_CLASS_SYSTEM,"System started");
}
void cb_connection_sta_disconnected(nm_state_t new_state, int sub_state) {
led_blink_pushed(LED_GREEN, 250, 250);
messaging_post_message(MESSAGING_WARNING, MESSAGING_CLASS_SYSTEM, "Wifi disconnected");
}
void handle_ap_connect(nm_state_t new_state, int sub_state) { start_telnet(NULL); }
void handle_network_up(nm_state_t new_state, int sub_state) { bootstate_uptate_counter(0); }
void initialize_network() {
ESP_LOGI(TAG, "Starting Network Manager");
TRACE_START
network_initialize_task();
// register main
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE, WIFI_CONNECTED_STATE, "cb_connection_got_ip", &cb_connection_got_ip);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE, ETH_ACTIVE_CONNECTED_STATE, "cb_connection_got_ip", &cb_connection_got_ip);
// OTA Processing should happen when a network IP address is received
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE, WIFI_CONNECTED_STATE, "cb_handle_ota", &cb_handle_ota);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE, ETH_ACTIVE_CONNECTED_STATE, "cb_handle_ota", &cb_handle_ota);
network_register_state_callback(
NETWORK_WIFI_ACTIVE_STATE, WIFI_LOST_CONNECTION_STATE, "cb_connection_sta_disconnected", &cb_connection_sta_disconnected);
/* Start the telnet service after we are certain that the network stack has been properly
* initialized. This can be either after we're started the AP mode, or after we've started
* the STA mode */
network_register_state_callback(NETWORK_INITIALIZING_STATE, -1, "handle_ap_connect", &handle_ap_connect);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE, ETH_ACTIVE_LINKDOWN_STATE, "handle_network_up", &handle_network_up);
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE, WIFI_INITIALIZING_STATE, "handle_network_up", &handle_network_up);
TRACE_STOP;
}
void app_main() {
/* initialize console here, as it will capture logs earlier */
initialize_console();
ESP_LOGI(TAG, "Setting log level to max. System compiled with max level %s", get_log_level_desc(CONFIG_LOG_MAXIMUM_LEVEL));
// calling this will set the log level to verbose,
// but in reality, the actual log level used is limited
// by CONFIG_LOG_MAXIMUM_LEVEL in sdkconfig as well as
// LOG_LOCAL_LEVEL of each component
esp_log_level_set("*", ESP_LOG_VERBOSE);
messaging_service_init();
bootstate_handle_boot();
TRACE_INIT;
ESP_LOGI(TAG, "Starting app_main");
init_spiffs();
if (esp_log_level_get(TAG) >= ESP_LOG_DEBUG) {
listFiles("/spiffs");
}
// now that the spiffs is initialized, we can load the
// core configuration system, which is needed by
// most of the other system components
config_load();
if (!platform) {
ESP_LOGE(TAG, "Invalid configuration object. Cannot continue");
config_erase_config();
}
// initialize SPI/I2C and gpios/gpio expansion modules
// now as they may be required for hardware access by
// ethernet, etc. later
services_ports_init();
services_gpio_init();
// Start the network task at this point; this is critical
// as various subsequent init steps will post events to the queue
initialize_network();
#if defined(CONFIG_WITH_METRICS)
ESP_LOGI(TAG, "Setting up metrics.");
metrics_init();
#endif
init_telnet(); // align on 32 bits boundaries
services_init();
display_init("SqueezeESP32");
if (platform->target && strlen(platform->target) > 0) {
target_init(platform->target);
}
led_vu_init();
if (is_recovery_running) {
if (display) {
ESP_LOGD(TAG, "Writing to display");
GDS_ClearExt(display, true);
GDS_SetFont(display, Font_line_2);
GDS_TextPos(display, GDS_FONT_DEFAULT, GDS_TEXT_CENTERED, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "RECOVERY");
}
if (led_display) {
led_vu_color_yellow(LED_VU_BRIGHT);
}
}
#if defined(CONFIG_WITH_METRICS)
metrics_event_boot(is_recovery_running ? "recovery" : "ota");
#endif
if (!is_recovery_running) {
ESP_LOGD(TAG, "Getting audio control mapping ");
if (platform && platform->has_dev && platform->dev.root_button_profile && strlen(platform->dev.root_button_profile) > 0) {
ESP_LOGD(TAG, "Initializing audio control buttons type %s", platform->dev.root_button_profile);
if (actrls_init(platform->dev.root_button_profile) == ESP_OK) {
ESP_LOGD(TAG, "Done Initializing audio control buttons type %s", platform->dev.root_button_profile);
} else {
ESP_LOGD(TAG, "No audio control buttons");
}
}
}
led_blink_pushed(LED_GREEN, 250, 250);
if (!is_recovery_running) {
start_squeezelite();
}
console_start();
services_sleep_init();
messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_SYSTEM, "System started");
#ifdef CONFIG_HEAP_TRACING
#endif
}

View File

@@ -16,7 +16,6 @@
#define CONFIG_SQUEEZELITE_ESP32_RELEASE_URL "https://github.com/sle118/squeezelite-esp32/releases"
#endif
extern bool wait_for_wifi();
extern void console_start();
extern pthread_cond_t wifi_connect_suspend_cond;
extern pthread_t wifi_connect_suspend_mutex;