Skip to main content

nrf52/comp/refsel/
mod.rs

1#[doc = r" Value read from the register"]
2pub struct R {
3    bits: u32,
4}
5#[doc = r" Value to write to the register"]
6pub struct W {
7    bits: u32,
8}
9impl super::REFSEL {
10    #[doc = r" Modifies the contents of the register"]
11    #[inline]
12    pub fn modify<F>(&self, f: F)
13    where
14        for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W,
15    {
16        let bits = self.register.get();
17        let r = R { bits: bits };
18        let mut w = W { bits: bits };
19        f(&r, &mut w);
20        self.register.set(w.bits);
21    }
22    #[doc = r" Reads the contents of the register"]
23    #[inline]
24    pub fn read(&self) -> R {
25        R {
26            bits: self.register.get(),
27        }
28    }
29    #[doc = r" Writes to the register"]
30    #[inline]
31    pub fn write<F>(&self, f: F)
32    where
33        F: FnOnce(&mut W) -> &mut W,
34    {
35        let mut w = W::reset_value();
36        f(&mut w);
37        self.register.set(w.bits);
38    }
39    #[doc = r" Writes the reset value to the register"]
40    #[inline]
41    pub fn reset(&self) {
42        self.write(|w| w)
43    }
44}
45#[doc = "Possible values of the field `REFSEL`"]
46#[derive(Clone, Copy, Debug, PartialEq)]
47pub enum REFSELR {
48    #[doc = "VREF = internal 1.2 V reference (VDD &gt;= 1.7 V)"]
49    INT1V2,
50    #[doc = "VREF = internal 1.8 V reference (VDD &gt;= VREF + 0.2 V)"]
51    INT1V8,
52    #[doc = "VREF = internal 2.4 V reference (VDD &gt;= VREF + 0.2 V)"]
53    INT2V4,
54    #[doc = "VREF = VDD"]
55    VDD,
56    #[doc = "VREF = AREF (VDD &gt;= VREF &gt;= AREFMIN)"]
57    AREF,
58    #[doc = r" Reserved"]
59    _Reserved(u8),
60}
61impl REFSELR {
62    #[doc = r" Value of the field as raw bits"]
63    #[inline]
64    pub fn bits(&self) -> u8 {
65        match *self {
66            REFSELR::INT1V2 => 0,
67            REFSELR::INT1V8 => 1,
68            REFSELR::INT2V4 => 2,
69            REFSELR::VDD => 4,
70            REFSELR::AREF => 7,
71            REFSELR::_Reserved(bits) => bits,
72        }
73    }
74    #[allow(missing_docs)]
75    #[doc(hidden)]
76    #[inline]
77    pub fn _from(value: u8) -> REFSELR {
78        match value {
79            0 => REFSELR::INT1V2,
80            1 => REFSELR::INT1V8,
81            2 => REFSELR::INT2V4,
82            4 => REFSELR::VDD,
83            7 => REFSELR::AREF,
84            i => REFSELR::_Reserved(i),
85        }
86    }
87    #[doc = "Checks if the value of the field is `INT1V2`"]
88    #[inline]
89    pub fn is_int1v2(&self) -> bool {
90        *self == REFSELR::INT1V2
91    }
92    #[doc = "Checks if the value of the field is `INT1V8`"]
93    #[inline]
94    pub fn is_int1v8(&self) -> bool {
95        *self == REFSELR::INT1V8
96    }
97    #[doc = "Checks if the value of the field is `INT2V4`"]
98    #[inline]
99    pub fn is_int2v4(&self) -> bool {
100        *self == REFSELR::INT2V4
101    }
102    #[doc = "Checks if the value of the field is `VDD`"]
103    #[inline]
104    pub fn is_vdd(&self) -> bool {
105        *self == REFSELR::VDD
106    }
107    #[doc = "Checks if the value of the field is `AREF`"]
108    #[inline]
109    pub fn is_aref(&self) -> bool {
110        *self == REFSELR::AREF
111    }
112}
113#[doc = "Values that can be written to the field `REFSEL`"]
114pub enum REFSELW {
115    #[doc = "VREF = internal 1.2 V reference (VDD &gt;= 1.7 V)"]
116    INT1V2,
117    #[doc = "VREF = internal 1.8 V reference (VDD &gt;= VREF + 0.2 V)"]
118    INT1V8,
119    #[doc = "VREF = internal 2.4 V reference (VDD &gt;= VREF + 0.2 V)"]
120    INT2V4,
121    #[doc = "VREF = VDD"]
122    VDD,
123    #[doc = "VREF = AREF (VDD &gt;= VREF &gt;= AREFMIN)"]
124    AREF,
125}
126impl REFSELW {
127    #[allow(missing_docs)]
128    #[doc(hidden)]
129    #[inline]
130    pub fn _bits(&self) -> u8 {
131        match *self {
132            REFSELW::INT1V2 => 0,
133            REFSELW::INT1V8 => 1,
134            REFSELW::INT2V4 => 2,
135            REFSELW::VDD => 4,
136            REFSELW::AREF => 7,
137        }
138    }
139}
140#[doc = r" Proxy"]
141pub struct _REFSELW<'a> {
142    w: &'a mut W,
143}
144impl<'a> _REFSELW<'a> {
145    #[doc = r" Writes `variant` to the field"]
146    #[inline]
147    pub fn variant(self, variant: REFSELW) -> &'a mut W {
148        unsafe { self.bits(variant._bits()) }
149    }
150    #[doc = "VREF = internal 1.2 V reference (VDD &gt;= 1.7 V)"]
151    #[inline]
152    pub fn int1v2(self) -> &'a mut W {
153        self.variant(REFSELW::INT1V2)
154    }
155    #[doc = "VREF = internal 1.8 V reference (VDD &gt;= VREF + 0.2 V)"]
156    #[inline]
157    pub fn int1v8(self) -> &'a mut W {
158        self.variant(REFSELW::INT1V8)
159    }
160    #[doc = "VREF = internal 2.4 V reference (VDD &gt;= VREF + 0.2 V)"]
161    #[inline]
162    pub fn int2v4(self) -> &'a mut W {
163        self.variant(REFSELW::INT2V4)
164    }
165    #[doc = "VREF = VDD"]
166    #[inline]
167    pub fn vdd(self) -> &'a mut W {
168        self.variant(REFSELW::VDD)
169    }
170    #[doc = "VREF = AREF (VDD &gt;= VREF &gt;= AREFMIN)"]
171    #[inline]
172    pub fn aref(self) -> &'a mut W {
173        self.variant(REFSELW::AREF)
174    }
175    #[doc = r" Writes raw bits to the field"]
176    #[inline]
177    pub unsafe fn bits(self, value: u8) -> &'a mut W {
178        const MASK: u8 = 7;
179        const OFFSET: u8 = 0;
180        self.w.bits &= !((MASK as u32) << OFFSET);
181        self.w.bits |= ((value & MASK) as u32) << OFFSET;
182        self.w
183    }
184}
185impl R {
186    #[doc = r" Value of the register as raw bits"]
187    #[inline]
188    pub fn bits(&self) -> u32 {
189        self.bits
190    }
191    #[doc = "Bits 0:2 - Reference select"]
192    #[inline]
193    pub fn refsel(&self) -> REFSELR {
194        REFSELR::_from({
195            const MASK: u8 = 7;
196            const OFFSET: u8 = 0;
197            ((self.bits >> OFFSET) & MASK as u32) as u8
198        })
199    }
200}
201impl W {
202    #[doc = r" Reset value of the register"]
203    #[inline]
204    pub fn reset_value() -> W {
205        W { bits: 4 }
206    }
207    #[doc = r" Writes raw bits to the register"]
208    #[inline]
209    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
210        self.bits = bits;
211        self
212    }
213    #[doc = "Bits 0:2 - Reference select"]
214    #[inline]
215    pub fn refsel(&mut self) -> _REFSELW {
216        _REFSELW { w: self }
217    }
218}