nrf52840_pac/saadc/
samplerate.rs

1#[doc = "Register `SAMPLERATE` reader"]
2pub struct R(crate::R<SAMPLERATE_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<SAMPLERATE_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<SAMPLERATE_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<SAMPLERATE_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `SAMPLERATE` writer"]
17pub struct W(crate::W<SAMPLERATE_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<SAMPLERATE_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<SAMPLERATE_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<SAMPLERATE_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `CC` reader - Capture and compare value. Sample rate is 16 MHz/CC"]
38pub type CC_R = crate::FieldReader<u16, u16>;
39#[doc = "Field `CC` writer - Capture and compare value. Sample rate is 16 MHz/CC"]
40pub type CC_W<'a, const O: u8> = crate::FieldWriter<'a, u32, SAMPLERATE_SPEC, u16, u16, 11, O>;
41#[doc = "Field `MODE` reader - Select mode for sample rate control"]
42pub type MODE_R = crate::BitReader<MODE_A>;
43#[doc = "Select mode for sample rate control\n\nValue on reset: 0"]
44#[derive(Clone, Copy, Debug, PartialEq)]
45pub enum MODE_A {
46    #[doc = "0: Rate is controlled from SAMPLE task"]
47    TASK = 0,
48    #[doc = "1: Rate is controlled from local timer (use CC to control the rate)"]
49    TIMERS = 1,
50}
51impl From<MODE_A> for bool {
52    #[inline(always)]
53    fn from(variant: MODE_A) -> Self {
54        variant as u8 != 0
55    }
56}
57impl MODE_R {
58    #[doc = "Get enumerated values variant"]
59    #[inline(always)]
60    pub fn variant(&self) -> MODE_A {
61        match self.bits {
62            false => MODE_A::TASK,
63            true => MODE_A::TIMERS,
64        }
65    }
66    #[doc = "Checks if the value of the field is `TASK`"]
67    #[inline(always)]
68    pub fn is_task(&self) -> bool {
69        *self == MODE_A::TASK
70    }
71    #[doc = "Checks if the value of the field is `TIMERS`"]
72    #[inline(always)]
73    pub fn is_timers(&self) -> bool {
74        *self == MODE_A::TIMERS
75    }
76}
77#[doc = "Field `MODE` writer - Select mode for sample rate control"]
78pub type MODE_W<'a, const O: u8> = crate::BitWriter<'a, u32, SAMPLERATE_SPEC, MODE_A, O>;
79impl<'a, const O: u8> MODE_W<'a, O> {
80    #[doc = "Rate is controlled from SAMPLE task"]
81    #[inline(always)]
82    pub fn task(self) -> &'a mut W {
83        self.variant(MODE_A::TASK)
84    }
85    #[doc = "Rate is controlled from local timer (use CC to control the rate)"]
86    #[inline(always)]
87    pub fn timers(self) -> &'a mut W {
88        self.variant(MODE_A::TIMERS)
89    }
90}
91impl R {
92    #[doc = "Bits 0:10 - Capture and compare value. Sample rate is 16 MHz/CC"]
93    #[inline(always)]
94    pub fn cc(&self) -> CC_R {
95        CC_R::new((self.bits & 0x07ff) as u16)
96    }
97    #[doc = "Bit 12 - Select mode for sample rate control"]
98    #[inline(always)]
99    pub fn mode(&self) -> MODE_R {
100        MODE_R::new(((self.bits >> 12) & 1) != 0)
101    }
102}
103impl W {
104    #[doc = "Bits 0:10 - Capture and compare value. Sample rate is 16 MHz/CC"]
105    #[inline(always)]
106    pub fn cc(&mut self) -> CC_W<0> {
107        CC_W::new(self)
108    }
109    #[doc = "Bit 12 - Select mode for sample rate control"]
110    #[inline(always)]
111    pub fn mode(&mut self) -> MODE_W<12> {
112        MODE_W::new(self)
113    }
114    #[doc = "Writes raw bits to the register."]
115    #[inline(always)]
116    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
117        self.0.bits(bits);
118        self
119    }
120}
121#[doc = "Controls normal or continuous sample rate\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 [samplerate](index.html) module"]
122pub struct SAMPLERATE_SPEC;
123impl crate::RegisterSpec for SAMPLERATE_SPEC {
124    type Ux = u32;
125}
126#[doc = "`read()` method returns [samplerate::R](R) reader structure"]
127impl crate::Readable for SAMPLERATE_SPEC {
128    type Reader = R;
129}
130#[doc = "`write(|w| ..)` method takes [samplerate::W](W) writer structure"]
131impl crate::Writable for SAMPLERATE_SPEC {
132    type Writer = W;
133}
134#[doc = "`reset()` method sets SAMPLERATE to value 0"]
135impl crate::Resettable for SAMPLERATE_SPEC {
136    #[inline(always)]
137    fn reset_value() -> Self::Ux {
138        0
139    }
140}