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 {