efm32pg12_pac/csen/
emactrl.rs

1#[doc = "Reader of register EMACTRL"]
2pub type R = crate::R<u32, super::EMACTRL>;
3#[doc = "Writer for register EMACTRL"]
4pub type W = crate::W<u32, super::EMACTRL>;
5#[doc = "Register EMACTRL `reset()`'s with value 0"]
6impl crate::ResetValue for super::EMACTRL {
7    type Type = u32;
8    #[inline(always)]
9    fn reset_value() -> Self::Type {
10        0
11    }
12}
13#[doc = "EMA Sample Weight\n\nValue on reset: 0"]
14#[derive(Clone, Copy, Debug, PartialEq)]
15#[repr(u8)]
16pub enum EMASAMPLE_A {
17    #[doc = "0: EMA weight (N) is 1."]
18    W1 = 0,
19    #[doc = "1: EMA weight (N) is 2."]
20    W2 = 1,
21    #[doc = "2: EMA weight (N) is 4."]
22    W4 = 2,
23    #[doc = "3: EMA weight (N) is 8."]
24    W8 = 3,
25    #[doc = "4: EMA weight (N) is 16."]
26    W16 = 4,
27    #[doc = "5: EMA weight (N) is 32."]
28    W32 = 5,
29    #[doc = "6: EMA weight (N) is 64."]
30    W64 = 6,
31}
32impl From<EMASAMPLE_A> for u8 {
33    #[inline(always)]
34    fn from(variant: EMASAMPLE_A) -> Self {
35        variant as _
36    }
37}
38#[doc = "Reader of field `EMASAMPLE`"]
39pub type EMASAMPLE_R = crate::R<u8, EMASAMPLE_A>;
40impl EMASAMPLE_R {
41    #[doc = r"Get enumerated values variant"]
42    #[inline(always)]
43    pub fn variant(&self) -> crate::Variant<u8, EMASAMPLE_A> {
44        use crate::Variant::*;
45        match self.bits {
46            0 => Val(EMASAMPLE_A::W1),
47            1 => Val(EMASAMPLE_A::W2),
48            2 => Val(EMASAMPLE_A::W4),
49            3 => Val(EMASAMPLE_A::W8),
50            4 => Val(EMASAMPLE_A::W16),
51            5 => Val(EMASAMPLE_A::W32),
52            6 => Val(EMASAMPLE_A::W64),
53            i => Res(i),
54        }
55    }
56    #[doc = "Checks if the value of the field is `W1`"]
57    #[inline(always)]
58    pub fn is_w1(&self) -> bool {
59        *self == EMASAMPLE_A::W1
60    }
61    #[doc = "Checks if the value of the field is `W2`"]
62    #[inline(always)]
63    pub fn is_w2(&self) -> bool {
64        *self == EMASAMPLE_A::W2
65    }
66    #[doc = "Checks if the value of the field is `W4`"]
67    #[inline(always)]
68    pub fn is_w4(&self) -> bool {
69        *self == EMASAMPLE_A::W4
70    }
71    #[doc = "Checks if the value of the field is `W8`"]
72    #[inline(always)]
73    pub fn is_w8(&self) -> bool {
74        *self == EMASAMPLE_A::W8
75    }
76    #[doc = "Checks if the value of the field is `W16`"]
77    #[inline(always)]
78    pub fn is_w16(&self) -> bool {
79        *self == EMASAMPLE_A::W16
80    }
81    #[doc = "Checks if the value of the field is `W32`"]
82    #[inline(always)]
83    pub fn is_w32(&self) -> bool {
84        *self == EMASAMPLE_A::W32
85    }
86    #[doc = "Checks if the value of the field is `W64`"]
87    #[inline(always)]
88    pub fn is_w64(&self) -> bool {
89        *self == EMASAMPLE_A::W64
90    }
91}
92#[doc = "Write proxy for field `EMASAMPLE`"]
93pub struct EMASAMPLE_W<'a> {
94    w: &'a mut W,
95}
96impl<'a> EMASAMPLE_W<'a> {
97    #[doc = r"Writes `variant` to the field"]
98    #[inline(always)]
99    pub fn variant(self, variant: EMASAMPLE_A) -> &'a mut W {
100        unsafe { self.bits(variant.into()) }
101    }
102    #[doc = "EMA weight (N) is 1."]
103    #[inline(always)]
104    pub fn w1(self) -> &'a mut W {
105        self.variant(EMASAMPLE_A::W1)
106    }
107    #[doc = "EMA weight (N) is 2."]
108    #[inline(always)]
109    pub fn w2(self) -> &'a mut W {
110        self.variant(EMASAMPLE_A::W2)
111    }
112    #[doc = "EMA weight (N) is 4."]
113    #[inline(always)]
114    pub fn w4(self) -> &'a mut W {
115        self.variant(EMASAMPLE_A::W4)
116    }
117    #[doc = "EMA weight (N) is 8."]
118    #[inline(always)]
119    pub fn w8(self) -> &'a mut W {
120        self.variant(EMASAMPLE_A::W8)
121    }
122    #[doc = "EMA weight (N) is 16."]
123    #[inline(always)]
124    pub fn w16(self) -> &'a mut W {
125        self.variant(EMASAMPLE_A::W16)
126    }
127    #[doc = "EMA weight (N) is 32."]
128    #[inline(always)]
129    pub fn w32(self) -> &'a mut W {
130        self.variant(EMASAMPLE_A::W32)
131    }
132    #[doc = "EMA weight (N) is 64."]
133    #[inline(always)]
134    pub fn w64(self) -> &'a mut W {
135        self.variant(EMASAMPLE_A::W64)
136    }
137    #[doc = r"Writes raw bits to the field"]
138    #[inline(always)]
139    pub unsafe fn bits(self, value: u8) -> &'a mut W {
140        self.w.bits = (self.w.bits & !0x07) | ((value as u32) & 0x07);
141        self.w
142    }
143}
144impl R {
145    #[doc = "Bits 0:2 - EMA Sample Weight"]
146    #[inline(always)]
147    pub fn emasample(&self) -> EMASAMPLE_R {
148        EMASAMPLE_R::new((self.bits & 0x07) as u8)
149    }
150}
151impl W {
152    #[doc = "Bits 0:2 - EMA Sample Weight"]
153    #[inline(always)]
154    pub fn emasample(&mut self) -> EMASAMPLE_W {
155        EMASAMPLE_W { w: self }
156    }
157}