Skip to content

Commit 8b1c816

Browse files
authored
Tab5 mmc (#264)
* SDMMC for tab5 * tab5 sdmmc 2nd try * elecrow resolution * Elecrow touch * elecrow calData * elecrow calData * elecrow to TFT_eSPI with calibration * T-Watch Ultra port, and sorting fix #262 * fix build * Add empty display function to VectorDisplay Added an empty display function with a default parameter.
1 parent afa499d commit 8b1c816

File tree

22 files changed

+602
-225
lines changed

22 files changed

+602
-225
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
- { env: "lilygo-t5-epaper-s3-pro" }
6666
- { env: "lilygo-t-hmi" }
6767
- { env: "lilygo-t-display-S3-amoled" }
68+
- { env: "lilygo-t-watch-ultra" }
6869
- { env: "smoochiee-board" }
6970
- { env: "Marauder-v4-OG" }
7071
- { env: "Marauder-v61" }

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Things that needs to be done in next updates
8585

8686
## Latest Changelog
8787
* 2.6.5:
88+
* [x] M5-Tab5 using SDMMC driver for compatibility with other firmware
8889
* [x] Added possibility to order by "Latest update"
8990
* [x] Port to OpenSourceSRDLabs [WaveSentry and WaveSentry Pro ](https://opensourcesdrlab.com/products/aifw-wavesentry-esp32?VariantsId=10331)
9091
* [x] Battery ADC measurement fix for Cardputer, Tdeck, StickCPlus2, T-Display S3, T-HMI

boards/elecrow/interface.cpp

Lines changed: 81 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,33 @@
1+
#include "nvs.h"
2+
#include "nvs_handle.hpp"
13
#include "powerSave.h"
24
#include <Wire.h>
35
#include <interface.h>
46

7+
namespace {
8+
std::unique_ptr<nvs::NVSHandle> openNamespace(const char *ns, nvs_open_mode_t mode, esp_err_t &err) {
9+
auto handle = nvs::open_nvs_handle(ns, mode, &err);
10+
if (err != ESP_OK) {
11+
log_i("openNamespace(%s) failed: %d", ns, err);
12+
return nullptr;
13+
}
14+
return handle;
15+
}
16+
} // namespace
517
#ifndef TFT_BRIGHT_CHANNEL
618
#define TFT_BRIGHT_CHANNEL 0
719
#define TFT_BRIGHT_FREQ 5000
820
#define TFT_BRIGHT_Bits 8
921
#define TFT_BL 27
1022
#endif
1123

12-
#if defined(HAS_CAPACITIVE_TOUCH) // CST816S
13-
#include "CYD28_TouchscreenC.h"
14-
#define CYD28_DISPLAY_HOR_RES_MAX 240
15-
#define CYD28_DISPLAY_VER_RES_MAX 320
16-
CYD28_TouchC touch(CYD28_DISPLAY_HOR_RES_MAX, CYD28_DISPLAY_VER_RES_MAX);
17-
18-
#elif defined(TOUCH_GT911_I2C) || defined(TOUCH_CST816S_I2C)
19-
#ifdef TOUCH_GT911_I2C
20-
#define TOUCH_MODULES_GT911
21-
#define TOUCH_SDA_PIN GT911_I2C_CONFIG_SDA_IO_NUM
22-
#define TOUCH_SCL_PIN GT911_I2C_CONFIG_SCL_IO_NUM
23-
#define TOUCH_RST_PIN GT911_TOUCH_CONFIG_RST_GPIO_NUM
24-
#define TOUCH_INT_PIN GT911_TOUCH_CONFIG_INT_GPIO_NUM
25-
#define TOUCH_ADDR GT911_SLAVE_ADDRESS1
26-
#ifndef TOUCH_INVERTED
27-
#define TOUCH_INVERTED 0
28-
#endif
29-
#elif TOUCH_CST816S_I2C
30-
#define TOUCH_MODULES_CST_SELF
31-
#define TOUCH_SDA_PIN CST816S_I2C_CONFIG_SDA_IO_NUM
32-
#define TOUCH_SCL_PIN CST816S_I2C_CONFIG_SCL_IO_NUM
33-
#define TOUCH_RST_PIN CST816S_TOUCH_CONFIG_RST_GPIO_NUM
34-
#define TOUCH_INT_PIN CST816S_TOUCH_CONFIG_INT_GPIO_NUM
35-
#define TOUCH_ADDR CTS820_SLAVE_ADDRESS
36-
#endif
37-
38-
#include <TouchLib.h>
39-
class CYD_Touch : public TouchLib {
40-
public:
41-
TouchPoint t;
42-
TP_Point ti;
43-
CYD_Touch() : TouchLib(Wire, TOUCH_SDA_PIN, TOUCH_SCL_PIN, TOUCH_ADDR, TOUCH_RST_PIN) {}
44-
inline bool begin() {
45-
bool result = init();
46-
setRotation(ROTATION);
47-
return result;
48-
}
49-
inline bool touched() { return read(); }
50-
inline TouchPoint getPointScaled() {
51-
ti = getPoint(0);
52-
#if TOUCH_INVERTED
53-
t.x = ti.y;
54-
t.y = TFT_WIDTH - ti.x;
55-
#else
56-
t.x = ti.x;
57-
t.y = (tftHeight + 20) - ti.y;
58-
#endif
59-
t.pressed = true;
60-
TouchLib::raw_data[0] = 0; // resets the read raw reading, that triggers TouchLib::read() to true, and
61-
// is not resetted at the lib
62-
return t;
63-
}
64-
};
65-
CYD_Touch touch;
66-
#else
67-
#include "CYD28_TouchscreenR.h"
68-
#ifndef CYD28_DISPLAY_HOR_RES_MAX
69-
#define CYD28_DISPLAY_HOR_RES_MAX TFT_HEIGHT
70-
#endif
71-
72-
#ifndef CYD28_DISPLAY_VER_RES_MAX
73-
#define CYD28_DISPLAY_VER_RES_MAX TFT_WIDTH
74-
#endif
75-
CYD28_TouchR touch(CYD28_DISPLAY_HOR_RES_MAX, CYD28_DISPLAY_VER_RES_MAX);
76-
#endif
77-
7824
/***************************************************************************************
7925
** Function name: _setup_gpio()
8026
** Location: main.cpp
8127
** Description: initial setup for the device
8228
***************************************************************************************/
8329
void _setup_gpio() {
84-
#if !defined(HAS_CAPACITIVE_TOUCH) && (defined(TOUCH_GT911_I2C) || defined(TOUCH_CST816S_I2C))
85-
Wire.begin(TOUCH_SDA_PIN, TOUCH_SCL_PIN);
86-
#endif
87-
#if !defined(HAS_CAPACITIVE_TOUCH) && defined(ELECROW)
8830
pinMode(33, OUTPUT); // touch CS
89-
#endif
9031
}
9132

9233
/***************************************************************************************
@@ -99,18 +40,52 @@ void _post_setup_gpio() {
9940
pinMode(TFT_BL, OUTPUT);
10041
ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits);
10142
ledcWrite(TFT_BL, 255);
43+
esp_err_t err = ESP_OK;
44+
uint16_t calData[5];
45+
auto nvsHandle = openNamespace("calData", NVS_READWRITE, err);
46+
if (nvsHandle) {
47+
err = nvsHandle->get_item("x0", calData[0]);
48+
err |= nvsHandle->get_item("x1", calData[1]);
49+
err |= nvsHandle->get_item("y0", calData[2]);
50+
err |= nvsHandle->get_item("y1", calData[3]);
51+
err |= nvsHandle->get_item("r", calData[4]);
52+
} else {
53+
err = 1;
54+
Serial.println("Can't access calData namespace in NVS");
55+
}
10256

103-
if (!touch.begin(
104-
#ifdef CYD28_TouchR_MOSI
105-
#if TFT_MOSI == CYD28_TouchR_MOSI
106-
&SPI
107-
#endif
108-
#endif
109-
110-
)) {
111-
Serial.println("Touch IC not Started");
112-
log_i("Touch IC not Started");
113-
} else Serial.println("Touch IC Started");
57+
if (err) {
58+
Serial.println("No calData available");
59+
tft->setRotation(1);
60+
tft->setTextSize(2);
61+
tft->drawCentreString("Touch corners as indicated", TFT_HEIGHT / 2, TFT_WIDTH / 2, 1);
62+
tft->calibrateTouch(calData, TFT_GREEN, TFT_BLACK, 15);
63+
tft->setTouch(calData);
64+
if (nvsHandle) {
65+
Serial.println("Saving values into NVS");
66+
err = ESP_OK;
67+
err = nvsHandle->set_item("x0", calData[0]);
68+
err |= nvsHandle->set_item("x1", calData[1]);
69+
err |= nvsHandle->set_item("y0", calData[2]);
70+
err |= nvsHandle->set_item("y1", calData[3]);
71+
err |= nvsHandle->set_item("r", calData[4]);
72+
if (err != ESP_OK) {
73+
Serial.printf("Failed to store settings in NVS: %d\n", err);
74+
} else {
75+
Serial.println("Settings stored in NVS successfully");
76+
}
77+
tft->setRotation(rotation);
78+
}
79+
} else {
80+
tft->setTouch(calData);
81+
}
82+
Serial.print("\ncalData[5] = ");
83+
Serial.print("{ ");
84+
for (uint8_t i = 0; i < 5; i++) {
85+
Serial.print(calData[i]);
86+
if (i < 4) Serial.print(", ");
87+
}
88+
Serial.println(" }");
11489
}
11590

11691
/*********************************************************************
@@ -140,18 +115,24 @@ void _setBrightness(uint8_t brightval) {
140115
** Function: InputHandler
141116
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
142117
**********************************************************************/
118+
struct TouchPointPro {
119+
uint16_t x;
120+
uint16_t y;
121+
};
143122
void InputHandler(void) {
123+
TouchPointPro t;
144124
static long d_tmp = millis();
125+
const uint16_t w = tftWidth;
126+
const uint16_t h = tftHeight + 20;
145127
if (millis() - d_tmp > 250 || LongPress) { // I know R3CK.. I Should NOT nest if statements..
146128
// but it is needed to not keep SPI bus used without need, it save resources
147-
TouchPoint t;
148129
#ifdef DONT_USE_INPUT_TASK
149130
checkPowerSaveTime();
150131
#endif
151-
if (touch.touched()) {
152-
auto t = touch.getPointScaled();
132+
bool pressed = tft->getTouch(&t.x, &t.y);
133+
if (pressed) {
153134
d_tmp = millis();
154-
#ifdef DONT_USE_INPUT_TASK // need to reset the variables to avoid ghost click
135+
// need to reset the variables to avoid ghost click
155136
NextPress = false;
156137
PrevPress = false;
157138
UpPress = false;
@@ -160,39 +141,26 @@ void InputHandler(void) {
160141
EscPress = false;
161142
AnyKeyPress = false;
162143
touchPoint.pressed = false;
163-
#endif
164144

165-
#ifdef CYD28_TouchR_MOSI
166-
#if TFT_MOSI == CYD28_TouchR_MOSI // S024R is inverted
167-
int tmp = t.x;
168-
t.x = t.y;
169-
t.y = tmp;
170-
#endif
171-
#endif
172-
173-
if (rotation == 3) {
174-
t.y = (tftHeight + 20) - t.y;
175-
t.x = tftWidth - t.x;
145+
Serial.printf("\nRaw Touch on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
146+
if (rotation == 1) { // Landscape
147+
// Do Nothing
148+
}
149+
if (rotation == 3) { // Landscape
150+
t.y = h - t.y; // invert y
151+
t.x = w - t.x; // invert x
176152
}
177-
if (rotation == 0) {
178-
int tmp = t.x;
179-
t.x = tftWidth - t.y;
153+
if (rotation == 0) { // Portrait
154+
int tmp = t.x; // swap x y
155+
t.x = w - t.y; // invert x
180156
t.y = tmp;
181157
}
182-
if (rotation == 2) {
183-
int tmp = t.x;
158+
if (rotation == 2) { // Portrait
159+
int tmp = t.x; // swap x y
184160
t.x = t.y;
185-
t.y = (tftHeight + 20) - tmp;
161+
t.y = h - tmp; // invert y
186162
}
187-
Serial.printf("\nTouch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
188-
log_i("\nTouch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
189-
#if defined(CYD28_DISPLAY_VER_RES_MAX) && !defined(HAS_CAPACITIVE_TOUCH)
190-
#if CYD28_DISPLAY_VER_RES_MAX > 340
191-
auto t2 = touch.getPointRaw();
192-
Serial.printf("RAW d Pressed on x=%d, y=%d\n", t2.x, t2.y);
193-
#endif
194-
#endif
195-
163+
Serial.printf("Touch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
196164
if (!wakeUpScreen()) AnyKeyPress = true;
197165
else return;
198166

@@ -203,10 +171,6 @@ void InputHandler(void) {
203171
touchHeatMap(touchPoint);
204172
}
205173
}
206-
#ifdef TOUCH_GT911_I2C
207-
else
208-
touch.touched(); // keep calling it to keep refreshing raw readings for when needed it will be ok
209-
#endif
210174
}
211175

212176
/*********************************************************************

boards/elecrow/platformio.ini

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ build_flags =
2222
-DDISABLE_OTA
2323

2424
# Configurações de hardware
25-
-DROTATION=3
25+
-DROTATION=1
2626
-DHAS_BTN=0
2727
-DSEL_BTN=-1
2828
-DUP_BTN=-1
@@ -35,6 +35,9 @@ build_flags =
3535
-DLED_ON=LOW
3636
-DHAS_TOUCH=1
3737

38+
# Using TFT_eSPI to make use of its calibration
39+
-DUSE_TFT_ESPI
40+
3841
#TFT Configs
3942
-DDONT_USE_INPUT_TASK=1 # TFT and Touch share the same SPI bus
4043
-DILI9341_DRIVER=1
@@ -45,13 +48,12 @@ build_flags =
4548
-DTFT_DC=2
4649
-DTFT_RST=-1
4750
-DTFT_BL=27
48-
-DTFT_WIDTH=320
49-
-DTFT_HEIGHT=480
5051
-DTFT_IPS=0
5152
-DTFT_COL_OFS1=0
5253
-DTFT_ROW_OFS1=0
5354
-DTFT_COL_OFS2=0
5455
-DTFT_ROW_OFS2=0
56+
-DTOUCH_CS=33
5557
-DCYD28_TouchR_IRQ=36
5658
-DCYD28_TouchR_MISO=12
5759
-DCYD28_TouchR_MOSI=13
@@ -69,6 +71,9 @@ build_flags =
6971

7072
lib_deps =
7173
${env.lib_deps}
74+
Bodmer/TFT_eSPI @ 2.5.43
75+
lib_ignore =
76+
GFX Library for Arduino
7277

7378
[elecrowS3]
7479
board_build.partitions = support_files/custom_16Mb.csv
@@ -109,7 +114,9 @@ extends=elecrow
109114
board=elecrow-esp32-24B
110115
build_flags =
111116
${elecrow.build_flags}
112-
-D CYD28_TouchR_ROT=3
117+
-D TFT_WIDTH=240
118+
-D TFT_HEIGHT=320
119+
-D CYD28_TouchR_ROT=6
113120
-D CYD28_TouchR_CAL_XMIN=557
114121
-D CYD28_TouchR_CAL_XMAX=3263
115122
-D CYD28_TouchR_CAL_YMIN=369
@@ -121,7 +128,9 @@ extends=elecrow
121128
board=elecrow-esp32-24B
122129
build_flags =
123130
${elecrow.build_flags}
124-
-D CYD28_TouchR_ROT=1
131+
-D TFT_WIDTH=240
132+
-D TFT_HEIGHT=320
133+
-D CYD28_TouchR_ROT=6
125134
-D CYD28_TouchR_CAL_XMIN=189
126135
-D CYD28_TouchR_CAL_XMAX=3416
127136
-D CYD28_TouchR_CAL_YMIN=359
@@ -133,8 +142,9 @@ board=elecrow-esp32-24B
133142
build_flags =
134143
${elecrow.build_flags}
135144
-D ILI9488_DRIVER=1
136-
137-
-D CYD28_TouchR_ROT=7
145+
-D TFT_WIDTH=320
146+
-D TFT_HEIGHT=480
147+
-D CYD28_TouchR_ROT=6
138148
-D CYD28_TouchR_CAL_XMIN=353
139149
-D CYD28_TouchR_CAL_XMAX=3568
140150
-D CYD28_TouchR_CAL_YMIN=269

0 commit comments

Comments
 (0)