From b1dd7eea9d81c2bb14c5d4e4b9be7d8b6b1a9a38 Mon Sep 17 00:00:00 2001 From: doryan Date: Fri, 14 Feb 2025 00:09:48 +0400 Subject: [PATCH] feat(conditions): use if let ... conditions instead match --- src/types/usb_device.rs | 57 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/types/usb_device.rs b/src/types/usb_device.rs index de2cef9..8db5d29 100644 --- a/src/types/usb_device.rs +++ b/src/types/usb_device.rs @@ -169,41 +169,42 @@ impl UsbDevice { 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), } } }