From 896cdab22dfde5fbd64f3d0506d0d0d3990ef28b Mon Sep 17 00:00:00 2001 From: Manuel Kasper Date: Tue, 18 Jun 2024 21:53:01 +0200 Subject: [PATCH] Fix garbled graphics on LILYGO T4-S3 display (#6910) --- esphome/components/qspi_amoled/display.py | 20 +++++++++++++++---- .../components/qspi_amoled/qspi_amoled.cpp | 13 ++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/esphome/components/qspi_amoled/display.py b/esphome/components/qspi_amoled/display.py index 84bf9553cb..77d1e3d095 100644 --- a/esphome/components/qspi_amoled/display.py +++ b/esphome/components/qspi_amoled/display.py @@ -42,6 +42,14 @@ COLOR_ORDERS = { } DATA_PIN_SCHEMA = pins.internal_gpio_output_pin_schema + +def validate_dimension(value): + value = cv.positive_int(value) + if value % 2 != 0: + raise cv.Invalid("Width/height/offset must be divisible by 2") + return value + + CONFIG_SCHEMA = cv.All( display.FULL_DISPLAY_SCHEMA.extend( cv.Schema( @@ -52,10 +60,14 @@ CONFIG_SCHEMA = cv.All( cv.dimensions, cv.Schema( { - cv.Required(CONF_WIDTH): cv.int_, - cv.Required(CONF_HEIGHT): cv.int_, - cv.Optional(CONF_OFFSET_HEIGHT, default=0): cv.int_, - cv.Optional(CONF_OFFSET_WIDTH, default=0): cv.int_, + cv.Required(CONF_WIDTH): validate_dimension, + cv.Required(CONF_HEIGHT): validate_dimension, + cv.Optional( + CONF_OFFSET_HEIGHT, default=0 + ): validate_dimension, + cv.Optional( + CONF_OFFSET_WIDTH, default=0 + ): validate_dimension, } ), ), diff --git a/esphome/components/qspi_amoled/qspi_amoled.cpp b/esphome/components/qspi_amoled/qspi_amoled.cpp index 697989e861..36e9b03252 100644 --- a/esphome/components/qspi_amoled/qspi_amoled.cpp +++ b/esphome/components/qspi_amoled/qspi_amoled.cpp @@ -26,6 +26,19 @@ void QspiAmoLed::setup() { void QspiAmoLed::update() { this->do_update_(); + // Start addresses and widths/heights must be divisible by 2 (CASET/RASET restriction in datasheet) + if (this->x_low_ % 2 == 1) { + this->x_low_--; + } + if (this->x_high_ % 2 == 0) { + this->x_high_++; + } + if (this->y_low_ % 2 == 1) { + this->y_low_--; + } + if (this->y_high_ % 2 == 0) { + this->y_high_++; + } int w = this->x_high_ - this->x_low_ + 1; int h = this->y_high_ - this->y_low_ + 1; this->draw_pixels_at(this->x_low_, this->y_low_, w, h, this->buffer_, this->color_mode_, display::COLOR_BITNESS_565,