USB device-mode support (#613)

This commit is contained in:
Shadowtrance
2026-08-13 05:29:35 +10:00
committed by GitHub
parent 37c507544b
commit cc8be3faef
94 changed files with 3466 additions and 399 deletions
@@ -43,6 +43,21 @@ extern Driver esp32_usbhost_hid_driver;
extern Driver esp32_usbhost_midi_driver;
extern Driver esp32_usbhost_msc_driver;
#endif
#if SOC_USB_OTG_SUPPORTED && (CONFIG_TINYUSB_HID_COUNT || CONFIG_TINYUSB_MSC_ENABLED || CONFIG_TINYUSB_MIDI_COUNT || CONFIG_TINYUSB_CDC_ENABLED)
extern Driver esp32_usb_device_controller_driver;
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_HID_COUNT
extern Driver esp32_usb_hid_device_driver;
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_MSC_ENABLED
extern Driver esp32_usb_msc_device_driver;
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_MIDI_COUNT
extern Driver esp32_usb_midi_device_driver;
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_CDC_ENABLED
extern Driver esp32_usb_cdc_device_driver;
#endif
static error_t start() {
/* We crash when construct fails, because if a single driver fails to construct,
@@ -78,6 +93,25 @@ static error_t start() {
check(driver_construct_add(&esp32_usbhost_hid_driver) == ERROR_NONE);
check(driver_construct_add(&esp32_usbhost_midi_driver) == ERROR_NONE);
check(driver_construct_add(&esp32_usbhost_msc_driver) == ERROR_NONE);
#endif
// usbdevice0 and its children (usbdevicehid0, usbdevicemsc0, ...) are declared per-board in
// .dts, same pattern as usbhost0 above - the devicetree compiler constructs/adds/starts their
// Device instances and wires parent/child relationships. Only driver registration happens
// here.
#if SOC_USB_OTG_SUPPORTED && (CONFIG_TINYUSB_HID_COUNT || CONFIG_TINYUSB_MSC_ENABLED || CONFIG_TINYUSB_MIDI_COUNT || CONFIG_TINYUSB_CDC_ENABLED)
check(driver_construct_add(&esp32_usb_device_controller_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_HID_COUNT
check(driver_construct_add(&esp32_usb_hid_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_MSC_ENABLED
check(driver_construct_add(&esp32_usb_msc_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_MIDI_COUNT
check(driver_construct_add(&esp32_usb_midi_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_CDC_ENABLED
check(driver_construct_add(&esp32_usb_cdc_device_driver) == ERROR_NONE);
#endif
return ERROR_NONE;
}
@@ -89,6 +123,21 @@ static error_t stop() {
check(driver_remove_destruct(&esp32_wifi_pinned_driver) == ERROR_NONE);
check(driver_remove_destruct(&esp32_wifi_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_CDC_ENABLED
check(driver_remove_destruct(&esp32_usb_cdc_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_MIDI_COUNT
check(driver_remove_destruct(&esp32_usb_midi_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_MSC_ENABLED
check(driver_remove_destruct(&esp32_usb_msc_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && CONFIG_TINYUSB_HID_COUNT
check(driver_remove_destruct(&esp32_usb_hid_device_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED && (CONFIG_TINYUSB_HID_COUNT || CONFIG_TINYUSB_MSC_ENABLED || CONFIG_TINYUSB_MIDI_COUNT || CONFIG_TINYUSB_CDC_ENABLED)
check(driver_remove_destruct(&esp32_usb_device_controller_driver) == ERROR_NONE);
#endif
#if SOC_USB_OTG_SUPPORTED
check(driver_remove_destruct(&esp32_usbhost_msc_driver) == ERROR_NONE);
check(driver_remove_destruct(&esp32_usbhost_midi_driver) == ERROR_NONE);