diff --git a/Adafruit_ILI9341.cpp b/Adafruit_ILI9341.cpp index c962765..eda9b4a 100755 --- a/Adafruit_ILI9341.cpp +++ b/Adafruit_ILI9341.cpp @@ -302,13 +302,24 @@ 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 }