Optimized setAddrWindow() to only set the axis which changes

This commit is contained in:
Laurence Bank committed 2020-06-06 18:47:46 -04:00
1 parent 655e7494ae
commit 7e17a48754
1 file changed
+15 -6
+15 -6
View File
@@ -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
}