fix
This commit is contained in:
parent
7436a78885
commit
16812fe119
19
src/lib.rs
19
src/lib.rs
|
@ -10,7 +10,9 @@ use usb_device::{
|
|||
};
|
||||
|
||||
mod types;
|
||||
use types::{UsbDevice, DPRAM_SIZE, ENDPOINTS_ALLOC_LAYOUT};
|
||||
pub use types::UsbDevice;
|
||||
|
||||
use types::{DPRAM_SIZE, ENDPOINTS_ALLOC_LAYOUT};
|
||||
|
||||
impl<const L: usize> UsbBus for UsbDevice<L> {
|
||||
fn alloc_ep(
|
||||
|
@ -104,6 +106,10 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
usb.usbcon
|
||||
.modify(|_, w| w.frzclk().clear_bit().otgpade().set_bit());
|
||||
|
||||
self.allocated_endpoints().for_each(|(i, _)| {
|
||||
self.configure_endpoint(cs, i).unwrap();
|
||||
});
|
||||
|
||||
// Interrupts. //
|
||||
|
||||
usb.udien
|
||||
|
@ -165,12 +171,7 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
if usb.usbcon.read().frzclk().bit_is_clear() {
|
||||
let (mut ep_out, mut ep_setup, mut ep_in_complete) = (0u8, 0u8, 0u8);
|
||||
|
||||
for (index, _ep) in self
|
||||
.ep_table
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_i, e)| e.is_allocated)
|
||||
{
|
||||
for (index, _ep) in self.allocated_endpoints() {
|
||||
if self.select_endpoint(cs, index).is_err() {
|
||||
// Endpoint selection has stopped working...
|
||||
break;
|
||||
|
@ -273,6 +274,10 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
|||
}
|
||||
});
|
||||
|
||||
self.allocated_endpoints().for_each(|(i, _)| {
|
||||
self.configure_endpoint(cs, i).unwrap();
|
||||
});
|
||||
|
||||
// Reset endpoints //
|
||||
|
||||
usb.uerst.modify(|_, w| unsafe { w.bits(u8::MAX >> 1) });
|
||||
|
|
|
@ -55,7 +55,7 @@ impl USBEndpoint {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) struct UsbDevice<const L: usize> {
|
||||
pub struct UsbDevice<const L: usize> {
|
||||
pub(crate) pll: Mutex<PLL>,
|
||||
pub(crate) usb: Mutex<USB_DEVICE>,
|
||||
pub(crate) ep_table: [USBEndpoint; L],
|
||||
|
@ -67,7 +67,7 @@ pub(crate) const ENDPOINTS_ALLOC_LAYOUT: [u16; 7] = [64, 256, 64, 64, 64, 64, 64
|
|||
|
||||
impl<const L: usize> UsbDevice<L> {
|
||||
#[inline]
|
||||
pub(crate) fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator<Self> {
|
||||
pub fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator<Self> {
|
||||
let (pll, usb) = (Mutex::new(pll), Mutex::new(usb));
|
||||
let ep_table: [USBEndpoint; L] = [Default::default(); L];
|
||||
UsbBusAllocator::new(Self {
|
||||
|
@ -78,6 +78,14 @@ impl<const L: usize> UsbDevice<L> {
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn allocated_endpoints(&self) -> impl Iterator<Item = (usize, &USBEndpoint)> {
|
||||
self.ep_table
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, ep)| ep.is_allocated)
|
||||
}
|
||||
|
||||
pub(crate) fn select_endpoint(
|
||||
&self,
|
||||
cs: CriticalSection<'_>,
|
||||
|
@ -100,7 +108,7 @@ impl<const L: usize> UsbDevice<L> {
|
|||
}
|
||||
|
||||
pub(crate) fn configure_endpoint(
|
||||
&mut self,
|
||||
&self,
|
||||
cs: CriticalSection<'_>,
|
||||
endpoint_index: usize,
|
||||
) -> Result<(), UsbError> {
|
||||
|
|
Loading…
Reference in New Issue