1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Minor fix for disp driver (#2135)

* fix(disp): correct the typo error in comment

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>

* fix(disp): fix the field definition

1.change rotated from 3bits to 2bits since lv_disp_rot_t has only four value
2.change inv_p from 10bits to uint16_t to avoid the bit operation
3.reorder bg_opa to save the memory space

* fix(disp): remove the unnecessary field zero

since lv_memset_00 is already done for the main struct

* fix(disp): handle the out of memmory gracefully

* fix(disp): delete the refresh timer in lv_disp_remove

* fix(disp): handle NULL pointer correctly in lv_disp_[g|s]et_rotation

like other similar(allow NULL disp) functions

* fix(disp): call lv_area_set_[width|height] in lv_disp_drv_update

to remove one extra row and column
This commit is contained in:
Xiang Xiao 2021-03-14 05:46:35 -07:00 committed by GitHub
parent 54b8862609
commit d90759aaab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 36 deletions

View File

@ -1,6 +1,5 @@
/**
* @file hal_disp.c
* @file lv_hal_disp.c
*
* @description HAL layer for display driver
*
@ -57,20 +56,12 @@ void lv_disp_drv_init(lv_disp_drv_t * driver)
{
lv_memset_00(driver, sizeof(lv_disp_drv_t));
driver->flush_cb = NULL;
driver->hor_res = 320;
driver->ver_res = 240;
driver->draw_buf = NULL;
driver->rotated = LV_DISP_ROT_NONE;
driver->sw_rotate = 0;
driver->antialiasing = LV_COLOR_DEPTH > 8 ? 1: 0;
driver->screen_transp = LV_COLOR_SCREEN_TRANSP;
driver->dpi = LV_DPI_DEF;
driver->color_chroma_key = LV_COLOR_CHROMA_KEY;
driver->dpi = LV_DPI_DEF;
driver->antialiasing = LV_COLOR_DEPTH > 8 ? 1: 0;
#if LV_COLOR_SCREEN_TRANSP
driver->screen_transp = 1;
#endif
}
/**
@ -116,23 +107,18 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
disp->driver = driver;
disp->last_activity_time = 0;
if(disp_def == NULL) disp_def = disp;
lv_disp_t * disp_def_tmp = disp_def;
disp_def = disp; /*Temporarily change the default screen to create the default screens on the
new display*/
/*Create a refresh timer*/
disp->refr_timer = lv_timer_create(_lv_disp_refr_timer, LV_DISP_DEF_REFR_PERIOD, disp);
LV_ASSERT_MALLOC(disp->refr_timer);
if(disp->refr_timer == NULL) return NULL;
disp->inv_p = 0;
disp->last_activity_time = 0;
if(disp->refr_timer == NULL) {
lv_mem_free(disp);
return NULL;
}
disp->bg_color = lv_color_white();
disp->bg_img = NULL;
#if LV_COLOR_SCREEN_TRANSP
disp->bg_opa = LV_OPA_TRANSP;
#else
@ -145,7 +131,6 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
}
#endif
disp->prev_scr = NULL;
disp->act_scr = lv_obj_create(NULL, NULL); /*Create a default screen on the display*/
disp->top_layer = lv_obj_create(NULL, NULL); /*Create top layer on the display*/
disp->sys_layer = lv_obj_create(NULL, NULL); /*Create sys layer on the display*/
@ -160,6 +145,7 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
lv_obj_invalidate(disp->act_scr);
disp_def = disp_def_tmp; /*Revert the default display*/
if(disp_def == NULL) disp_def = disp; /*Initialize the default display*/
lv_timer_ready(disp->refr_timer); /*Be sure the screen will be refreshed immediately on start up*/
@ -181,8 +167,8 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv)
for(i = 0; i < disp->screen_cnt; i++) {
lv_area_t prev_coords;
lv_obj_get_coords(disp->screens[i], &prev_coords);
disp->screens[i]->coords.x2 = w;
disp->screens[i]->coords.y2 = h;
lv_area_set_width(&disp->screens[i]->coords, w);
lv_area_set_height(&disp->screens[i]->coords, h);
lv_signal_send(disp->screens[i], LV_SIGNAL_COORD_CHG, &prev_coords);
}
@ -218,13 +204,14 @@ void lv_disp_remove(lv_disp_t * disp)
}
_lv_ll_remove(&LV_GC_ROOT(_lv_disp_ll), disp);
lv_timer_del(disp->refr_timer);
lv_mem_free(disp);
if(was_default) lv_disp_set_default(_lv_ll_get_head(&LV_GC_ROOT(_lv_disp_ll)));
}
/**
* Set a default screen. The new screens will be created on it by default.
* Set a default display. The new screens will be created on it by default.
* @param disp pointer to a display
*/
void lv_disp_set_default(lv_disp_t * disp)
@ -422,6 +409,7 @@ bool lv_disp_is_true_double_buf(lv_disp_t * disp)
void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL) return;
disp->driver->rotated = rotation;
lv_disp_drv_update(disp, disp->driver);
@ -435,7 +423,7 @@ void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation)
lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL) return LV_DISP_ROT_NONE;
return disp->driver->rotated;
}

