Skip to content

ST7789: Make display offsets runtime configurable #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lvgl_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ void lvgl_driver_init(void)
void display_bsp_init_io(void)
{
esp_err_t err = ESP_OK;
gpio_config_t io_conf;
gpio_config_t io_conf = {
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};

#ifdef CONFIG_LV_DISPLAY_USE_DC
io_conf.mode = GPIO_MODE_OUTPUT;
Expand All @@ -160,7 +164,7 @@ void display_bsp_init_io(void)
ESP_ERROR_CHECK(err);
#endif

#ifdef CONFIG_LV_DISP_PIN_BUSY
#ifdef CONFIG_LV_DISP_USE_BUSY
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = (1ULL << CONFIG_LV_DISP_PIN_BUSY);
err = gpio_config(&io_conf);
Expand Down
7 changes: 7 additions & 0 deletions lvgl_tft/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,13 @@ menu "LVGL TFT Display controller"
help
Configure the display Reset pin here.

config LV_DISP_USE_BUSY
bool "Use a GPIO for busy signal" if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
default y if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
default n
help
Use a GPIO for busy signal available in e-ink display controllers.

config LV_DISP_PIN_BUSY
int "GPIO for Busy" if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
default 35 if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
Expand Down
89 changes: 58 additions & 31 deletions lvgl_tft/st7789.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_reset(lv_disp_drv_t * drv);

static void setup_initial_offsets(void);
/**********************
* STATIC VARIABLES
**********************/
static uint16_t user_x_offset = 0u;
static uint16_t user_y_offset = 0u;

/**********************
* MACROS
Expand All @@ -46,6 +49,8 @@ static void st7789_reset(lv_disp_drv_t * drv);
**********************/
void st7789_init(lv_disp_drv_t *drv)
{
setup_initial_offsets();

lcd_init_cmd_t st7789_init_cmds[] = {
{0xCF, {0x00, 0x83, 0X30}, 3},
{0xED, {0x64, 0x03, 0X12, 0X81}, 4},
Expand Down Expand Up @@ -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;
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);

#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 (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
offsetx1 += st7789_x_offset();
offsetx2 += st7789_x_offset();
offsety1 += st7789_y_offset();
offsety2 += st7789_y_offset();

/*Column addresses*/
st7789_send_cmd(drv, ST7789_CASET);
Expand All @@ -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);
}

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
**********************/
Expand Down Expand Up @@ -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);
}

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
* NOTE Available only for LVGL v8 */
void st7789_update_cb(lv_disp_drv_t *drv)
Expand Down
20 changes: 20 additions & 0 deletions lvgl_tft/st7789.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
* 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
*
Expand Down