From 0a8c0daa9f48093682a3197ad24d37c16dc32c99 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sat, 10 Aug 2019 14:19:38 -0400 Subject: Use endpoint's max packet size for pipe. --- src/pipe.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/pipe.rs') diff --git a/src/pipe.rs b/src/pipe.rs index 607e1c9..e90b88b 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -107,6 +107,26 @@ impl PipeTable { w.pdaddr().set_addr(endpoint.address()); w.pepnum().set_epnum(endpoint.endpoint_num()) }); + pdesc.bank0.pcksize.write(|w| { + let mps = endpoint.max_packet_size(); + if mps >= 1023 { + w.size().bytes1024() + } else if mps >= 512 { + w.size().bytes512() + } else if mps >= 256 { + w.size().bytes256() + } else if mps >= 128 { + w.size().bytes128() + } else if mps >= 64 { + w.size().bytes64() + } else if mps >= 32 { + w.size().bytes32() + } else if mps >= 16 { + w.size().bytes16() + } else { + w.size().bytes8() + } + }); Pipe { num: i, regs: pregs, @@ -175,7 +195,7 @@ impl Pipe<'_, '_> { */ // TODO: status stage has up to 50ms to complete. cf ยง9.2.6.4 // of USB 2.0. - self.desc.bank0.pcksize.write(|w| { + self.desc.bank0.pcksize.modify(|_, w| { unsafe { w.byte_count().bits(0) }; unsafe { w.multi_packet_size().bits(0) } }); @@ -206,7 +226,7 @@ impl Pipe<'_, '_> { .addr .write(|w| unsafe { w.addr().bits(buf.ptr as u32) }); // configure packet size PCKSIZE.SIZE - self.desc.bank0.pcksize.write(|w| { + self.desc.bank0.pcksize.modify(|_, w| { unsafe { w.byte_count().bits(buf.len as u16) }; unsafe { w.multi_packet_size().bits(0) } }); @@ -225,7 +245,7 @@ impl Pipe<'_, '_> { let packet_size = 8; trace!("p{}: Should IN for {}b.", self.num, buf.len()); - self.desc.bank0.pcksize.write(|w| { + self.desc.bank0.pcksize.modify(|_, w| { unsafe { w.byte_count().bits(buf.len() as u16) }; unsafe { w.multi_packet_size().bits(0) } }); @@ -283,7 +303,7 @@ impl Pipe<'_, '_> { millis: &dyn Fn() -> usize, ) -> Result { trace!("p{}: Should OUT for {}b.", self.num, buf.len()); - self.desc.bank0.pcksize.write(|w| { + self.desc.bank0.pcksize.modify(|_, w| { unsafe { w.byte_count().bits(buf.len() as u16) }; unsafe { w.multi_packet_size().bits(0) } }); -- cgit v1.2.3