fix(const): use mask as constant value instead magic number

This commit is contained in:
doryan 2025-02-14 00:10:41 +04:00
parent b1dd7eea9d
commit 7c3fcdabcc

View File

@ -84,6 +84,8 @@ pub(crate) const ONE_MS_16_MGHZ: u32 = 16000;
const UDINT_BYTE: u8 = 0x7d; const UDINT_BYTE: u8 = 0x7d;
const USBINT_BYTE: u8 = 0x01; const USBINT_BYTE: u8 = 0x01;
const UEINTX_BYTE: u8 = 0xdf; const UEINTX_BYTE: u8 = 0xdf;
const UENUM_MASK: u8 = 0b111;
pub(crate) trait InterruptCleaner { pub(crate) trait InterruptCleaner {
fn clear_interrupts(&mut self) -> &mut Self; fn clear_interrupts(&mut self) -> &mut Self;
} }
@ -142,9 +144,8 @@ impl<const L: usize> UsbDevice<L> {
endpoint_index: usize, endpoint_index: usize,
) -> Result<(), UsbError> { ) -> Result<(), UsbError> {
let usb = self.usb.borrow(cs); let usb = self.usb.borrow(cs);
let endpoint_index = endpoint_index as u8;
if endpoint_index >= 7 { if endpoint_index >= MAX_ENDPOINTS {
return Err(UsbError::InvalidEndpoint); return Err(UsbError::InvalidEndpoint);
} }
@ -152,9 +153,9 @@ impl<const L: usize> UsbDevice<L> {
return Err(UsbError::InvalidState); return Err(UsbError::InvalidState);
} }
usb.uenum.write(|w| w.bits(endpoint_index)); usb.uenum.write(|w| w.bits(endpoint_index as u8));
if usb.uenum.read().bits() & 7 /* 0b111 */ != endpoint_index { if usb.uenum.read().bits() & UENUM_MASK != endpoint_index as u8 {
return Err(UsbError::InvalidEndpoint); return Err(UsbError::InvalidEndpoint);
} }