@@ -479,16 +479,31 @@ void Adafruit_ILI9341::begin(void) {
479
479
480
480
}
481
481
482
-
483
482
void Adafruit_ILI9341::setAddrWindow (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
483
+ spiCsLow ();
484
+ setAddrWindow_ (x0, y0, x1, y1);
485
+ spiCsHigh ();
486
+ }
484
487
485
- uint8_t buffC[] = {(uint8_t )(x0 >> 8 ), (uint8_t )x0, (uint8_t )(x1 >> 8 ), (uint8_t )x1};
486
- uint8_t buffP[] = {(uint8_t )(y0 >> 8 ), (uint8_t )y0, (uint8_t )(y1 >> 8 ), (uint8_t )y1};
488
+ void Adafruit_ILI9341::setAddrWindow_ (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
487
489
488
- writeCmdData (ILI9341_CASET, &buffC[0 ], sizeof (buffC)); // Column addr set
489
- writeCmdData (ILI9341_PASET, &buffP[0 ], sizeof (buffP)); // Column addr set
490
+ uint8_t buffC[] = { (uint8_t ) (x0 >> 8 ), (uint8_t ) x0, (uint8_t ) (x1 >> 8 ), (uint8_t ) x1 };
491
+ uint8_t buffP[] = { (uint8_t ) (y0 >> 8 ), (uint8_t ) y0, (uint8_t ) (y1 >> 8 ), (uint8_t ) y1 };
492
+
493
+ spiDcLow ();
494
+ spiwrite (ILI9341_CASET);
495
+ spiDcHigh ();
496
+ spiwriteBytes (&buffC[0 ], sizeof (buffC));
497
+
498
+ spiDcLow ();
499
+ spiwrite (ILI9341_PASET);
500
+ spiDcHigh ();
501
+ spiwriteBytes (&buffP[0 ], sizeof (buffP));
502
+
503
+ spiDcLow ();
504
+ spiwrite (ILI9341_RAMWR);
505
+ spiDcHigh ();
490
506
491
- writecommand (ILI9341_RAMWR); // write to RAM
492
507
}
493
508
494
509
@@ -512,71 +527,80 @@ void Adafruit_ILI9341::pushColor(uint16_t color) {
512
527
513
528
void Adafruit_ILI9341::drawPixel (int16_t x, int16_t y, uint16_t color) {
514
529
515
- if ((x < 0 ) ||(x >= _width) || (y < 0 ) || (y >= _height)) return ;
530
+ if ((x < 0 ) || (x >= _width) || (y < 0 ) || (y >= _height)) {
531
+ return ;
532
+ }
516
533
517
- if (hwSPI) spi_begin ();
518
- setAddrWindow (x,y,x+1 ,y+1 );
519
- spiDcHigh ();
520
- spiCsLow ();
534
+ if (hwSPI) {
535
+ spi_begin ();
536
+ }
537
+
538
+ spiCsLow ();
539
+
540
+ setAddrWindow_ (x, y, x + 1 , y + 1 );
521
541
522
542
#ifdef ESP8266
523
- spiwrite16 (color);
543
+ spiwrite16 (color);
524
544
#else
525
- spiwrite (color >> 8 );
526
- spiwrite (color);
545
+ spiwrite (color >> 8 );
546
+ spiwrite (color);
527
547
#endif
528
548
529
- spiCsHigh ();
549
+ spiCsHigh ();
530
550
531
- if (hwSPI) spi_end ();
551
+ if (hwSPI) {
552
+ spi_end ();
553
+ }
532
554
}
533
555
534
556
535
- void Adafruit_ILI9341::drawFastVLine (int16_t x, int16_t y, int16_t h,
536
- uint16_t color) {
557
+ void Adafruit_ILI9341::drawFastVLine (int16_t x, int16_t y, int16_t h, uint16_t color) {
537
558
538
- // Rudimentary clipping
539
- if ((x >= _width) || (y >= _height)) return ;
559
+ // Rudimentary clipping
560
+ if ((x >= _width) || (y >= _height)) return ;
561
+ if ((y + h - 1 ) >= _height) h = _height - y;
540
562
541
- if ((y+h-1 ) >= _height)
542
- h = _height-y;
563
+ if (hwSPI) {
564
+ spi_begin ();
565
+ }
543
566
544
- if (hwSPI) spi_begin ();
545
- setAddrWindow (x, y, x, y+h-1 );
546
- #ifndef ESP8266
547
- uint8_t hi = color >> 8 , lo = color;
548
- #endif
567
+ spiCsLow ();
549
568
550
- spiDcHigh ();
551
- spiCsLow ();
569
+ setAddrWindow_ (x, y, x, (y + h - 1 ));
552
570
553
- uint8_t colorBin[] = { (uint8_t ) (color >> 8 ), (uint8_t ) color };
554
- spiwritePattern (&colorBin[0 ], 2 , h);
571
+ uint8_t colorBin[] = { (uint8_t ) (color >> 8 ), (uint8_t ) color };
572
+ spiwritePattern (&colorBin[0 ], 2 , h);
555
573
556
- spiCsHigh ();
574
+ spiCsHigh ();
557
575
558
- if (hwSPI) spi_end ();
576
+ if (hwSPI) {
577
+ spi_end ();
578
+ }
559
579
}
560
580
581
+ void Adafruit_ILI9341::drawFastHLine (int16_t x, int16_t y, int16_t w, uint16_t color) {
561
582
562
- void Adafruit_ILI9341::drawFastHLine (int16_t x, int16_t y, int16_t w,
563
- uint16_t color) {
583
+ // Rudimentary clipping
584
+ if ((x >= _width) || (y >= _height)) return ;
585
+ if ((x+w-1 ) >= _width) w = _width-x;
564
586
565
- // Rudimentary clipping
566
- if ((x >= _width) || (y >= _height)) return ;
567
- if ((x+w-1 ) >= _width) w = _width-x;
568
- if (hwSPI) spi_begin ();
569
- setAddrWindow (x, y, x+w-1 , y);
587
+ if (hwSPI) {
588
+ spi_begin ();
589
+ }
570
590
571
- spiDcHigh ();
572
- spiCsLow ();
591
+ spiDcHigh ();
592
+ spiCsLow ();
573
593
574
- uint8_t colorBin[] = { (uint8_t ) (color >> 8 ), (uint8_t ) color };
575
- spiwritePattern (&colorBin[0 ], 2 , w);
594
+ setAddrWindow_ (x, y, (x + w - 1 ), y);
576
595
577
- spiCsHigh ();
596
+ uint8_t colorBin[] = { (uint8_t ) (color >> 8 ), (uint8_t ) color };
597
+ spiwritePattern (&colorBin[0 ], 2 , w);
578
598
579
- if (hwSPI) spi_end ();
599
+ spiCsHigh ();
600
+
601
+ if (hwSPI) {
602
+ spi_end ();
603
+ }
580
604
}
581
605
582
606
void Adafruit_ILI9341::fillScreen (uint16_t color) {
@@ -598,11 +622,10 @@ void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint
598
622
spi_begin ();
599
623
}
600
624
601
- setAddrWindow (x, y, x + w - 1 , y + h - 1 );
602
-
603
- spiDcHigh ();
604
625
spiCsLow ();
605
626
627
+ setAddrWindow_ (x, y, x + w - 1 , y + h - 1 );
628
+
606
629
uint8_t colorBin[] = { (uint8_t ) (color >> 8 ), (uint8_t ) color };
607
630
spiwritePattern (&colorBin[0 ], 2 , (w * h));
608
631
0 commit comments