From 74b8024dc9fd59b9a7ffb9a42975aaf3c3b821e2 Mon Sep 17 00:00:00 2001 From: kostuch Date: Wed, 13 Nov 2019 23:09:45 +0100 Subject: [PATCH] External function to manipulate pins --- TFT_eSPI.cpp | 11 ++++++---- TFT_eSPI.h | 15 ++++++++------ User_Setup.h | 12 +++++------ User_Setup_Select.h | 5 ++--- User_Setups/SDMoto18_ST7735.h | 39 +++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 User_Setups/SDMoto18_ST7735.h diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 7414516..3170cae 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -266,7 +266,6 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) #endif } - /*************************************************************************************** ** Function name: begin ** Description: Included for backwards compatibility @@ -276,15 +275,18 @@ void TFT_eSPI::begin(uint8_t tc) init(tc); } - /*************************************************************************************** ** Function name: init (tc is tab colour for ST7735 displays only) ** Description: Reset, then initialise the TFT display registers ***************************************************************************************/ -void TFT_eSPI::init(uint8_t tc) +void TFT_eSPI::init(uint8_t tc, void (*ext_dc_func)(bool state), void (*ext_cs_func)(bool state), void (*ext_rst_func)(void)) { if (_booted) { + ext_cs = ext_cs_func; + ext_dc = ext_dc_func; + ext_rst = ext_rst_func; + #if !defined (ESP32) #if defined (TFT_CS) && (TFT_CS >= 0) cspinmask = (uint32_t) digitalPinToBitMask(TFT_CS); @@ -368,7 +370,8 @@ void TFT_eSPI::init(uint8_t tc) } else writecommand(TFT_SWRST); // Software reset #else - writecommand(TFT_SWRST); // Software reset + if (ext_rst) ext_rst(); // External function for reset + else writecommand(TFT_SWRST); // Software reset #endif spi_end(); diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 7f7622d..d4db06a 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -125,8 +125,8 @@ #endif #ifndef TFT_DC - #define DC_C // No macro allocated so it generates no code - #define DC_D // No macro allocated so it generates no code + #define DC_C if(ext_dc) ext_dc(false) // If callback set, call function + #define DC_D if(ext_dc) ext_dc(true) // If callback set, call function #else #if defined (ESP8266) && (TFT_DC == 16) #define DC_C digitalWrite(TFT_DC, LOW) @@ -182,8 +182,8 @@ #endif #ifndef TFT_CS - #define CS_L // No macro allocated so it generates no code - #define CS_H // No macro allocated so it generates no code + #define CS_L if(ext_cs) ext_cs(false) // If callback set, call function + #define CS_H if(ext_cs) ext_cs(true) // If callback set, call function #else #if defined (ESP8266) && (TFT_CS == 16) #define CS_L digitalWrite(TFT_CS, LOW) @@ -664,8 +664,8 @@ class TFT_eSPI : public Print { TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT); - void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR); // Same - begin included for backwards compatibility - + void init(uint8_t tc = TAB_COLOUR, void (*ext_dc_func)(bool state) = NULL, void (*ext_cs_func)(bool state) = NULL, void (*ext_rst_func)(void) = NULL), begin(uint8_t tc = TAB_COLOUR); // Same - begin included for backwards compatibility + // These are virtual so the TFT_eSprite class can override them with sprite specific functions virtual void drawPixel(int32_t x, int32_t y, uint32_t color), drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size), @@ -850,6 +850,9 @@ class TFT_eSPI : public Print { uint16_t decoderBuffer; // Unicode code-point buffer private: + void (*ext_dc)(bool state); + void (*ext_cs)(bool state); + void (*ext_rst)(void); inline void spi_begin() __attribute__((always_inline)); inline void spi_end() __attribute__((always_inline)); diff --git a/User_Setup.h b/User_Setup.h index 95b3ef1..7e3a41b 100644 --- a/User_Setup.h +++ b/User_Setup.h @@ -16,8 +16,8 @@ // ################################################################################## // Only define one driver, the other ones must be commented out -#define ILI9341_DRIVER -//#define ST7735_DRIVER // Define additional parameters below for this display +//#define ILI9341_DRIVER +#define ST7735_DRIVER // Define additional parameters below for this display //#define ILI9163_DRIVER // Define additional parameters below for this display //#define S6D02A1_DRIVER //#define RPI_ILI9486_DRIVER // 20MHz maximum SPI @@ -68,7 +68,7 @@ // #define ST7735_GREENTAB3 // #define ST7735_GREENTAB128 // For 128 x 128 display // #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset) -// #define ST7735_REDTAB +#define ST7735_REDTAB // #define ST7735_BLACKTAB // #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset @@ -125,9 +125,9 @@ // ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP8266 SETUP ###### // For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation -#define TFT_CS PIN_D8 // Chip select control pin D8 -#define TFT_DC PIN_D3 // Data Command control pin -#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line) +//#define TFT_CS PIN_D8 // Chip select control pin D8 +//#define TFT_DC PIN_D0 // Data Command control pin +//#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line) //#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V //#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin) diff --git a/User_Setup_Select.h b/User_Setup_Select.h index fc620ac..ab82fc1 100644 --- a/User_Setup_Select.h +++ b/User_Setup_Select.h @@ -19,8 +19,8 @@ // Only ONE line below should be uncommented. Add extra lines and files as needed. -#include // Default setup is root library folder - +//#include // Default setup is root library folder +#include // Setup file configured for my ST7735 //#include // Setup file configured for my ILI9341 //#include // Setup file configured for my ST7735 //#include // Setup file configured for my ILI9163 @@ -125,7 +125,6 @@ #define TFT_DRIVER 0x0000 #endif - // These are the pins for ESP8266 boards // Name GPIO NodeMCU Function #define PIN_D0 D0 // GPIO16 WAKE diff --git a/User_Setups/SDMoto18_ST7735.h b/User_Setups/SDMoto18_ST7735.h new file mode 100644 index 0000000..be5b275 --- /dev/null +++ b/User_Setups/SDMoto18_ST7735.h @@ -0,0 +1,39 @@ +// See SetupX_Template.h for all options available + +#define ST7735_DRIVER + + +#define TFT_WIDTH 128 +#define TFT_HEIGHT 160 + + +#define ST7735_REDTAB + + +// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation +//#define TFT_CS PIN_D8 // Chip select control pin D8 +//#define TFT_DC PIN_D0 // Data Command control pin +#define TFT_DC 16 // Data Command control pin (no Arduino IDE) +//#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line) +//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V + +#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH +#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters +#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters +#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm +#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:. +#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. +//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT +#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts + +#define SMOOTH_FONT + + +// #define SPI_FREQUENCY 20000000 +#define SPI_FREQUENCY 27000000 +// #define SPI_FREQUENCY 40000000 + +#define SPI_TOUCH_FREQUENCY 2500000 + + +// #define SUPPORT_TRANSACTIONS