aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipe/ctrl_pipe.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-09-23 12:45:09 -0400
committerBrian Cully <bjc@kublai.com>2019-09-24 10:55:25 -0400
commitfcc6951c707144ba423b81e03bc2f34b6cfa7286 (patch)
tree574f64eb11e23920343137e352eb1279f1940a5d /src/pipe/ctrl_pipe.rs
parent77d1fdf044326cfb039728bf94a998f1dd1e8d1e (diff)
downloadatsamd-usb-host-fcc6951c707144ba423b81e03bc2f34b6cfa7286.tar.gz
atsamd-usb-host-fcc6951c707144ba423b81e03bc2f34b6cfa7286.zip
Mark pipe descriptor register memory as volatile.
Most of the values in the descriptor memory can be modified by the hardware, so we need to tell Rust that. Also, refactor the common register setup code into `register.rs`.
Diffstat (limited to 'src/pipe/ctrl_pipe.rs')
-rw-r--r--src/pipe/ctrl_pipe.rs60
1 files changed, 8 insertions, 52 deletions
diff --git a/src/pipe/ctrl_pipe.rs b/src/pipe/ctrl_pipe.rs
index 360a0e7..5db00c1 100644
--- a/src/pipe/ctrl_pipe.rs
+++ b/src/pipe/ctrl_pipe.rs
@@ -1,57 +1,20 @@
+use super::register::{Readable, Register, Writable, R as GenR, W as GenW};
+
/// Host Control Pipe.
///
/// Offset: 0x0c
/// Reset: 0xXXXX
/// Property: PAC Write-Protection, Write-Synchronized, Read-Synchronized
-#[derive(Clone, Copy, Debug)]
-#[repr(C, packed)]
-pub struct CtrlPipe(u16);
-
-pub struct R {
- bits: u16,
-}
-
-pub struct W {
- bits: u16,
-}
-
-impl CtrlPipe {
- pub fn read(self) -> R {
- R { bits: self.0 }
- }
-
- pub fn write<F>(&mut self, f: F)
- where
- F: FnOnce(&mut W) -> &mut W,
- {
- let mut w = W { bits: self.0 };
- f(&mut w);
- self.0 = w.bits;
- }
+pub type CtrlPipe = Register<u16, _CtrlPipe>;
+impl Readable for CtrlPipe {}
+impl Writable for CtrlPipe {}
- 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;
- }
-}
+pub type R = GenR<u16, CtrlPipe>;
+pub type W = GenW<u16, CtrlPipe>;
-impl From<u16> for CtrlPipe {
- fn from(v: u16) -> Self {
- Self(v)
- }
-}
+pub struct _CtrlPipe;
impl R {
- /// Value in raw bits.
- pub fn bits(&self) -> u16 {
- self.bits
- }
-
pub fn permax(&self) -> PErMaxR {
let bits = {
const POS: u8 = 12;
@@ -115,13 +78,6 @@ impl PDAddrR {
}
impl W {
- /// Write raw bits.
-
- pub unsafe fn bits(&mut self, v: u16) -> &mut Self {
- self.bits = v;
- self
- }
-
pub fn permax(&mut self) -> PErMaxW {
PErMaxW { w: self }
}