#pragma once // The Elecrow CrowPanel 7.0" wires its GT911 touch I2C to GPIO19 and GPIO20, the ESP32-S3's USB D- and D+. The ROM // leaves the USB_SERIAL_JTAG PHY on those pads, and ESP-IDF's I2C driver cannot take them back: the bus reads as // "I2C software timeout" and the touch never answers (esphome/esphome#15356, ESPHome 2026.3+). release_usb_pads() lets // the pads go: the PHY drops them, and both become plain GPIOs with their pull-ups, as the I2C driver expects to find // them. The board's USB-C port is a CH340 on UART0, so nothing is lost. // // It runs three times, because three things hand the pads back to the PHY: once before any ESPHome component (a // static constructor at priority 101, after the ROM), once in the board's BOOT_TOUCH hook (the core's on_boot at // priority -100, after Wi-Fi started: the Wi-Fi PHY library keeps the USB PHY unless CONFIG_ESP_PHY_ENABLE_USB is // off, which the board file sets as well), and from a one-second interval that reads the pad bit and releases the pads // again when anything took them (ESPHome's logger keeps the USB-Serial-JTAG secondary console, and a Wi-Fi restart // re-enables the PHY). The interval logs once per event, so the log says whether it ever had to. // // ESPHome includes every header of the component in every build, so the code is behind a flag only the Elecrow's board // file sets (`-DESP_SCREENS_FREE_USB_PADS=1`, packages/boards/elecrow-crowpanel7.yaml): the CYD has no such peripheral, // and the Guition, an ESP32-S3 too, keeps its USB. #if defined(ESP_SCREENS_FREE_USB_PADS) && ESP_SCREENS_FREE_USB_PADS #include "hal/usb_serial_jtag_ll.h" #include "soc/io_mux_reg.h" #include "soc/usb_serial_jtag_reg.h" namespace elecrow { // True while the USB PHY holds GPIO19 and GPIO20. inline bool usb_pads_taken() { return REG_GET_BIT(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE) != 0; } inline void release_usb_pads() { usb_serial_jtag_ll_phy_enable_pad(false); CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP); for (uint32_t reg : {IO_MUX_GPIO19_REG, IO_MUX_GPIO20_REG}) { PIN_FUNC_SELECT(reg, PIN_FUNC_GPIO); PIN_INPUT_ENABLE(reg); REG_SET_BIT(reg, FUN_PU); REG_CLR_BIT(reg, FUN_PD); } } static __attribute__((constructor(101))) void release_usb_pads_early() { release_usb_pads(); } } // namespace elecrow #endif