diff --git a/README.md b/README.md index 0c8db79..d459dd0 100644 --- a/README.md +++ b/README.md @@ -527,6 +527,7 @@ Included below is the default system setup defines of the Vertical NFT example ( #define SETUP_UI_KEY_REPEAT_INTERVAL 350 // Key repeat interval, in milliseconds #define SETUP_UI_JS_ACCELERATION 3.0f // Joystick acceleration (decrease divisor), if using analog joystick #define SETUP_UI_TOUCHSCREEN_ORIENT Same // Touchscreen orientation tuning (Same, None, InvertX, InvertY, InvertXY, SwapXY, InvertX_SwapXY, InvertY_SwapXY, InvertXY_SwapXY), if using touchscreen +#define SETUP_UI_TOUCHSCREEN_SPI SPI // SPI class for XPT2046 touchscreen, if using XTP2046 #define SETUP_UI_ESP32TOUCH_SWITCH 800 // ESP32 Touch key switch threshold, if on ESP32/using ESP32Touch #define SETUP_UI_ESP32TOUCH_HVOLTS V_2V7 // ESP32 Touch key high reference voltage (Keep, V_2V4, V_2V5, V_2V6, V_2V7, Max), if on ESP32/using ESP32Touch #define SETUP_UI_ESP32TOUCH_LVOLTS V_0V5 // ESP32 Touch key low reference voltage (Keep, V_0V5, V_0V6, V_0V7, V_0V8, Max), if on ESP32/using ESP32Touch diff --git a/examples/FullSystem/FullSystem.ino b/examples/FullSystem/FullSystem.ino index a4ff252..3384690 100644 --- a/examples/FullSystem/FullSystem.ino +++ b/examples/FullSystem/FullSystem.ino @@ -127,6 +127,7 @@ SoftwareSerial SWSerial(RX, TX); // Replace with Rx/Tx pi #define SETUP_UI_KEY_REPEAT_INTERVAL 350 // Key repeat interval, in milliseconds #define SETUP_UI_JS_ACCELERATION 3.0f // Joystick acceleration (decrease divisor), if using analog joystick #define SETUP_UI_TOUCHSCREEN_ORIENT Same // Touchscreen orientation tuning (Same, None, InvertX, InvertY, InvertXY, SwapXY, InvertX_SwapXY, InvertY_SwapXY, InvertXY_SwapXY), if using touchscreen +#define SETUP_UI_TOUCHSCREEN_SPI SPI // SPI class for XPT2046 touchscreen, if using XTP2046 #define SETUP_UI_ESP32TOUCH_SWITCH 800 // ESP32 Touch key switch threshold, if on ESP32/using ESP32Touch #define SETUP_UI_ESP32TOUCH_HVOLTS V_2V7 // ESP32 Touch key high reference voltage (Keep, V_2V4, V_2V5, V_2V6, V_2V7, Max), if on ESP32/using ESP32Touch #define SETUP_UI_ESP32TOUCH_LVOLTS V_0V5 // ESP32 Touch key low reference voltage (Keep, V_0V5, V_0V6, V_0V7, V_0V8, Max), if on ESP32/using ESP32Touch @@ -316,7 +317,11 @@ inline void setupUI() case Hydro_ControlInputMode_ResistiveTouch: case Hydro_ControlInputMode_TouchScreen: case Hydro_ControlInputMode_TFTTouch: - uiCtrlSetup = UIControlSetup(TouchscreenSetup(JOIN(Hydro_TouchscreenOrientation,SETUP_UI_TOUCHSCREEN_ORIENT))); + #ifndef HYDRO_UI_ENABLE_XPT2046TS + uiCtrlSetup = UIControlSetup(TouchscreenSetup(JOIN(Hydro_TouchscreenOrientation,SETUP_UI_TOUCHSCREEN_ORIENT))); + #else + uiCtrlSetup = UIControlSetup(TouchscreenSetup(JOIN(Hydro_TouchscreenOrientation,SETUP_UI_TOUCHSCREEN_ORIENT), &SETUP_UI_TOUCHSCREEN_SPI)); + #endif break; default: break; } diff --git a/examples/VerticalNFT/VerticalNFT.ino b/examples/VerticalNFT/VerticalNFT.ino index b196b34..2dd53e3 100644 --- a/examples/VerticalNFT/VerticalNFT.ino +++ b/examples/VerticalNFT/VerticalNFT.ino @@ -128,6 +128,7 @@ SoftwareSerial SWSerial(RX, TX); // Replace with Rx/Tx pi #define SETUP_UI_KEY_REPEAT_INTERVAL 350 // Key repeat interval, in milliseconds #define SETUP_UI_JS_ACCELERATION 3.0f // Joystick acceleration (decrease divisor), if using analog joystick #define SETUP_UI_TOUCHSCREEN_ORIENT Same // Touchscreen orientation tuning (Same, None, InvertX, InvertY, InvertXY, SwapXY, InvertX_SwapXY, InvertY_SwapXY, InvertXY_SwapXY), if using touchscreen +#define SETUP_UI_TOUCHSCREEN_SPI SPI // SPI class for XPT2046 touchscreen, if using XTP2046 #define SETUP_UI_ESP32TOUCH_SWITCH 800 // ESP32 Touch key switch threshold, if on ESP32/using ESP32Touch #define SETUP_UI_ESP32TOUCH_HVOLTS V_2V7 // ESP32 Touch key high reference voltage (Keep, V_2V4, V_2V5, V_2V6, V_2V7, Max), if on ESP32/using ESP32Touch #define SETUP_UI_ESP32TOUCH_LVOLTS V_0V5 // ESP32 Touch key low reference voltage (Keep, V_0V5, V_0V6, V_0V7, V_0V8, Max), if on ESP32/using ESP32Touch @@ -834,7 +835,11 @@ inline void setupUI() case Hydro_ControlInputMode_ResistiveTouch: case Hydro_ControlInputMode_TouchScreen: case Hydro_ControlInputMode_TFTTouch: - uiCtrlSetup = UIControlSetup(TouchscreenSetup(JOIN(Hydro_TouchscreenOrientation,SETUP_UI_TOUCHSCREEN_ORIENT))); + #ifndef HYDRO_UI_ENABLE_XPT2046TS + uiCtrlSetup = UIControlSetup(TouchscreenSetup(JOIN(Hydro_TouchscreenOrientation,SETUP_UI_TOUCHSCREEN_ORIENT))); + #else + uiCtrlSetup = UIControlSetup(TouchscreenSetup(JOIN(Hydro_TouchscreenOrientation,SETUP_UI_TOUCHSCREEN_ORIENT), &SETUP_UI_TOUCHSCREEN_SPI)); + #endif break; default: break; } diff --git a/src/shared/HydroInputDrivers.cpp b/src/shared/HydroInputDrivers.cpp index bb0a623..6b6df27 100644 --- a/src/shared/HydroInputDrivers.cpp +++ b/src/shared/HydroInputDrivers.cpp @@ -417,7 +417,11 @@ HydroInputTouchscreen::HydroInputTouchscreen(Pair co void HydroInputTouchscreen::begin(HydroDisplayDriver *displayDriver, MenuItem *initialItem) { - _touchInterrogator.init(displayDriver->getScreenSize(false).first, displayDriver->getScreenSize(false).second); + #ifndef HYDRO_UI_ENABLE_XPT2046TS + _touchInterrogator.init(displayDriver->getScreenSize(false).first, displayDriver->getScreenSize(false).second); + #else + _touchInterrogator.init(getBaseUI() ? getBaseUI()->getControlSetup().ctrlCfgAs.touchscreen.spiClass : nullptr); + #endif menuMgr.initWithoutInput(displayDriver->getBaseRenderer(), initialItem); #ifdef HYDRO_UI_ENABLE_XPT2046TS _touchScreen.setRotation(getBaseUI() ? (uint8_t)getBaseUI()->getDisplaySetup().getDisplayRotation() : 0); diff --git a/src/shared/HydroUIInlines.hh b/src/shared/HydroUIInlines.hh index bab8d38..7d8e4fa 100644 --- a/src/shared/HydroUIInlines.hh +++ b/src/shared/HydroUIInlines.hh @@ -189,8 +189,15 @@ struct MatrixControlSetup { // Touchscreen Input Setup struct TouchscreenSetup { Hydro_TouchscreenOrientation orient; // Touchscreen orientation tuning (default: Same) - - inline TouchscreenSetup(Hydro_TouchscreenOrientation orientIn = Hydro_TouchscreenOrientation_Same) : orient(orientIn) { ; } + #ifdef HYDRO_UI_ENABLE_XPT2046TS + SPIClass *spiClass; + #endif + + #ifndef HYDRO_UI_ENABLE_XPT2046TS + inline TouchscreenSetup(Hydro_TouchscreenOrientation orientIn = Hydro_TouchscreenOrientation_Same) : orient(orientIn) { ; } + #else + inline TouchscreenSetup(Hydro_TouchscreenOrientation orientIn = Hydro_TouchscreenOrientation_Same, SPIClass *spiClassIn = HYDRO_USE_SPI) : orient(orientIn), spiClass(spiClassIn) { ; } + #endif }; // Combined UI Control Setup diff --git a/src/shared/tcMenu_Input_AdaTouchDriver.cpp b/src/shared/tcMenu_Input_AdaTouchDriver.cpp index 70f3d21..74419a4 100644 --- a/src/shared/tcMenu_Input_AdaTouchDriver.cpp +++ b/src/shared/tcMenu_Input_AdaTouchDriver.cpp @@ -18,7 +18,7 @@ iotouch::AdaLibTouchInterrogator::AdaLibTouchInterrogator(Adafruit_FT6206& touch : theTouchDevice(touchLibRef), maxWidthDim(0), maxHeightDim(0) {} #else iotouch::AdaLibTouchInterrogator::AdaLibTouchInterrogator(XPT2046_Touchscreen& touchLibRef) - : theTouchDevice(touchLibRef), maxWidthDim(0), maxHeightDim(0) {} + : theTouchDevice(touchLibRef) {} #endif iotouch::TouchState iotouch::AdaLibTouchInterrogator::internalProcessTouch(float *ptrX, float *ptrY, const iotouch::TouchOrientationSettings& rotation, const iotouch::CalibrationHandler& calib) { diff --git a/src/shared/tcMenu_Input_AdaTouchDriver.h b/src/shared/tcMenu_Input_AdaTouchDriver.h index 3d274f4..0c94f53 100644 --- a/src/shared/tcMenu_Input_AdaTouchDriver.h +++ b/src/shared/tcMenu_Input_AdaTouchDriver.h @@ -13,7 +13,7 @@ */ /* Changelist: - * - Refactored to have screen size given in init + * - Refactored to have screen size/SPI given in init * - Split into proper header/source file * - Enclosed inside of #ifdef & reorg'ed for general inclusion */ @@ -46,11 +46,12 @@ namespace iotouch { private: #ifndef HYDRO_UI_ENABLE_XPT2046TS Adafruit_FT6206& theTouchDevice; + uint16_t maxWidthDim; + uint16_t maxHeightDim; #else XPT2046_Touchscreen& theTouchDevice; #endif - uint16_t maxWidthDim; - uint16_t maxHeightDim; + public: #ifndef HYDRO_UI_ENABLE_XPT2046TS AdaLibTouchInterrogator(Adafruit_FT6206& touchLibRef); @@ -58,7 +59,11 @@ namespace iotouch { AdaLibTouchInterrogator(XPT2046_Touchscreen& touchLibRef); #endif - inline void init(uint16_t xMax, uint16_t yMax) { maxWidthDim = xMax; maxHeightDim = yMax; theTouchDevice.begin(); } + #ifndef HYDRO_UI_ENABLE_XPT2046TS + inline void init(uint16_t xMax, uint16_t yMax) { maxWidthDim = xMax; maxHeightDim = yMax; theTouchDevice.begin(); } + #else + inline void init(SPIClass *spi = nullptr) { if (spi) { theTouchDevice.begin(*spi); } else { theTouchDevice.begin(); } } + #endif iotouch::TouchState internalProcessTouch(float *ptrX, float *ptrY, const iotouch::TouchOrientationSettings& rotation, const iotouch::CalibrationHandler& calib); };