avr_device/devices/atmega32u4/twi/
twsr.rs

1#[doc = "Register `TWSR` reader"]
2pub struct R(crate::R<TWSR_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<TWSR_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<TWSR_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<TWSR_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `TWSR` writer"]
17pub struct W(crate::W<TWSR_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<TWSR_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<TWSR_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<TWSR_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `TWPS` reader - TWI Prescaler"]
38pub type TWPS_R = crate::FieldReader<u8, TWPS_A>;
39#[doc = "TWI Prescaler\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41#[repr(u8)]
42pub enum TWPS_A {
43    #[doc = "0: Prescaler Value 1"]
44    PRESCALER_1 = 0,
45    #[doc = "1: Prescaler Value 4"]
46    PRESCALER_4 = 1,
47    #[doc = "2: Prescaler Value 16"]
48    PRESCALER_16 = 2,
49    #[doc = "3: Prescaler Value 64"]
50    PRESCALER_64 = 3,
51}
52impl From<TWPS_A> for u8 {
53    #[inline(always)]
54    fn from(variant: TWPS_A) -> Self {
55        variant as _
56    }
57}
58impl TWPS_R {
59    #[doc = "Get enumerated values variant"]
60    #[inline(always)]
61    pub fn variant(&self) -> TWPS_A {
62        match self.bits {
63            0 => TWPS_A::PRESCALER_1,
64            1 => TWPS_A::PRESCALER_4,
65            2 => TWPS_A::PRESCALER_16,
66            3 => TWPS_A::PRESCALER_64,
67            _ => unreachable!(),
68        }
69    }
70    #[doc = "Checks if the value of the field is `PRESCALER_1`"]
71    #[inline(always)]
72    pub fn is_prescaler_1(&self) -> bool {
73        *self == TWPS_A::PRESCALER_1
74    }
75    #[doc = "Checks if the value of the field is `PRESCALER_4`"]
76    #[inline(always)]
77    pub fn is_prescaler_4(&self) -> bool {
78        *self == TWPS_A::PRESCALER_4
79    }
80    #[doc = "Checks if the value of the field is `PRESCALER_16`"]
81    #[inline(always)]
82    pub fn is_prescaler_16(&self) -> bool {
83        *self == TWPS_A::PRESCALER_16
84    }
85    #[doc = "Checks if the value of the field is `PRESCALER_64`"]
86    #[inline(always)]
87    pub fn is_prescaler_64(&self) -> bool {
88        *self == TWPS_A::PRESCALER_64
89    }
90}
91#[doc = "Field `TWPS` writer - TWI Prescaler"]
92pub type TWPS_W<'a, const O: u8> = crate::FieldWriterSafe<'a, u8, TWSR_SPEC, u8, TWPS_A, 2, O>;
93impl<'a, const O: u8> TWPS_W<'a, O> {
94    #[doc = "Prescaler Value 1"]
95    #[inline(always)]
96    pub fn prescaler_1(self) -> &'a mut W {
97        self.variant(TWPS_A::PRESCALER_1)
98    }
99    #[doc = "Prescaler Value 4"]
100    #[inline(always)]
101    pub fn prescaler_4(self) -> &'a mut W {
102        self.variant(TWPS_A::PRESCALER_4)
103    }
104    #[doc = "Prescaler Value 16"]
105    #[inline(always)]
106    pub fn prescaler_16(self) -> &'a mut W {
107        self.variant(TWPS_A::PRESCALER_16)
108    }
109    #[doc = "Prescaler Value 64"]
110    #[inline(always)]
111    pub fn prescaler_64(self) -> &'a mut W {
112        self.variant(TWPS_A::PRESCALER_64)
113    }
114}
115#[doc = "Field `TWS` reader - TWI Status"]
116pub type TWS_R = crate::FieldReader<u8, u8>;
117impl R {
118    #[doc = "Bits 0:1 - TWI Prescaler"]
119    #[inline(always)]
120    pub fn twps(&self) -> TWPS_R {
121        TWPS_R::new(self.bits & 3)
122    }
123    #[doc = "Bits 3:7 - TWI Status"]
124    #[inline(always)]
125    pub fn tws(&self) -> TWS_R {
126        TWS_R::new((self.bits >> 3) & 0x1f)
127    }
128}
129impl W {
130    #[doc = "Bits 0:1 - TWI Prescaler"]
131    #[inline(always)]
132    #[must_use]
133    pub fn twps(&mut self) -> TWPS_W<0> {
134        TWPS_W::new(self)
135    }
136    #[doc = "Writes raw bits to the register."]
137    #[inline(always)]
138    pub unsafe fn bits(&mut self, bits: u8) -> &mut Self {
139        self.0.bits(bits);
140        self
141    }
142}
143#[doc = "TWI Status 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 [twsr](index.html) module"]
144pub struct TWSR_SPEC;
145impl crate::RegisterSpec for TWSR_SPEC {
146    type Ux = u8;
147}
148#[doc = "`read()` method returns [twsr::R](R) reader structure"]
149impl crate::Readable for TWSR_SPEC {
150    type Reader = R;
151}
152#[doc = "`write(|w| ..)` method takes [twsr::W](W) writer structure"]
153impl crate::Writable for TWSR_SPEC {
154    type Writer = W;
155    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
156    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
157}
158#[doc = "`reset()` method sets TWSR to value 0"]
159impl crate::Resettable for TWSR_SPEC {
160    const RESET_VALUE: Self::Ux = 0;
161}