News detail
Technical Deep Dive | Designing a Product-Level MCU Menu Framework


void test_main(void)
{
while(1)
{
get_key(&key);
switch(key)
{
case 1:
test_key();
break;
case 2:
test_lcd();
break;
....
}
}
}
Taking on too much: A menu only needs to handle menu switching. Once it reaches the lowest level-the actual test functions-it should not manage them. Menu switching is similar; actual tests are all different. For example, in a menu, pressing key 1 enters the first menu. But in tests, pressing key 1 has different functions. If the menu also manages this, there are too many functions for the same action, making unified abstraction impossible and modularization difficult. Different starting point: The menus mentioned above start from how to design a good menu data structure so the program runs quickly and efficiently. What I want is a menu structure that is easy to maintain. It does not matter how messy or complicated the menu code is. Moreover, even with hundreds or thousands of menus, polling would take only a few hundred microseconds; that is fine.
/**
* @brief Menu object
*/
typedef struct _strMenu
{
MenuLel l; ///<Menu level
char cha[MENU_LANG_BUF_SIZE]; ///Chinese
char eng[MENU_LANG_BUF_SIZE]; ///English
MenuType type; ///Menu type
s32 (*fun)(void); ///Test function
} MENU;
const MENU EMenuListTest[]=
{
MENU_L_0,//Menu level
"Test program",//Chinese
"test", //English
MENU_TYPE_LIST,//Menu type
NULL,//Menu function; only functional menu items execute, those with submenus do not execute
MENU_L_1,//Menu level
"LCD",//Chinese
"LCD", // English
MENU_TYPE_LIST,// Menu type
NULL,// Menu function; only function menus execute; menus with submenus do not execute
MENU_L_2,// Menu level
"VSPI OLED",// Chinese
"VSPI OLED", // English
MENU_TYPE_FUN,// Menu type
test_oled,// Menu function; only function menus execute, those with submenus do not
MENU_L_2,// Menu level
"I2C OLED",// Chinese
"I2C OLED", // English
MENU_TYPE_FUN,// Menu type
test_i2coled,// Menu function; only function menus execute, those with submenus do not
MENU_L_1,// Menu level
"Sound",// Chinese
"sound", // English
MENU_TYPE_LIST,// Menu type
NULL,// Menu function; only function menus execute; those with submenus do not
MENU_L_2,// Menu level
"Buzzer",// Chinese
"buzzer", //English
MENU_TYPE_FUN,//Menu type
test_test,//Menu function; only function menus will execute; those with submenus will not execute
MENU_L_2,//Menu level
"DAC music",//Chinese
"DAC music", //English
MENU_TYPE_FUN,//Menu type
test_test,// Menu function; only function menus execute; menus with submenus do not execute
MENU_L_2,// Menu level
"Radio",// Chinese
"FM", // English
MENU_TYPE_FUN,// Menu type
test_test,// Menu function; only function menus execute; menus with submenus do not execute
MENU_L_1,// Menu level
"Touchscreen",// Chinese
"tp", // English
MENU_TYPE_LIST,// Menu type
NULL,// Menu function; only function menus are executed; those with submenus are not executed
MENU_L_2,// Menu level
"Calibration",// Chinese
"calibrate" // English
MENU_TYPE_FUN,// Menu type
test_cal,// Menu function; only function menus execute; those with submenus do not.
MENU_L_2,// Menu level
"Test",// Chinese
"test", // English
MENU_TYPE_FUN,// Menu type
test_tp,// Menu function; only function menus execute; those with submenus do not.
MENU_L_1,//Menu level
"Key",//Chinese
"KEY", //English
MENU_TYPE_FUN,//Menu type
test_key,//Menu function; only function menus execute, menus with submenus do not execute
/*The last menu is the end menu and is meaningless*/
MENU_L_0,//Menu level
"END",// Chinese
"END", // English
MENU_TYPE_NULL,// Menu type
NULL,// Menu function: only functional menus execute; those with submenus do not execute
};
-----------------------------------------------
Root node
No.1piece1st-level menu
No.1submenu
No.2submenu
No.3submenu
No.2:1st-level menu
No.1submenu
No.1grandchild menu
No.2grandchild menu
No.2submenu
No.3submenu
No.3item1st-level menu
No.4item1level menu
the5th1-level menu
end node
------------------------------------------------
emenu_run(WJQTestLcd, (MENU *)&WJQTestList[0], sizeof(WJQTestList)/sizeof(MENU), FONT_SONGTI_1616, 2);
Display results
128*64 OLED


128*128 tft lcd


320*240 tft lcd


Summary
Note: This article is reposted from , reposted thisarticle for the purpose of conveying more information; copyright belongs to the original author.

Zhuhai Taixin Semiconductor Co., Ltd.
Zhuhai Taixin Semiconductor Co., Ltd. was founded in 2016 and is a high-tech enterprise integrating IC design and wireless intelligent communication solutions. We have successively launched long-range, low-power IoT WIFI chips, low-power motor controller chips, and product solutions. The company adheres to a market-oriented and technology-centered approach to provide customers with high-quality chips and product technical solutions.
The company's core product: WIFI communication chip for long-range low-power IoT. This chip can be used in smart homes, security monitoring, drone image transmission, smart meter reading, smart door locks, smart grids, smart hospitals, logistics robots, and other product fields.

