Skip to content

Commit 7e17a48

Browse files
committed
Optimized setAddrWindow() to only set the axis which changes
1 parent 655e749 commit 7e17a48

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Adafruit_ILI9341.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,22 @@ void Adafruit_ILI9341::setScrollMargins(uint16_t top, uint16_t bottom) {
302302
/**************************************************************************/
303303
void Adafruit_ILI9341::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w,
304304
uint16_t h) {
305+
static uint16_t old_x1 = 0xffff, old_x2 = 0xffff;
306+
static uint16_t old_y1 = 0xffff, old_y2 = 0xffff;
307+
305308
uint16_t x2 = (x1 + w - 1), y2 = (y1 + h - 1);
306-
writeCommand(ILI9341_CASET); // Column address set
307-
SPI_WRITE16(x1);
308-
SPI_WRITE16(x2);
309-
writeCommand(ILI9341_PASET); // Row address set
310-
SPI_WRITE16(y1);
311-
SPI_WRITE16(y2);
309+
if (x1 != old_x1 || x2 != old_x2) {
310+
writeCommand(ILI9341_CASET); // Column address set
311+
SPI_WRITE16(x1);
312+
SPI_WRITE16(x2);
313+
old_x1 = x1; old_x2 = x2;
314+
}
315+
if (y1 != old_y1 || y2 != old_y2) {
316+
writeCommand(ILI9341_PASET); // Row address set
317+
SPI_WRITE16(y1);
318+
SPI_WRITE16(y2);
319+
old_y1 = y1; old_y2 = y2;
320+
}
312321
writeCommand(ILI9341_RAMWR); // Write to RAM
313322
}
314323

0 commit comments

Comments
 (0)