Skip to content

Commit 051a229

Browse files
committed
fixes stm32 build
1 parent 696e634 commit 051a229

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

ext_mod/lvgl/micropython.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ $(LVGL_MPY): $(ALL_LVGL_SRC) $(LVGL_BINDING_DIR)/gen/$(GEN_SCRIPT)_api_gen_mpy.p
3131
.PHONY: LVGL_MPY
3232
LVGL_MPY: $(LVGL_MPY)
3333

34+
3435
SRC_USERMOD_LIB_C += $(shell find $(LVGL_DIR)/src -type f -name "*.c")
3536
SRC_USERMOD_LIB_C += $(LVGL_ADDON_DIR)/src/color_addons.c
3637
SRC_USERMOD_C += $(LVGL_MPY)
3738

39+
ifneq (,$(findstring stm32, $(LV_PORT)))
40+
CFLAGS_USERMOD += -DMP_SOFT_ATAN2=1
41+
endif
42+
43+
ifneq (,$(findstring rp2, $(LV_PORT)))
44+
CFLAGS_USERMOD += -DMP_SOFT_ATAN2=1
45+
endif

ext_mod/lvgl_addons/src/color_addons.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@
88
#define TWO_PI 6.28318530717958647693f
99
#define INV_TWO_PI 0.15915494309189533576876437577476f
1010

11+
#ifdef MP_SOFT_ATAN2
12+
13+
// Approximates atan2(y, x) normalized to the [0,4) range
14+
// with a maximum error of 0.1620 degrees
15+
float soft_atan2( float y, float x )
16+
{
17+
static const uint32_t sign_mask = 0x80000000;
18+
static const float b = 0.596227f;
19+
20+
// Extract the sign bits
21+
uint32_t ux_s = sign_mask & (uint32_t &)x;
22+
uint32_t uy_s = sign_mask & (uint32_t &)y;
23+
24+
// Determine the quadrant offset
25+
float q = (float)( ( ~ux_s & uy_s ) >> 29 | ux_s >> 30 );
26+
27+
// Calculate the arctangent in the first quadrant
28+
float bxy_a = fabs( b * x * y );
29+
float num = bxy_a + y * y;
30+
float atan_1q = num / ( x * x + bxy_a + num );
31+
32+
// Translate it to the proper quadrant
33+
uint32_t uatan_2q = (ux_s ^ uy_s) | (uint32_t &)atan_1q;
34+
return q + (float &)uatan_2q;
35+
}
36+
37+
#endif /* MP_SOFT_ATAN */
38+
1139

1240
float floormod(float x, float y) {
1341
int32_t res = (int32_t)x;
@@ -49,7 +77,11 @@ void lv_conical_gradient(uint8_t *buf, uint16_t radius, const lv_grad_dsc_t *gra
4977
run = radius;
5078

5179
for (uint32_t x=0; x < diameter; x++) {
52-
t = (float)atan2((float)rise, (float)run) + (float)PI - (float)angle;
80+
#ifdef MP_SOFT_ATAN2
81+
t = (float)soft_atan2((float)rise, (float)run) + (float)PI - (float)angle;
82+
#else
83+
t = (float)atan2((float)rise, (float)run) + (float)PI - (float)angle;
84+
#endif
5385

5486
if (twist > 0) {
5587
t += TWO_PI * sqrtf((float)(rise * rise + run * run) / (float)twist);

0 commit comments

Comments
 (0)