Skip to content

Commit d63f5cf

Browse files
committed
core: code refactoring
1 parent bb17cb4 commit d63f5cf

File tree

20 files changed

+138
-164
lines changed

20 files changed

+138
-164
lines changed

main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
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_TXTFILES res/cert/cert0.pem)
44
set(COMPONENT_EMBED_FILES res/snd/snd0.mp3 res/snd/snd1.mp3 res/snd/snd2.mp3 res/snd/snd3.mp3 res/snd/snd4.mp3 res/snd/snd5.mp3 res/snd/snd6.mp3 res/snd/snd7.mp3 res/ani/ani0_160x80.gif res/ani/ani1_160x80.gif res/ani/ani2_160x80.gif res/ani/ani3_160x80.gif res/ani/ani4_160x80.gif res/ani/ani5_160x80.gif res/ani/ani6_160x80.gif res/ani/ani7_160x80.gif res/ani/ani8_160x80.gif res/ani/ani0_240x135.gif res/ani/ani1_240x135.gif res/ani/ani2_240x135.gif res/ani/ani3_240x135.gif res/ani/ani4_240x135.gif res/ani/ani5_240x135.gif res/ani/ani6_240x135.gif res/ani/ani7_240x135.gif res/ani/ani8_240x135.gif)

main/Kconfig.projbuild

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,4 @@ config I2S_DOUT_PIN
203203
depends on ENABLE_AUDIO_PROMPT
204204
endmenu
205205

206-
config FIRMWARE_VERSION
207-
string "Firmware Version"
208-
default "v5.6.0"
209-
help
210-
Set firmware version.
211-
212206
endmenu

main/inc/core/app.h

Lines changed: 14 additions & 0 deletions
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 <redchenjs@live.com>
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

Lines changed: 5 additions & 5 deletions
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 <redchenjs@live.com>
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"
@@ -39,6 +39,6 @@ typedef enum user_event_group_bits {
3939
extern EventGroupHandle_t os_event_group;
4040
extern EventGroupHandle_t user_event_group;
4141

42-
extern void os_core_init(void);
42+
extern void os_init(void);
4343

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

main/inc/os/firmware.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

main/inc/os/init.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

main/src/app_main.c

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,87 @@
55
* Author: Jack Chen <redchenjs@live.com>
66
*/
77

8-
#include "os/init.h"
8+
#include "core/os.h"
9+
#include "core/app.h"
10+
11+
#include "chip/nvs.h"
12+
#include "chip/spi.h"
13+
#include "chip/i2s.h"
14+
#include "chip/i2c.h"
15+
#include "chip/wifi.h"
16+
#include "chip/uart.h"
17+
18+
#include "board/pn532.h"
19+
20+
#include "user/ntp.h"
21+
#include "user/led.h"
22+
#include "user/gui.h"
23+
#include "user/nfc_app.h"
24+
#include "user/key_scan.h"
25+
#include "user/http_app.h"
26+
#include "user/audio_mp3.h"
27+
28+
static void core_init(void)
29+
{
30+
app_print_version();
31+
32+
os_init();
33+
}
34+
35+
static void chip_init(void)
36+
{
37+
nvs_init();
38+
39+
wifi_init();
40+
41+
#ifdef CONFIG_PN532_IFCE_UART
42+
uart1_init();
43+
#else
44+
i2c0_init();
45+
#endif
46+
47+
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
48+
i2s0_init();
49+
#endif
50+
51+
#ifdef CONFIG_ENABLE_GUI
52+
hspi_init();
53+
#endif
54+
}
55+
56+
static void board_init(void)
57+
{
58+
pn532_init();
59+
}
60+
61+
static void user_init(void)
62+
{
63+
ntp_init();
64+
65+
nfc_app_init();
66+
67+
http_app_init();
68+
69+
#ifdef CONFIG_ENABLE_SMARTCONFIG
70+
key_scan_init();
71+
#endif
72+
73+
#ifdef CONFIG_ENABLE_LED
74+
led_init();
75+
#endif
76+
77+
#ifdef CONFIG_ENABLE_GUI
78+
gui_init();
79+
#endif
80+
81+
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
82+
audio_mp3_init();
83+
#endif
84+
}
985

1086
int app_main(void)
1187
{
12-
os_init(); // OS Event
88+
core_init(); // App Core
1389
chip_init(); // OnChip Module
1490
board_init(); // OnBoard Module
1591
user_init(); // User Task

main/src/core/app.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* app.c
3+
*
4+
* Created on: 2018-04-05 19:09
5+
* Author: Jack Chen <redchenjs@live.com>
6+
*/
7+
8+
#include <string.h>
9+
10+
#include "esp_log.h"
11+
#include "esp_ota_ops.h"
12+
13+
#define TAG "app"
14+
15+
const char *app_get_version(void)
16+
{
17+
const esp_app_desc_t *app_desc = esp_ota_get_app_description();
18+
19+
return (const char *)app_desc->version;
20+
}
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

Lines changed: 4 additions & 8 deletions
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 <redchenjs@live.com>
@@ -15,8 +15,7 @@
1515

1616
#include "freertos/event_groups.h"
1717

18-
#include "os/core.h"
19-
#include "os/firmware.h"
18+
#include "core/os.h"
2019
#include "chip/wifi.h"
2120
#include "user/nfc_app.h"
2221
#include "user/gui.h"
@@ -25,8 +24,7 @@
2524
#include "user/audio_mp3.h"
2625
#include "user/http_app_ota.h"
2726

28-
#define OS_CORE_TAG "os_core"
29-
#define OS_SC_TAG "os_sc"
27+
#define OS_SC_TAG "os_sc"
3028

3129
EventGroupHandle_t os_event_group;
3230
EventGroupHandle_t user_event_group;
@@ -128,10 +126,8 @@ static void sc_event_handler(void* arg, esp_event_base_t event_base,
128126
}
129127
}
130128

131-
void os_core_init(void)
129+
void os_init(void)
132130
{
133-
ESP_LOGW(OS_CORE_TAG, "current firmware version is %s", os_firmware_get_version());
134-
135131
os_event_group = xEventGroupCreate();
136132
user_event_group = xEventGroupCreate();
137133

main/src/os/firmware.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)