From 15007e9071d1c321869dfc899e5a822f54b89d49 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 8 Mar 2019 06:57:16 +0100 Subject: [PATCH] add lv_disp_remove --- lv_core/lv_indev.c | 1 + lv_core/lv_refr.c | 2 +- lv_hal/lv_hal_disp.c | 25 +++++++++++++++++++++++++ lv_hal/lv_hal_disp.h | 6 ++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 1928c370b..76a302fb2 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -310,6 +310,7 @@ static void indev_proc_task(void * param) /*Read and process all indevs*/ while(i) { + if(i->driver.disp == NULL) continue; /*Not assigned to any displays*/ indev_act = i; /*Handle reset query before processing the point*/ diff --git a/lv_core/lv_refr.c b/lv_core/lv_refr.c index 52c5afa1b..b81d71cb4 100644 --- a/lv_core/lv_refr.c +++ b/lv_core/lv_refr.c @@ -280,7 +280,7 @@ static void lv_refr_area(const lv_area_t * area_p) /*Calculate the max row num*/ lv_coord_t w = lv_area_get_width(area_p); lv_coord_t h = lv_area_get_height(area_p); - lv_coord_t y2 = area_p->y2 >= lv_disp_get_ver_res(NULL) ? y2 = lv_disp_get_ver_res(NULL) - 1 : area_p->y2; + lv_coord_t y2 = area_p->y2 >= lv_disp_get_ver_res(disp_refr) ? y2 = lv_disp_get_ver_res(disp_refr) - 1 : area_p->y2; int32_t max_row = (uint32_t) vdb->size / w; diff --git a/lv_hal/lv_hal_disp.c b/lv_hal/lv_hal_disp.c index c3d1683b7..a7dcf228a 100644 --- a/lv_hal/lv_hal_disp.c +++ b/lv_hal/lv_hal_disp.c @@ -135,6 +135,31 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) return disp; } +/** + * Remove a display + * @param disp pointer to display + */ +void lv_disp_remove(lv_disp_t * disp) +{ + bool was_default = false; + if(disp == lv_disp_get_default()) was_default = true; + + /*Detach the input devices */ + lv_indev_t * indev; + indev = lv_indev_next(NULL); + while(indev) { + if(indev->driver.disp == disp) { + indev->driver.disp = NULL; + } + indev = lv_indev_next(indev); + } + + lv_ll_rem(&LV_GC_ROOT(_lv_disp_ll), disp); + 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. * @param disp pointer to a display diff --git a/lv_hal/lv_hal_disp.h b/lv_hal/lv_hal_disp.h index e1397b5d2..89b5a22f8 100644 --- a/lv_hal/lv_hal_disp.h +++ b/lv_hal/lv_hal_disp.h @@ -160,6 +160,12 @@ void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32 */ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver); +/** + * Remove a display + * @param disp pointer to display + */ +void lv_disp_remove(lv_disp_t * disp); + /** * Set a default screen. The new screens will be created on it by default. * @param disp pointer to a display