feat(stdlib):add rtthread function to stdlib (#4777)

This commit is contained in:
lhdjply 2023-11-10 20:41:00 +08:00 committed by GitHub
parent 17d1da62af
commit df910893e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 253 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <rtthread.h>
#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*/

View File

@ -0,0 +1,61 @@
/**
* @file lv_sprintf_rtthread.c
*
*/
/*********************
* INCLUDES
*********************/
#include "../../lv_conf_internal.h"
#if LV_USE_STDLIB_SPRINTF == LV_STDLIB_RTTHREAD
#include <rtthread.h>
#include <stdarg.h>
#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*/

View File

@ -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 <rtthread.h>
#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*/