ra4m2/can0/
bcr.rs

1#[doc = "Register `BCR` reader"]
2pub struct R(crate::R<BCR_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<BCR_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<BCR_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<BCR_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `BCR` writer"]
17pub struct W(crate::W<BCR_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<BCR_SPEC>;
20    #[inline(always)]
21    fn deref(&self) -> &Self::Target {
22        &self.0
23    }
24}
25impl core::ops::DerefMut for W {
26    #[inline(always)]
27    fn deref_mut(&mut self) -> &mut Self::Target {
28        &mut self.0
29    }
30}
31impl From<crate::W<BCR_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<BCR_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `CCLKS` reader - CAN Clock Source Selection"]
38pub type CCLKS_R = crate::BitReader<CCLKS_A>;
39#[doc = "CAN Clock Source Selection\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41pub enum CCLKS_A {
42    #[doc = "0: PCLKB (generated by the PLL clock)"]
43    _0 = 0,
44    #[doc = "1: CANMCLK (generated by the main clock oscillator)"]
45    _1 = 1,
46}
47impl From<CCLKS_A> for bool {
48    #[inline(always)]
49    fn from(variant: CCLKS_A) -> Self {
50        variant as u8 != 0
51    }
52}
53impl CCLKS_R {
54    #[doc = "Get enumerated values variant"]
55    #[inline(always)]
56    pub fn variant(&self) -> CCLKS_A {
57        match self.bits {
58            false => CCLKS_A::_0,
59            true => CCLKS_A::_1,
60        }
61    }
62    #[doc = "Checks if the value of the field is `_0`"]
63    #[inline(always)]
64    pub fn is_0(&self) -> bool {
65        *self == CCLKS_A::_0
66    }
67    #[doc = "Checks if the value of the field is `_1`"]
68    #[inline(always)]
69    pub fn is_1(&self) -> bool {
70        *self == CCLKS_A::_1
71    }
72}
73#[doc = "Field `CCLKS` writer - CAN Clock Source Selection"]
74pub type CCLKS_W<'a, const O: u8> = crate::BitWriter<'a, u32, BCR_SPEC, CCLKS_A, O>;
75impl<'a, const O: u8> CCLKS_W<'a, O> {
76    #[doc = "PCLKB (generated by the PLL clock)"]
77    #[inline(always)]
78    pub fn _0(self) -> &'a mut W {
79        self.variant(CCLKS_A::_0)
80    }
81    #[doc = "CANMCLK (generated by the main clock oscillator)"]
82    #[inline(always)]
83    pub fn _1(self) -> &'a mut W {
84        self.variant(CCLKS_A::_1)
85    }
86}
87#[doc = "Field `TSEG2` reader - Time Segment 2 Control"]
88pub type TSEG2_R = crate::FieldReader<u8, TSEG2_A>;
89#[doc = "Time Segment 2 Control\n\nValue on reset: 0"]
90#[derive(Clone, Copy, Debug, PartialEq, Eq)]
91#[repr(u8)]
92pub enum TSEG2_A {
93    #[doc = "0: Setting prohibited"]
94    _000 = 0,
95    #[doc = "1: 2 Tq"]
96    _001 = 1,
97    #[doc = "2: 3 Tq"]
98    _010 = 2,
99    #[doc = "3: 4 Tq"]
100    _011 = 3,
101    #[doc = "4: 5 Tq"]
102    _100 = 4,
103    #[doc = "5: 6 Tq"]
104    _101 = 5,
105    #[doc = "6: 7 Tq"]
106    _110 = 6,
107    #[doc = "7: 8 Tq"]
108    _111 = 7,
109}
110impl From<TSEG2_A> for u8 {
111    #[inline(always)]
112    fn from(variant: TSEG2_A) -> Self {
113        variant as _
114    }
115}
116impl TSEG2_R {
117    #[doc = "Get enumerated values variant"]
118    #[inline(always)]
119    pub fn variant(&self) -> TSEG2_A {
120        match self.bits {
121            0 => TSEG2_A::_000,
122            1 => TSEG2_A::_001,
123            2 => TSEG2_A::_010,
124            3 => TSEG2_A::_011,
125            4 => TSEG2_A::_100,
126            5 => TSEG2_A::_101,
127            6 => TSEG2_A::_110,
128            7 => TSEG2_A::_111,
129            _ => unreachable!(),
130        }
131    }
132    #[doc = "Checks if the value of the field is `_000`"]
133    #[inline(always)]
134    pub fn is_000(&self) -> bool {
135        *self == TSEG2_A::_000
136    }
137    #[doc = "Checks if the value of the field is `_001`"]
138    #[inline(always)]
139    pub fn is_001(&self) -> bool {
140        *self == TSEG2_A::_001
141    }
142    #[doc = "Checks if the value of the field is `_010`"]
143    #[inline(always)]
144    pub fn is_010(&self) -> bool {
145        *self == TSEG2_A::_010
146    }
147    #[doc = "Checks if the value of the field is `_011`"]
148    #[inline(always)]
149    pub fn is_011(&self) -> bool {
150        *self == TSEG2_A::_011
151    }
152    #[doc = "Checks if the value of the field is `_100`"]
153    #[inline(always)]
154    pub fn is_100(&self) -> bool {
155        *self == TSEG2_A::_100
156    }
157    #[doc = "Checks if the value of the field is `_101`"]
158    #[inline(always)]
159    pub fn is_101(&self) -> bool {
160        *self == TSEG2_A::_101
161    }
162    #[doc = "Checks if the value of the field is `_110`"]
163    #[inline(always)]
164    pub fn is_110(&self) -> bool {
165        *self == TSEG2_A::_110
166    }
167    #[doc = "Checks if the value of the field is `_111`"]
168    #[inline(always)]
169    pub fn is_111(&self) -> bool {
170        *self == TSEG2_A::_111
171    }
172}
173#[doc = "Field `TSEG2` writer - Time Segment 2 Control"]
174pub type TSEG2_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u32, BCR_SPEC, u8, TSEG2_A, 3, O>;
175impl<'a, const O: u8> TSEG2_W<'a, O> {
176    #[doc = "Setting prohibited"]
177    #[inline(always)]
178    pub fn _000(self) -> &'a mut W {
179        self.variant(TSEG2_A::_000)
180    }
181    #[doc = "2 Tq"]
182    #[inline(always)]
183    pub fn _001(self) -> &'a mut W {
184        self.variant(TSEG2_A::_001)
185    }
186    #[doc = "3 Tq"]
187    #[inline(always)]
188    pub fn _010(self) -> &'a mut W {
189        self.variant(TSEG2_A::_010)
190    }
191    #[doc = "4 Tq"]
192    #[inline(always)]
193    pub fn _011(self) -> &'a mut W {
194        self.variant(TSEG2_A::_011)
195    }
196    #[doc = "5 Tq"]
197    #[inline(always)]
198    pub fn _100(self) -> &'a mut W {
199        self.variant(TSEG2_A::_100)
200    }
201    #[doc = "6 Tq"]
202    #[inline(always)]
203    pub fn _101(self) -> &'a mut W {
204        self.variant(TSEG2_A::_101)
205    }
206    #[doc = "7 Tq"]
207    #[inline(always)]
208    pub fn _110(self) -> &'a mut W {
209        self.variant(TSEG2_A::_110)
210    }
211    #[doc = "8 Tq"]
212    #[inline(always)]
213    pub fn _111(self) -> &'a mut W {
214        self.variant(TSEG2_A::_111)
215    }
216}
217#[doc = "Field `SJW` reader - Synchronization Jump Width Control"]
218pub type SJW_R = crate::FieldReader<u8, SJW_A>;
219#[doc = "Synchronization Jump Width Control\n\nValue on reset: 0"]
220#[derive(Clone, Copy, Debug, PartialEq, Eq)]
221#[repr(u8)]
222pub enum SJW_A {
223    #[doc = "0: 1 Tq"]
224    _00 = 0,
225    #[doc = "1: 2 Tq"]
226    _01 = 1,
227    #[doc = "2: 3 Tq"]
228    _10 = 2,
229    #[doc = "3: 4 Tq"]
230    _11 = 3,
231}
232impl From<SJW_A> for u8 {
233    #[inline(always)]
234    fn from(variant: SJW_A) -> Self {
235        variant as _
236    }
237}
238impl SJW_R {
239    #[doc = "Get enumerated values variant"]
240    #[inline(always)]
241    pub fn variant(&self) -> SJW_A {
242        match self.bits {
243            0 => SJW_A::_00,
244            1 => SJW_A::_01,
245            2 => SJW_A::_10,
246            3 => SJW_A::_11,
247            _ => unreachable!(),
248        }
249    }
250    #[doc = "Checks if the value of the field is `_00`"]
251    #[inline(always)]
252    pub fn is_00(&self) -> bool {
253        *self == SJW_A::_00
254    }
255    #[doc = "Checks if the value of the field is `_01`"]
256    #[inline(always)]
257    pub fn is_01(&self) -> bool {
258        *self == SJW_A::_01
259    }
260    #[doc = "Checks if the value of the field is `_10`"]
261    #[inline(always)]
262    pub fn is_10(&self) -> bool {
263        *self == SJW_A::_10
264    }
265    #[doc = "Checks if the value of the field is `_11`"]
266    #[inline(always)]
267    pub fn is_11(&self) -> bool {
268        *self == SJW_A::_11
269    }
270}
271#[doc = "Field `SJW` writer - Synchronization Jump Width Control"]
272pub type SJW_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u32, BCR_SPEC, u8, SJW_A, 2, O>;
273impl<'a, const O: u8> SJW_W<'a, O> {
274    #[doc = "1 Tq"]
275    #[inline(always)]
276    pub fn _00(self) -> &'a mut W {
277        self.variant(SJW_A::_00)
278    }
279    #[doc = "2 Tq"]
280    #[inline(always)]
281    pub fn _01(self) -> &'a mut W {
282        self.variant(SJW_A::_01)
283    }
284    #[doc = "3 Tq"]
285    #[inline(always)]
286    pub fn _10(self) -> &'a mut W {
287        self.variant(SJW_A::_10)
288    }
289    #[doc = "4 Tq"]
290    #[inline(always)]
291    pub fn _11(self) -> &'a mut W {
292        self.variant(SJW_A::_11)
293    }
294}
295#[doc = "Field `BRP` reader - Baud Rate Prescaler Select"]
296pub type BRP_R = crate::FieldReader<u16, u16>;
297#[doc = "Field `BRP` writer - Baud Rate Prescaler Select"]
298pub type BRP_W<'a, const O: u8> = crate::FieldWriter<'a, u32, BCR_SPEC, u16, u16, 10, O>;
299#[doc = "Field `TSEG1` reader - Time Segment 1 Control"]
300pub type TSEG1_R = crate::FieldReader<u8, TSEG1_A>;
301#[doc = "Time Segment 1 Control\n\nValue on reset: 0"]
302#[derive(Clone, Copy, Debug, PartialEq, Eq)]
303#[repr(u8)]
304pub enum TSEG1_A {
305    #[doc = "3: 4 Tq"]
306    _0X3 = 3,
307    #[doc = "4: 5 Tq"]
308    _0X4 = 4,
309    #[doc = "5: 6 Tq"]
310    _0X5 = 5,
311    #[doc = "6: 7 Tq"]
312    _0X6 = 6,
313    #[doc = "7: 8 Tq"]
314    _0X7 = 7,
315    #[doc = "8: 9 Tq"]
316    _0X8 = 8,
317    #[doc = "9: 10 Tq"]
318    _0X9 = 9,
319    #[doc = "10: 11 Tq"]
320    _0X_A = 10,
321    #[doc = "11: 12 Tq"]
322    _0X_B = 11,
323    #[doc = "12: 13 Tq"]
324    _0X_C = 12,
325    #[doc = "13: 14 Tq"]
326    _0X_D = 13,
327    #[doc = "14: 15 Tq"]
328    _0X_E = 14,
329    #[doc = "15: 16 Tq"]
330    _0X_F = 15,
331}
332impl From<TSEG1_A> for u8 {
333    #[inline(always)]
334    fn from(variant: TSEG1_A) -> Self {
335        variant as _
336    }
337}
338impl TSEG1_R {
339    #[doc = "Get enumerated values variant"]
340    #[inline(always)]
341    pub fn variant(&self) -> Option<TSEG1_A> {
342        match self.bits {
343            3 => Some(TSEG1_A::_0X3),
344            4 => Some(TSEG1_A::_0X4),
345            5 => Some(TSEG1_A::_0X5),
346            6 => Some(TSEG1_A::_0X6),
347            7 => Some(TSEG1_A::_0X7),
348            8 => Some(TSEG1_A::_0X8),
349            9 => Some(TSEG1_A::_0X9),
350            10 => Some(TSEG1_A::_0X_A),
351            11 => Some(TSEG1_A::_0X_B),
352            12 => Some(TSEG1_A::_0X_C),
353            13 => Some(TSEG1_A::_0X_D),
354            14 => Some(TSEG1_A::_0X_E),
355            15 => Some(TSEG1_A::_0X_F),
356            _ => None,
357        }
358    }
359    #[doc = "Checks if the value of the field is `_0X3`"]
360    #[inline(always)]
361    pub fn is_0x3(&self) -> bool {
362        *self == TSEG1_A::_0X3
363    }
364    #[doc = "Checks if the value of the field is `_0X4`"]
365    #[inline(always)]
366    pub fn is_0x4(&self) -> bool {
367        *self == TSEG1_A::_0X4
368    }
369    #[doc = "Checks if the value of the field is `_0X5`"]
370    #[inline(always)]
371    pub fn is_0x5(&self) -> bool {
372        *self == TSEG1_A::_0X5
373    }
374    #[doc = "Checks if the value of the field is `_0X6`"]
375    #[inline(always)]
376    pub fn is_0x6(&self) -> bool {
377        *self == TSEG1_A::_0X6
378    }
379    #[doc = "Checks if the value of the field is `_0X7`"]
380    #[inline(always)]
381    pub fn is_0x7(&self) -> bool {
382        *self == TSEG1_A::_0X7
383    }
384    #[doc = "Checks if the value of the field is `_0X8`"]
385    #[inline(always)]
386    pub fn is_0x8(&self) -> bool {
387        *self == TSEG1_A::_0X8
388    }
389    #[doc = "Checks if the value of the field is `_0X9`"]
390    #[inline(always)]
391    pub fn is_0x9(&self) -> bool {
392        *self == TSEG1_A::_0X9
393    }
394    #[doc = "Checks if the value of the field is `_0X_A`"]
395    #[inline(always)]
396    pub fn is_0x_a(&self) -> bool {
397        *self == TSEG1_A::_0X_A
398    }
399    #[doc = "Checks if the value of the field is `_0X_B`"]
400    #[inline(always)]
401    pub fn is_0x_b(&self) -> bool {
402        *self == TSEG1_A::_0X_B
403    }
404    #[doc = "Checks if the value of the field is `_0X_C`"]
405    #[inline(always)]
406    pub fn is_0x_c(&self) -> bool {
407        *self == TSEG1_A::_0X_C
408    }
409    #[doc = "Checks if the value of the field is `_0X_D`"]
410    #[inline(always)]
411    pub fn is_0x_d(&self) -> bool {
412        *self == TSEG1_A::_0X_D
413    }
414    #[doc = "Checks if the value of the field is `_0X_E`"]
415    #[inline(always)]
416    pub fn is_0x_e(&self) -> bool {
417        *self == TSEG1_A::_0X_E
418    }
419    #[doc = "Checks if the value of the field is `_0X_F`"]
420    #[inline(always)]
421    pub fn is_0x_f(&self) -> bool {
422        *self == TSEG1_A::_0X_F
423    }
424}
425#[doc = "Field `TSEG1` writer - Time Segment 1 Control"]
426pub type TSEG1_W<'a, const O: u8> = crate::FieldWriter<'a, u32, BCR_SPEC, u8, TSEG1_A, 4, O>;
427impl<'a, const O: u8> TSEG1_W<'a, O> {
428    #[doc = "4 Tq"]
429    #[inline(always)]
430    pub fn _0x3(self) -> &'a mut W {
431        self.variant(TSEG1_A::_0X3)
432    }
433    #[doc = "5 Tq"]
434    #[inline(always)]
435    pub fn _0x4(self) -> &'a mut W {
436        self.variant(TSEG1_A::_0X4)
437    }
438    #[doc = "6 Tq"]
439    #[inline(always)]
440    pub fn _0x5(self) -> &'a mut W {
441        self.variant(TSEG1_A::_0X5)
442    }
443    #[doc = "7 Tq"]
444    #[inline(always)]
445    pub fn _0x6(self) -> &'a mut W {
446        self.variant(TSEG1_A::_0X6)
447    }
448    #[doc = "8 Tq"]
449    #[inline(always)]
450    pub fn _0x7(self) -> &'a mut W {
451        self.variant(TSEG1_A::_0X7)
452    }
453    #[doc = "9 Tq"]
454    #[inline(always)]
455    pub fn _0x8(self) -> &'a mut W {
456        self.variant(TSEG1_A::_0X8)
457    }
458    #[doc = "10 Tq"]
459    #[inline(always)]
460    pub fn _0x9(self) -> &'a mut W {
461        self.variant(TSEG1_A::_0X9)
462    }
463    #[doc = "11 Tq"]
464    #[inline(always)]
465    pub fn _0x_a(self) -> &'a mut W {
466        self.variant(TSEG1_A::_0X_A)
467    }
468    #[doc = "12 Tq"]
469    #[inline(always)]
470    pub fn _0x_b(self) -> &'a mut W {
471        self.variant(TSEG1_A::_0X_B)
472    }
473    #[doc = "13 Tq"]
474    #[inline(always)]
475    pub fn _0x_c(self) -> &'a mut W {
476        self.variant(TSEG1_A::_0X_C)
477    }
478    #[doc = "14 Tq"]
479    #[inline(always)]
480    pub fn _0x_d(self) -> &'a mut W {
481        self.variant(TSEG1_A::_0X_D)
482    }
483    #[doc = "15 Tq"]
484    #[inline(always)]
485    pub fn _0x_e(self) -> &'a mut W {
486        self.variant(TSEG1_A::_0X_E)
487    }
488    #[doc = "16 Tq"]
489    #[inline(always)]
490    pub fn _0x_f(self) -> &'a mut W {
491        self.variant(TSEG1_A::_0X_F)
492    }
493}
494impl R {
495    #[doc = "Bit 0 - CAN Clock Source Selection"]
496    #[inline(always)]
497    pub fn cclks(&self) -> CCLKS_R {
498        CCLKS_R::new((self.bits & 1) != 0)
499    }
500    #[doc = "Bits 8:10 - Time Segment 2 Control"]
501    #[inline(always)]
502    pub fn tseg2(&self) -> TSEG2_R {
503        TSEG2_R::new(((self.bits >> 8) & 7) as u8)
504    }
505    #[doc = "Bits 12:13 - Synchronization Jump Width Control"]
506    #[inline(always)]
507    pub fn sjw(&self) -> SJW_R {
508        SJW_R::new(((self.bits >> 12) & 3) as u8)
509    }
510    #[doc = "Bits 16:25 - Baud Rate Prescaler Select"]
511    #[inline(always)]
512    pub fn brp(&self) -> BRP_R {
513        BRP_R::new(((self.bits >> 16) & 0x03ff) as u16)
514    }
515    #[doc = "Bits 28:31 - Time Segment 1 Control"]
516    #[inline(always)]
517    pub fn tseg1(&self) -> TSEG1_R {
518        TSEG1_R::new(((self.bits >> 28) & 0x0f) as u8)
519    }
520}
521impl W {
522    #[doc = "Bit 0 - CAN Clock Source Selection"]
523    #[inline(always)]
524    #[must_use]
525    pub fn cclks(&mut self) -> CCLKS_W<0> {
526        CCLKS_W::new(self)
527    }
528    #[doc = "Bits 8:10 - Time Segment 2 Control"]
529    #[inline(always)]
530    #[must_use]
531    pub fn tseg2(&mut self) -> TSEG2_W<8> {
532        TSEG2_W::new(self)
533    }
534    #[doc = "Bits 12:13 - Synchronization Jump Width Control"]
535    #[inline(always)]
536    #[must_use]
537    pub fn sjw(&mut self) -> SJW_W<12> {
538        SJW_W::new(self)
539    }
540    #[doc = "Bits 16:25 - Baud Rate Prescaler Select"]
541    #[inline(always)]
542    #[must_use]
543    pub fn brp(&mut self) -> BRP_W<16> {
544        BRP_W::new(self)
545    }
546    #[doc = "Bits 28:31 - Time Segment 1 Control"]
547    #[inline(always)]
548    #[must_use]
549    pub fn tseg1(&mut self) -> TSEG1_W<28> {
550        TSEG1_W::new(self)
551    }
552    #[doc = "Writes raw bits to the register."]
553    #[inline(always)]
554    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
555        self.0.bits(bits);
556        self
557    }
558}
559#[doc = "Bit Configuration Register\n\nThis register you can [`read`](crate::generic::Reg::read), [`write_with_zero`](crate::generic::Reg::write_with_zero), [`reset`](crate::generic::Reg::reset), [`write`](crate::generic::Reg::write), [`modify`](crate::generic::Reg::modify). See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [bcr](index.html) module"]
560pub struct BCR_SPEC;
561impl crate::RegisterSpec for BCR_SPEC {
562    type Ux = u32;
563}
564#[doc = "`read()` method returns [bcr::R](R) reader structure"]
565impl crate::Readable for BCR_SPEC {
566    type Reader = R;
567}
568#[doc = "`write(|w| ..)` method takes [bcr::W](W) writer structure"]
569impl crate::Writable for BCR_SPEC {
570    type Writer = W;
571    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
572    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
573}
574#[doc = "`reset()` method sets BCR to value 0"]
575impl crate::Resettable for BCR_SPEC {
576    const RESET_VALUE: Self::Ux = 0;
577}