MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / detectVariant

Function detectVariant

Devices/m5stack-tab5/Source/devices/Detect.cpp:13–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11static const auto LOGGER = tt::Logger("Tab5Detect");
12
13Tab5Variant detectVariant() {
14 // Allow time for touch IC to fully boot after expander reset in initBoot().
15 // 100ms is enough for I2C ACK (probe) but cold power-on needs ~300ms before
16 // register reads (read_fw_info) succeed reliably.
17 vTaskDelay(pdMS_TO_TICKS(300));
18
19 auto* i2c0 = device_find_by_name("i2c0");
20 check(i2c0);
21
22 constexpr auto PROBE_TIMEOUT = pdMS_TO_TICKS(50);
23
24 for (int attempt = 0; attempt < 3; ++attempt) {
25 // GT911 address depends on INT pin state during reset:
26 // GPIO 23 has a pull-up resistor to 3V3, so INT is high at reset → GT911 uses 0x5D (primary)
27 // It may also appear at 0x14 (backup) if the pin happened to be driven low
28 if (i2c_controller_has_device_at_address(i2c0, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS, PROBE_TIMEOUT) == ERROR_NONE ||
29 i2c_controller_has_device_at_address(i2c0, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP, PROBE_TIMEOUT) == ERROR_NONE) {
30 LOGGER.info("Detected GT911 touch — using ILI9881C display");
31 return Tab5Variant::Ili9881c_Gt911;
32 }
33
34 // Probe for ST7123 touch (new variant)
35 if (i2c_controller_has_device_at_address(i2c0, ESP_LCD_TOUCH_IO_I2C_ST7123_ADDRESS, PROBE_TIMEOUT) == ERROR_NONE) {
36 LOGGER.info("Detected ST7123 touch — using ST7123 display");
37 return Tab5Variant::St7123;
38 }
39
40 vTaskDelay(pdMS_TO_TICKS(100));
41 }
42
43 LOGGER.warn("No known touch controller detected, defaulting to ST7123");
44 return Tab5Variant::St7123;
45}

Callers 1

createDisplayFunction · 0.85

Calls 5

device_find_by_nameFunction · 0.85
infoMethod · 0.80
warnMethod · 0.80
checkFunction · 0.50

Tested by

no test coverage detected