chore: make lv_utils as public and align function prototype with stdlib (#6473)

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
Neo Xu
2024-07-15 22:11:44 +08:00
committed by GitHub
parent 48ce05d71e
commit bf1e6ab39c
10 changed files with 35 additions and 34 deletions

1
lvgl.h
View File

@@ -32,6 +32,7 @@ extern "C" {
#include "src/misc/lv_anim_timeline.h" #include "src/misc/lv_anim_timeline.h"
#include "src/misc/lv_profiler_builtin.h" #include "src/misc/lv_profiler_builtin.h"
#include "src/misc/lv_rb.h" #include "src/misc/lv_rb.h"
#include "src/misc/lv_utils.h"
#include "src/tick/lv_tick.h" #include "src/tick/lv_tick.h"

View File

@@ -142,13 +142,13 @@ lv_prop_id_t lv_obj_property_get_id(const lv_obj_t * obj, const char * name)
continue; continue;
} }
found = _lv_utils_bsearch(name, names, clz->names_count, sizeof(lv_property_name_t), property_name_compare); found = lv_utils_bsearch(name, names, clz->names_count, sizeof(lv_property_name_t), property_name_compare);
if(found) return found->id; if(found) return found->id;
} }
/*Check style property*/ /*Check style property*/
found = _lv_utils_bsearch(name, lv_style_property_names, sizeof(lv_style_property_names) / sizeof(lv_property_name_t), found = lv_utils_bsearch(name, lv_style_property_names, sizeof(lv_style_property_names) / sizeof(lv_property_name_t),
sizeof(lv_property_name_t), property_name_compare); sizeof(lv_property_name_t), property_name_compare);
if(found) return found->id; if(found) return found->id;
#else #else
LV_UNUSED(obj); LV_UNUSED(obj);
@@ -254,7 +254,7 @@ static lv_result_t obj_property(lv_obj_t * obj, lv_prop_id_t id, lv_property_t *
return LV_RESULT_INVALID; return LV_RESULT_INVALID;
} }
static int32_t property_name_compare(const void * ref, const void * element) static int property_name_compare(const void * ref, const void * element)
{ {
const lv_property_name_t * prop = element; const lv_property_name_t * prop = element;
return lv_strcmp(ref, prop->name); return lv_strcmp(ref, prop->name);

View File

@@ -35,9 +35,9 @@ typedef struct {
**********************/ **********************/
static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter); static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter);
static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t gid_right); static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t gid_right);
static int32_t unicode_list_compare(const void * ref, const void * element); static int unicode_list_compare(const void * ref, const void * element);
static int32_t kern_pair_8_compare(const void * ref, const void * element); static int kern_pair_8_compare(const void * ref, const void * element);
static int32_t kern_pair_16_compare(const void * ref, const void * element); static int kern_pair_16_compare(const void * ref, const void * element);
#if LV_USE_FONT_COMPRESSED #if LV_USE_FONT_COMPRESSED
static void decompress(const uint8_t * in, uint8_t * out, int32_t w, int32_t h, uint8_t bpp, bool prefilter); static void decompress(const uint8_t * in, uint8_t * out, int32_t w, int32_t h, uint8_t bpp, bool prefilter);
@@ -236,8 +236,8 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
} }
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) { else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) {
uint16_t key = rcp; uint16_t key = rcp;
uint16_t * p = _lv_utils_bsearch(&key, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, uint16_t * p = lv_utils_bsearch(&key, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length,
sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare);
if(p) { if(p) {
lv_uintptr_t ofs = p - fdsc->cmaps[i].unicode_list; lv_uintptr_t ofs = p - fdsc->cmaps[i].unicode_list;
@@ -246,8 +246,8 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
} }
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) { else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) {
uint16_t key = rcp; uint16_t key = rcp;
uint16_t * p = _lv_utils_bsearch(&key, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, uint16_t * p = lv_utils_bsearch(&key, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length,
sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare);
if(p) { if(p) {
lv_uintptr_t ofs = p - fdsc->cmaps[i].unicode_list; lv_uintptr_t ofs = p - fdsc->cmaps[i].unicode_list;
@@ -277,7 +277,7 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t
*The pairs are ordered left_id first, then right_id secondly.*/ *The pairs are ordered left_id first, then right_id secondly.*/
const uint16_t * g_ids = kdsc->glyph_ids; const uint16_t * g_ids = kdsc->glyph_ids;
kern_pair_ref_t g_id_both = {gid_left, gid_right}; kern_pair_ref_t g_id_both = {gid_left, gid_right};
uint16_t * kid_p = _lv_utils_bsearch(&g_id_both, g_ids, kdsc->pair_cnt, 2, kern_pair_8_compare); uint16_t * kid_p = lv_utils_bsearch(&g_id_both, g_ids, kdsc->pair_cnt, 2, kern_pair_8_compare);
/*If the `g_id_both` were found get its index from the pointer*/ /*If the `g_id_both` were found get its index from the pointer*/
if(kid_p) { if(kid_p) {
@@ -290,7 +290,7 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t
*The pairs are ordered left_id first, then right_id secondly.*/ *The pairs are ordered left_id first, then right_id secondly.*/
const uint32_t * g_ids = kdsc->glyph_ids; const uint32_t * g_ids = kdsc->glyph_ids;
kern_pair_ref_t g_id_both = {gid_left, gid_right}; kern_pair_ref_t g_id_both = {gid_left, gid_right};
uint32_t * kid_p = _lv_utils_bsearch(&g_id_both, g_ids, kdsc->pair_cnt, 4, kern_pair_16_compare); uint32_t * kid_p = lv_utils_bsearch(&g_id_both, g_ids, kdsc->pair_cnt, 4, kern_pair_16_compare);
/*If the `g_id_both` were found get its index from the pointer*/ /*If the `g_id_both` were found get its index from the pointer*/
if(kid_p) { if(kid_p) {
@@ -319,25 +319,24 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t
return value; return value;
} }
static int32_t kern_pair_8_compare(const void * ref, const void * element) static int kern_pair_8_compare(const void * ref, const void * element)
{ {
const kern_pair_ref_t * ref8_p = ref; const kern_pair_ref_t * ref8_p = ref;
const uint8_t * element8_p = element; const uint8_t * element8_p = element;
/*If the MSB is different it will matter. If not return the diff. of the LSB*/ /*If the MSB is different it will matter. If not return the diff. of the LSB*/
if(ref8_p->gid_left != element8_p[0]) return (int32_t) ref8_p->gid_left - element8_p[0]; if(ref8_p->gid_left != element8_p[0]) return ref8_p->gid_left - element8_p[0];
else return (int32_t) ref8_p->gid_right - element8_p[1]; else return ref8_p->gid_right - element8_p[1];
} }
static int32_t kern_pair_16_compare(const void * ref, const void * element) static int kern_pair_16_compare(const void * ref, const void * element)
{ {
const kern_pair_ref_t * ref16_p = ref; const kern_pair_ref_t * ref16_p = ref;
const uint16_t * element16_p = element; const uint16_t * element16_p = element;
/*If the MSB is different it will matter. If not return the diff. of the LSB*/ /*If the MSB is different it will matter. If not return the diff. of the LSB*/
if(ref16_p->gid_left != element16_p[0]) return (int32_t) ref16_p->gid_left - element16_p[0]; if(ref16_p->gid_left != element16_p[0]) return ref16_p->gid_left - element16_p[0];
else return (int32_t) ref16_p->gid_right - element16_p[1]; else return ref16_p->gid_right - element16_p[1];
} }
#if LV_USE_FONT_COMPRESSED #if LV_USE_FONT_COMPRESSED
@@ -550,7 +549,7 @@ static inline uint8_t rle_next(void)
* @retval > 0 Reference is greater than element. * @retval > 0 Reference is greater than element.
* *
*/ */
static int32_t unicode_list_compare(const void * ref, const void * element) static int unicode_list_compare(const void * ref, const void * element)
{ {
return ((int32_t)(*(uint16_t *)ref)) - ((int32_t)(*(uint16_t *)element)); return (*(uint16_t *)ref) - (*(uint16_t *)element);
} }

View File

@@ -41,6 +41,7 @@ extern "C" {
#define LV_DRAW_BUF_DEFINE LV_DRAW_BUF_DEFINE_STATIC #define LV_DRAW_BUF_DEFINE LV_DRAW_BUF_DEFINE_STATIC
#define _lv_utils_bsearch lv_utils_bsearch
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/

View File

@@ -35,8 +35,8 @@
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, void * lv_utils_bsearch(const void * key, const void * base, size_t n, size_t size,
int32_t (*cmp)(const void * pRef, const void * pElement)) int (*cmp)(const void * pRef, const void * pElement))
{ {
const char * middle; const char * middle;
int32_t c; int32_t c;

View File

@@ -46,8 +46,8 @@ extern "C" {
* *
* @return a pointer to a matching item, or NULL if none exists. * @return a pointer to a matching item, or NULL if none exists.
*/ */
void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, void * lv_utils_bsearch(const void * key, const void * base, size_t n, size_t size,
int32_t (*cmp)(const void * pRef, const void * pElement)); int (*cmp)(const void * pRef, const void * pElement));
/** /**
* Save a draw buf to a file * Save a draw buf to a file

View File

@@ -171,7 +171,7 @@ void * LV_ATTRIBUTE_FAST_MEM lv_memmove(void * dst, const void * src, size_t len
return dst; return dst;
} }
int32_t lv_memcmp(const void * p1, const void * p2, size_t len) int lv_memcmp(const void * p1, const void * p2, size_t len)
{ {
const char * s1 = (const char *) p1; const char * s1 = (const char *) p1;
const char * s2 = (const char *) p2; const char * s2 = (const char *) p2;
@@ -223,7 +223,7 @@ char * lv_strcpy(char * dst, const char * src)
return tmp; return tmp;
} }
int32_t lv_strcmp(const char * s1, const char * s2) int lv_strcmp(const char * s1, const char * s2)
{ {
while(*s1 && (*s1 == *s2)) { while(*s1 && (*s1 == *s2)) {
s1++; s1++;

View File

@@ -50,7 +50,7 @@ void * LV_ATTRIBUTE_FAST_MEM lv_memmove(void * dst, const void * src, size_t len
return memmove(dst, src, len); return memmove(dst, src, len);
} }
int32_t lv_memcmp(const void * p1, const void * p2, size_t len) int lv_memcmp(const void * p1, const void * p2, size_t len)
{ {
return memcmp(p1, p2, len); return memcmp(p1, p2, len);
} }
@@ -81,7 +81,7 @@ char * lv_strcpy(char * dst, const char * src)
return strcpy(dst, src); return strcpy(dst, src);
} }
int32_t lv_strcmp(const char * s1, const char * s2) int lv_strcmp(const char * s1, const char * s2)
{ {
return strcmp(s1, s2); return strcmp(s1, s2);
} }

View File

@@ -63,7 +63,7 @@ void * lv_memmove(void * dst, const void * src, size_t len);
* @param len Number of bytes to compare * @param len Number of bytes to compare
* @return The difference between the value of the first unmatching byte. * @return The difference between the value of the first unmatching byte.
*/ */
int32_t lv_memcmp(const void * p1, const void * p2, size_t len); int lv_memcmp(const void * p1, const void * p2, size_t len);
/** /**
* Same as `memset(dst, 0x00, len)`. * Same as `memset(dst, 0x00, len)`.
@@ -117,7 +117,7 @@ char * lv_strcpy(char * dst, const char * src);
* @param s2 pointer to the second string * @param s2 pointer to the second string
* @return the difference between the value of the first unmatching character. * @return the difference between the value of the first unmatching character.
*/ */
int32_t lv_strcmp(const char * s1, const char * s2); int lv_strcmp(const char * s1, const char * s2);
/** /**
* @brief Duplicate a string by allocating a new one and copying the content. * @brief Duplicate a string by allocating a new one and copying the content.

View File

@@ -55,7 +55,7 @@ size_t lv_strlen(const char * str)
return rt_strlen(str); return rt_strlen(str);
} }
int32_t lv_memcmp(const void * p1, const void * p2, size_t len) int lv_memcmp(const void * p1, const void * p2, size_t len)
{ {
return rt_memcmp(p1, p2, len); return rt_memcmp(p1, p2, len);
} }
@@ -81,7 +81,7 @@ char * lv_strcpy(char * dst, const char * src)
return rt_strcpy(dst, src); return rt_strcpy(dst, src);
} }
int32_t lv_strcmp(const char * s1, const char * s2) int lv_strcmp(const char * s1, const char * s2)
{ {
return rt_strcmp(s1, s2); return rt_strcmp(s1, s2);
} }