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;