usb: remove address arg from endpoint allocation.
This commit is contained in:
parent
e9ab960ebf
commit
2e104170de
@ -143,38 +143,32 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
|
|||||||
|
|
||||||
fn alloc_endpoint_in(
|
fn alloc_endpoint_in(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
packet_size: u16,
|
||||||
interval: u8,
|
interval: u8,
|
||||||
) -> Result<Self::EndpointIn, driver::EndpointAllocError> {
|
) -> Result<Self::EndpointIn, driver::EndpointAllocError> {
|
||||||
let index = self
|
let index = self.alloc_in.allocate(ep_type, packet_size, interval)?;
|
||||||
.alloc_in
|
|
||||||
.allocate(ep_addr, ep_type, max_packet_size, interval)?;
|
|
||||||
let ep_addr = EndpointAddress::from_parts(index, UsbDirection::In);
|
let ep_addr = EndpointAddress::from_parts(index, UsbDirection::In);
|
||||||
Ok(Endpoint::new(EndpointInfo {
|
Ok(Endpoint::new(EndpointInfo {
|
||||||
addr: ep_addr,
|
addr: ep_addr,
|
||||||
ep_type,
|
ep_type,
|
||||||
max_packet_size,
|
max_packet_size: packet_size,
|
||||||
interval,
|
interval,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc_endpoint_out(
|
fn alloc_endpoint_out(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
packet_size: u16,
|
||||||
interval: u8,
|
interval: u8,
|
||||||
) -> Result<Self::EndpointOut, driver::EndpointAllocError> {
|
) -> Result<Self::EndpointOut, driver::EndpointAllocError> {
|
||||||
let index = self
|
let index = self.alloc_out.allocate(ep_type, packet_size, interval)?;
|
||||||
.alloc_out
|
|
||||||
.allocate(ep_addr, ep_type, max_packet_size, interval)?;
|
|
||||||
let ep_addr = EndpointAddress::from_parts(index, UsbDirection::Out);
|
let ep_addr = EndpointAddress::from_parts(index, UsbDirection::Out);
|
||||||
Ok(Endpoint::new(EndpointInfo {
|
Ok(Endpoint::new(EndpointInfo {
|
||||||
addr: ep_addr,
|
addr: ep_addr,
|
||||||
ep_type,
|
ep_type,
|
||||||
max_packet_size,
|
max_packet_size: packet_size,
|
||||||
interval,
|
interval,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -183,8 +177,10 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
max_packet_size: u16,
|
max_packet_size: u16,
|
||||||
) -> Result<Self::ControlPipe, driver::EndpointAllocError> {
|
) -> Result<Self::ControlPipe, driver::EndpointAllocError> {
|
||||||
self.alloc_endpoint_out(Some(0x00.into()), EndpointType::Control, max_packet_size, 0)?;
|
self.alloc_in.used |= 0x01;
|
||||||
self.alloc_endpoint_in(Some(0x80.into()), EndpointType::Control, max_packet_size, 0)?;
|
self.alloc_in.lens[0] = max_packet_size as u8;
|
||||||
|
self.alloc_out.used |= 0x01;
|
||||||
|
self.alloc_out.lens[0] = max_packet_size as u8;
|
||||||
Ok(ControlPipe {
|
Ok(ControlPipe {
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
max_packet_size,
|
max_packet_size,
|
||||||
@ -681,8 +677,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Reset shorts
|
// Reset shorts
|
||||||
regs.shorts
|
regs.shorts.write(|w| w);
|
||||||
.modify(|_, w| w.ep0datadone_ep0status().clear_bit());
|
|
||||||
regs.events_ep0setup.reset();
|
regs.events_ep0setup.reset();
|
||||||
|
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
@ -746,7 +741,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
regs.shorts
|
regs.shorts
|
||||||
.modify(|_, w| w.ep0datadone_ep0status().bit(last_packet));
|
.write(|w| w.ep0datadone_ep0status().bit(last_packet));
|
||||||
|
|
||||||
regs.intenset.write(|w| {
|
regs.intenset.write(|w| {
|
||||||
w.usbreset().set();
|
w.usbreset().set();
|
||||||
@ -810,7 +805,6 @@ impl Allocator {
|
|||||||
|
|
||||||
fn allocate(
|
fn allocate(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
max_packet_size: u16,
|
||||||
_interval: u8,
|
_interval: u8,
|
||||||
@ -828,19 +822,9 @@ impl Allocator {
|
|||||||
|
|
||||||
// Endpoint directions are allocated individually.
|
// Endpoint directions are allocated individually.
|
||||||
|
|
||||||
let alloc_index = if let Some(ep_addr) = ep_addr {
|
let alloc_index = match ep_type {
|
||||||
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::Isochronous => 8,
|
||||||
EndpointType::Control => 0,
|
EndpointType::Control => return Err(driver::EndpointAllocError),
|
||||||
EndpointType::Interrupt | EndpointType::Bulk => {
|
EndpointType::Interrupt | EndpointType::Bulk => {
|
||||||
// Find rightmost zero bit in 1..=7
|
// Find rightmost zero bit in 1..=7
|
||||||
let ones = (self.used >> 1).trailing_ones() as usize;
|
let ones = (self.used >> 1).trailing_ones() as usize;
|
||||||
@ -849,7 +833,6 @@ impl Allocator {
|
|||||||
}
|
}
|
||||||
ones + 1
|
ones + 1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.used & (1 << alloc_index) != 0 {
|
if self.used & (1 << alloc_index) != 0 {
|
||||||
|
@ -372,7 +372,6 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
|
|
||||||
fn endpoint_in(
|
fn endpoint_in(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
max_packet_size: u16,
|
||||||
interval: u8,
|
interval: u8,
|
||||||
@ -380,7 +379,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
let ep = self
|
let ep = self
|
||||||
.builder
|
.builder
|
||||||
.driver
|
.driver
|
||||||
.alloc_endpoint_in(ep_addr, ep_type, max_packet_size, interval)
|
.alloc_endpoint_in(ep_type, max_packet_size, interval)
|
||||||
.expect("alloc_endpoint_in failed");
|
.expect("alloc_endpoint_in failed");
|
||||||
|
|
||||||
self.builder.config_descriptor.endpoint(ep.info());
|
self.builder.config_descriptor.endpoint(ep.info());
|
||||||
@ -390,7 +389,6 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
|
|
||||||
fn endpoint_out(
|
fn endpoint_out(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
max_packet_size: u16,
|
||||||
interval: u8,
|
interval: u8,
|
||||||
@ -398,7 +396,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
let ep = self
|
let ep = self
|
||||||
.builder
|
.builder
|
||||||
.driver
|
.driver
|
||||||
.alloc_endpoint_out(ep_addr, ep_type, max_packet_size, interval)
|
.alloc_endpoint_out(ep_type, max_packet_size, interval)
|
||||||
.expect("alloc_endpoint_out failed");
|
.expect("alloc_endpoint_out failed");
|
||||||
|
|
||||||
self.builder.config_descriptor.endpoint(ep.info());
|
self.builder.config_descriptor.endpoint(ep.info());
|
||||||
@ -411,7 +409,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
/// Descriptors are written in the order builder functions are called. Note that some
|
/// Descriptors are written in the order builder functions are called. Note that some
|
||||||
/// classes care about the order.
|
/// classes care about the order.
|
||||||
pub fn endpoint_bulk_in(&mut self, max_packet_size: u16) -> D::EndpointIn {
|
pub fn endpoint_bulk_in(&mut self, max_packet_size: u16) -> D::EndpointIn {
|
||||||
self.endpoint_in(None, EndpointType::Bulk, max_packet_size, 0)
|
self.endpoint_in(EndpointType::Bulk, max_packet_size, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate a BULK OUT endpoint and write its descriptor.
|
/// Allocate a BULK OUT endpoint and write its descriptor.
|
||||||
@ -419,7 +417,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
/// Descriptors are written in the order builder functions are called. Note that some
|
/// Descriptors are written in the order builder functions are called. Note that some
|
||||||
/// classes care about the order.
|
/// classes care about the order.
|
||||||
pub fn endpoint_bulk_out(&mut self, max_packet_size: u16) -> D::EndpointOut {
|
pub fn endpoint_bulk_out(&mut self, max_packet_size: u16) -> D::EndpointOut {
|
||||||
self.endpoint_out(None, EndpointType::Bulk, max_packet_size, 0)
|
self.endpoint_out(EndpointType::Bulk, max_packet_size, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate a INTERRUPT IN endpoint and write its descriptor.
|
/// Allocate a INTERRUPT IN endpoint and write its descriptor.
|
||||||
@ -427,11 +425,11 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
|
|||||||
/// Descriptors are written in the order builder functions are called. Note that some
|
/// Descriptors are written in the order builder functions are called. Note that some
|
||||||
/// classes care about the order.
|
/// classes care about the order.
|
||||||
pub fn endpoint_interrupt_in(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointIn {
|
pub fn endpoint_interrupt_in(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointIn {
|
||||||
self.endpoint_in(None, EndpointType::Interrupt, max_packet_size, interval)
|
self.endpoint_in(EndpointType::Interrupt, max_packet_size, interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate a INTERRUPT OUT endpoint and write its descriptor.
|
/// Allocate a INTERRUPT OUT endpoint and write its descriptor.
|
||||||
pub fn endpoint_interrupt_out(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointOut {
|
pub fn endpoint_interrupt_out(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointOut {
|
||||||
self.endpoint_out(None, EndpointType::Interrupt, max_packet_size, interval)
|
self.endpoint_out(EndpointType::Interrupt, max_packet_size, interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ pub trait Driver<'a> {
|
|||||||
/// * `interval` - Polling interval parameter for interrupt endpoints.
|
/// * `interval` - Polling interval parameter for interrupt endpoints.
|
||||||
fn alloc_endpoint_out(
|
fn alloc_endpoint_out(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
max_packet_size: u16,
|
||||||
interval: u8,
|
interval: u8,
|
||||||
@ -33,7 +32,6 @@ pub trait Driver<'a> {
|
|||||||
|
|
||||||
fn alloc_endpoint_in(
|
fn alloc_endpoint_in(
|
||||||
&mut self,
|
&mut self,
|
||||||
ep_addr: Option<EndpointAddress>,
|
|
||||||
ep_type: EndpointType,
|
ep_type: EndpointType,
|
||||||
max_packet_size: u16,
|
max_packet_size: u16,
|
||||||
interval: u8,
|
interval: u8,
|
||||||
|
@ -71,7 +71,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
let mut device_descriptor = [0; 256];
|
let mut device_descriptor = [0; 256];
|
||||||
let mut config_descriptor = [0; 256];
|
let mut config_descriptor = [0; 256];
|
||||||
let mut bos_descriptor = [0; 256];
|
let mut bos_descriptor = [0; 256];
|
||||||
let mut control_buf = [0; 16];
|
let mut control_buf = [0; 64];
|
||||||
let request_handler = MyRequestHandler {};
|
let request_handler = MyRequestHandler {};
|
||||||
let device_state_handler = MyDeviceStateHandler::new();
|
let device_state_handler = MyDeviceStateHandler::new();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
let mut device_descriptor = [0; 256];
|
let mut device_descriptor = [0; 256];
|
||||||
let mut config_descriptor = [0; 256];
|
let mut config_descriptor = [0; 256];
|
||||||
let mut bos_descriptor = [0; 256];
|
let mut bos_descriptor = [0; 256];
|
||||||
let mut control_buf = [0; 16];
|
let mut control_buf = [0; 64];
|
||||||
let request_handler = MyRequestHandler {};
|
let request_handler = MyRequestHandler {};
|
||||||
|
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
|
@ -48,7 +48,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
let mut device_descriptor = [0; 256];
|
let mut device_descriptor = [0; 256];
|
||||||
let mut config_descriptor = [0; 256];
|
let mut config_descriptor = [0; 256];
|
||||||
let mut bos_descriptor = [0; 256];
|
let mut bos_descriptor = [0; 256];
|
||||||
let mut control_buf = [0; 7];
|
let mut control_buf = [0; 64];
|
||||||
|
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ async fn main(spawner: Spawner, p: Peripherals) {
|
|||||||
device_descriptor: [u8; 256],
|
device_descriptor: [u8; 256],
|
||||||
config_descriptor: [u8; 256],
|
config_descriptor: [u8; 256],
|
||||||
bos_descriptor: [u8; 256],
|
bos_descriptor: [u8; 256],
|
||||||
control_buf: [u8; 7],
|
control_buf: [u8; 64],
|
||||||
serial_state: State<'static>,
|
serial_state: State<'static>,
|
||||||
}
|
}
|
||||||
static RESOURCES: Forever<Resources> = Forever::new();
|
static RESOURCES: Forever<Resources> = Forever::new();
|
||||||
@ -72,7 +72,7 @@ async fn main(spawner: Spawner, p: Peripherals) {
|
|||||||
device_descriptor: [0; 256],
|
device_descriptor: [0; 256],
|
||||||
config_descriptor: [0; 256],
|
config_descriptor: [0; 256],
|
||||||
bos_descriptor: [0; 256],
|
bos_descriptor: [0; 256],
|
||||||
control_buf: [0; 7],
|
control_buf: [0; 64],
|
||||||
serial_state: State::new(),
|
serial_state: State::new(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user