From d70f7209259222cc0e3dcdc07df5e8804e8de075 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 19 Nov 2025 22:31:42 +0000 Subject: [PATCH] Add support for Arduino Nesso-N1 ExpanderPin args --- Adafruit_SPITFT.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++- Adafruit_SPITFT.h | 50 +++++++++++++++++++++ 2 files changed, 153 insertions(+), 2 deletions(-) diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index 870979b3..3452d0d0 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -352,6 +352,81 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, } #endif // end !ESP8266 +#if defined(ARDUINO_ARDUINO_NESSO_N1) +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + int8_t cs, ExpanderPin *dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(-1) { + hwspi._spi = spiClass; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _dcExp = dc; + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + int8_t cs, int8_t dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(dc) { + hwspi._spi = spiClass; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + ExpanderPin *cs, ExpanderPin *dc, + ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(-1), _dc(-1) { + hwspi._spi = spiClass; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _csExp = cs; + _dcExp = dc; + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, + ExpanderPin *dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(-1) { + hwspi._spi = &SPI; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _dcExp = dc; + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, + ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(cs), _dc(dc) { + hwspi._spi = &SPI; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _rstExp = rst; +} + +Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, ExpanderPin *cs, + ExpanderPin *dc, ExpanderPin *rst) + : Adafruit_GFX(w, h), connection(TFT_HARD_SPI), _rst(-1), _cs(-1), _dc(-1) { + hwspi._spi = &SPI; +#if !defined(SPI_HAS_TRANSACTION) + hwspi._freq = 0; + hwspi._mode = SPI_MODE0; +#endif + _csExp = cs; + _dcExp = dc; + _rstExp = rst; +} +#endif + /*! @brief Adafruit_SPITFT constructor for parallel display connection. @param w Display width in pixels at default rotation (0). @@ -543,8 +618,23 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { pinMode(_cs, OUTPUT); digitalWrite(_cs, HIGH); // Deselect } - pinMode(_dc, OUTPUT); - digitalWrite(_dc, HIGH); // Data mode +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_csExp) { + pinMode(*_csExp, OUTPUT); + digitalWrite(*_csExp, HIGH); + } +#endif + + if (_dc >= 0) { + pinMode(_dc, OUTPUT); + digitalWrite(_dc, HIGH); // Data mode + } +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_dcExp) { + pinMode(*_dcExp, OUTPUT); + digitalWrite(*_dcExp, HIGH); + } +#endif if (connection == TFT_HARD_SPI) { @@ -657,6 +747,17 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { digitalWrite(_rst, HIGH); delay(200); } +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_rstExp) { + pinMode(*_rstExp, OUTPUT); + digitalWrite(*_rstExp, HIGH); + delay(100); + digitalWrite(*_rstExp, LOW); + delay(100); + digitalWrite(*_rstExp, HIGH); + delay(200); + } +#endif #if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) && diff --git a/Adafruit_SPITFT.h b/Adafruit_SPITFT.h index 7d0843e6..07deb8ba 100644 --- a/Adafruit_SPITFT.h +++ b/Adafruit_SPITFT.h @@ -26,6 +26,10 @@ #include "Adafruit_GFX.h" #include +#if defined(ARDUINO_ARDUINO_NESSO_N1) +class ExpanderPin; +#endif + // HARDWARE CONFIG --------------------------------------------------------- #if defined(__AVR__) @@ -157,6 +161,23 @@ class Adafruit_SPITFT : public Adafruit_GFX { int8_t dc, int8_t rst = -1); #endif // end !ESP8266 +#if defined(ARDUINO_ARDUINO_NESSO_N1) + // Hardware SPI constructor using default or an arbitrary SPI peripheral + // and ExpanderPin for cs, dc, rst + Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs, + ExpanderPin *dc, ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs, + int8_t dc, ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, + ExpanderPin *cs, ExpanderPin *dc, ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, ExpanderPin *dc, + ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, + ExpanderPin *rst = NULL); + Adafruit_SPITFT(uint16_t w, uint16_t h, ExpanderPin *cs, ExpanderPin *dc, + ExpanderPin *rst = NULL); +#endif + // Parallel constructor: expects width & height (rotation 0), flag // indicating whether 16-bit (true) or 8-bit (false) interface, 3 signal // pins (d0, wr, dc), 3 optional pins (cs, rst, rd). 16-bit parallel @@ -300,6 +321,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { connection is parallel. */ void SPI_CS_HIGH(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_csExp) { + digitalWrite(*_csExp, HIGH); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -322,6 +349,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { connection is parallel. */ void SPI_CS_LOW(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_csExp) { + digitalWrite(*_csExp, LOW); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -341,6 +374,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { @brief Set the data/command line HIGH (data mode). */ void SPI_DC_HIGH(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_dcExp) { + digitalWrite(*_dcExp, HIGH); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -360,6 +399,12 @@ class Adafruit_SPITFT : public Adafruit_GFX { @brief Set the data/command line LOW (command mode). */ void SPI_DC_LOW(void) { +#if defined(ARDUINO_ARDUINO_NESSO_N1) + if (_dcExp) { + digitalWrite(*_dcExp, LOW); + return; + } +#endif #if defined(USE_FAST_PINIO) #if defined(HAS_PORT_SET_CLR) #if defined(KINETISK) @@ -528,6 +573,11 @@ class Adafruit_SPITFT : public Adafruit_GFX { int8_t _rst; ///< Reset pin # (or -1) int8_t _cs; ///< Chip select pin # (or -1) int8_t _dc; ///< Data/command pin # +#if defined(ARDUINO_ARDUINO_NESSO_N1) + ExpanderPin *_rstExp = NULL; + ExpanderPin *_csExp = NULL; + ExpanderPin *_dcExp = NULL; +#endif int16_t _xstart = 0; ///< Internal framebuffer X offset int16_t _ystart = 0; ///< Internal framebuffer Y offset