From 1721de0b76f5c2d61db02ac1b9e4e349dfcaf437 Mon Sep 17 00:00:00 2001 From: Christian Baars Date: Wed, 10 Apr 2024 11:31:18 +0200 Subject: [PATCH] use new API for check of USB cable connection (#21135) --- tasmota/tasmota.ino | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 85e6a1231..c4e8ff09d 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -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