Uploading the first files

This commit is contained in:
carterCE10 committed 2026-07-20 15:08:43 -04:00
commit eab3a5dd48
356 files changed
+78694

No files matched your search

+484
View File
@@ -0,0 +1,484 @@
/**
* @file lv_anim.h
*
*/
#ifndef LV_ANIM_H
#define LV_ANIM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
/*********************
* DEFINES
*********************/
#define LV_ANIM_REPEAT_INFINITE 0xFFFF
#define LV_ANIM_PLAYTIME_INFINITE 0xFFFFFFFF
LV_EXPORT_CONST_INT(LV_ANIM_REPEAT_INFINITE);
LV_EXPORT_CONST_INT(LV_ANIM_PLAYTIME_INFINITE);
/**********************
* TYPEDEFS
**********************/
/** Can be used to indicate if animations are enabled or disabled in a case*/
typedef enum {
LV_ANIM_OFF,
LV_ANIM_ON,
} lv_anim_enable_t;
struct _lv_anim_t;
struct _lv_timer_t;
/** Get the current value during an animation*/
typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *);
/** Generic prototype of "animator" functions.
* First parameter is the variable to animate.
* Second parameter is the value to set.
* Compatible with `lv_xxx_set_yyy(obj, value)` functions
* The `x` in `_xcb_t` means it's not a fully generic prototype because
* it doesn't receive `lv_anim_t *` as its first argument*/
typedef void (*lv_anim_exec_xcb_t)(void *, int32_t);
/** Same as `lv_anim_exec_xcb_t` but receives `lv_anim_t *` as the first parameter.
* It's more consistent but less convenient. Might be used by binding generator functions.*/
typedef void (*lv_anim_custom_exec_cb_t)(struct _lv_anim_t *, int32_t);
/** Callback to call when the animation is ready*/
typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *);
/** Callback to call when the animation really stars (considering `delay`)*/
typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *);
/** Callback used when the animation values are relative to get the current value*/
typedef int32_t (*lv_anim_get_value_cb_t)(struct _lv_anim_t *);
/** Callback used when the animation is deleted*/
typedef void (*lv_anim_deleted_cb_t)(struct _lv_anim_t *);
/** Describes an animation*/
typedef struct _lv_anim_t {
void * var; /**<Variable to animate*/
lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/
lv_anim_start_cb_t start_cb; /**< Call it when the animation is starts (considering `delay`)*/
lv_anim_ready_cb_t ready_cb; /**< Call it when the animation is ready*/
lv_anim_deleted_cb_t deleted_cb; /**< Call it when the animation is deleted*/
lv_anim_get_value_cb_t get_value_cb; /**< Get the current value in relative mode*/
#if LV_USE_USER_DATA
void * user_data; /**< Custom user data*/
#endif
lv_anim_path_cb_t path_cb; /**< Describe the path (curve) of animations*/
int32_t start_value; /**< Start value*/
int32_t current_value; /**< Current value*/
int32_t end_value; /**< End value*/
int32_t time; /**< Animation time in ms*/
int32_t act_time; /**< Current time in animation. Set to negative to make delay.*/
uint32_t playback_delay; /**< Wait before play back*/
uint32_t playback_time; /**< Duration of playback animation*/
uint32_t repeat_delay; /**< Wait before repeat*/
uint16_t repeat_cnt; /**< Repeat count for the animation*/
uint8_t early_apply : 1; /**< 1: Apply start value immediately even is there is `delay`*/
/*Animation system use these - user shouldn't set*/
uint8_t playback_now : 1; /**< Play back is in progress*/
uint8_t run_round : 1; /**< Indicates the animation has run in this round*/
uint8_t start_cb_called : 1; /**< Indicates that the `start_cb` was already called*/
} lv_anim_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init. the animation module
*/
void _lv_anim_core_init(void);
/**
* Initialize an animation variable.
* E.g.:
* lv_anim_t a;
* lv_anim_init(&a);
* lv_anim_set_...(&a);
* lv_anim_start(&a);
* @param a pointer to an `lv_anim_t` variable to initialize
*/
void lv_anim_init(lv_anim_t * a);
/**
* Set a variable to animate
* @param a pointer to an initialized `lv_anim_t` variable
* @param var pointer to a variable to animate
*/
static inline void lv_anim_set_var(lv_anim_t * a, void * var)
{
a->var = var;
}
/**
* Set a function to animate `var`
* @param a pointer to an initialized `lv_anim_t` variable
* @param exec_cb a function to execute during animation
* LVGL's built-in functions can be used.
* E.g. lv_obj_set_x
*/
static inline void lv_anim_set_exec_cb(lv_anim_t * a, lv_anim_exec_xcb_t exec_cb)
{
a->exec_cb = exec_cb;
}
/**
* Set the duration of an animation
* @param a pointer to an initialized `lv_anim_t` variable
* @param duration duration of the animation in milliseconds
*/
static inline void lv_anim_set_time(lv_anim_t * a, uint32_t duration)
{
a->time = duration;
}
/**
* Set a delay before starting the animation
* @param a pointer to an initialized `lv_anim_t` variable
* @param delay delay before the animation in milliseconds
*/
static inline void lv_anim_set_delay(lv_anim_t * a, uint32_t delay)
{
a->act_time = -(int32_t)(delay);
}
/**
* Set the start and end values of an animation
* @param a pointer to an initialized `lv_anim_t` variable
* @param start the start value
* @param end the end value
*/
static inline void lv_anim_set_values(lv_anim_t * a, int32_t start, int32_t end)
{
a->start_value = start;
a->current_value = start;
a->end_value = end;
}
/**
* Similar to `lv_anim_set_exec_cb` but `lv_anim_custom_exec_cb_t` receives
* `lv_anim_t * ` as its first parameter instead of `void *`.
* This function might be used when LVGL is bound to other languages because
* it's more consistent to have `lv_anim_t *` as first parameter.
* The variable to animate can be stored in the animation's `user_data`
* @param a pointer to an initialized `lv_anim_t` variable
* @param exec_cb a function to execute.
*/
static inline void lv_anim_set_custom_exec_cb(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
{
a->var = a;
a->exec_cb = (lv_anim_exec_xcb_t)exec_cb;
}
/**
* Set the path (curve) of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param path_cb a function to set the current value of the animation.
*/
static inline void lv_anim_set_path_cb(lv_anim_t * a, lv_anim_path_cb_t path_cb)
{
a->path_cb = path_cb;
}
/**
* Set a function call when the animation really starts (considering `delay`)
* @param a pointer to an initialized `lv_anim_t` variable
* @param start_cb a function call when the animation starts
*/
static inline void lv_anim_set_start_cb(lv_anim_t * a, lv_anim_start_cb_t start_cb)
{
a->start_cb = start_cb;
}
/**
* Set a function to use the current value of the variable and make start and end value
* relative to the returned current value.
* @param a pointer to an initialized `lv_anim_t` variable
* @param get_value_cb a function call when the animation starts
*/
static inline void lv_anim_set_get_value_cb(lv_anim_t * a, lv_anim_get_value_cb_t get_value_cb)
{
a->get_value_cb = get_value_cb;
}
/**
* Set a function call when the animation is ready
* @param a pointer to an initialized `lv_anim_t` variable
* @param ready_cb a function call when the animation is ready
*/
static inline void lv_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_cb)
{
a->ready_cb = ready_cb;
}
/**
* Set a function call when the animation is deleted.
* @param a pointer to an initialized `lv_anim_t` variable
* @param deleted_cb a function call when the animation is deleted
*/
static inline void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb)
{
a->deleted_cb = deleted_cb;
}
/**
* Make the animation to play back to when the forward direction is ready
* @param a pointer to an initialized `lv_anim_t` variable
* @param time the duration of the playback animation in milliseconds. 0: disable playback
*/
static inline void lv_anim_set_playback_time(lv_anim_t * a, uint32_t time)
{
a->playback_time = time;
}
/**
* Make the animation to play back to when the forward direction is ready
* @param a pointer to an initialized `lv_anim_t` variable
* @param delay delay in milliseconds before starting the playback animation.
*/
static inline void lv_anim_set_playback_delay(lv_anim_t * a, uint32_t delay)
{
a->playback_delay = delay;
}
/**
* Make the animation repeat itself.
* @param a pointer to an initialized `lv_anim_t` variable
* @param cnt repeat count or `LV_ANIM_REPEAT_INFINITE` for infinite repetition. 0: to disable repetition.
*/
static inline void lv_anim_set_repeat_count(lv_anim_t * a, uint16_t cnt)
{
a->repeat_cnt = cnt;
}
/**
* Set a delay before repeating the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param delay delay in milliseconds before repeating the animation.
*/
static inline void lv_anim_set_repeat_delay(lv_anim_t * a, uint32_t delay)
{
a->repeat_delay = delay;
}
/**
* Set a whether the animation's should be applied immediately or only when the delay expired.
* @param a pointer to an initialized `lv_anim_t` variable
* @param en true: apply the start value immediately in `lv_anim_start`;
* false: apply the start value only when `delay` ms is elapsed and the animations really starts
*/
static inline void lv_anim_set_early_apply(lv_anim_t * a, bool en)
{
a->early_apply = en;
}
/**
* Set the custom user data field of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param user_data pointer to the new user_data.
*/
#if LV_USE_USER_DATA
static inline void lv_anim_set_user_data(lv_anim_t * a, void * user_data)
{
a->user_data = user_data;
}
#endif
/**
* Create an animation
* @param a an initialized 'anim_t' variable. Not required after call.
* @return pointer to the created animation (different from the `a` parameter)
*/
lv_anim_t * lv_anim_start(const lv_anim_t * a);
/**
* Get a delay before starting the animation
* @param a pointer to an initialized `lv_anim_t` variable
* @return delay before the animation in milliseconds
*/
static inline uint32_t lv_anim_get_delay(lv_anim_t * a)
{
return -a->act_time;
}
/**
* Get the time used to play the animation.
* @param a pointer to an animation.
* @return the play time in milliseconds.
*/
uint32_t lv_anim_get_playtime(lv_anim_t * a);
/**
* Get the user_data field of the animation
* @param a pointer to an initialized `lv_anim_t` variable
* @return the pointer to the custom user_data of the animation
*/
#if LV_USE_USER_DATA
static inline void * lv_anim_get_user_data(lv_anim_t * a)
{
return a->user_data;
}
#endif
/**
* Delete an animation of a variable with a given animator function
* @param var pointer to variable
* @param exec_cb a function pointer which is animating 'var',
* or NULL to ignore it and delete all the animations of 'var
* @return true: at least 1 animation is deleted, false: no animation is deleted
*/
bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb);
/**
* Delete all the animations
*/
void lv_anim_del_all(void);
/**
* Get the animation of a variable and its `exec_cb`.
* @param var pointer to variable
* @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var'
* @return pointer to the animation.
*/
lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb);
/**
* Get global animation refresher timer.
* @return pointer to the animation refresher timer.
*/
struct _lv_timer_t * lv_anim_get_timer(void);
/**
* Delete an animation by getting the animated variable from `a`.
* Only animations with `exec_cb` will be deleted.
* This function exists because it's logical that all anim. functions receives an
* `lv_anim_t` as their first parameter. It's not practical in C but might make
* the API more consequent and makes easier to generate bindings.
* @param a pointer to an animation.
* @param exec_cb a function pointer which is animating 'var',
* or NULL to ignore it and delete all the animations of 'var
* @return true: at least 1 animation is deleted, false: no animation is deleted
*/
static inline bool lv_anim_custom_del(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
{
return lv_anim_del(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb);
}
/**
* Get the animation of a variable and its `exec_cb`.
* This function exists because it's logical that all anim. functions receives an
* `lv_anim_t` as their first parameter. It's not practical in C but might make
* the API more consequent and makes easier to generate bindings.
* @param a pointer to an animation.
* @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var'
* @return pointer to the animation.
*/
static inline lv_anim_t * lv_anim_custom_get(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
{
return lv_anim_get(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb);
}
/**
* Get the number of currently running animations
* @return the number of running animations
*/
uint16_t lv_anim_count_running(void);
/**
* Calculate the time of an animation with a given speed and the start and end values
* @param speed speed of animation in unit/sec
* @param start start value of the animation
* @param end end value of the animation
* @return the required time [ms] for the animation with the given parameters
*/
uint32_t lv_anim_speed_to_time(uint32_t speed, int32_t start, int32_t end);
/**
* Manually refresh the state of the animations.
* Useful to make the animations running in a blocking process where
* `lv_timer_handler` can't run for a while.
* Shouldn't be used directly because it is called in `lv_refr_now()`.
*/
void lv_anim_refr_now(void);
/**
* Calculate the current value of an animation applying linear characteristic
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_linear(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the start phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the end phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying an "S" characteristic (cosine)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation with overshoot at the end
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
/**
* Calculate the current value of an animation with 3 bounces
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_bounce(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying step characteristic.
* (Set end value on the end of the animation)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_step(const lv_anim_t * a);
/**********************
* GLOBAL VARIABLES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ANIM_H*/
+103
View File
@@ -0,0 +1,103 @@
/**
* @file lv_anim_timeline.h
*
*/
#ifndef LV_ANIM_TIMELINE_H
#define LV_ANIM_TIMELINE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_anim.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct _lv_anim_timeline_t;
typedef struct _lv_anim_timeline_t lv_anim_timeline_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create an animation timeline.
* @return pointer to the animation timeline.
*/
lv_anim_timeline_t * lv_anim_timeline_create(void);
/**
* Delete animation timeline.
* @param at pointer to the animation timeline.
*/
void lv_anim_timeline_del(lv_anim_timeline_t * at);
/**
* Add animation to the animation timeline.
* @param at pointer to the animation timeline.
* @param start_time the time the animation started on the timeline, note that start_time will override the value of delay.
* @param a pointer to an animation.
*/
void lv_anim_timeline_add(lv_anim_timeline_t * at, uint32_t start_time, lv_anim_t * a);
/**
* Start the animation timeline.
* @param at pointer to the animation timeline.
* @return total time spent in animation timeline.
*/
uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at);
/**
* Stop the animation timeline.
* @param at pointer to the animation timeline.
*/
void lv_anim_timeline_stop(lv_anim_timeline_t * at);
/**
* Set the playback direction of the animation timeline.
* @param at pointer to the animation timeline.
* @param reverse whether to play in reverse.
*/
void lv_anim_timeline_set_reverse(lv_anim_timeline_t * at, bool reverse);
/**
* Set the progress of the animation timeline.
* @param at pointer to the animation timeline.
* @param progress set value 0~65535 to map 0~100% animation progress.
*/
void lv_anim_timeline_set_progress(lv_anim_timeline_t * at, uint16_t progress);
/**
* Get the time used to play the animation timeline.
* @param at pointer to the animation timeline.
* @return total time spent in animation timeline.
*/
uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at);
/**
* Get whether the animation timeline is played in reverse.
* @param at pointer to the animation timeline.
* @return return true if it is reverse playback.
*/
bool lv_anim_timeline_get_reverse(lv_anim_timeline_t * at);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ANIM_TIMELINE_H*/
+295
View File
@@ -0,0 +1,295 @@
/**
* @file lv_area.h
*
*/
#ifndef LV_AREA_H
#define LV_AREA_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdbool.h>
#include <stdint.h>
/*********************
* DEFINES
*********************/
#if LV_USE_LARGE_COORD
typedef int32_t lv_coord_t;
#else
typedef int16_t lv_coord_t;
#endif
/**********************
* TYPEDEFS
**********************/
/**
* Represents a point on the screen.
*/
typedef struct {
lv_coord_t x;
lv_coord_t y;
} lv_point_t;
/** Represents an area of the screen.*/
typedef struct {
lv_coord_t x1;
lv_coord_t y1;
lv_coord_t x2;
lv_coord_t y2;
} lv_area_t;
/** Alignments*/
enum {
LV_ALIGN_DEFAULT = 0,
LV_ALIGN_TOP_LEFT,
LV_ALIGN_TOP_MID,
LV_ALIGN_TOP_RIGHT,
LV_ALIGN_BOTTOM_LEFT,
LV_ALIGN_BOTTOM_MID,
LV_ALIGN_BOTTOM_RIGHT,
LV_ALIGN_LEFT_MID,
LV_ALIGN_RIGHT_MID,
LV_ALIGN_CENTER,
LV_ALIGN_OUT_TOP_LEFT,
LV_ALIGN_OUT_TOP_MID,
LV_ALIGN_OUT_TOP_RIGHT,
LV_ALIGN_OUT_BOTTOM_LEFT,
LV_ALIGN_OUT_BOTTOM_MID,
LV_ALIGN_OUT_BOTTOM_RIGHT,
LV_ALIGN_OUT_LEFT_TOP,
LV_ALIGN_OUT_LEFT_MID,
LV_ALIGN_OUT_LEFT_BOTTOM,
LV_ALIGN_OUT_RIGHT_TOP,
LV_ALIGN_OUT_RIGHT_MID,
LV_ALIGN_OUT_RIGHT_BOTTOM,
};
typedef uint8_t lv_align_t;
enum {
LV_DIR_NONE = 0x00,
LV_DIR_LEFT = (1 << 0),
LV_DIR_RIGHT = (1 << 1),
LV_DIR_TOP = (1 << 2),
LV_DIR_BOTTOM = (1 << 3),
LV_DIR_HOR = LV_DIR_LEFT | LV_DIR_RIGHT,
LV_DIR_VER = LV_DIR_TOP | LV_DIR_BOTTOM,
LV_DIR_ALL = LV_DIR_HOR | LV_DIR_VER,
};
typedef uint8_t lv_dir_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize an area
* @param area_p pointer to an area
* @param x1 left coordinate of the area
* @param y1 top coordinate of the area
* @param x2 right coordinate of the area
* @param y2 bottom coordinate of the area
*/
void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2);
/**
* Copy an area
* @param dest pointer to the destination area
* @param src pointer to the source area
*/
inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
{
dest->x1 = src->x1;
dest->y1 = src->y1;
dest->x2 = src->x2;
dest->y2 = src->y2;
}
/**
* Get the width of an area
* @param area_p pointer to an area
* @return the width of the area (if x1 == x2 -> width = 1)
*/
static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p)
{
return (lv_coord_t)(area_p->x2 - area_p->x1 + 1);
}
/**
* Get the height of an area
* @param area_p pointer to an area
* @return the height of the area (if y1 == y2 -> height = 1)
*/
static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p)
{
return (lv_coord_t)(area_p->y2 - area_p->y1 + 1);
}
/**
* Set the width of an area
* @param area_p pointer to an area
* @param w the new width of the area (w == 1 makes x1 == x2)
*/
void lv_area_set_width(lv_area_t * area_p, lv_coord_t w);
/**
* Set the height of an area
* @param area_p pointer to an area
* @param h the new height of the area (h == 1 makes y1 == y2)
*/
void lv_area_set_height(lv_area_t * area_p, lv_coord_t h);
/**
* Set the position of an area (width and height will be kept)
* @param area_p pointer to an area
* @param x the new x coordinate of the area
* @param y the new y coordinate of the area
*/
void _lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y);
/**
* Return with area of an area (x * y)
* @param area_p pointer to an area
* @return size of area
*/
uint32_t lv_area_get_size(const lv_area_t * area_p);
void lv_area_increase(lv_area_t * area, lv_coord_t w_extra, lv_coord_t h_extra);
void lv_area_move(lv_area_t * area, lv_coord_t x_ofs, lv_coord_t y_ofs);
/**
* Get the common parts of two areas
* @param res_p pointer to an area, the result will be stored her
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return false: the two area has NO common parts, res_p is invalid
*/
bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Join two areas into a third which involves the other two
* @param res_p pointer to an area, the result will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
*/
void _lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Check if a point is on an area
* @param a_p pointer to an area
* @param p_p pointer to a point
* @param radius radius of area (e.g. for rounded rectangle)
* @return false:the point is out of the area
*/
bool _lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius);
/**
* Check if two area has common parts
* @param a1_p pointer to an area.
* @param a2_p pointer to an other area
* @return false: a1_p and a2_p has no common parts
*/
bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Check if an area is fully on an other
* @param ain_p pointer to an area which could be in 'aholder_p'
* @param aholder_p pointer to an area which could involve 'ain_p'
* @param radius radius of `aholder_p` (e.g. for rounded rectangle)
* @return true: `ain_p` is fully inside `aholder_p`
*/
bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius);
/**
* Check if an area is fully out of an other
* @param aout_p pointer to an area which could be in 'aholder_p'
* @param aholder_p pointer to an area which could involve 'ain_p'
* @param radius radius of `aholder_p` (e.g. for rounded rectangle)
* @return true: `aout_p` is fully outside `aholder_p`
*/
bool _lv_area_is_out(const lv_area_t * aout_p, const lv_area_t * aholder_p, lv_coord_t radius);
/**
* Check if 2 area is the same
* @param a pointer to an area
* @param b pointer to another area
*/
bool _lv_area_is_equal(const lv_area_t * a, const lv_area_t * b);
/**
* Align an area to an other
* @param base an are where the other will be aligned
* @param to_align the area to align
* @param align `LV_ALIGN_...`
*/
void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t align, lv_coord_t ofs_x, lv_coord_t ofs_y);
void lv_point_transform(lv_point_t * p, int32_t angle, int32_t zoom, const lv_point_t * pivot);
/**********************
* MACROS
**********************/
#if LV_USE_LARGE_COORD
#define _LV_COORD_TYPE_SHIFT (29U)
#else
#define _LV_COORD_TYPE_SHIFT (13U)
#endif
#define _LV_COORD_TYPE_MASK (3 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE(x) ((x) & _LV_COORD_TYPE_MASK) /*Extract type specifiers*/
#define _LV_COORD_PLAIN(x) ((x) & ~_LV_COORD_TYPE_MASK) /*Remove type specifiers*/
#define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_PX_NEG (3 << _LV_COORD_TYPE_SHIFT)
#define LV_COORD_IS_PX(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX || \
_LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX_NEG ? true : false)
#define LV_COORD_IS_SPEC(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_SPEC ? true : false)
#define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC)
/*Special coordinates*/
#define LV_PCT(x) (x < 0 ? LV_COORD_SET_SPEC(1000 - (x)) : LV_COORD_SET_SPEC(x))
#define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 2000) ? true : false)
#define LV_COORD_GET_PCT(x) (_LV_COORD_PLAIN(x) > 1000 ? 1000 - _LV_COORD_PLAIN(x) : _LV_COORD_PLAIN(x))
#define LV_SIZE_CONTENT LV_COORD_SET_SPEC(2001)
LV_EXPORT_CONST_INT(LV_SIZE_CONTENT);
/*Max coordinate value*/
#define LV_COORD_MAX ((1 << _LV_COORD_TYPE_SHIFT) - 1)
#define LV_COORD_MIN (-LV_COORD_MAX)
LV_EXPORT_CONST_INT(LV_COORD_MAX);
LV_EXPORT_CONST_INT(LV_COORD_MIN);
/**
* Convert a percentage value to `lv_coord_t`.
* Percentage values are stored in special range
* @param x the percentage (0..1000)
* @return a coordinate that stores the percentage
*/
static inline lv_coord_t lv_pct(lv_coord_t x)
{
return LV_PCT(x);
}
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
+79
View File
@@ -0,0 +1,79 @@
/**
* @file lv_assert.h
*
*/
#ifndef LV_ASSERT_H
#define LV_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include "lv_log.h"
#include "lv_mem.h"
#include LV_ASSERT_HANDLER_INCLUDE
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#define LV_ASSERT(expr) \
do { \
if(!(expr)) { \
LV_LOG_ERROR("Asserted at expression: %s", #expr); \
LV_ASSERT_HANDLER \
} \
} while(0)
#define LV_ASSERT_MSG(expr, msg) \
do { \
if(!(expr)) { \
LV_LOG_ERROR("Asserted at expression: %s (%s)", #expr, msg); \
LV_ASSERT_HANDLER \
} \
} while(0)
/*-----------------
* ASSERTS
*-----------------*/
#if LV_USE_ASSERT_NULL
# define LV_ASSERT_NULL(p) LV_ASSERT_MSG(p != NULL, "NULL pointer");
#else
# define LV_ASSERT_NULL(p)
#endif
#if LV_USE_ASSERT_MALLOC
# define LV_ASSERT_MALLOC(p) LV_ASSERT_MSG(p != NULL, "Out of memory");
#else
# define LV_ASSERT_MALLOC(p)
#endif
#if LV_USE_ASSERT_MEM_INTEGRITY
# define LV_ASSERT_MEM_INTEGRITY() LV_ASSERT_MSG(lv_mem_test() == LV_RES_OK, "Memory integrity error");
#else
# define LV_ASSERT_MEM_INTEGRITY()
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ASSERT_H*/
+61
View File
@@ -0,0 +1,61 @@
/**
* @file lv_async.h
*
*/
#ifndef LV_ASYNC_H
#define LV_ASYNC_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_types.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**
* Type for async callback.
*/
typedef void (*lv_async_cb_t)(void *);
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Call an asynchronous function the next time lv_timer_handler() is run. This function is likely to return
* **before** the call actually happens!
* @param async_xcb a callback which is the task itself.
* (the 'x' in the argument name indicates that it's not a fully generic function because it not follows
* the `func_name(object, callback, ...)` convention)
* @param user_data custom parameter
*/
lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data);
/**
* Cancel an asynchronous function call
* @param async_xcb a callback which is the task itself.
* @param user_data custom parameter
*/
lv_res_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ASYNC_H*/
+141
View File
@@ -0,0 +1,141 @@
/**
* @file lv_bidi.h
*
*/
#ifndef LV_BIDI_H
#define LV_BIDI_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdbool.h>
#include <stdint.h>
#include "lv_txt.h"
/*********************
* DEFINES
*********************/
/*Special non printable strong characters.
*They can be inserted to texts to affect the run's direction*/
#define LV_BIDI_LRO "\xE2\x80\xAD" /*U+202D*/
#define LV_BIDI_RLO "\xE2\x80\xAE" /*U+202E*/
/**********************
* TYPEDEFS
**********************/
enum {
LV_BASE_DIR_LTR = 0x00,
LV_BASE_DIR_RTL = 0x01,
LV_BASE_DIR_AUTO = 0x02,
LV_BASE_DIR_NEUTRAL = 0x20,
LV_BASE_DIR_WEAK = 0x21,
};
typedef uint8_t lv_base_dir_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
#if LV_USE_BIDI
/**
* Convert a text to get the characters in the correct visual order according to
* Unicode Bidirectional Algorithm
* @param str_in the text to process
* @param str_out store the result here. Has the be `strlen(str_in)` length
* @param base_dir `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
*/
void _lv_bidi_process(const char * str_in, char * str_out, lv_base_dir_t base_dir);
/**
* Auto-detect the direction of a text based on the first strong character
* @param txt the text to process
* @return `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
*/
lv_base_dir_t _lv_bidi_detect_base_dir(const char * txt);
/**
* Get the logical position of a character in a line
* @param str_in the input string. Can be only one line.
* @param bidi_txt internally the text is bidi processed which buffer can be get here.
* If not required anymore has to freed with `lv_mem_free()`
* Can be `NULL` is unused
* @param len length of the line in character count
* @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
* @param visual_pos the visual character position which logical position should be get
* @param is_rtl tell the char at `visual_pos` is RTL or LTR context
* @return the logical character position
*/
uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_base_dir_t base_dir,
uint32_t visual_pos, bool * is_rtl);
/**
* Get the visual position of a character in a line
* @param str_in the input string. Can be only one line.
* @param bidi_txt internally the text is bidi processed which buffer can be get here.
* If not required anymore has to freed with `lv_mem_free()`
* Can be `NULL` is unused
* @param len length of the line in character count
* @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
* @param logical_pos the logical character position which visual position should be get
* @param is_rtl tell the char at `logical_pos` is RTL or LTR context
* @return the visual character position
*/
uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_base_dir_t base_dir,
uint32_t logical_pos, bool * is_rtl);
/**
* Bidi process a paragraph of text
* @param str_in the string to process
* @param str_out store the result here
* @param len length of the text
* @param base_dir base dir of the text
* @param pos_conv_out an `uint16_t` array to store the related logical position of the character.
* Can be `NULL` is unused
* @param pos_conv_len length of `pos_conv_out` in element count
*/
void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_base_dir_t base_dir,
uint16_t * pos_conv_out, uint16_t pos_conv_len);
/**
* Get the real text alignment from the a text alignment, base direction and a text.
* @param align LV_TEXT_ALIGN_..., write back the calculated align here (LV_TEXT_ALIGN_LEFT/RIGHT/CENTER)
* @param base_dir LV_BASE_DIR_..., write the calculated base dir here (LV_BASE_DIR_LTR/RTL)
* @param txt a text, used with LV_BASE_DIR_AUTO to determine the base direction
*/
void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt);
/**********************
* MACROS
**********************/
#else /*LV_USE_BIDI*/
/**
* For compatibility if LV_USE_BIDI = 0
* Get the real text alignment from the a text alignment, base direction and a text.
* @param align For LV_TEXT_ALIGN_AUTO give LV_TEXT_ALIGN_LEFT else leave unchanged, write back the calculated align here
* @param base_dir Unused
* @param txt Unused
*/
static inline void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt)
{
LV_UNUSED(txt);
LV_UNUSED(base_dir);
if(*align == LV_TEXT_ALIGN_AUTO) * align = LV_TEXT_ALIGN_LEFT;
}
#endif /*LV_USE_BIDI*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_BIDI_H*/
+708
View File
@@ -0,0 +1,708 @@
/**
* @file lv_color.h
*
*/
#ifndef LV_COLOR_H
#define LV_COLOR_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include "lv_assert.h"
#include "lv_math.h"
#include "lv_types.h"
/*Error checking*/
#if LV_COLOR_DEPTH == 24
#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)"
#endif
#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0
#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h"
#endif
#include <stdint.h>
/*********************
* DEFINES
*********************/
LV_EXPORT_CONST_INT(LV_COLOR_DEPTH);
LV_EXPORT_CONST_INT(LV_COLOR_16_SWAP);
/**
* Opacity percentages.
*/
enum {
LV_OPA_TRANSP = 0,
LV_OPA_0 = 0,
LV_OPA_10 = 25,
LV_OPA_20 = 51,
LV_OPA_30 = 76,
LV_OPA_40 = 102,
LV_OPA_50 = 127,
LV_OPA_60 = 153,
LV_OPA_70 = 178,
LV_OPA_80 = 204,
LV_OPA_90 = 229,
LV_OPA_100 = 255,
LV_OPA_COVER = 255,
};
#define LV_OPA_MIN 2 /*Opacities below this will be transparent*/
#define LV_OPA_MAX 253 /*Opacities above this will fully cover*/
#if LV_COLOR_DEPTH == 1
#define LV_COLOR_SIZE 8
#elif LV_COLOR_DEPTH == 8
#define LV_COLOR_SIZE 8
#elif LV_COLOR_DEPTH == 16
#define LV_COLOR_SIZE 16
#elif LV_COLOR_DEPTH == 32
#define LV_COLOR_SIZE 32
#else
#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
#endif
#if defined(__cplusplus) && !defined(_LV_COLOR_HAS_MODERN_CPP)
/**
* MSVC compiler's definition of the __cplusplus indicating 199711L regardless to C++ standard version
* see https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-cplusplus
* so we use _MSC_VER macro instead of __cplusplus
*/
#ifdef _MSC_VER
#if _MSC_VER >= 1900 /*Visual Studio 2015*/
#define _LV_COLOR_HAS_MODERN_CPP 1
#endif
#else
#if __cplusplus >= 201103L
#define _LV_COLOR_HAS_MODERN_CPP 1
#endif
#endif
#endif /*__cplusplus*/
#ifndef _LV_COLOR_HAS_MODERN_CPP
#define _LV_COLOR_HAS_MODERN_CPP 0
#endif
#if _LV_COLOR_HAS_MODERN_CPP
/*Fix msvc compiler error C4576 inside C++ code*/
#define _LV_COLOR_MAKE_TYPE_HELPER lv_color_t
#else
#define _LV_COLOR_MAKE_TYPE_HELPER (lv_color_t)
#endif
/*---------------------------------------
* Macros for all existing color depths
* to set/get values of the color channels
*------------------------------------------*/
# define LV_COLOR_SET_R1(c, v) (c).ch.red = (uint8_t)((v) & 0x1)
# define LV_COLOR_SET_G1(c, v) (c).ch.green = (uint8_t)((v) & 0x1)
# define LV_COLOR_SET_B1(c, v) (c).ch.blue = (uint8_t)((v) & 0x1)
# define LV_COLOR_SET_A1(c, v) do {} while(0)
# define LV_COLOR_GET_R1(c) (c).ch.red
# define LV_COLOR_GET_G1(c) (c).ch.green
# define LV_COLOR_GET_B1(c) (c).ch.blue
# define LV_COLOR_GET_A1(c) 0xFF
# define _LV_COLOR_ZERO_INITIALIZER1 {0x00}
# define LV_COLOR_MAKE1(r8, g8, b8) {(uint8_t)((b8 >> 7) | (g8 >> 7) | (r8 >> 7))}
# define LV_COLOR_SET_R8(c, v) (c).ch.red = (uint8_t)((v) & 0x7U)
# define LV_COLOR_SET_G8(c, v) (c).ch.green = (uint8_t)((v) & 0x7U)
# define LV_COLOR_SET_B8(c, v) (c).ch.blue = (uint8_t)((v) & 0x3U)
# define LV_COLOR_SET_A8(c, v) do {} while(0)
# define LV_COLOR_GET_R8(c) (c).ch.red
# define LV_COLOR_GET_G8(c) (c).ch.green
# define LV_COLOR_GET_B8(c) (c).ch.blue
# define LV_COLOR_GET_A8(c) 0xFF
# define _LV_COLOR_ZERO_INITIALIZER8 {{0x00, 0x00, 0x00}}
# define LV_COLOR_MAKE8(r8, g8, b8) {{(uint8_t)((b8 >> 6) & 0x3U), (uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 5) & 0x7U)}}
# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)((v) & 0x1FU)
#if LV_COLOR_16_SWAP == 0
# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)((v) & 0x3FU)
#else
# define LV_COLOR_SET_G16(c, v) {(c).ch.green_h = (uint8_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint8_t)((v) & 0x7);}
#endif
# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)((v) & 0x1FU)
# define LV_COLOR_SET_A16(c, v) do {} while(0)
# define LV_COLOR_GET_R16(c) (c).ch.red
#if LV_COLOR_16_SWAP == 0
# define LV_COLOR_GET_G16(c) (c).ch.green
#else
# define LV_COLOR_GET_G16(c) (((c).ch.green_h << 3) + (c).ch.green_l)
#endif
# define LV_COLOR_GET_B16(c) (c).ch.blue
# define LV_COLOR_GET_A16(c) 0xFF
#if LV_COLOR_16_SWAP == 0
# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00}}
# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x3FU), (uint8_t)((r8 >> 3) & 0x1FU)}}
#else
# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00, 0x00}}
# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 3) & 0x1FU), (uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x7U)}}
#endif
# define LV_COLOR_SET_R32(c, v) (c).ch.red = (uint8_t)((v) & 0xFF)
# define LV_COLOR_SET_G32(c, v) (c).ch.green = (uint8_t)((v) & 0xFF)
# define LV_COLOR_SET_B32(c, v) (c).ch.blue = (uint8_t)((v) & 0xFF)
# define LV_COLOR_SET_A32(c, v) (c).ch.alpha = (uint8_t)((v) & 0xFF)
# define LV_COLOR_GET_R32(c) (c).ch.red
# define LV_COLOR_GET_G32(c) (c).ch.green
# define LV_COLOR_GET_B32(c) (c).ch.blue
# define LV_COLOR_GET_A32(c) (c).ch.alpha
# define _LV_COLOR_ZERO_INITIALIZER32 {{0x00, 0x00, 0x00, 0x00}}
# define LV_COLOR_MAKE32(r8, g8, b8) {{b8, g8, r8, 0xff}} /*Fix 0xff alpha*/
/*---------------------------------------
* Macros for the current color depth
* to set/get values of the color channels
*------------------------------------------*/
#define LV_COLOR_SET_R(c, v) LV_CONCAT(LV_COLOR_SET_R, LV_COLOR_DEPTH)(c, v)
#define LV_COLOR_SET_G(c, v) LV_CONCAT(LV_COLOR_SET_G, LV_COLOR_DEPTH)(c, v)
#define LV_COLOR_SET_B(c, v) LV_CONCAT(LV_COLOR_SET_B, LV_COLOR_DEPTH)(c, v)
#define LV_COLOR_SET_A(c, v) LV_CONCAT(LV_COLOR_SET_A, LV_COLOR_DEPTH)(c, v)
#define LV_COLOR_GET_R(c) LV_CONCAT(LV_COLOR_GET_R, LV_COLOR_DEPTH)(c)
#define LV_COLOR_GET_G(c) LV_CONCAT(LV_COLOR_GET_G, LV_COLOR_DEPTH)(c)
#define LV_COLOR_GET_B(c) LV_CONCAT(LV_COLOR_GET_B, LV_COLOR_DEPTH)(c)
#define LV_COLOR_GET_A(c) LV_CONCAT(LV_COLOR_GET_A, LV_COLOR_DEPTH)(c)
#define _LV_COLOR_ZERO_INITIALIZER LV_CONCAT(_LV_COLOR_ZERO_INITIALIZER, LV_COLOR_DEPTH)
#define LV_COLOR_MAKE(r8, g8, b8) LV_CONCAT(LV_COLOR_MAKE, LV_COLOR_DEPTH)(r8, g8, b8)
/**********************
* TYPEDEFS
**********************/
typedef union {
uint8_t full; /*must be declared first to set all bits of byte via initializer list*/
union {
uint8_t blue : 1;
uint8_t green : 1;
uint8_t red : 1;
} ch;
} lv_color1_t;
typedef union {
struct {
uint8_t blue : 2;
uint8_t green : 3;
uint8_t red : 3;
} ch;
uint8_t full;
} lv_color8_t;
typedef union {
struct {
#if LV_COLOR_16_SWAP == 0
uint16_t blue : 5;
uint16_t green : 6;
uint16_t red : 5;
#else
uint16_t green_h : 3;
uint16_t red : 5;
uint16_t blue : 5;
uint16_t green_l : 3;
#endif
} ch;
uint16_t full;
} lv_color16_t;
typedef union {
struct {
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t alpha;
} ch;
uint32_t full;
} lv_color32_t;
typedef LV_CONCAT3(uint, LV_COLOR_SIZE, _t) lv_color_int_t;
typedef LV_CONCAT3(lv_color, LV_COLOR_DEPTH, _t) lv_color_t;
typedef struct {
uint16_t h;
uint8_t s;
uint8_t v;
} lv_color_hsv_t;
//! @cond Doxygen_Suppress
/*No idea where the guard is required but else throws warnings in the docs*/
typedef uint8_t lv_opa_t;
//! @endcond
struct _lv_color_filter_dsc_t;
typedef lv_color_t (*lv_color_filter_cb_t)(const struct _lv_color_filter_dsc_t *, lv_color_t, lv_opa_t);
typedef struct _lv_color_filter_dsc_t {
lv_color_filter_cb_t filter_cb;
void * user_data;
} lv_color_filter_dsc_t;
typedef enum {
LV_PALETTE_RED,
LV_PALETTE_PINK,
LV_PALETTE_PURPLE,
LV_PALETTE_DEEP_PURPLE,
LV_PALETTE_INDIGO,
LV_PALETTE_BLUE,
LV_PALETTE_LIGHT_BLUE,
LV_PALETTE_CYAN,
LV_PALETTE_TEAL,
LV_PALETTE_GREEN,
LV_PALETTE_LIGHT_GREEN,
LV_PALETTE_LIME,
LV_PALETTE_YELLOW,
LV_PALETTE_AMBER,
LV_PALETTE_ORANGE,
LV_PALETTE_DEEP_ORANGE,
LV_PALETTE_BROWN,
LV_PALETTE_BLUE_GREY,
LV_PALETTE_GREY,
_LV_PALETTE_LAST,
LV_PALETTE_NONE = 0xff,
} lv_palette_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*In color conversations:
* - When converting to bigger color type the LSB weight of 1 LSB is calculated
* E.g. 16 bit Red has 5 bits
* 8 bit Red has 3 bits
* ----------------------
* 8 bit red LSB = (2^5 - 1) / (2^3 - 1) = 31 / 7 = 4
*
* - When calculating to smaller color type simply shift out the LSBs
* E.g. 8 bit Red has 3 bits
* 16 bit Red has 5 bits
* ----------------------
* Shift right with 5 - 3 = 2
*/
static inline uint8_t lv_color_to1(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
return color.full;
#elif LV_COLOR_DEPTH == 8
if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) {
return 1;
}
else {
return 0;
}
#elif LV_COLOR_DEPTH == 16
if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) {
return 1;
}
else {
return 0;
}
#elif LV_COLOR_DEPTH == 32
if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) {
return 1;
}
else {
return 0;
}
#endif
}
static inline uint8_t lv_color_to8(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
if(color.full == 0)
return 0;
else
return 0xFF;
#elif LV_COLOR_DEPTH == 8
return color.full;
#elif LV_COLOR_DEPTH == 16
lv_color8_t ret;
LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 2); /*5 - 3 = 2*/
LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 3); /*6 - 3 = 3*/
LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 3); /*5 - 2 = 3*/
return ret.full;
#elif LV_COLOR_DEPTH == 32
lv_color8_t ret;
LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 5); /*8 - 3 = 5*/
LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 5); /*8 - 3 = 5*/
LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 6); /*8 - 2 = 6*/
return ret.full;
#endif
}
static inline uint16_t lv_color_to16(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
if(color.full == 0)
return 0;
else
return 0xFFFF;
#elif LV_COLOR_DEPTH == 8
lv_color16_t ret;
LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) * 4); /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/
LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) * 9); /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) * 10); /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/
return ret.full;
#elif LV_COLOR_DEPTH == 16
return color.full;
#elif LV_COLOR_DEPTH == 32
lv_color16_t ret;
LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) >> 3); /*8 - 5 = 3*/
LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) >> 2); /*8 - 6 = 2*/
LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) >> 3); /*8 - 5 = 3*/
return ret.full;
#endif
}
static inline uint32_t lv_color_to32(lv_color_t color)
{
#if LV_COLOR_DEPTH == 1
if(color.full == 0)
return 0xFF000000;
else
return 0xFFFFFFFF;
#elif LV_COLOR_DEPTH == 8
lv_color32_t ret;
LV_COLOR_SET_R32(ret, LV_COLOR_GET_R(color) * 36); /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
LV_COLOR_SET_G32(ret, LV_COLOR_GET_G(color) * 36); /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
LV_COLOR_SET_B32(ret, LV_COLOR_GET_B(color) * 85); /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/
LV_COLOR_SET_A32(ret, 0xFF);
return ret.full;
#elif LV_COLOR_DEPTH == 16
/**
* The floating point math for conversion is:
* valueto = valuefrom * ( (2^bitsto - 1) / (float)(2^bitsfrom - 1) )
* The faster integer math for conversion is:
* valueto = ( valuefrom * multiplier + adder ) >> divisor
* multiplier = FLOOR( ( (2^bitsto - 1) << divisor ) / (float)(2^bitsfrom - 1) )
*
* Find the first divisor where ( adder >> divisor ) <= 0
*
* 5-bit to 8-bit: ( 31 * multiplier + adder ) >> divisor = 255
* divisor multiplier adder min (0) max (31)
* 0 8 7 7 255
* 1 16 14 7 255
* 2 32 28 7 255
* 3 65 25 3 255
* 4 131 19 1 255
* 5 263 7 0 255
*
* 6-bit to 8-bit: 255 = ( 63 * multiplier + adder ) >> divisor
* divisor multiplier adder min (0) max (63)
* 0 4 3 3 255
* 1 8 6 3 255
* 2 16 12 3 255
* 3 32 24 3 255
* 4 64 48 3 255
* 5 129 33 1 255
* 6 259 3 0 255
*/
lv_color32_t ret;
LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7) >> 5);
LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3) >> 6);
LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7) >> 5);
LV_COLOR_SET_A32(ret, 0xFF);
return ret.full;
#elif LV_COLOR_DEPTH == 32
return color.full;
#endif
}
//! @cond Doxygen_Suppress
/**
* Mix two colors with a given ratio.
* @param c1 the first color to mix (usually the foreground)
* @param c2 the second color to mix (usually the background)
* @param mix The ratio of the colors. 0: full `c2`, 255: full `c1`, 127: half `c1` and half`c2`
* @return the mixed color
*/
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
{
lv_color_t ret;
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 && LV_COLOR_MIX_ROUND_OFS == 0
/*Source: https://stackoverflow.com/a/50012418/1999969*/
mix = (uint32_t)((uint32_t)mix + 4) >> 3;
uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) &
0x7E0F81F; /*0b00000111111000001111100000011111*/
uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F;
uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F;
ret.full = (uint16_t)((result >> 16) | result);
#elif LV_COLOR_DEPTH != 1
/*LV_COLOR_DEPTH == 8, 16 or 32*/
LV_COLOR_SET_R(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) *
(255 - mix) + LV_COLOR_MIX_ROUND_OFS));
LV_COLOR_SET_G(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_G(c1) * mix + LV_COLOR_GET_G(c2) *
(255 - mix) + LV_COLOR_MIX_ROUND_OFS));
LV_COLOR_SET_B(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_B(c1) * mix + LV_COLOR_GET_B(c2) *
(255 - mix) + LV_COLOR_MIX_ROUND_OFS));
LV_COLOR_SET_A(ret, 0xFF);
#else
/*LV_COLOR_DEPTH == 1*/
ret.full = mix > LV_OPA_50 ? c1.full : c2.full;
#endif
return ret;
}
LV_ATTRIBUTE_FAST_MEM static inline void lv_color_premult(lv_color_t c, uint8_t mix, uint16_t * out)
{
#if LV_COLOR_DEPTH != 1
out[0] = (uint16_t)LV_COLOR_GET_R(c) * mix;
out[1] = (uint16_t)LV_COLOR_GET_G(c) * mix;
out[2] = (uint16_t)LV_COLOR_GET_B(c) * mix;
#else
(void) mix;
/*Pre-multiplication can't be used with 1 bpp*/
out[0] = LV_COLOR_GET_R(c);
out[1] = LV_COLOR_GET_G(c);
out[2] = LV_COLOR_GET_B(c);
#endif
}
/**
* Mix two colors with a given ratio. It runs faster then `lv_color_mix` but requires some pre computation.
* @param premult_c1 The first color. Should be preprocessed with `lv_color_premult(c1)`
* @param c2 The second color. As it is no pre computation required on it
* @param mix The ratio of the colors. 0: full `c1`, 255: full `c2`, 127: half `c1` and half `c2`.
* Should be modified like mix = `255 - mix`
* @return the mixed color
* @note 255 won't give clearly `c1`.
*/
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix_premult(uint16_t * premult_c1, lv_color_t c2, uint8_t mix)
{
lv_color_t ret;
#if LV_COLOR_DEPTH != 1
/*LV_COLOR_DEPTH == 8 or 32*/
LV_COLOR_SET_R(ret, LV_UDIV255(premult_c1[0] + LV_COLOR_GET_R(c2) * mix + LV_COLOR_MIX_ROUND_OFS));
LV_COLOR_SET_G(ret, LV_UDIV255(premult_c1[1] + LV_COLOR_GET_G(c2) * mix + LV_COLOR_MIX_ROUND_OFS));
LV_COLOR_SET_B(ret, LV_UDIV255(premult_c1[2] + LV_COLOR_GET_B(c2) * mix + LV_COLOR_MIX_ROUND_OFS));
LV_COLOR_SET_A(ret, 0xFF);
#else
/*LV_COLOR_DEPTH == 1*/
/*Restore color1*/
lv_color_t c1;
LV_COLOR_SET_R(c1, premult_c1[0]);
LV_COLOR_SET_G(c1, premult_c1[1]);
LV_COLOR_SET_B(c1, premult_c1[2]);
ret.full = mix > LV_OPA_50 ? c2.full : c1.full;
#endif
return ret;
}
/**
* Mix two colors. Both color can have alpha value.
* @param bg_color background color
* @param bg_opa alpha of the background color
* @param fg_color foreground color
* @param fg_opa alpha of the foreground color
* @param res_color the result color
* @param res_opa the result opacity
*/
LV_ATTRIBUTE_FAST_MEM static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa,
lv_color_t fg_color, lv_opa_t fg_opa,
lv_color_t * res_color, lv_opa_t * res_opa)
{
/*Pick the foreground if it's fully opaque or the Background is fully transparent*/
if(fg_opa >= LV_OPA_MAX || bg_opa <= LV_OPA_MIN) {
res_color->full = fg_color.full;
*res_opa = fg_opa;
}
/*Transparent foreground: use the Background*/
else if(fg_opa <= LV_OPA_MIN) {
res_color->full = bg_color.full;
*res_opa = bg_opa;
}
/*Opaque background: use simple mix*/
else if(bg_opa >= LV_OPA_MAX) {
*res_color = lv_color_mix(fg_color, bg_color, fg_opa);
*res_opa = LV_OPA_COVER;
}
/*Both colors have alpha. Expensive calculation need to be applied*/
else {
/*Save the parameters and the result. If they will be asked again don't compute again*/
static lv_opa_t fg_opa_save = 0;
static lv_opa_t bg_opa_save = 0;
static lv_color_t fg_color_save = _LV_COLOR_ZERO_INITIALIZER;
static lv_color_t bg_color_save = _LV_COLOR_ZERO_INITIALIZER;
static lv_color_t res_color_saved = _LV_COLOR_ZERO_INITIALIZER;
static lv_opa_t res_opa_saved = 0;
if(fg_opa != fg_opa_save || bg_opa != bg_opa_save || fg_color.full != fg_color_save.full ||
bg_color.full != bg_color_save.full) {
fg_opa_save = fg_opa;
bg_opa_save = bg_opa;
fg_color_save.full = fg_color.full;
bg_color_save.full = bg_color.full;
/*Info:
* https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/
res_opa_saved = 255 - ((uint16_t)((uint16_t)(255 - fg_opa) * (255 - bg_opa)) >> 8);
LV_ASSERT(res_opa_saved != 0);
lv_opa_t ratio = (uint16_t)((uint16_t)fg_opa * 255) / res_opa_saved;
res_color_saved = lv_color_mix(fg_color, bg_color, ratio);
}
res_color->full = res_color_saved.full;
*res_opa = res_opa_saved;
}
}
//! @endcond
/**
* Get the brightness of a color
* @param color a color
* @return the brightness [0..255]
*/
static inline uint8_t lv_color_brightness(lv_color_t color)
{
lv_color32_t c32;
c32.full = lv_color_to32(color);
uint16_t bright = (uint16_t)(3u * LV_COLOR_GET_R32(c32) + LV_COLOR_GET_B32(c32) + 4u * LV_COLOR_GET_G32(c32));
return (uint8_t)(bright >> 3);
}
static inline lv_color_t lv_color_make(uint8_t r, uint8_t g, uint8_t b)
{
return _LV_COLOR_MAKE_TYPE_HELPER LV_COLOR_MAKE(r, g, b);
}
static inline lv_color_t lv_color_hex(uint32_t c)
{
#if LV_COLOR_DEPTH == 16
lv_color_t r;
#if LV_COLOR_16_SWAP == 0
/* Convert a 4 bytes per pixel in format ARGB32 to R5G6B5 format
naive way (by calling lv_color_make with components):
r = ((c & 0xFF0000) >> 19)
g = ((c & 0xFF00) >> 10)
b = ((c & 0xFF) >> 3)
rgb565 = (r << 11) | (g << 5) | b
That's 3 mask, 5 bitshift and 2 or operations
A bit better:
r = ((c & 0xF80000) >> 8)
g = ((c & 0xFC00) >> 5)
b = ((c & 0xFF) >> 3)
rgb565 = r | g | b
That's 3 mask, 3 bitshifts and 2 or operations */
r.full = (uint16_t)(((c & 0xF80000) >> 8) | ((c & 0xFC00) >> 5) | ((c & 0xFF) >> 3));
#else
/* We want: rrrr rrrr GGGg gggg bbbb bbbb => gggb bbbb rrrr rGGG */
r.full = (uint16_t)(((c & 0xF80000) >> 16) | ((c & 0xFC00) >> 13) | ((c & 0x1C00) << 3) | ((c & 0xF8) << 5));
#endif
return r;
#elif LV_COLOR_DEPTH == 32
lv_color_t r;
r.full = c | 0xFF000000;
return r;
#else /*LV_COLOR_DEPTH == 8*/
return lv_color_make((uint8_t)((c >> 16) & 0xFF), (uint8_t)((c >> 8) & 0xFF), (uint8_t)(c & 0xFF));
#endif
}
static inline lv_color_t lv_color_hex3(uint32_t c)
{
return lv_color_make((uint8_t)(((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), (uint8_t)((c & 0xF0) | ((c & 0xF0) >> 4)),
(uint8_t)((c & 0xF) | ((c & 0xF) << 4)));
}
static inline void lv_color_filter_dsc_init(lv_color_filter_dsc_t * dsc, lv_color_filter_cb_t cb)
{
dsc->filter_cb = cb;
}
//! @cond Doxygen_Suppress
//!
LV_ATTRIBUTE_FAST_MEM void lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num);
//! @endcond
lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl);
lv_color_t lv_color_darken(lv_color_t c, lv_opa_t lvl);
lv_color_t lv_color_change_lightness(lv_color_t c, lv_opa_t lvl);
/**
* Convert a HSV color to RGB
* @param h hue [0..359]
* @param s saturation [0..100]
* @param v value [0..100]
* @return the given RGB color in RGB (with LV_COLOR_DEPTH depth)
*/
lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v);
/**
* Convert a 32-bit RGB color to HSV
* @param r8 8-bit red
* @param g8 8-bit green
* @param b8 8-bit blue
* @return the given RGB color in HSV
*/
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8);
/**
* Convert a color to HSV
* @param color color
* @return the given color in HSV
*/
lv_color_hsv_t lv_color_to_hsv(lv_color_t color);
/**
* Just a wrapper around LV_COLOR_CHROMA_KEY because it might be more convenient to use a function in some cases
* @return LV_COLOR_CHROMA_KEY
*/
static inline lv_color_t lv_color_chroma_key(void)
{
return LV_COLOR_CHROMA_KEY;
}
/**********************
* PREDEFINED COLORS
**********************/
/*Source: https://vuetifyjs.com/en/styles/colors/#material-colors*/
lv_color_t lv_palette_main(lv_palette_t p);
static inline lv_color_t lv_color_white(void)
{
return lv_color_make(0xff, 0xff, 0xff);
}
static inline lv_color_t lv_color_black(void)
{
return lv_color_make(0x00, 0x0, 0x00);
}
lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl);
lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_COLOR_H*/
+262
View File
@@ -0,0 +1,262 @@
/**
* @file lv_fs.h
*
*/
#ifndef LV_FS_H
#define LV_FS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
#define LV_FS_MAX_FN_LENGTH 64
#define LV_FS_MAX_PATH_LENGTH 256
/**********************
* TYPEDEFS
**********************/
/**
* Errors in the file system module.
*/
enum {
LV_FS_RES_OK = 0,
LV_FS_RES_HW_ERR, /*Low level hardware error*/
LV_FS_RES_FS_ERR, /*Error in the file system structure*/
LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/
LV_FS_RES_FULL, /*Disk full*/
LV_FS_RES_LOCKED, /*The file is already opened*/
LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/
LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/
LV_FS_RES_TOUT, /*Process time outed*/
LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/
LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/
LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/
LV_FS_RES_UNKNOWN, /*Other unknown error*/
};
typedef uint8_t lv_fs_res_t;
/**
* File open mode.
*/
enum {
LV_FS_MODE_WR = 0x01,
LV_FS_MODE_RD = 0x02,
};
typedef uint8_t lv_fs_mode_t;
/**
* Seek modes.
*/
typedef enum {
LV_FS_SEEK_SET = 0x00, /**< Set the position from absolutely (from the start of file)*/
LV_FS_SEEK_CUR = 0x01, /**< Set the position from the current position*/
LV_FS_SEEK_END = 0x02, /**< Set the position from the end of the file*/
} lv_fs_whence_t;
typedef struct _lv_fs_drv_t {
char letter;
uint16_t cache_size;
bool (*ready_cb)(struct _lv_fs_drv_t * drv);
void * (*open_cb)(struct _lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode);
lv_fs_res_t (*close_cb)(struct _lv_fs_drv_t * drv, void * file_p);
lv_fs_res_t (*read_cb)(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
lv_fs_res_t (*write_cb)(struct _lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
lv_fs_res_t (*seek_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence);
lv_fs_res_t (*tell_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
void * (*dir_open_cb)(struct _lv_fs_drv_t * drv, const char * path);
lv_fs_res_t (*dir_read_cb)(struct _lv_fs_drv_t * drv, void * rddir_p, char * fn);
lv_fs_res_t (*dir_close_cb)(struct _lv_fs_drv_t * drv, void * rddir_p);
#if LV_USE_USER_DATA
void * user_data; /**< Custom file user data*/
#endif
} lv_fs_drv_t;
typedef struct {
uint32_t start;
uint32_t end;
uint32_t file_position;
void * buffer;
} lv_fs_file_cache_t;
typedef struct {
void * file_d;
lv_fs_drv_t * drv;
lv_fs_file_cache_t * cache;
} lv_fs_file_t;
typedef struct {
void * dir_d;
lv_fs_drv_t * drv;
} lv_fs_dir_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the File system interface
*/
void _lv_fs_init(void);
/**
* Initialize a file system driver with default values.
* It is used to surly have known values in the fields ant not memory junk.
* After it you can set the fields.
* @param drv pointer to driver variable to initialize
*/
void lv_fs_drv_init(lv_fs_drv_t * drv);
/**
* Add a new drive
* @param drv pointer to an lv_fs_drv_t structure which is inited with the
* corresponding function pointers. Only pointer is saved, so the
* driver should be static or dynamically allocated.
*/
void lv_fs_drv_register(lv_fs_drv_t * drv);
/**
* Give a pointer to a driver from its letter
* @param letter the driver letter
* @return pointer to a driver or NULL if not found
*/
lv_fs_drv_t * lv_fs_get_drv(char letter);
/**
* Test if a drive is ready or not. If the `ready` function was not initialized `true` will be
* returned.
* @param letter letter of the drive
* @return true: drive is ready; false: drive is not ready
*/
bool lv_fs_is_ready(char letter);
/**
* Open a file
* @param file_p pointer to a lv_fs_file_t variable
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode);
/**
* Close an already opened file
* @param file_p pointer to a lv_fs_file_t variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p);
/**
* Read from a file
* @param file_p pointer to a lv_fs_file_t variable
* @param buf pointer to a buffer where the read bytes are stored
* @param btr Bytes To Read
* @param br the number of real read bytes (Bytes Read). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br);
/**
* Write into a file
* @param file_p pointer to a lv_fs_file_t variable
* @param buf pointer to a buffer with the bytes to write
* @param btw Bytes To Write
* @param bw the number of real written bytes (Bytes Written). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw);
/**
* Set the position of the 'cursor' (read write pointer) in a file
* @param file_p pointer to a lv_fs_file_t variable
* @param pos the new position expressed in bytes index (0: start of file)
* @param whence tells from where set the position. See @lv_fs_whence_t
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos, lv_fs_whence_t whence);
/**
* Give the position of the read write pointer
* @param file_p pointer to a lv_fs_file_t variable
* @param pos_p pointer to store the position of the read write pointer
* @return LV_FS_RES_OK or any error from 'fs_res_t'
*/
lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos);
/**
* Initialize a 'fs_dir_t' variable for directory reading
* @param rddir_p pointer to a 'lv_fs_dir_t' variable
* @param path path to a directory
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path);
/**
* Read the next filename form a directory.
* The name of the directories will begin with '/'
* @param rddir_p pointer to an initialized 'fs_dir_t' variable
* @param fn pointer to a buffer to store the filename
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn);
/**
* Close the directory reading
* @param rddir_p pointer to an initialized 'fs_dir_t' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p);
/**
* Fill a buffer with the letters of existing drivers
* @param buf buffer to store the letters ('\0' added after the last letter)
* @return the buffer
*/
char * lv_fs_get_letters(char * buf);
/**
* Return with the extension of the filename
* @param fn string with a filename
* @return pointer to the beginning extension or empty string if no extension
*/
const char * lv_fs_get_ext(const char * fn);
/**
* Step up one level
* @param path pointer to a file name
* @return the truncated file name
*/
char * lv_fs_up(char * path);
/**
* Get the last element of a path (e.g. U:/folder/file -> file)
* @param path pointer to a file name
* @return pointer to the beginning of the last element in the path
*/
const char * lv_fs_get_last(const char * path);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_FS_H*/
+97
View File
@@ -0,0 +1,97 @@
/**
* @file lv_gc.h
*
*/
#ifndef LV_GC_H
#define LV_GC_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdint.h>
#include "lv_mem.h"
#include "lv_ll.h"
#include "lv_timer.h"
#include "lv_types.h"
#include "liblvgl/draw/lv_img_cache.h"
#include "liblvgl/draw/lv_draw_mask.h"
#include "liblvgl/core/lv_obj_pos.h"
/*********************
* DEFINES
*********************/
#if LV_IMG_CACHE_DEF_SIZE
# define LV_IMG_CACHE_DEF 1
#else
# define LV_IMG_CACHE_DEF 0
#endif
#define LV_DISPATCH(f, t, n) f(t, n)
#define LV_DISPATCH_COND(f, t, n, m, v) LV_CONCAT3(LV_DISPATCH, m, v)(f, t, n)
#define LV_DISPATCH00(f, t, n) LV_DISPATCH(f, t, n)
#define LV_DISPATCH01(f, t, n)
#define LV_DISPATCH10(f, t, n)
#define LV_DISPATCH11(f, t, n) LV_DISPATCH(f, t, n)
#define LV_ITERATE_ROOTS(f) \
LV_DISPATCH(f, lv_ll_t, _lv_timer_ll) /*Linked list to store the lv_timers*/ \
LV_DISPATCH(f, lv_ll_t, _lv_disp_ll) /*Linked list of display device*/ \
LV_DISPATCH(f, lv_ll_t, _lv_indev_ll) /*Linked list of input device*/ \
LV_DISPATCH(f, lv_ll_t, _lv_fsdrv_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_anim_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_group_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_img_decoder_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_obj_style_trans_ll) \
LV_DISPATCH(f, lv_layout_dsc_t *, _lv_layout_list) \
LV_DISPATCH_COND(f, _lv_img_cache_entry_t*, _lv_img_cache_array, LV_IMG_CACHE_DEF, 1) \
LV_DISPATCH_COND(f, _lv_img_cache_entry_t, _lv_img_cache_single, LV_IMG_CACHE_DEF, 0) \
LV_DISPATCH(f, lv_timer_t*, _lv_timer_act) \
LV_DISPATCH(f, lv_mem_buf_arr_t , lv_mem_buf) \
LV_DISPATCH_COND(f, _lv_draw_mask_radius_circle_dsc_arr_t , _lv_circle_cache, LV_DRAW_COMPLEX, 1) \
LV_DISPATCH_COND(f, _lv_draw_mask_saved_arr_t , _lv_draw_mask_list, LV_DRAW_COMPLEX, 1) \
LV_DISPATCH(f, void * , _lv_theme_default_styles) \
LV_DISPATCH(f, void * , _lv_theme_basic_styles) \
LV_DISPATCH_COND(f, uint8_t *, _lv_font_decompr_buf, LV_USE_FONT_COMPRESSED, 1) \
LV_DISPATCH(f, uint8_t * , _lv_grad_cache_mem) \
LV_DISPATCH(f, uint8_t * , _lv_style_custom_prop_flag_lookup_table)
#define LV_DEFINE_ROOT(root_type, root_name) root_type root_name;
#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT)
#if LV_ENABLE_GC == 1
#if LV_MEM_CUSTOM != 1
#error "GC requires CUSTOM_MEM"
#endif /*LV_MEM_CUSTOM*/
#include LV_GC_INCLUDE
#else /*LV_ENABLE_GC*/
#define LV_GC_ROOT(x) x
#define LV_EXTERN_ROOT(root_type, root_name) extern root_type root_name;
LV_ITERATE_ROOTS(LV_EXTERN_ROOT)
#endif /*LV_ENABLE_GC*/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void _lv_gc_clear_roots(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_GC_H*/
+167
View File
@@ -0,0 +1,167 @@
/**
* @file lv_ll.h
* Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module.
*/
#ifndef LV_LL_H
#define LV_LL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/** Dummy type to make handling easier*/
typedef uint8_t lv_ll_node_t;
/** Description of a linked list*/
typedef struct {
uint32_t n_size;
lv_ll_node_t * head;
lv_ll_node_t * tail;
} lv_ll_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize linked list
* @param ll_p pointer to lv_ll_t variable
* @param node_size the size of 1 node in bytes
*/
void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size);
/**
* Add a new head to a linked list
* @param ll_p pointer to linked list
* @return pointer to the new head
*/
void * _lv_ll_ins_head(lv_ll_t * ll_p);
/**
* Insert a new node in front of the n_act node
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the new node
*/
void * _lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act);
/**
* Add a new tail to a linked list
* @param ll_p pointer to linked list
* @return pointer to the new tail
*/
void * _lv_ll_ins_tail(lv_ll_t * ll_p);
/**
* Remove the node 'node_p' from 'll_p' linked list.
* It does not free the memory of node.
* @param ll_p pointer to the linked list of 'node_p'
* @param node_p pointer to node in 'll_p' linked list
*/
void _lv_ll_remove(lv_ll_t * ll_p, void * node_p);
/**
* Remove and free all elements from a linked list. The list remain valid but become empty.
* @param ll_p pointer to linked list
*/
void _lv_ll_clear(lv_ll_t * ll_p);
/**
* Move a node to a new linked list
* @param ll_ori_p pointer to the original (old) linked list
* @param ll_new_p pointer to the new linked list
* @param node pointer to a node
* @param head true: be the head in the new list
* false be the tail in the new list
*/
void _lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head);
/**
* Return with head node of the linked list
* @param ll_p pointer to linked list
* @return pointer to the head of 'll_p'
*/
void * _lv_ll_get_head(const lv_ll_t * ll_p);
/**
* Return with tail node of the linked list
* @param ll_p pointer to linked list
* @return pointer to the tail of 'll_p'
*/
void * _lv_ll_get_tail(const lv_ll_t * ll_p);
/**
* Return with the pointer of the next node after 'n_act'
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the next node
*/
void * _lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act);
/**
* Return with the pointer of the previous node after 'n_act'
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the previous node
*/
void * _lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act);
/**
* Return the length of the linked list.
* @param ll_p pointer to linked list
* @return length of the linked list
*/
uint32_t _lv_ll_get_len(const lv_ll_t * ll_p);
/**
* TODO
* @param ll_p
* @param n1_p
* @param n2_p
void lv_ll_swap(lv_ll_t * ll_p, void * n1_p, void * n2_p);
*/
/**
* Move a node before an other node in the same linked list
* @param ll_p pointer to a linked list
* @param n_act pointer to node to move
* @param n_after pointer to a node which should be after `n_act`
*/
void _lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after);
/**
* Check if a linked list is empty
* @param ll_p pointer to a linked list
* @return true: the linked list is empty; false: not empty
*/
bool _lv_ll_is_empty(lv_ll_t * ll_p);
/**********************
* MACROS
**********************/
#define _LV_LL_READ(list, i) for(i = _lv_ll_get_head(list); i != NULL; i = _lv_ll_get_next(list, i))
#define _LV_LL_READ_BACK(list, i) for(i = _lv_ll_get_tail(list); i != NULL; i = _lv_ll_get_prev(list, i))
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
+154
View File
@@ -0,0 +1,154 @@
/**
* @file lv_log.h
*
*/
#ifndef LV_LOG_H
#define LV_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdint.h>
#include "lv_types.h"
/*********************
* DEFINES
*********************/
/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/
#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/
#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/
#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/
#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/
#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels*/
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);
typedef int8_t lv_log_level_t;
#if LV_USE_LOG
/**********************
* TYPEDEFS
**********************/
/**
* Log print function. Receives a string buffer to print".
*/
typedef void (*lv_log_print_g_cb_t)(const char * buf);
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Register custom print/write function to call when a log is added.
* It can format its "File path", "Line number" and "Description" as required
* and send the formatted log message to a console or serial port.
* @param print_cb a function pointer to print a log
*/
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);
/**
* Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h`
* and/or a print callback if registered with `lv_log_register_print_cb`
* @param format printf-like format string
* @param ... parameters for `format`
*/
void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2);
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param func name of the function when the log added
* @param format printf-like format string
* @param ... parameters for `format`
*/
void _lv_log_add(lv_log_level_t level, const char * file, int line,
const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6);
/**********************
* MACROS
**********************/
#ifndef LV_LOG_TRACE
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
# define LV_LOG_TRACE(...) _lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, __VA_ARGS__)
# else
# define LV_LOG_TRACE(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_INFO
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
# define LV_LOG_INFO(...) _lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
# else
# define LV_LOG_INFO(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_WARN
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
# define LV_LOG_WARN(...) _lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__)
# else
# define LV_LOG_WARN(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_ERROR
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
# define LV_LOG_ERROR(...) _lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
# else
# define LV_LOG_ERROR(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_USER
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER
# define LV_LOG_USER(...) _lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __func__, __VA_ARGS__)
# else
# define LV_LOG_USER(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG
# if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE
# define LV_LOG(...) lv_log(__VA_ARGS__)
# else
# define LV_LOG(...) do {} while(0)
# endif
#endif
#else /*LV_USE_LOG*/
/*Do nothing if `LV_USE_LOG 0`*/
#define _lv_log_add(level, file, line, ...)
#define LV_LOG_TRACE(...) do {}while(0)
#define LV_LOG_INFO(...) do {}while(0)
#define LV_LOG_WARN(...) do {}while(0)
#define LV_LOG_ERROR(...) do {}while(0)
#define LV_LOG_USER(...) do {}while(0)
#define LV_LOG(...) do {}while(0)
#endif /*LV_USE_LOG*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_LOG_H*/
+87
View File
@@ -0,0 +1,87 @@
/**
* @file lv_lru.h
*
*/
#ifndef LV_LRU_H
#define LV_LRU_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include "lv_types.h"
#include <stdint.h>
#include <stddef.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_LRU_OK = 0,
LV_LRU_MISSING_CACHE,
LV_LRU_MISSING_KEY,
LV_LRU_MISSING_VALUE,
LV_LRU_LOCK_ERROR,
LV_LRU_VALUE_TOO_LARGE
} lv_lru_res_t;
typedef void (lv_lru_free_t)(void * v);
typedef struct _lv_lru_item_t lv_lru_item_t;
typedef struct lv_lru_t {
lv_lru_item_t ** items;
uint64_t access_count;
size_t free_memory;
size_t total_memory;
size_t average_item_length;
size_t hash_table_size;
uint32_t seed;
lv_lru_free_t * value_free;
lv_lru_free_t * key_free;
lv_lru_item_t * free_items;
} lv_lru_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
lv_lru_t * lv_lru_create(size_t cache_size, size_t average_length, lv_lru_free_t * value_free,
lv_lru_free_t * key_free);
void lv_lru_del(lv_lru_t * cache);
lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, void * value, size_t value_length);
lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, void ** value);
lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size);
/**
* remove the least recently used item
*
* @todo we can optimise this by finding the n lru items, where n = required_space / average_length
*/
void lv_lru_remove_lru_item(lv_lru_t * cache);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_LRU_H*/
+143
View File
@@ -0,0 +1,143 @@
/**
* @file lv_math.h
*
*/
#ifndef LV_MATH_H
#define LV_MATH_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdint.h>
/*********************
* DEFINES
*********************/
#define LV_TRIGO_SIN_MAX 32767
#define LV_TRIGO_SHIFT 15 /**< >> LV_TRIGO_SHIFT to normalize*/
#define LV_BEZIER_VAL_MAX 1024 /**< Max time in Bezier functions (not [0..1] to use integers)*/
#define LV_BEZIER_VAL_SHIFT 10 /**< log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint16_t i;
uint16_t f;
} lv_sqrt_res_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
//! @cond Doxygen_Suppress
/**
* Return with sinus of an angle
* @param angle
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
*/
LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_sin(int16_t angle);
static inline LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_cos(int16_t angle)
{
return lv_trigo_sin(angle + 90);
}
//! @endcond
/**
* Calculate a value of a Cubic Bezier function.
* @param t time in range of [0..LV_BEZIER_VAL_MAX]
* @param u0 start values in range of [0..LV_BEZIER_VAL_MAX]
* @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX]
* @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX]
* @param u3 end values in range of [0..LV_BEZIER_VAL_MAX]
* @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX]
*/
uint32_t lv_bezier3(uint32_t t, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3);
/**
* Calculate the atan2 of a vector.
* @param x
* @param y
* @return the angle in degree calculated from the given parameters in range of [0..360]
*/
uint16_t lv_atan2(int x, int y);
//! @cond Doxygen_Suppress
/**
* Get the square root of a number
* @param x integer which square root should be calculated
* @param q store the result here. q->i: integer part, q->f: fractional part in 1/256 unit
* @param mask optional to skip some iterations if the magnitude of the root is known.
* Set to 0x8000 by default.
* If root < 16: mask = 0x80
* If root < 256: mask = 0x800
* Else: mask = 0x8000
*/
LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask);
//! @endcond
/**
* Calculate the integer exponents.
* @param base
* @param power
* @return base raised to the power exponent
*/
int64_t lv_pow(int64_t base, int8_t exp);
/**
* Get the mapped of a number given an input and output range
* @param x integer which mapped value should be calculated
* @param min_in min input range
* @param max_in max input range
* @param min_out max output range
* @param max_out max output range
* @return the mapped number
*/
int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out);
/**
* Get a pseudo random number in the given range
* @param min the minimum value
* @param max the maximum value
* @return return the random number. min <= return_value <= max
*/
uint32_t lv_rand(uint32_t min, uint32_t max);
/**********************
* MACROS
**********************/
#define LV_MIN(a, b) ((a) < (b) ? (a) : (b))
#define LV_MIN3(a, b, c) (LV_MIN(LV_MIN(a,b), c))
#define LV_MIN4(a, b, c, d) (LV_MIN(LV_MIN(a,b), LV_MIN(c,d)))
#define LV_MAX(a, b) ((a) > (b) ? (a) : (b))
#define LV_MAX3(a, b, c) (LV_MAX(LV_MAX(a,b), c))
#define LV_MAX4(a, b, c, d) (LV_MAX(LV_MAX(a,b), LV_MAX(c,d)))
#define LV_CLAMP(min, val, max) (LV_MAX(min, (LV_MIN(val, max))))
#define LV_ABS(x) ((x) > 0 ? (x) : (-(x)))
#define LV_UDIV255(x) (((x) * 0x8081U) >> 0x17)
#define LV_IS_SIGNED(t) (((t)(-1)) < ((t)0))
#define LV_UMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL)))
#define LV_SMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL)))
#define LV_MAX_OF(t) ((unsigned long)(LV_IS_SIGNED(t) ? LV_SMAX_OF(t) : LV_UMAX_OF(t)))
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
+243
View File
@@ -0,0 +1,243 @@
/**
* @file lv_mem.h
*
*/
#ifndef LV_MEM_H
#define LV_MEM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "lv_types.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**
* Heap information structure.
*/
typedef struct {
uint32_t total_size; /**< Total heap size*/
uint32_t free_cnt;
uint32_t free_size; /**< Size of available memory*/
uint32_t free_biggest_size;
uint32_t used_cnt;
uint32_t max_used; /**< Max size of Heap memory used*/
uint8_t used_pct; /**< Percentage used*/
uint8_t frag_pct; /**< Amount of fragmentation*/
} lv_mem_monitor_t;
typedef struct {
void * p;
uint16_t size;
uint8_t used : 1;
} lv_mem_buf_t;
typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM];
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the dyn_mem module (work memory and other variables)
*/
void lv_mem_init(void);
/**
* Clean up the memory buffer which frees all the allocated memories.
* @note It work only if `LV_MEM_CUSTOM == 0`
*/
void lv_mem_deinit(void);
/**
* Allocate a memory dynamically
* @param size size of the memory to allocate in bytes
* @return pointer to the allocated memory
*/
void * lv_mem_alloc(size_t size);
/**
* Free an allocated data
* @param data pointer to an allocated memory
*/
void lv_mem_free(void * data);
/**
* Reallocate a memory with a new size. The old content will be kept.
* @param data pointer to an allocated memory.
* Its content will be copied to the new memory block and freed
* @param new_size the desired new size in byte
* @return pointer to the new memory, NULL on failure
*/
void * lv_mem_realloc(void * data_p, size_t new_size);
/**
*
* @return
*/
lv_res_t lv_mem_test(void);
/**
* Give information about the work memory of dynamic allocation
* @param mon_p pointer to a lv_mem_monitor_t variable,
* the result of the analysis will be stored here
*/
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
/**
* Get a temporal buffer with the given size.
* @param size the required size
*/
void * lv_mem_buf_get(uint32_t size);
/**
* Release a memory buffer
* @param p buffer to release
*/
void lv_mem_buf_release(void * p);
/**
* Free all memory buffers
*/
void lv_mem_buf_free_all(void);
//! @cond Doxygen_Suppress
#if LV_MEMCPY_MEMSET_STD
/**
* Wrapper for the standard memcpy
* @param dst pointer to the destination buffer
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
static inline void * lv_memcpy(void * dst, const void * src, size_t len)
{
return memcpy(dst, src, len);
}
/**
* Wrapper for the standard memcpy
* @param dst pointer to the destination buffer
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
static inline void * lv_memcpy_small(void * dst, const void * src, size_t len)
{
return memcpy(dst, src, len);
}
/**
* Wrapper for the standard memset
* @param dst pointer to the destination buffer
* @param v value to set [0..255]
* @param len number of byte to set
*/
static inline void lv_memset(void * dst, uint8_t v, size_t len)
{
memset(dst, v, len);
}
/**
* Wrapper for the standard memset with fixed 0x00 value
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
static inline void lv_memset_00(void * dst, size_t len)
{
memset(dst, 0x00, len);
}
/**
* Wrapper for the standard memset with fixed 0xFF value
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
static inline void lv_memset_ff(void * dst, size_t len)
{
memset(dst, 0xFF, len);
}
#else
/**
* Same as `memcpy` but optimized for 4 byte operation.
* @param dst pointer to the destination buffer
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len);
/**
* Same as `memcpy` but optimized to copy only a few bytes.
* @param dst pointer to the destination buffer
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
LV_ATTRIBUTE_FAST_MEM static inline void * lv_memcpy_small(void * dst, const void * src, size_t len)
{
uint8_t * d8 = (uint8_t *)dst;
const uint8_t * s8 = (const uint8_t *)src;
while(len) {
*d8 = *s8;
d8++;
s8++;
len--;
}
return dst;
}
/**
* Same as `memset` but optimized for 4 byte operation.
* @param dst pointer to the destination buffer
* @param v value to set [0..255]
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len);
/**
* Same as `memset(dst, 0x00, len)` but optimized for 4 byte operation.
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset_00(void * dst, size_t len);
/**
* Same as `memset(dst, 0xFF, len)` but optimized for 4 byte operation.
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset_ff(void * dst, size_t len);
//! @endcond
#endif
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_MEM_H*/
+92
View File
@@ -0,0 +1,92 @@
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland ([email protected])
// 2014-2019, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant.
//
///////////////////////////////////////////////////////////////////////////////
/*Original repository: https://github.com/mpaland/printf*/
#ifndef _LV_PRINTF_H_
#define _LV_PRINTF_H_
#if defined(__has_include)
#if __has_include(<inttypes.h>)
#include <inttypes.h>
/* platform-specific printf format for int32_t, usually "d" or "ld" */
#define LV_PRId32 PRId32
#define LV_PRIu32 PRIu32
#else
#define LV_PRId32 "d"
#define LV_PRIu32 "u"
#endif
#else
/* hope this is correct for ports without __has_include or without inttypes.h */
#define LV_PRId32 "d"
#define LV_PRIu32 "u"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include "../lv_conf_internal.h"
#if LV_SPRINTF_CUSTOM == 0
#include <stdarg.h>
#include <stddef.h>
#include "lv_types.h"
typedef struct {
const char * fmt;
va_list * va;
} lv_vaformat_t;
/**
* Tiny snprintf/vsnprintf implementation
* \param buffer A pointer to the buffer where to store the formatted string
* \param count The maximum number of characters to store in the buffer, including a terminating null character
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
* null character. A value equal or larger than count indicates truncation. Only when the returned value
* is non-negative and less than count, the string has been completely written.
*/
int lv_snprintf(char * buffer, size_t count, const char * format, ...) LV_FORMAT_ATTRIBUTE(3, 4);
int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va) LV_FORMAT_ATTRIBUTE(3, 0);
#else
#include LV_SPRINTF_INCLUDE
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif // _LV_PRINTF_H_
+592
View File
@@ -0,0 +1,592 @@
/**
* @file lv_style.h
*
*/
#ifndef LV_STYLE_H
#define LV_STYLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include <stdint.h>
#include "liblvgl/font/lv_font.h"
#include "lv_color.h"
#include "lv_area.h"
#include "lv_anim.h"
#include "lv_txt.h"
#include "lv_types.h"
#include "lv_assert.h"
#include "lv_bidi.h"
/*********************
* DEFINES
*********************/
#define LV_STYLE_SENTINEL_VALUE 0xAABBCCDD
/**
* Flags for style behavior
*
* The rest of the flags will have _FLAG added to their name in v9.
*/
#define LV_STYLE_PROP_FLAG_NONE (0)
#define LV_STYLE_PROP_INHERIT (1 << 0) /*Inherited*/
#define LV_STYLE_PROP_EXT_DRAW (1 << 1) /*Requires ext. draw size update when changed*/
#define LV_STYLE_PROP_LAYOUT_REFR (1 << 2) /*Requires layout update when changed*/
#define LV_STYLE_PROP_PARENT_LAYOUT_REFR (1 << 3) /*Requires layout update on parent when changed*/
#define LV_STYLE_PROP_LAYER_REFR (1 << 4) /*Affects layer handling*/
#define LV_STYLE_PROP_ALL (0x1F) /*Indicating all flags*/
/**
* Other constants
*/
#define LV_IMG_ZOOM_NONE 256 /*Value for not zooming the image*/
LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE);
// *INDENT-OFF*
#if LV_USE_ASSERT_STYLE
#define LV_STYLE_CONST_INIT(var_name, prop_array) \
const lv_style_t var_name = { \
.sentinel = LV_STYLE_SENTINEL_VALUE, \
.v_p = { .const_props = prop_array }, \
.has_group = 0xFF, \
.prop1 = LV_STYLE_PROP_ANY, \
.prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \
}
#else
#define LV_STYLE_CONST_INIT(var_name, prop_array) \
const lv_style_t var_name = { \
.v_p = { .const_props = prop_array }, \
.has_group = 0xFF, \
.prop1 = LV_STYLE_PROP_ANY, \
.prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \
}
#endif
// *INDENT-ON*
#define LV_STYLE_PROP_META_INHERIT 0x8000
#define LV_STYLE_PROP_META_INITIAL 0x4000
#define LV_STYLE_PROP_META_MASK (LV_STYLE_PROP_META_INHERIT | LV_STYLE_PROP_META_INITIAL)
#define LV_STYLE_PROP_ID_MASK(prop) ((lv_style_prop_t)((prop) & ~LV_STYLE_PROP_META_MASK))
/**********************
* TYPEDEFS
**********************/
/**
* Possible options how to blend opaque drawings
*/
enum {
LV_BLEND_MODE_NORMAL, /**< Simply mix according to the opacity value*/
LV_BLEND_MODE_ADDITIVE, /**< Add the respective color channels*/
LV_BLEND_MODE_SUBTRACTIVE,/**< Subtract the foreground from the background*/
LV_BLEND_MODE_MULTIPLY, /**< Multiply the foreground and background*/
LV_BLEND_MODE_REPLACE, /**< Replace background with foreground in the area*/
};
typedef uint8_t lv_blend_mode_t;
/**
* Some options to apply decorations on texts.
* 'OR'ed values can be used.
*/
enum {
LV_TEXT_DECOR_NONE = 0x00,
LV_TEXT_DECOR_UNDERLINE = 0x01,
LV_TEXT_DECOR_STRIKETHROUGH = 0x02,
};
typedef uint8_t lv_text_decor_t;
/**
* Selects on which sides border should be drawn
* 'OR'ed values can be used.
*/
enum {
LV_BORDER_SIDE_NONE = 0x00,
LV_BORDER_SIDE_BOTTOM = 0x01,
LV_BORDER_SIDE_TOP = 0x02,
LV_BORDER_SIDE_LEFT = 0x04,
LV_BORDER_SIDE_RIGHT = 0x08,
LV_BORDER_SIDE_FULL = 0x0F,
LV_BORDER_SIDE_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/
};
typedef uint8_t lv_border_side_t;
/**
* The direction of the gradient.
*/
enum {
LV_GRAD_DIR_NONE, /**< No gradient (the `grad_color` property is ignored)*/
LV_GRAD_DIR_VER, /**< Vertical (top to bottom) gradient*/
LV_GRAD_DIR_HOR, /**< Horizontal (left to right) gradient*/
};
typedef uint8_t lv_grad_dir_t;
/**
* The dithering algorithm for the gradient
* Depends on LV_DITHER_GRADIENT
*/
enum {
LV_DITHER_NONE, /**< No dithering, colors are just quantized to the output resolution*/
LV_DITHER_ORDERED, /**< Ordered dithering. Faster to compute and use less memory but lower quality*/
LV_DITHER_ERR_DIFF, /**< Error diffusion mode. Slower to compute and use more memory but give highest dither quality*/
};
typedef uint8_t lv_dither_mode_t;
/** A gradient stop definition.
* This matches a color and a position in a virtual 0-255 scale.
*/
typedef struct {
lv_color_t color; /**< The stop color */
uint8_t frac; /**< The stop position in 1/255 unit */
} lv_gradient_stop_t;
/** A descriptor of a gradient. */
typedef struct {
lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS]; /**< A gradient stop array */
uint8_t stops_count; /**< The number of used stops in the array */
lv_grad_dir_t dir : 3; /**< The gradient direction.
* Any of LV_GRAD_DIR_HOR, LV_GRAD_DIR_VER, LV_GRAD_DIR_NONE */
lv_dither_mode_t dither : 3; /**< Whether to dither the gradient or not.
* Any of LV_DITHER_NONE, LV_DITHER_ORDERED, LV_DITHER_ERR_DIFF */
} lv_grad_dsc_t;
/**
* A common type to handle all the property types in the same way.
*/
typedef union {
int32_t num; /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/
const void * ptr; /**< Constant pointers (font, cone text, etc)*/
lv_color_t color; /**< Colors*/
} lv_style_value_t;
/**
* Enumeration of all built in style properties
*
* Props are split into groups of 16. When adding a new prop to a group, ensure it does not overflow into the next one.
*/
typedef enum {
LV_STYLE_PROP_INV = 0,
/*Group 0*/
LV_STYLE_WIDTH = 1,
LV_STYLE_MIN_WIDTH = 2,
LV_STYLE_MAX_WIDTH = 3,
LV_STYLE_HEIGHT = 4,
LV_STYLE_MIN_HEIGHT = 5,
LV_STYLE_MAX_HEIGHT = 6,
LV_STYLE_X = 7,
LV_STYLE_Y = 8,
LV_STYLE_ALIGN = 9,
LV_STYLE_LAYOUT = 10,
LV_STYLE_RADIUS = 11,
/*Group 1*/
LV_STYLE_PAD_TOP = 16,
LV_STYLE_PAD_BOTTOM = 17,
LV_STYLE_PAD_LEFT = 18,
LV_STYLE_PAD_RIGHT = 19,
LV_STYLE_PAD_ROW = 20,
LV_STYLE_PAD_COLUMN = 21,
LV_STYLE_BASE_DIR = 22,
LV_STYLE_CLIP_CORNER = 23,
/*Group 2*/
LV_STYLE_BG_COLOR = 32,
LV_STYLE_BG_OPA = 33,
LV_STYLE_BG_GRAD_COLOR = 34,
LV_STYLE_BG_GRAD_DIR = 35,
LV_STYLE_BG_MAIN_STOP = 36,
LV_STYLE_BG_GRAD_STOP = 37,
LV_STYLE_BG_GRAD = 38,
LV_STYLE_BG_DITHER_MODE = 39,
LV_STYLE_BG_IMG_SRC = 40,
LV_STYLE_BG_IMG_OPA = 41,
LV_STYLE_BG_IMG_RECOLOR = 42,
LV_STYLE_BG_IMG_RECOLOR_OPA = 43,
LV_STYLE_BG_IMG_TILED = 44,
/*Group 3*/
LV_STYLE_BORDER_COLOR = 48,
LV_STYLE_BORDER_OPA = 49,
LV_STYLE_BORDER_WIDTH = 50,
LV_STYLE_BORDER_SIDE = 51,
LV_STYLE_BORDER_POST = 52,
LV_STYLE_OUTLINE_WIDTH = 53,
LV_STYLE_OUTLINE_COLOR = 54,
LV_STYLE_OUTLINE_OPA = 55,
LV_STYLE_OUTLINE_PAD = 56,
/*Group 4*/
LV_STYLE_SHADOW_WIDTH = 64,
LV_STYLE_SHADOW_OFS_X = 65,
LV_STYLE_SHADOW_OFS_Y = 66,
LV_STYLE_SHADOW_SPREAD = 67,
LV_STYLE_SHADOW_COLOR = 68,
LV_STYLE_SHADOW_OPA = 69,
LV_STYLE_IMG_OPA = 70,
LV_STYLE_IMG_RECOLOR = 71,
LV_STYLE_IMG_RECOLOR_OPA = 72,
LV_STYLE_LINE_WIDTH = 73,
LV_STYLE_LINE_DASH_WIDTH = 74,
LV_STYLE_LINE_DASH_GAP = 75,
LV_STYLE_LINE_ROUNDED = 76,
LV_STYLE_LINE_COLOR = 77,
LV_STYLE_LINE_OPA = 78,
/*Group 5*/
LV_STYLE_ARC_WIDTH = 80,
LV_STYLE_ARC_ROUNDED = 81,
LV_STYLE_ARC_COLOR = 82,
LV_STYLE_ARC_OPA = 83,
LV_STYLE_ARC_IMG_SRC = 84,
LV_STYLE_TEXT_COLOR = 85,
LV_STYLE_TEXT_OPA = 86,
LV_STYLE_TEXT_FONT = 87,
LV_STYLE_TEXT_LETTER_SPACE = 88,
LV_STYLE_TEXT_LINE_SPACE = 89,
LV_STYLE_TEXT_DECOR = 90,
LV_STYLE_TEXT_ALIGN = 91,
/*Group 6*/
LV_STYLE_OPA = 96,
LV_STYLE_COLOR_FILTER_DSC = 97,
LV_STYLE_COLOR_FILTER_OPA = 98,
LV_STYLE_ANIM = 99,
LV_STYLE_ANIM_TIME = 100,
LV_STYLE_ANIM_SPEED = 101,
LV_STYLE_TRANSITION = 102,
LV_STYLE_BLEND_MODE = 103,
LV_STYLE_TRANSFORM_WIDTH = 104,
LV_STYLE_TRANSFORM_HEIGHT = 105,
LV_STYLE_TRANSLATE_X = 106,
LV_STYLE_TRANSLATE_Y = 107,
LV_STYLE_TRANSFORM_ZOOM = 108,
LV_STYLE_TRANSFORM_ANGLE = 109,
LV_STYLE_TRANSFORM_PIVOT_X = 110,
LV_STYLE_TRANSFORM_PIVOT_Y = 111,
_LV_STYLE_LAST_BUILT_IN_PROP = 111,
_LV_STYLE_NUM_BUILT_IN_PROPS = _LV_STYLE_LAST_BUILT_IN_PROP + 1,
LV_STYLE_PROP_ANY = 0xFFFF,
_LV_STYLE_PROP_CONST = 0xFFFF /* magic value for const styles */
} lv_style_prop_t;
enum {
LV_STYLE_RES_NOT_FOUND,
LV_STYLE_RES_FOUND,
LV_STYLE_RES_INHERIT
};
typedef uint8_t lv_style_res_t;
/**
* Descriptor for style transitions
*/
typedef struct {
const lv_style_prop_t * props; /**< An array with the properties to animate.*/
#if LV_USE_USER_DATA
void * user_data; /**< A custom user data that will be passed to the animation's user_data */
#endif
lv_anim_path_cb_t path_xcb; /**< A path for the animation.*/
uint32_t time; /**< Duration of the transition in [ms]*/
uint32_t delay; /**< Delay before the transition in [ms]*/
} lv_style_transition_dsc_t;
/**
* Descriptor of a constant style property.
*/
typedef struct {
lv_style_prop_t prop;
lv_style_value_t value;
} lv_style_const_prop_t;
/**
* Descriptor of a style (a collection of properties and values).
*/
typedef struct {
#if LV_USE_ASSERT_STYLE
uint32_t sentinel;
#endif
/*If there is only one property store it directly.
*For more properties allocate an array*/
union {
lv_style_value_t value1;
uint8_t * values_and_props;
const lv_style_const_prop_t * const_props;
} v_p;
uint16_t prop1;
uint8_t has_group;
uint8_t prop_cnt;
} lv_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a style
* @param style pointer to a style to initialize
* @note Do not call `lv_style_init` on styles that already have some properties
* because this function won't free the used memory, just sets a default state for the style.
* In other words be sure to initialize styles only once!
*/
void lv_style_init(lv_style_t * style);
/**
* Clear all properties from a style and free all allocated memories.
* @param style pointer to a style
*/
void lv_style_reset(lv_style_t * style);
/**
* Register a new style property for custom usage
* @return a new property ID, or LV_STYLE_PROP_INV if there are no more available.
* @example
* lv_style_prop_t MY_PROP;
* static inline void lv_style_set_my_prop(lv_style_t * style, lv_color_t value) {
* lv_style_value_t v = {.color = value}; lv_style_set_prop(style, MY_PROP, v); }
*
* ...
* MY_PROP = lv_style_register_prop();
* ...
* lv_style_set_my_prop(&style1, lv_palette_main(LV_PALETTE_RED));
*/
lv_style_prop_t lv_style_register_prop(uint8_t flag);
/**
* Get the number of custom properties that have been registered thus far.
*/
lv_style_prop_t lv_style_get_num_custom_props(void);
/**
* Remove a property from a style
* @param style pointer to a style
* @param prop a style property ORed with a state.
* @return true: the property was found and removed; false: the property wasn't found
*/
bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop);
/**
* Set the value of property in a style.
* This function shouldn't be used directly by the user.
* Instead use `lv_style_set_<prop_name>()`. E.g. `lv_style_set_bg_color()`
* @param style pointer to style
* @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`)
* @param value `lv_style_value_t` variable in which a field is set according to the type of `prop`
*/
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value);
/**
* Set a special meta state for a property in a style.
* This function shouldn't be used directly by the user.
* @param style pointer to style
* @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`)
* @param meta the meta value to attach to the property in the style
*/
void lv_style_set_prop_meta(lv_style_t * style, lv_style_prop_t prop, uint16_t meta);
/**
* Get the value of a property
* @param style pointer to a style
* @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value
* @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged)
* LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
*/
lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
/**
* Initialize a transition descriptor.
* @param tr pointer to a transition descriptor to initialize
* @param props an array with the properties to transition. The last element must be zero.
* @param path_cb an animation path (ease) callback. If `NULL` liner path will be used.
* @param time duration of the transition in [ms]
* @param delay delay before the transition in [ms]
* @param user_data any custom data that will be saved in the transition animation and will be available when `path_cb` is called
* @example
* const static lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, 0 };
* static lv_style_transition_dsc_t trans1;
* lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL);
*/
void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[],
lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data);
/**
* Get the default value of a property
* @param prop the ID of a property
* @return the default value
*/
lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop);
/**
* Get the value of a property
* @param style pointer to a style
* @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value
* @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged)
* LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
* @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places
*/
static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop,
lv_style_value_t * value)
{
if(style->prop1 == LV_STYLE_PROP_ANY) {
const lv_style_const_prop_t * const_prop;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
const_prop = style->v_p.const_props + i;
lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(const_prop->prop);
if(prop_id == prop) {
if(const_prop->prop & LV_STYLE_PROP_META_INHERIT)
return LV_STYLE_RES_INHERIT;
*value = (const_prop->prop & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(prop_id) : const_prop->value;
return LV_STYLE_RES_FOUND;
}
}
return LV_STYLE_RES_NOT_FOUND;
}
if(style->prop_cnt == 0) return LV_STYLE_RES_NOT_FOUND;
if(style->prop_cnt > 1) {
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(props[i]);
if(prop_id == prop) {
if(props[i] & LV_STYLE_PROP_META_INHERIT)
return LV_STYLE_RES_INHERIT;
if(props[i] & LV_STYLE_PROP_META_INITIAL)
*value = lv_style_prop_get_default(prop_id);
else {
lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
*value = values[i];
}
return LV_STYLE_RES_FOUND;
}
}
}
else if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop) {
if(style->prop1 & LV_STYLE_PROP_META_INHERIT)
return LV_STYLE_RES_INHERIT;
*value = (style->prop1 & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(LV_STYLE_PROP_ID_MASK(
style->prop1)) : style->v_p.value1;
return LV_STYLE_RES_FOUND;
}
return LV_STYLE_RES_NOT_FOUND;
}
/**
* Checks if a style is empty (has no properties)
* @param style pointer to a style
* @return true if the style is empty
*/
bool lv_style_is_empty(const lv_style_t * style);
/**
* Tell the group of a property. If the a property from a group is set in a style the (1 << group) bit of style->has_group is set.
* It allows early skipping the style if the property is not exists in the style at all.
* @param prop a style property
* @return the group [0..7] 7 means all the custom properties with index > 112
*/
uint8_t _lv_style_get_prop_group(lv_style_prop_t prop);
/**
* Get the flags of a built-in or custom property.
*
* @param prop a style property
* @return the flags of the property
*/
uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop);
#include "lv_style_gen.h"
static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value)
{
lv_style_set_width(style, value);
lv_style_set_height(style, value);
}
static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
{
lv_style_set_pad_left(style, value);
lv_style_set_pad_right(style, value);
lv_style_set_pad_top(style, value);
lv_style_set_pad_bottom(style, value);
}
static inline void lv_style_set_pad_hor(lv_style_t * style, lv_coord_t value)
{
lv_style_set_pad_left(style, value);
lv_style_set_pad_right(style, value);
}
static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value)
{
lv_style_set_pad_top(style, value);
lv_style_set_pad_bottom(style, value);
}
static inline void lv_style_set_pad_gap(lv_style_t * style, lv_coord_t value)
{
lv_style_set_pad_row(style, value);
lv_style_set_pad_column(style, value);
}
/**
* @brief Check if the style property has a specified behavioral flag.
*
* Do not pass multiple flags to this function as backwards-compatibility is not guaranteed
* for that.
*
* @param prop Property ID
* @param flag Flag
* @return true if the flag is set for this property
*/
static inline bool lv_style_prop_has_flag(lv_style_prop_t prop, uint8_t flag)
{
return _lv_style_prop_lookup_flags(prop) & flag;
}
/*************************
* GLOBAL VARIABLES
*************************/
/**********************
* MACROS
**********************/
#if LV_USE_ASSERT_STYLE
# define LV_ASSERT_STYLE(style_p) \
do { \
LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \
LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); \
} while(0)
#else
# define LV_ASSERT_STYLE(p) do{}while(0)
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_STYLE_H*/
+504
View File
@@ -0,0 +1,504 @@
void lv_style_set_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_min_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_max_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_height(lv_style_t * style, lv_coord_t value);
void lv_style_set_min_height(lv_style_t * style, lv_coord_t value);
void lv_style_set_max_height(lv_style_t * style, lv_coord_t value);
void lv_style_set_x(lv_style_t * style, lv_coord_t value);
void lv_style_set_y(lv_style_t * style, lv_coord_t value);
void lv_style_set_align(lv_style_t * style, lv_align_t value);
void lv_style_set_transform_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_height(lv_style_t * style, lv_coord_t value);
void lv_style_set_translate_x(lv_style_t * style, lv_coord_t value);
void lv_style_set_translate_y(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_pivot_x(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_pivot_y(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_top(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_bottom(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_left(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_right(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_row(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_column(lv_style_t * style, lv_coord_t value);
void lv_style_set_bg_color(lv_style_t * style, lv_color_t value);
void lv_style_set_bg_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_bg_grad_color(lv_style_t * style, lv_color_t value);
void lv_style_set_bg_grad_dir(lv_style_t * style, lv_grad_dir_t value);
void lv_style_set_bg_main_stop(lv_style_t * style, lv_coord_t value);
void lv_style_set_bg_grad_stop(lv_style_t * style, lv_coord_t value);
void lv_style_set_bg_grad(lv_style_t * style, const lv_grad_dsc_t * value);
void lv_style_set_bg_dither_mode(lv_style_t * style, lv_dither_mode_t value);
void lv_style_set_bg_img_src(lv_style_t * style, const void * value);
void lv_style_set_bg_img_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_bg_img_recolor(lv_style_t * style, lv_color_t value);
void lv_style_set_bg_img_recolor_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_bg_img_tiled(lv_style_t * style, bool value);
void lv_style_set_border_color(lv_style_t * style, lv_color_t value);
void lv_style_set_border_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_border_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_border_side(lv_style_t * style, lv_border_side_t value);
void lv_style_set_border_post(lv_style_t * style, bool value);
void lv_style_set_outline_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_outline_color(lv_style_t * style, lv_color_t value);
void lv_style_set_outline_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_outline_pad(lv_style_t * style, lv_coord_t value);
void lv_style_set_shadow_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_shadow_ofs_x(lv_style_t * style, lv_coord_t value);
void lv_style_set_shadow_ofs_y(lv_style_t * style, lv_coord_t value);
void lv_style_set_shadow_spread(lv_style_t * style, lv_coord_t value);
void lv_style_set_shadow_color(lv_style_t * style, lv_color_t value);
void lv_style_set_shadow_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_img_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_img_recolor(lv_style_t * style, lv_color_t value);
void lv_style_set_img_recolor_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_line_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_line_dash_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_line_dash_gap(lv_style_t * style, lv_coord_t value);
void lv_style_set_line_rounded(lv_style_t * style, bool value);
void lv_style_set_line_color(lv_style_t * style, lv_color_t value);
void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_arc_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_arc_rounded(lv_style_t * style, bool value);
void lv_style_set_arc_color(lv_style_t * style, lv_color_t value);
void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_arc_img_src(lv_style_t * style, const void * value);
void lv_style_set_text_color(lv_style_t * style, lv_color_t value);
void lv_style_set_text_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_text_font(lv_style_t * style, const lv_font_t * value);
void lv_style_set_text_letter_space(lv_style_t * style, lv_coord_t value);
void lv_style_set_text_line_space(lv_style_t * style, lv_coord_t value);
void lv_style_set_text_decor(lv_style_t * style, lv_text_decor_t value);
void lv_style_set_text_align(lv_style_t * style, lv_text_align_t value);
void lv_style_set_radius(lv_style_t * style, lv_coord_t value);
void lv_style_set_clip_corner(lv_style_t * style, bool value);
void lv_style_set_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value);
void lv_style_set_color_filter_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value);
void lv_style_set_anim_time(lv_style_t * style, uint32_t value);
void lv_style_set_anim_speed(lv_style_t * style, uint32_t value);
void lv_style_set_transition(lv_style_t * style, const lv_style_transition_dsc_t * value);
void lv_style_set_blend_mode(lv_style_t * style, lv_blend_mode_t value);
void lv_style_set_layout(lv_style_t * style, uint16_t value);
void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value);
#define LV_STYLE_CONST_WIDTH(val) \
{ \
.prop = LV_STYLE_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MIN_WIDTH(val) \
{ \
.prop = LV_STYLE_MIN_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MAX_WIDTH(val) \
{ \
.prop = LV_STYLE_MAX_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_HEIGHT(val) \
{ \
.prop = LV_STYLE_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MIN_HEIGHT(val) \
{ \
.prop = LV_STYLE_MIN_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MAX_HEIGHT(val) \
{ \
.prop = LV_STYLE_MAX_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_X(val) \
{ \
.prop = LV_STYLE_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_Y(val) \
{ \
.prop = LV_STYLE_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ALIGN(val) \
{ \
.prop = LV_STYLE_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_WIDTH(val) \
{ \
.prop = LV_STYLE_TRANSFORM_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_HEIGHT(val) \
{ \
.prop = LV_STYLE_TRANSFORM_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSLATE_X(val) \
{ \
.prop = LV_STYLE_TRANSLATE_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSLATE_Y(val) \
{ \
.prop = LV_STYLE_TRANSLATE_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_ZOOM(val) \
{ \
.prop = LV_STYLE_TRANSFORM_ZOOM, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_ANGLE(val) \
{ \
.prop = LV_STYLE_TRANSFORM_ANGLE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_PIVOT_X(val) \
{ \
.prop = LV_STYLE_TRANSFORM_PIVOT_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_PIVOT_Y(val) \
{ \
.prop = LV_STYLE_TRANSFORM_PIVOT_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_TOP(val) \
{ \
.prop = LV_STYLE_PAD_TOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_BOTTOM(val) \
{ \
.prop = LV_STYLE_PAD_BOTTOM, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_LEFT(val) \
{ \
.prop = LV_STYLE_PAD_LEFT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_RIGHT(val) \
{ \
.prop = LV_STYLE_PAD_RIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_ROW(val) \
{ \
.prop = LV_STYLE_PAD_ROW, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_COLUMN(val) \
{ \
.prop = LV_STYLE_PAD_COLUMN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_COLOR(val) \
{ \
.prop = LV_STYLE_BG_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BG_OPA(val) \
{ \
.prop = LV_STYLE_BG_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD_COLOR(val) \
{ \
.prop = LV_STYLE_BG_GRAD_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BG_GRAD_DIR(val) \
{ \
.prop = LV_STYLE_BG_GRAD_DIR, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_MAIN_STOP(val) \
{ \
.prop = LV_STYLE_BG_MAIN_STOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD_STOP(val) \
{ \
.prop = LV_STYLE_BG_GRAD_STOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD(val) \
{ \
.prop = LV_STYLE_BG_GRAD, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_BG_DITHER_MODE(val) \
{ \
.prop = LV_STYLE_BG_DITHER_MODE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_IMG_SRC(val) \
{ \
.prop = LV_STYLE_BG_IMG_SRC, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_BG_IMG_OPA(val) \
{ \
.prop = LV_STYLE_BG_IMG_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_IMG_RECOLOR(val) \
{ \
.prop = LV_STYLE_BG_IMG_RECOLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BG_IMG_RECOLOR_OPA(val) \
{ \
.prop = LV_STYLE_BG_IMG_RECOLOR_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_IMG_TILED(val) \
{ \
.prop = LV_STYLE_BG_IMG_TILED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_COLOR(val) \
{ \
.prop = LV_STYLE_BORDER_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BORDER_OPA(val) \
{ \
.prop = LV_STYLE_BORDER_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_WIDTH(val) \
{ \
.prop = LV_STYLE_BORDER_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_SIDE(val) \
{ \
.prop = LV_STYLE_BORDER_SIDE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_POST(val) \
{ \
.prop = LV_STYLE_BORDER_POST, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OUTLINE_WIDTH(val) \
{ \
.prop = LV_STYLE_OUTLINE_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OUTLINE_COLOR(val) \
{ \
.prop = LV_STYLE_OUTLINE_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_OUTLINE_OPA(val) \
{ \
.prop = LV_STYLE_OUTLINE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OUTLINE_PAD(val) \
{ \
.prop = LV_STYLE_OUTLINE_PAD, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_WIDTH(val) \
{ \
.prop = LV_STYLE_SHADOW_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_OFS_X(val) \
{ \
.prop = LV_STYLE_SHADOW_OFS_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_OFS_Y(val) \
{ \
.prop = LV_STYLE_SHADOW_OFS_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_SPREAD(val) \
{ \
.prop = LV_STYLE_SHADOW_SPREAD, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_COLOR(val) \
{ \
.prop = LV_STYLE_SHADOW_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_SHADOW_OPA(val) \
{ \
.prop = LV_STYLE_SHADOW_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_IMG_OPA(val) \
{ \
.prop = LV_STYLE_IMG_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_IMG_RECOLOR(val) \
{ \
.prop = LV_STYLE_IMG_RECOLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_IMG_RECOLOR_OPA(val) \
{ \
.prop = LV_STYLE_IMG_RECOLOR_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_WIDTH(val) \
{ \
.prop = LV_STYLE_LINE_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_DASH_WIDTH(val) \
{ \
.prop = LV_STYLE_LINE_DASH_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_DASH_GAP(val) \
{ \
.prop = LV_STYLE_LINE_DASH_GAP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_ROUNDED(val) \
{ \
.prop = LV_STYLE_LINE_ROUNDED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_COLOR(val) \
{ \
.prop = LV_STYLE_LINE_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_LINE_OPA(val) \
{ \
.prop = LV_STYLE_LINE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_WIDTH(val) \
{ \
.prop = LV_STYLE_ARC_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_ROUNDED(val) \
{ \
.prop = LV_STYLE_ARC_ROUNDED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_COLOR(val) \
{ \
.prop = LV_STYLE_ARC_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_ARC_OPA(val) \
{ \
.prop = LV_STYLE_ARC_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_IMG_SRC(val) \
{ \
.prop = LV_STYLE_ARC_IMG_SRC, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_TEXT_COLOR(val) \
{ \
.prop = LV_STYLE_TEXT_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_TEXT_OPA(val) \
{ \
.prop = LV_STYLE_TEXT_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_FONT(val) \
{ \
.prop = LV_STYLE_TEXT_FONT, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_TEXT_LETTER_SPACE(val) \
{ \
.prop = LV_STYLE_TEXT_LETTER_SPACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_LINE_SPACE(val) \
{ \
.prop = LV_STYLE_TEXT_LINE_SPACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_DECOR(val) \
{ \
.prop = LV_STYLE_TEXT_DECOR, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_ALIGN(val) \
{ \
.prop = LV_STYLE_TEXT_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_RADIUS(val) \
{ \
.prop = LV_STYLE_RADIUS, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_CLIP_CORNER(val) \
{ \
.prop = LV_STYLE_CLIP_CORNER, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OPA(val) \
{ \
.prop = LV_STYLE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_COLOR_FILTER_DSC(val) \
{ \
.prop = LV_STYLE_COLOR_FILTER_DSC, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_COLOR_FILTER_OPA(val) \
{ \
.prop = LV_STYLE_COLOR_FILTER_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ANIM(val) \
{ \
.prop = LV_STYLE_ANIM, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_ANIM_TIME(val) \
{ \
.prop = LV_STYLE_ANIM_TIME, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ANIM_SPEED(val) \
{ \
.prop = LV_STYLE_ANIM_SPEED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSITION(val) \
{ \
.prop = LV_STYLE_TRANSITION, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_BLEND_MODE(val) \
{ \
.prop = LV_STYLE_BLEND_MODE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LAYOUT(val) \
{ \
.prop = LV_STYLE_LAYOUT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BASE_DIR(val) \
{ \
.prop = LV_STYLE_BASE_DIR, .value = { .num = (int32_t)val } \
}
+37
View File
@@ -0,0 +1,37 @@
/**
* @file lv_templ.h
*
*/
#ifndef LV_TEMPL_H
#define LV_TEMPL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TEMPL_H*/
+183
View File
@@ -0,0 +1,183 @@
/**
* @file lv_timer.h
*/
#ifndef LV_TIMER_H
#define LV_TIMER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include "liblvgl/hal/lv_hal_tick.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
#ifndef LV_ATTRIBUTE_TIMER_HANDLER
#define LV_ATTRIBUTE_TIMER_HANDLER
#endif
#define LV_NO_TIMER_READY 0xFFFFFFFF
/**********************
* TYPEDEFS
**********************/
struct _lv_timer_t;
/**
* Timers execute this type of functions.
*/
typedef void (*lv_timer_cb_t)(struct _lv_timer_t *);
/**
* Descriptor of a lv_timer
*/
typedef struct _lv_timer_t {
uint32_t period; /**< How often the timer should run*/
uint32_t last_run; /**< Last time the timer ran*/
lv_timer_cb_t timer_cb; /**< Timer function*/
void * user_data; /**< Custom user data*/
int32_t repeat_count; /**< 1: One time; -1 : infinity; n>0: residual times*/
uint32_t paused : 1;
} lv_timer_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init the lv_timer module
*/
void _lv_timer_core_init(void);
//! @cond Doxygen_Suppress
/**
* Call it periodically to handle lv_timers.
* @return time till it needs to be run next (in ms)
*/
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
//! @endcond
/**
* Call it in the super-loop of main() or threads. It will run lv_timer_handler()
* with a given period in ms. You can use it with sleep or delay in OS environment.
* This function is used to simplify the porting.
* @param __ms the period for running lv_timer_handler()
*/
static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period(uint32_t ms)
{
static uint32_t last_tick = 0;
uint32_t curr_tick = lv_tick_get();
if((curr_tick - last_tick) >= (ms)) {
last_tick = curr_tick;
return lv_timer_handler();
}
return 1;
}
/**
* Create an "empty" timer. It needs to initialized with at least
* `lv_timer_set_cb` and `lv_timer_set_period`
* @return pointer to the created timer
*/
lv_timer_t * lv_timer_create_basic(void);
/**
* Create a new lv_timer
* @param timer_xcb a callback to call periodically.
* (the 'x' in the argument name indicates that it's not a fully generic function because it not follows
* the `func_name(object, callback, ...)` convention)
* @param period call period in ms unit
* @param user_data custom parameter
* @return pointer to the new timer
*/
lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data);
/**
* Delete a lv_timer
* @param timer pointer to an lv_timer
*/
void lv_timer_del(lv_timer_t * timer);
/**
* Pause/resume a timer.
* @param timer pointer to an lv_timer
*/
void lv_timer_pause(lv_timer_t * timer);
void lv_timer_resume(lv_timer_t * timer);
/**
* Set the callback the timer (the function to call periodically)
* @param timer pointer to a timer
* @param timer_cb the function to call periodically
*/
void lv_timer_set_cb(lv_timer_t * timer, lv_timer_cb_t timer_cb);
/**
* Set new period for a lv_timer
* @param timer pointer to a lv_timer
* @param period the new period
*/
void lv_timer_set_period(lv_timer_t * timer, uint32_t period);
/**
* Make a lv_timer ready. It will not wait its period.
* @param timer pointer to a lv_timer.
*/
void lv_timer_ready(lv_timer_t * timer);
/**
* Set the number of times a timer will repeat.
* @param timer pointer to a lv_timer.
* @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times
*/
void lv_timer_set_repeat_count(lv_timer_t * timer, int32_t repeat_count);
/**
* Reset a lv_timer.
* It will be called the previously set period milliseconds later.
* @param timer pointer to a lv_timer.
*/
void lv_timer_reset(lv_timer_t * timer);
/**
* Enable or disable the whole lv_timer handling
* @param en true: lv_timer handling is running, false: lv_timer handling is suspended
*/
void lv_timer_enable(bool en);
/**
* Get idle percentage
* @return the lv_timer idle in percentage
*/
uint8_t lv_timer_get_idle(void);
/**
* Iterate through the timers
* @param timer NULL to start iteration or the previous return value to get the next timer
* @return the next timer or NULL if there is no more timer
*/
lv_timer_t * lv_timer_get_next(lv_timer_t * timer);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
+95
View File
@@ -0,0 +1,95 @@
#include "../lv_conf_internal.h"
#if LV_MEM_CUSTOM == 0
#ifndef LV_TLSF_H
#define LV_TLSF_H
/*
** Two Level Segregated Fit memory allocator, version 3.1.
** Written by Matthew Conte
** http://tlsf.baisoku.org
**
** Based on the original documentation by Miguel Masmano:
** http://www.gii.upv.es/tlsf/main/docs
**
** This implementation was written to the specification
** of the document, therefore no GPL restrictions apply.
**
** Copyright (c) 2006-2016, Matthew Conte
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stddef.h>
#if defined(__cplusplus)
extern "C" {
#endif
/* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */
/* lv_pool_t: a block of memory that TLSF can manage. */
typedef void * lv_tlsf_t;
typedef void * lv_pool_t;
/* Create/destroy a memory pool. */
lv_tlsf_t lv_tlsf_create(void * mem);
lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes);
void lv_tlsf_destroy(lv_tlsf_t tlsf);
lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf);
/* Add/remove memory pools. */
lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes);
void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool);
/* malloc/memalign/realloc/free replacements. */
void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes);
void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes);
void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size);
size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr);
/* Returns internal block size, not original request size */
size_t lv_tlsf_block_size(void * ptr);
/* Overheads/limits of internal structures. */
size_t lv_tlsf_size(void);
size_t lv_tlsf_align_size(void);
size_t lv_tlsf_block_size_min(void);
size_t lv_tlsf_block_size_max(void);
size_t lv_tlsf_pool_overhead(void);
size_t lv_tlsf_alloc_overhead(void);
/* Debugging. */
typedef void (*lv_tlsf_walker)(void * ptr, size_t size, int used, void * user);
void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user);
/* Returns nonzero if any internal consistency check fails. */
int lv_tlsf_check(lv_tlsf_t tlsf);
int lv_tlsf_check_pool(lv_pool_t pool);
#if defined(__cplusplus)
};
#endif
#endif /*LV_TLSF_H*/
#endif /* LV_MEM_CUSTOM == 0 */
+264
View File
@@ -0,0 +1,264 @@
/**
* @file lv_txt.h
*
*/
#ifndef LV_TXT_H
#define LV_TXT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "liblvgl/lv_conf_internal.h"
#include <stdbool.h>
#include <stdarg.h>
#include "lv_area.h"
#include "liblvgl/font/lv_font.h"
#include "lv_printf.h"
#include "lv_types.h"
/*********************
* DEFINES
*********************/
#ifndef LV_TXT_COLOR_CMD
#define LV_TXT_COLOR_CMD "#"
#endif
#define LV_TXT_ENC_UTF8 1
#define LV_TXT_ENC_ASCII 2
/**********************
* TYPEDEFS
**********************/
/**
* Options for text rendering.
*/
enum {
LV_TEXT_FLAG_NONE = 0x00,
LV_TEXT_FLAG_RECOLOR = 0x01, /**< Enable parsing of recolor command*/
LV_TEXT_FLAG_EXPAND = 0x02, /**< Ignore max-width to avoid automatic word wrapping*/
LV_TEXT_FLAG_FIT = 0x04, /**< Max-width is already equal to the longest line. (Used to skip some calculation)*/
};
typedef uint8_t lv_text_flag_t;
/**
* State machine for text renderer.*/
enum {
LV_TEXT_CMD_STATE_WAIT, /**< Waiting for command*/
LV_TEXT_CMD_STATE_PAR, /**< Processing the parameter*/
LV_TEXT_CMD_STATE_IN, /**< Processing the command*/
};
typedef uint8_t lv_text_cmd_state_t;
/** Label align policy*/
enum {
LV_TEXT_ALIGN_AUTO, /**< Align text auto*/
LV_TEXT_ALIGN_LEFT, /**< Align text to left*/
LV_TEXT_ALIGN_CENTER, /**< Align text to center*/
LV_TEXT_ALIGN_RIGHT, /**< Align text to right*/
};
typedef uint8_t lv_text_align_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Get size of a text
* @param size_res pointer to a 'point_t' variable to store the result
* @param text pointer to a text
* @param font pointer to font of the text
* @param letter_space letter space of the text
* @param line_space line space of the text
* @param flags settings for the text from ::lv_text_flag_t
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
* line breaks
*/
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, lv_coord_t letter_space,
lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag);
/**
* Get the next line of text. Check line length and break chars too.
* @param txt a '\0' terminated string
* @param font pointer to a font
* @param letter_space letter space
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
* line breaks
* @param used_width When used_width != NULL, save the width of this line if
* flag == LV_TEXT_FLAG_NONE, otherwise save -1.
* @param flags settings for the text from 'txt_flag_type' enum
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8
* they are different)
*/
uint32_t _lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord_t letter_space,
lv_coord_t max_width, lv_coord_t * used_width, lv_text_flag_t flag);
/**
* Give the length of a text with a given font
* @param txt a '\0' terminate string
* @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in
* UTF-8)
* @param font pointer to a font
* @param letter_space letter space
* @param flags settings for the text from 'txt_flag_t' enum
* @return length of a char_num long text
*/
lv_coord_t lv_txt_get_width(const char * txt, uint32_t length, const lv_font_t * font, lv_coord_t letter_space,
lv_text_flag_t flag);
/**
* Check next character in a string and decide if the character is part of the command or not
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command
* processing
* @param c the current character
* @return true: the character is part of a command and should not be written,
* false: the character should be written
*/
bool _lv_txt_is_cmd(lv_text_cmd_state_t * state, uint32_t c);
/**
* Insert a string into an other
* @param txt_buf the original text (must be big enough for the result text and NULL terminated)
* @param pos position to insert (0: before the original text, 1: after the first char etc.)
* @param ins_txt text to insert, must be '\0' terminated
*/
void _lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt);
/**
* Delete a part of a string
* @param txt string to modify, must be '\0' terminated and should point to a heap or stack frame, not read-only memory.
* @param pos position where to start the deleting (0: before the first char, 1: after the first
* char etc.)
* @param len number of characters to delete
*/
void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len);
/**
* return a new formatted text. Memory will be allocated to store the text.
* @param fmt `printf`-like format
* @return pointer to the allocated text string.
*/
char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0);
/**
* Decode two encoded character from a string.
* @param txt pointer to '\0' terminated string
* @param letter the first decoded Unicode character or 0 on invalid data code
* @param letter_next the second decoded Unicode character or 0 on invalid data code
* @param ofs start index in 'txt' where to start.
* After the call it will point to the next encoded char in 'txt'.
* NULL to use txt[0] as index
*/
void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs);
/**
* Test if char is break char or not (a text can broken here or not)
* @param letter a letter
* @return false: 'letter' is not break char
*/
static inline bool _lv_txt_is_break_char(uint32_t letter)
{
uint8_t i;
bool ret = false;
/* each chinese character can be break */
if(letter >= 0x4E00 && letter <= 0x9FA5) {
return true;
}
/*Compare the letter to TXT_BREAK_CHARS*/
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
ret = true; /*If match then it is break char*/
break;
}
}
return ret;
}
/***************************************************************
* GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE
***************************************************************/
/**
* Give the size of an encoded character
* @param str pointer to a character in a string
* @return length of the encoded character (1,2,3 ...). O in invalid
*/
extern uint8_t (*_lv_txt_encoded_size)(const char *);
/**
* Convert a Unicode letter to encoded
* @param letter_uni a Unicode letter
* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')
*/
extern uint32_t (*_lv_txt_unicode_to_encoded)(uint32_t);
/**
* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.
* @param c a wide character
* @return `c` in the encoded format
*/
extern uint32_t (*_lv_txt_encoded_conv_wc)(uint32_t c);
/**
* Decode the next encoded character from a string.
* @param txt pointer to '\0' terminated string
* @param i start index in 'txt' where to start.
* After the call it will point to the next encoded char in 'txt'.
* NULL to use txt[0] as index
* @return the decoded Unicode character or 0 on invalid data code
*/
extern uint32_t (*_lv_txt_encoded_next)(const char *, uint32_t *);
/**
* Get the previous encoded character form a string.
* @param txt pointer to '\0' terminated string
* @param i_start index in 'txt' where to start. After the call it will point to the previous
* encoded char in 'txt'.
* @return the decoded Unicode character or 0 on invalid data
*/
extern uint32_t (*_lv_txt_encoded_prev)(const char *, uint32_t *);
/**
* Convert a letter index (in the encoded text) to byte index.
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param enc_id letter index
* @return byte index of the 'enc_id'th letter
*/
extern uint32_t (*_lv_txt_encoded_get_byte_id)(const char *, uint32_t);
/**
* Convert a byte index (in an encoded text) to character index.
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param byte_id byte index
* @return character index of the letter at 'byte_id'th position
*/
extern uint32_t (*_lv_txt_encoded_get_char_id)(const char *, uint32_t);
/**
* Get the number of characters (and NOT bytes) in a string.
* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)
* @param txt a '\0' terminated char string
* @return number of characters
*/
extern uint32_t (*_lv_txt_get_encoded_length)(const char *);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TXT_H*/
+49
View File
@@ -0,0 +1,49 @@
/**
* @file lv_txt_ap.h
*
*/
#ifndef LV_TXT_AP_H
#define LV_TXT_AP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_txt.h"
#include "liblvgl/draw/lv_draw.h"
#if LV_USE_ARABIC_PERSIAN_CHARS == 1
/*********************
* DEFINES
*********************/
#define LV_UNDEF_ARABIC_PERSIAN_CHARS (UINT32_MAX)
#define LV_AP_ALPHABET_BASE_CODE 0x0622
#define LV_AP_END_CHARS_LIST {0,0,0,0,0,{0,0}}
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
uint32_t _lv_txt_ap_calc_bytes_cnt(const char * txt);
void _lv_txt_ap_proc(const char * txt, char * txt_out);
/**********************
* MACROS
**********************/
#endif // LV_USE_ARABIC_PERSIAN_CHARS
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TXT_AP_H*/
+94
View File
@@ -0,0 +1,94 @@
/**
* @file lv_types.h
*
*/
#ifndef LV_TYPES_H
#define LV_TYPES_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
/*********************
* DEFINES
*********************/
// If __UINTPTR_MAX__ or UINTPTR_MAX are available, use them to determine arch size
#if defined(__UINTPTR_MAX__) && __UINTPTR_MAX__ > 0xFFFFFFFF
#define LV_ARCH_64
#elif defined(UINTPTR_MAX) && UINTPTR_MAX > 0xFFFFFFFF
#define LV_ARCH_64
// Otherwise use compiler-dependent means to determine arch size
#elif defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined (__aarch64__)
#define LV_ARCH_64
#endif
/**********************
* TYPEDEFS
**********************/
/**
* LVGL error codes.
*/
enum {
LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action
function or an operation was failed*/
LV_RES_OK, /*The object is valid (no deleted) after the action*/
};
typedef uint8_t lv_res_t;
#if defined(__cplusplus) || __STDC_VERSION__ >= 199901L
// If c99 or newer, use the definition of uintptr_t directly from <stdint.h>
typedef uintptr_t lv_uintptr_t;
#else
// Otherwise, use the arch size determination
#ifdef LV_ARCH_64
typedef uint64_t lv_uintptr_t;
#else
typedef uint32_t lv_uintptr_t;
#endif
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#define LV_UNUSED(x) ((void)x)
#define _LV_CONCAT(x, y) x ## y
#define LV_CONCAT(x, y) _LV_CONCAT(x, y)
#define _LV_CONCAT3(x, y, z) x ## y ## z
#define LV_CONCAT3(x, y, z) _LV_CONCAT3(x, y, z)
#if defined(PYCPARSER) || defined(__CC_ARM)
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg)
#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4)
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(gnu_printf, fmtstr, vararg)))
#elif (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__))
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(printf, fmtstr, vararg)))
#else
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg)
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TYPES_H*/
+58
View File
@@ -0,0 +1,58 @@
/**
* @file lv_utils.h
*
*/
#ifndef LV_UTILS_H
#define LV_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/** Searches base[0] to base[n - 1] for an item that matches *key.
*
* @note The function cmp must return negative if it's first
* argument (the search key) is less that it's second (a table entry),
* zero if equal, and positive if greater.
*
* @note Items in the array must be in ascending order.
*
* @param key Pointer to item being searched for
* @param base Pointer to first element to search
* @param n Number of elements
* @param size Size of each element
* @param cmp Pointer to comparison function (see #unicode_list_compare as a comparison function
* example)
*
* @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,
int32_t (*cmp)(const void * pRef, const void * pElement));
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif