mirror of
https://github.com/meshtastic/firmware.git
synced 2025-10-03 13:55:45 +00:00
Compare commits
2 Commits
0f1e528b20
...
f30f5281c1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f30f5281c1 | ||
![]() |
f5c3e77a60 |
@ -3,34 +3,35 @@
|
||||
|
||||
#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);
|
||||
return;
|
||||
}
|
||||
@ -41,17 +42,22 @@ 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) {
|
||||
x = x_array[0];
|
||||
y = y_array[0];
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -59,10 +65,10 @@ 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)
|
||||
|
@ -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};
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user