From 788aeb96604a6f0f5eb4d0a4d9f3fa6fe8985a9a Mon Sep 17 00:00:00 2001 From: N1netyNine99 Date: Thu, 26 Feb 2026 21:34:04 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[fix]=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=AF=B9?= =?UTF-8?q?=20cpp=20=E7=9A=84=E6=94=AF=E6=8C=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- L2_Core/hal/inc/ek_hal_adc.h | 12 +++++++++++- L2_Core/hal/inc/ek_hal_dac.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_dma.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_dma2d.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_gpio.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_i2c.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_ltdc.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_pwm.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_spi.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_tick.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_tim.h | 9 +++++++++ L2_Core/hal/inc/ek_hal_uart.h | 9 +++++++++ L2_Core/port/inc/gd_hal_port.h | 9 +++++++++ L2_Core/port/inc/st_hal_port.h | 9 +++++++++ L2_Core/utils/inc/ek_assert.h | 9 +++++++++ L2_Core/utils/inc/ek_export.h | 9 +++++++++ L2_Core/utils/inc/ek_io.h | 9 +++++++++ L2_Core/utils/inc/ek_list.h | 26 +++++++++++++------------- L2_Core/utils/inc/ek_str.h | 9 +++++++++ 19 files changed, 177 insertions(+), 14 deletions(-) diff --git a/L2_Core/hal/inc/ek_hal_adc.h b/L2_Core/hal/inc/ek_hal_adc.h index e6f5ee3..ab1b6c5 100644 --- a/L2_Core/hal/inc/ek_hal_adc.h +++ b/L2_Core/hal/inc/ek_hal_adc.h @@ -4,11 +4,17 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_adc_t ek_hal_adc_t; typedef struct ek_adc_ops_t ek_adc_ops_t; /** @brief ADC 分辨率枚举 */ -typedef enum { +typedef enum +{ EK_HAL_ADC_RES_8B, EK_HAL_ADC_RES_10B, EK_HAL_ADC_RES_12B, @@ -47,4 +53,8 @@ bool ek_hal_adc_read_dma(ek_hal_adc_t *const dev, uint32_t *buffer, size_t size) void ek_hal_adc_start(ek_hal_adc_t *const dev); void ek_hal_adc_stop(ek_hal_adc_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_ADC_H diff --git a/L2_Core/hal/inc/ek_hal_dac.h b/L2_Core/hal/inc/ek_hal_dac.h index 1e29755..c6103a2 100644 --- a/L2_Core/hal/inc/ek_hal_dac.h +++ b/L2_Core/hal/inc/ek_hal_dac.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_dac_t ek_hal_dac_t; typedef struct ek_dac_ops_t ek_dac_ops_t; @@ -38,4 +43,8 @@ bool ek_hal_dac_write_dma(ek_hal_dac_t *const dev, uint32_t *buffer, size_t size void ek_hal_dac_start(ek_hal_dac_t *const dev); void ek_hal_dac_stop(ek_hal_dac_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_DAC_H diff --git a/L2_Core/hal/inc/ek_hal_dma.h b/L2_Core/hal/inc/ek_hal_dma.h index c215d5a..72f4eb0 100644 --- a/L2_Core/hal/inc/ek_hal_dma.h +++ b/L2_Core/hal/inc/ek_hal_dma.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_dma_t ek_hal_dma_t; typedef struct ek_dma_ops_t ek_dma_ops_t; @@ -42,4 +47,8 @@ bool ek_hal_dma_transfer(ek_hal_dma_t *const dev, void *src, void *dst, size_t s bool ek_hal_dma_transfer_it(ek_hal_dma_t *const dev, void *src, void *dst, size_t size, ek_dma_direction_t dir); void ek_hal_dma_abort(ek_hal_dma_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_DMA_H diff --git a/L2_Core/hal/inc/ek_hal_dma2d.h b/L2_Core/hal/inc/ek_hal_dma2d.h index 0129a48..e028743 100644 --- a/L2_Core/hal/inc/ek_hal_dma2d.h +++ b/L2_Core/hal/inc/ek_hal_dma2d.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_dma2d_t ek_hal_dma2d_t; typedef struct ek_dma2d_ops_t ek_dma2d_ops_t; @@ -71,4 +76,8 @@ bool ek_hal_dma2d_convert_it(ek_hal_dma2d_t *const dev, uint32_t offset, ek_dma2d_color_mode_t input_mode); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_DMA2D_H diff --git a/L2_Core/hal/inc/ek_hal_gpio.h b/L2_Core/hal/inc/ek_hal_gpio.h index 435b296..7fb8c9b 100644 --- a/L2_Core/hal/inc/ek_hal_gpio.h +++ b/L2_Core/hal/inc/ek_hal_gpio.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_gpio_t ek_hal_gpio_t; typedef struct ek_gpio_ops_t ek_gpio_ops_t; @@ -56,4 +61,8 @@ void ek_hal_gpio_set(ek_hal_gpio_t *const dev, ek_gpio_status_t status); void ek_hal_gpio_toggle(ek_hal_gpio_t *const dev); ek_gpio_status_t ek_hal_gpio_read(ek_hal_gpio_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_GPIO_H diff --git a/L2_Core/hal/inc/ek_hal_i2c.h b/L2_Core/hal/inc/ek_hal_i2c.h index 15ecdbe..bce98c8 100644 --- a/L2_Core/hal/inc/ek_hal_i2c.h +++ b/L2_Core/hal/inc/ek_hal_i2c.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_i2c_t ek_hal_i2c_t; typedef struct ek_i2c_ops_t ek_i2c_ops_t; @@ -65,4 +70,8 @@ bool ek_hal_i2c_mem_read(ek_hal_i2c_t *const dev, uint8_t *rxdata, size_t size); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_I2C_H diff --git a/L2_Core/hal/inc/ek_hal_ltdc.h b/L2_Core/hal/inc/ek_hal_ltdc.h index e4e239d..daf250f 100644 --- a/L2_Core/hal/inc/ek_hal_ltdc.h +++ b/L2_Core/hal/inc/ek_hal_ltdc.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_ltdc_t ek_hal_ltdc_t; typedef struct ek_ltdc_ops_t ek_ltdc_ops_t; @@ -41,4 +46,8 @@ bool ek_hal_ltdc_reload_config(ek_hal_ltdc_t *const dev); void ek_hal_ltdc_display_on(ek_hal_ltdc_t *const dev); void ek_hal_ltdc_display_off(ek_hal_ltdc_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_LTDC_H diff --git a/L2_Core/hal/inc/ek_hal_pwm.h b/L2_Core/hal/inc/ek_hal_pwm.h index 6141296..5543705 100644 --- a/L2_Core/hal/inc/ek_hal_pwm.h +++ b/L2_Core/hal/inc/ek_hal_pwm.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_pwm_t ek_hal_pwm_t; typedef struct ek_pwm_ops_t ek_pwm_ops_t; @@ -43,4 +48,8 @@ void ek_hal_pwm_set_freq(ek_hal_pwm_t *const dev, uint32_t freq); uint32_t ek_hal_pwm_get_duty(ek_hal_pwm_t *const dev); uint32_t ek_hal_pwm_get_freq(ek_hal_pwm_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_PWM_H diff --git a/L2_Core/hal/inc/ek_hal_spi.h b/L2_Core/hal/inc/ek_hal_spi.h index b232398..4cf1860 100644 --- a/L2_Core/hal/inc/ek_hal_spi.h +++ b/L2_Core/hal/inc/ek_hal_spi.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_spi_t ek_hal_spi_t; typedef struct ek_spi_ops_t ek_spi_ops_t; @@ -35,4 +40,8 @@ bool ek_hal_spi_write(ek_hal_spi_t *const dev, uint8_t *txdata, size_t size); bool ek_hal_spi_read(ek_hal_spi_t *const dev, uint8_t *rxdata, size_t size); bool ek_hal_spi_write_read(ek_hal_spi_t *const dev, uint8_t *txdata, uint8_t *rxdata, size_t size); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_SPI_H diff --git a/L2_Core/hal/inc/ek_hal_tick.h b/L2_Core/hal/inc/ek_hal_tick.h index a3b4879..a30b9e2 100644 --- a/L2_Core/hal/inc/ek_hal_tick.h +++ b/L2_Core/hal/inc/ek_hal_tick.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_tick_t ek_hal_tick_t; typedef struct ek_tick_ops_t ek_tick_ops_t; @@ -33,4 +38,8 @@ ek_hal_tick_t *ek_hal_tick_find(const char *name); uint32_t ek_hal_tick_get(ek_hal_tick_t *const dev); void ek_hal_tick_delay(ek_hal_tick_t *const dev, uint32_t xtick); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_TICK_H diff --git a/L2_Core/hal/inc/ek_hal_tim.h b/L2_Core/hal/inc/ek_hal_tim.h index bcdae20..4babc20 100644 --- a/L2_Core/hal/inc/ek_hal_tim.h +++ b/L2_Core/hal/inc/ek_hal_tim.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_tim_base_t ek_hal_tim_base_t; typedef struct ek_tim_ops_t ek_tim_ops_t; @@ -53,4 +58,8 @@ void ek_hal_tim_stop(ek_hal_tim_base_t *const dev); uint32_t ek_hal_tim_get(ek_hal_tim_base_t *const dev); void ek_hal_tim_set(ek_hal_tim_base_t *const dev, uint32_t value); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_TIMER_H diff --git a/L2_Core/hal/inc/ek_hal_uart.h b/L2_Core/hal/inc/ek_hal_uart.h index 5693e9e..ff807fe 100644 --- a/L2_Core/hal/inc/ek_hal_uart.h +++ b/L2_Core/hal/inc/ek_hal_uart.h @@ -4,6 +4,11 @@ #include "../../utils/inc/ek_def.h" #include "../../utils/inc/ek_list.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct ek_hal_uart_t ek_hal_uart_t; typedef struct ek_uart_ops_t ek_uart_ops_t; @@ -38,4 +43,8 @@ bool ek_hal_uart_write(ek_hal_uart_t *const dev, uint8_t *txdata, size_t size); bool ek_hal_uart_write_dma(ek_hal_uart_t *const dev, uint8_t *txdata, size_t size); void ek_hal_uart_read(ek_hal_uart_t *const dev); +#ifdef __cplusplus +} +#endif + #endif // EK_HAL_UART_H diff --git a/L2_Core/port/inc/gd_hal_port.h b/L2_Core/port/inc/gd_hal_port.h index bd60ec0..52b5a8f 100644 --- a/L2_Core/port/inc/gd_hal_port.h +++ b/L2_Core/port/inc/gd_hal_port.h @@ -1,6 +1,11 @@ #ifndef GD_HAL_PORT_H #define GD_HAL_PORT_H +#ifdef __cplusplus +extern "C" +{ +#endif + void gd_gpio_drv_init(void); void gd_uart_drv_init(void); void gd_spi_drv_init(void); @@ -12,4 +17,8 @@ void gd_adc_drv_init(void); void gd_dac_drv_init(void); void gd_pwm_drv_init(void); +#ifdef __cplusplus +} +#endif + #endif // GD_HAL_PORT_H diff --git a/L2_Core/port/inc/st_hal_port.h b/L2_Core/port/inc/st_hal_port.h index 834982c..89c9112 100644 --- a/L2_Core/port/inc/st_hal_port.h +++ b/L2_Core/port/inc/st_hal_port.h @@ -1,6 +1,11 @@ #ifndef ST_HAL_PORT_H #define ST_HAL_PORT_H +#ifdef __cplusplus +extern "C" +{ +#endif + void st_gpio_drv_init(void); void st_spi_drv_init(void); void st_uart_drv_init(void); @@ -10,4 +15,8 @@ void st_dma2d_drv_init(void); void st_ltdc_drv_init(void); void st_tick_drv_init(void); +#ifdef __cplusplus +} +#endif + #endif // ST_HAL_PORT_H diff --git a/L2_Core/utils/inc/ek_assert.h b/L2_Core/utils/inc/ek_assert.h index 48b452d..0459e0f 100644 --- a/L2_Core/utils/inc/ek_assert.h +++ b/L2_Core/utils/inc/ek_assert.h @@ -59,6 +59,11 @@ # define ek_assert_param(expr) ek_assert_full(expr) #endif /* EK_ASSERT_USE_TINY */ +#ifdef __cplusplus +extern "C" +{ +#endif + /** * @brief 断言失败处理函数 * @param file 源文件名 @@ -68,4 +73,8 @@ */ void ek_assert_fault(const char *file, uint32_t line, const char *expr); +#ifdef __cplusplus +} +#endif + #endif /* EK_ASSERT_H */ diff --git a/L2_Core/utils/inc/ek_export.h b/L2_Core/utils/inc/ek_export.h index 15a45f8..2529b9a 100644 --- a/L2_Core/utils/inc/ek_export.h +++ b/L2_Core/utils/inc/ek_export.h @@ -72,10 +72,19 @@ typedef void (*_ek_export_init_fn_t)(void); #endif /* EK_EXPORT_ENABLE */ +#ifdef __cplusplus +extern "C" +{ +#endif + /** * @brief 执行所有导出的初始化函数 * @note 按优先级顺序调用所有通过 EK_EXPORT 导出的函数 */ void ek_export_init(void); +#ifdef __cplusplus +} +#endif + #endif /* EK_EXPORT_H */ diff --git a/L2_Core/utils/inc/ek_io.h b/L2_Core/utils/inc/ek_io.h index 8258448..e28d5db 100644 --- a/L2_Core/utils/inc/ek_io.h +++ b/L2_Core/utils/inc/ek_io.h @@ -13,6 +13,11 @@ #include "../../../ek_conf.h" +#ifdef __cplusplus +extern "C" +{ +#endif + #if EK_IO_NO_LWPRTF == 0 # include "../../third_party/lwprintf/inc/lwprintf.h" @@ -56,4 +61,8 @@ void ek_io_init(void); #endif /* EK_IO_NO_LWPRTF */ +#ifdef __cplusplus +} +#endif + #endif diff --git a/L2_Core/utils/inc/ek_list.h b/L2_Core/utils/inc/ek_list.h index 60555cd..da98417 100644 --- a/L2_Core/utils/inc/ek_list.h +++ b/L2_Core/utils/inc/ek_list.h @@ -13,7 +13,7 @@ #if EK_LIST_ENABLE == 1 -#include "ek_def.h" +# include "ek_def.h" /** * @brief 链表节点结构 @@ -81,36 +81,36 @@ __STATIC_INLINE void ek_list_init(ek_list_node_t *head) /** * @brief 内部函数:在两个节点之间插入新节点 - * @param new 要插入的新节点 + * @param new_node 要插入的新节点 * @param prev 前一个节点(插入位置之前) * @param next 后一个节点(插入位置之后) */ -__STATIC_INLINE void __ek_list_add(ek_list_node_t *new, ek_list_node_t *prev, ek_list_node_t *next) +__STATIC_INLINE void __ek_list_add(ek_list_node_t *new_node, ek_list_node_t *prev, ek_list_node_t *next) { - prev->next = new; - new->next = next; - new->prev = prev; - next->prev = new; + prev->next = new_node; + new_node->next = next; + new_node->prev = prev; + next->prev = new_node; } /** * @brief 在链表头部添加节点 * @param head 链表头节点指针 - * @param new 要添加的新节点 + * @param new_node 要添加的新节点 */ -__STATIC_INLINE void ek_list_add_head(ek_list_node_t *head, ek_list_node_t *new) +__STATIC_INLINE void ek_list_add_head(ek_list_node_t *head, ek_list_node_t *new_node) { - __ek_list_add(new, head, head->next); + __ek_list_add(new_node, head, head->next); } /** * @brief 在链表尾部添加节点 * @param head 链表头节点指针 - * @param new 要添加的新节点 + * @param new_node 要添加的新节点 */ -__STATIC_INLINE void ek_list_add_tail(ek_list_node_t *head, ek_list_node_t *new) +__STATIC_INLINE void ek_list_add_tail(ek_list_node_t *head, ek_list_node_t *new_node) { - __ek_list_add(new, head->prev, head); + __ek_list_add(new_node, head->prev, head); } /** diff --git a/L2_Core/utils/inc/ek_str.h b/L2_Core/utils/inc/ek_str.h index 7ed9552..6827580 100644 --- a/L2_Core/utils/inc/ek_str.h +++ b/L2_Core/utils/inc/ek_str.h @@ -21,6 +21,11 @@ # include "ek_def.h" +# ifdef __cplusplus +extern "C" +{ +# endif + /** * @brief 动态字符串结构体 */ @@ -138,6 +143,10 @@ int ek_str_cmp(ek_str_t *s1, ek_str_t *s2); */ int ek_str_ncmp(ek_str_t *s1, ek_str_t *s2, size_t n); +# ifdef __cplusplus +} +# endif + #endif // EK_STR_ENABLE #endif // EK_STR_H From eaad7163a642d4446f0cad552458b5c151c91fd0 Mon Sep 17 00:00:00 2001 From: N1netyNine99 <2570955716@qq.com> Date: Sun, 8 Mar 2026 19:13:31 +0800 Subject: [PATCH 2/5] =?UTF-8?q?add=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=20ek=5Fstr=5Freverse=20=E5=87=BD=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=BF=BB=E8=BD=AC=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- L2_Core/utils/inc/ek_str.h | 8 ++++++++ L2_Core/utils/src/ek_str.c | 21 +++++++++++++++++++++ Test/str_test.c | 10 ++++++++++ 3 files changed, 39 insertions(+) diff --git a/L2_Core/utils/inc/ek_str.h b/L2_Core/utils/inc/ek_str.h index 6827580..b14877b 100644 --- a/L2_Core/utils/inc/ek_str.h +++ b/L2_Core/utils/inc/ek_str.h @@ -104,6 +104,14 @@ bool ek_str_cat(ek_str_t *dst, ek_str_t *src); */ ek_str_t *ek_str_slice(const ek_str_t *s, int32_t start, int32_t end); +/** + * @brief 翻转字符串 + * @param s 源字符串 + * @return 是否执行成功 + * @note 如果字符串的缓冲区为空会直接返回 false + */ +bool ek_str_reverse(ek_str_t *s); + /** * @brief 获取 C 风格字符串 * @param s 字符串对象指针 diff --git a/L2_Core/utils/src/ek_str.c b/L2_Core/utils/src/ek_str.c index 8fabdd9..8eb529f 100644 --- a/L2_Core/utils/src/ek_str.c +++ b/L2_Core/utils/src/ek_str.c @@ -170,6 +170,27 @@ ek_str_t *ek_str_slice(const ek_str_t *s, int32_t start, int32_t end) return new_s; } +bool ek_str_reverse(ek_str_t *s) +{ + ek_assert_param(s != NULL); + + if (s->buf == NULL) return false; + + char *left = s->buf; + char *right = s->buf + s->len - 1; + + while (left < right) + { + char temp = *left; + *left = *right; + *right = temp; + left++; + right--; + } + + return true; +} + const char *ek_str_get_cstring(ek_str_t *s) { ek_assert_param(s != NULL); diff --git a/Test/str_test.c b/Test/str_test.c index bbca161..bc1721c 100644 --- a/Test/str_test.c +++ b/Test/str_test.c @@ -49,8 +49,18 @@ void str_test(void) ek_str_cat(s, s1); EK_LOG_INFO("cat result:%s", ek_str_get_cstring(s)); + const char *abcdefg = "abcdefg"; + EK_LOG_INFO("reverse test"); + EK_LOG_INFO("make a new string:%s", abcdefg); + ek_str_t *s2 = ek_str_create(abcdefg); + EK_LOG_INFO("string:%s", ek_str_get_cstring(s2)); + EK_LOG_INFO("reverse start"); + ek_str_reverse(s2); + EK_LOG_INFO("reverse result:%s", ek_str_get_cstring(s2)); + ek_str_free(s); ek_str_free(s1); + ek_str_free(s2); EK_LOG_INFO("string finished,unused heap:%zu", ek_heap_unused()); EK_LOG_INFO("string finished,used heap:%zu", ek_heap_used()); } From 3c90490ecefee6e4f8439bf5d945915c11ca400f Mon Sep 17 00:00:00 2001 From: N1netyNine99 <2570955716@qq.com> Date: Mon, 9 Mar 2026 11:41:49 +0800 Subject: [PATCH 3/5] add marco EK_FREQ_K and EK_FREQ_M --- L2_Core/utils/inc/ek_def.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/L2_Core/utils/inc/ek_def.h b/L2_Core/utils/inc/ek_def.h index b21bc5d..7018af0 100644 --- a/L2_Core/utils/inc/ek_def.h +++ b/L2_Core/utils/inc/ek_def.h @@ -82,7 +82,8 @@ #else # if 1 -# error "Unsupported compiler detected. Please review and update the macro definitions in ek_def.h for this toolchain." +# error \ + "Unsupported compiler detected. Please review and update the macro definitions in ek_def.h for this toolchain." # endif # define __WEAK @@ -100,10 +101,12 @@ #endif /* ========== 功能宏 ========== */ +#define EK_FREQ_K(x) ((x) * 1000UL) +#define EK_FREQ_M(x) ((x) * 1000UL * 1000UL) #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 \ +#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 */ From 0eca4886b200cd5d69d2a15a1401bae8287b2c93 Mon Sep 17 00:00:00 2001 From: N1netyNine99 <2570955716@qq.com> Date: Mon, 9 Mar 2026 11:43:08 +0800 Subject: [PATCH 4/5] [fmt] --- L2_Core/utils/src/ek_str.c | 52 ++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/L2_Core/utils/src/ek_str.c b/L2_Core/utils/src/ek_str.c index 8eb529f..3e4eebb 100644 --- a/L2_Core/utils/src/ek_str.c +++ b/L2_Core/utils/src/ek_str.c @@ -20,31 +20,7 @@ if ((idx) > (len)) (idx) = (len); \ } while (0) -static bool _ek_str_ensure_cap(ek_str_t *s, uint32_t len) -{ - ek_assert_param(s != NULL); - - if (s->cap >= len) return true; - - uint32_t new_cap = s->cap; - do - { - if (new_cap == 0) new_cap = 2; - new_cap += new_cap / 2; - } while (new_cap < len); - - char *buf = NULL; - - if (s->buf == NULL) buf = ek_malloc(len); - else buf = ek_realloc(s->buf, new_cap); - - if (buf == NULL) return false; - - s->buf = buf; - s->cap = new_cap; - - return true; -} +static bool _ek_str_ensure_cap(ek_str_t *s, uint32_t len); ek_str_t *ek_str_create(const char *str) { @@ -235,4 +211,30 @@ int ek_str_ncmp(ek_str_t *s1, ek_str_t *s2, size_t n) return strncmp(ek_str_get_cstring(s1), ek_str_get_cstring(s2), n); } +static bool _ek_str_ensure_cap(ek_str_t *s, uint32_t len) +{ + ek_assert_param(s != NULL); + + if (s->cap >= len) return true; + + uint32_t new_cap = s->cap; + do + { + if (new_cap == 0) new_cap = 2; + new_cap += new_cap / 2; + } while (new_cap < len); + + char *buf = NULL; + + if (s->buf == NULL) buf = ek_malloc(len); + else buf = ek_realloc(s->buf, new_cap); + + if (buf == NULL) return false; + + s->buf = buf; + s->cap = new_cap; + + return true; +} + #endif // EK_STR_ENABLE From ee8edecd1d48ef8a879810b1fed9c0e346b05e65 Mon Sep 17 00:00:00 2001 From: N1netyNine99 Date: Wed, 18 Mar 2026 18:40:17 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E5=B8=A6=E5=8F=82=E6=95=B0=E7=9A=84=E5=AE=8F=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=B0=86=E5=8F=82=E6=95=B0=E7=94=A8=E6=8B=AC=E5=8F=B7=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- L2_Core/utils/inc/ek_def.h | 2 +- L2_Core/utils/inc/ek_export.h | 13 ++-- L2_Core/utils/inc/ek_log.h | 2 +- L2_Core/utils/inc/ek_mem.h | 18 ++--- L2_Core/utils/inc/ek_ringbuf.h | 3 +- L2_Core/utils/inc/ek_stack.h | 2 +- L2_Core/utils/inc/ek_vec.h | 137 +++++++++++++++++---------------- 7 files changed, 89 insertions(+), 88 deletions(-) diff --git a/L2_Core/utils/inc/ek_def.h b/L2_Core/utils/inc/ek_def.h index 7018af0..c8d0463 100644 --- a/L2_Core/utils/inc/ek_def.h +++ b/L2_Core/utils/inc/ek_def.h @@ -69,7 +69,7 @@ # define __WEAK __weak # define __PACKED __packed # define __PACKED_STRUCT __packed struct -# define __ALIGNED(x) __align(x) +# define __ALIGNED(x) __align((x)) # define __USED __attribute__((used)) # define __SECTION(x) __attribute__((section(x))) # define __NO_RETURN __declspec(noreturn) diff --git a/L2_Core/utils/inc/ek_export.h b/L2_Core/utils/inc/ek_export.h index 2529b9a..fb37170 100644 --- a/L2_Core/utils/inc/ek_export.h +++ b/L2_Core/utils/inc/ek_export.h @@ -54,13 +54,14 @@ typedef void (*_ek_export_init_fn_t)(void); * } * EK_EXPORT(my_init, 10); // 优先级 10 */ -# define EK_EXPORT(fn, prio) \ - const _ek_export_init_fn_t __init_##fn##prio __attribute__((used, section(".ek_export_fn." _EK_STR(prio)))) = fn +# define EK_EXPORT(fn, prio) \ + const _ek_export_init_fn_t __init_##fn##prio __attribute__((used, section(".ek_export_fn." _EK_STR(prio)))) = \ + (fn) -# define EK_EXPORT_HARDWARE(fn) EK_EXPORT(fn, 0) -# define EK_EXPORT_COMPONENTS(fn) EK_EXPORT(fn, 1) -# define EK_EXPORT_APP(fn) EK_EXPORT(fn, 2) -# define EK_EXPORT_USER(fn) EK_EXPORT(fn, 3) +# define EK_EXPORT_HARDWARE(fn) EK_EXPORT((fn), 0) +# define EK_EXPORT_COMPONENTS(fn) EK_EXPORT((fn), 1) +# define EK_EXPORT_APP(fn) EK_EXPORT((fn), 2) +# define EK_EXPORT_USER(fn) EK_EXPORT((fn), 3) #else diff --git a/L2_Core/utils/inc/ek_log.h b/L2_Core/utils/inc/ek_log.h index a89abb0..a754919 100644 --- a/L2_Core/utils/inc/ek_log.h +++ b/L2_Core/utils/inc/ek_log.h @@ -53,7 +53,7 @@ * @example * EK_LOG_FILE_TAG("main.c"); */ -# define EK_LOG_FILE_TAG(tag) static const char *_EK_LOG_TAG_ = tag; +# define EK_LOG_FILE_TAG(tag) static const char *_EK_LOG_TAG_ = (tag); /** * @brief 定义获取时间戳函数 diff --git a/L2_Core/utils/inc/ek_mem.h b/L2_Core/utils/inc/ek_mem.h index 3b91aab..efaff0e 100644 --- a/L2_Core/utils/inc/ek_mem.h +++ b/L2_Core/utils/inc/ek_mem.h @@ -41,7 +41,7 @@ void *_ek_realloc(void *ptr, size_t size); * @retval 分配的内存指针,失败返回 NULL */ #ifndef ek_malloc -# define ek_malloc(size) _ek_malloc(size) +# define ek_malloc(size) _ek_malloc((size)) #endif /** @@ -51,7 +51,7 @@ void *_ek_realloc(void *ptr, size_t size); * @retval 重新分配后的内存指针,失败返回 NULL */ #ifndef ek_realloc -# define ek_realloc(ptr, size) _ek_realloc(ptr, size) +# define ek_realloc(ptr, size) _ek_realloc((ptr), (size)) #endif /** @@ -60,11 +60,11 @@ void *_ek_realloc(void *ptr, size_t size); * @note 释放后指针会被置为 NULL,避免悬空指针 */ #ifndef ek_free -# define ek_free(ptr) \ - do \ - { \ - _ek_free(ptr); \ - ptr = NULL; \ +# define ek_free(ptr) \ + do \ + { \ + _ek_free((ptr)); \ + ptr = NULL; \ } while (0) #endif @@ -109,7 +109,7 @@ extern tlsf_t ek_default_tlsf; * @param size: 内存池大小(字节) */ # ifndef ek_heap_add_pool -# define ek_heap_add_pool(ptr, size) tlsf_add_pool(ek_default_tlsf, ptr, size) +# define ek_heap_add_pool(ptr, size) tlsf_add_pool(ek_default_tlsf, (ptr), (size)) # endif /** @@ -117,7 +117,7 @@ extern tlsf_t ek_default_tlsf; * @param pool: 要移除的内存池指针 */ # ifndef ek_heap_remove_pool -# define ek_heap_remove_pool(pool) tlsf_remove_pool(ek_default_tlsf, pool) +# define ek_heap_remove_pool(pool) tlsf_remove_pool(ek_default_tlsf, (pool)) # endif /** diff --git a/L2_Core/utils/inc/ek_ringbuf.h b/L2_Core/utils/inc/ek_ringbuf.h index 0b513a6..860d1e8 100644 --- a/L2_Core/utils/inc/ek_ringbuf.h +++ b/L2_Core/utils/inc/ek_ringbuf.h @@ -15,7 +15,6 @@ # include "ek_def.h" - /** * @brief 环形缓冲区结构 */ @@ -79,7 +78,7 @@ void ek_ringbuf_destroy(ek_ringbuf_t *rb); # define ek_ringbuf_destroy_safely(rb_ptr) \ do \ { \ - ek_ringbuf_destroy(rb_ptr); \ + ek_ringbuf_destroy((rb_ptr)); \ rb_ptr = NULL; \ } while (0) diff --git a/L2_Core/utils/inc/ek_stack.h b/L2_Core/utils/inc/ek_stack.h index 0c834b7..9555728 100644 --- a/L2_Core/utils/inc/ek_stack.h +++ b/L2_Core/utils/inc/ek_stack.h @@ -102,7 +102,7 @@ void ek_stack_destroy(ek_stack_t *sk); # define ek_stack_destroy_safely(sk_ptr) \ do \ { \ - ek_stack_destroy(sk_ptr); \ + ek_stack_destroy((sk_ptr)); \ sk_ptr = NULL; \ } while (0) diff --git a/L2_Core/utils/inc/ek_vec.h b/L2_Core/utils/inc/ek_vec.h index a08a0e4..119bc99 100644 --- a/L2_Core/utils/inc/ek_vec.h +++ b/L2_Core/utils/inc/ek_vec.h @@ -62,7 +62,7 @@ * * @warning 遍历过程中不能删除元素,否则会导致索引混乱 */ -# define ek_vec_iterate(pos, v) for (pos = 0; pos < v.amount; pos++) +# define ek_vec_iterate(pos, v) for (pos = 0; pos < (v).amount; pos++) /** * @brief 从指定索引开始遍历动态数组 @@ -72,7 +72,8 @@ * * @note 如果 index 超出范围,则从数组末尾开始(不会执行循环体) */ -# define ek_vec_iterate_index(pos, index, v) for (pos = (index < v.amount) ? index : v.amount; pos < v.amount; pos++) +# define ek_vec_iterate_index(pos, index, v) \ + for (pos = ((index) < (v).amount) ? (index) : (v).amount; pos < (v).amount; pos++) /** * @brief 初始化动态数组 @@ -80,12 +81,12 @@ * * @note 使用前必须调用此宏进行初始化 */ -# define ek_vec_init(v) \ - do \ - { \ - v.items = NULL; \ - v.amount = 0; \ - v.cap = 0; \ +# define ek_vec_init(v) \ + do \ + { \ + (v).items = NULL; \ + (v).amount = 0; \ + (v).cap = 0; \ } while (0) /** @@ -95,12 +96,12 @@ * @note 销毁后动态数组变量仍存在,但内容已清空 * @note 如需重新使用,应重新调用 ek_vec_init */ -# define ek_vec_destroy(v) \ - do \ - { \ - ek_free(v.items); \ - v.amount = 0; \ - v.cap = 0; \ +# define ek_vec_destroy(v) \ + do \ + { \ + ek_free((v).items); \ + (v).amount = 0; \ + (v).cap = 0; \ } while (0) /** @@ -111,22 +112,22 @@ * @note 当容量不足时自动扩容 * @note 扩容策略:小数组翻倍,大数组增加 1/2 */ -# define ek_vec_append(v, val) \ - do \ - { \ - if (v.cap <= v.amount) \ - { \ - uint32_t _temp_for_cap_ex_ = \ - (v.cap < VEC_LARGE_THRESHOLD) ? (v.cap ? 2 * v.cap : 8) : (v.cap + v.cap / 2); \ - void *_temp_for_new_items_ = ek_realloc(v.items, _temp_for_cap_ex_ * sizeof(*v.items)); \ - if (_temp_for_new_items_ != NULL) \ - { \ - v.cap = _temp_for_cap_ex_; \ - v.items = _temp_for_new_items_; \ - } \ - else break; \ - } \ - v.items[v.amount++] = val; \ +# define ek_vec_append(v, val) \ + do \ + { \ + if ((v).cap <= (v).amount) \ + { \ + uint32_t _temp_for_cap_ex_ = \ + ((v).cap < VEC_LARGE_THRESHOLD) ? ((v).cap ? 2 * (v).cap : 8) : ((v).cap + (v).cap / 2); \ + void *_temp_for_new_items_ = ek_realloc((v).items, _temp_for_cap_ex_ * sizeof(*(v).items)); \ + if (_temp_for_new_items_ != NULL) \ + { \ + (v).cap = _temp_for_cap_ex_; \ + (v).items = _temp_for_new_items_; \ + } \ + else break; \ + } \ + (v).items[(v).amount++] = (val); \ } while (0) /** @@ -137,17 +138,17 @@ * @note 移除后,后续元素会向前移动填补空位 * @note 如果索引超出范围,则不执行任何操作 */ -# define ek_vec_remove(v, index) \ - do \ - { \ - if (index < v.amount) \ - { \ - for (uint32_t _temp_for_iter_v_ = index; _temp_for_iter_v_ < v.amount - 1; _temp_for_iter_v_++) \ - { \ - v.items[_temp_for_iter_v_] = v.items[_temp_for_iter_v_ + 1]; \ - } \ - v.amount--; \ - } \ +# define ek_vec_remove(v, index) \ + do \ + { \ + if ((index) < (v).amount) \ + { \ + for (uint32_t _temp_for_iter_v_ = (index); _temp_for_iter_v_ < (v).amount - 1; _temp_for_iter_v_++) \ + { \ + (v).items[_temp_for_iter_v_] = (v).items[_temp_for_iter_v_ + 1]; \ + } \ + (v).amount--; \ + } \ } while (0) /** @@ -159,14 +160,14 @@ * @note 时间复杂度:O(1) * @warning 会破坏数组中元素的原始顺序,仅适用于对顺序不敏感的场景 */ -# define ek_vec_remove_unorder(v, index) \ - do \ - { \ - if (index < v.amount) \ - { \ - v.items[index] = v.items[v.amount - 1]; \ - v.amount--; \ - } \ +# define ek_vec_remove_unorder(v, index) \ + do \ + { \ + if ((index) < (v).amount) \ + { \ + (v).items[(index)] = (v).items[(v).amount - 1]; \ + (v).amount--; \ + } \ } while (0) /** @@ -179,7 +180,7 @@ # define ek_vec_clear(v) \ do \ { \ - v.amount = 0; \ + (v).amount = 0; \ } while (0) /** @@ -189,24 +190,24 @@ * @note 将容量缩减为当前元素数量,释放多余内存,如果元素数目为0,则会释放items的所有内存 * @note 如果 realloc 失败,则保持原状态不变 */ -# define ek_vec_shrink(v) \ - do \ - { \ - if (v.amount) \ - { \ - void *_temp_for_new_items_ = ek_realloc(v.items, v.amount * sizeof(*v.items)); \ - if (_temp_for_new_items_) \ - { \ - v.items = _temp_for_new_items_; \ - v.cap = v.amount; \ - } \ - } \ - else if (v.items) \ - { \ - ek_free(v.items); \ - v.items = NULL; \ - v.cap = 0; \ - } \ +# define ek_vec_shrink(v) \ + do \ + { \ + if ((v).amount) \ + { \ + void *_temp_for_new_items_ = ek_realloc((v).items, (v).amount * sizeof(*(v).items)); \ + if (_temp_for_new_items_) \ + { \ + (v).items = _temp_for_new_items_; \ + (v).cap = (v).amount; \ + } \ + } \ + else if ((v).items) \ + { \ + ek_free((v).items); \ + (v).items = NULL; \ + (v).cap = 0; \ + } \ } while (0) #endif /* EK_VEC_ENABLE */