avr_device/devices/atmega4809/twi0/
mctrlb.rs

1#[doc = "Register `MCTRLB` reader"]
2pub struct R(crate::R<MCTRLB_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<MCTRLB_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<MCTRLB_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<MCTRLB_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `MCTRLB` writer"]
17pub struct W(crate::W<MCTRLB_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<MCTRLB_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<MCTRLB_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<MCTRLB_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `MCMD` reader - Command"]
38pub type MCMD_R = crate::FieldReader<u8, MCMD_A>;
39#[doc = "Command\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41#[repr(u8)]
42pub enum MCMD_A {
43    #[doc = "0: No Action"]
44    NOACT = 0,
45    #[doc = "1: Issue Repeated Start Condition"]
46    REPSTART = 1,
47    #[doc = "2: Receive or Transmit Data, depending on DIR"]
48    RECVTRANS = 2,
49    #[doc = "3: Issue Stop Condition"]
50    STOP = 3,
51}
52impl From<MCMD_A> for u8 {
53    #[inline(always)]
54    fn from(variant: MCMD_A) -> Self {
55        variant as _
56    }
57}
58impl MCMD_R {
59    #[doc = "Get enumerated values variant"]
60    #[inline(always)]
61    pub fn variant(&self) -> MCMD_A {
62        match self.bits {
63            0 => MCMD_A::NOACT,
64            1 => MCMD_A::REPSTART,
65            2 => MCMD_A::RECVTRANS,
66            3 => MCMD_A::STOP,
67            _ => unreachable!(),
68        }
69    }
70    #[doc = "Checks if the value of the field is `NOACT`"]
71    #[inline(always)]
72    pub fn is_noact(&self) -> bool {
73        *self == MCMD_A::NOACT
74    }
75    #[doc = "Checks if the value of the field is `REPSTART`"]
76    #[inline(always)]
77    pub fn is_repstart(&self) -> bool {
78        *self == MCMD_A::REPSTART
79    }
80    #[doc = "Checks if the value of the field is `RECVTRANS`"]
81    #[inline(always)]
82    pub fn is_recvtrans(&self) -> bool {
83        *self == MCMD_A::RECVTRANS
84    }
85    #[doc = "Checks if the value of the field is `STOP`"]
86    #[inline(always)]
87    pub fn is_stop(&self) -> bool {
88        *self == MCMD_A::STOP
89    }
90}
91#[doc = "Field `MCMD` writer - Command"]
92pub type MCMD_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u8, MCTRLB_SPEC, u8, MCMD_A, 2, O>;
93impl<'a, const O: u8> MCMD_W<'a, O> {
94    #[doc = "No Action"]
95    #[inline(always)]
96    pub fn noact(self) -> &'a mut W {
97        self.variant(MCMD_A::NOACT)
98    }
99    #[doc = "Issue Repeated Start Condition"]
100    #[inline(always)]
101    pub fn repstart(self) -> &'a mut W {
102        self.variant(MCMD_A::REPSTART)
103    }
104    #[doc = "Receive or Transmit Data, depending on DIR"]
105    #[inline(always)]
106    pub fn recvtrans(self) -> &'a mut W {
107        self.variant(MCMD_A::RECVTRANS)
108    }
109    #[doc = "Issue Stop Condition"]
110    #[inline(always)]
111    pub fn stop(self) -> &'a mut W {
112        self.variant(MCMD_A::STOP)
113    }
114}
115#[doc = "Field `ACKACT` reader - Acknowledge Action"]
116pub type ACKACT_R = crate::BitReader<ACKACT_A>;
117#[doc = "Acknowledge Action\n\nValue on reset: 0"]
118#[derive(Clone, Copy, Debug, PartialEq, Eq)]
119pub enum ACKACT_A {
120    #[doc = "0: Send ACK"]
121    ACK = 0,
122    #[doc = "1: Send NACK"]
123    NACK = 1,
124}
125impl From<ACKACT_A> for bool {
126    #[inline(always)]
127    fn from(variant: ACKACT_A) -> Self {
128        variant as u8 != 0
129    }
130}
131impl ACKACT_R {
132    #[doc = "Get enumerated values variant"]
133    #[inline(always)]
134    pub fn variant(&self) -> ACKACT_A {
135        match self.bits {
136            false => ACKACT_A::ACK,
137            true => ACKACT_A::NACK,
138        }
139    }
140    #[doc = "Checks if the value of the field is `ACK`"]
141    #[inline(always)]
142    pub fn is_ack(&self) -> bool {
143        *self == ACKACT_A::ACK
144    }
145    #[doc = "Checks if the value of the field is `NACK`"]
146    #[inline(always)]
147    pub fn is_nack(&self) -> bool {
148        *self == ACKACT_A::NACK
149    }
150}
151#[doc = "Field `ACKACT` writer - Acknowledge Action"]
152pub type ACKACT_W<'a, const O: u8> = crate::BitWriter<'a, u8, MCTRLB_SPEC, ACKACT_A, O>;
153impl<'a, const O: u8> ACKACT_W<'a, O> {
154    #[doc = "Send ACK"]
155    #[inline(always)]
156    pub fn ack(self) -> &'a mut W {
157        self.variant(ACKACT_A::ACK)
158    }
159    #[doc = "Send NACK"]
160    #[inline(always)]
161    pub fn nack(self) -> &'a mut W {
162        self.variant(ACKACT_A::NACK)
163    }
164}
165#[doc = "Field `FLUSH` reader - Flush"]
166pub type FLUSH_R = crate::BitReader<bool>;
167#[doc = "Field `FLUSH` writer - Flush"]
168pub type FLUSH_W<'a, const O: u8> = crate::BitWriter<'a, u8, MCTRLB_SPEC, bool, O>;
169impl R {
170    #[doc = "Bits 0:1 - Command"]
171    #[inline(always)]
172    pub fn mcmd(&self) -> MCMD_R {
173        MCMD_R::new(self.bits & 3)
174    }
175    #[doc = "Bit 2 - Acknowledge Action"]
176    #[inline(always)]
177    pub fn ackact(&self) -> ACKACT_R {
178        ACKACT_R::new(((self.bits >> 2) & 1) != 0)
179    }
180    #[doc = "Bit 3 - Flush"]
181    #[inline(always)]
182    pub fn flush(&self) -> FLUSH_R {
183        FLUSH_R::new(((self.bits >> 3) & 1) != 0)
184    }
185}
186impl W {
187    #[doc = "Bits 0:1 - Command"]
188    #[inline(always)]
189    #[must_use]
190    pub fn mcmd(&mut self) -> MCMD_W<0> {
191        MCMD_W::new(self)
192    }
193    #[doc = "Bit 2 - Acknowledge Action"]
194    #[inline(always)]
195    #[must_use]
196    pub fn ackact(&mut self) -> ACKACT_W<2> {
197        ACKACT_W::new(self)
198    }
199    #[doc = "Bit 3 - Flush"]
200    #[inline(always)]
201    #[must_use]
202    pub fn flush(&mut self) -> FLUSH_W<3> {
203        FLUSH_W::new(self)
204    }
205    #[doc = "Writes raw bits to the register."]
206    #[inline(always)]
207    pub unsafe fn bits(&mut self, bits: u8) -> &mut Self {
208        self.0.bits(bits);
209        self
210    }
211}
212#[doc = "Master Control B\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 [mctrlb](index.html) module"]
213pub struct MCTRLB_SPEC;
214impl crate::RegisterSpec for MCTRLB_SPEC {
215    type Ux = u8;
216}
217#[doc = "`read()` method returns [mctrlb::R](R) reader structure"]
218impl crate::Readable for MCTRLB_SPEC {
219    type Reader = R;
220}
221#[doc = "`write(|w| ..)` method takes [mctrlb::W](W) writer structure"]
222impl crate::Writable for MCTRLB_SPEC {
223    type Writer = W;
224    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
225    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
226}
227#[doc = "`reset()` method sets MCTRLB to value 0"]
228impl crate::Resettable for MCTRLB_SPEC {
229    const RESET_VALUE: Self::Ux = 0;
230}