Skip to main content

nrf52/saadc/oversample/
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::OVERSAMPLE {
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 `OVERSAMPLE`"]
46#[derive(Clone, Copy, Debug, PartialEq)]
47pub enum OVERSAMPLER {
48    #[doc = "Bypass oversampling"]
49    BYPASS,
50    #[doc = "Oversample 2x"]
51    OVER2X,
52    #[doc = "Oversample 4x"]
53    OVER4X,
54    #[doc = "Oversample 8x"]
55    OVER8X,
56    #[doc = "Oversample 16x"]
57    OVER16X,
58    #[doc = "Oversample 32x"]
59    OVER32X,
60    #[doc = "Oversample 64x"]
61    OVER64X,
62    #[doc = "Oversample 128x"]
63    OVER128X,
64    #[doc = "Oversample 256x"]
65    OVER256X,
66    #[doc = r" Reserved"]
67    _Reserved(u8),
68}
69impl OVERSAMPLER {
70    #[doc = r" Value of the field as raw bits"]
71    #[inline]
72    pub fn bits(&self) -> u8 {
73        match *self {
74            OVERSAMPLER::BYPASS => 0,
75            OVERSAMPLER::OVER2X => 1,
76            OVERSAMPLER::OVER4X => 2,
77            OVERSAMPLER::OVER8X => 3,
78            OVERSAMPLER::OVER16X => 4,
79            OVERSAMPLER::OVER32X => 5,
80            OVERSAMPLER::OVER64X => 6,
81            OVERSAMPLER::OVER128X => 7,
82            OVERSAMPLER::OVER256X => 8,
83            OVERSAMPLER::_Reserved(bits) => bits,
84        }
85    }
86    #[allow(missing_docs)]
87    #[doc(hidden)]
88    #[inline]
89    pub fn _from(value: u8) -> OVERSAMPLER {
90        match value {
91            0 => OVERSAMPLER::BYPASS,
92            1 => OVERSAMPLER::OVER2X,
93            2 => OVERSAMPLER::OVER4X,
94            3 => OVERSAMPLER::OVER8X,
95            4 => OVERSAMPLER::OVER16X,
96            5 => OVERSAMPLER::OVER32X,
97            6 => OVERSAMPLER::OVER64X,
98            7 => OVERSAMPLER::OVER128X,
99            8 => OVERSAMPLER::OVER256X,
100            i => OVERSAMPLER::_Reserved(i),
101        }
102    }
103    #[doc = "Checks if the value of the field is `BYPASS`"]
104    #[inline]
105    pub fn is_bypass(&self) -> bool {
106        *self == OVERSAMPLER::BYPASS
107    }
108    #[doc = "Checks if the value of the field is `OVER2X`"]
109    #[inline]
110    pub fn is_over2x(&self) -> bool {
111        *self == OVERSAMPLER::OVER2X
112    }
113    #[doc = "Checks if the value of the field is `OVER4X`"]
114    #[inline]
115    pub fn is_over4x(&self) -> bool {
116        *self == OVERSAMPLER::OVER4X
117    }
118    #[doc = "Checks if the value of the field is `OVER8X`"]
119    #[inline]
120    pub fn is_over8x(&self) -> bool {
121        *self == OVERSAMPLER::OVER8X
122    }
123    #[doc = "Checks if the value of the field is `OVER16X`"]
124    #[inline]
125    pub fn is_over16x(&self) -> bool {
126        *self == OVERSAMPLER::OVER16X
127    }
128    #[doc = "Checks if the value of the field is `OVER32X`"]
129    #[inline]
130    pub fn is_over32x(&self) -> bool {
131        *self == OVERSAMPLER::OVER32X
132    }
133    #[doc = "Checks if the value of the field is `OVER64X`"]
134    #[inline]
135    pub fn is_over64x(&self) -> bool {
136        *self == OVERSAMPLER::OVER64X
137    }
138    #[doc = "Checks if the value of the field is `OVER128X`"]
139    #[inline]
140    pub fn is_over128x(&self) -> bool {
141        *self == OVERSAMPLER::OVER128X
142    }
143    #[doc = "Checks if the value of the field is `OVER256X`"]
144    #[inline]
145    pub fn is_over256x(&self) -> bool {
146        *self == OVERSAMPLER::OVER256X
147    }
148}
149#[doc = "Values that can be written to the field `OVERSAMPLE`"]
150pub enum OVERSAMPLEW {
151    #[doc = "Bypass oversampling"]
152    BYPASS,
153    #[doc = "Oversample 2x"]
154    OVER2X,
155    #[doc = "Oversample 4x"]
156    OVER4X,
157    #[doc = "Oversample 8x"]
158    OVER8X,
159    #[doc = "Oversample 16x"]
160    OVER16X,
161    #[doc = "Oversample 32x"]
162    OVER32X,
163    #[doc = "Oversample 64x"]
164    OVER64X,
165    #[doc = "Oversample 128x"]
166    OVER128X,
167    #[doc = "Oversample 256x"]
168    OVER256X,
169}
170impl OVERSAMPLEW {
171    #[allow(missing_docs)]
172    #[doc(hidden)]
173    #[inline]
174    pub fn _bits(&self) -> u8 {
175        match *self {
176            OVERSAMPLEW::BYPASS => 0,
177            OVERSAMPLEW::OVER2X => 1,
178            OVERSAMPLEW::OVER4X => 2,
179            OVERSAMPLEW::OVER8X => 3,
180            OVERSAMPLEW::OVER16X => 4,
181            OVERSAMPLEW::OVER32X => 5,
182            OVERSAMPLEW::OVER64X => 6,
183            OVERSAMPLEW::OVER128X => 7,
184            OVERSAMPLEW::OVER256X => 8,
185        }
186    }
187}
188#[doc = r" Proxy"]
189pub struct _OVERSAMPLEW<'a> {
190    w: &'a mut W,
191}
192impl<'a> _OVERSAMPLEW<'a> {
193    #[doc = r" Writes `variant` to the field"]
194    #[inline]
195    pub fn variant(self, variant: OVERSAMPLEW) -> &'a mut W {
196        unsafe { self.bits(variant._bits()) }
197    }
198    #[doc = "Bypass oversampling"]
199    #[inline]
200    pub fn bypass(self) -> &'a mut W {
201        self.variant(OVERSAMPLEW::BYPASS)
202    }
203    #[doc = "Oversample 2x"]
204    #[inline]
205    pub fn over2x(self) -> &'a mut W {
206        self.variant(OVERSAMPLEW::OVER2X)
207    }
208    #[doc = "Oversample 4x"]
209    #[inline]
210    pub fn over4x(self) -> &'a mut W {
211        self.variant(OVERSAMPLEW::OVER4X)
212    }
213    #[doc = "Oversample 8x"]
214    #[inline]
215    pub fn over8x(self) -> &'a mut W {
216        self.variant(OVERSAMPLEW::OVER8X)
217    }
218    #[doc = "Oversample 16x"]
219    #[inline]
220    pub fn over16x(self) -> &'a mut W {
221        self.variant(OVERSAMPLEW::OVER16X)
222    }
223    #[doc = "Oversample 32x"]
224    #[inline]
225    pub fn over32x(self) -> &'a mut W {
226        self.variant(OVERSAMPLEW::OVER32X)
227    }
228    #[doc = "Oversample 64x"]
229    #[inline]
230    pub fn over64x(self) -> &'a mut W {
231        self.variant(OVERSAMPLEW::OVER64X)
232    }
233    #[doc = "Oversample 128x"]
234    #[inline]
235    pub fn over128x(self) -> &'a mut W {
236        self.variant(OVERSAMPLEW::OVER128X)
237    }
238    #[doc = "Oversample 256x"]
239    #[inline]
240    pub fn over256x(self) -> &'a mut W {
241        self.variant(OVERSAMPLEW::OVER256X)
242    }
243    #[doc = r" Writes raw bits to the field"]
244    #[inline]
245    pub unsafe fn bits(self, value: u8) -> &'a mut W {
246        const MASK: u8 = 15;
247        const OFFSET: u8 = 0;
248        self.w.bits &= !((MASK as u32) << OFFSET);
249        self.w.bits |= ((value & MASK) as u32) << OFFSET;
250        self.w
251    }
252}
253impl R {
254    #[doc = r" Value of the register as raw bits"]
255    #[inline]
256    pub fn bits(&self) -> u32 {
257        self.bits
258    }
259    #[doc = "Bits 0:3 - Oversample control"]
260    #[inline]
261    pub fn oversample(&self) -> OVERSAMPLER {
262        OVERSAMPLER::_from({
263            const MASK: u8 = 15;
264            const OFFSET: u8 = 0;
265            ((self.bits >> OFFSET) & MASK as u32) as u8
266        })
267    }
268}
269impl W {
270    #[doc = r" Reset value of the register"]
271    #[inline]
272    pub fn reset_value() -> W {
273        W { bits: 0 }
274    }
275    #[doc = r" Writes raw bits to the register"]
276    #[inline]
277    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
278        self.bits = bits;
279        self
280    }
281    #[doc = "Bits 0:3 - Oversample control"]
282    #[inline]
283    pub fn oversample(&mut self) -> _OVERSAMPLEW {
284        _OVERSAMPLEW { w: self }
285    }
286}