Skip to content

Commit d70f720

Browse files
committed
Add support for Arduino Nesso-N1 ExpanderPin args
1 parent e4df4cc commit d70f720

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed

Adafruit_SPITFT.cpp

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,81 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
352352
}
353353
#endif // end !ESP8266
354354

355+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
356+
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
357+
int8_t cs, ExpanderPin *dc, ExpanderPin *rst)
358+
: Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(-1) {
359+
hwspi._spi = spiClass;
360+
#if !defined(SPI_HAS_TRANSACTION)
361+
hwspi._freq = 0;
362+
hwspi._mode = SPI_MODE0;
363+
#endif
364+
_dcExp = dc;
365+
_rstExp = rst;
366+
}
367+
368+
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
369+
int8_t cs, int8_t dc, ExpanderPin *rst)
370+
: Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(dc) {
371+
hwspi._spi = spiClass;
372+
#if !defined(SPI_HAS_TRANSACTION)
373+
hwspi._freq = 0;
374+
hwspi._mode = SPI_MODE0;
375+
#endif
376+
_rstExp = rst;
377+
}
378+
379+
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
380+
ExpanderPin *cs, ExpanderPin *dc,
381+
ExpanderPin *rst)
382+
: Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(-1), _dc(-1) {
383+
hwspi._spi = spiClass;
384+
#if !defined(SPI_HAS_TRANSACTION)
385+
hwspi._freq = 0;
386+
hwspi._mode = SPI_MODE0;
387+
#endif
388+
_csExp = cs;
389+
_dcExp = dc;
390+
_rstExp = rst;
391+
}
392+
393+
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs,
394+
ExpanderPin *dc, ExpanderPin *rst)
395+
: Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(-1) {
396+
hwspi._spi = &SPI;
397+
#if !defined(SPI_HAS_TRANSACTION)
398+
hwspi._freq = 0;
399+
hwspi._mode = SPI_MODE0;
400+
#endif
401+
_dcExp = dc;
402+
_rstExp = rst;
403+
}
404+
405+
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc,
406+
ExpanderPin *rst)
407+
: Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(dc) {
408+
hwspi._spi = &SPI;
409+
#if !defined(SPI_HAS_TRANSACTION)
410+
hwspi._freq = 0;
411+
hwspi._mode = SPI_MODE0;
412+
#endif
413+
_rstExp = rst;
414+
}
415+
416+
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, ExpanderPin *cs,
417+
ExpanderPin *dc, ExpanderPin *rst)
418+
: Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(-1), _dc(-1) {
419+
hwspi._spi = &SPI;
420+
#if !defined(SPI_HAS_TRANSACTION)
421+
hwspi._freq = 0;
422+
hwspi._mode = SPI_MODE0;
423+
#endif
424+
_csExp = cs;
425+
_dcExp = dc;
426+
_rstExp = rst;
427+
}
428+
#endif
429+
355430
/*!
356431
@brief Adafruit_SPITFT constructor for parallel display connection.
357432
@param w Display width in pixels at default rotation (0).
@@ -543,8 +618,23 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) {
543618
pinMode(_cs, OUTPUT);
544619
digitalWrite(_cs, HIGH); // Deselect
545620
}
546-
pinMode(_dc, OUTPUT);
547-
digitalWrite(_dc, HIGH); // Data mode
621+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
622+
if (_csExp) {
623+
pinMode(*_csExp, OUTPUT);
624+
digitalWrite(*_csExp, HIGH);
625+
}
626+
#endif
627+
628+
if (_dc >= 0) {
629+
pinMode(_dc, OUTPUT);
630+
digitalWrite(_dc, HIGH); // Data mode
631+
}
632+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
633+
if (_dcExp) {
634+
pinMode(*_dcExp, OUTPUT);
635+
digitalWrite(*_dcExp, HIGH);
636+
}
637+
#endif
548638

549639
if (connection == TFT_HARD_SPI) {
550640

@@ -657,6 +747,17 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) {
657747
digitalWrite(_rst, HIGH);
658748
delay(200);
659749
}
750+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
751+
if (_rstExp) {
752+
pinMode(*_rstExp, OUTPUT);
753+
digitalWrite(*_rstExp, HIGH);
754+
delay(100);
755+
digitalWrite(*_rstExp, LOW);
756+
delay(100);
757+
digitalWrite(*_rstExp, HIGH);
758+
delay(200);
759+
}
760+
#endif
660761

661762
#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO))
662763
if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) &&

Adafruit_SPITFT.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "Adafruit_GFX.h"
2727
#include <SPI.h>
2828

29+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
30+
class ExpanderPin;
31+
#endif
32+
2933
// HARDWARE CONFIG ---------------------------------------------------------
3034

3135
#if defined(__AVR__)
@@ -157,6 +161,23 @@ class Adafruit_SPITFT : public Adafruit_GFX {
157161
int8_t dc, int8_t rst = -1);
158162
#endif // end !ESP8266
159163

164+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
165+
// Hardware SPI constructor using default or an arbitrary SPI peripheral
166+
// and ExpanderPin for cs, dc, rst
167+
Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs,
168+
ExpanderPin *dc, ExpanderPin *rst = NULL);
169+
Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs,
170+
int8_t dc, ExpanderPin *rst = NULL);
171+
Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
172+
ExpanderPin *cs, ExpanderPin *dc, ExpanderPin *rst = NULL);
173+
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, ExpanderPin *dc,
174+
ExpanderPin *rst = NULL);
175+
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc,
176+
ExpanderPin *rst = NULL);
177+
Adafruit_SPITFT(uint16_t w, uint16_t h, ExpanderPin *cs, ExpanderPin *dc,
178+
ExpanderPin *rst = NULL);
179+
#endif
180+
160181
// Parallel constructor: expects width & height (rotation 0), flag
161182
// indicating whether 16-bit (true) or 8-bit (false) interface, 3 signal
162183
// pins (d0, wr, dc), 3 optional pins (cs, rst, rd). 16-bit parallel
@@ -300,6 +321,12 @@ class Adafruit_SPITFT : public Adafruit_GFX {
300321
connection is parallel.
301322
*/
302323
void SPI_CS_HIGH(void) {
324+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
325+
if (_csExp) {
326+
digitalWrite(*_csExp, HIGH);
327+
return;
328+
}
329+
#endif
303330
#if defined(USE_FAST_PINIO)
304331
#if defined(HAS_PORT_SET_CLR)
305332
#if defined(KINETISK)
@@ -322,6 +349,12 @@ class Adafruit_SPITFT : public Adafruit_GFX {
322349
connection is parallel.
323350
*/
324351
void SPI_CS_LOW(void) {
352+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
353+
if (_csExp) {
354+
digitalWrite(*_csExp, LOW);
355+
return;
356+
}
357+
#endif
325358
#if defined(USE_FAST_PINIO)
326359
#if defined(HAS_PORT_SET_CLR)
327360
#if defined(KINETISK)
@@ -341,6 +374,12 @@ class Adafruit_SPITFT : public Adafruit_GFX {
341374
@brief Set the data/command line HIGH (data mode).
342375
*/
343376
void SPI_DC_HIGH(void) {
377+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
378+
if (_dcExp) {
379+
digitalWrite(*_dcExp, HIGH);
380+
return;
381+
}
382+
#endif
344383
#if defined(USE_FAST_PINIO)
345384
#if defined(HAS_PORT_SET_CLR)
346385
#if defined(KINETISK)
@@ -360,6 +399,12 @@ class Adafruit_SPITFT : public Adafruit_GFX {
360399
@brief Set the data/command line LOW (command mode).
361400
*/
362401
void SPI_DC_LOW(void) {
402+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
403+
if (_dcExp) {
404+
digitalWrite(*_dcExp, LOW);
405+
return;
406+
}
407+
#endif
363408
#if defined(USE_FAST_PINIO)
364409
#if defined(HAS_PORT_SET_CLR)
365410
#if defined(KINETISK)
@@ -528,6 +573,11 @@ class Adafruit_SPITFT : public Adafruit_GFX {
528573
int8_t _rst; ///< Reset pin # (or -1)
529574
int8_t _cs; ///< Chip select pin # (or -1)
530575
int8_t _dc; ///< Data/command pin #
576+
#if defined(ARDUINO_ARDUINO_NESSO_N1)
577+
ExpanderPin *_rstExp = NULL;
578+
ExpanderPin *_csExp = NULL;
579+
ExpanderPin *_dcExp = NULL;
580+
#endif
531581

532582
int16_t _xstart = 0; ///< Internal framebuffer X offset
533583
int16_t _ystart = 0; ///< Internal framebuffer Y offset

0 commit comments

Comments
 (0)