usb: unify companion + repeater CDC ACM init, drop boot waits

Single ZephyrUSBCDC module owns the usbd context, 1200-baud DFU
detection, and DTR transitions for both roles. The boot banner
now blocks on a k_event signalled by the usbd_msg_callback when
DTR transitions high — host attached → wakes immediately; no host
→ bounded timeout (2 s repeater, 1 s companion). Replaces the
fixed k_sleep delays in both mains.

Deletes the companion's 10 s DTR-polling work — line state changes
arrive as events now, same callback handles disconnect (resets V3
parser, flips active_iface) and DFU touch (reboots to bootloader).

Side effect: prod companion no longer enumerates a phantom CDC ACM
port (CONFIG_LOG=n skips the whole stack instead of auto-initing
an unused device).
This commit is contained in:
liquidraver
2026-05-27 09:04:32 +02:00
parent 99279fd9fa
commit f06c472e87
10 changed files with 363 additions and 317 deletions
+10 -2
View File
@@ -35,6 +35,7 @@ LOG_MODULE_REGISTER(zephcore_main, CONFIG_ZEPHCORE_MAIN_LOG_LEVEL);
#if IS_ENABLED(CONFIG_LOG)
#include <ZephyrCompanionUSB.h>
#include <ZephyrUSBCDC.h>
#endif
#if IS_ENABLED(CONFIG_ZEPHCORE_UI_DESIGN_JOYSTICK)
@@ -525,8 +526,15 @@ int main(void)
/* Clear any stale bootloader magic from previous sessions */
zephyr_board.clearBootloaderMagic();
/* Brief settle — deferred logging will catch up once USB CDC enumerates */
k_sleep(K_MSEC(100));
/* USB CDC init up front so the host can enumerate, then block until the
* host opens the port (DTR-high) — event-driven via the shared usbd
* message callback. Unplugged → 1 s timeout, banner is buffered for any
* later attach. CONFIG_LOG=n prod builds skip the whole stack. */
#if IS_ENABLED(CONFIG_LOG) && DT_HAS_COMPAT_STATUS_OKAY(zephyr_cdc_acm_uart) && \
!IS_ENABLED(CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT)
zephcore_usbd_init();
zephcore_usbd_wait_dtr(1000);
#endif
LOG_INF("=== ZephCore starting ===");
/* Log reset reason so we can diagnose random reboots */