diff options
-rw-r--r-- | usbh/src/pipe/addr.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/usbh/src/pipe/addr.rs b/usbh/src/pipe/addr.rs index 8b92177..3ff2d2d 100644 --- a/usbh/src/pipe/addr.rs +++ b/usbh/src/pipe/addr.rs @@ -27,8 +27,16 @@ impl Addr { { let mut w = W { bits: self.0 }; f(&mut w); - // Address must be 32-bit aligned. - assert!((w.bits & 0x3) == 0); + 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; } } @@ -79,6 +87,8 @@ pub(crate) struct AddrW<'a> { } impl<'a> AddrW<'a> { pub unsafe fn bits(self, v: u32) -> &'a mut W { + // Address must be 32-bit aligned. + assert!((v & 0x3) == 0); self.w.bits = v; self.w } |