View File

@ -38,6 +38,7 @@ extern "C" {
* TYPEDEFS
**********************/
struct _lv_obj_t;
struct _lv_disp_t;
struct _lv_disp_drv_t;
struct _lv_theme_t;
@ -55,7 +56,7 @@ typedef struct {
lv_area_t area;
/*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 bi tfield because when it's cleared from IRQ Read-Modify-Write issue might occur)*/
/*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*/
@ -85,14 +86,14 @@ typedef struct _lv_disp_drv_t {
uint32_t sw_rotate : 1; /**< 1: use software rotation (slower) */
uint32_t antialiasing : 1; /**< 1: anti-aliasing is enabled on this display. */
uint32_t rotated : 3; /**< 1: turn the display by 90 degree. @warning Does not update coordinates for you!*/
uint32_t rotated : 2; /**< 1: turn the display by 90 degree. @warning Does not update coordinates for you!*/
/**Handle if the screen doesn't have a solid (opa == LV_OPA_COVER) background.
* Use only if required because it's slower.*/
uint32_t screen_transp : 1;
/** DPI (dot per inch) of the display.
* Set to `LV_DPI` from `lv_Conf.h` by default.
* Set to `LV_DPI_DEF` from `lv_conf.h` by default.
*/
uint32_t dpi : 10;
@ -130,7 +131,7 @@ typedef struct _lv_disp_drv_t {
const lv_area_t * fill_area, lv_color_t color);
/** On CHROMA_KEYED images this color will be transparent.
* `LV_COLOR_TRANSP` by default. (lv_conf.h)*/
* `LV_COLOR_CHROMA_KEY` by default. (lv_conf.h)*/
lv_color_t color_chroma_key;
#if LV_USE_USER_DATA
@ -139,8 +140,6 @@ typedef struct _lv_disp_drv_t {
} lv_disp_drv_t;
struct _lv_obj_t;
/**
* Display structure.
* @note `lv_disp_drv_t` should be the first member of the structure.
@ -165,14 +164,14 @@ typedef struct _lv_disp_t {
uint32_t screen_cnt;
uint8_t del_prev : 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready */
lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper */
lv_color_t bg_color; /**< Default display color when screens are transparent*/
const void * bg_img; /**< An image source to display as wallpaper*/
lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper */
/** Invalidated (marked to redraw) areas*/
lv_area_t inv_areas[LV_INV_BUF_SIZE];
uint8_t inv_area_joined[LV_INV_BUF_SIZE];
uint32_t inv_p : 10;
uint16_t inv_p;
/*Miscellaneous data*/
uint32_t last_activity_time; /**< Last time when there was activity on this display */
@ -236,7 +235,7 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv);
void lv_disp_remove(lv_disp_t * disp);
/**
* Set a default screen. The new screens will be created on it by default.
* Set a default display. The new screens will be created on it by default.
* @param disp pointer to a display
*/
void lv_disp_set_default(lv_disp_t * disp);