Skip to content

Commit

Permalink
feat(arc): add float support
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Oct 25, 2023
1 parent f273475 commit 84c8cf8
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 160 deletions.
2 changes: 1 addition & 1 deletion demos/transform/lv_demo_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void arc_event_cb(lv_event_t * e)
{
lv_obj_t * arc = lv_event_get_target(e);

int32_t v = lv_arc_get_angle_end(arc);
int32_t v = (int32_t)lv_arc_get_angle_end(arc);
lv_obj_set_style_transform_rotation(card_to_transform, v * 10, 0);
}

Expand Down
1 change: 0 additions & 1 deletion env_support/rt-thread/lv_rt_thread_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#define LV_SPRINTF_INCLUDE LV_RTTHREAD_INCLUDE
#define LV_SNPRINTF rt_snprintf
#define LV_VSNPRINTF rt_vsnprintf
#define LV_SPRINTF_USE_FLOAT 0

/*=====================
* COMPILER SETTINGS
Expand Down
18 changes: 8 additions & 10 deletions lv_conf_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
#endif
#endif /*LV_USE_MALLOC == LV_STDLIB_BUILTIN*/


#if LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN
#define LV_SPRINTF_USE_FLOAT 0
#endif /*LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN*/

/*====================
HAL SETTINGS
*====================*/
Expand Down Expand Up @@ -267,20 +262,20 @@

/*Number of stops allowed per gradient. Increase this to allow more stops.
*This adds (sizeof(lv_color_t) + 1) bytes per additional stop*/
#define LV_GRADIENT_MAX_STOPS 2
#define LV_GRADIENT_MAX_STOPS 2

/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently.
* 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */
#define LV_COLOR_MIX_ROUND_OFS 0
#define LV_COLOR_MIX_ROUND_OFS 0

/* Add 2 x 32 bit variables to each lv_obj_t to speed up getting style properties */
#define LV_OBJ_STYLE_CACHE 0
#define LV_OBJ_STYLE_CACHE 0

/* Add `id` field to `lv_obj_t` */
#define LV_USE_OBJ_ID 0
#define LV_USE_OBJ_ID 0

/* Use lvgl builtin method for obj ID */
#define LV_USE_OBJ_ID_BUILTIN 0
#define LV_USE_OBJ_ID_BUILTIN 0

/*=====================
* COMPILER SETTINGS
Expand Down Expand Up @@ -321,6 +316,9 @@
/*Extend the default -32k..32k coordinate range to -4M..4M by using int32_t for coordinates instead of int16_t*/
#define LV_USE_LARGE_COORD 0

/* Use `float` as `lv_value_precise_t` */
#define LV_USE_FLOAT 0

/*==================
* FONT USAGE
*===================*/
Expand Down
5 changes: 5 additions & 0 deletions scripts/lv_conf_internal_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
#undef _LV_KCONFIG_PRESENT
#if LV_USE_FLOAT
typedef float lv_value_precise_t;
#else
typedef int32_t lv_value_precise_t;
#endif
/*Set some defines if a dependency is disabled*/
#if LV_USE_LOG == 0
Expand Down
81 changes: 42 additions & 39 deletions src/draw/lv_draw_arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,89 +66,92 @@ void lv_draw_arc(lv_layer_t * layer, const lv_draw_arc_dsc_t * dsc)
LV_PROFILER_END;
}

