SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
TouchDrvCSTXXX.cpp
Go to the documentation of this file.
1
30#include "../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_TOUCH_CSTXXX
32
33#include "TouchDrvCSTXXX.hpp"
34
35TouchDrvCSTXXX::DriverCreator TouchDrvCSTXXX::driverCreators[TouchDrvCSTXXX::driverCreatorMaxNum] = {
36 []() -> std::unique_ptr<TouchDrvInterface> { return std::make_unique<TouchDrvCST226>(); },
37 []() -> std::unique_ptr<TouchDrvInterface> { return std::make_unique<TouchDrvCST816>(); },
38 []() -> std::unique_ptr<TouchDrvInterface> { return std::make_unique<TouchDrvCST92xx>(); },
39 []() -> std::unique_ptr<TouchDrvInterface> { return std::make_unique<TouchDrvCST3530>(); }
40};
41
43
44
46{
47 _touchType = model;
48}
49
50void TouchDrvCSTXXX::setupDriver()
51{
52 if (_drv) {
53 _drv->setPins(_pinsCfg.rstPin, _pinsCfg.irqPin);
55 }
56}
57
58#if defined(ARDUINO)
59bool TouchDrvCSTXXX::begin(TwoWire &wire, uint8_t addr, int sda, int scl)
60{
61 return beginImpl(wire, addr, sda, scl);
62}
63#elif defined(ESP_PLATFORM)
64#if defined(SENSORLIB_USE_I2C_LEGACY)
65bool TouchDrvCSTXXX::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
66{
67 return beginImpl(port_num, addr, sda, scl);
68}
69#else
70bool TouchDrvCSTXXX::begin(i2c_master_bus_handle_t handle, uint8_t addr)
71{
72 return beginImpl(handle, addr);
73}
74#endif // ESP_PLATFORM
75#endif // ARDUINO
76
77
80 uint8_t addr)
81{
82 return beginImpl(callback, hal_callback, addr);
83}
84
85
87{
88 if (!_drv)return;
89 _drv->reset();
90}
91
93{
94 return _drv ? _drv->getTouchPoints() : _touchPoints;
95}
96
97bool TouchDrvCSTXXX::isPressed(uint32_t filter_ms)
98{
99 if (!_drv)return false;
100 return _drv->isPressed(filter_ms);
101}
102
104{
105 return _drv ? _drv->getModelName() : "NULL";
106}
107
109{
110 return _drv ? _drv->getChipID() : 0;
111}
112
114{
115 if (!_drv)return;
116 _drv->sleep();
117}
118
120{
121 if (!_drv)return;
122 _drv->wakeup();
123}
124
126{
127 return _drv ? _drv->getSupportTouchPoint() : 0;
128}
129
130void TouchDrvCSTXXX::getResolution(uint16_t &x, uint16_t &y)
131{
132 if (!_drv)return;
133 _drv->getResolution(x, y);
134}
135
136
138{
139 return _drv ? _drv->getResolutionY() : 0;
140}
141
143{
144 return _drv ? _drv->getResolutionX() : 0;
145}
146
147
149{
150 if (!_drv)return ;
151 if (_touchType == TouchDrv_CST8XX) {
152 static_cast<TouchDrvCST816 *>(_drv.get())->setCenterButtonCoordinate(x, y);
153 }
154}
155
157{
158 if (!_drv)return ;
159 if (_touchType == TouchDrv_CST8XX) {
160 static_cast<TouchDrvCST816 *>(_drv.get())->setHomeButtonCallback(callback, user_data);
161 } else if (_touchType == TouchDrv_CST226) {
162 static_cast<TouchDrvCST226 *>(_drv.get())->setHomeButtonCallback(callback, user_data);
163 }
164}
165
167{
168 if (!_drv)return ;
169 if (_touchType == TouchDrv_CST8XX) {
170 static_cast<TouchDrvCST816 *>(_drv.get())->disableAutoSleep();
171 }
172}
173
175{
176 if (!_drv)return ;
177 if (_touchType == TouchDrv_CST8XX) {
178 static_cast<TouchDrvCST816 *>(_drv.get())->enableAutoSleep();
179 }
180}
181
183{
184 if (!_drv)return ;
185 _drv->setSwapXY(swap);
186}
187
188void TouchDrvCSTXXX::setMirrorXY(bool mirrorX, bool mirrorY)
189{
190 if (!_drv)return ;
191 _drv->setMirrorXY(mirrorX, mirrorY);
192}
193
194void TouchDrvCSTXXX::setMaxCoordinates(uint16_t x, uint16_t y)
195{
196 if (!_drv)return ;
197 _drv->setMaxCoordinates(x, y);
198}
199
200#endif
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.
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.
bool isPressed(uint32_t filter_ms=0) override
Check if any touch point is currently pressed.
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.
void(*)(void *user_data) HomeButtonCallback
Callback type for home button events.
SensorHalCustom::CustomMode _halModeCallback
Custom GPIO mode callback.
TouchPinsCfg _pinsCfg
Configuration for reset and interrupt pins.
SensorHalCustom::CustomWrite _halWriteCallback
Custom GPIO write callback.
TouchPoints _touchPoints
Touch points data.
SensorHalCustom::CustomRead _halReadCallback
Custom GPIO read callback.
Container for touch point data and optional gesture information.
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
@ TouchDrv_CST226
@ TouchDrv_UNKNOWN
@ TouchDrv_CST8XX
int16_t x[5]
int16_t y[5]