diff options
author | Brian Cully <bjc@kublai.com> | 2019-08-10 14:19:38 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2019-08-10 14:19:38 -0400 |
commit | 0a8c0daa9f48093682a3197ad24d37c16dc32c99 (patch) | |
tree | d2bee1deab45a90fe1557aede6fc626b77a40764 | |
parent | aab5cd2b36986c51e4a91291e0a083795b0c735f (diff) | |
download | atsamd-usb-host-0a8c0daa9f48093682a3197ad24d37c16dc32c99.tar.gz atsamd-usb-host-0a8c0daa9f48093682a3197ad24d37c16dc32c99.zip |
Use endpoint's max packet size for pipe.
-rw-r--r-- | src/pipe.rs | 28 | ||||
-rw-r--r-- | src/pipe/pck_size.rs | 10 |
2 files changed, 34 insertions, 4 deletions
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<usize, PipeErr> { 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) } }); diff --git a/src/pipe/pck_size.rs b/src/pipe/pck_size.rs index acc499f..c95140d 100644 --- a/src/pipe/pck_size.rs +++ b/src/pipe/pck_size.rs @@ -29,6 +29,16 @@ impl PckSize { f(&mut w); self.0 = w.bits; } + + pub fn modify<F>(&mut self, f: F) + where + for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W, + { + let r = R { bits: self.0 }; + let mut w = W { bits: self.0 }; + f(&r, &mut w); + self.0 = w.bits; + } } impl From<u32> for PckSize { |