feat(endpoint): add configure endpoint method

This commit is contained in:
doryan 2024-11-09 16:45:39 +04:00
parent f44aa6459a
commit 8e3517eafe

View File

@ -91,6 +91,51 @@ impl<const L: usize> UsbDevice<L> {
Ok(()) Ok(())
} }
pub fn configure_endpoint(
&mut self,
cs: CriticalSection<'_>,
endpoint_index: usize,
) -> Result<(), UsbError> {
match self.select_endpoint(cs, endpoint_index) {
Ok(_) => {
let usb = self.usb.borrow(cs);
let current_endpoint = self.ep_table[endpoint_index];
// Clear interrupt. //
usb.udint.modify(|_, w| w.eorsti().clear_bit());
// Enable endpoint. //
usb.ueconx.modify(|_, w| w.epen().set_bit());
// Set markered endpoint parameters to uecfg0x/1x register. //
usb.uecfg0x.modify(|_, w| {
w.epdir()
.bit(current_endpoint.ep_dir)
.eptype()
.bits(current_endpoint.ep_type)
});
usb.uecfg1x.modify(|_, w| {
w.epbk()
.bits(current_endpoint.banks)
.epsize()
.bits(current_endpoint.size)
.alloc()
.bit(current_endpoint.is_allocated)
});
if !usb.uesta0x.read().cfgok().bit() {
Err(UsbError::EndpointOverflow)
} else {
Ok(())
}
}
Err(exception) => Err(exception),
}
}
} }
impl<const L: usize> UsbBus for UsbDevice<L> { impl<const L: usize> UsbBus for UsbDevice<L> {