void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, lv_value_precise_t start_angle,
lv_value_precise_t end_angle,
lv_coord_t w, bool rounded, lv_area_t * area)
{
lv_coord_t rout = radius;
int32_t start_angle_int = (int32_t) start_angle;
int32_t end_angle_int = (int32_t) end_angle;

/*Special case: full arc invalidation */
if(end_angle == start_angle + 360) {
if(end_angle_int == start_angle_int + 360) {
area->x1 = x - rout;
area->y1 = y - rout;
area->x2 = x + rout;
area->y2 = y + rout;
return;
}

if(start_angle > 360) start_angle -= 360;
if(end_angle > 360) end_angle -= 360;
if(start_angle_int > 360) start_angle_int -= 360;
if(end_angle_int > 360) end_angle_int -= 360;

lv_coord_t rin = radius - w;
lv_coord_t extra_area = rounded ? w / 2 + 1 : 0;
uint8_t start_quarter = start_angle / 90;
uint8_t end_quarter = end_angle / 90;
uint8_t start_quarter = start_angle_int / 90;
uint8_t end_quarter = end_angle_int / 90;

/*360 deg still counts as quarter 3 (360 / 90 would be 4)*/
if(start_quarter == 4) start_quarter = 3;
if(end_quarter == 4) end_quarter = 3;

if(start_quarter == end_quarter && start_angle <= end_angle) {
if(start_quarter == end_quarter && start_angle_int <= end_angle_int) {
if(start_quarter == 0) {
area->y1 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y1 = y + ((lv_trigo_sin(start_angle_int) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;

area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->y2 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->x1 = x + ((lv_trigo_sin(end_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
}
else if(start_quarter == 1) {
area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->x2 = x + ((lv_trigo_sin(start_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;

area->y1 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((lv_trigo_sin(end_angle_int) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->x1 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
}
else if(start_quarter == 2) {
area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->y2 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->x1 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->y2 = y + ((lv_trigo_sin(start_angle_int) * rin) >> LV_TRIGO_SHIFT) + extra_area;

area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->y1 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((lv_trigo_sin(end_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
}
else if(start_quarter == 3) {
area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x1 = x + ((lv_trigo_sin(start_angle_int + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;

area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->x2 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + ((lv_trigo_sin(end_angle_int) * rin) >> LV_TRIGO_SHIFT) + extra_area;
}
}
else if(start_quarter == 0 && end_quarter == 1) {
area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((LV_MIN(lv_trigo_sin(end_angle),
lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->x1 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((LV_MIN(lv_trigo_sin(end_angle_int),
lv_trigo_sin(start_angle_int)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + rout + extra_area;
}
else if(start_quarter == 1 && end_quarter == 2) {
area->x1 = x - rout - extra_area;
area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((LV_MAX(lv_trigo_sin(start_angle + 90),
lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y1 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + ((LV_MAX(lv_trigo_sin(start_angle_int + 90),
lv_trigo_sin(end_angle_int + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;
}
else if(start_quarter == 2 && end_quarter == 3) {
area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x1 = x + ((lv_trigo_sin(start_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y - rout - extra_area;
area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + (LV_MAX(lv_trigo_sin(end_angle) * rin,
lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
area->x2 = x + ((lv_trigo_sin(end_angle_int + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + (LV_MAX(lv_trigo_sin(end_angle_int) * rin,
lv_trigo_sin(start_angle_int) * rin) >> LV_TRIGO_SHIFT) + extra_area;
}
else if(start_quarter == 3 && end_quarter == 0) {
area->x1 = x + ((LV_MIN(lv_trigo_sin(end_angle + 90),
lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x1 = x + ((LV_MIN(lv_trigo_sin(end_angle_int + 90),
lv_trigo_sin(start_angle_int + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
area->y1 = y + ((lv_trigo_sin(start_angle_int) * rout) >> LV_TRIGO_SHIFT) - extra_area;
area->x2 = x + rout + extra_area;
area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
area->y2 = y + ((lv_trigo_sin(end_angle_int) * rout) >> LV_TRIGO_SHIFT) + extra_area;

}
else {
Expand Down
7 changes: 4 additions & 3 deletions src/draw/lv_draw_arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ typedef struct {

lv_color_t color;
lv_coord_t width;
uint16_t start_angle;
uint16_t end_angle;
lv_value_precise_t start_angle;
lv_value_precise_t end_angle;
lv_point_t center;
uint16_t radius;
const void * img_src;
Expand Down Expand Up @@ -60,7 +60,8 @@ void lv_draw_arc(struct _lv_layer_t * layer, const lv_draw_arc_dsc_t * dsc);
* @param rounded true: the arc is rounded
* @param area store the area to invalidate here
*/
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, lv_value_precise_t start_angle,
lv_value_precise_t end_angle,
lv_coord_t w, bool rounded, lv_area_t * area);

/**********************
Expand Down
4 changes: 2 additions & 2 deletions src/draw/sw/lv_draw_sw_arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void lv_draw_sw_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc, c
area_in.x2 -= dsc->width;
area_in.y2 -= dsc->width;

int32_t start_angle = dsc->start_angle;
int32_t end_angle = dsc->end_angle;
int32_t start_angle = (int32_t)dsc->start_angle;
int32_t end_angle = (int32_t)dsc->end_angle;
while(start_angle >= 360) start_angle -= 360;
while(end_angle >= 360) end_angle -= 360;

Expand Down
35 changes: 19 additions & 16 deletions src/lv_conf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,6 @@
#endif
#endif /*LV_USE_MALLOC == LV_STDLIB_BUILTIN*/


#if LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN
#ifndef LV_SPRINTF_USE_FLOAT
#ifdef CONFIG_LV_SPRINTF_USE_FLOAT
#define LV_SPRINTF_USE_FLOAT CONFIG_LV_SPRINTF_USE_FLOAT
#else
#define LV_SPRINTF_USE_FLOAT 0
#endif
#endif
#endif /*LV_USE_STDLIB_SPRINTF == LV_STDLIB_BUILTIN*/

/*====================
HAL SETTINGS
*====================*/
Expand Down Expand Up @@ -737,7 +726,7 @@
#ifdef CONFIG_LV_GRADIENT_MAX_STOPS
#define LV_GRADIENT_MAX_STOPS CONFIG_LV_GRADIENT_MAX_STOPS
#else
#define LV_GRADIENT_MAX_STOPS 2
#define LV_GRADIENT_MAX_STOPS 2
#endif
#endif

Expand All @@ -747,7 +736,7 @@
#ifdef CONFIG_LV_COLOR_MIX_ROUND_OFS
#define LV_COLOR_MIX_ROUND_OFS CONFIG_LV_COLOR_MIX_ROUND_OFS
#else
#define LV_COLOR_MIX_ROUND_OFS 0
#define LV_COLOR_MIX_ROUND_OFS 0
#endif
#endif

Expand All @@ -756,7 +745,7 @@
#ifdef CONFIG_LV_OBJ_STYLE_CACHE
#define LV_OBJ_STYLE_CACHE CONFIG_LV_OBJ_STYLE_CACHE
#else
#define LV_OBJ_STYLE_CACHE 0
#define LV_OBJ_STYLE_CACHE 0
#endif
#endif

Expand All @@ -765,7 +754,7 @@
#ifdef CONFIG_LV_USE_OBJ_ID
#define LV_USE_OBJ_ID CONFIG_LV_USE_OBJ_ID
#else
#define LV_USE_OBJ_ID 0
#define LV_USE_OBJ_ID 0
#endif
#endif

Expand All @@ -774,7 +763,7 @@
#ifdef CONFIG_LV_USE_OBJ_ID_BUILTIN
#define LV_USE_OBJ_ID_BUILTIN CONFIG_LV_USE_OBJ_ID_BUILTIN
#else
#define LV_USE_OBJ_ID_BUILTIN 0
#define LV_USE_OBJ_ID_BUILTIN 0
#endif
#endif

Expand Down Expand Up @@ -887,6 +876,15 @@
#endif
#endif

/* Use `float` as `lv_value_precise_t` */
#ifndef LV_USE_FLOAT
#ifdef CONFIG_LV_USE_FLOAT
#define LV_USE_FLOAT CONFIG_LV_USE_FLOAT
#else
#define LV_USE_FLOAT 0
#endif
#endif

/*==================
* FONT USAGE
*===================*/
Expand Down Expand Up @@ -2747,6 +2745,11 @@ LV_EXPORT_CONST_INT(LV_DPI_DEF);

#undef _LV_KCONFIG_PRESENT

#if LV_USE_FLOAT
typedef float lv_value_precise_t;
#else
typedef int32_t lv_value_precise_t;
#endif

/*Set some defines if a dependency is disabled*/
#if LV_USE_LOG == 0
Expand Down
1 change: 0 additions & 1 deletion src/misc/lv_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ extern "C" {
#define LV_OS_CMSIS_RTOS2 3
#define LV_OS_CUSTOM 255


#define LV_STDLIB_BUILTIN 0
#define LV_STDLIB_CLIB 1
#define LV_STDLIB_MICROPYTHON 2
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib/builtin/lv_sprintf_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "../lv_sprintf.h"
#include "../../misc/lv_types.h"

#define PRINTF_DISABLE_SUPPORT_FLOAT (!LV_SPRINTF_USE_FLOAT)
#define PRINTF_DISABLE_SUPPORT_FLOAT (!LV_USE_FLOAT)

// 'ntoa' conversion buffer size, this must be big enough to hold one converted
// numeric number including padded zeros (dynamically created on stack)
Expand Down
Loading

0 comments on commit 84c8cf8

Please sign in to comment.