From f44aa6459a03844203c2a1cf1121a7b84e74a851 Mon Sep 17 00:00:00 2001 From: doryan Date: Sat, 9 Nov 2024 16:44:38 +0400 Subject: [PATCH] feat(endpoint): add select endpoint method --- src/types/usb_device.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/types/usb_device.rs b/src/types/usb_device.rs index 0e2dab5..78b4dae 100644 --- a/src/types/usb_device.rs +++ b/src/types/usb_device.rs @@ -71,6 +71,26 @@ impl UsbDevice { dpram_already_used: 0, } } + pub fn select_endpoint( + &mut self, + cs: CriticalSection<'_>, + endpoint_index: usize, + ) -> Result<(), UsbError> { + let usb = self.usb.borrow(cs); + let endpoint_index = endpoint_index as u8; + + if endpoint_index > 6 { + return Err(UsbError::InvalidEndpoint); + } + + usb.uenum.write(|w| w.bits(endpoint_index)); + + if usb.uenum.read().bits() != endpoint_index { + return Err(UsbError::InvalidEndpoint); + } + + Ok(()) + } } impl UsbBus for UsbDevice {