From 8c329414284dba6ab6d6799286e9fb4360eaf9a9 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 10 May 2023 01:19:28 +0200 Subject: [PATCH] [ili9xxx] Improve fill operation performance (#4702) Co-authored-by: Your Name --- esphome/components/ili9xxx/ili9xxx_display.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/esphome/components/ili9xxx/ili9xxx_display.cpp b/esphome/components/ili9xxx/ili9xxx_display.cpp index 1b5248fa29..67d643fe31 100644 --- a/esphome/components/ili9xxx/ili9xxx_display.cpp +++ b/esphome/components/ili9xxx/ili9xxx_display.cpp @@ -84,9 +84,18 @@ void ILI9XXXDisplay::fill(Color color) { break; case BITS_16: new_color = display::ColorUtil::color_to_565(color); - for (uint32_t i = 0; i < this->get_buffer_length_() * 2; i = i + 2) { - this->buffer_[i] = (uint8_t) (new_color >> 8); - this->buffer_[i + 1] = (uint8_t) new_color; + { + const uint32_t buffer_length_16_bits = this->get_buffer_length_() * 2; + if (((uint8_t) (new_color >> 8)) == ((uint8_t) new_color)) { + // Upper and lower is equal can use quicker memset operation. Takes ~20ms. + memset(this->buffer_, (uint8_t) new_color, buffer_length_16_bits); + } else { + // Slower set of both buffers. Takes ~30ms. + for (uint32_t i = 0; i < buffer_length_16_bits; i = i + 2) { + this->buffer_[i] = (uint8_t) (new_color >> 8); + this->buffer_[i + 1] = (uint8_t) new_color; + } + } } return; break;