atsamd51p19a/adc0/
refctrl.rs

1#[doc = "Reader of register REFCTRL"]
2pub type R = crate::R<u8, super::REFCTRL>;
3#[doc = "Writer for register REFCTRL"]
4pub type W = crate::W<u8, super::REFCTRL>;
5#[doc = "Register REFCTRL `reset()`'s with value 0"]
6impl crate::ResetValue for super::REFCTRL {
7    type Type = u8;
8    #[inline(always)]
9    fn reset_value() -> Self::Type {
10        0
11    }
12}
13#[doc = "Reference Selection\n\nValue on reset: 0"]
14#[derive(Clone, Copy, Debug, PartialEq)]
15#[repr(u8)]
16pub enum REFSEL_A {
17    #[doc = "0: Internal Bandgap Reference"]
18    INTREF = 0,
19    #[doc = "2: 1/2 VDDANA"]
20    INTVCC0 = 2,
21    #[doc = "3: VDDANA"]
22    INTVCC1 = 3,
23    #[doc = "4: External Reference"]
24    AREFA = 4,
25    #[doc = "5: External Reference"]
26    AREFB = 5,
27    #[doc = "6: External Reference (only on ADC1)"]
28    AREFC = 6,
29}
30impl From<REFSEL_A> for u8 {
31    #[inline(always)]
32    fn from(variant: REFSEL_A) -> Self {
33        variant as _
34    }
35}
36#[doc = "Reader of field `REFSEL`"]
37pub type REFSEL_R = crate::R<u8, REFSEL_A>;
38impl REFSEL_R {
39    #[doc = r"Get enumerated values variant"]
40    #[inline(always)]
41    pub fn variant(&self) -> crate::Variant<u8, REFSEL_A> {
42        use crate::Variant::*;
43        match self.bits {
44            0 => Val(REFSEL_A::INTREF),
45            2 => Val(REFSEL_A::INTVCC0),
46            3 => Val(REFSEL_A::INTVCC1),
47            4 => Val(REFSEL_A::AREFA),
48            5 => Val(REFSEL_A::AREFB),
49            6 => Val(REFSEL_A::AREFC),
50            i => Res(i),
51        }
52    }
53    #[doc = "Checks if the value of the field is `INTREF`"]
54    #[inline(always)]
55    pub fn is_intref(&self) -> bool {
56        *self == REFSEL_A::INTREF
57    }
58    #[doc = "Checks if the value of the field is `INTVCC0`"]
59    #[inline(always)]
60    pub fn is_intvcc0(&self) -> bool {
61        *self == REFSEL_A::INTVCC0
62    }
63    #[doc = "Checks if the value of the field is `INTVCC1`"]
64    #[inline(always)]
65    pub fn is_intvcc1(&self) -> bool {
66        *self == REFSEL_A::INTVCC1
67    }
68    #[doc = "Checks if the value of the field is `AREFA`"]
69    #[inline(always)]
70    pub fn is_arefa(&self) -> bool {
71        *self == REFSEL_A::AREFA
72    }
73    #[doc = "Checks if the value of the field is `AREFB`"]
74    #[inline(always)]
75    pub fn is_arefb(&self) -> bool {
76        *self == REFSEL_A::AREFB
77    }
78    #[doc = "Checks if the value of the field is `AREFC`"]
79    #[inline(always)]
80    pub fn is_arefc(&self) -> bool {
81        *self == REFSEL_A::AREFC
82    }
83}
84#[doc = "Write proxy for field `REFSEL`"]
85pub struct REFSEL_W<'a> {
86    w: &'a mut W,
87}
88impl<'a> REFSEL_W<'a> {
89    #[doc = r"Writes `variant` to the field"]
90    #[inline(always)]
91    pub fn variant(self, variant: REFSEL_A) -> &'a mut W {
92        unsafe { self.bits(variant.into()) }
93    }
94    #[doc = "Internal Bandgap Reference"]
95    #[inline(always)]
96    pub fn intref(self) -> &'a mut W {
97        self.variant(REFSEL_A::INTREF)
98    }
99    #[doc = "1/2 VDDANA"]
100    #[inline(always)]
101    pub fn intvcc0(self) -> &'a mut W {
102        self.variant(REFSEL_A::INTVCC0)
103    }
104    #[doc = "VDDANA"]
105    #[inline(always)]
106    pub fn intvcc1(self) -> &'a mut W {
107        self.variant(REFSEL_A::INTVCC1)
108    }
109    #[doc = "External Reference"]
110    #[inline(always)]
111    pub fn arefa(self) -> &'a mut W {
112        self.variant(REFSEL_A::AREFA)
113    }
114    #[doc = "External Reference"]
115    #[inline(always)]
116    pub fn arefb(self) -> &'a mut W {
117        self.variant(REFSEL_A::AREFB)
118    }
119    #[doc = "External Reference (only on ADC1)"]
120    #[inline(always)]
121    pub fn arefc(self) -> &'a mut W {
122        self.variant(REFSEL_A::AREFC)
123    }
124    #[doc = r"Writes raw bits to the field"]
125    #[inline(always)]
126    pub unsafe fn bits(self, value: u8) -> &'a mut W {
127        self.w.bits = (self.w.bits & !0x0f) | ((value as u8) & 0x0f);
128        self.w
129    }
130}
131#[doc = "Reader of field `REFCOMP`"]
132pub type REFCOMP_R = crate::R<bool, bool>;
133#[doc = "Write proxy for field `REFCOMP`"]
134pub struct REFCOMP_W<'a> {
135    w: &'a mut W,
136}
137impl<'a> REFCOMP_W<'a> {
138    #[doc = r"Sets the field bit"]
139    #[inline(always)]
140    pub fn set_bit(self) -> &'a mut W {
141        self.bit(true)
142    }
143    #[doc = r"Clears the field bit"]
144    #[inline(always)]
145    pub fn clear_bit(self) -> &'a mut W {
146        self.bit(false)
147    }
148    #[doc = r"Writes raw bits to the field"]
149    #[inline(always)]
150    pub fn bit(self, value: bool) -> &'a mut W {
151        self.w.bits = (self.w.bits & !(0x01 << 7)) | (((value as u8) & 0x01) << 7);
152        self.w
153    }
154}
155impl R {
156    #[doc = "Bits 0:3 - Reference Selection"]
157    #[inline(always)]
158    pub fn refsel(&self) -> REFSEL_R {
159        REFSEL_R::new((self.bits & 0x0f) as u8)
160    }
161    #[doc = "Bit 7 - Reference Buffer Offset Compensation Enable"]
162    #[inline(always)]
163    pub fn refcomp(&self) -> REFCOMP_R {
164        REFCOMP_R::new(((self.bits >> 7) & 0x01) != 0)
165    }
166}
167impl W {
168    #[doc = "Bits 0:3 - Reference Selection"]
169    #[inline(always)]
170    pub fn refsel(&mut self) -> REFSEL_W {
171        REFSEL_W { w: self }
172    }
173    #[doc = "Bit 7 - Reference Buffer Offset Compensation Enable"]
174    #[inline(always)]
175    pub fn refcomp(&mut self) -> REFCOMP_W {
176        REFCOMP_W { w: self }
177    }
178}