diff --git a/main/inc/user/led.h b/main/inc/user/led.h index 44659f5..39a6d38 100644 --- a/main/inc/user/led.h +++ b/main/inc/user/led.h @@ -8,8 +8,6 @@ #ifndef INC_USER_LED_H_ #define INC_USER_LED_H_ -#include - typedef enum { LED_MODE_IDX_BLINK_S1 = 0x00, LED_MODE_IDX_BLINK_S0 = 0x01, diff --git a/main/src/chip/i2s.c b/main/src/chip/i2s.c index 31a38ad..d52f8e9 100644 --- a/main/src/chip/i2s.c +++ b/main/src/chip/i2s.c @@ -19,9 +19,8 @@ static i2s_config_t i2s_output_config = { .use_apll = 1, // use APLL .sample_rate = 44100, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL3, .tx_desc_auto_clear = true, // auto clear tx descriptor on underflow - .dma_buf_count = 8, + .dma_buf_count = 2, .dma_buf_len = 128, .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT // 2-channels }; diff --git a/main/src/core/app.c b/main/src/core/app.c index 18d8ecb..846afcb 100644 --- a/main/src/core/app.c +++ b/main/src/core/app.c @@ -31,19 +31,19 @@ esp_err_t app_getenv(const char *key, void *out_value, size_t *length) { nvs_handle_t handle; - esp_err_t err = nvs_open("storage", NVS_READONLY, &handle); + esp_err_t err = nvs_open("storage", NVS_READWRITE, &handle); if (err != ESP_OK) { - ESP_LOGE(TAG, "open nvs failed"); + ESP_LOGE(TAG, "failed to open nvs"); return err; } err = nvs_get_blob(handle, key, out_value, length); if (err == ESP_ERR_NVS_NOT_FOUND) { - ESP_LOGW(TAG, "env \"%s\" not found", key); + ESP_LOGW(TAG, "env not found: %s", key); nvs_close(handle); return err; } else if (err != ESP_OK) { - ESP_LOGE(TAG, "read env \"%s\" failed", key); + ESP_LOGE(TAG, "failed to read env: %s", key); nvs_close(handle); return err; } @@ -59,20 +59,20 @@ esp_err_t app_setenv(const char *key, const void *value, size_t length) esp_err_t err = nvs_open("storage", NVS_READWRITE, &handle); if (err != ESP_OK) { - ESP_LOGE(TAG, "open nvs failed"); + ESP_LOGE(TAG, "failed to open nvs"); return err; } err = nvs_set_blob(handle, key, value, length); if (err != ESP_OK) { - ESP_LOGE(TAG, "set nvs blob failed"); + ESP_LOGE(TAG, "failed to set nvs blob"); nvs_close(handle); return err; } err = nvs_commit(handle); if (err != ESP_OK) { - ESP_LOGE(TAG, "write env \"%s\" failed", key); + ESP_LOGE(TAG, "failed to write env: %s", key); nvs_close(handle); return err; } diff --git a/main/src/core/os.c b/main/src/core/os.c index 00fb375..7101a4d 100644 --- a/main/src/core/os.c +++ b/main/src/core/os.c @@ -18,10 +18,10 @@ #include "core/os.h" #include "chip/wifi.h" -#include "user/gui.h" -#include "user/led.h" #include "user/ntp.h" #include "user/key.h" +#include "user/led.h" +#include "user/gui.h" #include "user/nfc_app.h" #include "user/http_app_ota.h" @@ -58,11 +58,14 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, vTaskDelay(2000 / portTICK_RATE_MS); #endif os_pwr_reset_wait(OS_PWR_DUMMY_BIT); + break; } + + xEventGroupClearBits(wifi_event_group, WIFI_RDY_BIT); + if (!(uxBits & WIFI_CFG_BIT)) { esp_wifi_connect(); } - xEventGroupClearBits(wifi_event_group, WIFI_RDY_BIT); break; } default: @@ -74,11 +77,11 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { switch (event_id) { - case IP_EVENT_STA_GOT_IP: { + case IP_EVENT_STA_GOT_IP: xEventGroupSetBits(wifi_event_group, WIFI_RDY_BIT); - +#ifdef CONFIG_ENABLE_SC_KEY key_set_scan_mode(KEY_SCAN_MODE_IDX_OFF); - +#endif ntp_sync_time(); #ifdef CONFIG_ENABLE_OTA http_app_check_for_updates(); @@ -92,7 +95,6 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base, nfc_app_set_mode(NFC_APP_MODE_IDX_ON); break; - } default: break; } @@ -121,7 +123,6 @@ static void sc_event_handler(void* arg, esp_event_base_t event_base, #ifdef CONFIG_ENABLE_LED led_set_mode(LED_MODE_IDX_PULSE_D1); #endif - smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)event_data; memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid)); memcpy(wifi_config.sta.password, evt->password, sizeof(wifi_config.sta.password)); diff --git a/main/src/user/http_app.c b/main/src/user/http_app.c index 18b4e52..6579aeb 100644 --- a/main/src/user/http_app.c +++ b/main/src/user/http_app.c @@ -11,8 +11,8 @@ #include "esp_http_client.h" #include "core/os.h" -#include "user/gui.h" #include "user/led.h" +#include "user/gui.h" #include "user/http_app.h" #include "user/audio_player.h" #include "user/http_app_ota.h" diff --git a/main/src/user/http_app_ota.c b/main/src/user/http_app_ota.c index e56d6f8..664056f 100644 --- a/main/src/user/http_app_ota.c +++ b/main/src/user/http_app_ota.c @@ -24,8 +24,8 @@ static uint32_t data_length = 0; -static const esp_partition_t *update_partition = NULL; static esp_ota_handle_t update_handle = 0; +static const esp_partition_t *update_partition = NULL; esp_err_t http_app_ota_event_handler(esp_http_client_event_t *evt) { diff --git a/main/src/user/nfc_app.c b/main/src/user/nfc_app.c index e1d5b16..0761d79 100644 --- a/main/src/user/nfc_app.c +++ b/main/src/user/nfc_app.c @@ -118,8 +118,10 @@ static void nfc_app_task_handle(void *pvParameter) if (res > 0) { if (strstr((char *)rx_data, RX_FRAME_PRFX) != NULL && strlen((char *)rx_data + RX_FRAME_PRFX_LEN) == RX_FRAME_DATA_LEN) { - ESP_LOGW(TAG, "token is %32s", (char *)rx_data + RX_FRAME_PRFX_LEN); + ESP_LOGW(TAG, "token: %32s", (char *)rx_data + RX_FRAME_PRFX_LEN); +#ifdef CONFIG_ENABLE_AUDIO_PROMPT audio_player_play_file(MP3_FILE_IDX_NOTIFY); +#endif http_app_verify_token((char *)rx_data + RX_FRAME_PRFX_LEN); } else { ESP_LOGW(TAG, "unexpected frame"); diff --git a/main/src/user/ntp.c b/main/src/user/ntp.c index 02d0584..b5822ef 100644 --- a/main/src/user/ntp.c +++ b/main/src/user/ntp.c @@ -12,8 +12,8 @@ #include "core/os.h" -#include "user/gui.h" #include "user/led.h" +#include "user/gui.h" #include "user/nfc_app.h" #include "user/http_app_ota.h"