diff --git a/L2_Core/port/gd32f470zgt6/gd_gpio_port.c b/L2_Core/port/gd32f470zgt6/gd_gpio_port.c index 984b486..e61fa35 100644 --- a/L2_Core/port/gd32f470zgt6/gd_gpio_port.c +++ b/L2_Core/port/gd32f470zgt6/gd_gpio_port.c @@ -59,7 +59,7 @@ static const ek_gpio_ops_t gd_gpio_ops = { // 注册到hal void gd_gpio_drv_init(void) { - for (uint8_t i = 0; i < sizeof(gd_drv_gpio_table) / sizeof(gd_drv_gpio_table[0]); i++) + for (uint8_t i = 0; i < EK_ARRAY_LEN(gd_drv_gpio_table); i++) { ek_hal_gpio_register(gd_drv_gpio_table[i].dev, gd_drv_gpio_table[i].name, diff --git a/L2_Core/port/stm32f429zi/st_gpio_port.c b/L2_Core/port/stm32f429zi/st_gpio_port.c index 52c4162..53be942 100644 --- a/L2_Core/port/stm32f429zi/st_gpio_port.c +++ b/L2_Core/port/stm32f429zi/st_gpio_port.c @@ -49,7 +49,7 @@ static const ek_gpio_ops_t st_gpio_ops = { // 注册到hal void st_gpio_drv_init(void) { - for (uint8_t i = 0; i < sizeof(st_drv_gpio_table) / sizeof(st_drv_gpio_table[0]); i++) + for (uint8_t i = 0; i < EK_ARRAY_LEN(st_drv_gpio_table); i++) { ek_hal_gpio_register(st_drv_gpio_table[i].dev, st_drv_gpio_table[i].name, diff --git a/L2_Core/utils/inc/ek_def.h b/L2_Core/utils/inc/ek_def.h index 964e18d..b21bc5d 100644 --- a/L2_Core/utils/inc/ek_def.h +++ b/L2_Core/utils/inc/ek_def.h @@ -16,6 +16,7 @@ #define EK_DEF_H #include +#include #include #include #include @@ -77,8 +78,13 @@ # define __STATIC_INLINE static __inline # define __ALWAYS_INLINE __forceinline # define __ASM __asm -/* ========== 不支持的编译器(空定义) ========== */ +/* ========== 不支持的编译器(需手动适配,默认编译报错) ========== */ #else + +# if 1 +# error "Unsupported compiler detected. Please review and update the macro definitions in ek_def.h for this toolchain." +# endif + # define __WEAK # define __PACKED # define __PACKED_STRUCT struct @@ -93,4 +99,11 @@ # define __ASM asm #endif +/* ========== 功能宏 ========== */ +#define EK_ARRAY_LEN(x) (sizeof(x) / (sizeof((x)[0]))) +#define EK_CLAMP(val, min, max) (((val) < (min)) ? (min) : (((val) > (max)) ? (max) : (val))) +#define EK_GET_FILE_NAME(file_path) \ + (strrchr((file_path), '/') ? strrchr((file_path), '/') + 1 \ + : (strrchr((file_path), '\\') ? strrchr((file_path), '\\') + 1 : (file_path))) + #endif /* EK_DEF_H */ diff --git a/L2_Core/utils/src/ek_assert.c b/L2_Core/utils/src/ek_assert.c index 2150a32..fef0a5e 100644 --- a/L2_Core/utils/src/ek_assert.c +++ b/L2_Core/utils/src/ek_assert.c @@ -6,17 +6,12 @@ #include "../inc/ek_assert.h" #include "../inc/ek_log.h" -#include - -#define GET_FILE_NAME(file_path) \ - (strrchr(file_path, '/') ? strrchr(file_path, '/') + 1 \ - : (strrchr(file_path, '\\') ? strrchr(file_path, '\\') + 1 : file_path)) void ek_assert_fault(const char *file, uint32_t line, const char *expr) { #if EK_ASSERT_WITH_LOG == 1 EK_LOG_FILE_TAG("ek_assert.c"); - EK_LOG_ERROR("file:%s,line:%" PRIu32 ",expr: %s", GET_FILE_NAME(file), line, expr); + EK_LOG_ERROR("file:%s,line:%" PRIu32 ",expr: %s", EK_GET_FILE_NAME(file), line, expr); #else __UNUSED(file); __UNUSED(line); diff --git a/L2_Core/utils/src/ek_log.c b/L2_Core/utils/src/ek_log.c index 6d89ec3..5b9a5e8 100644 --- a/L2_Core/utils/src/ek_log.c +++ b/L2_Core/utils/src/ek_log.c @@ -46,20 +46,15 @@ void _ek_log_printf(const char *tag, uint32_t line, ek_log_type_t type, uint32_t EK_LOG_LOCK(); # if (EK_LOG_COLOR_ENABLE == 1) - - ek_printf("%s[%s/%s L:%" PRIu32 ",T:%" PRIu32 "]:", - ek_log_color_table[type], - ek_log_type_table[type], - tag, - line, - _ek_log_get_tick()); + ek_printf( + "%s[%s/%s L:%" PRIu32 ",T:%" PRIu32 "]:", ek_log_color_table[type], ek_log_type_table[type], tag, line, tick); # else /* EK_LOG_COLOR_ENABLE == 1 */ ek_printf("[%s/%s L:%" PRIu32 ",T:%" PRIu32 "]:", ek_log_type_table[type], tag, line, tick); # endif /* EK_LOG_COLOR_ENABLE == 1 */ va_list args; va_start(args, fmt); - lwvsnprintf(ek_log_buffer, EK_LOG_BUFFER_SIZE - 1, fmt, args); + ek_vsnprintf(ek_log_buffer, EK_LOG_BUFFER_SIZE - 1, fmt, args); va_end(args); ek_printf("%s", ek_log_buffer); diff --git a/ek_conf.h b/ek_conf.h index 0ceee69..e44e1b9 100644 --- a/ek_conf.h +++ b/ek_conf.h @@ -46,7 +46,7 @@ #define EK_VEC_ENABLE (1) #define EK_RINGBUF_ENABLE (1) #define EK_STACK_ENABLE (1) -#define EK_SHELL_ENABLE (1) +#define EK_SHELL_ENABLE (0) /* ======================================================================== * 日志模块配置