Skip to content
Draft
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
54 changes: 54 additions & 0 deletions MODIFICATIONS_GT911.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ESP32 Marauder v1.13.0: ESP32-3248S035C GT911 support

This is a community modification of `justcallmekoko/ESP32Marauder` tag `v1.13.0` for the 3.5-inch ESP32-3248S035C board.

## Hardware target

- ESP32-D0WD-V3, 4 MB flash
- ST7796 display, 320 x 480
- GT911 capacitive touch
- GT911 SDA: GPIO33
- GT911 SCL: GPIO32
- GT911 INT: GPIO21
- GT911 RST is documented as GPIO25; the tested code does not actively toggle it

## Code changes

`esp32_marauder/configs.h`

- adds `HAS_GT911_TOUCH` to the official `MARAUDER_CYD_3_5_INCH` target;
- defines the GT911 I2C and interrupt pins.

`esp32_marauder/Display.cpp`

- adds SensorLib's `TouchDrvGT911` driver;
- probes GT911 at I2C addresses `0x5D` and `0x14`;
- maps native 320 x 480 coordinates for display rotations 0-3;
- bypasses TFT_eSPI resistive-touch calibration;
- prints a clear serial success or failure message;
- adds a 100 ms release debounce.

## Why the debounce is required

SensorLib's GT911 `getPoint()` clears the controller data-ready frame. A rapid poll immediately afterward may return zero even while the finger is still on the screen. Marauder can interpret that zero as a release and process the same physical tap twice. The final build retains the last valid point for 100 ms, making one physical tap produce one menu action.

## TFT_eSPI build configuration

- TFT_eSPI 2.5.34
- `User_Setup_cyd_3_5_inch.h`
- ST7796 driver
- 320 x 480 resolution
- resistive `TOUCH_CS 33` disabled because GPIO33 is GT911 SDA
- complete upstream `User_Setup_Select.h` retained; only the selected setup include is changed

## Tested build

- Marauder version: v1.13.0
- ESP32 Arduino core: 2.0.11
- FQBN: `esp32:esp32:d32:PartitionScheme=min_spiffs`
- SensorLib: 0.2.2
- final sketch size: 1,360,937 bytes
- final global memory: 76,892 bytes
- full flash and application-only update tested successfully

This is not an official ESP32Marauder release. Preserve the upstream and third-party license notices when redistributing it.
122 changes: 119 additions & 3 deletions esp32_marauder/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

#ifdef HAS_SCREEN

#ifdef HAS_GT911_TOUCH
#include <Wire.h>
#include <TouchDrvGT911.hpp>

static TouchDrvGT911 cyd_gt911;
static bool cyd_gt911_ready = false;
#endif

