feat(conditions): use if let ... conditions instead match

This commit is contained in:
doryan 2025-02-14 00:09:48 +04:00
parent 18a3368565
commit b1dd7eea9d

View File

@ -169,41 +169,42 @@ impl<const L: usize> UsbDevice<L> {
let usb = self.usb.borrow(cs);
let current_endpoint = self.ep_table[endpoint_index];
match self.select_endpoint(cs, endpoint_index) {
Ok(_) => {
// Enable endpoint. //
let select_endpoint_result = self.select_endpoint(cs, endpoint_index);
usb.ueconx.modify(|_, w| w.epen().set_bit());
usb.uecfg1x.modify(|_, w| w.alloc().clear_bit());
if select_endpoint_result.is_err() {
select_endpoint_result
} else {
// Enable endpoint. //
// Set markered endpoint parameters to uecfg0x/1x register. //
usb.ueconx.modify(|_, w| w.epen().set_bit());
usb.uecfg1x.modify(|_, w| w.alloc().clear_bit());
usb.uecfg0x.modify(|_, w| {
w.epdir()
.bit(current_endpoint.ep_dir)
.eptype()
.bits(current_endpoint.ep_type)
});
// Set markered endpoint parameters to uecfg0x/1x register. //
usb.uecfg1x.modify(|_, w| {
w.epbk()
.bits(0)
.epsize()
.bits(current_endpoint.size)
.alloc()
.set_bit()
});
usb.uecfg0x.modify(|_, w| {
w.epdir()
.bit(current_endpoint.ep_dir)
.eptype()
.bits(current_endpoint.ep_type)
});
if usb.uesta0x.read().cfgok().bit_is_clear() {
Err(UsbError::EndpointMemoryOverflow)
} else {
usb.ueienx
.modify(|_, w| w.rxoute().set_bit().rxstpe().set_bit());
usb.uecfg1x.modify(|_, w| {
w.epbk()
.bits(0)
.epsize()
.bits(current_endpoint.size)
.alloc()
.set_bit()
});
Ok(())
}
if usb.uesta0x.read().cfgok().bit_is_clear() {
Err(UsbError::EndpointMemoryOverflow)
} else {
usb.ueienx
.modify(|_, w| w.rxoute().set_bit().rxstpe().set_bit());
select_endpoint_result
}
Err(exception) => Err(exception),
}
}
}