From 0052ff96258270bc61a14e49ef85f34ccb03d176 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Sun, 23 Jan 2022 00:01:55 -0800 Subject: [PATCH 1/6] add battery led --- build-scripts/Muse-sdkconfig.defaults | 2 +- components/targets/muse/muse.c | 52 ++++++++------------------- main/Kconfig.projbuild | 3 +- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/build-scripts/Muse-sdkconfig.defaults b/build-scripts/Muse-sdkconfig.defaults index fbe0f755..ddbe0a78 100644 --- a/build-scripts/Muse-sdkconfig.defaults +++ b/build-scripts/Muse-sdkconfig.defaults @@ -204,7 +204,7 @@ CONFIG_AMP_GPIO=21 CONFIG_JACK_GPIO=34 CONFIG_SPKFAULT_GPIO=-1 CONFIG_BAT_CHANNEL=-1 -CONFIG_LED_GREEN_GPIO=22 +CONFIG_LED_GREEN_GPIO=-1 CONFIG_LED_RED_GPIO=-1 CONFIG_TARGET="muse" # end of Target diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index 3501fe2d..b2a180e1 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -52,51 +52,27 @@ const struct target_s target_muse = { "muse", init }; static bool init(void) { battery_handler_chain = battery_handler_svc; battery_handler_svc = battery_svc; + ws2812_control_init(); ESP_LOGI(TAG, "Initializing for Muse"); return true; } -static void battery_svc(float value) { - ESP_LOGI(TAG, "Called for battery service with %f", value); - // put here your code for LED according to value - if (battery_handler_chain) battery_handler_chain(value); -} +#define VGREEN 4.0 +#define VRED 3.6 + +static void battery_svc(float value) { + struct led_state new_state; + + ESP_LOGI(TAG, "Called for battery service with %f", value); + + if (value > VGREEN) new_state.leds[0] = GREEN; + else if (value < VRED) new_state.leds[0] = RED; + else new_state.leds[0] = YELLOW; -// Battery monitoring -/* -static void battery(void *data) -{ -#define VGREEN 2300 -#define VRED 2000 -#define NM 10 - static int val; - static int V[NM]; - static int I=0; - int S; - for(int i=0;i= NM)I = 0; - S = 0; - for(int i=0;i VGREEN) new_state.leds[0] = GREEN; - if(val < VRED) new_state.leds[0] = RED; - printf("====> %d %6x\n", val, new_state.leds[0]); ws2812_write_leds(new_state); - } + if (battery_handler_chain) battery_handler_chain(value); } -*/ // This is the buffer which the hw peripheral will access while pulsing the output pin rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS]; @@ -139,5 +115,5 @@ void setup_rmt_data_buffer(struct led_state new_state) mask >>= 1; } } - } +} diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 2fd73169..8209a124 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -138,7 +138,7 @@ menu "Squeezelite-ESP32" config BAT_CONFIG string 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=7.48,atten=3,cells=1" if MUSE default "" config TARGET string @@ -163,7 +163,6 @@ menu "Squeezelite-ESP32" config LED_GREEN_GPIO int default 12 if SQUEEZEAMP - default 22 if MUSE default -1 config LED_RED_GPIO int From cf4ed64eb0c2773832ceaa94e08e725f6994a886 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Mon, 24 Jan 2022 16:08:00 -0800 Subject: [PATCH 2/6] muse long_press & battery read at boot --- build-scripts/Muse-sdkconfig.defaults | 2 +- components/targets/muse/muse.c | 18 +++++++++++++----- main/Kconfig.projbuild | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/build-scripts/Muse-sdkconfig.defaults b/build-scripts/Muse-sdkconfig.defaults index ddbe0a78..faba225d 100644 --- a/build-scripts/Muse-sdkconfig.defaults +++ b/build-scripts/Muse-sdkconfig.defaults @@ -198,7 +198,7 @@ CONFIG_SPI_CONFIG="" CONFIG_DISPLAY_CONFIG="" CONFIG_ETH_CONFIG="" CONFIG_DAC_CONTROLSET="{\"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} ]}" -CONFIG_AUDIO_CONTROLS="[{\"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\"}}]" +CONFIG_AUDIO_CONTROLS="[{\"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, \"long_press\":1000, \"normal\":{\"pressed\":\"ACTRLS_TOGGLE\"},\"longpress\":{\"pressed\":\"ACTRLS_POWER\"}}]" CONFIG_BAT_CONFIG="channel=5,scale=1,atten=3,cells=1" CONFIG_AMP_GPIO=21 CONFIG_JACK_GPIO=34 diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index b2a180e1..6a7676ae 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -46,30 +46,38 @@ static const char TAG[] = "muse"; static void (*battery_handler_chain)(float value); static void battery_svc(float value); static bool init(void); +static void set_battery_led(float value); const struct target_s target_muse = { "muse", init }; static bool init(void) { battery_handler_chain = battery_handler_svc; battery_handler_svc = battery_svc; + ws2812_control_init(); - ESP_LOGI(TAG, "Initializing for Muse"); + float value = battery_value_svc(); + + ESP_LOGI(TAG, "Initializing for Muse %f", value); + return true; } #define VGREEN 4.0 #define VRED 3.6 -static void battery_svc(float value) { +static void set_battery_led(float value) { struct led_state new_state; - - ESP_LOGI(TAG, "Called for battery service with %f", value); - + if (value > VGREEN) new_state.leds[0] = GREEN; else if (value < VRED) new_state.leds[0] = RED; else new_state.leds[0] = YELLOW; ws2812_write_leds(new_state); +} + +static void battery_svc(float value) { + set_battery_led(value); + ESP_LOGI(TAG, "Called for battery service with %f", value); if (battery_handler_chain) battery_handler_chain(value); } diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 8209a124..fd353cde 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -133,7 +133,7 @@ menu "Squeezelite-ESP32" default "" config AUDIO_CONTROLS string - 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, \"long_press\":1000, \"normal\":{\"pressed\":\"ACTRLS_TOGGLE\"},\"longpress\":{\"pressed\":\"ACTRLS_POWER\"}}]" if MUSE default "" config BAT_CONFIG string From eb3a8f76da43dfc55574239fd4cf2e922fa7cad4 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Mon, 24 Jan 2022 16:10:43 -0800 Subject: [PATCH 3/6] really add battery led at boot --- components/targets/muse/muse.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index 6a7676ae..7e7dc19e 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -56,6 +56,7 @@ static bool init(void) { ws2812_control_init(); float value = battery_value_svc(); + set_battery_led(value); ESP_LOGI(TAG, "Initializing for Muse %f", value); From 8e6d409311f12259a4736b9e098fb842178412a6 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Wed, 26 Jan 2022 02:30:31 -0800 Subject: [PATCH 4/6] use muse built-in keyboard definition --- components/services/audio_controls.c | 14 +++++++++----- main/esp_app_main.c | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/services/audio_controls.c b/components/services/audio_controls.c index 397a698c..4104c561 100644 --- a/components/services/audio_controls.c +++ b/components/services/audio_controls.c @@ -157,7 +157,7 @@ esp_err_t actrls_init(const char *profile_name) { // set infrared GPIO if any parse_set_GPIO(set_ir_gpio); - + if (!err) return actrls_init_json(profile_name, true); else return err; } @@ -508,11 +508,13 @@ static esp_err_t actrls_init_json(const char *profile_name, bool create) { char *config; const cJSON *button; - if (!profile_name || !*profile_name) return ESP_OK; + if (!profile_name) return ESP_OK; - config = config_alloc_get_default(NVS_TYPE_STR, profile_name, NULL, 0); - if(!config) return ESP_FAIL; - + config = config_alloc_get_str(profile_name, NULL, CONFIG_AUDIO_CONTROLS); + + if (!config) return ESP_FAIL; + else if (!*config) return ESP_OK; + ESP_LOGD(TAG,"Parsing JSON structure %s", config); cJSON *buttons = cJSON_Parse(config); if (buttons == NULL) { @@ -526,6 +528,7 @@ static esp_err_t actrls_init_json(const char *profile_name, bool create) { if(!cur_config) { ESP_LOGE(TAG,"Config buffer was empty. "); cJSON_Delete(buttons); + free(config); return ESP_FAIL; } ESP_LOGD(TAG,"Processing button definitions. "); @@ -557,6 +560,7 @@ static esp_err_t actrls_init_json(const char *profile_name, bool create) { // the last init that completes will assigh the first json config object found, which will match // the default config from nvs. json_config = config_root; + free(config); return err; } diff --git a/main/esp_app_main.c b/main/esp_app_main.c index aa29835f..76856ee1 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -481,7 +481,7 @@ void app_main() if(!is_recovery_running){ ESP_LOGD(TAG,"Getting audio control mapping "); - char *actrls_config = config_alloc_get_default(NVS_TYPE_STR, "actrls_config", CONFIG_AUDIO_CONTROLS, 0); + char *actrls_config = config_alloc_get_default(NVS_TYPE_STR, "actrls_config", "", 0); if (actrls_init(actrls_config) == ESP_OK) { ESP_LOGD(TAG,"Initializing audio control buttons type %s", actrls_config); } else { From 6d1cf28fd650fff0373c310b24642d09a3e93965 Mon Sep 17 00:00:00 2001 From: Philippe G Date: Wed, 26 Jan 2022 12:41:39 -0800 Subject: [PATCH 5/6] tweaks --- components/services/audio_controls.c | 12 +++++------- .../spotify/cspot/bell/libhelix-mp3/assembly.h | 2 +- components/spotify/cspot/bell/libhelix-mp3/mp3dec.h | 4 +++- components/targets/muse/muse.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/services/audio_controls.c b/components/services/audio_controls.c index 4104c561..0e2cf8b8 100644 --- a/components/services/audio_controls.c +++ b/components/services/audio_controls.c @@ -509,11 +509,8 @@ static esp_err_t actrls_init_json(const char *profile_name, bool create) { const cJSON *button; if (!profile_name) return ESP_OK; - - config = config_alloc_get_str(profile_name, NULL, CONFIG_AUDIO_CONTROLS); - - if (!config) return ESP_FAIL; - else if (!*config) return ESP_OK; + if ((config = config_alloc_get_str(profile_name, NULL, CONFIG_AUDIO_CONTROLS)) == NULL) return ESP_FAIL; + if (!*config) goto exit; ESP_LOGD(TAG,"Parsing JSON structure %s", config); cJSON *buttons = cJSON_Parse(config); @@ -528,8 +525,8 @@ static esp_err_t actrls_init_json(const char *profile_name, bool create) { if(!cur_config) { ESP_LOGE(TAG,"Config buffer was empty. "); cJSON_Delete(buttons); - free(config); - return ESP_FAIL; + err = ESP_FAIL; + goto exit; } ESP_LOGD(TAG,"Processing button definitions. "); cJSON_ArrayForEach(button, buttons){ @@ -560,6 +557,7 @@ static esp_err_t actrls_init_json(const char *profile_name, bool create) { // the last init that completes will assigh the first json config object found, which will match // the default config from nvs. json_config = config_root; +exit: free(config); return err; } diff --git a/components/spotify/cspot/bell/libhelix-mp3/assembly.h b/components/spotify/cspot/bell/libhelix-mp3/assembly.h index ff7979b6..c55e329a 100644 --- a/components/spotify/cspot/bell/libhelix-mp3/assembly.h +++ b/components/spotify/cspot/bell/libhelix-mp3/assembly.h @@ -316,7 +316,7 @@ static __inline Word64 xSAR64(Word64 x, int n) } //mw -#elif defined(__APPLE__) || defined(ESP_PLATFORM) || defined(__x86_64__) +#elif defined(__APPLE__) || defined(ESP_PLATFORM) || defined(__amd64__) static __inline int FASTABS(int x) { diff --git a/components/spotify/cspot/bell/libhelix-mp3/mp3dec.h b/components/spotify/cspot/bell/libhelix-mp3/mp3dec.h index 4e28b1e7..f69eae39 100644 --- a/components/spotify/cspot/bell/libhelix-mp3/mp3dec.h +++ b/components/spotify/cspot/bell/libhelix-mp3/mp3dec.h @@ -67,7 +67,9 @@ # #elif defined(__GNUC__) && defined(__thumb__) # -#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) +#elif defined(__GNUC__) && defined(__i386__) +# +#elif defined(__amd64__) # #elif defined(_OPENWAVE_SIMULATOR) || defined(_OPENWAVE_ARMULATOR) # diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index 7e7dc19e..87cf38f0 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -48,7 +48,7 @@ static void battery_svc(float value); static bool init(void); static void set_battery_led(float value); -const struct target_s target_muse = { "muse", init }; +const struct target_s target_muse = { .model = "muse", .init = init }; static bool init(void) { battery_handler_chain = battery_handler_svc; From 839f31d48578dc5b5fea310b628902d111f9658c Mon Sep 17 00:00:00 2001 From: Philippe G Date: Wed, 26 Jan 2022 15:09:25 -0800 Subject: [PATCH 6/6] fix target config priority between NVS and dedicated builds --- components/targets/targets.c | 2 +- main/esp_app_main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/targets/targets.c b/components/targets/targets.c index 89574e4d..9f54d364 100644 --- a/components/targets/targets.c +++ b/components/targets/targets.c @@ -4,7 +4,7 @@ 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)) { + for (int i = 0; *target && target_set[i]; i++) if (strcasestr(target_set[i]->model, target)) { target_set[i]->init(); break; } diff --git a/main/esp_app_main.c b/main/esp_app_main.c index 76856ee1..04579215 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -449,7 +449,7 @@ void app_main() ESP_LOGI(TAG,"Initializing display"); display_init("SqueezeESP32"); MEMTRACE_PRINT_DELTA(); - char *target = config_alloc_get_default(NVS_TYPE_STR, "target", CONFIG_TARGET, 0); + char *target = config_alloc_get_str("target", CONFIG_TARGET, NULL); if (target) { target_init(target); free(target);