Skip to content

Commit 0271e24

Browse files
committed
core: code refactoring
1 parent c9df214 commit 0271e24

16 files changed

+118
-137
lines changed

main/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(COMPONENT_SRCDIRS src src/user src/board src/chip src/os)
1+
set(COMPONENT_SRCDIRS src src/user src/board src/chip src/core)
22
set(COMPONENT_ADD_INCLUDEDIRS inc)
33
set(COMPONENT_EMBED_FILES res/snd/snd0.mp3 res/snd/snd1.mp3 res/snd/snd2.mp3 res/snd/snd3.mp3)
44

main/inc/core/app.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* app.h
3+
*
4+
* Created on: 2018-04-05 19:09
5+
* Author: Jack Chen <[email protected]>
6+
*/
7+
8+
#ifndef INC_CORE_APP_H_
9+
#define INC_CORE_APP_H_
10+
11+
extern const char *app_get_version(void);
12+
extern void app_print_version(void);
13+
14+
#endif /* INC_CORE_APP_H_ */

main/inc/os/core.h renamed to main/inc/core/os.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* core.h
2+
* os.h
33
*
44
* Created on: 2018-03-04 20:07
55
* Author: Jack Chen <[email protected]>
66
*/
77

8-
#ifndef INC_OS_CORE_H_
9-
#define INC_OS_CORE_H_
8+
#ifndef INC_CORE_OS_H_
9+
#define INC_CORE_OS_H_
1010

1111
#include "freertos/FreeRTOS.h"
1212
#include "freertos/event_groups.h"
@@ -27,6 +27,6 @@ extern EventGroupHandle_t user_event_group;
2727
extern void os_enter_sleep_mode(void);
2828
#endif
2929

30-
extern void os_core_init(void);
30+
extern void os_init(void);
3131

32-
#endif /* INC_OS_CORE_H_ */
32+
#endif /* INC_CORE_OS_H_ */

main/inc/os/firmware.h

-13
This file was deleted.

main/inc/os/init.h

-16
This file was deleted.

main/src/app_main.c

+73-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,82 @@
55
* Author: Jack Chen <[email protected]>
66
*/
77

8-
#include "os/init.h"
8+
#include "core/os.h"
9+
#include "core/app.h"
10+
11+
#include "chip/bt.h"
12+
#include "chip/nvs.h"
13+
#include "chip/spi.h"
14+
#include "chip/i2s.h"
15+
16+
#include "user/led.h"
17+
#include "user/vfx.h"
18+
#include "user/bt_app.h"
19+
#include "user/ble_app.h"
20+
#include "user/key_scan.h"
21+
#include "user/audio_mp3.h"
22+
#include "user/audio_input.h"
23+
24+
static void core_init(void)
25+
{
26+
app_print_version();
27+
28+
os_init();
29+
}
30+
31+
static void chip_init(void)
32+
{
33+
nvs_init();
34+
35+
bt_init();
36+
37+
#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == 0) || (CONFIG_AUDIO_INPUT_I2S_NUM == 0)
38+
i2s0_init();
39+
#endif
40+
41+
#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == 1) || (CONFIG_AUDIO_INPUT_I2S_NUM == 1)
42+
i2s1_init();
43+
#endif
44+
45+
#ifdef CONFIG_ENABLE_VFX
46+
hspi_init();
47+
#endif
48+
}
49+
50+
static void board_init(void) {}
51+
52+
static void user_init(void)
53+
{
54+
bt_app_init();
55+
56+
#ifdef CONFIG_ENABLE_BLE_CONTROL_IF
57+
ble_app_init();
58+
#endif
59+
60+
#ifdef CONFIG_ENABLE_VFX
61+
vfx_init();
62+
#endif
63+
64+
#ifdef CONFIG_ENABLE_LED
65+
led_init();
66+
#endif
67+
68+
#ifdef CONFIG_ENABLE_SLEEP_KEY
69+
key_scan_init();
70+
#endif
71+
72+
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
73+
audio_mp3_init();
74+
#endif
75+
76+
#ifndef CONFIG_AUDIO_INPUT_NONE
77+
audio_input_init();
78+
#endif
79+
}
980

