atsaml21j18b/adc/
refctrl.rs

1#[doc = "Register `REFCTRL` reader"]
2pub struct R(crate::R<REFCTRL_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<REFCTRL_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<REFCTRL_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<REFCTRL_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `REFCTRL` writer"]
17pub struct W(crate::W<REFCTRL_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<REFCTRL_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<REFCTRL_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<REFCTRL_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `REFSEL` reader - Reference Selection"]
38pub type REFSEL_R = crate::FieldReader<u8, REFSELSELECT_A>;
39#[doc = "Reference Selection\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41#[repr(u8)]
42pub enum REFSELSELECT_A {
43    #[doc = "0: Internal Bandgap Reference"]
44    INTREF = 0,
45    #[doc = "1: 1/1.6 VDDANA"]
46    INTVCC0 = 1,
47    #[doc = "2: 1/2 VDDANA"]
48    INTVCC1 = 2,
49    #[doc = "3: External Reference"]
50    AREFA = 3,
51    #[doc = "4: External Reference"]
52    AREFB = 4,
53    #[doc = "5: VCCANA"]
54    INTVCC2 = 5,
55}
56impl From<REFSELSELECT_A> for u8 {
57    #[inline(always)]
58    fn from(variant: REFSELSELECT_A) -> Self {
59        variant as _
60    }
61}
62impl REFSEL_R {
63    #[doc = "Get enumerated values variant"]
64    #[inline(always)]
65    pub fn variant(&self) -> Option<REFSELSELECT_A> {
66        match self.bits {
67            0 => Some(REFSELSELECT_A::INTREF),
68            1 => Some(REFSELSELECT_A::INTVCC0),
69            2 => Some(REFSELSELECT_A::INTVCC1),
70            3 => Some(REFSELSELECT_A::AREFA),
71            4 => Some(REFSELSELECT_A::AREFB),
72            5 => Some(REFSELSELECT_A::INTVCC2),
73            _ => None,
74        }
75    }
76    #[doc = "Checks if the value of the field is `INTREF`"]
77    #[inline(always)]
78    pub fn is_intref(&self) -> bool {
79        *self == REFSELSELECT_A::INTREF
80    }
81    #[doc = "Checks if the value of the field is `INTVCC0`"]
82    #[inline(always)]
83    pub fn is_intvcc0(&self) -> bool {
84        *self == REFSELSELECT_A::INTVCC0
85    }
86    #[doc = "Checks if the value of the field is `INTVCC1`"]
87    #[inline(always)]
88    pub fn is_intvcc1(&self) -> bool {
89        *self == REFSELSELECT_A::INTVCC1
90    }
91    #[doc = "Checks if the value of the field is `AREFA`"]
92    #[inline(always)]
93    pub fn is_arefa(&self) -> bool {
94        *self == REFSELSELECT_A::AREFA
95    }
96    #[doc = "Checks if the value of the field is `AREFB`"]
97    #[inline(always)]
98    pub fn is_arefb(&self) -> bool {
99        *self == REFSELSELECT_A::AREFB
100    }
101    #[doc = "Checks if the value of the field is `INTVCC2`"]
102    #[inline(always)]
103    pub fn is_intvcc2(&self) -> bool {
104        *self == REFSELSELECT_A::INTVCC2
105    }
106}
107#[doc = "Field `REFSEL` writer - Reference Selection"]
108pub type REFSEL_W<'a, const O: u8> =
109    crate::FieldWriter<'a, u8, REFCTRL_SPEC, u8, REFSELSELECT_A, 4, O>;
110impl<'a, const O: u8> REFSEL_W<'a, O> {
111    #[doc = "Internal Bandgap Reference"]
112    #[inline(always)]
113    pub fn intref(self) -> &'a mut W {
114        self.variant(REFSELSELECT_A::INTREF)
115    }
116    #[doc = "1/1.6 VDDANA"]
117    #[inline(always)]
118    pub fn intvcc0(self) -> &'a mut W {
119        self.variant(REFSELSELECT_A::INTVCC0)
120    }
121    #[doc = "1/2 VDDANA"]
122    #[inline(always)]
123    pub fn intvcc1(self) -> &'a mut W {
124        self.variant(REFSELSELECT_A::INTVCC1)
125    }
126    #[doc = "External Reference"]
127    #[inline(always)]
128    pub fn arefa(self) -> &'a mut W {
129        self.variant(REFSELSELECT_A::AREFA)
130    }
131    #[doc = "External Reference"]
132    #[inline(always)]
133    pub fn arefb(self) -> &'a mut W {
134        self.variant(REFSELSELECT_A::AREFB)
135    }
136    #[doc = "VCCANA"]
137    #[inline(always)]
138    pub fn intvcc2(self) -> &'a mut W {
139        self.variant(REFSELSELECT_A::INTVCC2)
140    }
141}
142#[doc = "Field `REFCOMP` reader - Reference Buffer Offset Compensation Enable"]
143pub type REFCOMP_R = crate::BitReader<bool>;
144#[doc = "Field `REFCOMP` writer - Reference Buffer Offset Compensation Enable"]
145pub type REFCOMP_W<'a, const O: u8> = crate::BitWriter<'a, u8, REFCTRL_SPEC, bool, O>;
146impl R {
147    #[doc = "Bits 0:3 - Reference Selection"]
148    #[inline(always)]
149    pub fn refsel(&self) -> REFSEL_R {
150        REFSEL_R::new(self.bits & 0x0f)
151    }
152    #[doc = "Bit 7 - Reference Buffer Offset Compensation Enable"]
153    #[inline(always)]
154    pub fn refcomp(&self) -> REFCOMP_R {
155        REFCOMP_R::new(((self.bits >> 7) & 1) != 0)
156    }
157}
158impl W {
159    #[doc = "Bits 0:3 - Reference Selection"]
160    #[inline(always)]
161    #[must_use]
162    pub fn refsel(&mut self) -> REFSEL_W<0> {
163        REFSEL_W::new(self)
164    }
165    #[doc = "Bit 7 - Reference Buffer Offset Compensation Enable"]
166    #[inline(always)]
167    #[must_use]
168    pub fn refcomp(&mut self) -> REFCOMP_W<7> {
169        REFCOMP_W::new(self)
170    }
171    #[doc = "Writes raw bits to the register."]
172    #[inline(always)]
173    pub unsafe fn bits(&mut self, bits: u8) -> &mut Self {
174        self.0.bits(bits);
175        self
176    }
177}
178#[doc = "Reference Control\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 [refctrl](index.html) module"]
179pub struct REFCTRL_SPEC;
180impl crate::RegisterSpec for REFCTRL_SPEC {
181    type Ux = u8;
182}
183#[doc = "`read()` method returns [refctrl::R](R) reader structure"]
184impl crate::Readable for REFCTRL_SPEC {
185    type Reader = R;
186}
187#[doc = "`write(|w| ..)` method takes [refctrl::W](W) writer structure"]
188impl crate::Writable for REFCTRL_SPEC {
189    type Writer = W;
190    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
191    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
192}
193#[doc = "`reset()` method sets REFCTRL to value 0"]
194impl crate::Resettable for REFCTRL_SPEC {
195    const RESET_VALUE: Self::Ux = 0;
196}