commited for clippy fix
This commit is contained in:
parent
90708794db
commit
9b4f758045
|
@ -3,7 +3,6 @@ name = "usb_avr"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
[dependencies]
|
||||
panic-halt = "0.2.0"
|
||||
ufmt = "0.2.0"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2024-03-22"
|
||||
channel = "nightly-2024-06-13"
|
||||
components = [ "rust-src" ]
|
||||
profile = "complete"
|
||||
|
|
68
src/lib.rs
68
src/lib.rs
|
@ -1,6 +1,6 @@
|
|||
#![no_std]
|
||||
|
||||
use core::{cmp::max, u8};
|
||||
use core::cmp::max;
|
||||
|
||||
use avr_device::{asm::delay_cycles, interrupt::free};
|
||||
use usb_device::{
|
||||
|
@ -10,7 +10,7 @@ use usb_device::{
|
|||
};
|
||||
|
||||
mod types;
|
||||
pub use types::UsbDevice;
|
||||
pub use types::*;
|
||||
|
||||
use types::{DPRAM_SIZE, ENDPOINTS_ALLOC_LAYOUT, ONE_MS_16_MGHZ};
|
||||
|
||||
|
@ -24,6 +24,7 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
_interval: u8,
|
||||
) -> UsbResult<EndpointAddress> {
|
||||
// Handle first endpoint. //
|
||||
free(|_cs| {
|
||||
if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) {
|
||||
Ok(ep_addr.unwrap())
|
||||
} else {
|
||||
|
@ -39,7 +40,8 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
.enumerate()
|
||||
.skip(1)
|
||||
.find(|(index, ep)| {
|
||||
!ep.is_allocated && max_packet_size <= ENDPOINTS_ALLOC_LAYOUT[*index]
|
||||
!ep.is_allocated
|
||||
&& max_packet_size <= ENDPOINTS_ALLOC_LAYOUT[*index]
|
||||
})
|
||||
.ok_or(UsbError::EndpointOverflow)?
|
||||
.0;
|
||||
|
@ -75,6 +77,7 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
Ok(address)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn enable(&mut self) {
|
||||
|
@ -118,7 +121,8 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
|
||||
// Set high speed and attach the USB. //
|
||||
|
||||
usb.udcon.modify(|_, w| w.detach().clear_bit());
|
||||
usb.udcon
|
||||
.modify(|_, w| w.detach().clear_bit().lsm().clear_bit());
|
||||
|
||||
// Interrupts. //
|
||||
|
||||
|
@ -157,7 +161,9 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
let (udint, udien, usbint) = (usb.udint.read(), usb.udien.read(), usb.usbint.read());
|
||||
|
||||
if usbint.vbusti().bit_is_set() {
|
||||
usb.usbint.write(|w| w.vbusti().clear_bit());
|
||||
usb.usbint.write(|w|
|
||||
// unsafe { w.bits(0x01) }
|
||||
w.vbusti().clear_bit());
|
||||
if usb.usbsta.read().vbus().bit_is_set() {
|
||||
return PollResult::Resume;
|
||||
} else {
|
||||
|
@ -178,7 +184,9 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
}
|
||||
|
||||
if udint.sofi().bit_is_set() {
|
||||
usb.udint.write(|w| w.sofi().clear_bit());
|
||||
usb.udint.write(|w|
|
||||
// unsafe { w.bits(0x7d) }
|
||||
w.sofi().clear_bit());
|
||||
}
|
||||
|
||||
if usb.usbcon.read().frzclk().bit_is_clear() {
|
||||
|
@ -241,15 +249,19 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
*byte = usb.uedatx.read().bits();
|
||||
}
|
||||
|
||||
usb.ueintx
|
||||
.write(|w| w.rxouti().clear_bit().rxstpi().clear_bit());
|
||||
usb.ueintx.write(|w| {
|
||||
/* unsafe { w.bits(0xdf) } */
|
||||
w.rxouti().clear_bit().rxstpi().clear_bit()
|
||||
});
|
||||
|
||||
Ok(buf_size)
|
||||
} else {
|
||||
if usb.ueintx.read().rxouti().bit_is_clear() {
|
||||
return Err(UsbError::WouldBlock);
|
||||
}
|
||||
usb.ueintx.write(|w| w.rxouti().clear_bit());
|
||||
usb.ueintx.write(|w|
|
||||
// unsafe { w.bits(0xdf) }
|
||||
w.rxouti().clear_bit());
|
||||
|
||||
let mut bytes_read = 0;
|
||||
for slot in buf {
|
||||
|
@ -264,7 +276,9 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
return Err(UsbError::BufferOverflow);
|
||||
}
|
||||
|
||||
usb.ueintx.write(|w| w.fifocon().clear_bit());
|
||||
usb.ueintx.write(|w|
|
||||
// unsafe { w.bits(0xdf) }
|
||||
w.fifocon().clear_bit());
|
||||
Ok(bytes_read)
|
||||
}
|
||||
}
|
||||
|
@ -283,8 +297,10 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
|
||||
// Clear resume informations. //
|
||||
|
||||
usb.udint
|
||||
.write(|w| w.wakeupi().clear_bit().suspi().clear_bit());
|
||||
usb.udint.write(|w| {
|
||||
// unsafe { w.bits(0x7d) }
|
||||
w.wakeupi().clear_bit().suspi().clear_bit()
|
||||
});
|
||||
|
||||
usb.udien
|
||||
.modify(|_, w| w.wakeupe().clear_bit().suspe().set_bit());
|
||||
|
@ -306,8 +322,10 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
|
||||
usb.usbcon.modify(|_, w| w.frzclk().clear_bit());
|
||||
|
||||
usb.udint
|
||||
.write(|w| w.wakeupi().clear_bit().suspi().clear_bit());
|
||||
usb.udint.write(|w| {
|
||||
// unsafe { w.bits(0x7d) }
|
||||
w.wakeupi().clear_bit().suspi().clear_bit()
|
||||
});
|
||||
|
||||
usb.udien
|
||||
.modify(|_, w| w.wakeupe().clear_bit().suspe().set_bit());
|
||||
|
@ -345,8 +363,10 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
free(|cs| {
|
||||
let (usb, pll) = (self.usb.borrow(cs), self.pll.borrow(cs));
|
||||
|
||||
usb.udint
|
||||
.write(|w| w.wakeupi().clear_bit().suspi().clear_bit());
|
||||
usb.udint.write(|w| {
|
||||
// unsafe { w.bits(0x7d) }
|
||||
w.wakeupi().clear_bit().suspi().clear_bit()
|
||||
});
|
||||
|
||||
// Suspend. //
|
||||
|
||||
|
@ -387,13 +407,17 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
usb.uedatx.write(|w| w.bits(byte));
|
||||
}
|
||||
|
||||
usb.ueintx.write(|w| w.txini().clear_bit());
|
||||
usb.ueintx.write(|w|
|
||||
// unsafe { w.bits(0xdf) }
|
||||
w.txini().clear_bit());
|
||||
} else {
|
||||
if usb.ueintx.read().txini().bit_is_clear() {
|
||||
return Err(UsbError::WouldBlock);
|
||||
}
|
||||
usb.ueintx
|
||||
.write(|w| w.txini().clear_bit().rxouti().clear_bit());
|
||||
usb.ueintx.write(|w| {
|
||||
// unsafe { w.bits(0xdf) }
|
||||
w.txini().clear_bit().rxouti().clear_bit()
|
||||
});
|
||||
|
||||
for &byte in buf {
|
||||
if usb.ueintx.read().rwal().bit_is_set() {
|
||||
|
@ -403,8 +427,10 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
}
|
||||
}
|
||||
|
||||
usb.ueintx
|
||||
.write(|w| w.txini().clear_bit().fifocon().clear_bit());
|
||||
usb.ueintx.write(|w| {
|
||||
// unsafe { w.bits(0xdf) }
|
||||
w.rxouti().clear_bit().fifocon().clear_bit()
|
||||
});
|
||||
}
|
||||
|
||||
let pending_ins = self.pending_ins.borrow(cs);
|
||||
|
|
Loading…
Reference in New Issue