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:
parent
54b8862609
commit
d90759aaab
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file hal_disp.c
|
* @file lv_hal_disp.c
|
||||||
*
|
*
|
||||||
* @description HAL layer for display driver
|
* @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));
|
lv_memset_00(driver, sizeof(lv_disp_drv_t));
|
||||||
|
|
||||||
driver->flush_cb = NULL;
|
|
||||||
driver->hor_res = 320;
|
driver->hor_res = 320;
|
||||||
driver->ver_res = 240;
|
driver->ver_res = 240;
|
||||||
driver->draw_buf = NULL;
|
driver->antialiasing = LV_COLOR_DEPTH > 8 ? 1: 0;
|
||||||
driver->rotated = LV_DISP_ROT_NONE;
|
driver->screen_transp = LV_COLOR_SCREEN_TRANSP;
|
||||||
driver->sw_rotate = 0;
|
driver->dpi = LV_DPI_DEF;
|
||||||
driver->color_chroma_key = LV_COLOR_CHROMA_KEY;
|
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->driver = driver;
|
||||||
|
|
||||||
disp->last_activity_time = 0;
|
|
||||||
|
|
||||||
if(disp_def == NULL) disp_def = disp;
|
|
||||||
|
|
||||||
lv_disp_t * disp_def_tmp = disp_def;
|
lv_disp_t * disp_def_tmp = disp_def;
|
||||||
disp_def = disp; /*Temporarily change the default screen to create the default screens on the
|
disp_def = disp; /*Temporarily change the default screen to create the default screens on the
|
||||||
new display*/
|
new display*/
|
||||||
/*Create a refresh timer*/
|
/*Create a refresh timer*/
|
||||||
disp->refr_timer = lv_timer_create(_lv_disp_refr_timer, LV_DISP_DEF_REFR_PERIOD, disp);
|
disp->refr_timer = lv_timer_create(_lv_disp_refr_timer, LV_DISP_DEF_REFR_PERIOD, disp);
|
||||||
LV_ASSERT_MALLOC(disp->refr_timer);
|
LV_ASSERT_MALLOC(disp->refr_timer);
|
||||||
if(disp->refr_timer == NULL) return NULL;
|
if(disp->refr_timer == NULL) {
|
||||||
|
lv_mem_free(disp);
|
||||||
disp->inv_p = 0;
|
return NULL;
|
||||||
disp->last_activity_time = 0;
|
}
|
||||||
|
|
||||||
disp->bg_color = lv_color_white();
|
disp->bg_color = lv_color_white();
|
||||||
disp->bg_img = NULL;
|
|
||||||
#if LV_COLOR_SCREEN_TRANSP
|
#if LV_COLOR_SCREEN_TRANSP
|
||||||
disp->bg_opa = LV_OPA_TRANSP;
|
disp->bg_opa = LV_OPA_TRANSP;
|
||||||
#else
|
#else
|
||||||
@ -145,7 +131,6 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
disp->prev_scr = NULL;
|
|
||||||
disp->act_scr = lv_obj_create(NULL, NULL); /*Create a default screen on the display*/
|
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->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*/
|
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);
|
lv_obj_invalidate(disp->act_scr);
|
||||||
|
|
||||||
disp_def = disp_def_tmp; /*Revert the default display*/
|
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*/
|
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++) {
|
for(i = 0; i < disp->screen_cnt; i++) {
|
||||||
lv_area_t prev_coords;
|
lv_area_t prev_coords;
|
||||||
lv_obj_get_coords(disp->screens[i], &prev_coords);
|
lv_obj_get_coords(disp->screens[i], &prev_coords);
|
||||||
disp->screens[i]->coords.x2 = w;
|
lv_area_set_width(&disp->screens[i]->coords, w);
|
||||||
disp->screens[i]->coords.y2 = h;
|
lv_area_set_height(&disp->screens[i]->coords, h);
|
||||||
lv_signal_send(disp->screens[i], LV_SIGNAL_COORD_CHG, &prev_coords);
|
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_ll_remove(&LV_GC_ROOT(_lv_disp_ll), disp);
|
||||||
|
lv_timer_del(disp->refr_timer);
|
||||||
lv_mem_free(disp);
|
lv_mem_free(disp);
|
||||||
|
|
||||||
if(was_default) lv_disp_set_default(_lv_ll_get_head(&LV_GC_ROOT(_lv_disp_ll)));
|
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
|
* @param disp pointer to a display
|
||||||
*/
|
*/
|
||||||
void lv_disp_set_default(lv_disp_t * disp)
|
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)
|
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) disp = lv_disp_get_default();
|
||||||
|
if(disp == NULL) return;
|
||||||
|
|
||||||
disp->driver->rotated = rotation;
|
disp->driver->rotated = rotation;
|
||||||
lv_disp_drv_update(disp, disp->driver);
|
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)
|
lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp)
|
||||||
{
|
{
|
||||||
if(disp == NULL) disp = lv_disp_get_default();
|
if(disp == NULL) disp = lv_disp_get_default();
|
||||||
|
if(disp == NULL) return LV_DISP_ROT_NONE;
|
||||||
return disp->driver->rotated;
|
return disp->driver->rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ extern "C" {
|
|||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
struct _lv_obj_t;
|
||||||
struct _lv_disp_t;
|
struct _lv_disp_t;
|
||||||
struct _lv_disp_drv_t;
|
struct _lv_disp_drv_t;
|
||||||
struct _lv_theme_t;
|
struct _lv_theme_t;
|
||||||
@ -55,7 +56,7 @@ typedef struct {
|
|||||||
lv_area_t area;
|
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)*/
|
/*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;
|
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 int flushing_last;
|
||||||
volatile uint32_t last_area : 1; /*1: the last area is being rendered*/
|
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*/
|
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 sw_rotate : 1; /**< 1: use software rotation (slower) */
|
||||||
uint32_t antialiasing : 1; /**< 1: anti-aliasing is enabled on this display. */
|
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.
|
/**Handle if the screen doesn't have a solid (opa == LV_OPA_COVER) background.
|
||||||
* Use only if required because it's slower.*/
|
* Use only if required because it's slower.*/
|
||||||
uint32_t screen_transp : 1;
|
uint32_t screen_transp : 1;
|
||||||
|
|
||||||
/** DPI (dot per inch) of the display.
|
/** 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;
|
uint32_t dpi : 10;
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ typedef struct _lv_disp_drv_t {
|
|||||||
const lv_area_t * fill_area, lv_color_t color);
|
const lv_area_t * fill_area, lv_color_t color);
|
||||||
|
|
||||||
/** On CHROMA_KEYED images this color will be transparent.
|
/** 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;
|
lv_color_t color_chroma_key;
|
||||||
|
|
||||||
#if LV_USE_USER_DATA
|
#if LV_USE_USER_DATA
|
||||||
@ -139,8 +140,6 @@ typedef struct _lv_disp_drv_t {
|
|||||||
|
|
||||||
} lv_disp_drv_t;
|
} lv_disp_drv_t;
|
||||||
|
|
||||||
struct _lv_obj_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display structure.
|
* Display structure.
|
||||||
* @note `lv_disp_drv_t` should be the first member of the 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;
|
uint32_t screen_cnt;
|
||||||
uint8_t del_prev : 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready */
|
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*/
|
lv_color_t bg_color; /**< Default display color when screens are transparent*/
|
||||||
const void * bg_img; /**< An image source to display as wallpaper*/
|
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*/
|
/** Invalidated (marked to redraw) areas*/
|
||||||
lv_area_t inv_areas[LV_INV_BUF_SIZE];
|
lv_area_t inv_areas[LV_INV_BUF_SIZE];
|
||||||
uint8_t inv_area_joined[LV_INV_BUF_SIZE];
|
uint8_t inv_area_joined[LV_INV_BUF_SIZE];
|
||||||
uint32_t inv_p : 10;
|
uint16_t inv_p;
|
||||||
|
|
||||||
/*Miscellaneous data*/
|
/*Miscellaneous data*/
|
||||||
uint32_t last_activity_time; /**< Last time when there was activity on this display */
|
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);
|
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
|
* @param disp pointer to a display
|
||||||
*/
|
*/
|
||||||
void lv_disp_set_default(lv_disp_t * disp);
|
void lv_disp_set_default(lv_disp_t * disp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user