diff --git a/src/hal/lv_hal_disp.h b/src/hal/lv_hal_disp.h index cd0d676e14..ec7c1ff3e5 100644 --- a/src/hal/lv_hal_disp.h +++ b/src/hal/lv_hal_disp.h @@ -23,6 +23,11 @@ extern "C" { #include "../misc/lv_area.h" #include "../misc/lv_ll.h" #include "../misc/lv_timer.h" +#include "../misc/lv_types.h" + +#if LV_USE_ATOMICS == 1 +#include +#endif /********************* * DEFINES @@ -47,6 +52,11 @@ struct _lv_disp_t; struct _lv_disp_drv_t; struct _lv_theme_t; +#if LV_USE_ATOMICS == 1 +#define FLUSHING_TYPE atomic_int +#else +#define FLUSHING_TYPE volatile int +#endif /** * Structure for holding display buffer information. */ @@ -57,13 +67,13 @@ typedef struct _lv_disp_draw_buf_t { /*Internal, used by the library*/ void * buf_act; uint32_t size; /*In pixel count*/ - /*1: flushing is in progress. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ - volatile int flushing; - /*1: It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ - volatile int flushing_last; - volatile uint32_t last_area : 1; /*1: the last area is being rendered*/ - volatile uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/ + FLUSHING_TYPE flushing; + /*It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + FLUSHING_TYPE flushing_last; + uint32_t last_area : 1; /*1: the last area is being rendered*/ + uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/ } lv_disp_draw_buf_t; +#undef FLUSHING_TYPE typedef enum { LV_DISP_ROT_NONE = 0, diff --git a/src/hal/lv_hal_tick.c b/src/hal/lv_hal_tick.c index c12a5942eb..0b904672c8 100644 --- a/src/hal/lv_hal_tick.c +++ b/src/hal/lv_hal_tick.c @@ -7,6 +7,8 @@ * INCLUDES *********************/ #include "lv_hal_tick.h" +#include "../misc/lv_types.h" +#include #include #if LV_TICK_CUSTOM == 1 @@ -29,8 +31,13 @@ * STATIC VARIABLES **********************/ #if !LV_TICK_CUSTOM - static uint32_t sys_time = 0; - static volatile uint8_t tick_irq_flag; + #if LV_USE_ATOMICS == 1 + static _Atomic(uint32_t) sys_time = 0; + static atomic_int tick_irq_flag; + #else + static volatile uint32_t sys_time = 0; + static volatile int tick_irq_flag; + #endif #endif /********************** diff --git a/src/misc/lv_types.h b/src/misc/lv_types.h index 8dfc07b0f3..e2ea2f0be4 100644 --- a/src/misc/lv_types.h +++ b/src/misc/lv_types.h @@ -32,6 +32,15 @@ extern "C" { #endif +/*Use atomics instead of volatile variables for state which is potentially shared between threads, as long as + *the compiler supports it.*/ +#if (defined(__cplusplus) && __cplusplus >= 201103L)\ + || (__STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)) +#define LV_USE_ATOMICS 1 +#else +#define LV_USE_ATOMICS 0 +#endif + /********************** * TYPEDEFS **********************/