From 5eb37885e8ff023fbf2cf90152f7fb700e2a6cb6 Mon Sep 17 00:00:00 2001 From: Johan Cronje Date: Mon, 27 Nov 2017 11:57:38 -0800 Subject: [PATCH] Add support for ESP32 (#19) --- CHANGES.md | 2 ++ README.md | 2 ++ examples/Basic_Demo/Basic_Demo.ino | 2 +- library.json | 2 +- library.properties | 2 +- src/DefaultFonts.c | 2 +- src/TFT_22_ILI9225.cpp | 28 ++++++++++++++++------------ src/TFT_22_ILI9225.h | 6 +++--- 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bf0d917..58cc7a2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ TFT_22_ILI9225 ============== +**v1.3.4, released 2017-11-27, add support for ESP32** + **v1.3.3, released 2017-11-26, add support for STM32F1** Credit: [nicolasimeoni](https://github.com/nicolasimeoni) **v1.3.2, released 2017-11-20, add triangle function demo** diff --git a/README.md b/README.md index 15c5f37..b2ec4af 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ TFT_22_ILI9225 ============== +**v1.3.4, released 2017-11-27, add support for ESP32** + **v1.3.3, released 2017-11-26, add support for STM32F1** Credit: [nicolasimeoni](https://github.com/nicolasimeoni) This is a library for the ILI9225 based 2.2" 176x220 TFT LCD shields commonly found on eBay, originally forked from the screen_4D_22_library library. The ability to use GLCD fonts has been added and the syntax has been changed to match the Adafruit libraries somewhat. diff --git a/examples/Basic_Demo/Basic_Demo.ino b/examples/Basic_Demo/Basic_Demo.ino index 7649ab2..a162b51 100644 --- a/examples/Basic_Demo/Basic_Demo.ino +++ b/examples/Basic_Demo/Basic_Demo.ino @@ -2,7 +2,7 @@ #include "SPI.h" #include "TFT_22_ILI9225.h" -#if defined (ARDUINO_ARCH_STM32F1) +#ifdef ARDUINO_ARCH_STM32F1 #define TFT_RST PA1 #define TFT_RS PA2 #define TFT_CS PA0 // SS diff --git a/library.json b/library.json index 09e3d8e..52083e3 100644 --- a/library.json +++ b/library.json @@ -9,7 +9,7 @@ "authors": { "name": "Nkawu" }, - "version": "1.3.3", + "version": "1.3.4", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index 1b7f8e9..4882ad6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_22_ILI9225 -version=1.3.3 +version=1.3.4 author=Nkawu maintainer=Nkawu sentence=ILI9225 2.2" 176x220 TFT LCD shield diff --git a/src/DefaultFonts.c b/src/DefaultFonts.c index 77df01b..c05afef 100644 --- a/src/DefaultFonts.c +++ b/src/DefaultFonts.c @@ -4,7 +4,7 @@ #include #endif -#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) || defined(STM32F1) +#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) || defined(STM32F1) || defined(ESP32) #define PROGMEM #define fontdatatype const char #else diff --git a/src/TFT_22_ILI9225.cpp b/src/TFT_22_ILI9225.cpp index c23b644..389824a 100644 --- a/src/TFT_22_ILI9225.cpp +++ b/src/TFT_22_ILI9225.cpp @@ -63,12 +63,12 @@ #define SSPI_SCK_LOW() digitalWrite(_clk, LOW) #endif -// #define SSPI_BEGIN_TRANSACTION() -// #define SSPI_END_TRANSACTION() -// #define SSPI_WRITE(v) _spiWrite(v) -// #define SSPI_WRITE16(s) SSPI_WRITE((s) >> 8); SSPI_WRITE(s) -// #define SSPI_WRITE32(l) SSPI_WRITE((l) >> 24); SSPI_WRITE((l) >> 16); SSPI_WRITE((l) >> 8); SSPI_WRITE(l) -// #define SSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<(l); i+=2){ SSPI_WRITE(((uint8_t*)(c))[i+1]); SSPI_WRITE(((uint8_t*)(c))[i]); } +#define SSPI_BEGIN_TRANSACTION() +#define SSPI_END_TRANSACTION() +#define SSPI_WRITE(v) _spiWrite(v) +#define SSPI_WRITE16(s) SSPI_WRITE((s) >> 8); SSPI_WRITE(s) +#define SSPI_WRITE32(l) SSPI_WRITE((l) >> 24); SSPI_WRITE((l) >> 16); SSPI_WRITE((l) >> 8); SSPI_WRITE(l) +#define SSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<(l); i+=2){ SSPI_WRITE(((uint8_t*)(c))[i+1]); SSPI_WRITE(((uint8_t*)(c))[i]); } // Hardware SPI Macros @@ -105,15 +105,15 @@ #endif #if defined(ESP8266) || defined(ESP32) // Optimized SPI (ESP8266 and ESP32) - // #define HSPI_READ() SPI_OBJECT.transfer(0) + #define HSPI_READ() SPI_OBJECT.transfer(0) #define HSPI_WRITE(b) SPI_OBJECT.write(b) - // #define HSPI_WRITE16(s) SPI_OBJECT.write16(s) - // #define HSPI_WRITE32(l) SPI_OBJECT.write32(l) + #define HSPI_WRITE16(s) SPI_OBJECT.write16(s) + #define HSPI_WRITE32(l) SPI_OBJECT.write32(l) #ifdef SPI_HAS_WRITE_PIXELS #define SPI_MAX_PIXELS_AT_ONCE 32 - // #define HSPI_WRITE_PIXELS(c,l) SPI_OBJECT.writePixels(c,l) + #define HSPI_WRITE_PIXELS(c,l) SPI_OBJECT.writePixels(c,l) #else - // #define HSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<((l)/2); i++){ SPI_WRITE16(((uint16_t*)(c))[i]); } + #define HSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<((l)/2); i++){ SPI_WRITE16(((uint16_t*)(c))[i]); } #endif #else // Standard Byte-by-Byte SPI @@ -221,11 +221,13 @@ TFT_22_ILI9225::TFT_22_ILI9225(int8_t rst, int8_t rs, int8_t cs, int8_t led, uin #ifdef ESP32 void TFT_22_ILI9225::begin(SPIClass &spi) - _spi = spi; #else void TFT_22_ILI9225::begin() #endif { +#ifdef ESP32 + _spi = spi; +#endif // Set up reset pin if (_rst > 0) { pinMode(_rst, OUTPUT); @@ -461,7 +463,9 @@ void TFT_22_ILI9225::invert(boolean flag) { void TFT_22_ILI9225::setBacklight(boolean flag) { blState = flag; +#ifndef ESP32 if (_led) analogWrite(_led, blState ? _brightness : 0); +#endif } diff --git a/src/TFT_22_ILI9225.h b/src/TFT_22_ILI9225.h index 39bc4fe..0a3e46b 100644 --- a/src/TFT_22_ILI9225.h +++ b/src/TFT_22_ILI9225.h @@ -141,10 +141,10 @@ class TFT_22_ILI9225 { TFT_22_ILI9225(int8_t RST, int8_t RS, int8_t CS, int8_t LED, uint8_t brightness); /// Initialization -#ifdef ESP32 - void begin(SPIClass &spi) -#else +#ifndef ESP32 void begin(void); +#else + void begin(SPIClass &spi=SPI); #endif /// Clear the screen