aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipe/ext_reg.rs
blob: 95a8f047f803645df62d5e03031ea74dd870850d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use super::register::{Readable, Register, Writable, R as GenR, W as GenW};

/// §32.8.7.4
/// Extended Register.
///
/// Offset: 0x08
/// Reset: 0xxxxxxxx
/// Property: NA
pub type ExtReg = Register<u16, _ExtReg>;
impl Readable for ExtReg {}
impl Writable for ExtReg {}

pub type R = GenR<u16, ExtReg>;
pub type W = GenW<u16, ExtReg>;

pub struct _ExtReg;

impl R {
    pub fn variable(&self) -> VariableR {
        let bits = {
            const POS: u8 = 4;
            const MASK: u16 = 0x7ff;
            (self.bits >> POS) & MASK
        };

        VariableR(bits)
    }

    pub fn subpid(&self) -> SubPIDR {
        let bits = {
            const POS: u8 = 0;
            const MASK: u16 = 0xf;
            ((self.bits >> POS) & MASK) as u8
        };

        SubPIDR(bits)
    }
}

/// Variable field send with extended token
///
/// These bits define the VARIABLE field sent with extended token. See
/// “Section 2.1.1 Protocol Extension Token in the reference document
/// ENGINEERING CHANGE NOTICE, USB 2.0 Link Power Management
/// Addendum.”
///
/// To support the USB2.0 Link Power Management addition the VARIABLE
/// field should be set as described below.
///
/// | VARIABLE       | Description           |
/// +----------------+-----------------------+
/// | VARIABLE[3:0]  | bLinkState[1]         |
/// | VARIABLE[7:4]  | BESL (See LPM ECN)[2] |
/// | VARIABLE[8]    | bRemoteWake[1]        |
/// | VARIABLE[10:9] | Reserved              |
///
/// [1] for a definition of LPM Token bRemoteWake and bLinkState
/// fields, refer to "Table 2-3 in the reference document ENGINEERING
/// CHANGE NOTICE, USB 2.0 Link Power Management Addendum"
///
/// [2] for a definition of LPM Token BESL field, refer to "Table 2-3
/// in the reference document ENGINEERING CHANGE NOTICE, USB 2.0 Link
/// Power Management Addendum" and "Table X-X1 in Errata for ECN USB
/// 2.0 Link Power Management.
pub struct VariableR(u16);
impl VariableR {
    pub fn bits(&self) -> u16 {
        self.0
    }
}

/// SUBPID field with extended token
///
/// These bits define the SUBPID field sent with extended token. See
/// “Section 2.1.1 Protocol Extension Token in the reference document
/// ENGINEERING CHANGE NOTICE, USB 2.0 Link Power Management
/// Addendum”.
///
/// To support the USB2.0 Link Power Management addition the SUBPID
/// field should be set as described in “Table 2.2 SubPID Types in the
/// reference document ENGINEERING CHANGE NOTICE, USB 2.0 Link Power
/// Management Addendum”.
pub struct SubPIDR(u8);
impl SubPIDR {
    pub fn bits(&self) -> u8 {
        self.0
    }
}

impl W {
    pub fn variable(&mut self) -> VariableW {
        VariableW { w: self }
    }
    pub fn subpid(&mut self) -> SubPIDW {
        SubPIDW { w: self }
    }
}

pub struct VariableW<'a> {
    w: &'a mut W,
}
impl<'a> VariableW<'a> {
    pub unsafe fn bits(self, v: u16) -> &'a mut W {
        const POS: u8 = 4;
        const MASK: u16 = 0x7ff;
        self.w.bits &= !((MASK as u16) << POS);
        self.w.bits |= ((v & MASK) as u16) << POS;
        self.w
    }
}

pub struct SubPIDW<'a> {
    w: &'a mut W,
}
impl<'a> SubPIDW<'a> {
    pub unsafe fn bits(self, v: u16) -> &'a mut W {
        const POS: u8 = 0;
        const MASK: u16 = 0xf;
        self.w.bits &= !((MASK as u16) << POS);
        self.w.bits |= ((v & MASK) as u16) << POS;
        self.w
    }
}