stm32l4x2_pac/iwdg/
pr.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::PR {
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 = "Possible values of the field `PR`"]
46#[derive(Clone, Copy, Debug, PartialEq)]
47pub enum PRR {
48    #[doc = "Divider /4"]
49    DIVIDEBY4,
50    #[doc = "Divider /8"]
51    DIVIDEBY8,
52    #[doc = "Divider /16"]
53    DIVIDEBY16,
54    #[doc = "Divider /32"]
55    DIVIDEBY32,
56    #[doc = "Divider /64"]
57    DIVIDEBY64,
58    #[doc = "Divider /128"]
59    DIVIDEBY128,
60    #[doc = "Divider /256"]
61    DIVIDEBY256,
62    #[doc = "Divider /256"]
63    DIVIDEBY256BIS,
64}
65impl PRR {
66    #[doc = r" Value of the field as raw bits"]
67    #[inline]
68    pub fn bits(&self) -> u8 {
69        match *self {
70            PRR::DIVIDEBY4 => 0,
71            PRR::DIVIDEBY8 => 1,
72            PRR::DIVIDEBY16 => 2,
73            PRR::DIVIDEBY32 => 3,
74            PRR::DIVIDEBY64 => 4,
75            PRR::DIVIDEBY128 => 5,
76            PRR::DIVIDEBY256 => 6,
77            PRR::DIVIDEBY256BIS => 7,
78        }
79    }
80    #[allow(missing_docs)]
81    #[doc(hidden)]
82    #[inline]
83    pub fn _from(value: u8) -> PRR {
84        match value {
85            0 => PRR::DIVIDEBY4,
86            1 => PRR::DIVIDEBY8,
87            2 => PRR::DIVIDEBY16,
88            3 => PRR::DIVIDEBY32,
89            4 => PRR::DIVIDEBY64,
90            5 => PRR::DIVIDEBY128,
91            6 => PRR::DIVIDEBY256,
92            7 => PRR::DIVIDEBY256BIS,
93            _ => unreachable!(),
94        }
95    }
96    #[doc = "Checks if the value of the field is `DIVIDEBY4`"]
97    #[inline]
98    pub fn is_divide_by4(&self) -> bool {
99        *self == PRR::DIVIDEBY4
100    }
101    #[doc = "Checks if the value of the field is `DIVIDEBY8`"]
102    #[inline]
103    pub fn is_divide_by8(&self) -> bool {
104        *self == PRR::DIVIDEBY8
105    }
106    #[doc = "Checks if the value of the field is `DIVIDEBY16`"]
107    #[inline]
108    pub fn is_divide_by16(&self) -> bool {
109        *self == PRR::DIVIDEBY16
110    }
111    #[doc = "Checks if the value of the field is `DIVIDEBY32`"]
112    #[inline]
113    pub fn is_divide_by32(&self) -> bool {
114        *self == PRR::DIVIDEBY32
115    }
116    #[doc = "Checks if the value of the field is `DIVIDEBY64`"]
117    #[inline]
118    pub fn is_divide_by64(&self) -> bool {
119        *self == PRR::DIVIDEBY64
120    }
121    #[doc = "Checks if the value of the field is `DIVIDEBY128`"]
122    #[inline]
123    pub fn is_divide_by128(&self) -> bool {
124        *self == PRR::DIVIDEBY128
125    }
126    #[doc = "Checks if the value of the field is `DIVIDEBY256`"]
127    #[inline]
128    pub fn is_divide_by256(&self) -> bool {
129        *self == PRR::DIVIDEBY256
130    }
131    #[doc = "Checks if the value of the field is `DIVIDEBY256BIS`"]
132    #[inline]
133    pub fn is_divide_by256bis(&self) -> bool {
134        *self == PRR::DIVIDEBY256BIS
135    }
136}
137#[doc = "Values that can be written to the field `PR`"]
138pub enum PRW {
139    #[doc = "Divider /4"]
140    DIVIDEBY4,
141    #[doc = "Divider /8"]
142    DIVIDEBY8,
143    #[doc = "Divider /16"]
144    DIVIDEBY16,
145    #[doc = "Divider /32"]
146    DIVIDEBY32,
147    #[doc = "Divider /64"]
148    DIVIDEBY64,
149    #[doc = "Divider /128"]
150    DIVIDEBY128,
151    #[doc = "Divider /256"]
152    DIVIDEBY256,
153    #[doc = "Divider /256"]
154    DIVIDEBY256BIS,
155}
156impl PRW {
157    #[allow(missing_docs)]
158    #[doc(hidden)]
159    #[inline]
160    pub fn _bits(&self) -> u8 {
161        match *self {
162            PRW::DIVIDEBY4 => 0,
163            PRW::DIVIDEBY8 => 1,
164            PRW::DIVIDEBY16 => 2,
165            PRW::DIVIDEBY32 => 3,
166            PRW::DIVIDEBY64 => 4,
167            PRW::DIVIDEBY128 => 5,
168            PRW::DIVIDEBY256 => 6,
169            PRW::DIVIDEBY256BIS => 7,
170        }
171    }
172}
173#[doc = r" Proxy"]
174pub struct _PRW<'a> {
175    w: &'a mut W,
176}
177impl<'a> _PRW<'a> {
178    #[doc = r" Writes `variant` to the field"]
179    #[inline]
180    pub fn variant(self, variant: PRW) -> &'a mut W {
181        {
182            self.bits(variant._bits())
183        }
184    }
185    #[doc = "Divider /4"]
186    #[inline]
187    pub fn divide_by4(self) -> &'a mut W {
188        self.variant(PRW::DIVIDEBY4)
189    }
190    #[doc = "Divider /8"]
191    #[inline]
192    pub fn divide_by8(self) -> &'a mut W {
193        self.variant(PRW::DIVIDEBY8)
194    }
195    #[doc = "Divider /16"]
196    #[inline]
197    pub fn divide_by16(self) -> &'a mut W {
198        self.variant(PRW::DIVIDEBY16)
199    }
200    #[doc = "Divider /32"]
201    #[inline]
202    pub fn divide_by32(self) -> &'a mut W {
203        self.variant(PRW::DIVIDEBY32)
204    }
205    #[doc = "Divider /64"]
206    #[inline]
207    pub fn divide_by64(self) -> &'a mut W {
208        self.variant(PRW::DIVIDEBY64)
209    }
210    #[doc = "Divider /128"]
211    #[inline]
212    pub fn divide_by128(self) -> &'a mut W {
213        self.variant(PRW::DIVIDEBY128)
214    }
215    #[doc = "Divider /256"]
216    #[inline]
217    pub fn divide_by256(self) -> &'a mut W {
218        self.variant(PRW::DIVIDEBY256)
219    }
220    #[doc = "Divider /256"]
221    #[inline]
222    pub fn divide_by256bis(self) -> &'a mut W {
223        self.variant(PRW::DIVIDEBY256BIS)
224    }
225    #[doc = r" Writes raw bits to the field"]
226    #[inline]
227    pub fn bits(self, value: u8) -> &'a mut W {
228        const MASK: u8 = 7;
229        const OFFSET: u8 = 0;
230        self.w.bits &= !((MASK as u32) << OFFSET);
231        self.w.bits |= ((value & MASK) as u32) << OFFSET;
232        self.w
233    }
234}
235impl R {
236    #[doc = r" Value of the register as raw bits"]
237    #[inline]
238    pub fn bits(&self) -> u32 {
239        self.bits
240    }
241    #[doc = "Bits 0:2 - Prescaler divider"]
242    #[inline]
243    pub fn pr(&self) -> PRR {
244        PRR::_from({
245            const MASK: u8 = 7;
246            const OFFSET: u8 = 0;
247            ((self.bits >> OFFSET) & MASK as u32) as u8
248        })
249    }
250}
251impl W {
252    #[doc = r" Reset value of the register"]
253    #[inline]
254    pub fn reset_value() -> W {
255        W { bits: 0 }
256    }
257    #[doc = r" Writes raw bits to the register"]
258    #[inline]
259    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
260        self.bits = bits;
261        self
262    }
263    #[doc = "Bits 0:2 - Prescaler divider"]
264    #[inline]
265    pub fn pr(&mut self) -> _PRW {
266        _PRW { w: self }
267    }
268}