lv_math.h
API reference for lv_math.h
Functions
lv_rand_set_seed
Set the seed of the pseudo random number generator
void lv_rand_set_seed(uint32_t seed)| Name | Type | Description |
|---|---|---|
seed | uint32_t | a number to initialize the random generator |
lv_trigo_sin
Return with sinus of an angle
int32_t lv_trigo_sin(int16_t angle)| Name | Type |
|---|---|
angle | int16_t |
Returns: int32_t — sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
lv_trigo_cos
int32_t lv_trigo_cos(int16_t angle)| Name | Type |
|---|---|
angle | int16_t |
lv_cubic_bezier
Calculate the y value of cubic-bezier(x1, y1, x2, y2) function as specified x.
int32_t lv_cubic_bezier(int32_t x, int32_t x1, int32_t y1, int32_t x2, int32_t y2)| Name | Type | Description |
|---|---|---|
x | int32_t | time in range of [0..LV_BEZIER_VAL_MAX] |
x1 | int32_t | x of control point 1 in range of [0..LV_BEZIER_VAL_MAX] |
y1 | int32_t | y of control point 1 in range of [0..LV_BEZIER_VAL_MAX] |
x2 | int32_t | x of control point 2 in range of [0..LV_BEZIER_VAL_MAX] |
y2 | int32_t | y of control point 2 in range of [0..LV_BEZIER_VAL_MAX] |
Returns: int32_t — the value calculated
lv_bezier3
Calculate a value of a Cubic Bezier function.
int32_t lv_bezier3(int32_t t, int32_t u0, uint32_t u1, int32_t u2, int32_t u3)| Name | Type | Description |
|---|---|---|
t | int32_t | time in range of [0..LV_BEZIER_VAL_MAX] |
u0 | int32_t | must be 0 |
u1 | uint32_t | control value 1 values in range of [0..LV_BEZIER_VAL_MAX] |
u2 | int32_t | control value 2 in range of [0..LV_BEZIER_VAL_MAX] |
u3 | int32_t | must be LV_BEZIER_VAL_MAX |
Returns: int32_t — the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX]
lv_atan2
Calculate the atan2 of a vector.
uint16_t lv_atan2(int x, int y)| Name | Type |
|---|---|
x | int |
y | int |
Returns: uint16_t — the angle in degree calculated from the given parameters in range of [0..360]
lv_sqrt
Get the square root of a number
void lv_sqrt(uint32_t x, lv_sqrt_res_t *q, uint32_t mask)| Name | Type | Description |
|---|---|---|
x | uint32_t | integer which square root should be calculated |
q | lv_sqrt_res_t * | store the result here. q->i: integer part, q->f: fractional part in 1/256 unit |
mask | uint32_t | 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_sqrt32
Alternative (fast, approximate) implementation for getting the square root of an integer.
int32_t lv_sqrt32(uint32_t x)| Name | Type | Description |
|---|---|---|
x | uint32_t | integer which square root should be calculated |
lv_sqr
Calculate the square of an integer (input range is 0..32767).
static int32_t lv_sqr(int32_t x)| Name | Type | Description |
|---|---|---|
x | int32_t | input |
Returns: int32_t — square
lv_pow
Calculate the integer exponents.
int64_t lv_pow(int64_t base, int8_t exp)| Name | Type |
|---|---|
base | int64_t |
exp | int8_t |
Returns: int64_t — base raised to the power exponent
lv_map
Get the mapped of a number given an input and output range
int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out)| Name | Type | Description |
|---|---|---|
x | int32_t | integer which mapped value should be calculated |
min_in | int32_t | min input range |
max_in | int32_t | max input range |
min_out | int32_t | max output range |
max_out | int32_t | max output range |
Returns: int32_t — the mapped number
lv_rand
Get a pseudo random number in the given range
uint32_t lv_rand(uint32_t min, uint32_t max)| Name | Type | Description |
|---|---|---|
min | uint32_t | the minimum value |
max | uint32_t | the maximum value |
Returns: uint32_t — return the random number. min <= return_value <= max
Structs
lv_sqrt_res_t
| Member | Type | Description |
|---|---|---|
i | uint16_t | |
f | uint16_t |
Used by 1 function
lv_sqrt— paramq
Macros
LV_TRIGO_SIN_MAX
#define LV_TRIGO_SIN_MAX 32768LV_TRIGO_SHIFT
#define LV_TRIGO_SHIFT 15> > LV_TRIGO_SHIFT to normalize
LV_BEZIER_VAL_SHIFT
#define LV_BEZIER_VAL_SHIFT 10log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values
LV_BEZIER_VAL_MAX
#define LV_BEZIER_VAL_MAX (1L << LV_BEZIER_VAL_SHIFT)Max time in Bezier functions (not [0..1] to use integers)
LV_BEZIER_VAL_FLOAT
#define LV_BEZIER_VAL_FLOAT(f) \
((int32_t)((f) * LV_BEZIER_VAL_MAX))Convert const float number cubic-bezier values to fix-point value
LV_ALIGN_UP
#define LV_ALIGN_UP(x, align) \
(((x) + ((align) - 1)) & ~((align) - 1))Align up value x to align, align must be a power of two
LV_ROUND_UP
#define LV_ROUND_UP(x, round) \
((((x) + ((round) - 1)) / (round)) * (round))Round up value x to round, round can be any integer number
LV_MIN
#define LV_MIN(a, b) \
((a) < (b) ? (a) : (b))LV_MIN3
#define LV_MIN3(a, b, c) \
(LV_MIN(LV_MIN(a,b), c))LV_MIN4
#define LV_MIN4(a, b, c, d) \
(LV_MIN(LV_MIN(a,b), LV_MIN(c,d)))LV_MAX
#define LV_MAX(a, b) \
((a) > (b) ? (a) : (b))LV_MAX3
#define LV_MAX3(a, b, c) \
(LV_MAX(LV_MAX(a,b), c))LV_MAX4
#define LV_MAX4(a, b, c, d) \
(LV_MAX(LV_MAX(a,b), LV_MAX(c,d)))LV_CLAMP
#define LV_CLAMP(min, val, max) \
(LV_MAX(min, (LV_MIN(val, max))))LV_ABS
#define LV_ABS(x) \
((x) > 0 ? (x) : (-(x)))LV_UDIV255
#define LV_UDIV255(x) \
(((x) * 0x8081U) >> 0x17)LV_IS_SIGNED
#define LV_IS_SIGNED(t) \
(((t)(-1)) < ((t)0))LV_UMAX_OF
#define LV_UMAX_OF(t) \
(((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL)))LV_SMAX_OF
#define LV_SMAX_OF(t) \
(((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL)))LV_MAX_OF
#define LV_MAX_OF(t) \
((unsigned long)(LV_IS_SIGNED(t) ? LV_SMAX_OF(t) : LV_UMAX_OF(t)))Dependencies
Last updated on