diff --git a/build-scripts/Muse-sdkconfig.defaults b/build-scripts/Muse-sdkconfig.defaults index fbe0f755..faba225d 100644 --- a/build-scripts/Muse-sdkconfig.defaults +++ b/build-scripts/Muse-sdkconfig.defaults @@ -198,13 +198,13 @@ 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 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/services/audio_controls.c b/components/services/audio_controls.c index 397a698c..0e2cf8b8 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,10 @@ 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; - - config = config_alloc_get_default(NVS_TYPE_STR, profile_name, NULL, 0); - if(!config) return ESP_FAIL; - + if (!profile_name) 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); if (buttons == NULL) { @@ -526,7 +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); - return ESP_FAIL; + err = ESP_FAIL; + goto exit; } ESP_LOGD(TAG,"Processing button definitions. "); cJSON_ArrayForEach(button, buttons){ @@ -557,6 +557,8 @@ 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 3501fe2d..87cf38f0 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -46,58 +46,43 @@ 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 }; +const struct target_s target_muse = { .model = "muse", .init = init }; static bool init(void) { battery_handler_chain = battery_handler_svc; battery_handler_svc = battery_svc; - ESP_LOGI(TAG, "Initializing for Muse"); + + ws2812_control_init(); + float value = battery_value_svc(); + set_battery_led(value); + + ESP_LOGI(TAG, "Initializing for Muse %f", value); + return true; } +#define VGREEN 4.0 +#define VRED 3.6 + +static void set_battery_led(float value) { + struct led_state new_state; + + 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); - // put here your code for LED according to value + if (battery_handler_chain) battery_handler_chain(value); } -// 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); - - } -} -*/ - // 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 +124,5 @@ void setup_rmt_data_buffer(struct led_state new_state) mask >>= 1; } } - } +} 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/Kconfig.projbuild b/main/Kconfig.projbuild index 2fd73169..fd353cde 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -133,12 +133,12 @@ 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 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 diff --git a/main/esp_app_main.c b/main/esp_app_main.c index aa29835f..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); @@ -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 {