Skip to content

Commit 355127f

Browse files
committed
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]>
1 parent d9dc158 commit 355127f

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

hw/drivers/display/lvgl/tft/st7789/src/st7789.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@
138138
#define ST7789_HOR_RES MYNEWT_VAL(LVGL_DISPLAY_HORIZONTAL_RESOLUTION)
139139
#define ST7789_VER_RES MYNEWT_VAL(LVGL_DISPLAY_VERTICAL_RESOLUTION)
140140

141+
#ifdef MYNEWT_VAL_ST7789_HORIZONTAL_OFFSET
142+
#define HOR_OFF MYNEWT_VAL_ST7789_HORIZONTAL_OFFSET
143+
#else
144+
#define HOR_OFF ((240 - ST7789_HOR_RES) / 2)
145+
#endif
146+
#ifdef MYNEWT_VAL_ST7789_VERTICAL_OFFSET
147+
#define VER_OFF MYNEWT_VAL_ST7789_VERTICAL_OFFSET
148+
#else
149+
#define VER_OFF ((320 - ST7789_VER_RES) / 2)
150+
#endif
151+
152+
static const uint16_t x_off[4] = { HOR_OFF, 320 - ST7789_VER_RES - VER_OFF,
153+
240 - ST7789_HOR_RES - HOR_OFF, VER_OFF };
154+
static const uint16_t y_off[4] = { VER_OFF, 240 - ST7789_HOR_RES - HOR_OFF,
155+
320 - ST7789_VER_RES - VER_OFF, HOR_OFF };
156+
141157
void
142158
st7789_rotate(lv_disp_rot_t rotation)
143159
{
@@ -212,6 +228,7 @@ st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p)
212228
lv_disp_t *disp = lv_disp_get_default();
213229
lv_coord_t hor_res = lv_disp_get_hor_res(disp);
214230
lv_coord_t ver_res = lv_disp_get_ver_res(disp);
231+
int rot = drv->rotated;
215232

216233
if (area->x2 < 0 || area->y2 < 0 || area->x1 >= hor_res || area->y1 >= ver_res) {
217234
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)
224241
int32_t offsetx2 = area->x2 >= hor_res ? hor_res - 1 : area->x2;
225242
int32_t offsety2 = area->y2 >= ver_res ? ver_res - 1 : area->y2;
226243

227-
#if (CONFIG_LV_TFT_DISPLAY_OFFSETS)
228-
offsetx1 += CONFIG_LV_TFT_DISPLAY_X_OFFSET;
229-
offsetx2 += CONFIG_LV_TFT_DISPLAY_X_OFFSET;
230-
offsety1 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET;
231-
offsety2 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET;
232-
233-
#elif (ST7789_HOR_RES == 240) && (ST7789_VER_RES == 240)
234-
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT)
235-
offsetx1 += 80;
236-
offsetx2 += 80;
237-
#elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
238-
offsety1 += 80;
239-
offsety2 += 80;
240-
#endif
241-
#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 135)
242-
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) || \
243-
(CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
244-
offsetx1 += 40;
245-
offsetx2 += 40;
246-
offsety1 += 53;
247-
offsety2 += 53;
248-
#endif
249-
#elif (LV_HOR_RES_MAX == 135) && (LV_VER_RES_MAX == 240)
250-
#if (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE) || \
251-
(CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
252-
offsetx1 += 52;
253-
offsetx2 += 52;
254-
offsety1 += 40;
255-
offsety2 += 40;
256-
#endif
257-
#endif
244+
offsetx1 += x_off[rot];
245+
offsetx2 += x_off[rot];
246+
offsety1 += y_off[rot];
247+
offsety2 += y_off[rot];
258248

259249
/* Column addresses */
260250
cmd[0] = ST7789_CASET;

hw/drivers/display/lvgl/tft/st7789/syscfg.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ syscfg.defs:
2020
ST7789_INVERSION_ON:
2121
description: ST7789 enable display inversion.
2222
value: 1
23-
23+
ST7789_HORIZONTAL_OFFSET:
24+
description: >
25+
Value added to x coordinates.
26+
This can be set if display is not aligned correctly.
27+
value:
28+
ST7789_VERTICAL_OFFSET:
29+
description: >
30+
Value added to y coordinates.
31+
This can be set if display is not aligned correctly.
32+
value:
2433
syscfg.vals:
2534
LVGL_DISPLAY_HORIZONTAL_RESOLUTION: 240
2635
LVGL_DISPLAY_VERTICAL_RESOLUTION: 320

0 commit comments

Comments
 (0)