stm32l4x2_pac/usb/
daddr.rs

1#[doc = r" Value read from the register"]
2pub struct R {
3    bits: u32,
4}
5#[doc = r" Value to write to the register"]
6pub struct W {
7    bits: u32,
8}
9impl super::DADDR {
10    #[doc = r" Modifies the contents of the register"]
11    #[inline]
12    pub fn modify<F>(&self, f: F)
13    where
14        for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W,
15    {
16        let bits = self.register.get();
17        let r = R { bits: bits };
18        let mut w = W { bits: bits };
19        f(&r, &mut w);
20        self.register.set(w.bits);
21    }
22    #[doc = r" Reads the contents of the register"]
23    #[inline]
24    pub fn read(&self) -> R {
25        R {
26            bits: self.register.get(),
27        }
28    }
29    #[doc = r" Writes to the register"]
30    #[inline]
31    pub fn write<F>(&self, f: F)
32    where
33        F: FnOnce(&mut W) -> &mut W,
34    {
35        let mut w = W::reset_value();
36        f(&mut w);
37        self.register.set(w.bits);
38    }
39    #[doc = r" Writes the reset value to the register"]
40    #[inline]
41    pub fn reset(&self) {
42        self.write(|w| w)
43    }
44}
45#[doc = r" Value of the field"]
46pub struct ADDR {
47    bits: u8,
48}
49impl ADDR {
50    #[doc = r" Value of the field as raw bits"]
51    #[inline]
52    pub fn bits(&self) -> u8 {
53        self.bits
54    }
55}
56#[doc = "Possible values of the field `EF`"]
57#[derive(Clone, Copy, Debug, PartialEq)]
58pub enum EFR {
59    #[doc = "USB device disabled"]
60    DISABLED,
61    #[doc = "USB device enabled"]
62    ENABLED,
63}
64impl EFR {
65    #[doc = r" Returns `true` if the bit is clear (0)"]
66    #[inline]
67    pub fn bit_is_clear(&self) -> bool {
68        !self.bit()
69    }
70    #[doc = r" Returns `true` if the bit is set (1)"]
71    #[inline]
72    pub fn bit_is_set(&self) -> bool {
73        self.bit()
74    }
75    #[doc = r" Value of the field as raw bits"]
76    #[inline]
77    pub fn bit(&self) -> bool {
78        match *self {
79            EFR::DISABLED => false,
80            EFR::ENABLED => true,
81        }
82    }
83    #[allow(missing_docs)]
84    #[doc(hidden)]
85    #[inline]
86    pub fn _from(value: bool) -> EFR {
87        match value {
88            false => EFR::DISABLED,
89            true => EFR::ENABLED,
90        }
91    }
92    #[doc = "Checks if the value of the field is `DISABLED`"]
93    #[inline]
94    pub fn is_disabled(&self) -> bool {
95        *self == EFR::DISABLED
96    }
97    #[doc = "Checks if the value of the field is `ENABLED`"]
98    #[inline]
99    pub fn is_enabled(&self) -> bool {
100        *self == EFR::ENABLED
101    }
102}
103#[doc = r" Proxy"]
104pub struct _ADDW<'a> {
105    w: &'a mut W,
106}
107impl<'a> _ADDW<'a> {
108    #[doc = r" Writes raw bits to the field"]
109    #[inline]
110    pub fn bits(self, value: u8) -> &'a mut W {
111        const MASK: u8 = 127;
112        const OFFSET: u8 = 0;
113        self.w.bits &= !((MASK as u32) << OFFSET);
114        self.w.bits |= ((value & MASK) as u32) << OFFSET;
115        self.w
116    }
117}
118#[doc = "Values that can be written to the field `EF`"]
119pub enum EFW {
120    #[doc = "USB device disabled"]
121    DISABLED,
122    #[doc = "USB device enabled"]
123    ENABLED,
124}
125impl EFW {
126    #[allow(missing_docs)]
127    #[doc(hidden)]
128    #[inline]
129    pub fn _bits(&self) -> bool {
130        match *self {
131            EFW::DISABLED => false,
132            EFW::ENABLED => true,
133        }
134    }
135}
136#[doc = r" Proxy"]
137pub struct _EFW<'a> {
138    w: &'a mut W,
139}
140impl<'a> _EFW<'a> {
141    #[doc = r" Writes `variant` to the field"]
142    #[inline]
143    pub fn variant(self, variant: EFW) -> &'a mut W {
144        {
145            self.bit(variant._bits())
146        }
147    }
148    #[doc = "USB device disabled"]
149    #[inline]
150    pub fn disabled(self) -> &'a mut W {
151        self.variant(EFW::DISABLED)
152    }
153    #[doc = "USB device enabled"]
154    #[inline]
155    pub fn enabled(self) -> &'a mut W {
156        self.variant(EFW::ENABLED)
157    }
158    #[doc = r" Sets the field bit"]
159    pub fn set_bit(self) -> &'a mut W {
160        self.bit(true)
161    }
162    #[doc = r" Clears the field bit"]
163    pub fn clear_bit(self) -> &'a mut W {
164        self.bit(false)
165    }
166    #[doc = r" Writes raw bits to the field"]
167    #[inline]
168    pub fn bit(self, value: bool) -> &'a mut W {
169        const MASK: bool = true;
170        const OFFSET: u8 = 7;
171        self.w.bits &= !((MASK as u32) << OFFSET);
172        self.w.bits |= ((value & MASK) as u32) << OFFSET;
173        self.w
174    }
175}
176impl R {
177    #[doc = r" Value of the register as raw bits"]
178    #[inline]
179    pub fn bits(&self) -> u32 {
180        self.bits
181    }
182    #[doc = "Bits 0:6 - Device address"]
183    #[inline]
184    pub fn add(&self) -> ADDR {
185        let bits = {
186            const MASK: u8 = 127;
187            const OFFSET: u8 = 0;
188            ((self.bits >> OFFSET) & MASK as u32) as u8
189        };
190        ADDR { bits }
191    }
192    #[doc = "Bit 7 - Enable function"]
193    #[inline]
194    pub fn ef(&self) -> EFR {
195        EFR::_from({
196            const MASK: bool = true;
197            const OFFSET: u8 = 7;
198            ((self.bits >> OFFSET) & MASK as u32) != 0
199        })
200    }
201}
202impl W {
203    #[doc = r" Reset value of the register"]
204    #[inline]
205    pub fn reset_value() -> W {
206        W { bits: 0 }
207    }
208    #[doc = r" Writes raw bits to the register"]
209    #[inline]
210    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
211        self.bits = bits;
212        self
213    }
214    #[doc = "Bits 0:6 - Device address"]
215    #[inline]
216    pub fn add(&mut self) -> _ADDW {
217        _ADDW { w: self }
218    }
219    #[doc = "Bit 7 - Enable function"]
220    #[inline]
221    pub fn ef(&mut self) -> _EFW {
222        _EFW { w: self }
223    }
224}