Skip to content

Commit ebcc1ac

Browse files
committed
main: code refactoring
1 parent 313676d commit ebcc1ac

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

main/inc/user/led.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#ifndef INC_USER_LED_H_
99
#define INC_USER_LED_H_
1010

11-
#include <stdint.h>
12-
1311
typedef enum {
1412
LED_MODE_IDX_BLINK_S1 = 0x00,
1513
LED_MODE_IDX_BLINK_S0 = 0x01,

main/src/chip/i2s.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ static i2s_config_t i2s_output_config = {
1919
.use_apll = 1, // use APLL
2020
.sample_rate = 44100,
2121
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
22-
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL3,
2322
.tx_desc_auto_clear = true, // auto clear tx descriptor on underflow
24-
.dma_buf_count = 8,
23+
.dma_buf_count = 2,
2524
.dma_buf_len = 128,
2625
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT // 2-channels
2726
};

main/src/core/app.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ esp_err_t app_getenv(const char *key, void *out_value, size_t *length)
3131
{
3232
nvs_handle_t handle;
3333

34-
esp_err_t err = nvs_open("storage", NVS_READONLY, &handle);
34+
esp_err_t err = nvs_open("storage", NVS_READWRITE, &handle);
3535
if (err != ESP_OK) {
36-
ESP_LOGE(TAG, "open nvs failed");
36+
ESP_LOGE(TAG, "failed to open nvs");
3737
return err;
3838
}
3939

4040
err = nvs_get_blob(handle, key, out_value, length);
4141
if (err == ESP_ERR_NVS_NOT_FOUND) {
42-
ESP_LOGW(TAG, "env \"%s\" not found", key);
42+
ESP_LOGW(TAG, "env not found: %s", key);
4343
nvs_close(handle);
4444
return err;
4545
} else if (err != ESP_OK) {
46-
ESP_LOGE(TAG, "read env \"%s\" failed", key);
46+
ESP_LOGE(TAG, "failed to read env: %s", key);
4747
nvs_close(handle);
4848
return err;
4949
}
@@ -59,20 +59,20 @@ esp_err_t app_setenv(const char *key, const void *value, size_t length)
5959

6060
esp_err_t err = nvs_open("storage", NVS_READWRITE, &handle);
6161
if (err != ESP_OK) {
62-
ESP_LOGE(TAG, "open nvs failed");
62+
ESP_LOGE(TAG, "failed to open nvs");
6363
return err;
6464
}
6565

6666
err = nvs_set_blob(handle, key, value, length);
6767
if (err != ESP_OK) {
68-
ESP_LOGE(TAG, "set nvs blob failed");
68+
ESP_LOGE(TAG, "failed to set nvs blob");
6969
nvs_close(handle);
7070
return err;
7171
}
7272

7373
err = nvs_commit(handle);
7474
if (err != ESP_OK) {
75-
ESP_LOGE(TAG, "write env \"%s\" failed", key);
75+
ESP_LOGE(TAG, "failed to write env: %s", key);
7676
nvs_close(handle);
7777
return err;
7878
}

main/src/core/os.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include "core/os.h"
1919
#include "chip/wifi.h"
2020

21-
#include "user/gui.h"
22-
#include "user/led.h"
2321
#include "user/ntp.h"
2422
#include "user/key.h"
23+
#include "user/led.h"
24+
#include "user/gui.h"
2525
#include "user/nfc_app.h"
2626
#include "user/http_app_ota.h"
2727

@@ -58,11 +58,14 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
5858
vTaskDelay(2000 / portTICK_RATE_MS);
5959
#endif
6060
os_pwr_reset_wait(OS_PWR_DUMMY_BIT);
61+
break;
6162
}
63+
64+
xEventGroupClearBits(wifi_event_group, WIFI_RDY_BIT);
65+
6266
if (!(uxBits & WIFI_CFG_BIT)) {
6367
esp_wifi_connect();
6468
}
65-
xEventGroupClearBits(wifi_event_group, WIFI_RDY_BIT);
6669
break;
6770
}
6871
default:
@@ -74,11 +77,11 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base,
7477
int32_t event_id, void* event_data)
7578
{
7679
switch (event_id) {
77-
case IP_EVENT_STA_GOT_IP: {
80+
case IP_EVENT_STA_GOT_IP:
7881
xEventGroupSetBits(wifi_event_group, WIFI_RDY_BIT);
79-
82+
#ifdef CONFIG_ENABLE_SC_KEY
8083
key_set_scan_mode(KEY_SCAN_MODE_IDX_OFF);
81-
84+
#endif
8285
ntp_sync_time();
8386
#ifdef CONFIG_ENABLE_OTA
8487
http_app_check_for_updates();
@@ -92,7 +95,6 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base,
9295
nfc_app_set_mode(NFC_APP_MODE_IDX_ON);
9396

9497
break;
95-
}
9698
default:
9799
break;
98100
}
@@ -121,7 +123,6 @@ static void sc_event_handler(void* arg, esp_event_base_t event_base,
121123
#ifdef CONFIG_ENABLE_LED
122124
led_set_mode(LED_MODE_IDX_PULSE_D1);
123125
#endif
124-
125126
smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)event_data;
126127
memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid));
127128
memcpy(wifi_config.sta.password, evt->password, sizeof(wifi_config.sta.password));

main/src/user/http_app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "esp_http_client.h"
1212

1313
#include "core/os.h"
14-
#include "user/gui.h"
1514
#include "user/led.h"
15+
#include "user/gui.h"
1616
#include "user/http_app.h"
1717
#include "user/audio_player.h"
1818
#include "user/http_app_ota.h"

main/src/user/http_app_ota.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
static uint32_t data_length = 0;
2626

27-
static const esp_partition_t *update_partition = NULL;
2827
static esp_ota_handle_t update_handle = 0;
28+
static const esp_partition_t *update_partition = NULL;
2929

3030
esp_err_t http_app_ota_event_handler(esp_http_client_event_t *evt)
3131
{

main/src/user/nfc_app.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ static void nfc_app_task_handle(void *pvParameter)
118118
if (res > 0) {
119119
if (strstr((char *)rx_data, RX_FRAME_PRFX) != NULL &&
120120
strlen((char *)rx_data + RX_FRAME_PRFX_LEN) == RX_FRAME_DATA_LEN) {
121-
ESP_LOGW(TAG, "token is %32s", (char *)rx_data + RX_FRAME_PRFX_LEN);
121+
ESP_LOGW(TAG, "token: %32s", (char *)rx_data + RX_FRAME_PRFX_LEN);
122+
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
122123
audio_player_play_file(MP3_FILE_IDX_NOTIFY);
124+
#endif
123125
http_app_verify_token((char *)rx_data + RX_FRAME_PRFX_LEN);
124126
} else {
125127
ESP_LOGW(TAG, "unexpected frame");

main/src/user/ntp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
#include "core/os.h"
1414

15-
#include "user/gui.h"
1615
#include "user/led.h"
16+
#include "user/gui.h"
1717
#include "user/nfc_app.h"
1818
#include "user/http_app_ota.h"
1919

0 commit comments

Comments
 (0)