From 09f362a1ed7d096eef62f9892da2c3f89eeed28e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 30 Mar 2019 06:23:41 +0100 Subject: [PATCH] add disp. rotate config for disp_drv --- src/lv_core/lv_refr.c | 4 ++-- src/lv_hal/lv_hal_disp.c | 24 ++++++++++++++++++++---- src/lv_hal/lv_hal_disp.h | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index b55fbe64b..29f97cfe9 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -92,8 +92,8 @@ void lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p) lv_area_t scr_area; scr_area.x1 = 0; scr_area.y1 = 0; - scr_area.x2 = disp->driver.hor_res - 1; - scr_area.y2 = disp->driver.ver_res - 1; + scr_area.x2 = lv_disp_get_hor_res(disp) - 1; + scr_area.y2 = lv_disp_get_ver_res(disp) - 1; lv_area_t com_area; bool suc; diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index 9993ae11b..6389e0e60 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -60,6 +60,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver) driver->hor_res = LV_HOR_RES_MAX; driver->ver_res = LV_VER_RES_MAX; driver->buffer = NULL; + driver->rotated = 1; #if LV_ANTIALIAS driver->antialiasing = true; @@ -171,6 +172,21 @@ void lv_disp_remove(lv_disp_t * disp) if(was_default) lv_disp_set_default(lv_ll_get_head(&LV_GC_ROOT(_lv_disp_ll))); } +/** + * Update the driver in run time. + * @param disp Pointer toa display. (return value of `lv_disp_drv_register`) + * @param new_drv pointer to the new driver + */ +void lv_disp_update_drv(lv_disp_t * disp, lv_disp_drv_t * new_drv) +{ + memcpy(&disp->driver, new_drv, sizeof(lv_disp_drv_t)); + + lv_obj_t * scr; + LV_LL_READ(disp->scr_ll, scr) { + lv_obj_set_size(scr, lv_disp_get_hor_res(disp), lv_disp_get_ver_res(disp)); + } +} + /** * Set a default screen. The new screens will be created on it by default. * @param disp pointer to a display @@ -198,8 +214,8 @@ lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp) { if(disp == NULL) disp = lv_disp_get_default(); - if(disp == NULL) return LV_HOR_RES_MAX; - else return disp->driver.hor_res; + if(disp == NULL) return disp->driver.rotated == 0 ? LV_HOR_RES_MAX : LV_VER_RES_MAX; + else return disp->driver.rotated == 0 ? disp->driver.hor_res : disp->driver.ver_res; } /** @@ -211,8 +227,8 @@ lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp) { if(disp == NULL) disp = lv_disp_get_default(); - if(disp == NULL) return LV_VER_RES_MAX; - else return disp->driver.ver_res; + if(disp == NULL) return disp->driver.rotated == 0 ? LV_VER_RES_MAX : LV_HOR_RES_MAX; + else return disp->driver.rotated == 0 ? disp->driver.ver_res : disp->driver.hor_res; } /** diff --git a/src/lv_hal/lv_hal_disp.h b/src/lv_hal/lv_hal_disp.h index 47818f513..3bd091959 100644 --- a/src/lv_hal/lv_hal_disp.h +++ b/src/lv_hal/lv_hal_disp.h @@ -71,6 +71,7 @@ typedef struct _disp_drv_t { #if LV_ANTIALIAS uint32_t antialiasing :1; #endif + uint32_t rotated :1; /*1: turn the display by 90 degree.*/ /* MANDATORY: Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished */ void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);