changed to sensorlib 0.3.1

This commit is contained in:
nasimovy 2025-04-19 20:48:06 +00:00
parent 0f1e528b20
commit f5c3e77a60
4 changed files with 28 additions and 26 deletions

View File

@ -3,35 +3,38 @@
#ifdef HAS_CST226SE
#ifndef TOUCH_IRQ
#define TOUCH_IRQ -1
#endif
#include "PowerFSM.h"
#include "Wire.h"
#include "configuration.h"
#include "modules/ExternalNotificationModule.h"
volatile bool CST_IRQ = false;
volatile bool isPressed = false;
TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr;
TouchScreenCST226SE *touchScreenCST226SE;
TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *))
: TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch)
: TouchScreenBase("CST226", width, height), _getTouch(getTouch)
{
instance = this;
}
void TouchScreenCST226SE::init()
{
touch.setPins(-1, TOUCH_IRQ);
touch.setTouchDrvModel(TouchDrv_CST226);
for (uint8_t addr : PossibleAddresses) {
if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) {
i2cAddress = addr;
// #ifdef TOUCHSCREEN_INT
// pinMode(TOUCHSCREEN_INT, INPUT);
// attachInterrupt(
// TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING);
// #endif
attachInterrupt(
TOUCH_IRQ, []() { isPressed = true; }, FALLING);
LOG_DEBUG("CST226SE init OK at address 0x%02X", addr);
touch.setMaxCoordinates(TFT_WIDTH + 5, TFT_HEIGHT + 5);
touch.setMirrorXY(true, true);
return;
}
}
@ -41,17 +44,18 @@ void TouchScreenCST226SE::init()
bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y)
{
if (!touch.isPressed())
if (!touch.isPressed()) {
return false;
int16_t x_array[1], y_array[1];
uint8_t count = touch.getPoint(x_array, y_array, 1);
if (count > 0) {
uint8_t touched = touch.getPoint(x_array, y_array, 1);
if (touched > 0) {
x = x_array[0];
y = y_array[0];
LOG_DEBUG("TouchScreen touched %dx %dy", x, y);
return true;
}
}
return false;
}
@ -59,11 +63,11 @@ bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y)
{
if (instance) {
return instance->getTouch(*x, *y);
LOG_DEBUG("TouchScreen touched %dx %dy", x, y);
}
LOG_DEBUG("TouchScreen parsed %dx %dy", x, y);
} else {
return false;
}
}
void TouchScreenCST226SE::onEvent(const TouchEvent &event)
{

View File

@ -6,8 +6,8 @@
#include "modules/CannedMessageModule.h"
#include "TouchDrvCSTXXX.hpp"
#include "TouchScreenBase.h"
#include "touch/TouchClassCST226.h"
class TouchScreenCST226SE : public TouchScreenBase
{
@ -17,14 +17,12 @@ class TouchScreenCST226SE : public TouchScreenBase
static bool forwardGetTouch(int16_t *x, int16_t *y);
bool (*_getTouch)(int16_t *, int16_t *);
protected:
virtual bool getTouch(int16_t &x, int16_t &y);
virtual void onEvent(const TouchEvent &event);
private:
static TouchScreenCST226SE *instance;
TouchClassCST226 touch;
TouchDrvCSTXXX touch;
uint8_t i2cAddress = 0;
static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT};

View File

@ -22,4 +22,4 @@ build_flags =
lib_deps =
${env:tbeam.lib_deps}
https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon
lewisxhe/SensorLib@0.2.0 ; touchscreen addon
lewisxhe/SensorLib@0.3.1 ; touchscreen addon

View File

@ -53,7 +53,7 @@
#define HAS_CST226SE 1
#define HAS_TOUCHSCREEN 1
#define TOUCHSCREEN_INT 35
#define TOUCH_IRQ 35
#define ST7796_NSS 25
#define ST7796_RS 13 // DC