diff --git a/src/lgfx/v1/Touch.hpp b/src/lgfx/v1/Touch.hpp index 6725f07c..18253cf7 100644 --- a/src/lgfx/v1/Touch.hpp +++ b/src/lgfx/v1/Touch.hpp @@ -67,6 +67,7 @@ namespace lgfx }; }; int16_t pin_cs = -1; + bool is_SPI = false; }; virtual ~ITouch(void) = default; @@ -74,7 +75,7 @@ namespace lgfx config_t config(void) const { return _cfg; } void config(const config_t& config) { _cfg = config; } - inline bool isSPI(void) const { return _cfg.pin_cs >= 0; } + inline bool isSPI(void) const { return _cfg.pin_cs >= 0 || _cfg.is_SPI; } virtual bool init(void) = 0; virtual void wakeup(void) = 0; diff --git a/src/lgfx/v1/platforms/arduino_default/common.cpp b/src/lgfx/v1/platforms/arduino_default/common.cpp index 5237a127..14b2ab7b 100644 --- a/src/lgfx/v1/platforms/arduino_default/common.cpp +++ b/src/lgfx/v1/platforms/arduino_default/common.cpp @@ -64,18 +64,26 @@ namespace lgfx //---------------------------------------------------------------------------- - /// unimplemented. namespace spi { - cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi) { cpp::result res = {}; return res; } + HardwareSPI *SPI_dev = &SPI; + cpp::result init(int spi_host, int spi_sclk, int spi_miso, int spi_mosi) { + cpp::result res = {}; + if (spi_host == 1) + SPI_dev = &SPI1; + else if (spi_host == 2) + SPI_dev = &SPI2; + return res; } void release(int spi_host) {} void beginTransaction(int spi_host, uint32_t freq, int spi_mode) { SPISettings setting(freq, MSBFIRST, SPI_MODE0); - SPI.beginTransaction(setting); + SPI_dev->beginTransaction(setting); } - void endTransaction(int spi_host) {SPI.endTransaction();} + void endTransaction(int spi_host) { SPI_dev->endTransaction();} void writeBytes(int spi_host, const uint8_t* data, size_t length) {} - void readBytes(int spi_host, uint8_t* data, size_t length) {SPI.transfer(data, length);} } + void readBytes(int spi_host, uint8_t* data, size_t length) { + SPI_dev->transfer(data, length); + } } //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/touch/Touch_XPT2046.cpp b/src/lgfx/v1/touch/Touch_XPT2046.cpp index d9545256..633c4e92 100644 --- a/src/lgfx/v1/touch/Touch_XPT2046.cpp +++ b/src/lgfx/v1/touch/Touch_XPT2046.cpp @@ -31,8 +31,10 @@ namespace lgfx _inited = false; if (!isSPI()) return false; - lgfx::gpio_hi(_cfg.pin_cs); - lgfx::pinMode(_cfg.pin_cs, lgfx::pin_mode_t::output); + if (_cfg.pin_cs > -1) { + lgfx::gpio_hi(_cfg.pin_cs); + lgfx::pinMode(_cfg.pin_cs, lgfx::pin_mode_t::output); + } if (_cfg.spi_host < 0) { pinMode(_cfg.pin_sclk, lgfx::pin_mode_t::output); @@ -110,9 +112,11 @@ namespace lgfx else { spi::beginTransaction(_cfg.spi_host, _cfg.freq, 0); - lgfx::gpio_lo(_cfg.pin_cs); + if (_cfg.pin_cs > -1) + lgfx::gpio_lo(_cfg.pin_cs); spi::readBytes(_cfg.spi_host, data, 57); - lgfx::gpio_hi(_cfg.pin_cs); + if (_cfg.pin_cs > -1) + lgfx::gpio_hi(_cfg.pin_cs); spi::endTransaction(_cfg.spi_host); }