From 7e17a48754181e5669222e17bf345224f624c073 Mon Sep 17 00:00:00 2001 From: Laurence Bank Date: Sat, 6 Jun 2020 18:47:46 -0400 Subject: [PATCH 1/2] Optimized setAddrWindow() to only set the axis which changes --- Adafruit_ILI9341.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Adafruit_ILI9341.cpp b/Adafruit_ILI9341.cpp index 1eb237a..a1d41e8 100755 --- a/Adafruit_ILI9341.cpp +++ b/Adafruit_ILI9341.cpp @@ -302,13 +302,22 @@ void Adafruit_ILI9341::setScrollMargins(uint16_t top, uint16_t bottom) { /**************************************************************************/ void Adafruit_ILI9341::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h) { +static uint16_t old_x1 = 0xffff, old_x2 = 0xffff; +static uint16_t old_y1 = 0xffff, old_y2 = 0xffff; + uint16_t x2 = (x1 + w - 1), y2 = (y1 + h - 1); - writeCommand(ILI9341_CASET); // Column address set - SPI_WRITE16(x1); - SPI_WRITE16(x2); - writeCommand(ILI9341_PASET); // Row address set - SPI_WRITE16(y1); - SPI_WRITE16(y2); + if (x1 != old_x1 || x2 != old_x2) { + writeCommand(ILI9341_CASET); // Column address set + SPI_WRITE16(x1); + SPI_WRITE16(x2); + old_x1 = x1; old_x2 = x2; + } + if (y1 != old_y1 || y2 != old_y2) { + writeCommand(ILI9341_PASET); // Row address set + SPI_WRITE16(y1); + SPI_WRITE16(y2); + old_y1 = y1; old_y2 = y2; + } writeCommand(ILI9341_RAMWR); // Write to RAM } From 86bc50a69e7d233a534feb5d3196c4c823756ccb Mon Sep 17 00:00:00 2001 From: Laurence Bank Date: Sun, 7 Jun 2020 12:55:55 -0400 Subject: [PATCH 2/2] Reformatted with clang-format --- Adafruit_ILI9341.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Adafruit_ILI9341.cpp b/Adafruit_ILI9341.cpp index a1d41e8..eea54ac 100755 --- a/Adafruit_ILI9341.cpp +++ b/Adafruit_ILI9341.cpp @@ -302,21 +302,23 @@ void Adafruit_ILI9341::setScrollMargins(uint16_t top, uint16_t bottom) { /**************************************************************************/ void Adafruit_ILI9341::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h) { -static uint16_t old_x1 = 0xffff, old_x2 = 0xffff; -static uint16_t old_y1 = 0xffff, old_y2 = 0xffff; + static uint16_t old_x1 = 0xffff, old_x2 = 0xffff; + static uint16_t old_y1 = 0xffff, old_y2 = 0xffff; uint16_t x2 = (x1 + w - 1), y2 = (y1 + h - 1); if (x1 != old_x1 || x2 != old_x2) { writeCommand(ILI9341_CASET); // Column address set SPI_WRITE16(x1); SPI_WRITE16(x2); - old_x1 = x1; old_x2 = x2; + old_x1 = x1; + old_x2 = x2; } if (y1 != old_y1 || y2 != old_y2) { writeCommand(ILI9341_PASET); // Row address set SPI_WRITE16(y1); SPI_WRITE16(y2); - old_y1 = y1; old_y2 = y2; + old_y1 = y1; + old_y2 = y2; } writeCommand(ILI9341_RAMWR); // Write to RAM }