use new API for check of USB cable connection (#21135)

This commit is contained in:
Christian Baars 2024-04-10 11:31:18 +02:00 committed by GitHub
parent 54e4aba750
commit 1721de0b76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 8 deletions

View File

@ -528,16 +528,11 @@ void setup(void) {
bool is_connected_to_USB = false;
#if SOC_USB_SERIAL_JTAG_SUPPORTED // Not S2
rtc_clk_bbpll_add_consumer(); // Maybe unneeded
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SOF);
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF);
// First check if USB cable is connected - maybe add a new SetOption to prevent this
for (uint32_t i = 0; i < 1000; i++) { // Allow the host to send at least one SOF packet, 1ms should be enough but let's be very conservative here - maybe unneeded
is_connected_to_USB = ((usb_serial_jtag_ll_get_intraw_mask() & USB_SERIAL_JTAG_INTR_SOF) != 0);
for (uint32_t i = 0; i < 5; i++) { // wait up to 250 ms - maybe a shorter time is enough
is_connected_to_USB = usb_serial_jtag_is_connected();
if (is_connected_to_USB) { break; }
delay(1);
delay(50);
}
rtc_clk_bbpll_remove_consumer();
#else
is_connected_to_USB = true; // S2
#endif // SOC_USB_SERIAL_JTAG_SUPPORTED