Compare commits
3 Commits
test
...
29e5edde8a
| Author | SHA1 | Date | |
|---|---|---|---|
| 29e5edde8a | |||
| 137fcc78e5 | |||
| 5ac1a07c6b |
15
src/lib.rs
15
src/lib.rs
@@ -38,16 +38,14 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||||||
|
|
||||||
// If ep_aadr not provided, or current endpoint is allocated, try to find next free endpoint, otherwise return UsbError. //
|
// If ep_aadr not provided, or current endpoint is allocated, try to find next free endpoint, otherwise return UsbError. //
|
||||||
_ => {
|
_ => {
|
||||||
let index = self
|
let index = self.ep_table[1..]
|
||||||
.ep_table
|
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.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)?
|
.map(|(index, _)| index)
|
||||||
.0;
|
.ok_or(UsbError::EndpointOverflow)?;
|
||||||
|
|
||||||
EndpointAddress::from_parts(index, ep_dir)
|
EndpointAddress::from_parts(index, ep_dir)
|
||||||
}
|
}
|
||||||
@@ -190,6 +188,7 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||||||
|
|
||||||
if usb.usbcon.read().frzclk().bit_is_clear() {
|
if usb.usbcon.read().frzclk().bit_is_clear() {
|
||||||
let (mut ep_out, mut ep_in_complete, mut ep_setup) = (0u16, 0u16, 0u16);
|
let (mut ep_out, mut ep_in_complete, mut ep_setup) = (0u16, 0u16, 0u16);
|
||||||
|
let pending_ins = self.pending_ins.borrow(cs);
|
||||||
|
|
||||||
for (ep_index, _ep) in self.allocated_endpoints() {
|
for (ep_index, _ep) in self.allocated_endpoints() {
|
||||||
if self.select_endpoint(cs, ep_index).is_err() {
|
if self.select_endpoint(cs, ep_index).is_err() {
|
||||||
@@ -204,8 +203,9 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||||||
ep_setup |= 1 << ep_index;
|
ep_setup |= 1 << ep_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ueintx.txini().bit_is_set() {
|
if pending_ins.get() & (1 << ep_index) != 0 && ueintx.txini().bit_is_set() {
|
||||||
ep_in_complete |= 1 << ep_index;
|
ep_in_complete |= 1 << ep_index;
|
||||||
|
pending_ins.set(pending_ins.get() & !(1 << ep_index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,6 +450,9 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let pending_ins = self.pending_ins.borrow(cs);
|
||||||
|
pending_ins.set(pending_ins.get() | 1 << ep_addr.index());
|
||||||
|
|
||||||
Ok(buf.len())
|
Ok(buf.len())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use core::cell::Cell;
|
||||||
|
|
||||||
use avr_device::{
|
use avr_device::{
|
||||||
atmega32u4::{PLL, USB_DEVICE},
|
atmega32u4::{PLL, USB_DEVICE},
|
||||||
interrupt::{CriticalSection, Mutex},
|
interrupt::{CriticalSection, Mutex},
|
||||||
@@ -6,7 +8,7 @@ use usb_device::{bus::UsbBusAllocator, endpoint::EndpointType, UsbDirection, Usb
|
|||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[derive(Default, Copy, Clone)]
|
#[derive(Default, Copy, Clone)]
|
||||||
pub struct USBEndpoint {
|
pub(crate) struct USBEndpoint {
|
||||||
pub(crate) is_allocated: bool,
|
pub(crate) is_allocated: bool,
|
||||||
pub(crate) size: u8,
|
pub(crate) size: u8,
|
||||||
pub(crate) ep_type: u8,
|
pub(crate) ep_type: u8,
|
||||||
@@ -70,6 +72,7 @@ pub struct UsbDevice<const L: usize> {
|
|||||||
pub(crate) pll: Mutex<PLL>,
|
pub(crate) pll: Mutex<PLL>,
|
||||||
pub(crate) usb: Mutex<USB_DEVICE>,
|
pub(crate) usb: Mutex<USB_DEVICE>,
|
||||||
pub(crate) ep_table: [USBEndpoint; L],
|
pub(crate) ep_table: [USBEndpoint; L],
|
||||||
|
pub(crate) pending_ins: Mutex<Cell<u8>>,
|
||||||
pub(crate) dpram_already_used: u16,
|
pub(crate) dpram_already_used: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +84,17 @@ pub(crate) const ONE_MS_16_MGHZ: u32 = 16000;
|
|||||||
impl<const L: usize> UsbDevice<L> {
|
impl<const L: usize> UsbDevice<L> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator<Self> {
|
pub fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator<Self> {
|
||||||
UsbBusAllocator::new(Self {
|
if L > 1 {
|
||||||
pll: Mutex::new(pll),
|
UsbBusAllocator::new(Self {
|
||||||
usb: Mutex::new(usb),
|
pll: Mutex::new(pll),
|
||||||
ep_table: [USBEndpoint::default(); L],
|
usb: Mutex::new(usb),
|
||||||
dpram_already_used: 0,
|
ep_table: [USBEndpoint::default(); L],
|
||||||
})
|
pending_ins: Mutex::new(Cell::new(0u8)),
|
||||||
|
dpram_already_used: 0,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
panic!("Endpoint table cannot be with length <= 1")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@@ -132,10 +140,6 @@ impl<const L: usize> UsbDevice<L> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ep_table(&self) -> &[USBEndpoint] {
|
|
||||||
&self.ep_table
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn configure_endpoint(
|
pub(crate) fn configure_endpoint(
|
||||||
&self,
|
&self,
|
||||||
cs: CriticalSection<'_>,
|
cs: CriticalSection<'_>,
|
||||||
|
|||||||
Reference in New Issue
Block a user