Compare commits

..

No commits in common. "f30f5281c1f496e80e9f78616578aa160a0d906c" and "0f1e528b20aaa8a9ee12620fbb891e96eaf4a57e" have entirely different histories.

4 changed files with 25 additions and 29 deletions

View File

@ -3,35 +3,34 @@
#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 isPressed = false;
volatile bool CST_IRQ = false;
TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr;
TouchScreenCST226SE *touchScreenCST226SE;
TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *))
: TouchScreenBase("CST226", width, height), _getTouch(getTouch)
: TouchScreenBase("touchscreen1", 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;
attachInterrupt(
TOUCH_IRQ, []() { isPressed = true; }, FALLING);
// #ifdef TOUCHSCREEN_INT
// pinMode(TOUCHSCREEN_INT, INPUT);
// attachInterrupt(
// TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING);
// #endif
LOG_DEBUG("CST226SE init OK at address 0x%02X", addr);
return;
}
@ -42,22 +41,17 @@ 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 touched = touch.getPoint(x_array, y_array, 1);
if (touched > 0) {
int16_t tx = x_array[0];
int16_t ty = y_array[0];
if (tx > (TFT_WIDTH + 10) && tx < (10) && ty > (TFT_HEIGHT + 10) && ty < (10)) {
return false;
}
x = tx;
y = ty;
LOG_DEBUG("TouchScreen touched %dx %dy", x, y);
uint8_t count = touch.getPoint(x_array, y_array, 1);
if (count > 0) {
x = x_array[0];
y = y_array[0];
return true;
}
return false;
}
@ -65,10 +59,10 @@ bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y)
{
if (instance) {
return instance->getTouch(*x, *y);
LOG_DEBUG("TouchScreen parsed %dx %dy", x, y);
} else {
return false;
LOG_DEBUG("TouchScreen touched %dx %dy", x, y);
}
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,12 +17,14 @@ 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;
TouchDrvCSTXXX touch;
TouchClassCST226 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.3.1 ; touchscreen addon
lewisxhe/SensorLib@0.2.0 ; touchscreen addon

View File

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