atsamd21e18a/tc3/count8/
ctrlbset.rs

1#[doc = "Reader of register CTRLBSET"]
2pub type R = crate::R<u8, super::CTRLBSET>;
3#[doc = "Writer for register CTRLBSET"]
4pub type W = crate::W<u8, super::CTRLBSET>;
5#[doc = "Register CTRLBSET `reset()`'s with value 0"]
6impl crate::ResetValue for super::CTRLBSET {
7    type Type = u8;
8    #[inline(always)]
9    fn reset_value() -> Self::Type {
10        0
11    }
12}
13#[doc = "Reader of field `DIR`"]
14pub type DIR_R = crate::R<bool, bool>;
15#[doc = "Write proxy for field `DIR`"]
16pub struct DIR_W<'a> {
17    w: &'a mut W,
18}
19impl<'a> DIR_W<'a> {
20    #[doc = r"Sets the field bit"]
21    #[inline(always)]
22    pub fn set_bit(self) -> &'a mut W {
23        self.bit(true)
24    }
25    #[doc = r"Clears the field bit"]
26    #[inline(always)]
27    pub fn clear_bit(self) -> &'a mut W {
28        self.bit(false)
29    }
30    #[doc = r"Writes raw bits to the field"]
31    #[inline(always)]
32    pub fn bit(self, value: bool) -> &'a mut W {
33        self.w.bits = (self.w.bits & !0x01) | ((value as u8) & 0x01);
34        self.w
35    }
36}
37#[doc = "Reader of field `ONESHOT`"]
38pub type ONESHOT_R = crate::R<bool, bool>;
39#[doc = "Write proxy for field `ONESHOT`"]
40pub struct ONESHOT_W<'a> {
41    w: &'a mut W,
42}
43impl<'a> ONESHOT_W<'a> {
44    #[doc = r"Sets the field bit"]
45    #[inline(always)]
46    pub fn set_bit(self) -> &'a mut W {
47        self.bit(true)
48    }
49    #[doc = r"Clears the field bit"]
50    #[inline(always)]
51    pub fn clear_bit(self) -> &'a mut W {
52        self.bit(false)
53    }
54    #[doc = r"Writes raw bits to the field"]
55    #[inline(always)]
56    pub fn bit(self, value: bool) -> &'a mut W {
57        self.w.bits = (self.w.bits & !(0x01 << 2)) | (((value as u8) & 0x01) << 2);
58        self.w
59    }
60}
61#[doc = "Command\n\nValue on reset: 0"]
62#[derive(Clone, Copy, Debug, PartialEq)]
63#[repr(u8)]
64pub enum CMD_A {
65    #[doc = "0: No action"]
66    NONE = 0,
67    #[doc = "1: Force a start, restart or retrigger"]
68    RETRIGGER = 1,
69    #[doc = "2: Force a stop"]
70    STOP = 2,
71}
72impl From<CMD_A> for u8 {
73    #[inline(always)]
74    fn from(variant: CMD_A) -> Self {
75        variant as _
76    }
77}
78#[doc = "Reader of field `CMD`"]
79pub type CMD_R = crate::R<u8, CMD_A>;
80impl CMD_R {
81    #[doc = r"Get enumerated values variant"]
82    #[inline(always)]
83    pub fn variant(&self) -> crate::Variant<u8, CMD_A> {
84        use crate::Variant::*;
85        match self.bits {
86            0 => Val(CMD_A::NONE),
87            1 => Val(CMD_A::RETRIGGER),
88            2 => Val(CMD_A::STOP),
89            i => Res(i),
90        }
91    }
92    #[doc = "Checks if the value of the field is `NONE`"]
93    #[inline(always)]
94    pub fn is_none(&self) -> bool {
95        *self == CMD_A::NONE
96    }
97    #[doc = "Checks if the value of the field is `RETRIGGER`"]
98    #[inline(always)]
99    pub fn is_retrigger(&self) -> bool {
100        *self == CMD_A::RETRIGGER
101    }
102    #[doc = "Checks if the value of the field is `STOP`"]
103    #[inline(always)]
104    pub fn is_stop(&self) -> bool {
105        *self == CMD_A::STOP
106    }
107}
108#[doc = "Write proxy for field `CMD`"]
109pub struct CMD_W<'a> {
110    w: &'a mut W,
111}
112impl<'a> CMD_W<'a> {
113    #[doc = r"Writes `variant` to the field"]
114    #[inline(always)]
115    pub fn variant(self, variant: CMD_A) -> &'a mut W {
116        unsafe { self.bits(variant.into()) }
117    }
118    #[doc = "No action"]
119    #[inline(always)]
120    pub fn none(self) -> &'a mut W {
121        self.variant(CMD_A::NONE)
122    }
123    #[doc = "Force a start, restart or retrigger"]
124    #[inline(always)]
125    pub fn retrigger(self) -> &'a mut W {
126        self.variant(CMD_A::RETRIGGER)
127    }
128    #[doc = "Force a stop"]
129    #[inline(always)]
130    pub fn stop(self) -> &'a mut W {
131        self.variant(CMD_A::STOP)
132    }
133    #[doc = r"Writes raw bits to the field"]
134    #[inline(always)]
135    pub unsafe fn bits(self, value: u8) -> &'a mut W {
136        self.w.bits = (self.w.bits & !(0x03 << 6)) | (((value as u8) & 0x03) << 6);
137        self.w
138    }
139}
140impl R {
141    #[doc = "Bit 0 - Counter Direction"]
142    #[inline(always)]
143    pub fn dir(&self) -> DIR_R {
144        DIR_R::new((self.bits & 0x01) != 0)
145    }
146    #[doc = "Bit 2 - One-Shot"]
147    #[inline(always)]
148    pub fn oneshot(&self) -> ONESHOT_R {
149        ONESHOT_R::new(((self.bits >> 2) & 0x01) != 0)
150    }
151    #[doc = "Bits 6:7 - Command"]
152    #[inline(always)]
153    pub fn cmd(&self) -> CMD_R {
154        CMD_R::new(((self.bits >> 6) & 0x03) as u8)
155    }
156}
157impl W {
158    #[doc = "Bit 0 - Counter Direction"]
159    #[inline(always)]
160    pub fn dir(&mut self) -> DIR_W {
161        DIR_W { w: self }
162    }
163    #[doc = "Bit 2 - One-Shot"]
164    #[inline(always)]
165    pub fn oneshot(&mut self) -> ONESHOT_W {
166        ONESHOT_W { w: self }
167    }
168    #[doc = "Bits 6:7 - Command"]
169    #[inline(always)]
170    pub fn cmd(&mut self) -> CMD_W {
171        CMD_W { w: self }
172    }
173}