ST7789: Display offsets are now runtime configurable

We don't change previous functionality by adding a helper function that sets the user offsets when initializing the display
This commit is contained in:
C47D 2022-01-06 00:05:03 -06:00 committed by Carlos Diaz
parent 31399e012a
commit 9ee177b684
2 changed files with 78 additions and 31 deletions

View file

@ -33,9 +33,12 @@ static void st7789_send_data(lv_disp_drv_t * drv, void *data, uint16_t length);
static void st7789_send_color(lv_disp_drv_t * drv, void *data, uint16_t length); static void st7789_send_color(lv_disp_drv_t * drv, void *data, uint16_t length);
static void st7789_reset(lv_disp_drv_t * drv); static void st7789_reset(lv_disp_drv_t * drv);
static void setup_initial_offsets(void);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static uint16_t user_x_offset = 0u;
static uint16_t user_y_offset = 0u;
/********************** /**********************
* MACROS * MACROS
@ -46,6 +49,8 @@ static void st7789_reset(lv_disp_drv_t * drv);
**********************/ **********************/
void st7789_init(lv_disp_drv_t *drv) void st7789_init(lv_disp_drv_t *drv)
{ {
setup_initial_offsets();
lcd_init_cmd_t st7789_init_cmds[] = { lcd_init_cmd_t st7789_init_cmds[] = {
{0xCF, {0x00, 0x83, 0X30}, 3}, {0xCF, {0x00, 0x83, 0X30}, 3},
{0xED, {0x64, 0x03, 0X12, 0X81}, 4}, {0xED, {0x64, 0x03, 0X12, 0X81}, 4},
@ -111,37 +116,10 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
uint16_t offsety2 = area->y2; uint16_t offsety2 = area->y2;
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
#if (CONFIG_LV_TFT_DISPLAY_OFFSETS) offsetx1 += st7789_x_offset();
offsetx1 += CONFIG_LV_TFT_DISPLAY_X_OFFSET; offsetx2 += st7789_x_offset();
offsetx2 += CONFIG_LV_TFT_DISPLAY_X_OFFSET; offsety1 += st7789_y_offset();
offsety1 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET; offsety2 += st7789_y_offset();
offsety2 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET;
#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 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
/*Column addresses*/ /*Column addresses*/
st7789_send_cmd(drv, ST7789_CASET); st7789_send_cmd(drv, ST7789_CASET);
@ -164,6 +142,26 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
st7789_send_color(drv, (void*) color_map, size * 2); st7789_send_color(drv, (void*) color_map, size * 2);
} }
void st7789_set_x_offset(const uint16_t offset)
{
user_x_offset = offset;
}
void st7789_set_y_offset(const uint16_t offset)
{
user_y_offset = offset;
}
uint16_t st7789_x_offset(void)
{
return user_x_offset;
}
uint16_t st7789_y_offset(void)
{
return user_y_offset;
}
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
@ -217,6 +215,35 @@ static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation)
st7789_send_data(drv, (void *) &data[orientation], 1); st7789_send_data(drv, (void *) &data[orientation], 1);
} }
static void setup_initial_offsets(void)
{
#if (CONFIG_LV_TFT_DISPLAY_OFFSETS)
st7789_set_x_offset(CONFIG_LV_TFT_DISPLAY_X_OFFSET);
st7789_set_y_offset(CONFIG_LV_TFT_DISPLAY_Y_OFFSET);
#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 240)
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT)
st7789_set_x_offset(80);
st7789_set_y_offset(0);
#elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
st7789_set_x_offset(0);
st7789_set_y_offset(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)
st7789_set_x_offset(40);
st7789_set_y_offset(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)
st7789_set_x_offset(52);
st7789_set_y_offset(40);
#endif
#endif
}
/* Display update callback, we could update the orientation in here /* Display update callback, we could update the orientation in here
* NOTE Available only for LVGL v8 */ * NOTE Available only for LVGL v8 */
void st7789_update_cb(lv_disp_drv_t *drv) void st7789_update_cb(lv_disp_drv_t *drv)

View file

@ -115,6 +115,26 @@ void st7789_init(lv_disp_drv_t *drv);
*/ */
void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map); void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
/**
* Set display buffer offset at x axis
*/
void st7789_set_x_offset(const uint16_t offset);
/**
* Set display buffer offset at y axis
*/
void st7789_set_y_offset(const uint16_t offset);
/**
* Get display buffer offset at x axis
*/
uint16_t st7789_x_offset(void);
/**
* Get display buffer offset at y axis
*/
uint16_t st7789_y_offset(void);
/** /**
* Display updated callback * Display updated callback
* *