110 lines
3.1 KiB
C
110 lines
3.1 KiB
C
/**
|
||
* @file menu_def.h
|
||
* @brief 菜单组件内部宏定义和辅助函数(用户无需关心)
|
||
*/
|
||
#ifndef MENU_DEF_H
|
||
#define MENU_DEF_H
|
||
|
||
#include "menu_config.h"
|
||
#include "menu.h"
|
||
#include <stdint.h>
|
||
#include <string.h>
|
||
|
||
/************************** 内部宏定义 **************************/
|
||
/**
|
||
* @brief 断言宏(工业级:调试时检查,发布时忽略)
|
||
*/
|
||
#if MENU_CONFIG_ENABLE_ASSERT
|
||
#define MENU_ASSERT(condition) \
|
||
do { \
|
||
if (!(condition)) { \
|
||
menu_utils_assert_failed(__FILE__, __LINE__); \
|
||
while (1); \
|
||
} \
|
||
} while (0)
|
||
#else
|
||
#define MENU_ASSERT(condition) ((void)0)
|
||
#endif
|
||
|
||
/**
|
||
* @brief 日志级别定义
|
||
*/
|
||
typedef enum {
|
||
MENU_LOG_LEVEL_DEBUG, ///< 调试信息
|
||
MENU_LOG_LEVEL_INFO, ///< 普通信息
|
||
MENU_LOG_LEVEL_WARN, ///< 警告信息
|
||
MENU_LOG_LEVEL_ERROR, ///< 错误信息
|
||
MENU_LOG_LEVEL_CRITICAL, ///< 严重错误
|
||
} MenuLogLevel;
|
||
|
||
/**
|
||
* @brief 调试打印宏(工业级:集中控制调试输出)
|
||
*/
|
||
#if MENU_CONFIG_ENABLE_DEBUG
|
||
#define MENU_DEBUG(fmt, ...) menu_utils_log(MENU_LOG_LEVEL_DEBUG, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||
#define MENU_INFO(fmt, ...) menu_utils_log(MENU_LOG_LEVEL_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||
#define MENU_WARN(fmt, ...) menu_utils_log(MENU_LOG_LEVEL_WARN, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||
#define MENU_ERROR(fmt, ...) menu_utils_log(MENU_LOG_LEVEL_ERROR, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||
#define MENU_CRITICAL(fmt, ...) menu_utils_log(MENU_LOG_LEVEL_CRITICAL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||
#else
|
||
#define MENU_DEBUG(fmt, ...) ((void)0)
|
||
#define MENU_INFO(fmt, ...) ((void)0)
|
||
#define MENU_WARN(fmt, ...) ((void)0)
|
||
#define MENU_ERROR(fmt, ...) ((void)0)
|
||
#define MENU_CRITICAL(fmt, ...) ((void)0)
|
||
#endif
|
||
|
||
/**
|
||
* @brief 内存清零宏
|
||
*/
|
||
#define MENU_MEM_SET_ZERO(ptr, size) memset((ptr), 0, (size))
|
||
|
||
/**
|
||
* @brief 无效ID定义
|
||
*/
|
||
#define MENU_INVALID_ID ((MenuNodeId)0xFFFF)
|
||
|
||
/**
|
||
* @brief 错误处理宏(简化错误检查和返回)
|
||
*/
|
||
#define MENU_CHECK_ERR(expr) \
|
||
do { \
|
||
MenuErrCode err = (expr); \
|
||
if (err != MENU_OK) { \
|
||
MENU_ERROR("Error at %s:%d: %s", __FILE__, __LINE__, menu_err_code_to_str(err)); \
|
||
return err; \
|
||
} \
|
||
} while (0)
|
||
|
||
/************************** 内部辅助函数声明 **************************/
|
||
/**
|
||
* @brief 断言失败处理函数
|
||
* @param file 文件名
|
||
* @param line 行号
|
||
*/
|
||
void menu_utils_assert_failed(const char* file, uint32_t line);
|
||
|
||
/**
|
||
* @brief 通用日志函数(对接port层的硬件打印接口)
|
||
* @param level 日志级别
|
||
* @param file 文件名
|
||
* @param line 行号
|
||
* @param fmt 格式化字符串
|
||
* @param ... 可变参数
|
||
*/
|
||
void menu_utils_log(MenuLogLevel level, const char* file, uint32_t line, const char* fmt, ...);
|
||
|
||
/**
|
||
* @brief 获取系统滴答时间(ms,对接port层)
|
||
* @return 当前滴答时间
|
||
*/
|
||
uint32_t menu_utils_get_tick(void);
|
||
|
||
/**
|
||
* @brief 错误码转换为字符串
|
||
* @param err_code 错误码
|
||
* @return 错误信息字符串
|
||
*/
|
||
const char* menu_err_code_to_str(MenuErrCode err_code);
|
||
|
||
#endif // MENU_DEF_H
|