diff options
author | Brian Cully <bjc@kublai.com> | 2019-07-25 16:51:23 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2019-07-25 16:51:23 -0400 |
commit | ff1e75868d22887548ecf8017e0b5e6df6537419 (patch) | |
tree | 4a6190fb54002542c2ac76404d8f7d5b987fb62b /usbh/src/pipe/addr.rs | |
parent | 2cfdcc6771958b510f770e28651b869c52b8c943 (diff) | |
download | samd21-demo-ff1e75868d22887548ecf8017e0b5e6df6537419.tar.gz samd21-demo-ff1e75868d22887548ecf8017e0b5e6df6537419.zip |
Add modify method for ADDR.
Diffstat (limited to 'usbh/src/pipe/addr.rs')
-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 } |