Merge first (maybe) stable version usb-avr for atmega32u4/atmega16u4 #1

Merged
doryan merged 9 commits from test into main 2025-05-18 22:52:53 +03:00
Showing only changes of commit c510d908d3 - Show all commits

View File

@ -14,6 +14,10 @@ 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};
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> { impl<const L: usize> UsbBus for UsbDevice<L> {
fn alloc_ep( fn alloc_ep(
&mut self, &mut self,
@ -26,7 +30,7 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
// Handle first endpoint. // // Handle first endpoint. //
if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) { if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) {
ep_addr.ok_or(UsbError::WouldBlock) ep_addr.ok_or(UsbError::InvalidState)
} else { } else {
let address = match ep_addr { let address = match ep_addr {
// If current endpoint doesn't allocated, assign ep_addr to variable. // // 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<()> { fn force_reset(&self) -> UsbResult<()> {
let set_detach = |bit| {
free(|cs| { free(|cs| {
let udcon = &self.usb.borrow(cs).udcon; self.usb.borrow(cs).udcon.modify(|_, w| w.detach().bit(bit));
udcon.modify(|_, w| w.detach().set_bit());
}); });
};
set_detach(true);
delay_cycles(ONE_MS_16_MGHZ); delay_cycles(ONE_MS_16_MGHZ);
set_detach(false);
free(|cs| {
let udcon = &self.usb.borrow(cs).udcon;
udcon.modify(|_, w| w.detach().clear_bit());
});
Ok(()) 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);