From e2e6479fb07d5f88d8dfd6335dea346acc54d7d1 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 7 Feb 2019 19:17:10 +0100 Subject: [PATCH] multi_disp: add dynamic hor/ver res --- lv_conf_checker.h | 4 +-- lv_core/lv_disp.c | 54 ++++++++++++++++++++++++++++++++++++++++ lv_core/lv_disp.h | 42 +++++++++++++++++++++++++++++++ lv_core/lv_obj.c | 4 +-- lv_core/lv_obj.h | 2 +- lv_core/lv_refr.c | 6 ++--- lv_draw/lv_draw_rbasic.c | 2 +- lv_draw/lv_draw_vbasic.c | 2 +- lv_hal/lv_hal_disp.h | 1 + lv_objx/lv_btnm.c | 2 +- lv_objx/lv_chart.c | 2 +- lv_objx/lv_kb.c | 2 +- lv_objx/lv_mbox.c | 2 +- lv_objx/lv_tabview.c | 4 +-- lv_objx/lv_tileview.c | 6 ++--- lv_objx/lv_win.c | 3 +-- lvgl.h | 1 + 17 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 lv_core/lv_disp.c create mode 100644 lv_core/lv_disp.h diff --git a/lv_conf_checker.h b/lv_conf_checker.h index e4caa9480..10f6a1436 100644 --- a/lv_conf_checker.h +++ b/lv_conf_checker.h @@ -62,10 +62,10 @@ /* Horizontal and vertical resolution of the library.*/ #ifndef LV_HOR_RES -#define LV_HOR_RES (480) +//#define LV_HOR_RES (480) #endif #ifndef LV_VER_RES -#define LV_VER_RES (320) +//#define LV_VER_RES (320) #endif /* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide diff --git a/lv_core/lv_disp.c b/lv_core/lv_disp.c new file mode 100644 index 000000000..d4fc22e25 --- /dev/null +++ b/lv_core/lv_disp.c @@ -0,0 +1,54 @@ +/** + * @file lv_disp.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_disp.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp) +{ + if(disp == NULL) disp = lv_disp_get_active(); + + if(disp == NULL) return LV_HOR_RES_MAX; + else return disp->driver.hor_res; +} + + +lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp) +{ + if(disp == NULL) disp = lv_disp_get_active(); + + if(disp == NULL) return LV_VER_RES_MAX; + else return disp->driver.ver_res; +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/lv_core/lv_disp.h b/lv_core/lv_disp.h new file mode 100644 index 000000000..89db388f9 --- /dev/null +++ b/lv_core/lv_disp.h @@ -0,0 +1,42 @@ +/** + * @file lv_disp.h + * + */ + +#ifndef LV_DISP_H +#define LV_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_hal/lv_hal_disp.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp); +lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/lv_core/lv_obj.c b/lv_core/lv_obj.c index a58ead8c2..ae8f45178 100644 --- a/lv_core/lv_obj.c +++ b/lv_core/lv_obj.c @@ -144,8 +144,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Set coordinates to full screen size*/ new_obj->coords.x1 = 0; new_obj->coords.y1 = 0; - new_obj->coords.x2 = LV_HOR_RES - 1; - new_obj->coords.y2 = LV_VER_RES - 1; + new_obj->coords.x2 = lv_disp_get_hor_res(NULL) - 1; + new_obj->coords.y2 = lv_disp_get_ver_res(NULL) - 1; new_obj->ext_size = 0; /*Init realign*/ diff --git a/lv_core/lv_obj.h b/lv_core/lv_obj.h index cfd8a8ac3..7f8f848ab 100644 --- a/lv_core/lv_obj.h +++ b/lv_core/lv_obj.h @@ -33,7 +33,7 @@ extern "C" { *********************/ /*Error check of lv_conf.h*/ -#if LV_HOR_RES == 0 || LV_VER_RES == 0 +#if LV_HOR_RES_MAX == 0 || LV_VER_RES_MAX == 0 #error "LittlevGL: LV_HOR_RES and LV_VER_RES must be greater than 0" #endif diff --git a/lv_core/lv_refr.c b/lv_core/lv_refr.c index d6987832a..98c3a2709 100644 --- a/lv_core/lv_refr.c +++ b/lv_core/lv_refr.c @@ -102,8 +102,8 @@ void lv_inv_area(const lv_area_t * area_p) lv_area_t scr_area; scr_area.x1 = 0; scr_area.y1 = 0; - scr_area.x2 = LV_HOR_RES - 1; - scr_area.y2 = LV_VER_RES - 1; + scr_area.x2 = LV_HOR_RES_MAX - 1; + scr_area.y2 = LV_VER_RES_MAX - 1; lv_area_t com_area; bool suc; @@ -346,7 +346,7 @@ static void lv_refr_area_with_vdb(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_VER_RES ? y2 = LV_VER_RES - 1 : area_p->y2; + lv_coord_t y2 = area_p->y2 >= lv_disp_get_ver_res(NULL) ? y2 = lv_disp_get_ver_res(NULL) - 1 : area_p->y2; int32_t max_row = (uint32_t) LV_VDB_SIZE / w; diff --git a/lv_draw/lv_draw_rbasic.c b/lv_draw/lv_draw_rbasic.c index 369adf523..647554924 100644 --- a/lv_draw/lv_draw_rbasic.c +++ b/lv_draw/lv_draw_rbasic.c @@ -79,7 +79,7 @@ void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, union_ok = lv_area_intersect(&masked_area, cords_p, mask_p); } else { lv_area_t scr_area; - lv_area_set(&scr_area, 0, 0, LV_HOR_RES - 1, LV_VER_RES - 1); + lv_area_set(&scr_area, 0, 0, lv_disp_get_hor_res(NULL) - 1, lv_disp_get_ver_res(NULL) - 1); union_ok = lv_area_intersect(&masked_area, cords_p, &scr_area); } diff --git a/lv_draw/lv_draw_vbasic.c b/lv_draw/lv_draw_vbasic.c index c8b2fab55..8ab127856 100644 --- a/lv_draw/lv_draw_vbasic.c +++ b/lv_draw/lv_draw_vbasic.c @@ -147,7 +147,7 @@ void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, #if USE_LV_GPU - static lv_color_t color_array_tmp[LV_HOR_RES]; /*Used by 'lv_disp_mem_blend'*/ + static lv_color_t color_array_tmp[LV_HOR_RES_MAX]; /*Used by 'lv_disp_mem_blend'*/ static lv_coord_t last_width = -1; lv_coord_t w = lv_area_get_width(&vdb_rel_a); diff --git a/lv_hal/lv_hal_disp.h b/lv_hal/lv_hal_disp.h index 15019ef43..e298b4ac8 100644 --- a/lv_hal/lv_hal_disp.h +++ b/lv_hal/lv_hal_disp.h @@ -20,6 +20,7 @@ extern "C" { #include "lv_hal.h" #include "../lv_misc/lv_color.h" #include "../lv_misc/lv_area.h" +#include "../lv_core/lv_obj.h" /********************* * DEFINES diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 07e6a72b2..33abbf20c 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -97,7 +97,7 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new button matrix object*/ if(copy == NULL) { - lv_obj_set_size(new_btnm, LV_HOR_RES / 2, LV_VER_RES / 4); + lv_obj_set_size(new_btnm, LV_DPI * 3, LV_DPI * 2); lv_btnm_set_map(new_btnm, lv_btnm_def_map); /*Set the default styles*/ diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index 1dedaa7a4..0904bb91f 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -90,7 +90,7 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new chart background object*/ if(copy == NULL) { - lv_obj_set_size(new_chart, LV_HOR_RES / 3, LV_VER_RES / 3); + lv_obj_set_size(new_chart, LV_DPI * 3, LV_DPI * 2); /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index 395fc8d5d..d41b5962d 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -102,7 +102,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new keyboard keyboard*/ if(copy == NULL) { - lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2); + lv_obj_set_size(new_kb, LV_DPI * 3, LV_DPI * 2); lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_btnm_set_action(new_kb, lv_kb_def_action); lv_btnm_set_map(new_kb, kb_map_lc); diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index af53ddd4d..ac355d10a 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -91,7 +91,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy) lv_cont_set_layout(new_mbox, LV_LAYOUT_COL_M); lv_cont_set_fit(new_mbox, false, true); - lv_obj_set_width(new_mbox, LV_HOR_RES / 2); + lv_obj_set_width(new_mbox, LV_DPI * 2); lv_obj_align(new_mbox, NULL, LV_ALIGN_CENTER, 0, 0); /*Set the default styles*/ diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index 8b16ec878..c09560fbd 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -106,7 +106,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) ext->tab_name_ptr[0] = ""; ext->tab_cnt = 0; - lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES); + lv_obj_set_size(new_tabview, LV_DPI * 3, LV_DPI * 2); ext->btns = lv_btnm_create(new_tabview, NULL); lv_obj_set_height(ext->btns, 3 * LV_DPI / 4); @@ -123,7 +123,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) lv_cont_set_fit(ext->content, true, false); lv_cont_set_layout(ext->content, LV_LAYOUT_ROW_T); lv_cont_set_style(ext->content, &lv_style_transp_tight); - lv_obj_set_height(ext->content, LV_VER_RES - lv_obj_get_height(ext->btns)); + lv_obj_set_height(ext->content, lv_obj_get_height(new_tabview) - lv_obj_get_height(ext->btns)); lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); /*Set the default styles*/ diff --git a/lv_objx/lv_tileview.c b/lv_objx/lv_tileview.c index c80cfecad..447534f32 100644 --- a/lv_objx/lv_tileview.c +++ b/lv_objx/lv_tileview.c @@ -89,7 +89,7 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new tileview*/ if(copy == NULL) { - lv_obj_set_size(new_tileview, LV_HOR_RES, LV_VER_RES); + lv_obj_set_size(new_tileview, LV_DPI * 3, LV_DPI * 3); lv_obj_set_drag_throw(lv_page_get_scrl(new_tileview), false); lv_page_set_scrl_fit(new_tileview, true, true); /*Set the default styles*/ @@ -506,8 +506,8 @@ static void drag_end_handler(lv_obj_t * tileview) lv_obj_t * scrl = lv_page_get_scrl(tileview); lv_point_t p; - p.x = - (scrl->coords.x1 - LV_HOR_RES / 2); - p.y = - (scrl->coords.y1 - LV_VER_RES / 2); + p.x = - (scrl->coords.x1 - lv_obj_get_width(tileview) / 2); + p.y = - (scrl->coords.y1 - lv_obj_get_height(tileview) / 2); /*From the drag vector (drag throw) predict the end position*/ if(ext->drag_hor) { diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index 3bc968dda..60dfe4784 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -70,7 +70,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new window object*/ if(copy == NULL) { - lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES); + lv_obj_set_size(new_win, LV_DPI * 3, LV_DPI * 3); lv_obj_set_pos(new_win, 0, 0); lv_obj_set_style(new_win, &lv_style_pretty); @@ -107,7 +107,6 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) } lv_obj_set_signal_func(new_win, lv_win_signal); - lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES); } /*Copy an existing object*/ else { diff --git a/lvgl.h b/lvgl.h index 2d0dd560d..6aab3e4e0 100644 --- a/lvgl.h +++ b/lvgl.h @@ -26,6 +26,7 @@ extern "C" { #include "lv_core/lv_lang.h" #include "lv_core/lv_vdb.h" #include "lv_core/lv_refr.h" +#include "lv_core/lv_disp.h" #include "lv_themes/lv_theme.h"