diff --git a/lv_core/lv_vdb.c b/lv_core/lv_vdb.c index 5180ddef3..bbbab51d9 100644 --- a/lv_core/lv_vdb.c +++ b/lv_core/lv_vdb.c @@ -39,7 +39,7 @@ typedef enum { static volatile lv_vdb_state_t vdb_state = LV_VDB_STATE_ACTIVE; # if LV_VDB_ADR == 0 /*If the buffer address is not specified simply allocate it*/ -static uint8_t vdb_buf[((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)]; +static uint8_t vdb_buf[LV_VDB_SIZE_IN_BYTES]; static lv_vdb_t vdb = {.buf = (lv_color_t*)vdb_buf}; # else /*LV_VDB_ADR != 0*/ /*If the buffer address is specified use that address*/ @@ -50,8 +50,8 @@ static lv_vdb_t vdb = {.buf = (lv_color_t *)LV_VDB_ADR}; static volatile lv_vdb_state_t vdb_state[2] = {LV_VDB_STATE_FREE, LV_VDB_STATE_FREE}; # if LV_VDB_ADR == 0 /*If the buffer address is not specified simply allocate it*/ -static uint8_t vdb_buf1[((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)]; -static uint8_t vdb_buf2[((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)]; +static uint8_t vdb_buf1[LV_VDB_SIZE_IN_BYTES]; +static uint8_t vdb_buf2[LV_VDB_SIZE_IN_BYTES]; static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *) vdb_buf1}, {.buf = (lv_color_t *) vdb_buf2}}; # else /*LV_VDB_ADR != 0*/ /*If the buffer address is specified use that address*/ @@ -133,8 +133,7 @@ void lv_vdb_flush(void) /** * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. - * It should be called before `lv_init()`. - * The size of the buffer should be: `((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)` + * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` * @param buf1 address of the VDB. * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` */ diff --git a/lv_core/lv_vdb.h b/lv_core/lv_vdb.h index 479f8e4e4..cbb4329a4 100644 --- a/lv_core/lv_vdb.h +++ b/lv_core/lv_vdb.h @@ -34,6 +34,13 @@ extern "C" { #warning "LV_VDB_PX_BPP is not specified in lv_conf.h. Use the default value (LV_COLOR_SIZE)" #define LV_VDB_PX_BPP LV_COLOR_SIZE #endif + +/* The size of VDB in bytes. + * (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes + * (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up. + * E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/ +#define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0) + /********************** * TYPEDEFS **********************/ @@ -61,8 +68,7 @@ void lv_vdb_flush(void); /** * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. - * It should be called before `lv_init()`. - * The size of the buffer should be: `((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)` + * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` * @param buf1 address of the VDB. * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` */