From e3f57f80df23c4b646f5c3896b52070efb48b4bf Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Fri, 17 Apr 2020 07:35:36 +0200 Subject: [PATCH] Accelerate clear screen in st7789 driver --- src/st7789.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/st7789.cc b/src/st7789.cc index 39bbc88..a2a4145 100644 --- a/src/st7789.cc +++ b/src/st7789.cc @@ -1,3 +1,4 @@ +#include #include #include "st7789.h" @@ -115,17 +116,21 @@ void St7789::send_data(uint8_t data) void St7789::clear(uint16_t Color) { - unsigned int i,j; + unsigned int odd = 0; + std::array line; + for(auto it = line.begin(); it != line.end(); ++it) { + if(odd % 2 == 0) { + *it = static_cast((Color >> 8) & 0xff); + } else { + *it = static_cast(Color & 0xff); + } + odd++; + } set_windows(0, 0, 240, 240); this->data_command.set(); - for(i = 0; i < 240; i++) { - for(j = 0; j < 240; j++){ - uint8_t c = (Color >> 8) & 0xff; - this->spi.send(&c, 1); - c = Color & 0xff; - this->spi.send(&c, 1); - } + for(unsigned int i = 0; i < 240 * 2; i++) { + this->spi.send(line.data(), line.size()); } }