diff --git a/esp-hal-common/src/peripherals/esp32c3.rs b/esp-hal-common/src/peripherals/esp32c3.rs index 4bbd50a8d8c..cf96540353a 100644 --- a/esp-hal-common/src/peripherals/esp32c3.rs +++ b/esp-hal-common/src/peripherals/esp32c3.rs @@ -52,5 +52,6 @@ mod peripherals { SYSTIMER, UART0, UART1, + USB_DEVICE, } } diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 1b9e8e3c8d6..0fa2dd501d8 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -71,5 +71,6 @@ mod peripherals { UART0, UART1, UART2, + USB_DEVICE, } } diff --git a/esp-hal-common/src/usb_serial_jtag.rs b/esp-hal-common/src/usb_serial_jtag.rs index 3350a68acaf..fbe630a197f 100644 --- a/esp-hal-common/src/usb_serial_jtag.rs +++ b/esp-hal-common/src/usb_serial_jtag.rs @@ -1,20 +1,24 @@ use core::convert::Infallible; -use crate::pac::{usb_device::RegisterBlock, USB_DEVICE}; +use crate::{ + pac::{usb_device::RegisterBlock, USB_DEVICE}, + peripheral::{Peripheral, PeripheralRef}, +}; -pub struct UsbSerialJtag { - usb_serial: T, +pub struct UsbSerialJtag<'d, T> { + usb_serial: PeripheralRef<'d, T>, } /// Custom USB serial error type type Error = Infallible; -impl UsbSerialJtag +impl<'d, T> UsbSerialJtag<'d, T> where T: Instance, { /// Create a new USB serial/JTAG instance with defaults - pub fn new(usb_serial: T) -> Self { + pub fn new(usb_serial: impl Peripheral

+ 'd) -> Self { + crate::into_ref!(usb_serial); let mut dev = Self { usb_serial }; dev.usb_serial.disable_rx_interrupts(); dev.usb_serial.disable_tx_interrupts(); @@ -22,11 +26,6 @@ where dev } - /// Return the raw interface to the underlying USB serial/JTAG instance - pub fn free(self) -> T { - self.usb_serial - } - /// Write data to the serial output in chunks of up to 64 bytes pub fn write_bytes(&mut self, data: &[u8]) -> Result<(), Error> { let reg_block = self.usb_serial.register_block(); @@ -186,14 +185,14 @@ pub trait Instance { } } -impl Instance for USB_DEVICE { +impl Instance for crate::peripherals::USB_DEVICE { #[inline(always)] fn register_block(&self) -> &RegisterBlock { self } } -impl core::fmt::Write for UsbSerialJtag +impl core::fmt::Write for UsbSerialJtag<'_, T> where T: Instance, { @@ -202,7 +201,7 @@ where } } -impl embedded_hal::serial::Read for UsbSerialJtag +impl embedded_hal::serial::Read for UsbSerialJtag<'_, T> where T: Instance, { @@ -213,7 +212,7 @@ where } } -impl embedded_hal::serial::Write for UsbSerialJtag +impl embedded_hal::serial::Write for UsbSerialJtag<'_, T> where T: Instance, {