efm32pg12_pac/lesense/
ch1_eval.rs

1#[doc = "Reader of register CH1_EVAL"]
2pub type R = crate::R<u32, super::CH1_EVAL>;
3#[doc = "Writer for register CH1_EVAL"]
4pub type W = crate::W<u32, super::CH1_EVAL>;
5#[doc = "Register CH1_EVAL `reset()`'s with value 0"]
6impl crate::ResetValue for super::CH1_EVAL {
7    type Type = u32;
8    #[inline(always)]
9    fn reset_value() -> Self::Type {
10        0
11    }
12}
13#[doc = "Reader of field `COMPTHRES`"]
14pub type COMPTHRES_R = crate::R<u16, u16>;
15#[doc = "Write proxy for field `COMPTHRES`"]
16pub struct COMPTHRES_W<'a> {
17    w: &'a mut W,
18}
19impl<'a> COMPTHRES_W<'a> {
20    #[doc = r"Writes raw bits to the field"]
21    #[inline(always)]
22    pub unsafe fn bits(self, value: u16) -> &'a mut W {
23        self.w.bits = (self.w.bits & !0xffff) | ((value as u32) & 0xffff);
24        self.w
25    }
26}
27#[doc = "Reader of field `COMP`"]
28pub type COMP_R = crate::R<bool, bool>;
29#[doc = "Write proxy for field `COMP`"]
30pub struct COMP_W<'a> {
31    w: &'a mut W,
32}
33impl<'a> COMP_W<'a> {
34    #[doc = r"Sets the field bit"]
35    #[inline(always)]
36    pub fn set_bit(self) -> &'a mut W {
37        self.bit(true)
38    }
39    #[doc = r"Clears the field bit"]
40    #[inline(always)]
41    pub fn clear_bit(self) -> &'a mut W {
42        self.bit(false)
43    }
44    #[doc = r"Writes raw bits to the field"]
45    #[inline(always)]
46    pub fn bit(self, value: bool) -> &'a mut W {
47        self.w.bits = (self.w.bits & !(0x01 << 16)) | (((value as u32) & 0x01) << 16);
48        self.w
49    }
50}
51#[doc = "Reader of field `DECODE`"]
52pub type DECODE_R = crate::R<bool, bool>;
53#[doc = "Write proxy for field `DECODE`"]
54pub struct DECODE_W<'a> {
55    w: &'a mut W,
56}
57impl<'a> DECODE_W<'a> {
58    #[doc = r"Sets the field bit"]
59    #[inline(always)]
60    pub fn set_bit(self) -> &'a mut W {
61        self.bit(true)
62    }
63    #[doc = r"Clears the field bit"]
64    #[inline(always)]
65    pub fn clear_bit(self) -> &'a mut W {
66        self.bit(false)
67    }
68    #[doc = r"Writes raw bits to the field"]
69    #[inline(always)]
70    pub fn bit(self, value: bool) -> &'a mut W {
71        self.w.bits = (self.w.bits & !(0x01 << 17)) | (((value as u32) & 0x01) << 17);
72        self.w
73    }
74}
75#[doc = "Enable Storing of Sensor Sample in Result Buffer\n\nValue on reset: 0"]
76#[derive(Clone, Copy, Debug, PartialEq)]
77#[repr(u8)]
78pub enum STRSAMPLE_A {
79    #[doc = "0: Nothing will be stored in the result buffer."]
80    DISABLE = 0,
81    #[doc = "1: The sensor sample data will be stored in the result buffer."]
82    DATA = 1,
83    #[doc = "2: The data source (i.e., the channel) will be stored alongside the sensor sample data."]
84    DATASRC = 2,
85}
86impl From<STRSAMPLE_A> for u8 {
87    #[inline(always)]
88    fn from(variant: STRSAMPLE_A) -> Self {
89        variant as _
90    }
91}
92#[doc = "Reader of field `STRSAMPLE`"]
93pub type STRSAMPLE_R = crate::R<u8, STRSAMPLE_A>;
94impl STRSAMPLE_R {
95    #[doc = r"Get enumerated values variant"]
96    #[inline(always)]
97    pub fn variant(&self) -> crate::Variant<u8, STRSAMPLE_A> {
98        use crate::Variant::*;
99        match self.bits {
100            0 => Val(STRSAMPLE_A::DISABLE),
101            1 => Val(STRSAMPLE_A::DATA),
102            2 => Val(STRSAMPLE_A::DATASRC),
103            i => Res(i),
104        }
105    }
106    #[doc = "Checks if the value of the field is `DISABLE`"]
107    #[inline(always)]
108    pub fn is_disable(&self) -> bool {
109        *self == STRSAMPLE_A::DISABLE
110    }
111    #[doc = "Checks if the value of the field is `DATA`"]
112    #[inline(always)]
113    pub fn is_data(&self) -> bool {
114        *self == STRSAMPLE_A::DATA
115    }
116    #[doc = "Checks if the value of the field is `DATASRC`"]
117    #[inline(always)]
118    pub fn is_datasrc(&self) -> bool {
119        *self == STRSAMPLE_A::DATASRC
120    }
121}
122#[doc = "Write proxy for field `STRSAMPLE`"]
123pub struct STRSAMPLE_W<'a> {
124    w: &'a mut W,
125}
126impl<'a> STRSAMPLE_W<'a> {
127    #[doc = r"Writes `variant` to the field"]
128    #[inline(always)]
129    pub fn variant(self, variant: STRSAMPLE_A) -> &'a mut W {
130        unsafe { self.bits(variant.into()) }
131    }
132    #[doc = "Nothing will be stored in the result buffer."]
133    #[inline(always)]
134    pub fn disable(self) -> &'a mut W {
135        self.variant(STRSAMPLE_A::DISABLE)
136    }
137    #[doc = "The sensor sample data will be stored in the result buffer."]
138    #[inline(always)]
139    pub fn data(self) -> &'a mut W {
140        self.variant(STRSAMPLE_A::DATA)
141    }
142    #[doc = "The data source (i.e., the channel) will be stored alongside the sensor sample data."]
143    #[inline(always)]
144    pub fn datasrc(self) -> &'a mut W {
145        self.variant(STRSAMPLE_A::DATASRC)
146    }
147    #[doc = r"Writes raw bits to the field"]
148    #[inline(always)]
149    pub unsafe fn bits(self, value: u8) -> &'a mut W {
150        self.w.bits = (self.w.bits & !(0x03 << 18)) | (((value as u32) & 0x03) << 18);
151        self.w
152    }
153}
154#[doc = "Reader of field `SCANRESINV`"]
155pub type SCANRESINV_R = crate::R<bool, bool>;
156#[doc = "Write proxy for field `SCANRESINV`"]
157pub struct SCANRESINV_W<'a> {
158    w: &'a mut W,
159}
160impl<'a> SCANRESINV_W<'a> {
161    #[doc = r"Sets the field bit"]
162    #[inline(always)]
163    pub fn set_bit(self) -> &'a mut W {
164        self.bit(true)
165    }
166    #[doc = r"Clears the field bit"]
167    #[inline(always)]
168    pub fn clear_bit(self) -> &'a mut W {
169        self.bit(false)
170    }
171    #[doc = r"Writes raw bits to the field"]
172    #[inline(always)]
173    pub fn bit(self, value: bool) -> &'a mut W {
174        self.w.bits = (self.w.bits & !(0x01 << 20)) | (((value as u32) & 0x01) << 20);
175        self.w
176    }
177}
178#[doc = "Configure Evaluation Mode\n\nValue on reset: 0"]
179#[derive(Clone, Copy, Debug, PartialEq)]
180#[repr(u8)]
181pub enum MODE_A {
182    #[doc = "0: Threshold comparison is used to evaluate sensor result"]
183    THRES = 0,
184    #[doc = "1: Sliding window is used to evaluate sensor result"]
185    SLIDINGWIN = 1,
186    #[doc = "2: Step detection is used to evaluate sensor result"]
187    STEPDET = 2,
188}
189impl From<MODE_A> for u8 {
190    #[inline(always)]
191    fn from(variant: MODE_A) -> Self {
192        variant as _
193    }
194}
195#[doc = "Reader of field `MODE`"]
196pub type MODE_R = crate::R<u8, MODE_A>;
197impl MODE_R {
198    #[doc = r"Get enumerated values variant"]
199    #[inline(always)]
200    pub fn variant(&self) -> crate::Variant<u8, MODE_A> {
201        use crate::Variant::*;
202        match self.bits {
203            0 => Val(MODE_A::THRES),
204            1 => Val(MODE_A::SLIDINGWIN),
205            2 => Val(MODE_A::STEPDET),
206            i => Res(i),
207        }
208    }
209    #[doc = "Checks if the value of the field is `THRES`"]
210    #[inline(always)]
211    pub fn is_thres(&self) -> bool {
212        *self == MODE_A::THRES
213    }
214    #[doc = "Checks if the value of the field is `SLIDINGWIN`"]
215    #[inline(always)]
216    pub fn is_slidingwin(&self) -> bool {
217        *self == MODE_A::SLIDINGWIN
218    }
219    #[doc = "Checks if the value of the field is `STEPDET`"]
220    #[inline(always)]
221    pub fn is_stepdet(&self) -> bool {
222        *self == MODE_A::STEPDET
223    }
224}
225#[doc = "Write proxy for field `MODE`"]
226pub struct MODE_W<'a> {
227    w: &'a mut W,
228}
229impl<'a> MODE_W<'a> {
230    #[doc = r"Writes `variant` to the field"]
231    #[inline(always)]
232    pub fn variant(self, variant: MODE_A) -> &'a mut W {
233        unsafe { self.bits(variant.into()) }
234    }
235    #[doc = "Threshold comparison is used to evaluate sensor result"]
236    #[inline(always)]
237    pub fn thres(self) -> &'a mut W {
238        self.variant(MODE_A::THRES)
239    }
240    #[doc = "Sliding window is used to evaluate sensor result"]
241    #[inline(always)]
242    pub fn slidingwin(self) -> &'a mut W {
243        self.variant(MODE_A::SLIDINGWIN)
244    }
245    #[doc = "Step detection is used to evaluate sensor result"]
246    #[inline(always)]
247    pub fn stepdet(self) -> &'a mut W {
248        self.variant(MODE_A::STEPDET)
249    }
250    #[doc = r"Writes raw bits to the field"]
251    #[inline(always)]
252    pub unsafe fn bits(self, value: u8) -> &'a mut W {
253        self.w.bits = (self.w.bits & !(0x03 << 21)) | (((value as u32) & 0x03) << 21);
254        self.w
255    }
256}
257impl R {
258    #[doc = "Bits 0:15 - Decision Threshold for Sensor Data"]
259    #[inline(always)]
260    pub fn compthres(&self) -> COMPTHRES_R {
261        COMPTHRES_R::new((self.bits & 0xffff) as u16)
262    }
263    #[doc = "Bit 16 - Select Mode for Threshold Comparison"]
264    #[inline(always)]
265    pub fn comp(&self) -> COMP_R {
266        COMP_R::new(((self.bits >> 16) & 0x01) != 0)
267    }
268    #[doc = "Bit 17 - Send Result to Decoder"]
269    #[inline(always)]
270    pub fn decode(&self) -> DECODE_R {
271        DECODE_R::new(((self.bits >> 17) & 0x01) != 0)
272    }
273    #[doc = "Bits 18:19 - Enable Storing of Sensor Sample in Result Buffer"]
274    #[inline(always)]
275    pub fn strsample(&self) -> STRSAMPLE_R {
276        STRSAMPLE_R::new(((self.bits >> 18) & 0x03) as u8)
277    }
278    #[doc = "Bit 20 - Enable Inversion of Result"]
279    #[inline(always)]
280    pub fn scanresinv(&self) -> SCANRESINV_R {
281        SCANRESINV_R::new(((self.bits >> 20) & 0x01) != 0)
282    }
283    #[doc = "Bits 21:22 - Configure Evaluation Mode"]
284    #[inline(always)]
285    pub fn mode(&self) -> MODE_R {
286        MODE_R::new(((self.bits >> 21) & 0x03) as u8)
287    }
288}
289impl W {
290    #[doc = "Bits 0:15 - Decision Threshold for Sensor Data"]
291    #[inline(always)]
292    pub fn compthres(&mut self) -> COMPTHRES_W {
293        COMPTHRES_W { w: self }
294    }
295    #[doc = "Bit 16 - Select Mode for Threshold Comparison"]
296    #[inline(always)]
297    pub fn comp(&mut self) -> COMP_W {
298        COMP_W { w: self }
299    }
300    #[doc = "Bit 17 - Send Result to Decoder"]
301    #[inline(always)]
302    pub fn decode(&mut self) -> DECODE_W {
303        DECODE_W { w: self }
304    }
305    #[doc = "Bits 18:19 - Enable Storing of Sensor Sample in Result Buffer"]
306    #[inline(always)]
307    pub fn strsample(&mut self) -> STRSAMPLE_W {
308        STRSAMPLE_W { w: self }
309    }
310    #[doc = "Bit 20 - Enable Inversion of Result"]
311    #[inline(always)]
312    pub fn scanresinv(&mut self) -> SCANRESINV_W {
313        SCANRESINV_W { w: self }
314    }
315    #[doc = "Bits 21:22 - Configure Evaluation Mode"]
316    #[inline(always)]
317    pub fn mode(&mut self) -> MODE_W {
318        MODE_W { w: self }
319    }
320}