Display::Display()
#ifdef HAS_CYD_TOUCH
: touchscreenSPI(VSPI),
Expand Down Expand Up @@ -42,7 +50,94 @@ int8_t Display::menuButton(uint16_t *x, uint16_t *y, bool pressed, bool check_ho
uint8_t Display::updateTouch(uint16_t *x, uint16_t *y, uint16_t threshold) {
#ifdef HAS_ILI9341
if (!this->headless_mode) {
#ifdef HAS_CAP_TOUCH
#ifdef HAS_GT911_TOUCH
/*
* GT911 only reports a new data frame periodically. getPoint()
* clears that frame, so an immediate second poll may return zero
* even though the finger is still touching the panel.
*
* Keep the touch logically pressed across short gaps. A genuine
* release is reported only after no GT911 frame has arrived for
* GT911_RELEASE_MS.
*/
static bool gt911_down = false;
static uint32_t gt911_last_frame = 0;
static uint16_t gt911_last_x = 0;
static uint16_t gt911_last_y = 0;

constexpr uint32_t GT911_RELEASE_MS = 100;

if (!cyd_gt911_ready) {
gt911_down = false;
return 0;
}

int16_t gt_x[1] = {0};
int16_t gt_y[1] = {0};

const uint8_t point_count =
cyd_gt911.getPoint(gt_x, gt_y, 1);

if (point_count > 0) {
const int32_t raw_x = gt_x[0];
const int32_t raw_y = gt_y[0];

uint16_t screen_x = 0;
uint16_t screen_y = 0;

switch (this->tft.getRotation()) {
case 0:
screen_x = raw_x;
screen_y = raw_y;
break;

case 1:
screen_x = raw_y;
screen_y = (TFT_WIDTH - 1) - raw_x;
break;

case 2:
screen_x = (TFT_WIDTH - 1) - raw_x;
screen_y = (TFT_HEIGHT - 1) - raw_y;
break;

case 3:
screen_x = (TFT_HEIGHT - 1) - raw_y;
screen_y = raw_x;
break;

default:
gt911_down = false;
return 0;
}

gt911_last_x = screen_x;
gt911_last_y = screen_y;
gt911_last_frame = millis();
gt911_down = true;

*x = screen_x;
*y = screen_y;
return 1;
}

/*
* Ignore short zero-report gaps between valid GT911 frames.
* Keep returning the most recent coordinate while the debounce
* interval has not expired.
*/
if (gt911_down &&
static_cast<uint32_t>(millis() - gt911_last_frame)
< GT911_RELEASE_MS) {
*x = gt911_last_x;
*y = gt911_last_y;
return 1;
}

gt911_down = false;
return 0;

#elif defined(HAS_CAP_TOUCH)
// FT6336 capacitive touch: rotation-aware + edge exclusion
{
uint16_t raw_x, raw_y;
Expand Down Expand Up @@ -158,7 +253,7 @@ void Display::init() {
}

void Display::setCalData(bool landscape) {
#if !defined(HAS_CYD_TOUCH) && !defined(HAS_CAP_TOUCH)
#if !defined(HAS_CYD_TOUCH) && !defined(HAS_CAP_TOUCH) && !defined(HAS_GT911_TOUCH)
if (!landscape) {
#ifdef TFT_SHIELD
uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
Expand Down Expand Up @@ -216,11 +311,32 @@ void Display::RunSetup() {

tft.setRotation(SCREEN_ORIENTATION);

#ifdef HAS_GT911_TOUCH
cyd_gt911.setPins(-1, TOUCH_INT);

cyd_gt911_ready =
cyd_gt911.begin(Wire, 0x5D, TOUCH_SDA, TOUCH_SCL);

if (!cyd_gt911_ready) {
cyd_gt911_ready =
cyd_gt911.begin(Wire, 0x14, TOUCH_SDA, TOUCH_SCL);
}

if (cyd_gt911_ready) {
cyd_gt911.setMaxCoordinates(TFT_WIDTH, TFT_HEIGHT);
cyd_gt911.setSwapXY(false);
cyd_gt911.setMirrorXY(false, false);
Serial.println("GT911 capacitive touch initialized");
} else {
Serial.println("ERROR: GT911 not detected at 0x5D or 0x14");
}
#endif

tft.setCursor(0, 0);

#ifdef HAS_ILI9341

#if !defined(HAS_CYD_TOUCH) && !defined(HAS_CAP_TOUCH)
#if !defined(HAS_CYD_TOUCH) && !defined(HAS_CAP_TOUCH) && !defined(HAS_GT911_TOUCH)
this->setCalData();
#endif

Expand Down
7 changes: 7 additions & 0 deletions esp32_marauder/configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@

#ifdef MARAUDER_CYD_3_5_INCH
#define HAS_TOUCH
#define HAS_GT911_TOUCH

// ESP32-3248S035C GT911 capacitive touch
#define TOUCH_SDA 33
#define TOUCH_SCL 32
#define TOUCH_INT 21
#define TOUCH_RST 25
#define HAS_FLIPPER_LED
//#define FLIPPER_ZERO_HAT
//#define HAS_BATTERY
Expand Down
Loading