avr_device/devices/attiny85/tc1/
tccr1.rs

1#[doc = "Register `TCCR1` reader"]
2pub struct R(crate::R<TCCR1_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<TCCR1_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<TCCR1_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<TCCR1_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `TCCR1` writer"]
17pub struct W(crate::W<TCCR1_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<TCCR1_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<TCCR1_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<TCCR1_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `CS1` reader - Clock Select Bits"]
38pub type CS1_R = crate::FieldReader<u8, CS1_A>;
39#[doc = "Clock Select Bits\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41#[repr(u8)]
42pub enum CS1_A {
43    #[doc = "0: No clock source (Timer/Counter stopped)"]
44    NO_CLOCK = 0,
45    #[doc = "1: Running, No Prescaling"]
46    DIRECT = 1,
47    #[doc = "2: Running, CLK/2"]
48    PRESCALE_2 = 2,
49    #[doc = "3: Running, CLK/4"]
50    PRESCALE_4 = 3,
51    #[doc = "4: Running, CLK/8"]
52    PRESCALE_8 = 4,
53    #[doc = "5: Running, CLK/16"]
54    PRESCALE_16 = 5,
55    #[doc = "6: Running, CLK/32"]
56    PRESCALE_32 = 6,
57    #[doc = "7: Running, CLK/64"]
58    PRESCALE_64 = 7,
59    #[doc = "8: Running, CLK/128"]
60    PRESCALE_128 = 8,
61    #[doc = "9: Running, CLK/256"]
62    PRESCALE_256 = 9,
63    #[doc = "10: Running, CLK/512"]
64    PRESCALE_512 = 10,
65    #[doc = "11: Running, CLK/1024"]
66    PRESCALE_1024 = 11,
67    #[doc = "12: Running, CLK/2048"]
68    PRESCALE_2048 = 12,
69    #[doc = "13: Running, CLK/4096"]
70    PRESCALE_4096 = 13,
71    #[doc = "14: Running, CLK/8192"]
72    PRESCALE_8192 = 14,
73    #[doc = "15: Running, CLK/16384"]
74    PRESCALE_16384 = 15,
75}
76impl From<CS1_A> for u8 {
77    #[inline(always)]
78    fn from(variant: CS1_A) -> Self {
79        variant as _
80    }
81}
82impl CS1_R {
83    #[doc = "Get enumerated values variant"]
84    #[inline(always)]
85    pub fn variant(&self) -> CS1_A {
86        match self.bits {
87            0 => CS1_A::NO_CLOCK,
88            1 => CS1_A::DIRECT,
89            2 => CS1_A::PRESCALE_2,
90            3 => CS1_A::PRESCALE_4,
91            4 => CS1_A::PRESCALE_8,
92            5 => CS1_A::PRESCALE_16,
93            6 => CS1_A::PRESCALE_32,
94            7 => CS1_A::PRESCALE_64,
95            8 => CS1_A::PRESCALE_128,
96            9 => CS1_A::PRESCALE_256,
97            10 => CS1_A::PRESCALE_512,
98            11 => CS1_A::PRESCALE_1024,
99            12 => CS1_A::PRESCALE_2048,
100            13 => CS1_A::PRESCALE_4096,
101            14 => CS1_A::PRESCALE_8192,
102            15 => CS1_A::PRESCALE_16384,
103            _ => unreachable!(),
104        }
105    }
106    #[doc = "Checks if the value of the field is `NO_CLOCK`"]
107    #[inline(always)]
108    pub fn is_no_clock(&self) -> bool {
109        *self == CS1_A::NO_CLOCK
110    }
111    #[doc = "Checks if the value of the field is `DIRECT`"]
112    #[inline(always)]
113    pub fn is_direct(&self) -> bool {
114        *self == CS1_A::DIRECT
115    }
116    #[doc = "Checks if the value of the field is `PRESCALE_2`"]
117    #[inline(always)]
118    pub fn is_prescale_2(&self) -> bool {
119        *self == CS1_A::PRESCALE_2
120    }
121    #[doc = "Checks if the value of the field is `PRESCALE_4`"]
122    #[inline(always)]
123    pub fn is_prescale_4(&self) -> bool {
124        *self == CS1_A::PRESCALE_4
125    }
126    #[doc = "Checks if the value of the field is `PRESCALE_8`"]
127    #[inline(always)]
128    pub fn is_prescale_8(&self) -> bool {
129        *self == CS1_A::PRESCALE_8
130    }
131    #[doc = "Checks if the value of the field is `PRESCALE_16`"]
132    #[inline(always)]
133    pub fn is_prescale_16(&self) -> bool {
134        *self == CS1_A::PRESCALE_16
135    }
136    #[doc = "Checks if the value of the field is `PRESCALE_32`"]
137    #[inline(always)]
138    pub fn is_prescale_32(&self) -> bool {
139        *self == CS1_A::PRESCALE_32
140    }
141    #[doc = "Checks if the value of the field is `PRESCALE_64`"]
142    #[inline(always)]
143    pub fn is_prescale_64(&self) -> bool {
144        *self == CS1_A::PRESCALE_64
145    }
146    #[doc = "Checks if the value of the field is `PRESCALE_128`"]
147    #[inline(always)]
148    pub fn is_prescale_128(&self) -> bool {
149        *self == CS1_A::PRESCALE_128
150    }
151    #[doc = "Checks if the value of the field is `PRESCALE_256`"]
152    #[inline(always)]
153    pub fn is_prescale_256(&self) -> bool {
154        *self == CS1_A::PRESCALE_256
155    }
156    #[doc = "Checks if the value of the field is `PRESCALE_512`"]
157    #[inline(always)]
158    pub fn is_prescale_512(&self) -> bool {
159        *self == CS1_A::PRESCALE_512
160    }
161    #[doc = "Checks if the value of the field is `PRESCALE_1024`"]
162    #[inline(always)]
163    pub fn is_prescale_1024(&self) -> bool {
164        *self == CS1_A::PRESCALE_1024
165    }
166    #[doc = "Checks if the value of the field is `PRESCALE_2048`"]
167    #[inline(always)]
168    pub fn is_prescale_2048(&self) -> bool {
169        *self == CS1_A::PRESCALE_2048
170    }
171    #[doc = "Checks if the value of the field is `PRESCALE_4096`"]
172    #[inline(always)]
173    pub fn is_prescale_4096(&self) -> bool {
174        *self == CS1_A::PRESCALE_4096
175    }
176    #[doc = "Checks if the value of the field is `PRESCALE_8192`"]
177    #[inline(always)]
178    pub fn is_prescale_8192(&self) -> bool {
179        *self == CS1_A::PRESCALE_8192
180    }
181    #[doc = "Checks if the value of the field is `PRESCALE_16384`"]
182    #[inline(always)]
183    pub fn is_prescale_16384(&self) -> bool {
184        *self == CS1_A::PRESCALE_16384
185    }
186}
187#[doc = "Field `CS1` writer - Clock Select Bits"]
188pub type CS1_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u8, TCCR1_SPEC, u8, CS1_A, 4, O>;
189impl<'a, const O: u8> CS1_W<'a, O> {
190    #[doc = "No clock source (Timer/Counter stopped)"]
191    #[inline(always)]
192    pub fn no_clock(self) -> &'a mut W {
193        self.variant(CS1_A::NO_CLOCK)
194    }
195    #[doc = "Running, No Prescaling"]
196    #[inline(always)]
197    pub fn direct(self) -> &'a mut W {
198        self.variant(CS1_A::DIRECT)
199    }
200    #[doc = "Running, CLK/2"]
201    #[inline(always)]
202    pub fn prescale_2(self) -> &'a mut W {
203        self.variant(CS1_A::PRESCALE_2)
204    }
205    #[doc = "Running, CLK/4"]
206    #[inline(always)]
207    pub fn prescale_4(self) -> &'a mut W {
208        self.variant(CS1_A::PRESCALE_4)
209    }
210    #[doc = "Running, CLK/8"]
211    #[inline(always)]
212    pub fn prescale_8(self) -> &'a mut W {
213        self.variant(CS1_A::PRESCALE_8)
214    }
215    #[doc = "Running, CLK/16"]
216    #[inline(always)]
217    pub fn prescale_16(self) -> &'a mut W {
218        self.variant(CS1_A::PRESCALE_16)
219    }
220    #[doc = "Running, CLK/32"]
221    #[inline(always)]
222    pub fn prescale_32(self) -> &'a mut W {
223        self.variant(CS1_A::PRESCALE_32)
224    }
225    #[doc = "Running, CLK/64"]
226    #[inline(always)]
227    pub fn prescale_64(self) -> &'a mut W {
228        self.variant(CS1_A::PRESCALE_64)
229    }
230    #[doc = "Running, CLK/128"]
231    #[inline(always)]
232    pub fn prescale_128(self) -> &'a mut W {
233        self.variant(CS1_A::PRESCALE_128)
234    }
235    #[doc = "Running, CLK/256"]
236    #[inline(always)]
237    pub fn prescale_256(self) -> &'a mut W {
238        self.variant(CS1_A::PRESCALE_256)
239    }
240    #[doc = "Running, CLK/512"]
241    #[inline(always)]
242    pub fn prescale_512(self) -> &'a mut W {
243        self.variant(CS1_A::PRESCALE_512)
244    }
245    #[doc = "Running, CLK/1024"]
246    #[inline(always)]
247    pub fn prescale_1024(self) -> &'a mut W {
248        self.variant(CS1_A::PRESCALE_1024)
249    }
250    #[doc = "Running, CLK/2048"]
251    #[inline(always)]
252    pub fn prescale_2048(self) -> &'a mut W {
253        self.variant(CS1_A::PRESCALE_2048)
254    }
255    #[doc = "Running, CLK/4096"]
256    #[inline(always)]
257    pub fn prescale_4096(self) -> &'a mut W {
258        self.variant(CS1_A::PRESCALE_4096)
259    }
260    #[doc = "Running, CLK/8192"]
261    #[inline(always)]
262    pub fn prescale_8192(self) -> &'a mut W {
263        self.variant(CS1_A::PRESCALE_8192)
264    }
265    #[doc = "Running, CLK/16384"]
266    #[inline(always)]
267    pub fn prescale_16384(self) -> &'a mut W {
268        self.variant(CS1_A::PRESCALE_16384)
269    }
270}
271#[doc = "Field `COM1A` reader - Compare Output Mode, Bits"]
272pub type COM1A_R = crate::FieldReader<u8, COM1A_A>;
273#[doc = "Compare Output Mode, Bits\n\nValue on reset: 0"]
274#[derive(Clone, Copy, Debug, PartialEq, Eq)]
275#[repr(u8)]
276pub enum COM1A_A {
277    #[doc = "0: Normal port operation, OCix disconnected"]
278    DISCONNECTED = 0,
279    #[doc = "1: Toggle OCix on Compare Match"]
280    MATCH_TOGGLE = 1,
281    #[doc = "2: Clear OCix on Compare Match"]
282    MATCH_CLEAR = 2,
283    #[doc = "3: Set OCix on Compare Match"]
284    MATCH_SET = 3,
285}
286impl From<COM1A_A> for u8 {
287    #[inline(always)]
288    fn from(variant: COM1A_A) -> Self {
289        variant as _
290    }
291}
292impl COM1A_R {
293    #[doc = "Get enumerated values variant"]
294    #[inline(always)]
295    pub fn variant(&self) -> COM1A_A {
296        match self.bits {
297            0 => COM1A_A::DISCONNECTED,
298            1 => COM1A_A::MATCH_TOGGLE,
299            2 => COM1A_A::MATCH_CLEAR,
300            3 => COM1A_A::MATCH_SET,
301            _ => unreachable!(),
302        }
303    }
304    #[doc = "Checks if the value of the field is `DISCONNECTED`"]
305    #[inline(always)]
306    pub fn is_disconnected(&self) -> bool {
307        *self == COM1A_A::DISCONNECTED
308    }
309    #[doc = "Checks if the value of the field is `MATCH_TOGGLE`"]
310    #[inline(always)]
311    pub fn is_match_toggle(&self) -> bool {
312        *self == COM1A_A::MATCH_TOGGLE
313    }
314    #[doc = "Checks if the value of the field is `MATCH_CLEAR`"]
315    #[inline(always)]
316    pub fn is_match_clear(&self) -> bool {
317        *self == COM1A_A::MATCH_CLEAR
318    }
319    #[doc = "Checks if the value of the field is `MATCH_SET`"]
320    #[inline(always)]
321    pub fn is_match_set(&self) -> bool {
322        *self == COM1A_A::MATCH_SET
323    }
324}
325#[doc = "Field `COM1A` writer - Compare Output Mode, Bits"]
326pub type COM1A_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u8, TCCR1_SPEC, u8, COM1A_A, 2, O>;
327impl<'a, const O: u8> COM1A_W<'a, O> {
328    #[doc = "Normal port operation, OCix disconnected"]
329    #[inline(always)]
330    pub fn disconnected(self) -> &'a mut W {
331        self.variant(COM1A_A::DISCONNECTED)
332    }
333    #[doc = "Toggle OCix on Compare Match"]
334    #[inline(always)]
335    pub fn match_toggle(self) -> &'a mut W {
336        self.variant(COM1A_A::MATCH_TOGGLE)
337    }
338    #[doc = "Clear OCix on Compare Match"]
339    #[inline(always)]
340    pub fn match_clear(self) -> &'a mut W {
341        self.variant(COM1A_A::MATCH_CLEAR)
342    }
343    #[doc = "Set OCix on Compare Match"]
344    #[inline(always)]
345    pub fn match_set(self) -> &'a mut W {
346        self.variant(COM1A_A::MATCH_SET)
347    }
348}
349#[doc = "Field `PWM1A` reader - Pulse Width Modulator Enable"]
350pub type PWM1A_R = crate::BitReader<bool>;
351#[doc = "Field `PWM1A` writer - Pulse Width Modulator Enable"]
352pub type PWM1A_W<'a, const O: u8> = crate::BitWriter<'a, u8, TCCR1_SPEC, bool, O>;
353#[doc = "Field `CTC1` reader - Clear Timer/Counter on Compare Match"]
354pub type CTC1_R = crate::BitReader<bool>;
355#[doc = "Field `CTC1` writer - Clear Timer/Counter on Compare Match"]
356pub type CTC1_W<'a, const O: u8> = crate::BitWriter<'a, u8, TCCR1_SPEC, bool, O>;
357impl R {
358    #[doc = "Bits 0:3 - Clock Select Bits"]
359    #[inline(always)]
360    pub fn cs1(&self) -> CS1_R {
361        CS1_R::new(self.bits & 0x0f)
362    }
363    #[doc = "Bits 4:5 - Compare Output Mode, Bits"]
364    #[inline(always)]
365    pub fn com1a(&self) -> COM1A_R {
366        COM1A_R::new((self.bits >> 4) & 3)
367    }
368    #[doc = "Bit 6 - Pulse Width Modulator Enable"]
369    #[inline(always)]
370    pub fn pwm1a(&self) -> PWM1A_R {
371        PWM1A_R::new(((self.bits >> 6) & 1) != 0)
372    }
373    #[doc = "Bit 7 - Clear Timer/Counter on Compare Match"]
374    #[inline(always)]
375    pub fn ctc1(&self) -> CTC1_R {
376        CTC1_R::new(((self.bits >> 7) & 1) != 0)
377    }
378}
379impl W {
380    #[doc = "Bits 0:3 - Clock Select Bits"]
381    #[inline(always)]
382    #[must_use]
383    pub fn cs1(&mut self) -> CS1_W<0> {
384        CS1_W::new(self)
385    }
386    #[doc = "Bits 4:5 - Compare Output Mode, Bits"]
387    #[inline(always)]
388    #[must_use]
389    pub fn com1a(&mut self) -> COM1A_W<4> {
390        COM1A_W::new(self)
391    }
392    #[doc = "Bit 6 - Pulse Width Modulator Enable"]
393    #[inline(always)]
394    #[must_use]
395    pub fn pwm1a(&mut self) -> PWM1A_W<6> {
396        PWM1A_W::new(self)
397    }
398    #[doc = "Bit 7 - Clear Timer/Counter on Compare Match"]
399    #[inline(always)]
400    #[must_use]
401    pub fn ctc1(&mut self) -> CTC1_W<7> {
402        CTC1_W::new(self)
403    }
404    #[doc = "Writes raw bits to the register."]
405    #[inline(always)]
406    pub unsafe fn bits(&mut self, bits: u8) -> &mut Self {
407        self.0.bits(bits);
408        self
409    }
410}
411#[doc = "Timer/Counter Control Register\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 [tccr1](index.html) module"]
412pub struct TCCR1_SPEC;
413impl crate::RegisterSpec for TCCR1_SPEC {
414    type Ux = u8;
415}
416#[doc = "`read()` method returns [tccr1::R](R) reader structure"]
417impl crate::Readable for TCCR1_SPEC {
418    type Reader = R;
419}
420#[doc = "`write(|w| ..)` method takes [tccr1::W](W) writer structure"]
421impl crate::Writable for TCCR1_SPEC {
422    type Writer = W;
423    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
424    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
425}
426#[doc = "`reset()` method sets TCCR1 to value 0"]
427impl crate::Resettable for TCCR1_SPEC {
428    const RESET_VALUE: Self::Ux = 0;
429}