@@ -73,25 +73,37 @@ inline void Adafruit_ST7735::spiwrite(uint8_t c) {
73
73
74
74
75
75
void Adafruit_ST7735::writecommand (uint8_t c) {
76
+ #ifdef SPI_HAS_TRANSACTION
77
+ if (hwSPI) SPI.beginTransaction (spisettings);
78
+ #endif
76
79
*rsport &= ~rspinmask;
77
80
*csport &= ~cspinmask;
78
81
79
82
// Serial.print("C ");
80
83
spiwrite (c);
81
84
82
85
*csport |= cspinmask;
86
+ #ifdef SPI_HAS_TRANSACTION
87
+ if (hwSPI) SPI.endTransaction ();
88
+ #endif
83
89
}
84
90
85
91
86
92
void Adafruit_ST7735::writedata (uint8_t c) {
93
+ #ifdef SPI_HAS_TRANSACTION
94
+ if (hwSPI) SPI.beginTransaction (spisettings);
95
+ #endif
87
96
*rsport |= rspinmask;
88
97
*csport &= ~cspinmask;
89
98
90
99
// Serial.print("D ");
91
100
spiwrite (c);
92
101
93
102
*csport |= cspinmask;
94
- }
103
+ #ifdef SPI_HAS_TRANSACTION
104
+ if (hwSPI) SPI.endTransaction ();
105
+ #endif
106
+ }
95
107
96
108
97
109
// Rather than a bazillion writecommand() and writedata() calls, screen
@@ -331,13 +343,17 @@ void Adafruit_ST7735::commonInit(const uint8_t *cmdList) {
331
343
332
344
if (hwSPI) { // Using hardware SPI
333
345
SPI.begin ();
346
+ #ifdef SPI_HAS_TRANSACTION
347
+ spisettings = SPISettings (4000000L , MSBFIRST, SPI_MODE0);
348
+ #else
334
349
#if defined(ARDUINO_ARCH_SAM)
335
350
SPI.setClockDivider (24 ); // 4 MHz (half speed)
336
351
#else
337
352
SPI.setClockDivider (SPI_CLOCK_DIV4); // 4 MHz (half speed)
338
353
#endif
339
354
SPI.setBitOrder (MSBFIRST);
340
355
SPI.setDataMode (SPI_MODE0);
356
+ #endif // SPI_HAS_TRANSACTION
341
357
} else {
342
358
pinMode (_sclk, OUTPUT);
343
359
pinMode (_sid , OUTPUT);
@@ -413,6 +429,9 @@ void Adafruit_ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1,
413
429
414
430
415
431
void Adafruit_ST7735::pushColor (uint16_t color) {
432
+ #ifdef SPI_HAS_TRANSACTION
433
+ if (hwSPI) SPI.beginTransaction (spisettings);
434
+ #endif
416
435
*rsport |= rspinmask;
417
436
*csport &= ~cspinmask;
418
437
@@ -421,6 +440,9 @@ void Adafruit_ST7735::pushColor(uint16_t color) {
421
440
spiwrite (color);
422
441
423
442
*csport |= cspinmask;
443
+ #ifdef SPI_HAS_TRANSACTION
444
+ if (hwSPI) SPI.endTransaction ();
445
+ #endif
424
446
}
425
447
426
448
void Adafruit_ST7735::drawPixel (int16_t x, int16_t y, uint16_t color) {
@@ -429,6 +451,9 @@ void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
429
451
430
452
setAddrWindow (x,y,x+1 ,y+1 );
431
453
454
+ #ifdef SPI_HAS_TRANSACTION
455
+ if (hwSPI) SPI.beginTransaction (spisettings);
456
+ #endif
432
457
*rsport |= rspinmask;
433
458
*csport &= ~cspinmask;
434
459
@@ -438,6 +463,9 @@ void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
438
463
spiwrite (color);
439
464
440
465
*csport |= cspinmask;
466
+ #ifdef SPI_HAS_TRANSACTION
467
+ if (hwSPI) SPI.endTransaction ();
468
+ #endif
441
469
}
442
470
443
471
@@ -452,13 +480,19 @@ void Adafruit_ST7735::drawFastVLine(int16_t x, int16_t y, int16_t h,
452
480
if (tabcolor == INITR_BLACKTAB) color = swapcolor (color);
453
481
454
482
uint8_t hi = color >> 8 , lo = color;
483
+ #ifdef SPI_HAS_TRANSACTION
484
+ if (hwSPI) SPI.beginTransaction (spisettings);
485
+ #endif
455
486
*rsport |= rspinmask;
456
487
*csport &= ~cspinmask;
457
488
while (h--) {
458
489
spiwrite (hi);
459
490
spiwrite (lo);
460
491
}
461
492
*csport |= cspinmask;
493
+ #ifdef SPI_HAS_TRANSACTION
494
+ if (hwSPI) SPI.endTransaction ();
495
+ #endif
462
496
}
463
497
464
498
@@ -473,13 +507,19 @@ void Adafruit_ST7735::drawFastHLine(int16_t x, int16_t y, int16_t w,
473
507
if (tabcolor == INITR_BLACKTAB) color = swapcolor (color);
474
508
475
509
uint8_t hi = color >> 8 , lo = color;
510
+ #ifdef SPI_HAS_TRANSACTION
511
+ if (hwSPI) SPI.beginTransaction (spisettings);
512
+ #endif
476
513
*rsport |= rspinmask;
477
514
*csport &= ~cspinmask;
478
515
while (w--) {
479
516
spiwrite (hi);
480
517
spiwrite (lo);
481
518
}
482
519
*csport |= cspinmask;
520
+ #ifdef SPI_HAS_TRANSACTION
521
+ if (hwSPI) SPI.endTransaction ();
522
+ #endif
483
523
}
484
524
485
525
@@ -504,6 +544,9 @@ void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
504
544
setAddrWindow (x, y, x+w-1 , y+h-1 );
505
545
506
546
uint8_t hi = color >> 8 , lo = color;
547
+ #ifdef SPI_HAS_TRANSACTION
548
+ if (hwSPI) SPI.beginTransaction (spisettings);
549
+ #endif
507
550
*rsport |= rspinmask;
508
551
*csport &= ~cspinmask;
509
552
for (y=h; y>0 ; y--) {
@@ -514,6 +557,9 @@ void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
514
557
}
515
558
516
559
*csport |= cspinmask;
560
+ #ifdef SPI_HAS_TRANSACTION
561
+ if (hwSPI) SPI.endTransaction ();
562
+ #endif
517
563
}
518
564
519
565
0 commit comments