Skip to main content

atsamd21j18a/sysctrl/
osc8m.rs

1#[doc = "Reader of register OSC8M"]
2pub type R = crate::R<u32, super::OSC8M>;
3#[doc = "Writer for register OSC8M"]
4pub type W = crate::W<u32, super::OSC8M>;
5#[doc = "Register OSC8M `reset()`'s with value 0x8707_0382"]
6impl crate::ResetValue for super::OSC8M {
7    type Type = u32;
8    #[inline(always)]
9    fn reset_value() -> Self::Type {
10        0x8707_0382
11    }
12}
13#[doc = "Reader of field `ENABLE`"]
14pub type ENABLE_R = crate::R<bool, bool>;
15#[doc = "Write proxy for field `ENABLE`"]
16pub struct ENABLE_W<'a> {
17    w: &'a mut W,
18}
19impl<'a> ENABLE_W<'a> {
20    #[doc = r"Sets the field bit"]
21    #[inline(always)]
22    pub fn set_bit(self) -> &'a mut W {
23        self.bit(true)
24    }
25    #[doc = r"Clears the field bit"]
26    #[inline(always)]
27    pub fn clear_bit(self) -> &'a mut W {
28        self.bit(false)
29    }
30    #[doc = r"Writes raw bits to the field"]
31    #[inline(always)]
32    pub fn bit(self, value: bool) -> &'a mut W {
33        self.w.bits = (self.w.bits & !(0x01 << 1)) | (((value as u32) & 0x01) << 1);
34        self.w
35    }
36}
37#[doc = "Reader of field `RUNSTDBY`"]
38pub type RUNSTDBY_R = crate::R<bool, bool>;
39#[doc = "Write proxy for field `RUNSTDBY`"]
40pub struct RUNSTDBY_W<'a> {
41    w: &'a mut W,
42}
43impl<'a> RUNSTDBY_W<'a> {
44    #[doc = r"Sets the field bit"]
45    #[inline(always)]
46    pub fn set_bit(self) -> &'a mut W {
47        self.bit(true)
48    }
49    #[doc = r"Clears the field bit"]
50    #[inline(always)]
51    pub fn clear_bit(self) -> &'a mut W {
52        self.bit(false)
53    }
54    #[doc = r"Writes raw bits to the field"]
55    #[inline(always)]
56    pub fn bit(self, value: bool) -> &'a mut W {
57        self.w.bits = (self.w.bits & !(0x01 << 6)) | (((value as u32) & 0x01) << 6);
58        self.w
59    }
60}
61#[doc = "Reader of field `ONDEMAND`"]
62pub type ONDEMAND_R = crate::R<bool, bool>;
63#[doc = "Write proxy for field `ONDEMAND`"]
64pub struct ONDEMAND_W<'a> {
65    w: &'a mut W,
66}
67impl<'a> ONDEMAND_W<'a> {
68    #[doc = r"Sets the field bit"]
69    #[inline(always)]
70    pub fn set_bit(self) -> &'a mut W {
71        self.bit(true)
72    }
73    #[doc = r"Clears the field bit"]
74    #[inline(always)]
75    pub fn clear_bit(self) -> &'a mut W {
76        self.bit(false)
77    }
78    #[doc = r"Writes raw bits to the field"]
79    #[inline(always)]
80    pub fn bit(self, value: bool) -> &'a mut W {
81        self.w.bits = (self.w.bits & !(0x01 << 7)) | (((value as u32) & 0x01) << 7);
82        self.w
83    }
84}
85#[doc = "Oscillator Prescaler\n\nValue on reset: 3"]
86#[derive(Clone, Copy, Debug, PartialEq)]
87#[repr(u8)]
88pub enum PRESC_A {
89    #[doc = "0: 1"]
90    _0 = 0,
91    #[doc = "1: 2"]
92    _1 = 1,
93    #[doc = "2: 4"]
94    _2 = 2,
95    #[doc = "3: 8"]
96    _3 = 3,
97}
98impl From<PRESC_A> for u8 {
99    #[inline(always)]
100    fn from(variant: PRESC_A) -> Self {
101        variant as _
102    }
103}
104#[doc = "Reader of field `PRESC`"]
105pub type PRESC_R = crate::R<u8, PRESC_A>;
106impl PRESC_R {
107    #[doc = r"Get enumerated values variant"]
108    #[inline(always)]
109    pub fn variant(&self) -> PRESC_A {
110        match self.bits {
111            0 => PRESC_A::_0,
112            1 => PRESC_A::_1,
113            2 => PRESC_A::_2,
114            3 => PRESC_A::_3,
115            _ => unreachable!(),
116        }
117    }
118    #[doc = "Checks if the value of the field is `_0`"]
119    #[inline(always)]
120    pub fn is_0(&self) -> bool {
121        *self == PRESC_A::_0
122    }
123    #[doc = "Checks if the value of the field is `_1`"]
124    #[inline(always)]
125    pub fn is_1(&self) -> bool {
126        *self == PRESC_A::_1
127    }
128    #[doc = "Checks if the value of the field is `_2`"]
129    #[inline(always)]
130    pub fn is_2(&self) -> bool {
131        *self == PRESC_A::_2
132    }
133    #[doc = "Checks if the value of the field is `_3`"]
134    #[inline(always)]
135    pub fn is_3(&self) -> bool {
136        *self == PRESC_A::_3
137    }
138}
139#[doc = "Write proxy for field `PRESC`"]
140pub struct PRESC_W<'a> {
141    w: &'a mut W,
142}
143impl<'a> PRESC_W<'a> {
144    #[doc = r"Writes `variant` to the field"]
145    #[inline(always)]
146    pub fn variant(self, variant: PRESC_A) -> &'a mut W {
147        {
148            self.bits(variant.into())
149        }
150    }
151    #[doc = "1"]
152    #[inline(always)]
153    pub fn _0(self) -> &'a mut W {
154        self.variant(PRESC_A::_0)
155    }
156    #[doc = "2"]
157    #[inline(always)]
158    pub fn _1(self) -> &'a mut W {
159        self.variant(PRESC_A::_1)
160    }
161    #[doc = "4"]
162    #[inline(always)]
163    pub fn _2(self) -> &'a mut W {
164        self.variant(PRESC_A::_2)
165    }
166    #[doc = "8"]
167    #[inline(always)]
168    pub fn _3(self) -> &'a mut W {
169        self.variant(PRESC_A::_3)
170    }
171    #[doc = r"Writes raw bits to the field"]
172    #[inline(always)]
173    pub fn bits(self, value: u8) -> &'a mut W {
174        self.w.bits = (self.w.bits & !(0x03 << 8)) | (((value as u32) & 0x03) << 8);
175        self.w
176    }
177}
178#[doc = "Reader of field `CALIB`"]
179pub type CALIB_R = crate::R<u16, u16>;
180#[doc = "Write proxy for field `CALIB`"]
181pub struct CALIB_W<'a> {
182    w: &'a mut W,
183}
184impl<'a> CALIB_W<'a> {
185    #[doc = r"Writes raw bits to the field"]
186    #[inline(always)]
187    pub unsafe fn bits(self, value: u16) -> &'a mut W {
188        self.w.bits = (self.w.bits & !(0x0fff << 16)) | (((value as u32) & 0x0fff) << 16);
189        self.w
190    }
191}
192#[doc = "Oscillator Frequency Range\n\nValue on reset: 2"]
193#[derive(Clone, Copy, Debug, PartialEq)]
194#[repr(u8)]
195pub enum FRANGE_A {
196    #[doc = "0: 4 to 6MHz"]
197    _0 = 0,
198    #[doc = "1: 6 to 8MHz"]
199    _1 = 1,
200    #[doc = "2: 8 to 11MHz"]
201    _2 = 2,
202    #[doc = "3: 11 to 15MHz"]
203    _3 = 3,
204}
205impl From<FRANGE_A> for u8 {
206    #[inline(always)]
207    fn from(variant: FRANGE_A) -> Self {
208        variant as _
209    }
210}
211#[doc = "Reader of field `FRANGE`"]
212pub type FRANGE_R = crate::R<u8, FRANGE_A>;
213impl FRANGE_R {
214    #[doc = r"Get enumerated values variant"]
215    #[inline(always)]
216    pub fn variant(&self) -> FRANGE_A {
217        match self.bits {
218            0 => FRANGE_A::_0,
219            1 => FRANGE_A::_1,
220            2 => FRANGE_A::_2,
221            3 => FRANGE_A::_3,
222            _ => unreachable!(),
223        }
224    }
225    #[doc = "Checks if the value of the field is `_0`"]
226    #[inline(always)]
227    pub fn is_0(&self) -> bool {
228        *self == FRANGE_A::_0
229    }
230    #[doc = "Checks if the value of the field is `_1`"]
231    #[inline(always)]
232    pub fn is_1(&self) -> bool {
233        *self == FRANGE_A::_1
234    }
235    #[doc = "Checks if the value of the field is `_2`"]
236    #[inline(always)]
237    pub fn is_2(&self) -> bool {
238        *self == FRANGE_A::_2
239    }
240    #[doc = "Checks if the value of the field is `_3`"]
241    #[inline(always)]
242    pub fn is_3(&self) -> bool {
243        *self == FRANGE_A::_3
244    }
245}
246#[doc = "Write proxy for field `FRANGE`"]
247pub struct FRANGE_W<'a> {
248    w: &'a mut W,
249}
250impl<'a> FRANGE_W<'a> {
251    #[doc = r"Writes `variant` to the field"]
252    #[inline(always)]
253    pub fn variant(self, variant: FRANGE_A) -> &'a mut W {
254        {
255            self.bits(variant.into())
256        }
257    }
258    #[doc = "4 to 6MHz"]
259    #[inline(always)]
260    pub fn _0(self) -> &'a mut W {
261        self.variant(FRANGE_A::_0)
262    }
263    #[doc = "6 to 8MHz"]
264    #[inline(always)]
265    pub fn _1(self) -> &'a mut W {
266        self.variant(FRANGE_A::_1)
267    }
268    #[doc = "8 to 11MHz"]
269    #[inline(always)]
270    pub fn _2(self) -> &'a mut W {
271        self.variant(FRANGE_A::_2)
272    }
273    #[doc = "11 to 15MHz"]
274    #[inline(always)]
275    pub fn _3(self) -> &'a mut W {
276        self.variant(FRANGE_A::_3)
277    }
278    #[doc = r"Writes raw bits to the field"]
279    #[inline(always)]
280    pub fn bits(self, value: u8) -> &'a mut W {
281        self.w.bits = (self.w.bits & !(0x03 << 30)) | (((value as u32) & 0x03) << 30);
282        self.w
283    }
284}
285impl R {
286    #[doc = "Bit 1 - Oscillator Enable"]
287    #[inline(always)]
288    pub fn enable(&self) -> ENABLE_R {
289        ENABLE_R::new(((self.bits >> 1) & 0x01) != 0)
290    }
291    #[doc = "Bit 6 - Run in Standby"]
292    #[inline(always)]
293    pub fn runstdby(&self) -> RUNSTDBY_R {
294        RUNSTDBY_R::new(((self.bits >> 6) & 0x01) != 0)
295    }
296    #[doc = "Bit 7 - On Demand Control"]
297    #[inline(always)]
298    pub fn ondemand(&self) -> ONDEMAND_R {
299        ONDEMAND_R::new(((self.bits >> 7) & 0x01) != 0)
300    }
301    #[doc = "Bits 8:9 - Oscillator Prescaler"]
302    #[inline(always)]
303    pub fn presc(&self) -> PRESC_R {
304        PRESC_R::new(((self.bits >> 8) & 0x03) as u8)
305    }
306    #[doc = "Bits 16:27 - Oscillator Calibration"]
307    #[inline(always)]
308    pub fn calib(&self) -> CALIB_R {
309        CALIB_R::new(((self.bits >> 16) & 0x0fff) as u16)
310    }
311    #[doc = "Bits 30:31 - Oscillator Frequency Range"]
312    #[inline(always)]
313    pub fn frange(&self) -> FRANGE_R {
314        FRANGE_R::new(((self.bits >> 30) & 0x03) as u8)
315    }
316}
317impl W {
318    #[doc = "Bit 1 - Oscillator Enable"]
319    #[inline(always)]
320    pub fn enable(&mut self) -> ENABLE_W {
321        ENABLE_W { w: self }
322    }
323    #[doc = "Bit 6 - Run in Standby"]
324    #[inline(always)]
325    pub fn runstdby(&mut self) -> RUNSTDBY_W {
326        RUNSTDBY_W { w: self }
327    }
328    #[doc = "Bit 7 - On Demand Control"]
329    #[inline(always)]
330    pub fn ondemand(&mut self) -> ONDEMAND_W {
331        ONDEMAND_W { w: self }
332    }
333    #[doc = "Bits 8:9 - Oscillator Prescaler"]
334    #[inline(always)]
335    pub fn presc(&mut self) -> PRESC_W {
336        PRESC_W { w: self }
337    }
338    #[doc = "Bits 16:27 - Oscillator Calibration"]
339    #[inline(always)]
340    pub fn calib(&mut self) -> CALIB_W {
341        CALIB_W { w: self }
342    }
343    #[doc = "Bits 30:31 - Oscillator Frequency Range"]
344    #[inline(always)]
345    pub fn frange(&mut self) -> FRANGE_W {
346        FRANGE_W { w: self }
347    }
348}