Merge branch 'embassy-rs:master' into qdec
This commit is contained in:
@ -143,58 +143,46 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
|
||||
|
||||
fn alloc_endpoint_in(
|
||||
&mut self,
|
||||
ep_addr: Option<EndpointAddress>,
|
||||
ep_type: EndpointType,
|
||||
max_packet_size: u16,
|
||||
packet_size: u16,
|
||||
interval: u8,
|
||||
) -> Result<Self::EndpointIn, driver::EndpointAllocError> {
|
||||
let index = self
|
||||
.alloc_in
|
||||
.allocate(ep_addr, ep_type, max_packet_size, interval)?;
|
||||
let index = self.alloc_in.allocate(ep_type)?;
|
||||
let ep_addr = EndpointAddress::from_parts(index, UsbDirection::In);
|
||||
Ok(Endpoint::new(EndpointInfo {
|
||||
addr: ep_addr,
|
||||
ep_type,
|
||||
max_packet_size,
|
||||
max_packet_size: packet_size,
|
||||
interval,
|
||||
}))
|
||||
}
|
||||
|
||||
fn alloc_endpoint_out(
|
||||
&mut self,
|
||||
ep_addr: Option<EndpointAddress>,
|
||||
ep_type: EndpointType,
|
||||
max_packet_size: u16,
|
||||
packet_size: u16,
|
||||
interval: u8,
|
||||
) -> Result<Self::EndpointOut, driver::EndpointAllocError> {
|
||||
let index = self
|
||||
.alloc_out
|
||||
.allocate(ep_addr, ep_type, max_packet_size, interval)?;
|
||||
let index = self.alloc_out.allocate(ep_type)?;
|
||||
let ep_addr = EndpointAddress::from_parts(index, UsbDirection::Out);
|
||||
Ok(Endpoint::new(EndpointInfo {
|
||||
addr: ep_addr,
|
||||
ep_type,
|
||||
max_packet_size,
|
||||
max_packet_size: packet_size,
|
||||
interval,
|
||||
}))
|
||||
}
|
||||
|
||||
fn alloc_control_pipe(
|
||||
&mut self,
|
||||
max_packet_size: u16,
|
||||
) -> Result<Self::ControlPipe, driver::EndpointAllocError> {
|
||||
self.alloc_endpoint_out(Some(0x00.into()), EndpointType::Control, max_packet_size, 0)?;
|
||||
self.alloc_endpoint_in(Some(0x80.into()), EndpointType::Control, max_packet_size, 0)?;
|
||||
Ok(ControlPipe {
|
||||
_phantom: PhantomData,
|
||||
max_packet_size,
|
||||
})
|
||||
}
|
||||
|
||||
fn into_bus(self) -> Self::Bus {
|
||||
Bus {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) {
|
||||
(
|
||||
Bus {
|
||||
phantom: PhantomData,
|
||||
},
|
||||
ControlPipe {
|
||||
_phantom: PhantomData,
|
||||
max_packet_size: control_max_packet_size,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -681,8 +669,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
|
||||
.await;
|
||||
|
||||
// Reset shorts
|
||||
regs.shorts
|
||||
.modify(|_, w| w.ep0datadone_ep0status().clear_bit());
|
||||
regs.shorts.write(|w| w);
|
||||
regs.events_ep0setup.reset();
|
||||
|
||||
let mut buf = [0; 8];
|
||||
@ -746,7 +733,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
|
||||
}
|
||||
|
||||
regs.shorts
|
||||
.modify(|_, w| w.ep0datadone_ep0status().bit(last_packet));
|
||||
.write(|w| w.ep0datadone_ep0status().bit(last_packet));
|
||||
|
||||
regs.intenset.write(|w| {
|
||||
w.usbreset().set();
|
||||
@ -796,25 +783,14 @@ fn dma_end() {
|
||||
|
||||
struct Allocator {
|
||||
used: u16,
|
||||
// Buffers can be up to 64 Bytes since this is a Full-Speed implementation.
|
||||
lens: [u8; 9],
|
||||
}
|
||||
|
||||
impl Allocator {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
used: 0,
|
||||
lens: [0; 9],
|
||||
}
|
||||
Self { used: 0 }
|
||||
}
|
||||
|
||||
fn allocate(
|
||||
&mut self,
|
||||
ep_addr: Option<EndpointAddress>,
|
||||
ep_type: EndpointType,
|
||||
max_packet_size: u16,
|
||||
_interval: u8,
|
||||
) -> Result<usize, driver::EndpointAllocError> {
|
||||
fn allocate(&mut self, ep_type: EndpointType) -> Result<usize, driver::EndpointAllocError> {
|
||||
// Endpoint addresses are fixed in hardware:
|
||||
// - 0x80 / 0x00 - Control EP0
|
||||
// - 0x81 / 0x01 - Bulk/Interrupt EP1
|
||||
@ -828,27 +804,16 @@ impl Allocator {
|
||||
|
||||
// Endpoint directions are allocated individually.
|
||||
|
||||
let alloc_index = if let Some(ep_addr) = ep_addr {
|
||||
match (ep_addr.index(), ep_type) {
|
||||
(0, EndpointType::Control) => {}
|
||||
(8, EndpointType::Isochronous) => {}
|
||||
(n, EndpointType::Bulk) | (n, EndpointType::Interrupt) if n >= 1 && n <= 7 => {}
|
||||
_ => return Err(driver::EndpointAllocError),
|
||||
}
|
||||
|
||||
ep_addr.index()
|
||||
} else {
|
||||
match ep_type {
|
||||
EndpointType::Isochronous => 8,
|
||||
EndpointType::Control => 0,
|
||||
EndpointType::Interrupt | EndpointType::Bulk => {
|
||||
// Find rightmost zero bit in 1..=7
|
||||
let ones = (self.used >> 1).trailing_ones() as usize;
|
||||
if ones >= 7 {
|
||||
return Err(driver::EndpointAllocError);
|
||||
}
|
||||
ones + 1
|
||||
let alloc_index = match ep_type {
|
||||
EndpointType::Isochronous => 8,
|
||||
EndpointType::Control => return Err(driver::EndpointAllocError),
|
||||
EndpointType::Interrupt | EndpointType::Bulk => {
|
||||
// Find rightmost zero bit in 1..=7
|
||||
let ones = (self.used >> 1).trailing_ones() as usize;
|
||||
if ones >= 7 {
|
||||
return Err(driver::EndpointAllocError);
|
||||
}
|
||||
ones + 1
|
||||
}
|
||||
};
|
||||
|
||||
@ -857,7 +822,6 @@ impl Allocator {
|
||||
}
|
||||
|
||||
self.used |= 1 << alloc_index;
|
||||
self.lens[alloc_index] = max_packet_size as u8;
|
||||
|
||||
Ok(alloc_index)
|
||||
}
|
||||
|
Reference in New Issue
Block a user