From 0cf787265ffe9422d72e73a380919c59d095d17f Mon Sep 17 00:00:00 2001
From: Serge Bazanski <q3k@q3k.org>
Date: Tue, 18 Jul 2023 23:32:40 +0200
Subject: [PATCH] st3m/usb: disconnect PHY on init

This makes sure we don't start claiming to be a ttyACM device before the
user actually enables USB.
---
 components/st3m/st3m_usb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/components/st3m/st3m_usb.c b/components/st3m/st3m_usb.c
index 04c13e5c7b..dc4c51fb83 100644
--- a/components/st3m/st3m_usb.c
+++ b/components/st3m/st3m_usb.c
@@ -47,6 +47,7 @@ void st3m_usb_init(void) {
 	assert(_mu == NULL);
 	_mu = xSemaphoreCreateMutex();
 	assert(_mu != NULL);
+	_mode = st3m_usb_mode_kind_disabled;
 
 	_generate_serial();
 	st3m_usb_cdc_init();
@@ -57,6 +58,7 @@ void st3m_usb_init(void) {
     };
 	// TODO(q3k): set self-powered based on battery state?
     ESP_ERROR_CHECK(usb_new_phy(&phy_conf, &phy_hdl));
+    usb_phy_action(phy_hdl, USB_PHY_ACTION_HOST_FORCE_DISCONN);
 
     if (!tusb_init()) {
         ESP_LOGE(TAG, "TInyUSB init failed");
-- 
GitLab