feat(endpoint): add select endpoint method

This commit is contained in:
doryan 2024-11-09 16:44:38 +04:00
parent 6eb6cef6ee
commit f44aa6459a

View File

@ -71,6 +71,26 @@ impl<const L: usize> UsbDevice<L> {
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<const L: usize> UsbBus for UsbDevice<L> {