atsamv71q21/uart0/
uart_cmpr.rs

1#[doc = "Register `UART_CMPR` reader"]
2pub struct R(crate::R<UART_CMPR_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<UART_CMPR_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<UART_CMPR_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<UART_CMPR_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `UART_CMPR` writer"]
17pub struct W(crate::W<UART_CMPR_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<UART_CMPR_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<UART_CMPR_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<UART_CMPR_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `VAL1` reader - First Comparison Value for Received Character"]
38pub struct VAL1_R(crate::FieldReader<u8, u8>);
39impl VAL1_R {
40    #[inline(always)]
41    pub(crate) fn new(bits: u8) -> Self {
42        VAL1_R(crate::FieldReader::new(bits))
43    }
44}
45impl core::ops::Deref for VAL1_R {
46    type Target = crate::FieldReader<u8, u8>;
47    #[inline(always)]
48    fn deref(&self) -> &Self::Target {
49        &self.0
50    }
51}
52#[doc = "Field `VAL1` writer - First Comparison Value for Received Character"]
53pub struct VAL1_W<'a> {
54    w: &'a mut W,
55}
56impl<'a> VAL1_W<'a> {
57    #[doc = r"Writes raw bits to the field"]
58    #[inline(always)]
59    pub unsafe fn bits(self, value: u8) -> &'a mut W {
60        self.w.bits = (self.w.bits & !0xff) | (value as u32 & 0xff);
61        self.w
62    }
63}
64#[doc = "Comparison Mode\n\nValue on reset: 0"]
65#[derive(Clone, Copy, Debug, PartialEq)]
66pub enum CMPMODE_A {
67    #[doc = "0: Any character is received and comparison function drives CMP flag."]
68    FLAG_ONLY = 0,
69    #[doc = "1: Comparison condition must be met to start reception."]
70    START_CONDITION = 1,
71}
72impl From<CMPMODE_A> for bool {
73    #[inline(always)]
74    fn from(variant: CMPMODE_A) -> Self {
75        variant as u8 != 0
76    }
77}
78#[doc = "Field `CMPMODE` reader - Comparison Mode"]
79pub struct CMPMODE_R(crate::FieldReader<bool, CMPMODE_A>);
80impl CMPMODE_R {
81    #[inline(always)]
82    pub(crate) fn new(bits: bool) -> Self {
83        CMPMODE_R(crate::FieldReader::new(bits))
84    }
85    #[doc = r"Get enumerated values variant"]
86    #[inline(always)]
87    pub fn variant(&self) -> CMPMODE_A {
88        match self.bits {
89            false => CMPMODE_A::FLAG_ONLY,
90            true => CMPMODE_A::START_CONDITION,
91        }
92    }
93    #[doc = "Checks if the value of the field is `FLAG_ONLY`"]
94    #[inline(always)]
95    pub fn is_flag_only(&self) -> bool {
96        **self == CMPMODE_A::FLAG_ONLY
97    }
98    #[doc = "Checks if the value of the field is `START_CONDITION`"]
99    #[inline(always)]
100    pub fn is_start_condition(&self) -> bool {
101        **self == CMPMODE_A::START_CONDITION
102    }
103}
104impl core::ops::Deref for CMPMODE_R {
105    type Target = crate::FieldReader<bool, CMPMODE_A>;
106    #[inline(always)]
107    fn deref(&self) -> &Self::Target {
108        &self.0
109    }
110}
111#[doc = "Field `CMPMODE` writer - Comparison Mode"]
112pub struct CMPMODE_W<'a> {
113    w: &'a mut W,
114}
115impl<'a> CMPMODE_W<'a> {
116    #[doc = r"Writes `variant` to the field"]
117    #[inline(always)]
118    pub fn variant(self, variant: CMPMODE_A) -> &'a mut W {
119        self.bit(variant.into())
120    }
121    #[doc = "Any character is received and comparison function drives CMP flag."]
122    #[inline(always)]
123    pub fn flag_only(self) -> &'a mut W {
124        self.variant(CMPMODE_A::FLAG_ONLY)
125    }
126    #[doc = "Comparison condition must be met to start reception."]
127    #[inline(always)]
128    pub fn start_condition(self) -> &'a mut W {
129        self.variant(CMPMODE_A::START_CONDITION)
130    }
131    #[doc = r"Sets the field bit"]
132    #[inline(always)]
133    pub fn set_bit(self) -> &'a mut W {
134        self.bit(true)
135    }
136    #[doc = r"Clears the field bit"]
137    #[inline(always)]
138    pub fn clear_bit(self) -> &'a mut W {
139        self.bit(false)
140    }
141    #[doc = r"Writes raw bits to the field"]
142    #[inline(always)]
143    pub fn bit(self, value: bool) -> &'a mut W {
144        self.w.bits = (self.w.bits & !(0x01 << 12)) | ((value as u32 & 0x01) << 12);
145        self.w
146    }
147}
148#[doc = "Field `CMPPAR` reader - Compare Parity"]
149pub struct CMPPAR_R(crate::FieldReader<bool, bool>);
150impl CMPPAR_R {
151    #[inline(always)]
152    pub(crate) fn new(bits: bool) -> Self {
153        CMPPAR_R(crate::FieldReader::new(bits))
154    }
155}
156impl core::ops::Deref for CMPPAR_R {
157    type Target = crate::FieldReader<bool, bool>;
158    #[inline(always)]
159    fn deref(&self) -> &Self::Target {
160        &self.0
161    }
162}
163#[doc = "Field `CMPPAR` writer - Compare Parity"]
164pub struct CMPPAR_W<'a> {
165    w: &'a mut W,
166}
167impl<'a> CMPPAR_W<'a> {
168    #[doc = r"Sets the field bit"]
169    #[inline(always)]
170    pub fn set_bit(self) -> &'a mut W {
171        self.bit(true)
172    }
173    #[doc = r"Clears the field bit"]
174    #[inline(always)]
175    pub fn clear_bit(self) -> &'a mut W {
176        self.bit(false)
177    }
178    #[doc = r"Writes raw bits to the field"]
179    #[inline(always)]
180    pub fn bit(self, value: bool) -> &'a mut W {
181        self.w.bits = (self.w.bits & !(0x01 << 14)) | ((value as u32 & 0x01) << 14);
182        self.w
183    }
184}
185#[doc = "Field `VAL2` reader - Second Comparison Value for Received Character"]
186pub struct VAL2_R(crate::FieldReader<u8, u8>);
187impl VAL2_R {
188    #[inline(always)]
189    pub(crate) fn new(bits: u8) -> Self {
190        VAL2_R(crate::FieldReader::new(bits))
191    }
192}
193impl core::ops::Deref for VAL2_R {
194    type Target = crate::FieldReader<u8, u8>;
195    #[inline(always)]
196    fn deref(&self) -> &Self::Target {
197        &self.0
198    }
199}
200#[doc = "Field `VAL2` writer - Second Comparison Value for Received Character"]
201pub struct VAL2_W<'a> {
202    w: &'a mut W,
203}
204impl<'a> VAL2_W<'a> {
205    #[doc = r"Writes raw bits to the field"]
206    #[inline(always)]
207    pub unsafe fn bits(self, value: u8) -> &'a mut W {
208        self.w.bits = (self.w.bits & !(0xff << 16)) | ((value as u32 & 0xff) << 16);
209        self.w
210    }
211}
212impl R {
213    #[doc = "Bits 0:7 - First Comparison Value for Received Character"]
214    #[inline(always)]
215    pub fn val1(&self) -> VAL1_R {
216        VAL1_R::new((self.bits & 0xff) as u8)
217    }
218    #[doc = "Bit 12 - Comparison Mode"]
219    #[inline(always)]
220    pub fn cmpmode(&self) -> CMPMODE_R {
221        CMPMODE_R::new(((self.bits >> 12) & 0x01) != 0)
222    }
223    #[doc = "Bit 14 - Compare Parity"]
224    #[inline(always)]
225    pub fn cmppar(&self) -> CMPPAR_R {
226        CMPPAR_R::new(((self.bits >> 14) & 0x01) != 0)
227    }
228    #[doc = "Bits 16:23 - Second Comparison Value for Received Character"]
229    #[inline(always)]
230    pub fn val2(&self) -> VAL2_R {
231        VAL2_R::new(((self.bits >> 16) & 0xff) as u8)
232    }
233}
234impl W {
235    #[doc = "Bits 0:7 - First Comparison Value for Received Character"]
236    #[inline(always)]
237    pub fn val1(&mut self) -> VAL1_W {
238        VAL1_W { w: self }
239    }
240    #[doc = "Bit 12 - Comparison Mode"]
241    #[inline(always)]
242    pub fn cmpmode(&mut self) -> CMPMODE_W {
243        CMPMODE_W { w: self }
244    }
245    #[doc = "Bit 14 - Compare Parity"]
246    #[inline(always)]
247    pub fn cmppar(&mut self) -> CMPPAR_W {
248        CMPPAR_W { w: self }
249    }
250    #[doc = "Bits 16:23 - Second Comparison Value for Received Character"]
251    #[inline(always)]
252    pub fn val2(&mut self) -> VAL2_W {
253        VAL2_W { w: self }
254    }
255    #[doc = "Writes raw bits to the register."]
256    #[inline(always)]
257    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
258        self.0.bits(bits);
259        self
260    }
261}
262#[doc = "Comparison 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 [uart_cmpr](index.html) module"]
263pub struct UART_CMPR_SPEC;
264impl crate::RegisterSpec for UART_CMPR_SPEC {
265    type Ux = u32;
266}
267#[doc = "`read()` method returns [uart_cmpr::R](R) reader structure"]
268impl crate::Readable for UART_CMPR_SPEC {
269    type Reader = R;
270}
271#[doc = "`write(|w| ..)` method takes [uart_cmpr::W](W) writer structure"]
272impl crate::Writable for UART_CMPR_SPEC {
273    type Writer = W;
274}
275#[doc = "`reset()` method sets UART_CMPR to value 0"]
276impl crate::Resettable for UART_CMPR_SPEC {
277    #[inline(always)]
278    fn reset_value() -> Self::Ux {
279        0
280    }
281}