Skip to content

Commit

Permalink
SPI class for XPT2046
Browse files Browse the repository at this point in the history
  • Loading branch information
NachtRaveVL committed Mar 26, 2023
1 parent a1af586 commit 1a28dfe
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion examples/FullSystem/FullSystem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion examples/VerticalNFT/VerticalNFT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/shared/HydroInputDrivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ HydroInputTouchscreen::HydroInputTouchscreen(Pair<uint8_t, const pintype_t *> 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);
Expand Down
11 changes: 9 additions & 2 deletions src/shared/HydroUIInlines.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/shared/tcMenu_Input_AdaTouchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions src/shared/tcMenu_Input_AdaTouchDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -46,19 +46,24 @@ 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);
#else
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);
};

Expand Down

0 comments on commit 1a28dfe

Please sign in to comment.