lpc845_pac/ctimer0/
tcr.rs

1#[doc = "Register `TCR` reader"]
2pub struct R(crate::R<TCR_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<TCR_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<TCR_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<TCR_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `TCR` writer"]
17pub struct W(crate::W<TCR_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<TCR_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<TCR_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<TCR_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Counter enable.\n\nValue on reset: 0"]
38#[derive(Clone, Copy, Debug, PartialEq)]
39pub enum CEN_A {
40    #[doc = "0: Disabled.The counters are disabled."]
41    DISABLED = 0,
42    #[doc = "1: Enabled. The Timer Counter and Prescale Counter are enabled."]
43    ENABLED = 1,
44}
45impl From<CEN_A> for bool {
46    #[inline(always)]
47    fn from(variant: CEN_A) -> Self {
48        variant as u8 != 0
49    }
50}
51#[doc = "Field `CEN` reader - Counter enable."]
52pub struct CEN_R(crate::FieldReader<bool, CEN_A>);
53impl CEN_R {
54    pub(crate) fn new(bits: bool) -> Self {
55        CEN_R(crate::FieldReader::new(bits))
56    }
57    #[doc = r"Get enumerated values variant"]
58    #[inline(always)]
59    pub fn variant(&self) -> CEN_A {
60        match self.bits {
61            false => CEN_A::DISABLED,
62            true => CEN_A::ENABLED,
63        }
64    }
65    #[doc = "Checks if the value of the field is `DISABLED`"]
66    #[inline(always)]
67    pub fn is_disabled(&self) -> bool {
68        **self == CEN_A::DISABLED
69    }
70    #[doc = "Checks if the value of the field is `ENABLED`"]
71    #[inline(always)]
72    pub fn is_enabled(&self) -> bool {
73        **self == CEN_A::ENABLED
74    }
75}
76impl core::ops::Deref for CEN_R {
77    type Target = crate::FieldReader<bool, CEN_A>;
78    #[inline(always)]
79    fn deref(&self) -> &Self::Target {
80        &self.0
81    }
82}
83#[doc = "Field `CEN` writer - Counter enable."]
84pub struct CEN_W<'a> {
85    w: &'a mut W,
86}
87impl<'a> CEN_W<'a> {
88    #[doc = r"Writes `variant` to the field"]
89    #[inline(always)]
90    pub fn variant(self, variant: CEN_A) -> &'a mut W {
91        self.bit(variant.into())
92    }
93    #[doc = "Disabled.The counters are disabled."]
94    #[inline(always)]
95    pub fn disabled(self) -> &'a mut W {
96        self.variant(CEN_A::DISABLED)
97    }
98    #[doc = "Enabled. The Timer Counter and Prescale Counter are enabled."]
99    #[inline(always)]
100    pub fn enabled(self) -> &'a mut W {
101        self.variant(CEN_A::ENABLED)
102    }
103    #[doc = r"Sets the field bit"]
104    #[inline(always)]
105    pub fn set_bit(self) -> &'a mut W {
106        self.bit(true)
107    }
108    #[doc = r"Clears the field bit"]
109    #[inline(always)]
110    pub fn clear_bit(self) -> &'a mut W {
111        self.bit(false)
112    }
113    #[doc = r"Writes raw bits to the field"]
114    #[inline(always)]
115    pub fn bit(self, value: bool) -> &'a mut W {
116        self.w.bits = (self.w.bits & !0x01) | (value as u32 & 0x01);
117        self.w
118    }
119}
120#[doc = "Counter reset.\n\nValue on reset: 0"]
121#[derive(Clone, Copy, Debug, PartialEq)]
122pub enum CRST_A {
123    #[doc = "0: Disabled. Do nothing."]
124    DISABLED = 0,
125    #[doc = "1: Enabled. The Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of the APB bus clock. The counters remain reset until TCR\\[1\\]
126is returned to zero."]
127    ENABLED = 1,
128}
129impl From<CRST_A> for bool {
130    #[inline(always)]
131    fn from(variant: CRST_A) -> Self {
132        variant as u8 != 0
133    }
134}
135#[doc = "Field `CRST` reader - Counter reset."]
136pub struct CRST_R(crate::FieldReader<bool, CRST_A>);
137impl CRST_R {
138    pub(crate) fn new(bits: bool) -> Self {
139        CRST_R(crate::FieldReader::new(bits))
140    }
141    #[doc = r"Get enumerated values variant"]
142    #[inline(always)]
143    pub fn variant(&self) -> CRST_A {
144        match self.bits {
145            false => CRST_A::DISABLED,
146            true => CRST_A::ENABLED,
147        }
148    }
149    #[doc = "Checks if the value of the field is `DISABLED`"]
150    #[inline(always)]
151    pub fn is_disabled(&self) -> bool {
152        **self == CRST_A::DISABLED
153    }
154    #[doc = "Checks if the value of the field is `ENABLED`"]
155    #[inline(always)]
156    pub fn is_enabled(&self) -> bool {
157        **self == CRST_A::ENABLED
158    }
159}
160impl core::ops::Deref for CRST_R {
161    type Target = crate::FieldReader<bool, CRST_A>;
162    #[inline(always)]
163    fn deref(&self) -> &Self::Target {
164        &self.0
165    }
166}
167#[doc = "Field `CRST` writer - Counter reset."]
168pub struct CRST_W<'a> {
169    w: &'a mut W,
170}
171impl<'a> CRST_W<'a> {
172    #[doc = r"Writes `variant` to the field"]
173    #[inline(always)]
174    pub fn variant(self, variant: CRST_A) -> &'a mut W {
175        self.bit(variant.into())
176    }
177    #[doc = "Disabled. Do nothing."]
178    #[inline(always)]
179    pub fn disabled(self) -> &'a mut W {
180        self.variant(CRST_A::DISABLED)
181    }
182    #[doc = "Enabled. The Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of the APB bus clock. The counters remain reset until TCR\\[1\\]
183is returned to zero."]
184    #[inline(always)]
185    pub fn enabled(self) -> &'a mut W {
186        self.variant(CRST_A::ENABLED)
187    }
188    #[doc = r"Sets the field bit"]
189    #[inline(always)]
190    pub fn set_bit(self) -> &'a mut W {
191        self.bit(true)
192    }
193    #[doc = r"Clears the field bit"]
194    #[inline(always)]
195    pub fn clear_bit(self) -> &'a mut W {
196        self.bit(false)
197    }
198    #[doc = r"Writes raw bits to the field"]
199    #[inline(always)]
200    pub fn bit(self, value: bool) -> &'a mut W {
201        self.w.bits = (self.w.bits & !(0x01 << 1)) | ((value as u32 & 0x01) << 1);
202        self.w
203    }
204}
205impl R {
206    #[doc = "Bit 0 - Counter enable."]
207    #[inline(always)]
208    pub fn cen(&self) -> CEN_R {
209        CEN_R::new((self.bits & 0x01) != 0)
210    }
211    #[doc = "Bit 1 - Counter reset."]
212    #[inline(always)]
213    pub fn crst(&self) -> CRST_R {
214        CRST_R::new(((self.bits >> 1) & 0x01) != 0)
215    }
216}
217impl W {
218    #[doc = "Bit 0 - Counter enable."]
219    #[inline(always)]
220    pub fn cen(&mut self) -> CEN_W {
221        CEN_W { w: self }
222    }
223    #[doc = "Bit 1 - Counter reset."]
224    #[inline(always)]
225    pub fn crst(&mut self) -> CRST_W {
226        CRST_W { w: self }
227    }
228    #[doc = "Writes raw bits to the register."]
229    #[inline(always)]
230    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
231        self.0.bits(bits);
232        self
233    }
234}
235#[doc = "Timer Control Register. The TCR is used to control the Timer Counter functions. The Timer Counter can be disabled or reset through the TCR.\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 [tcr](index.html) module"]
236pub struct TCR_SPEC;
237impl crate::RegisterSpec for TCR_SPEC {
238    type Ux = u32;
239}
240#[doc = "`read()` method returns [tcr::R](R) reader structure"]
241impl crate::Readable for TCR_SPEC {
242    type Reader = R;
243}
244#[doc = "`write(|w| ..)` method takes [tcr::W](W) writer structure"]
245impl crate::Writable for TCR_SPEC {
246    type Writer = W;
247}
248#[doc = "`reset()` method sets TCR to value 0"]
249impl crate::Resettable for TCR_SPEC {
250    #[inline(always)]
251    fn reset_value() -> Self::Ux {
252        0
253    }
254}