atsam4n8a_pac/adc/
emr.rs

1#[doc = "Register `EMR` reader"]
2pub struct R(crate::R<EMR_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<EMR_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<EMR_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<EMR_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `EMR` writer"]
17pub struct W(crate::W<EMR_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<EMR_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<EMR_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<EMR_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `CMPMODE` reader - Comparison Mode"]
38pub type CMPMODE_R = crate::FieldReader<u8, CMPMODE_A>;
39#[doc = "Comparison Mode\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41#[repr(u8)]
42pub enum CMPMODE_A {
43    #[doc = "0: Generates an event when the converted data is lower than the low threshold of the window."]
44    LOW = 0,
45    #[doc = "1: Generates an event when the converted data is higher than the high threshold of the window."]
46    HIGH = 1,
47    #[doc = "2: Generates an event when the converted data is in the comparison window."]
48    IN = 2,
49    #[doc = "3: Generates an event when the converted data is out of the comparison window."]
50    OUT = 3,
51}
52impl From<CMPMODE_A> for u8 {
53    #[inline(always)]
54    fn from(variant: CMPMODE_A) -> Self {
55        variant as _
56    }
57}
58impl CMPMODE_R {
59    #[doc = "Get enumerated values variant"]
60    #[inline(always)]
61    pub fn variant(&self) -> CMPMODE_A {
62        match self.bits {
63            0 => CMPMODE_A::LOW,
64            1 => CMPMODE_A::HIGH,
65            2 => CMPMODE_A::IN,
66            3 => CMPMODE_A::OUT,
67            _ => unreachable!(),
68        }
69    }
70    #[doc = "Checks if the value of the field is `LOW`"]
71    #[inline(always)]
72    pub fn is_low(&self) -> bool {
73        *self == CMPMODE_A::LOW
74    }
75    #[doc = "Checks if the value of the field is `HIGH`"]
76    #[inline(always)]
77    pub fn is_high(&self) -> bool {
78        *self == CMPMODE_A::HIGH
79    }
80    #[doc = "Checks if the value of the field is `IN`"]
81    #[inline(always)]
82    pub fn is_in(&self) -> bool {
83        *self == CMPMODE_A::IN
84    }
85    #[doc = "Checks if the value of the field is `OUT`"]
86    #[inline(always)]
87    pub fn is_out(&self) -> bool {
88        *self == CMPMODE_A::OUT
89    }
90}
91#[doc = "Field `CMPMODE` writer - Comparison Mode"]
92pub type CMPMODE_W<'a, const O: u8> =
93    crate::FieldWriterSafe<'a, u32, EMR_SPEC, u8, CMPMODE_A, 2, O>;
94impl<'a, const O: u8> CMPMODE_W<'a, O> {
95    #[doc = "Generates an event when the converted data is lower than the low threshold of the window."]
96    #[inline(always)]
97    pub fn low(self) -> &'a mut W {
98        self.variant(CMPMODE_A::LOW)
99    }
100    #[doc = "Generates an event when the converted data is higher than the high threshold of the window."]
101    #[inline(always)]
102    pub fn high(self) -> &'a mut W {
103        self.variant(CMPMODE_A::HIGH)
104    }
105    #[doc = "Generates an event when the converted data is in the comparison window."]
106    #[inline(always)]
107    pub fn in_(self) -> &'a mut W {
108        self.variant(CMPMODE_A::IN)
109    }
110    #[doc = "Generates an event when the converted data is out of the comparison window."]
111    #[inline(always)]
112    pub fn out(self) -> &'a mut W {
113        self.variant(CMPMODE_A::OUT)
114    }
115}
116#[doc = "Field `CMPSEL` reader - Comparison Selected Channel"]
117pub type CMPSEL_R = crate::FieldReader<u8, u8>;
118#[doc = "Field `CMPSEL` writer - Comparison Selected Channel"]
119pub type CMPSEL_W<'a, const O: u8> = crate::FieldWriter<'a, u32, EMR_SPEC, u8, u8, 4, O>;
120#[doc = "Field `CMPALL` reader - Compare All Channels"]
121pub type CMPALL_R = crate::BitReader<bool>;
122#[doc = "Field `CMPALL` writer - Compare All Channels"]
123pub type CMPALL_W<'a, const O: u8> = crate::BitWriter<'a, u32, EMR_SPEC, bool, O>;
124#[doc = "Field `CMPFILTER` reader - Compare Event Filtering"]
125pub type CMPFILTER_R = crate::FieldReader<u8, u8>;
126#[doc = "Field `CMPFILTER` writer - Compare Event Filtering"]
127pub type CMPFILTER_W<'a, const O: u8> = crate::FieldWriter<'a, u32, EMR_SPEC, u8, u8, 2, O>;
128#[doc = "Field `OSR` reader - Over Sampling Rate"]
129pub type OSR_R = crate::FieldReader<u8, OSR_A>;
130#[doc = "Over Sampling Rate\n\nValue on reset: 0"]
131#[derive(Clone, Copy, Debug, PartialEq, Eq)]
132#[repr(u8)]
133pub enum OSR_A {
134    #[doc = "0: no averaging. ADC sample rate is maximum."]
135    NO_AVERAGE = 0,
136    #[doc = "1: 1-bit enhanced resolution by interpolation. ADC sample rate divided by 4."]
137    OSR4 = 1,
138    #[doc = "2: 2-bit enhanced resolution by interpolation. ADC sample rate divided by 16."]
139    OSR16 = 2,
140}
141impl From<OSR_A> for u8 {
142    #[inline(always)]
143    fn from(variant: OSR_A) -> Self {
144        variant as _
145    }
146}
147impl OSR_R {
148    #[doc = "Get enumerated values variant"]
149    #[inline(always)]
150    pub fn variant(&self) -> Option<OSR_A> {
151        match self.bits {
152            0 => Some(OSR_A::NO_AVERAGE),
153            1 => Some(OSR_A::OSR4),
154            2 => Some(OSR_A::OSR16),
155            _ => None,
156        }
157    }
158    #[doc = "Checks if the value of the field is `NO_AVERAGE`"]
159    #[inline(always)]
160    pub fn is_no_average(&self) -> bool {
161        *self == OSR_A::NO_AVERAGE
162    }
163    #[doc = "Checks if the value of the field is `OSR4`"]
164    #[inline(always)]
165    pub fn is_osr4(&self) -> bool {
166        *self == OSR_A::OSR4
167    }
168    #[doc = "Checks if the value of the field is `OSR16`"]
169    #[inline(always)]
170    pub fn is_osr16(&self) -> bool {
171        *self == OSR_A::OSR16
172    }
173}
174#[doc = "Field `OSR` writer - Over Sampling Rate"]
175pub type OSR_W<'a, const O: u8> = crate::FieldWriter<'a, u32, EMR_SPEC, u8, OSR_A, 2, O>;
176impl<'a, const O: u8> OSR_W<'a, O> {
177    #[doc = "no averaging. ADC sample rate is maximum."]
178    #[inline(always)]
179    pub fn no_average(self) -> &'a mut W {
180        self.variant(OSR_A::NO_AVERAGE)
181    }
182    #[doc = "1-bit enhanced resolution by interpolation. ADC sample rate divided by 4."]
183    #[inline(always)]
184    pub fn osr4(self) -> &'a mut W {
185        self.variant(OSR_A::OSR4)
186    }
187    #[doc = "2-bit enhanced resolution by interpolation. ADC sample rate divided by 16."]
188    #[inline(always)]
189    pub fn osr16(self) -> &'a mut W {
190        self.variant(OSR_A::OSR16)
191    }
192}
193#[doc = "Field `ASTE` reader - Averaging on Single Trigger Event"]
194pub type ASTE_R = crate::BitReader<ASTE_A>;
195#[doc = "Averaging on Single Trigger Event\n\nValue on reset: 0"]
196#[derive(Clone, Copy, Debug, PartialEq, Eq)]
197pub enum ASTE_A {
198    #[doc = "0: The average requests several trigger events."]
199    MULTI_TRIG_AVERAGE = 0,
200    #[doc = "1: The average requests only one trigger event."]
201    SINGLE_TRIG_AVERAGE = 1,
202}
203impl From<ASTE_A> for bool {
204    #[inline(always)]
205    fn from(variant: ASTE_A) -> Self {
206        variant as u8 != 0
207    }
208}
209impl ASTE_R {
210    #[doc = "Get enumerated values variant"]
211    #[inline(always)]
212    pub fn variant(&self) -> ASTE_A {
213        match self.bits {
214            false => ASTE_A::MULTI_TRIG_AVERAGE,
215            true => ASTE_A::SINGLE_TRIG_AVERAGE,
216        }
217    }
218    #[doc = "Checks if the value of the field is `MULTI_TRIG_AVERAGE`"]
219    #[inline(always)]
220    pub fn is_multi_trig_average(&self) -> bool {
221        *self == ASTE_A::MULTI_TRIG_AVERAGE
222    }
223    #[doc = "Checks if the value of the field is `SINGLE_TRIG_AVERAGE`"]
224    #[inline(always)]
225    pub fn is_single_trig_average(&self) -> bool {
226        *self == ASTE_A::SINGLE_TRIG_AVERAGE
227    }
228}
229#[doc = "Field `ASTE` writer - Averaging on Single Trigger Event"]
230pub type ASTE_W<'a, const O: u8> = crate::BitWriter<'a, u32, EMR_SPEC, ASTE_A, O>;
231impl<'a, const O: u8> ASTE_W<'a, O> {
232    #[doc = "The average requests several trigger events."]
233    #[inline(always)]
234    pub fn multi_trig_average(self) -> &'a mut W {
235        self.variant(ASTE_A::MULTI_TRIG_AVERAGE)
236    }
237    #[doc = "The average requests only one trigger event."]
238    #[inline(always)]
239    pub fn single_trig_average(self) -> &'a mut W {
240        self.variant(ASTE_A::SINGLE_TRIG_AVERAGE)
241    }
242}
243#[doc = "Field `TAG` reader - TAG of the ADC_LDCR register"]
244pub type TAG_R = crate::BitReader<bool>;
245#[doc = "Field `TAG` writer - TAG of the ADC_LDCR register"]
246pub type TAG_W<'a, const O: u8> = crate::BitWriter<'a, u32, EMR_SPEC, bool, O>;
247impl R {
248    #[doc = "Bits 0:1 - Comparison Mode"]
249    #[inline(always)]
250    pub fn cmpmode(&self) -> CMPMODE_R {
251        CMPMODE_R::new((self.bits & 3) as u8)
252    }
253    #[doc = "Bits 4:7 - Comparison Selected Channel"]
254    #[inline(always)]
255    pub fn cmpsel(&self) -> CMPSEL_R {
256        CMPSEL_R::new(((self.bits >> 4) & 0x0f) as u8)
257    }
258    #[doc = "Bit 9 - Compare All Channels"]
259    #[inline(always)]
260    pub fn cmpall(&self) -> CMPALL_R {
261        CMPALL_R::new(((self.bits >> 9) & 1) != 0)
262    }
263    #[doc = "Bits 12:13 - Compare Event Filtering"]
264    #[inline(always)]
265    pub fn cmpfilter(&self) -> CMPFILTER_R {
266        CMPFILTER_R::new(((self.bits >> 12) & 3) as u8)
267    }
268    #[doc = "Bits 16:17 - Over Sampling Rate"]
269    #[inline(always)]
270    pub fn osr(&self) -> OSR_R {
271        OSR_R::new(((self.bits >> 16) & 3) as u8)
272    }
273    #[doc = "Bit 20 - Averaging on Single Trigger Event"]
274    #[inline(always)]
275    pub fn aste(&self) -> ASTE_R {
276        ASTE_R::new(((self.bits >> 20) & 1) != 0)
277    }
278    #[doc = "Bit 24 - TAG of the ADC_LDCR register"]
279    #[inline(always)]
280    pub fn tag(&self) -> TAG_R {
281        TAG_R::new(((self.bits >> 24) & 1) != 0)
282    }
283}
284impl W {
285    #[doc = "Bits 0:1 - Comparison Mode"]
286    #[inline(always)]
287    #[must_use]
288    pub fn cmpmode(&mut self) -> CMPMODE_W<0> {
289        CMPMODE_W::new(self)
290    }
291    #[doc = "Bits 4:7 - Comparison Selected Channel"]
292    #[inline(always)]
293    #[must_use]
294    pub fn cmpsel(&mut self) -> CMPSEL_W<4> {
295        CMPSEL_W::new(self)
296    }
297    #[doc = "Bit 9 - Compare All Channels"]
298    #[inline(always)]
299    #[must_use]
300    pub fn cmpall(&mut self) -> CMPALL_W<9> {
301        CMPALL_W::new(self)
302    }
303    #[doc = "Bits 12:13 - Compare Event Filtering"]
304    #[inline(always)]
305    #[must_use]
306    pub fn cmpfilter(&mut self) -> CMPFILTER_W<12> {
307        CMPFILTER_W::new(self)
308    }
309    #[doc = "Bits 16:17 - Over Sampling Rate"]
310    #[inline(always)]
311    #[must_use]
312    pub fn osr(&mut self) -> OSR_W<16> {
313        OSR_W::new(self)
314    }
315    #[doc = "Bit 20 - Averaging on Single Trigger Event"]
316    #[inline(always)]
317    #[must_use]
318    pub fn aste(&mut self) -> ASTE_W<20> {
319        ASTE_W::new(self)
320    }
321    #[doc = "Bit 24 - TAG of the ADC_LDCR register"]
322    #[inline(always)]
323    #[must_use]
324    pub fn tag(&mut self) -> TAG_W<24> {
325        TAG_W::new(self)
326    }
327    #[doc = "Writes raw bits to the register."]
328    #[inline(always)]
329    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
330        self.0.bits(bits);
331        self
332    }
333}
334#[doc = "Extended Mode 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 [emr](index.html) module"]
335pub struct EMR_SPEC;
336impl crate::RegisterSpec for EMR_SPEC {
337    type Ux = u32;
338}
339#[doc = "`read()` method returns [emr::R](R) reader structure"]
340impl crate::Readable for EMR_SPEC {
341    type Reader = R;
342}
343#[doc = "`write(|w| ..)` method takes [emr::W](W) writer structure"]
344impl crate::Writable for EMR_SPEC {
345    type Writer = W;
346    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
347    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
348}
349#[doc = "`reset()` method sets EMR to value 0"]
350impl crate::Resettable for EMR_SPEC {
351    const RESET_VALUE: Self::Ux = 0;
352}