nrf52840_pac/pwm0/
prescaler.rs

1#[doc = "Register `PRESCALER` reader"]
2pub struct R(crate::R<PRESCALER_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<PRESCALER_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<PRESCALER_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<PRESCALER_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `PRESCALER` writer"]
17pub struct W(crate::W<PRESCALER_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<PRESCALER_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<PRESCALER_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<PRESCALER_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `PRESCALER` reader - Prescaler of PWM_CLK"]
38pub type PRESCALER_R = crate::FieldReader<u8, PRESCALER_A>;
39#[doc = "Prescaler of PWM_CLK\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq)]
41#[repr(u8)]
42pub enum PRESCALER_A {
43    #[doc = "0: Divide by 1 (16 MHz)"]
44    DIV_1 = 0,
45    #[doc = "1: Divide by 2 (8 MHz)"]
46    DIV_2 = 1,
47    #[doc = "2: Divide by 4 (4 MHz)"]
48    DIV_4 = 2,
49    #[doc = "3: Divide by 8 (2 MHz)"]
50    DIV_8 = 3,
51    #[doc = "4: Divide by 16 (1 MHz)"]
52    DIV_16 = 4,
53    #[doc = "5: Divide by 32 (500 kHz)"]
54    DIV_32 = 5,
55    #[doc = "6: Divide by 64 (250 kHz)"]
56    DIV_64 = 6,
57    #[doc = "7: Divide by 128 (125 kHz)"]
58    DIV_128 = 7,
59}
60impl From<PRESCALER_A> for u8 {
61    #[inline(always)]
62    fn from(variant: PRESCALER_A) -> Self {
63        variant as _
64    }
65}
66impl PRESCALER_R {
67    #[doc = "Get enumerated values variant"]
68    #[inline(always)]
69    pub fn variant(&self) -> PRESCALER_A {
70        match self.bits {
71            0 => PRESCALER_A::DIV_1,
72            1 => PRESCALER_A::DIV_2,
73            2 => PRESCALER_A::DIV_4,
74            3 => PRESCALER_A::DIV_8,
75            4 => PRESCALER_A::DIV_16,
76            5 => PRESCALER_A::DIV_32,
77            6 => PRESCALER_A::DIV_64,
78            7 => PRESCALER_A::DIV_128,
79            _ => unreachable!(),
80        }
81    }
82    #[doc = "Checks if the value of the field is `DIV_1`"]
83    #[inline(always)]
84    pub fn is_div_1(&self) -> bool {
85        *self == PRESCALER_A::DIV_1
86    }
87    #[doc = "Checks if the value of the field is `DIV_2`"]
88    #[inline(always)]
89    pub fn is_div_2(&self) -> bool {
90        *self == PRESCALER_A::DIV_2
91    }
92    #[doc = "Checks if the value of the field is `DIV_4`"]
93    #[inline(always)]
94    pub fn is_div_4(&self) -> bool {
95        *self == PRESCALER_A::DIV_4
96    }
97    #[doc = "Checks if the value of the field is `DIV_8`"]
98    #[inline(always)]
99    pub fn is_div_8(&self) -> bool {
100        *self == PRESCALER_A::DIV_8
101    }
102    #[doc = "Checks if the value of the field is `DIV_16`"]
103    #[inline(always)]
104    pub fn is_div_16(&self) -> bool {
105        *self == PRESCALER_A::DIV_16
106    }
107    #[doc = "Checks if the value of the field is `DIV_32`"]
108    #[inline(always)]
109    pub fn is_div_32(&self) -> bool {
110        *self == PRESCALER_A::DIV_32
111    }
112    #[doc = "Checks if the value of the field is `DIV_64`"]
113    #[inline(always)]
114    pub fn is_div_64(&self) -> bool {
115        *self == PRESCALER_A::DIV_64
116    }
117    #[doc = "Checks if the value of the field is `DIV_128`"]
118    #[inline(always)]
119    pub fn is_div_128(&self) -> bool {
120        *self == PRESCALER_A::DIV_128
121    }
122}
123#[doc = "Field `PRESCALER` writer - Prescaler of PWM_CLK"]
124pub type PRESCALER_W<'a, const O: u8> =
125    crate::FieldWriterSafe<'a, u32, PRESCALER_SPEC, u8, PRESCALER_A, 3, O>;
126impl<'a, const O: u8> PRESCALER_W<'a, O> {
127    #[doc = "Divide by 1 (16 MHz)"]
128    #[inline(always)]
129    pub fn div_1(self) -> &'a mut W {
130        self.variant(PRESCALER_A::DIV_1)
131    }
132    #[doc = "Divide by 2 (8 MHz)"]
133    #[inline(always)]
134    pub fn div_2(self) -> &'a mut W {
135        self.variant(PRESCALER_A::DIV_2)
136    }
137    #[doc = "Divide by 4 (4 MHz)"]
138    #[inline(always)]
139    pub fn div_4(self) -> &'a mut W {
140        self.variant(PRESCALER_A::DIV_4)
141    }
142    #[doc = "Divide by 8 (2 MHz)"]
143    #[inline(always)]
144    pub fn div_8(self) -> &'a mut W {
145        self.variant(PRESCALER_A::DIV_8)
146    }
147    #[doc = "Divide by 16 (1 MHz)"]
148    #[inline(always)]
149    pub fn div_16(self) -> &'a mut W {
150        self.variant(PRESCALER_A::DIV_16)
151    }
152    #[doc = "Divide by 32 (500 kHz)"]
153    #[inline(always)]
154    pub fn div_32(self) -> &'a mut W {
155        self.variant(PRESCALER_A::DIV_32)
156    }
157    #[doc = "Divide by 64 (250 kHz)"]
158    #[inline(always)]
159    pub fn div_64(self) -> &'a mut W {
160        self.variant(PRESCALER_A::DIV_64)
161    }
162    #[doc = "Divide by 128 (125 kHz)"]
163    #[inline(always)]
164    pub fn div_128(self) -> &'a mut W {
165        self.variant(PRESCALER_A::DIV_128)
166    }
167}
168impl R {
169    #[doc = "Bits 0:2 - Prescaler of PWM_CLK"]
170    #[inline(always)]
171    pub fn prescaler(&self) -> PRESCALER_R {
172        PRESCALER_R::new((self.bits & 7) as u8)
173    }
174}
175impl W {
176    #[doc = "Bits 0:2 - Prescaler of PWM_CLK"]
177    #[inline(always)]
178    pub fn prescaler(&mut self) -> PRESCALER_W<0> {
179        PRESCALER_W::new(self)
180    }
181    #[doc = "Writes raw bits to the register."]
182    #[inline(always)]
183    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
184        self.0.bits(bits);
185        self
186    }
187}
188#[doc = "Configuration for PWM_CLK\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 [prescaler](index.html) module"]
189pub struct PRESCALER_SPEC;
190impl crate::RegisterSpec for PRESCALER_SPEC {
191    type Ux = u32;
192}
193#[doc = "`read()` method returns [prescaler::R](R) reader structure"]
194impl crate::Readable for PRESCALER_SPEC {
195    type Reader = R;
196}
197#[doc = "`write(|w| ..)` method takes [prescaler::W](W) writer structure"]
198impl crate::Writable for PRESCALER_SPEC {
199    type Writer = W;
200}
201#[doc = "`reset()` method sets PRESCALER to value 0"]
202impl crate::Resettable for PRESCALER_SPEC {
203    #[inline(always)]
204    fn reset_value() -> Self::Ux {
205        0
206    }
207}