mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 20:47:08 +03:00
make targets "loadable"
This commit is contained in:
@@ -12,6 +12,8 @@ CONFIG_DISPLAY_CONFIG=""
|
|||||||
CONFIG_I2C_CONFIG=""
|
CONFIG_I2C_CONFIG=""
|
||||||
CONFIG_SPI_CONFIG=""
|
CONFIG_SPI_CONFIG=""
|
||||||
CONFIG_SET_GPIO=""
|
CONFIG_SET_GPIO=""
|
||||||
|
CONFIG_TARGET_LOCKED=n
|
||||||
|
CONFIG_TARGET=""
|
||||||
CONFIG_GPIO_EXP_CONFIG=""
|
CONFIG_GPIO_EXP_CONFIG=""
|
||||||
CONFIG_ROTARY_ENCODER=""
|
CONFIG_ROTARY_ENCODER=""
|
||||||
CONFIG_LED_GREEN_GPIO=-1
|
CONFIG_LED_GREEN_GPIO=-1
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ CONFIG_AMP_LOCKED=y
|
|||||||
CONFIG_JACK_LOCKED=y
|
CONFIG_JACK_LOCKED=y
|
||||||
CONFIG_BAT_LOCKED=y
|
CONFIG_BAT_LOCKED=y
|
||||||
CONFIG_I2C_LOCKED=y
|
CONFIG_I2C_LOCKED=y
|
||||||
CONFIG_WELL_KNOWN=y
|
CONFIG_TARGET_LOCKED=y
|
||||||
|
CONFIG_TARGET="muse"
|
||||||
CONFIG_DISPLAY_CONFIG=""
|
CONFIG_DISPLAY_CONFIG=""
|
||||||
CONFIG_I2C_CONFIG=""
|
CONFIG_I2C_CONFIG=""
|
||||||
CONFIG_SPI_CONFIG="mosi=15,miso=2,clk=14"
|
CONFIG_SPI_CONFIG="mosi=15,miso=2,clk=14"
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ CONFIG_JACK_LOCKED=y
|
|||||||
CONFIG_BAT_LOCKED=y
|
CONFIG_BAT_LOCKED=y
|
||||||
CONFIG_I2C_LOCKED=y
|
CONFIG_I2C_LOCKED=y
|
||||||
CONFIG_LED_LOCKED=y
|
CONFIG_LED_LOCKED=y
|
||||||
CONFIG_WELL_KNOWN=y
|
CONFIG_TARGET_LOCKED=y
|
||||||
|
CONFIG_TARGET="squeezeamp"
|
||||||
CONFIG_DISPLAY_CONFIG=""
|
CONFIG_DISPLAY_CONFIG=""
|
||||||
CONFIG_I2C_CONFIG=""
|
CONFIG_I2C_CONFIG=""
|
||||||
CONFIG_SPI_CONFIG=""
|
CONFIG_SPI_CONFIG=""
|
||||||
|
|||||||
@@ -1,13 +1,4 @@
|
|||||||
# This should be made a pure CMake component but as CMake is even
|
idf_component_register( SRC_DIRS . muse
|
||||||
# more shitty under Windows, backslash in path screws it all
|
INCLUDE_DIRS .
|
||||||
|
|
||||||
if(CONFIG_MUSE)
|
|
||||||
message("Compiling for MUSE")
|
|
||||||
set(src_dirs "muse")
|
|
||||||
else()
|
|
||||||
set(src_dirs ".")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
idf_component_register( SRC_DIRS ${src_dirs}
|
|
||||||
PRIV_REQUIRES services
|
PRIV_REQUIRES services
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
// weak should do the job but it does not...
|
|
||||||
__attribute__((weak)) void target_init(void) {
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
//#include <driver/adc.h>
|
//#include <driver/adc.h>
|
||||||
#include "driver/rmt.h"
|
#include "driver/rmt.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
|
#include "targets.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
//*********************** NeoPixels ***************************
|
//*********************** NeoPixels ***************************
|
||||||
@@ -44,11 +45,15 @@ static const char TAG[] = "muse";
|
|||||||
|
|
||||||
static void (*battery_handler_chain)(float value);
|
static void (*battery_handler_chain)(float value);
|
||||||
static void battery_svc(float value);
|
static void battery_svc(float value);
|
||||||
|
static bool init(void);
|
||||||
|
|
||||||
void target_init(void) {
|
const struct target_s target_muse = { "muse", init };
|
||||||
|
|
||||||
|
static bool init(void) {
|
||||||
battery_handler_chain = battery_handler_svc;
|
battery_handler_chain = battery_handler_svc;
|
||||||
battery_handler_svc = battery_svc;
|
battery_handler_svc = battery_svc;
|
||||||
ESP_LOGI(TAG, "Initializing for Muse");
|
ESP_LOGI(TAG, "Initializing for Muse");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void battery_svc(float value) {
|
static void battery_svc(float value) {
|
||||||
|
|||||||
11
components/targets/targets.c
Normal file
11
components/targets/targets.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "string.h"
|
||||||
|
#include "targets.h"
|
||||||
|
|
||||||
|
const struct target_s *target_set[] = { &target_muse, NULL };
|
||||||
|
|
||||||
|
void target_init(char *target) {
|
||||||
|
for (int i = 0; target_set[i]; i++) if (strcasestr(target_set[i]->model, target)) {
|
||||||
|
target_set[i]->init();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
components/targets/targets.h
Normal file
22
components/targets/targets.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Squeezelite for esp32
|
||||||
|
*
|
||||||
|
* (c) Sebastien 2019
|
||||||
|
* Philippe G. 2019, philippe_44@outlook.com
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stddef.h"
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
struct target_s {
|
||||||
|
char *model;
|
||||||
|
bool (*init)(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct target_s target_muse;
|
||||||
@@ -21,6 +21,9 @@ menu "Squeezelite-ESP32"
|
|||||||
help
|
help
|
||||||
Set logging level info|debug|sdebug
|
Set logging level info|debug|sdebug
|
||||||
endmenu
|
endmenu
|
||||||
|
config TARGET_LOCKED
|
||||||
|
bool
|
||||||
|
default n
|
||||||
config AMP_LOCKED
|
config AMP_LOCKED
|
||||||
bool
|
bool
|
||||||
config JACK_LOCKED
|
config JACK_LOCKED
|
||||||
@@ -38,9 +41,6 @@ menu "Squeezelite-ESP32"
|
|||||||
config MUTE_GPIO_LEVEL
|
config MUTE_GPIO_LEVEL
|
||||||
int
|
int
|
||||||
default 0
|
default 0
|
||||||
config WELL_KNOWN
|
|
||||||
bool
|
|
||||||
default n
|
|
||||||
menu "Target"
|
menu "Target"
|
||||||
choice OUTPUT_TYPE
|
choice OUTPUT_TYPE
|
||||||
prompt "Main system"
|
prompt "Main system"
|
||||||
@@ -54,20 +54,20 @@ menu "Squeezelite-ESP32"
|
|||||||
select I2C_LOCKED
|
select I2C_LOCKED
|
||||||
select LED_LOCKED
|
select LED_LOCKED
|
||||||
select SPKFAULT_LOCKED
|
select SPKFAULT_LOCKED
|
||||||
select WELL_KNOWN
|
select TARGET_LOCKED
|
||||||
config MUSE
|
config MUSE
|
||||||
bool "Muse"
|
bool "Muse"
|
||||||
select JACK_LOCKED
|
select JACK_LOCKED
|
||||||
select BAT_LOCKED
|
select BAT_LOCKED
|
||||||
select I2C_LOCKED
|
select I2C_LOCKED
|
||||||
select AMP_LOCKED
|
select AMP_LOCKED
|
||||||
select WELL_KNOWN
|
select TARGET_LOCKED
|
||||||
config BASIC_I2C_BT
|
config BASIC_I2C_BT
|
||||||
bool "Generic I2S & Bluetooth"
|
bool "Generic I2S & Bluetooth"
|
||||||
config TWATCH2020
|
config TWATCH2020
|
||||||
bool "T-WATCH2020 by LilyGo"
|
bool "T-WATCH2020 by LilyGo"
|
||||||
select I2C_LOCKED
|
select I2C_LOCKED
|
||||||
select WELL_KNOWN
|
select TARGET_LOCKED
|
||||||
endchoice
|
endchoice
|
||||||
config RELEASE_API
|
config RELEASE_API
|
||||||
string "Software update URL"
|
string "Software update URL"
|
||||||
@@ -131,9 +131,14 @@ menu "Squeezelite-ESP32"
|
|||||||
default "[{\"gpio\":32, \"pull\":true, \"debounce\":10, \"normal\":{\"pressed\":\"ACTRLS_VOLDOWN\"}}, {\"gpio\":19, \"pull\":true, \"debounce\":40, \"normal\":{\"pressed\":\"ACTRLS_VOLUP\"}}, {\"gpio\":12, \"pull\":true, \"debounce\":40, \"longpress\":1000, \"normal\":{\"pressed\":\"ACTRLS_TOGGLE\"},\"longpress\":{\"pressed\":\"ACTRLS_POWER\"}}]" if MUSE
|
default "[{\"gpio\":32, \"pull\":true, \"debounce\":10, \"normal\":{\"pressed\":\"ACTRLS_VOLDOWN\"}}, {\"gpio\":19, \"pull\":true, \"debounce\":40, \"normal\":{\"pressed\":\"ACTRLS_VOLUP\"}}, {\"gpio\":12, \"pull\":true, \"debounce\":40, \"longpress\":1000, \"normal\":{\"pressed\":\"ACTRLS_TOGGLE\"},\"longpress\":{\"pressed\":\"ACTRLS_POWER\"}}]" if MUSE
|
||||||
default ""
|
default ""
|
||||||
config BAT_CONFIG
|
config BAT_CONFIG
|
||||||
|
string
|
||||||
default "channel=7,scale=20.24,atten=0" if SQUEEZEAMP
|
default "channel=7,scale=20.24,atten=0" if SQUEEZEAMP
|
||||||
default "channel=5,scale=1,atten=3,cells=1" if MUSE
|
default "channel=5,scale=1,atten=3,cells=1" if MUSE
|
||||||
default ""
|
default ""
|
||||||
|
config TARGET
|
||||||
|
string
|
||||||
|
default "muse" if MUSE
|
||||||
|
default ""
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Audio settings"
|
menu "Audio settings"
|
||||||
@@ -325,7 +330,7 @@ menu "Squeezelite-ESP32"
|
|||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "LED configuration"
|
menu "LED configuration"
|
||||||
visible if !WELL_KNOWN
|
visible if !TARGET_LOCKED
|
||||||
config LED_GREEN_GPIO
|
config LED_GREEN_GPIO
|
||||||
int "Green led GPIO"
|
int "Green led GPIO"
|
||||||
default 12 if SQUEEZEAMP
|
default 12 if SQUEEZEAMP
|
||||||
@@ -352,7 +357,7 @@ menu "Squeezelite-ESP32"
|
|||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Audio JACK"
|
menu "Audio JACK"
|
||||||
visible if !WELL_KNOWN
|
visible if !TARGET_LOCKED
|
||||||
config JACK_GPIO
|
config JACK_GPIO
|
||||||
int "Jack insertion GPIO"
|
int "Jack insertion GPIO"
|
||||||
default 34 if SQUEEZEAMP || MUSE
|
default 34 if SQUEEZEAMP || MUSE
|
||||||
@@ -366,7 +371,7 @@ menu "Squeezelite-ESP32"
|
|||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Amplifier"
|
menu "Amplifier"
|
||||||
visible if !WELL_KNOWN
|
visible if !TARGET_LOCKED
|
||||||
config AMP_GPIO
|
config AMP_GPIO
|
||||||
int "Amplifier GPIO"
|
int "Amplifier GPIO"
|
||||||
default 21 if MUSE
|
default 21 if MUSE
|
||||||
@@ -380,7 +385,7 @@ menu "Squeezelite-ESP32"
|
|||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Speaker Fault"
|
menu "Speaker Fault"
|
||||||
visible if !WELL_KNOWN
|
visible if !TARGET_LOCKED
|
||||||
config SPKFAULT_GPIO
|
config SPKFAULT_GPIO
|
||||||
int "Speaker fault GPIO"
|
int "Speaker fault GPIO"
|
||||||
default 2 if SQUEEZEAMP
|
default 2 if SQUEEZEAMP
|
||||||
@@ -394,7 +399,7 @@ menu "Squeezelite-ESP32"
|
|||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Battery measure"
|
menu "Battery measure"
|
||||||
visible if !WELL_KNOWN
|
visible if !TARGET_LOCKED
|
||||||
config BAT_CONFIG
|
config BAT_CONFIG
|
||||||
string "Battery acquisitiong configuration"
|
string "Battery acquisitiong configuration"
|
||||||
help
|
help
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
|
|||||||
// as an exception _init function don't need include
|
// as an exception _init function don't need include
|
||||||
extern void services_init(void);
|
extern void services_init(void);
|
||||||
extern void display_init(char *welcome);
|
extern void display_init(char *welcome);
|
||||||
extern void target_init(void);
|
extern void target_init(char *target);
|
||||||
const char * str_or_unknown(const char * str) { return (str?str:unknown_string_placeholder); }
|
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); }
|
const char * str_or_null(const char * str) { return (str?str:null_string_placeholder); }
|
||||||
bool is_recovery_running;
|
bool is_recovery_running;
|
||||||
@@ -421,6 +421,9 @@ void register_default_nvs(){
|
|||||||
|
|
||||||
ESP_LOGD(TAG,"Registering default value for key %s", "rel_api");
|
ESP_LOGD(TAG,"Registering default value for key %s", "rel_api");
|
||||||
config_set_default(NVS_TYPE_STR, "rel_api", CONFIG_RELEASE_API, 0);
|
config_set_default(NVS_TYPE_STR, "rel_api", CONFIG_RELEASE_API, 0);
|
||||||
|
|
||||||
|
ESP_LOGD(TAG,"Registering default value for key %s", "target");
|
||||||
|
config_set_default(NVS_TYPE_STR, "target", "", 0);
|
||||||
|
|
||||||
wait_for_commit();
|
wait_for_commit();
|
||||||
ESP_LOGD(TAG,"Done setting default values in nvs.");
|
ESP_LOGD(TAG,"Done setting default values in nvs.");
|
||||||
@@ -475,7 +478,11 @@ void app_main()
|
|||||||
ESP_LOGI(TAG,"Initializing display");
|
ESP_LOGI(TAG,"Initializing display");
|
||||||
display_init("SqueezeESP32");
|
display_init("SqueezeESP32");
|
||||||
|
|
||||||
target_init();
|
char *target = config_alloc_get_default(NVS_TYPE_STR, "target", CONFIG_TARGET, 0);
|
||||||
|
if (target) {
|
||||||
|
target_init(target);
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
if(is_recovery_running && display){
|
if(is_recovery_running && display){
|
||||||
GDS_ClearExt(display, true);
|
GDS_ClearExt(display, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user