Touch CS via external func

This commit is contained in:
kostuch 2019-11-28 09:50:40 +01:00
parent 74b8024dc9
commit 57f5335756
4 changed files with 44 additions and 31 deletions

View File

@ -99,7 +99,7 @@ inline void TFT_eSPI::spi_end_read(void){
#endif
}
#if defined (TOUCH_CS) && defined (SPI_TOUCH_FREQUENCY) // && !defined(ESP32_PARALLEL)
//#if defined (TOUCH_CS) && defined (SPI_TOUCH_FREQUENCY) // && !defined(ESP32_PARALLEL)
inline void TFT_eSPI::spi_begin_touch(void){
CS_H; // Just in case it has been left low
@ -131,7 +131,7 @@ inline void TFT_eSPI::spi_end_read(void){
#endif
}
#endif
//#endif
/***************************************************************************************
** Function name: TFT_eSPI
@ -146,12 +146,16 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h)
#ifdef TFT_CS
digitalWrite(TFT_CS, HIGH); // Chip select high (inactive)
pinMode(TFT_CS, OUTPUT);
#else
if (ext_cs && !_app_cs) ext_cs(false); // CS high
#endif
// Configure chip select for touchscreen controller if present
#ifdef TOUCH_CS
digitalWrite(TOUCH_CS, HIGH); // Chip select high (inactive)
pinMode(TOUCH_CS, OUTPUT);
#else
if (ext_tcs && !_app_cs) ext_tcs(false); // CS high
#endif
#ifdef TFT_WR
@ -162,6 +166,8 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h)
#ifdef TFT_DC
digitalWrite(TFT_DC, HIGH); // Data/Command high = data mode
pinMode(TFT_DC, OUTPUT);
#else
if (ext_dc) ext_dc(false); //DC high
#endif
#ifdef TFT_RST
@ -279,13 +285,20 @@ void TFT_eSPI::begin(uint8_t 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 (*ext_dc_func)(bool state), void (*ext_cs_func)(bool state), void (*ext_rst_func)(void))
void TFT_eSPI::init(void (*ext_dc_func)(bool dc_state), void (*ext_cs_func)(bool cs_state), void (*ext_rst_func)(void), void (*ext_tcs_func)(bool tcs_state), bool app_cs, uint8_t tc)
{
ext_cs = ext_cs_func; // callback function to manipulate TFT CS
ext_dc = ext_dc_func; // callback function to manipulate TFT DC
ext_rst = ext_rst_func; // callback function to manipulate TFT RST
ext_tcs = ext_tcs_func; // callback function to manipulate TouchPanel CS
_app_cs = app_cs; // flag FALSE: library drives CS lines, TRUE: application must take care about CS manipulation (to increase performance in case of slow I2C mux)
init(tc); // proceed with normal init
}
void TFT_eSPI::init(uint8_t tc)
{
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)
@ -343,7 +356,7 @@ void TFT_eSPI::init(uint8_t tc, void (*ext_dc_func)(bool state), void (*ext_cs_f
digitalWrite(TFT_CS, HIGH); // Chip select high (inactive)
pinMode(TFT_CS, OUTPUT);
#else
spi.setHwCs(1); // Use hardware SS toggling
spi.setHwCs(1); // Use hardware SS toggling
#endif
#endif
@ -5360,10 +5373,10 @@ void TFT_eSPI::getSetup(setup_t &tft_settings)
}
////////////////////////////////////////////////////////////////////////////////////////
#ifdef TOUCH_CS
//#ifdef TOUCH_CS
#include "Extensions/Touch.cpp"
#include "Extensions/Button.cpp"
#endif
//#endif
#include "Extensions/Sprite.cpp"

View File

@ -125,8 +125,8 @@
#endif
#ifndef TFT_DC
#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
#define DC_C if(ext_dc) ext_dc(true) // If callback set, call function
#define DC_D if(ext_dc) ext_dc(false) // 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 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
#define CS_L if(ext_cs && !_app_cs) ext_cs(true) // If callback set, call function
#define CS_H if(ext_cs && !_app_cs) ext_cs(false) // If callback set, call function
#else
#if defined (ESP8266) && (TFT_CS == 16)
#define CS_L digitalWrite(TFT_CS, LOW)
@ -246,8 +246,8 @@
// chip select signal for touchscreen
#ifndef TOUCH_CS
#define T_CS_L // No macro allocated so it generates no code
#define T_CS_H // No macro allocated so it generates no code
#define T_CS_L if(ext_tcs && !_app_cs) ext_tcs(true) // If callback set, call function
#define T_CS_H if(ext_tcs && !_app_cs) ext_tcs(false) // If callback set, call function
#else
#define T_CS_L digitalWrite(TOUCH_CS, LOW)
#define T_CS_H digitalWrite(TOUCH_CS, HIGH)
@ -663,8 +663,9 @@ class TFT_eSPI : public Print {
public:
TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT);
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
void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR); // Same - begin included for backwards compatibility
void init(void (*ext_dc_func)(bool dc_state), void (*ext_cs_func)(bool cs_state), void (*ext_rst_func)(void), void (*ext_tcs_func)(bool tcs_state), bool app_cs = false, uint8_t tc = TAB_COLOUR);
// 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),
@ -850,9 +851,10 @@ 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_dc)(bool dc_state);
void (*ext_cs)(bool cs_state);
void (*ext_rst)(void);
void (*ext_tcs)(bool tcs_state);
inline void spi_begin() __attribute__((always_inline));
inline void spi_end() __attribute__((always_inline));
@ -897,17 +899,17 @@ class TFT_eSPI : public Print {
bool _booted; // init() or begin() has already run once
bool _cp437; // If set, use correct CP437 charset (default is ON)
bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function (default ON)
bool _app_cs; // If CS is manipulated from main APP
uint32_t _lastColor; // Buffered value of last colour used
#ifdef LOAD_GFXFF
GFXfont *gfxFont;
#endif
// Load the Touch extension
#ifdef TOUCH_CS
// Load the Touch extension regardless TOUCH_CS state
//#ifdef TOUCH_CS
#include "Extensions/Touch.h"
#endif
//#endif
// Load the Anti-aliased font extension
#ifdef SMOOTH_FONT

View File

@ -20,8 +20,7 @@
// Only ONE line below should be uncommented. Add extra lines and files as needed.
//#include <User_Setup.h> // Default setup is root library folder
#include <User_Setups/SDMoto18_ST7735.h> // Setup file configured for my ST7735
//#include <User_Setups/Setup1_ILI9341.h> // Setup file configured for my ILI9341
#include <User_Setups/Setup1_ILI9341.h> // Setup file configured for my ILI9341
//#include <User_Setups/Setup2_ST7735.h> // Setup file configured for my ST7735
//#include <User_Setups/Setup3_ILI9163.h> // Setup file configured for my ILI9163
//#include <User_Setups/Setup4_S6D02A1.h> // Setup file configured for my S6D02A1

View File

@ -3,11 +3,10 @@
#define ILI9341_DRIVER
#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_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
//#define TFT_CS PIN_D8 // Chip select control pin D8
#define TFT_DC 16 // 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 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
@ -21,7 +20,7 @@
#define SMOOTH_FONT
// #define SPI_FREQUENCY 27000000
//#define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000
// #define SPI_FREQUENCY 80000000