This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 355127fa788f3ad29b36c9e0bf3ece79a75e29ce Author: Jerzy Kasenberg <[email protected]> AuthorDate: Thu Aug 21 00:08:12 2025 +0200 lvgl/st7789: Screen resolution update ST7789 had hardcoded configurations for few resolutions (240x320, 240x240, 240x135) There are other configurations available. Now offsets are computed in runtime. This also fixes rotation to be aligned with other drivers. Signed-off-by: Jerzy Kasenberg <[email protected]> --- hw/drivers/display/lvgl/tft/st7789/src/st7789.c | 52 ++++++++++--------------- hw/drivers/display/lvgl/tft/st7789/syscfg.yml | 11 +++++- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/hw/drivers/display/lvgl/tft/st7789/src/st7789.c b/hw/drivers/display/lvgl/tft/st7789/src/st7789.c index 633f1c98c..c8d0677ae 100644 --- a/hw/drivers/display/lvgl/tft/st7789/src/st7789.c +++ b/hw/drivers/display/lvgl/tft/st7789/src/st7789.c @@ -138,6 +138,22 @@ #define ST7789_HOR_RES MYNEWT_VAL(LVGL_DISPLAY_HORIZONTAL_RESOLUTION) #define ST7789_VER_RES MYNEWT_VAL(LVGL_DISPLAY_VERTICAL_RESOLUTION) +#ifdef MYNEWT_VAL_ST7789_HORIZONTAL_OFFSET +#define HOR_OFF MYNEWT_VAL_ST7789_HORIZONTAL_OFFSET +#else +#define HOR_OFF ((240 - ST7789_HOR_RES) / 2) +#endif +#ifdef MYNEWT_VAL_ST7789_VERTICAL_OFFSET +#define VER_OFF MYNEWT_VAL_ST7789_VERTICAL_OFFSET +#else +#define VER_OFF ((320 - ST7789_VER_RES) / 2) +#endif + +static const uint16_t x_off[4] = { HOR_OFF, 320 - ST7789_VER_RES - VER_OFF, + 240 - ST7789_HOR_RES - HOR_OFF, VER_OFF }; +static const uint16_t y_off[4] = { VER_OFF, 240 - ST7789_HOR_RES - HOR_OFF, + 320 - ST7789_VER_RES - VER_OFF, HOR_OFF }; + void st7789_rotate(lv_disp_rot_t rotation) { @@ -212,6 +228,7 @@ st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) lv_disp_t *disp = lv_disp_get_default(); lv_coord_t hor_res = lv_disp_get_hor_res(disp); lv_coord_t ver_res = lv_disp_get_ver_res(disp); + int rot = drv->rotated; if (area->x2 < 0 || area->y2 < 0 || area->x1 >= hor_res || area->y1 >= ver_res) { lv_disp_flush_ready(drv); @@ -224,37 +241,10 @@ st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) int32_t offsetx2 = area->x2 >= hor_res ? hor_res - 1 : area->x2; int32_t offsety2 = area->y2 >= ver_res ? ver_res - 1 : area->y2; -#if (CONFIG_LV_TFT_DISPLAY_OFFSETS) - offsetx1 += CONFIG_LV_TFT_DISPLAY_X_OFFSET; - offsetx2 += CONFIG_LV_TFT_DISPLAY_X_OFFSET; - offsety1 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET; - offsety2 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET; - -#elif (ST7789_HOR_RES == 240) && (ST7789_VER_RES == 240) -#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) - offsetx1 += 80; - offsetx2 += 80; -#elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) - offsety1 += 80; - offsety2 += 80; -#endif -#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 135) -#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) || \ - (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED) - offsetx1 += 40; - offsetx2 += 40; - offsety1 += 53; - offsety2 += 53; -#endif -#elif (LV_HOR_RES_MAX == 135) && (LV_VER_RES_MAX == 240) -#if (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE) || \ - (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) - offsetx1 += 52; - offsetx2 += 52; - offsety1 += 40; - offsety2 += 40; -#endif -#endif + offsetx1 += x_off[rot]; + offsetx2 += x_off[rot]; + offsety1 += y_off[rot]; + offsety2 += y_off[rot]; /* Column addresses */ cmd[0] = ST7789_CASET; diff --git a/hw/drivers/display/lvgl/tft/st7789/syscfg.yml b/hw/drivers/display/lvgl/tft/st7789/syscfg.yml index d37a5b817..2e44a93fd 100644 --- a/hw/drivers/display/lvgl/tft/st7789/syscfg.yml +++ b/hw/drivers/display/lvgl/tft/st7789/syscfg.yml @@ -20,7 +20,16 @@ syscfg.defs: ST7789_INVERSION_ON: description: ST7789 enable display inversion. value: 1 - + ST7789_HORIZONTAL_OFFSET: + description: > + Value added to x coordinates. + This can be set if display is not aligned correctly. + value: + ST7789_VERTICAL_OFFSET: + description: > + Value added to y coordinates. + This can be set if display is not aligned correctly. + value: syscfg.vals: LVGL_DISPLAY_HORIZONTAL_RESOLUTION: 240 LVGL_DISPLAY_VERTICAL_RESOLUTION: 320
