lpc82x_pac/acomp/
lad.rs

1#[doc = "Register `LAD` reader"]
2pub struct R(crate::R<LAD_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<LAD_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<LAD_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<LAD_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `LAD` writer"]
17pub struct W(crate::W<LAD_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<LAD_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<LAD_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<LAD_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `LADEN` reader - Voltage ladder enable"]
38pub struct LADEN_R(crate::FieldReader<bool, bool>);
39impl LADEN_R {
40    pub(crate) fn new(bits: bool) -> Self {
41        LADEN_R(crate::FieldReader::new(bits))
42    }
43}
44impl core::ops::Deref for LADEN_R {
45    type Target = crate::FieldReader<bool, bool>;
46    #[inline(always)]
47    fn deref(&self) -> &Self::Target {
48        &self.0
49    }
50}
51#[doc = "Field `LADEN` writer - Voltage ladder enable"]
52pub struct LADEN_W<'a> {
53    w: &'a mut W,
54}
55impl<'a> LADEN_W<'a> {
56    #[doc = r"Sets the field bit"]
57    #[inline(always)]
58    pub fn set_bit(self) -> &'a mut W {
59        self.bit(true)
60    }
61    #[doc = r"Clears the field bit"]
62    #[inline(always)]
63    pub fn clear_bit(self) -> &'a mut W {
64        self.bit(false)
65    }
66    #[doc = r"Writes raw bits to the field"]
67    #[inline(always)]
68    pub fn bit(self, value: bool) -> &'a mut W {
69        self.w.bits = (self.w.bits & !0x01) | (value as u32 & 0x01);
70        self.w
71    }
72}
73#[doc = "Field `LADSEL` reader - Voltage ladder value. The reference voltage Vref depends on the LADREF bit below. 00000 = VSS 00001 = 1 x Vref/31 00010 = 2 x Vref/31 ... 11111 = Vref"]
74pub struct LADSEL_R(crate::FieldReader<u8, u8>);
75impl LADSEL_R {
76    pub(crate) fn new(bits: u8) -> Self {
77        LADSEL_R(crate::FieldReader::new(bits))
78    }
79}
80impl core::ops::Deref for LADSEL_R {
81    type Target = crate::FieldReader<u8, u8>;
82    #[inline(always)]
83    fn deref(&self) -> &Self::Target {
84        &self.0
85    }
86}
87#[doc = "Field `LADSEL` writer - Voltage ladder value. The reference voltage Vref depends on the LADREF bit below. 00000 = VSS 00001 = 1 x Vref/31 00010 = 2 x Vref/31 ... 11111 = Vref"]
88pub struct LADSEL_W<'a> {
89    w: &'a mut W,
90}
91impl<'a> LADSEL_W<'a> {
92    #[doc = r"Writes raw bits to the field"]
93    #[inline(always)]
94    pub unsafe fn bits(self, value: u8) -> &'a mut W {
95        self.w.bits = (self.w.bits & !(0x1f << 1)) | ((value as u32 & 0x1f) << 1);
96        self.w
97    }
98}
99#[doc = "Selects the reference voltage Vref for the voltage ladder.\n\nValue on reset: 0"]
100#[derive(Clone, Copy, Debug, PartialEq)]
101pub enum LADREF_A {
102    #[doc = "0: Supply pin VDD"]
103    LADREF_0 = 0,
104    #[doc = "1: VDDCMP pin"]
105    LADREF_1 = 1,
106}
107impl From<LADREF_A> for bool {
108    #[inline(always)]
109    fn from(variant: LADREF_A) -> Self {
110        variant as u8 != 0
111    }
112}
113#[doc = "Field `LADREF` reader - Selects the reference voltage Vref for the voltage ladder."]
114pub struct LADREF_R(crate::FieldReader<bool, LADREF_A>);
115impl LADREF_R {
116    pub(crate) fn new(bits: bool) -> Self {
117        LADREF_R(crate::FieldReader::new(bits))
118    }
119    #[doc = r"Get enumerated values variant"]
120    #[inline(always)]
121    pub fn variant(&self) -> LADREF_A {
122        match self.bits {
123            false => LADREF_A::LADREF_0,
124            true => LADREF_A::LADREF_1,
125        }
126    }
127    #[doc = "Checks if the value of the field is `LADREF_0`"]
128    #[inline(always)]
129    pub fn is_ladref_0(&self) -> bool {
130        **self == LADREF_A::LADREF_0
131    }
132    #[doc = "Checks if the value of the field is `LADREF_1`"]
133    #[inline(always)]
134    pub fn is_ladref_1(&self) -> bool {
135        **self == LADREF_A::LADREF_1
136    }
137}
138impl core::ops::Deref for LADREF_R {
139    type Target = crate::FieldReader<bool, LADREF_A>;
140    #[inline(always)]
141    fn deref(&self) -> &Self::Target {
142        &self.0
143    }
144}
145#[doc = "Field `LADREF` writer - Selects the reference voltage Vref for the voltage ladder."]
146pub struct LADREF_W<'a> {
147    w: &'a mut W,
148}
149impl<'a> LADREF_W<'a> {
150    #[doc = r"Writes `variant` to the field"]
151    #[inline(always)]
152    pub fn variant(self, variant: LADREF_A) -> &'a mut W {
153        self.bit(variant.into())
154    }
155    #[doc = "Supply pin VDD"]
156    #[inline(always)]
157    pub fn ladref_0(self) -> &'a mut W {
158        self.variant(LADREF_A::LADREF_0)
159    }
160    #[doc = "VDDCMP pin"]
161    #[inline(always)]
162    pub fn ladref_1(self) -> &'a mut W {
163        self.variant(LADREF_A::LADREF_1)
164    }
165    #[doc = r"Sets the field bit"]
166    #[inline(always)]
167    pub fn set_bit(self) -> &'a mut W {
168        self.bit(true)
169    }
170    #[doc = r"Clears the field bit"]
171    #[inline(always)]
172    pub fn clear_bit(self) -> &'a mut W {
173        self.bit(false)
174    }
175    #[doc = r"Writes raw bits to the field"]
176    #[inline(always)]
177    pub fn bit(self, value: bool) -> &'a mut W {
178        self.w.bits = (self.w.bits & !(0x01 << 6)) | ((value as u32 & 0x01) << 6);
179        self.w
180    }
181}
182impl R {
183    #[doc = "Bit 0 - Voltage ladder enable"]
184    #[inline(always)]
185    pub fn laden(&self) -> LADEN_R {
186        LADEN_R::new((self.bits & 0x01) != 0)
187    }
188    #[doc = "Bits 1:5 - Voltage ladder value. The reference voltage Vref depends on the LADREF bit below. 00000 = VSS 00001 = 1 x Vref/31 00010 = 2 x Vref/31 ... 11111 = Vref"]
189    #[inline(always)]
190    pub fn ladsel(&self) -> LADSEL_R {
191        LADSEL_R::new(((self.bits >> 1) & 0x1f) as u8)
192    }
193    #[doc = "Bit 6 - Selects the reference voltage Vref for the voltage ladder."]
194    #[inline(always)]
195    pub fn ladref(&self) -> LADREF_R {
196        LADREF_R::new(((self.bits >> 6) & 0x01) != 0)
197    }
198}
199impl W {
200    #[doc = "Bit 0 - Voltage ladder enable"]
201    #[inline(always)]
202    pub fn laden(&mut self) -> LADEN_W {
203        LADEN_W { w: self }
204    }
205    #[doc = "Bits 1:5 - Voltage ladder value. The reference voltage Vref depends on the LADREF bit below. 00000 = VSS 00001 = 1 x Vref/31 00010 = 2 x Vref/31 ... 11111 = Vref"]
206    #[inline(always)]
207    pub fn ladsel(&mut self) -> LADSEL_W {
208        LADSEL_W { w: self }
209    }
210    #[doc = "Bit 6 - Selects the reference voltage Vref for the voltage ladder."]
211    #[inline(always)]
212    pub fn ladref(&mut self) -> LADREF_W {
213        LADREF_W { w: self }
214    }
215    #[doc = "Writes raw bits to the register."]
216    #[inline(always)]
217    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
218        self.0.bits(bits);
219        self
220    }
221}
222#[doc = "Voltage ladder 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 [lad](index.html) module"]
223pub struct LAD_SPEC;
224impl crate::RegisterSpec for LAD_SPEC {
225    type Ux = u32;
226}
227#[doc = "`read()` method returns [lad::R](R) reader structure"]
228impl crate::Readable for LAD_SPEC {
229    type Reader = R;
230}
231#[doc = "`write(|w| ..)` method takes [lad::W](W) writer structure"]
232impl crate::Writable for LAD_SPEC {
233    type Writer = W;
234}
235#[doc = "`reset()` method sets LAD to value 0"]
236impl crate::Resettable for LAD_SPEC {
237    #[inline(always)]
238    fn reset_value() -> Self::Ux {
239        0
240    }
241}