1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
24
25
29
30
33
34
35
36
39
40
43
46
47
48
51
54
55
56
59
62
63
64
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
89
90
93
94
99
100
101
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
181
182
183
188
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
245
246
250
251
252
253
254
255
256
257
258
259
261
262
263
264
265
266
267
268
272
273
274
275
276
277
278
279
280
281
282
283
293
294
295
296
297
300
301
304
305
/* ... */
#include "main.h"
/* ... */
/* ... */
/* ... */
#ifdef INCLUDE_THIRD_PARTY_MODULE
typedef void (*pFunc)(void);
#endif
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static void SystemClock_Config(void);
static void GUIThread(void const * argument);
static void TimerCallback(void const *n);
extern K_ModuleItem_Typedef video_player_board;
extern K_ModuleItem_Typedef audio_player_board;
#ifdef INCLUDE_THIRD_PARTY_MODULE
extern K_ModuleItem_Typedef third_party_board;
#endif
extern K_ModuleItem_Typedef games_board;
extern K_ModuleItem_Typedef gardening_control_board;
extern K_ModuleItem_Typedef home_alarm_board;
extern K_ModuleItem_Typedef settings_board;
extern K_ModuleItem_Typedef audio_recorder_board;
osTimerId lcd_timer;
uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
/* ... */
/* ... */
/* ... */
int main(void)
{
/* ... */
HAL_Init();
SystemClock_Config();
k_BspInit();
k_CalendarBkupInit();
osThreadDef(GUI_Thread, GUIThread, osPriorityLow, 0, 2048);
osThreadCreate (osThread(GUI_Thread), NULL);
k_ModuleInit();
k_ModuleAdd(&audio_player_board);
k_ModuleAdd(&video_player_board);
k_ModuleAdd(&games_board);
k_ModuleAdd(&audio_recorder_board);
k_ModuleAdd(&gardening_control_board);
k_ModuleAdd(&home_alarm_board);
k_ModuleAdd(&settings_board);
osKernelStart ();
for( ;; );
}{ ... }
/* ... */
static void GUIThread(void const * argument)
{
k_StorageInit();
GUI_Init();
WM_MULTIBUF_Enable(1);
GUI_SetLayerVisEx (1, 0);
GUI_SelectLayer(0);
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
k_SetGuiProfile();
k_StartUp();
osTimerDef(TS_Timer, TimerCallback);
lcd_timer = osTimerCreate(osTimer(TS_Timer), osTimerPeriodic, (void *)0);
osTimerStart(lcd_timer, 30);
k_InitMenu();
while(1) {
GUI_Exec();
osDelay(30);
}while (1) { ... }
}{ ... }
/* ... */
static void TimerCallback(void const *n)
{
k_TouchUpdate();
}{ ... }
/* ... */
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
/* ... */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 360;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
RCC_OscInitStruct.PLL.PLLR = 6;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
while(1);
}if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { ... }
if(HAL_PWREx_EnableOverDrive() != HAL_OK)
{
while(1);
}if (HAL_PWREx_EnableOverDrive() != HAL_OK) { ... }
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CK48;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
/* ... */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
while(1);
}if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { ... }
}{ ... }
#ifdef USE_FULL_ASSERT
/* ... */
void assert_failed(uint8_t* file, uint32_t line)
{
/* ... */
while (1)
{}while (1) { ... }
}assert_failed (uint8_t* file, uint32_t line) { ... }
/* ... */
#endif
/* ... */
/* ... */
/* ... */