nrf52840_pac/pwm0/
decoder.rs

1#[doc = "Register `DECODER` reader"]
2pub struct R(crate::R<DECODER_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<DECODER_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<DECODER_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<DECODER_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `DECODER` writer"]
17pub struct W(crate::W<DECODER_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<DECODER_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<DECODER_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<DECODER_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `LOAD` reader - How a sequence is read from RAM and spread to the compare register"]
38pub type LOAD_R = crate::FieldReader<u8, LOAD_A>;
39#[doc = "How a sequence is read from RAM and spread to the compare register\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq)]
41#[repr(u8)]
42pub enum LOAD_A {
43    #[doc = "0: 1st half word (16-bit) used in all PWM channels 0..3"]
44    COMMON = 0,
45    #[doc = "1: 1st half word (16-bit) used in channel 0..1; 2nd word in channel 2..3"]
46    GROUPED = 1,
47    #[doc = "2: 1st half word (16-bit) in ch.0; 2nd in ch.1; ...; 4th in ch.3"]
48    INDIVIDUAL = 2,
49    #[doc = "3: 1st half word (16-bit) in ch.0; 2nd in ch.1; ...; 4th in COUNTERTOP"]
50    WAVE_FORM = 3,
51}
52impl From<LOAD_A> for u8 {
53    #[inline(always)]
54    fn from(variant: LOAD_A) -> Self {
55        variant as _
56    }
57}
58impl LOAD_R {
59    #[doc = "Get enumerated values variant"]
60    #[inline(always)]
61    pub fn variant(&self) -> LOAD_A {
62        match self.bits {
63            0 => LOAD_A::COMMON,
64            1 => LOAD_A::GROUPED,
65            2 => LOAD_A::INDIVIDUAL,
66            3 => LOAD_A::WAVE_FORM,
67            _ => unreachable!(),
68        }
69    }
70    #[doc = "Checks if the value of the field is `COMMON`"]
71    #[inline(always)]
72    pub fn is_common(&self) -> bool {
73        *self == LOAD_A::COMMON
74    }
75    #[doc = "Checks if the value of the field is `GROUPED`"]
76    #[inline(always)]
77    pub fn is_grouped(&self) -> bool {
78        *self == LOAD_A::GROUPED
79    }
80    #[doc = "Checks if the value of the field is `INDIVIDUAL`"]
81    #[inline(always)]
82    pub fn is_individual(&self) -> bool {
83        *self == LOAD_A::INDIVIDUAL
84    }
85    #[doc = "Checks if the value of the field is `WAVE_FORM`"]
86    #[inline(always)]
87    pub fn is_wave_form(&self) -> bool {
88        *self == LOAD_A::WAVE_FORM
89    }
90}
91#[doc = "Field `LOAD` writer - How a sequence is read from RAM and spread to the compare register"]
92pub type LOAD_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u32, DECODER_SPEC, u8, LOAD_A, 2, O>;
93impl<'a, const O: u8> LOAD_W<'a, O> {
94    #[doc = "1st half word (16-bit) used in all PWM channels 0..3"]
95    #[inline(always)]
96    pub fn common(self) -> &'a mut W {
97        self.variant(LOAD_A::COMMON)
98    }
99    #[doc = "1st half word (16-bit) used in channel 0..1; 2nd word in channel 2..3"]
100    #[inline(always)]
101    pub fn grouped(self) -> &'a mut W {
102        self.variant(LOAD_A::GROUPED)
103    }
104    #[doc = "1st half word (16-bit) in ch.0; 2nd in ch.1; ...; 4th in ch.3"]
105    #[inline(always)]
106    pub fn individual(self) -> &'a mut W {
107        self.variant(LOAD_A::INDIVIDUAL)
108    }
109    #[doc = "1st half word (16-bit) in ch.0; 2nd in ch.1; ...; 4th in COUNTERTOP"]
110    #[inline(always)]
111    pub fn wave_form(self) -> &'a mut W {
112        self.variant(LOAD_A::WAVE_FORM)
113    }
114}
115#[doc = "Field `MODE` reader - Selects source for advancing the active sequence"]
116pub type MODE_R = crate::BitReader<MODE_A>;
117#[doc = "Selects source for advancing the active sequence\n\nValue on reset: 0"]
118#[derive(Clone, Copy, Debug, PartialEq)]
119pub enum MODE_A {
120    #[doc = "0: SEQ\\[n\\].REFRESH is used to determine loading internal compare registers"]
121    REFRESH_COUNT = 0,
122    #[doc = "1: NEXTSTEP task causes a new value to be loaded to internal compare registers"]
123    NEXT_STEP = 1,
124}
125impl From<MODE_A> for bool {
126    #[inline(always)]
127    fn from(variant: MODE_A) -> Self {
128        variant as u8 != 0
129    }
130}
131impl MODE_R {
132    #[doc = "Get enumerated values variant"]
133    #[inline(always)]
134    pub fn variant(&self) -> MODE_A {
135        match self.bits {
136            false => MODE_A::REFRESH_COUNT,
137            true => MODE_A::NEXT_STEP,
138        }
139    }
140    #[doc = "Checks if the value of the field is `REFRESH_COUNT`"]
141    #[inline(always)]
142    pub fn is_refresh_count(&self) -> bool {
143        *self == MODE_A::REFRESH_COUNT
144    }
145    #[doc = "Checks if the value of the field is `NEXT_STEP`"]
146    #[inline(always)]
147    pub fn is_next_step(&self) -> bool {
148        *self == MODE_A::NEXT_STEP
149    }
150}
151#[doc = "Field `MODE` writer - Selects source for advancing the active sequence"]
152pub type MODE_W<'a, const O: u8> = crate::BitWriter<'a, u32, DECODER_SPEC, MODE_A, O>;
153impl<'a, const O: u8> MODE_W<'a, O> {
154    #[doc = "SEQ\\[n\\].REFRESH is used to determine loading internal compare registers"]
155    #[inline(always)]
156    pub fn refresh_count(self) -> &'a mut W {
157        self.variant(MODE_A::REFRESH_COUNT)
158    }
159    #[doc = "NEXTSTEP task causes a new value to be loaded to internal compare registers"]
160    #[inline(always)]
161    pub fn next_step(self) -> &'a mut W {
162        self.variant(MODE_A::NEXT_STEP)
163    }
164}
165impl R {
166    #[doc = "Bits 0:1 - How a sequence is read from RAM and spread to the compare register"]
167    #[inline(always)]
168    pub fn load(&self) -> LOAD_R {
169        LOAD_R::new((self.bits & 3) as u8)
170    }
171    #[doc = "Bit 8 - Selects source for advancing the active sequence"]
172    #[inline(always)]
173    pub fn mode(&self) -> MODE_R {
174        MODE_R::new(((self.bits >> 8) & 1) != 0)
175    }
176}
177impl W {
178    #[doc = "Bits 0:1 - How a sequence is read from RAM and spread to the compare register"]
179    #[inline(always)]
180    pub fn load(&mut self) -> LOAD_W<0> {
181        LOAD_W::new(self)
182    }
183    #[doc = "Bit 8 - Selects source for advancing the active sequence"]
184    #[inline(always)]
185    pub fn mode(&mut self) -> MODE_W<8> {
186        MODE_W::new(self)
187    }
188    #[doc = "Writes raw bits to the register."]
189    #[inline(always)]
190    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
191        self.0.bits(bits);
192        self
193    }
194}
195#[doc = "Configuration of the decoder\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 [decoder](index.html) module"]
196pub struct DECODER_SPEC;
197impl crate::RegisterSpec for DECODER_SPEC {
198    type Ux = u32;
199}
200#[doc = "`read()` method returns [decoder::R](R) reader structure"]
201impl crate::Readable for DECODER_SPEC {
202    type Reader = R;
203}
204#[doc = "`write(|w| ..)` method takes [decoder::W](W) writer structure"]
205impl crate::Writable for DECODER_SPEC {
206    type Writer = W;
207}
208#[doc = "`reset()` method sets DECODER to value 0"]
209impl crate::Resettable for DECODER_SPEC {
210    #[inline(always)]
211    fn reset_value() -> Self::Ux {
212        0
213    }
214}