From 76afaa369211d2d634795981f4713d20193e041f Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 13 Dec 2022 17:13:47 +0100 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Peripheral?= =?UTF-8?q?Ref=20usb=20serial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp-hal-common/src/usb_serial_jtag.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) 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, { From 7d4cfa2070273ffa7ee23a392a1d8b3d501ed294 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 13 Dec 2022 17:17:24 +0100 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20impl=20Per?= =?UTF-8?q?ipheral=20for=20USB=5FDEVICE,=20USB0,=20and=20USB=5FWARP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp-hal-common/src/peripherals/esp32c3.rs | 1 + esp-hal-common/src/peripherals/esp32s2.rs | 2 ++ esp-hal-common/src/peripherals/esp32s3.rs | 3 +++ 3 files changed, 6 insertions(+) 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/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs index 3befeb7e410..e9288ad6d07 100644 --- a/esp-hal-common/src/peripherals/esp32s2.rs +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -60,5 +60,7 @@ mod peripherals { SYSTIMER, UART0, UART1, + USB0, + USB_WRAP, } } diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 1b9e8e3c8d6..155e4324abb 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -71,5 +71,8 @@ mod peripherals { UART0, UART1, UART2, + USB0, + USB_DEVICE, + USB_WRAP, } } From 0774018df51a83608f235be8570f978ca7afd49c Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 13 Dec 2022 17:19:11 +0100 Subject: [PATCH 3/3] =?UTF-8?q?revert:=20=E2=8F=AA=EF=B8=8F=20impl=20Perip?= =?UTF-8?q?heral=20only=20for=20USB=5FDEVICE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp-hal-common/src/peripherals/esp32s2.rs | 2 -- esp-hal-common/src/peripherals/esp32s3.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/esp-hal-common/src/peripherals/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs index e9288ad6d07..3befeb7e410 100644 --- a/esp-hal-common/src/peripherals/esp32s2.rs +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -60,7 +60,5 @@ mod peripherals { SYSTIMER, UART0, UART1, - USB0, - USB_WRAP, } } diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 155e4324abb..0fa2dd501d8 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -71,8 +71,6 @@ mod peripherals { UART0, UART1, UART2, - USB0, USB_DEVICE, - USB_WRAP, } }