Files
Xandrossian a3ef7f09a1
CI / checks (push) Waiting to run
CI / firmware (add-on) (push) Blocked by required conditions
CI / firmware (min_version) (push) Blocked by required conditions
Keep the Elecrow's touch bus free of the USB PHY after Wi-Fi starts (0.2.94, firmware 0.2.80)
The GT911 of the CrowPanel 7.0" sits on GPIO 19 and 20, the ESP32-S3's USB pins. Firmware 0.2.79 freed them once, in a
static constructor; the Wi-Fi PHY library then kept the USB PHY on (CONFIG_ESP_PHY_ENABLE_USB, on by default on an
ESP32-S3) and the touch went quiet once Wi-Fi came up. The board file turns that option off, frees the pins again in
BOOT_TOUCH after Wi-Fi started, and a one-second watchdog frees them whenever anything takes them, with a log line.
2026-09-21 12:05:28 -07:00

42 lines
2.4 KiB
C++

#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