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