1081
int app_main(void)
1182
{
12-
os_init(); // OS Event
83+
core_init(); // App Core
1384
chip_init(); // OnChip Module
1485
board_init(); // OnBoard Module
1586
user_init(); // User Task
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* firmware.c
2+
* app.c
33
*
44
* Created on: 2018-04-05 19:09
55
* Author: Jack Chen <[email protected]>
@@ -10,11 +10,16 @@
1010
#include "esp_log.h"
1111
#include "esp_ota_ops.h"
1212

13-
#define TAG "os_firmware"
13+
#define TAG "app"
1414

15-
const char *os_firmware_get_version(void)
15+
const char *app_get_version(void)
1616
{
1717
const esp_app_desc_t *app_desc = esp_ota_get_app_description();
1818

1919
return (const char *)app_desc->version;
2020
}
21+
22+
void app_print_version(void)
23+
{
24+
ESP_LOGW(TAG, "current app version is %s", app_get_version());
25+
}

main/src/os/core.c renamed to main/src/core/os.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* core.c
2+
* os.c
33
*
44
* Created on: 2018-03-04 20:07
55
* Author: Jack Chen <[email protected]>
@@ -12,19 +12,17 @@
1212
#include "freertos/event_groups.h"
1313
#include "freertos/task.h"
1414

15-
#include "os/core.h"
16-
#include "os/firmware.h"
15+
#include "core/os.h"
1716
#include "user/audio_mp3.h"
1817

19-
#define OS_CORE_TAG "os_core"
20-
#define OS_POWER_TAG "os_power"
18+
#define TAG "os"
2119

2220
EventGroupHandle_t user_event_group;
2321

2422
#ifdef CONFIG_ENABLE_WAKEUP_KEY
2523
void os_enter_sleep_mode(void)
2624
{
27-
ESP_LOGI(OS_POWER_TAG, "entering sleep mode");
25+
ESP_LOGI(TAG, "entering sleep mode");
2826

2927
#ifdef CONFIG_WAKEUP_KEY_ACTIVE_LOW
3028
esp_sleep_enable_ext1_wakeup(1ULL << CONFIG_WAKEUP_KEY_PIN, ESP_EXT1_WAKEUP_ALL_LOW);
@@ -36,12 +34,10 @@ void os_enter_sleep_mode(void)
3634
}
3735
#endif // CONFIG_ENABLE_WAKEUP_KEY
3836

39-
void os_core_init(void)
37+
void os_init(void)
4038
{
41-
ESP_LOGW(OS_CORE_TAG, "current firmware version is %s", os_firmware_get_version());
42-
4339
#ifdef CONFIG_ENABLE_WAKEUP_KEY
44-
ESP_LOGI(OS_POWER_TAG, "checking wakeup cause");
40+
ESP_LOGI(TAG, "checking wakeup cause");
4541
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED) {
4642
vTaskDelay(CONFIG_WAKEUP_KEY_EXTRA_HOLD_TIME / portTICK_RATE_MS);
4743

@@ -50,9 +46,9 @@ void os_core_init(void)
5046
#else
5147
if (gpio_get_level(CONFIG_WAKEUP_KEY_PIN) == 1) {
5248
#endif
53-
ESP_LOGI(OS_POWER_TAG, "resuming from sleep mode");
49+
ESP_LOGI(TAG, "resuming from sleep mode");
5450
} else {
55-
ESP_LOGI(OS_POWER_TAG, "resume aborted");
51+
ESP_LOGI(TAG, "resume aborted");
5652

5753
os_enter_sleep_mode();
5854
}

main/src/os/init.c

-76
This file was deleted.

main/src/user/audio_input.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "freertos/FreeRTOS.h"
1111
#include "driver/i2s.h"
1212

13-
#include "os/core.h"
13+
#include "core/os.h"
1414
#include "chip/i2s.h"
1515
#include "user/vfx_core.h"
1616

main/src/user/audio_mp3.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "synth.h"
1717
#include "stream.h"
1818

19-
#include "os/core.h"
19+
#include "core/os.h"
2020
#include "user/audio_mp3.h"
2121

2222
#define TAG "audio_mp3"

main/src/user/bt_app_av.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "freertos/task.h"
2222
#include "driver/i2s.h"
2323

24-
#include "os/core.h"
24+
#include "core/os.h"
2525
#include "chip/i2s.h"
2626
#include "user/led.h"
2727
#include "user/vfx_core.h"

main/src/user/bt_app_spp.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "freertos/FreeRTOS.h"
2020
#include "freertos/task.h"
2121

22-
#include "os/core.h"
23-
#include "os/firmware.h"
22+
#include "core/os.h"
23+
#include "core/app.h"
2424
#include "user/led.h"
2525
#include "user/vfx.h"
2626
#include "user/ble_app.h"
@@ -104,7 +104,7 @@ void bt_app_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
104104
ESP_LOGI(BT_SPP_TAG, "GET command: FW+VER?");
105105

106106
char str_buf[24] = {0};
107-
snprintf(str_buf, sizeof(str_buf), rsp_str[4], os_firmware_get_version());
107+
snprintf(str_buf, sizeof(str_buf), rsp_str[4], app_get_version());
108108
esp_spp_write(param->write.handle, strlen(str_buf), (uint8_t *)str_buf);
109109
} else if (strncmp(fw_cmd[2], (const char *)param->data_ind.data, 7) == 0) {
110110
sscanf((const char *)param->data_ind.data, fw_cmd[2], &image_length);

main/src/user/key_handle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "freertos/task.h"
1313
#include "driver/gpio.h"
1414

15-
#include "os/core.h"
15+
#include "core/os.h"
1616
#include "user/audio_mp3.h"
1717

1818
#ifdef CONFIG_ENABLE_SLEEP_KEY

main/src/user/key_scan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "freertos/task.h"
1313
#include "driver/gpio.h"
1414

15-
#include "os/core.h"
15+
#include "core/os.h"
1616
#include "user/key_handle.h"
1717

1818
#define TAG "key_scan"

main/src/user/vfx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "fft.h"
1313
#include "gfx.h"
1414

15-
#include "os/core.h"
15+
#include "core/os.h"
1616
#include "user/audio_input.h"
1717
#include "user/vfx_bitmap.h"
1818
#include "user/vfx_core.h"

0 commit comments

Comments
 (0)