From ff1e75868d22887548ecf8017e0b5e6df6537419 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Thu, 25 Jul 2019 16:51:23 -0400 Subject: Add modify method for ADDR. --- usbh/src/pipe/addr.rs | 14 ++++++++++++-- 1 file 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(&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 } -- cgit v1.2.3