SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
touch/TouchDrvCSTXXX.hpp
Go to the documentation of this file.
1
31#pragma once
32
33#include "../SensorBuildOpt.h"
34#if !SENSORLIB_EXCLUDE_TOUCH_CSTXXX
35
40
41static constexpr uint8_t CSTXXX_SLAVE_ADDRESS = (0x15);
42static constexpr uint8_t CST328_SLAVE_ADDRESS = (0x1A);
43
51
53{
54public:
60
65 ~TouchDrvCSTXXX() = default;
66
67// *INDENT-OFF*
75
76#if defined(ARDUINO)
86 bool begin(TwoWire &wire, uint8_t addr, int sda, int scl) override;
87#elif defined(ESP_PLATFORM)
88#if defined(SENSORLIB_USE_I2C_LEGACY)
98 bool begin(i2c_port_t port_num, uint8_t addr, int sda = -1, int scl = -1) override;
99#else
107 bool begin(i2c_master_bus_handle_t handle, uint8_t addr) override;
108#endif // ESP_PLATFORM
109#endif // ARDUINO
110
121 uint8_t addr) override;
122
128 void reset() override;
129
137 void sleep() override;
138
144 void wakeup() override;
145
151 const TouchPoints& getTouchPoints() override;
152
162 bool isPressed(uint32_t filter_ms = 0) override;
163
169 const char *getModelName() override;
170
176 uint32_t getChipID() override;
177
185 void setCenterButtonCoordinate(int16_t x, int16_t y) override;
186
194 void setHomeButtonCallback(TouchDrvInterface::HomeButtonCallback callback, void *user_data = NULL) override;
195
201 void disableAutoSleep();
202
208 void enableAutoSleep();
209
216 void setSwapXY(bool swap) override;
217
225 void setMirrorXY(bool mirrorX, bool mirrorY) override;
226
234 void setMaxCoordinates(uint16_t x, uint16_t y) override;
235
241 uint8_t getSupportTouchPoint() override;
242
250 void getResolution(uint16_t &x, uint16_t &y) override;
251
257 uint16_t getResolutionX() override;
258
264 uint16_t getResolutionY() override;
265
266// *INDENT-ON*
267
268private:
269
270 bool initImpl(uint8_t) override
271 {
272 return false;
273 }
274
275 using DriverCreator = std::unique_ptr<TouchDrvInterface> (*)();
276
277 static constexpr uint8_t driverCreatorMaxNum = 4;
278 static DriverCreator driverCreators[driverCreatorMaxNum];
279
280 std::unique_ptr<TouchDrvInterface> createDriver(TouchDrvType type)
281 {
282 if (type < driverCreatorMaxNum) {
283 return driverCreators[type]();
284 }
285 return nullptr;
286 }
287
288 template<typename... Args>
289 bool beginImpl(Args&&... args)
290 {
291 for (int i = (_touchType == TouchDrv_UNKNOWN) ? 0 : _touchType;
292 i < driverCreatorMaxNum; ++i) {
293 _drv = createDriver(static_cast<TouchDrvType>(i));
294 setupDriver();
295 if (_drv && _drv->begin(std::forward<Args>(args)...)) {
296 _touchType = static_cast<TouchDrvType>(i);
297 return true;
298 }
299 }
300 _touchType = TouchDrv_UNKNOWN;
301 return false;
302 }
303
304 static constexpr size_t TOUCH_DRV_TYPE_VALID_COUNT = TouchDrv_UNKNOWN;
305
306 static_assert(sizeof(driverCreators) / sizeof(driverCreators[0]) == TOUCH_DRV_TYPE_VALID_COUNT,
307 "driverCreators size mismatch");
308
309 void setupDriver();
310 TouchDrvType _touchType;
311 std::unique_ptr<TouchDrvInterface> _drv;
312};
313
314#endif
@license MIT License
@license MIT License
@license MIT License
@license MIT License
uint32_t(*)(Operation op, void *param1, void *param2) CustomHalCallback
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
void sleep() override
Puts the touch driver to sleep.
TouchDrvCSTXXX()
Constructor for the touch driver.
uint16_t getResolutionY() override
Gets the touch point resolution.
~TouchDrvCSTXXX()=default
Destructor for the touch driver.
void setSwapXY(bool swap) override
Set the swap XY flag.
uint8_t getSupportTouchPoint() override
Gets the number of supported touch points.
void reset() override
Reset the touch driver.
void setHomeButtonCallback(TouchDrvInterface::HomeButtonCallback callback, void *user_data=NULL) override
Set the home button callback.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr) override
Initialize the touch driver for custom communication.
const char * getModelName() override
Get the model name.
const TouchPoints & getTouchPoints() override
Get the touch points.
void wakeup() override
Wake up the touch driver.
void disableAutoSleep()
Disable automatic sleep.
uint32_t getChipID() override
Get the chip ID.
void getResolution(uint16_t &x, uint16_t &y) override
Gets the touch point coordinates.
void enableAutoSleep()
Enable automatic sleep.
void setCenterButtonCoordinate(int16_t x, int16_t y) override
Set the center button coordinate.
uint16_t getResolutionX() override
Gets the touch point resolution.
void setMaxCoordinates(uint16_t x, uint16_t y) override
Set the maximum coordinates.
void setTouchDrvModel(TouchDrvType model)
Set the touch driver model.
void setMirrorXY(bool mirrorX, bool mirrorY) override
Set the mirror XY flag.
Abstract base class for touch screen drivers.
void(*)(void *user_data) HomeButtonCallback
Callback type for home button events.
Container for touch point data and optional gesture information.
volatile bool isPressed
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
uint8_t i
@ TouchDrv_CST226
@ TouchDrv_UNKNOWN
@ TouchDrv_CST8XX
@ TouchDrv_CST92XX
@ TouchDrv_CST3530
int16_t x[5]
int16_t y[5]