Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
- { env: "lilygo-t5-epaper-s3-pro" }
- { env: "lilygo-t-hmi" }
- { env: "lilygo-t-display-S3-amoled" }
- { env: "lilygo-t-watch-ultra" }
- { env: "smoochiee-board" }
- { env: "Marauder-v4-OG" }
- { env: "Marauder-v61" }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Things that needs to be done in next updates

## Latest Changelog
* 2.6.5:
* [x] M5-Tab5 using SDMMC driver for compatibility with other firmware
* [x] Added possibility to order by "Latest update"
* [x] Port to OpenSourceSRDLabs [WaveSentry and WaveSentry Pro ](https://opensourcesdrlab.com/products/aifw-wavesentry-esp32?VariantsId=10331)
* [x] Battery ADC measurement fix for Cardputer, Tdeck, StickCPlus2, T-Display S3, T-HMI
Expand Down
198 changes: 81 additions & 117 deletions boards/elecrow/interface.cpp
Original file line number Diff line number Diff line change
@@ -1,92 +1,33 @@
#include "nvs.h"
#include "nvs_handle.hpp"
#include "powerSave.h"
#include <Wire.h>
#include <interface.h>

namespace {
std::unique_ptr<nvs::NVSHandle> openNamespace(const char *ns, nvs_open_mode_t mode, esp_err_t &err) {
auto handle = nvs::open_nvs_handle(ns, mode, &err);
if (err != ESP_OK) {
log_i("openNamespace(%s) failed: %d", ns, err);
return nullptr;
}
return handle;
}
} // namespace
#ifndef TFT_BRIGHT_CHANNEL
#define TFT_BRIGHT_CHANNEL 0
#define TFT_BRIGHT_FREQ 5000
#define TFT_BRIGHT_Bits 8
#define TFT_BL 27
#endif

#if defined(HAS_CAPACITIVE_TOUCH) // CST816S
#include "CYD28_TouchscreenC.h"
#define CYD28_DISPLAY_HOR_RES_MAX 240
#define CYD28_DISPLAY_VER_RES_MAX 320
CYD28_TouchC touch(CYD28_DISPLAY_HOR_RES_MAX, CYD28_DISPLAY_VER_RES_MAX);

#elif defined(TOUCH_GT911_I2C) || defined(TOUCH_CST816S_I2C)
#ifdef TOUCH_GT911_I2C
#define TOUCH_MODULES_GT911
#define TOUCH_SDA_PIN GT911_I2C_CONFIG_SDA_IO_NUM
#define TOUCH_SCL_PIN GT911_I2C_CONFIG_SCL_IO_NUM
#define TOUCH_RST_PIN GT911_TOUCH_CONFIG_RST_GPIO_NUM
#define TOUCH_INT_PIN GT911_TOUCH_CONFIG_INT_GPIO_NUM
#define TOUCH_ADDR GT911_SLAVE_ADDRESS1
#ifndef TOUCH_INVERTED
#define TOUCH_INVERTED 0
#endif
#elif TOUCH_CST816S_I2C
#define TOUCH_MODULES_CST_SELF
#define TOUCH_SDA_PIN CST816S_I2C_CONFIG_SDA_IO_NUM
#define TOUCH_SCL_PIN CST816S_I2C_CONFIG_SCL_IO_NUM
#define TOUCH_RST_PIN CST816S_TOUCH_CONFIG_RST_GPIO_NUM
#define TOUCH_INT_PIN CST816S_TOUCH_CONFIG_INT_GPIO_NUM
#define TOUCH_ADDR CTS820_SLAVE_ADDRESS
#endif

#include <TouchLib.h>
class CYD_Touch : public TouchLib {
public:
TouchPoint t;
TP_Point ti;
CYD_Touch() : TouchLib(Wire, TOUCH_SDA_PIN, TOUCH_SCL_PIN, TOUCH_ADDR, TOUCH_RST_PIN) {}
inline bool begin() {
bool result = init();
setRotation(ROTATION);
return result;
}
inline bool touched() { return read(); }
inline TouchPoint getPointScaled() {
ti = getPoint(0);
#if TOUCH_INVERTED
t.x = ti.y;
t.y = TFT_WIDTH - ti.x;
#else
t.x = ti.x;
t.y = (tftHeight + 20) - ti.y;
#endif
t.pressed = true;
TouchLib::raw_data[0] = 0; // resets the read raw reading, that triggers TouchLib::read() to true, and
// is not resetted at the lib
return t;
}
};
CYD_Touch touch;
#else
#include "CYD28_TouchscreenR.h"
#ifndef CYD28_DISPLAY_HOR_RES_MAX
#define CYD28_DISPLAY_HOR_RES_MAX TFT_HEIGHT
#endif

#ifndef CYD28_DISPLAY_VER_RES_MAX
#define CYD28_DISPLAY_VER_RES_MAX TFT_WIDTH
#endif
CYD28_TouchR touch(CYD28_DISPLAY_HOR_RES_MAX, CYD28_DISPLAY_VER_RES_MAX);
#endif

/***************************************************************************************
** Function name: _setup_gpio()
** Location: main.cpp
** Description: initial setup for the device
***************************************************************************************/
void _setup_gpio() {
#if !defined(HAS_CAPACITIVE_TOUCH) && (defined(TOUCH_GT911_I2C) || defined(TOUCH_CST816S_I2C))
Wire.begin(TOUCH_SDA_PIN, TOUCH_SCL_PIN);
#endif
#if !defined(HAS_CAPACITIVE_TOUCH) && defined(ELECROW)
pinMode(33, OUTPUT); // touch CS
#endif
}

/***************************************************************************************
Expand All @@ -99,18 +40,52 @@ void _post_setup_gpio() {
pinMode(TFT_BL, OUTPUT);
ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits);
ledcWrite(TFT_BL, 255);
esp_err_t err = ESP_OK;
uint16_t calData[5];
auto nvsHandle = openNamespace("calData", NVS_READWRITE, err);
if (nvsHandle) {
err = nvsHandle->get_item("x0", calData[0]);
err |= nvsHandle->get_item("x1", calData[1]);
err |= nvsHandle->get_item("y0", calData[2]);
err |= nvsHandle->get_item("y1", calData[3]);
err |= nvsHandle->get_item("r", calData[4]);
} else {
err = 1;
Serial.println("Can't access calData namespace in NVS");
}

if (!touch.begin(
#ifdef CYD28_TouchR_MOSI
#if TFT_MOSI == CYD28_TouchR_MOSI
&SPI
#endif
#endif

)) {
Serial.println("Touch IC not Started");
log_i("Touch IC not Started");
} else Serial.println("Touch IC Started");
if (err) {
Serial.println("No calData available");
tft->setRotation(1);
tft->setTextSize(2);
tft->drawCentreString("Touch corners as indicated", TFT_HEIGHT / 2, TFT_WIDTH / 2, 1);
tft->calibrateTouch(calData, TFT_GREEN, TFT_BLACK, 15);
tft->setTouch(calData);
if (nvsHandle) {
Serial.println("Saving values into NVS");
err = ESP_OK;
err = nvsHandle->set_item("x0", calData[0]);
err |= nvsHandle->set_item("x1", calData[1]);
err |= nvsHandle->set_item("y0", calData[2]);
Comment on lines +65 to +69

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Commit NVS writes so touch calibration persists

The new calibration path writes values with set_item(...) but never calls nvsHandle->commit(). On ESP-IDF, NVS writes are buffered until commit; without it the calibration data is lost on reboot, so users will be prompted to re‑calibrate every power cycle. Add a commit() after the last set_item (and handle any error) to persist the values.

Useful? React with 👍 / 👎.

err |= nvsHandle->set_item("y1", calData[3]);
err |= nvsHandle->set_item("r", calData[4]);
if (err != ESP_OK) {
Serial.printf("Failed to store settings in NVS: %d\n", err);
} else {
Serial.println("Settings stored in NVS successfully");
}
tft->setRotation(rotation);
}
} else {
tft->setTouch(calData);
}
Serial.print("\ncalData[5] = ");
Serial.print("{ ");
for (uint8_t i = 0; i < 5; i++) {
Serial.print(calData[i]);
if (i < 4) Serial.print(", ");
}
Serial.println(" }");
}

/*********************************************************************
Expand Down Expand Up @@ -140,18 +115,24 @@ void _setBrightness(uint8_t brightval) {
** Function: InputHandler
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
struct TouchPointPro {
uint16_t x;
uint16_t y;
};
void InputHandler(void) {
TouchPointPro t;
static long d_tmp = millis();
const uint16_t w = tftWidth;
const uint16_t h = tftHeight + 20;
if (millis() - d_tmp > 250 || LongPress) { // I know R3CK.. I Should NOT nest if statements..
// but it is needed to not keep SPI bus used without need, it save resources
TouchPoint t;
#ifdef DONT_USE_INPUT_TASK
checkPowerSaveTime();
#endif
if (touch.touched()) {
auto t = touch.getPointScaled();
bool pressed = tft->getTouch(&t.x, &t.y);
if (pressed) {
d_tmp = millis();
#ifdef DONT_USE_INPUT_TASK // need to reset the variables to avoid ghost click
// need to reset the variables to avoid ghost click
NextPress = false;
PrevPress = false;
UpPress = false;
Expand All @@ -160,39 +141,26 @@ void InputHandler(void) {
EscPress = false;
AnyKeyPress = false;
touchPoint.pressed = false;
#endif

#ifdef CYD28_TouchR_MOSI
#if TFT_MOSI == CYD28_TouchR_MOSI // S024R is inverted
int tmp = t.x;
t.x = t.y;
t.y = tmp;
#endif
#endif

if (rotation == 3) {
t.y = (tftHeight + 20) - t.y;
t.x = tftWidth - t.x;
Serial.printf("\nRaw Touch on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
if (rotation == 1) { // Landscape
// Do Nothing
}
if (rotation == 3) { // Landscape
t.y = h - t.y; // invert y
t.x = w - t.x; // invert x
}
if (rotation == 0) {
int tmp = t.x;
t.x = tftWidth - t.y;
if (rotation == 0) { // Portrait
int tmp = t.x; // swap x y
t.x = w - t.y; // invert x
t.y = tmp;
}
if (rotation == 2) {
int tmp = t.x;
if (rotation == 2) { // Portrait
int tmp = t.x; // swap x y
t.x = t.y;
t.y = (tftHeight + 20) - tmp;
t.y = h - tmp; // invert y
}
Serial.printf("\nTouch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
log_i("\nTouch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
#if defined(CYD28_DISPLAY_VER_RES_MAX) && !defined(HAS_CAPACITIVE_TOUCH)
#if CYD28_DISPLAY_VER_RES_MAX > 340
auto t2 = touch.getPointRaw();
Serial.printf("RAW d Pressed on x=%d, y=%d\n", t2.x, t2.y);
#endif
#endif

Serial.printf("Touch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
if (!wakeUpScreen()) AnyKeyPress = true;
else return;

Expand All @@ -203,10 +171,6 @@ void InputHandler(void) {
touchHeatMap(touchPoint);
}
}
#ifdef TOUCH_GT911_I2C
else
touch.touched(); // keep calling it to keep refreshing raw readings for when needed it will be ok
#endif
}

/*********************************************************************
Expand Down
24 changes: 17 additions & 7 deletions boards/elecrow/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build_flags =
-DDISABLE_OTA

# Configurações de hardware
-DROTATION=3
-DROTATION=1
-DHAS_BTN=0
-DSEL_BTN=-1
-DUP_BTN=-1
Expand All @@ -35,6 +35,9 @@ build_flags =
-DLED_ON=LOW
-DHAS_TOUCH=1

# Using TFT_eSPI to make use of its calibration
-DUSE_TFT_ESPI

#TFT Configs
-DDONT_USE_INPUT_TASK=1 # TFT and Touch share the same SPI bus
-DILI9341_DRIVER=1
Expand All @@ -45,13 +48,12 @@ build_flags =
-DTFT_DC=2
-DTFT_RST=-1
-DTFT_BL=27
-DTFT_WIDTH=320
-DTFT_HEIGHT=480
-DTFT_IPS=0
-DTFT_COL_OFS1=0
-DTFT_ROW_OFS1=0
-DTFT_COL_OFS2=0
-DTFT_ROW_OFS2=0
-DTOUCH_CS=33
-DCYD28_TouchR_IRQ=36
-DCYD28_TouchR_MISO=12
-DCYD28_TouchR_MOSI=13
Expand All @@ -69,6 +71,9 @@ build_flags =

lib_deps =
${env.lib_deps}
Bodmer/TFT_eSPI @ 2.5.43
lib_ignore =
GFX Library for Arduino

[elecrowS3]
board_build.partitions = support_files/custom_16Mb.csv
Expand Down Expand Up @@ -109,7 +114,9 @@ extends=elecrow
board=elecrow-esp32-24B
build_flags =
${elecrow.build_flags}
-D CYD28_TouchR_ROT=3
-D TFT_WIDTH=240
-D TFT_HEIGHT=320
-D CYD28_TouchR_ROT=6
-D CYD28_TouchR_CAL_XMIN=557
-D CYD28_TouchR_CAL_XMAX=3263
-D CYD28_TouchR_CAL_YMIN=369
Expand All @@ -121,7 +128,9 @@ extends=elecrow
board=elecrow-esp32-24B
build_flags =
${elecrow.build_flags}
-D CYD28_TouchR_ROT=1
-D TFT_WIDTH=240
-D TFT_HEIGHT=320
-D CYD28_TouchR_ROT=6
-D CYD28_TouchR_CAL_XMIN=189
-D CYD28_TouchR_CAL_XMAX=3416
-D CYD28_TouchR_CAL_YMIN=359
Expand All @@ -133,8 +142,9 @@ board=elecrow-esp32-24B
build_flags =
${elecrow.build_flags}
-D ILI9488_DRIVER=1

-D CYD28_TouchR_ROT=7
-D TFT_WIDTH=320
-D TFT_HEIGHT=480
-D CYD28_TouchR_ROT=6
-D CYD28_TouchR_CAL_XMIN=353
-D CYD28_TouchR_CAL_XMAX=3568
-D CYD28_TouchR_CAL_YMIN=269
Expand Down
Loading
Loading