refactor: move constants + remove code duplicate
This commit is contained in:
parent
cfa76a6672
commit
c510d908d3
28
src/lib.rs
28
src/lib.rs
|
@ -14,6 +14,10 @@ pub use types::*;
|
|||
|
||||
use types::{DPRAM_SIZE, ENDPOINTS_ALLOC_LAYOUT, ONE_MS_16_MGHZ};
|
||||
|
||||
const RESTRICT_RW_FLAG: u8 = !(1 << 5);
|
||||
const USBINT_CLEAR: u8 = 1 << 0;
|
||||
const UDINT_CLEAR: u8 = !(1 << 7 | 1 << 1);
|
||||
|
||||
impl<const L: usize> UsbBus for UsbDevice<L> {
|
||||
fn alloc_ep(
|
||||
&mut self,
|
||||
|
@ -26,7 +30,7 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
// Handle first endpoint. //
|
||||
|
||||
if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) {
|
||||
ep_addr.ok_or(UsbError::WouldBlock)
|
||||
ep_addr.ok_or(UsbError::InvalidState)
|
||||
} else {
|
||||
let address = match ep_addr {
|
||||
// If current endpoint doesn't allocated, assign ep_addr to variable. //
|
||||
|
@ -130,19 +134,15 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
}
|
||||
|
||||
fn force_reset(&self) -> UsbResult<()> {
|
||||
free(|cs| {
|
||||
let udcon = &self.usb.borrow(cs).udcon;
|
||||
|
||||
udcon.modify(|_, w| w.detach().set_bit());
|
||||
});
|
||||
let set_detach = |bit| {
|
||||
free(|cs| {
|
||||
self.usb.borrow(cs).udcon.modify(|_, w| w.detach().bit(bit));
|
||||
});
|
||||
};
|
||||
|
||||
set_detach(true);
|
||||
delay_cycles(ONE_MS_16_MGHZ);
|
||||
|
||||
free(|cs| {
|
||||
let udcon = &self.usb.borrow(cs).udcon;
|
||||
|
||||
udcon.modify(|_, w| w.detach().clear_bit());
|
||||
});
|
||||
set_detach(false);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -459,7 +459,3 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
const RESTRICT_RW_FLAG: u8 = !(1 << 5);
|
||||
const USBINT_CLEAR: u8 = 1 << 0;
|
||||
const UDINT_CLEAR: u8 = !(1 << 7 | 1 << 1);
|
||||
|
|
Loading…
Reference in New Issue