diff --git a/lv_conf_template.h b/lv_conf_template.h index 817131510..562400dc8 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -34,6 +34,7 @@ * - LV_STDLIB_BUILTIN: LVGL's built in implementation * - LV_STDLIB_CLIB: Standard C functions, like malloc, strlen, etc * - LV_STDLIB_MICROPYTHON: MicroPython implementation + * - LV_STDLIB_RTTHREAD: RT-Thread implementation * - LV_STDLIB_CUSTOM: Implement the functions externally */ #define LV_USE_STDLIB_MALLOC LV_STDLIB_BUILTIN diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 624fa2dcd..c18c3f1bd 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -78,6 +78,7 @@ * - LV_STDLIB_BUILTIN: LVGL's built in implementation * - LV_STDLIB_CLIB: Standard C functions, like malloc, strlen, etc * - LV_STDLIB_MICROPYTHON: MicroPython implementation + * - LV_STDLIB_RTTHREAD: RT-Thread implementation * - LV_STDLIB_CUSTOM: Implement the functions externally */ #ifndef LV_USE_STDLIB_MALLOC diff --git a/src/lv_conf_kconfig.h b/src/lv_conf_kconfig.h index dd6e4d379..fa4627c95 100644 --- a/src/lv_conf_kconfig.h +++ b/src/lv_conf_kconfig.h @@ -33,6 +33,8 @@ extern "C" { # define CONFIG_LV_USE_STDLIB_MALLOC LV_STDLIB_BUILTIN #elif defined(CONFIG_LV_USE_CLIB_MALLOC) # define CONFIG_LV_USE_STDLIB_MALLOC LV_STDLIB_CLIB +#elif defined(CONFIG_LV_USE_RTTHREAD_MALLOC) +# define CONFIG_LV_USE_STDLIB_MALLOC LV_STDLIB_RTTHREAD #elif defined (CONFIG_LV_USE_CUSTOM_MALLOC) # define CONFIG_LV_USE_STDLIB_MALLOC LV_STDLIB_CUSTOM #endif @@ -45,6 +47,8 @@ extern "C" { # define CONFIG_LV_USE_STDLIB_STRING LV_STDLIB_BUILTIN #elif defined(CONFIG_LV_USE_CLIB_STRING) # define CONFIG_LV_USE_STDLIB_STRING LV_STDLIB_CLIB +#elif defined(CONFIG_LV_USE_RTTHREAD_STRING) +# define CONFIG_LV_USE_STDLIB_STRING LV_STDLIB_RTTHREAD #elif defined (CONFIG_LV_USE_CUSTOM_STRING) # define CONFIG_LV_USE_STDLIB_STRING LV_STDLIB_CUSTOM #endif @@ -57,6 +61,8 @@ extern "C" { # define CONFIG_LV_USE_STDLIB_SPRINTF LV_STDLIB_BUILTIN #elif defined(CONFIG_LV_USE_CLIB_SPRINTF) # define CONFIG_LV_USE_STDLIB_SPRINTF LV_STDLIB_CLIB +#elif defined(CONFIG_LV_USE_RTTHREAD_SPRINTF) +# define CONFIG_LV_USE_STDLIB_SPRINTF LV_STDLIB_RTTHREAD #elif defined (CONFIG_LV_USE_CUSTOM_SPRINTF) # define CONFIG_LV_USE_STDLIB_SPRINTF LV_STDLIB_CUSTOM #endif diff --git a/src/misc/lv_types.h b/src/misc/lv_types.h index 05a247bab..c6271180e 100644 --- a/src/misc/lv_types.h +++ b/src/misc/lv_types.h @@ -43,6 +43,7 @@ extern "C" { #define LV_STDLIB_BUILTIN 0 #define LV_STDLIB_CLIB 1 #define LV_STDLIB_MICROPYTHON 2 +#define LV_STDLIB_RTTHREAD 3 #define LV_STDLIB_CUSTOM 255 #define LV_DRAW_SW_ASM_NONE 0 diff --git a/src/stdlib/rtthread/lv_mem_core_rtthread.c b/src/stdlib/rtthread/lv_mem_core_rtthread.c new file mode 100644 index 000000000..8e1f6fd26 --- /dev/null +++ b/src/stdlib/rtthread/lv_mem_core_rtthread.c @@ -0,0 +1,98 @@ +/** + * @file lv_malloc_core_rtthread.c + */ + +/********************* + * INCLUDES + *********************/ +#include "../lv_mem.h" +#if LV_USE_STDLIB_MALLOC == LV_STDLIB_RTTHREAD +#include "../../stdlib/lv_mem.h" +#include + +#ifndef RT_USING_HEAP + #error "lv_mem_core_rtthread: RT_USING_HEAP is required. Define it in rtconfig.h" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +void lv_mem_init(void) +{ + return; /*Nothing to init*/ +} + +void lv_mem_deinit(void) +{ + return; /*Nothing to deinit*/ +} + +lv_mem_pool_t lv_mem_add_pool(void * mem, size_t bytes) +{ + /*Not supported*/ + LV_UNUSED(mem); + LV_UNUSED(bytes); + return NULL; +} + +void lv_mem_remove_pool(lv_mem_pool_t pool) +{ + /*Not supported*/ + LV_UNUSED(pool); + return; +} + +void * lv_malloc_core(size_t size) +{ + return rt_malloc(size); +} + +void * lv_realloc_core(void * p, size_t new_size) +{ + return rt_realloc(p, new_size); +} + +void lv_free_core(void * p) +{ + rt_free(p); +} + +void lv_mem_monitor_core(lv_mem_monitor_t * mon_p) +{ + /*Not supported*/ + LV_UNUSED(mon_p); + return; +} + +lv_result_t lv_mem_test_core(void) +{ + /*Not supported*/ + return LV_RESULT_OK; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*LV_USE_STDLIB_MALLOC*/ diff --git a/src/stdlib/rtthread/lv_sprintf_rtthread.c b/src/stdlib/rtthread/lv_sprintf_rtthread.c new file mode 100644 index 000000000..835269dd3 --- /dev/null +++ b/src/stdlib/rtthread/lv_sprintf_rtthread.c @@ -0,0 +1,61 @@ +/** + * @file lv_sprintf_rtthread.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "../../lv_conf_internal.h" +#if LV_USE_STDLIB_SPRINTF == LV_STDLIB_RTTHREAD +#include +#include +#include "../lv_sprintf.h" + +#if LV_USE_FLOAT == 1 + #warning "lv_sprintf_rtthread: rtthread not support float in sprintf" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +int lv_snprintf(char * buffer, size_t count, const char * format, ...) +{ + va_list va; + va_start(va, format); + const int ret = rt_vsnprintf(buffer, count, format, va); + va_end(va); + return ret; +} + +int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va) +{ + return rt_vsnprintf(buffer, count, format, va); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*LV_USE_STDLIB_SPRINTF*/ diff --git a/src/stdlib/rtthread/lv_string_rtthread.c b/src/stdlib/rtthread/lv_string_rtthread.c new file mode 100644 index 000000000..8b23922ab --- /dev/null +++ b/src/stdlib/rtthread/lv_string_rtthread.c @@ -0,0 +1,85 @@ +/** + * @file lv_string_rtthread.c + */ + +/********************* + * INCLUDES + *********************/ +#include "../../lv_conf_internal.h" +#if LV_USE_STDLIB_STRING == LV_STDLIB_RTTHREAD +#include "../lv_string.h" +#include + +#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN + #include "../lv_mem.h" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len) +{ + return rt_memcpy(dst, src, len); +} + +LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len) +{ + rt_memset(dst, v, len); +} + +size_t lv_strlen(const char * str) +{ + return rt_strlen(str); +} + +char * lv_strncpy(char * dst, const char * src, size_t dest_size) +{ + return rt_strncpy(dst, src, dest_size); +} + +char * lv_strcpy(char * dst, const char * src) +{ + return rt_strcpy(dst, src); +} + +char * lv_strdup(const char * src) +{ + /*strdup uses malloc, so use the built in malloc if it's enabled */ +#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN + size_t len = lv_strlen(src) + 1; + char * dst = lv_malloc(len); + if(dst == NULL) return NULL; + + lv_memcpy(dst, src, len); /*do memcpy is faster than strncpy when length is known*/ + return dst; +#else + return rt_strdup(src); +#endif +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*LV_USE_STDLIB_STRING*/