Skip to content
Open
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
28 changes: 28 additions & 0 deletions src/display/drivers/AmoledDisplay/pin_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ constexpr AmoledHwConfig WAVESHARE_S3_AMOLED_HW_CONFIG{
.mirror_touch = true,
};

constexpr AmoledHwConfig WAVESHARE_S3_AMOLED_143_HW_CONFIG{
.lcd_sdio0 = 11,
.lcd_sdio1 = 12,
.lcd_sdio2 = 13,
.lcd_sdio3 = 14,
.lcd_sclk = 10,
.lcd_cs = 9,
.lcd_rst = 21,
.lcd_width = 466,
.lcd_height = 466,
.lcd_gram_offset_x = 6,
.lcd_gram_offset_y = 0,
.lcd_en = 42,
.i2c_sda = 47,
.i2c_scl = 48,
.tp_int = -1,
.tp_rst = -1,
.battery_voltage_adc_data = 4, // BAT_ADC is IO4 in the table
.sd_cs = 38,
.sd_mosi = 39,
.sd_miso = 40,
.sd_sclk = 41,
.pcf8563_int = 15, // RTC INT is IO15 in the table
.rotation_175 = 0,
.mirror_touch = false,
};
Comment on lines 84 to 109
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for tp_int usages to understand how it's handled
rg -n 'tp_int' --type=cpp --type=h -C 4

Repository: jniebuhr/gaggimate

Length of output: 7175


🏁 Script executed:

#!/bin/bash
# Check how initTouch is called and if there are guards around tp_int usage
rg -n 'initTouch|WAKEUP_FROM_TOUCH' src/display/drivers/AmoledDisplay/Amoled_DisplayPanel.cpp -B 2 -A 2

Repository: jniebuhr/gaggimate

Length of output: 914


🏁 Script executed:

#!/bin/bash
# Search for TouchDrvFT6X36 and TouchDrvCST92xx setPins implementation
rg -n 'setPins' --type=cpp --type=h -B 2 -A 5

Repository: jniebuhr/gaggimate

Length of output: 8012


🏁 Script executed:

#!/bin/bash
# Find the touch driver header files to see setPins implementation
find . -type f -name "*TouchDrv*.h" | head -20

Repository: jniebuhr/gaggimate

Length of output: 44


🏁 Script executed:

#!/bin/bash
# Check the full initTouch function to see if there's any handling for -1 pins
sed -n '223,260p' src/display/drivers/AmoledDisplay/Amoled_DisplayPanel.cpp

Repository: jniebuhr/gaggimate

Length of output: 1321


🏁 Script executed:

#!/bin/bash
# Check if there are any guards or checks for -1 pins elsewhere in the codebase
rg -n 'tp_int.*-1|tp_int\s*==\s*-1|tp_int\s*>=\s*0|tp_int\s*<\s*0' --type=cpp --type=h -C 3

Repository: jniebuhr/gaggimate

Length of output: 589


Critical: tp_int = -1 will cause runtime failures in touch wakeup and sleep paths.

The 1.43" display has no touch interrupt pin, but the sleep/wakeup code unconditionally uses tp_int without checking for -1:

  • Line 111: pinMode(hwConfig.tp_int, INPUT) — fails with invalid pin -1
  • Line 114: digitalRead(hwConfig.tp_int) — fails with invalid pin -1
  • Line 121: esp_sleep_enable_ext1_wakeup(_BV(hwConfig.tp_int), ...)_BV(-1) causes undefined behavior (negative bit shift)

If enableTouchWakeup() is called and the device enters sleep, the WAKEUP_FROM_TOUCH case will execute these invalid operations and crash.

Additionally, initTouch() unconditionally calls setPins(hwConfig.tp_rst, hwConfig.tp_int) with -1 values, passing the risk downstream to the touch driver library.

Add guard checks (e.g., if (hwConfig.tp_int >= 0)) around all GPIO operations using tp_int in the sleep/wakeup paths, or document that enableTouchWakeup() must not be called for the 1.43" variant.

🤖 Prompt for AI Agents
In `@src/display/drivers/AmoledDisplay/pin_config.h` around lines 84 - 109, The
code uses hwConfig.tp_int (-1 for the 1.43" variant) without guards causing
invalid-pin operations; update all touch-wakeup and touch-init paths to check
tp_int >= 0 before using it: wrap calls to pinMode(hwConfig.tp_int,...),
digitalRead(hwConfig.tp_int), esp_sleep_enable_ext1_wakeup(_BV(hwConfig.tp_int),
...), and any use of _BV(hwConfig.tp_int) with an if (hwConfig.tp_int >= 0)
block, and avoid calling initTouch()/setPins(hwConfig.tp_rst, hwConfig.tp_int)
or call setPins with only valid pins (guard hwConfig.tp_rst >= 0 and
hwConfig.tp_int >= 0) so the WAKEUP_FROM_TOUCH path and enableTouchWakeup() no
longer perform operations on -1 pins.



#define CST92XX_DEVICE_ADDRESS 0x5A
#define FT3168_DEVICE_ADDRESS 0x38
#define PCF8563_DEVICE_ADDRESS 0x51
Expand Down
7 changes: 6 additions & 1 deletion src/display/drivers/AmoledDisplayDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ bool AmoledDisplayDriver::isCompatible() {
hwConfig = LILYGO_T_DISPLAY_S3_DS_HW_CONFIG;
return true;
}
ESP_LOGI("AmoledDisplayDriver", "Testing Waveshare AMOLED Display...");
ESP_LOGI("AmoledDisplayDriver", "Testing Waveshare AMOLED Display (1.75 inch)...");
if (testHw(WAVESHARE_S3_AMOLED_HW_CONFIG)) {
hwConfig = WAVESHARE_S3_AMOLED_HW_CONFIG;
return true;
}
ESP_LOGI("AmoledDisplayDriver", "Testing Waveshare AMOLED Display (1.43 inch)...");
if (testHw(WAVESHARE_S3_AMOLED_143_HW_CONFIG)) {
hwConfig = WAVESHARE_S3_AMOLED_143_HW_CONFIG;
return true;
}
return false;
}

Expand Down