avr_device/devices/attiny85/adc/
adcsrb.rs

1#[doc = "Register `ADCSRB` reader"]
2pub struct R(crate::R<ADCSRB_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<ADCSRB_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<ADCSRB_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<ADCSRB_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `ADCSRB` writer"]
17pub struct W(crate::W<ADCSRB_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<ADCSRB_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<ADCSRB_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<ADCSRB_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "Field `ADTS` reader - ADC Auto Trigger Sources"]
38pub type ADTS_R = crate::FieldReader<u8, ADTS_A>;
39#[doc = "ADC Auto Trigger Sources\n\nValue on reset: 0"]
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41#[repr(u8)]
42pub enum ADTS_A {
43    #[doc = "0: Free Running mode"]
44    FREE = 0,
45    #[doc = "1: Analog Comparator"]
46    AC = 1,
47    #[doc = "2: External Interrupt Request 0"]
48    INT0 = 2,
49    #[doc = "3: Timer/Counter0 Compare Match A"]
50    TC0_CMA = 3,
51    #[doc = "4: Timer/Counter0 Overflow"]
52    TC0_OVF = 4,
53    #[doc = "5: Timer/Counter0 Compare Match B"]
54    TC0_CMB = 5,
55    #[doc = "6: Pin Change Interrupt Request"]
56    PCIR = 6,
57}
58impl From<ADTS_A> for u8 {
59    #[inline(always)]
60    fn from(variant: ADTS_A) -> Self {
61        variant as _
62    }
63}
64impl ADTS_R {
65    #[doc = "Get enumerated values variant"]
66    #[inline(always)]
67    pub fn variant(&self) -> Option<ADTS_A> {
68        match self.bits {
69            0 => Some(ADTS_A::FREE),
70            1 => Some(ADTS_A::AC),
71            2 => Some(ADTS_A::INT0),
72            3 => Some(ADTS_A::TC0_CMA),
73            4 => Some(ADTS_A::TC0_OVF),
74            5 => Some(ADTS_A::TC0_CMB),
75            6 => Some(ADTS_A::PCIR),
76            _ => None,
77        }
78    }
79    #[doc = "Checks if the value of the field is `FREE`"]
80    #[inline(always)]
81    pub fn is_free(&self) -> bool {
82        *self == ADTS_A::FREE
83    }
84    #[doc = "Checks if the value of the field is `AC`"]
85    #[inline(always)]
86    pub fn is_ac(&self) -> bool {
87        *self == ADTS_A::AC
88    }
89    #[doc = "Checks if the value of the field is `INT0`"]
90    #[inline(always)]
91    pub fn is_int0(&self) -> bool {
92        *self == ADTS_A::INT0
93    }
94    #[doc = "Checks if the value of the field is `TC0_CMA`"]
95    #[inline(always)]
96    pub fn is_tc0_cma(&self) -> bool {
97        *self == ADTS_A::TC0_CMA
98    }
99    #[doc = "Checks if the value of the field is `TC0_OVF`"]
100    #[inline(always)]
101    pub fn is_tc0_ovf(&self) -> bool {
102        *self == ADTS_A::TC0_OVF
103    }
104    #[doc = "Checks if the value of the field is `TC0_CMB`"]
105    #[inline(always)]
106    pub fn is_tc0_cmb(&self) -> bool {
107        *self == ADTS_A::TC0_CMB
108    }
109    #[doc = "Checks if the value of the field is `PCIR`"]
110    #[inline(always)]
111    pub fn is_pcir(&self) -> bool {
112        *self == ADTS_A::PCIR
113    }
114}
115#[doc = "Field `ADTS` writer - ADC Auto Trigger Sources"]
116pub type ADTS_W<'a, const O: u8> = crate::FieldWriter<'a, u8, ADCSRB_SPEC, u8, ADTS_A, 3, O>;
117impl<'a, const O: u8> ADTS_W<'a, O> {
118    #[doc = "Free Running mode"]
119    #[inline(always)]
120    pub fn free(self) -> &'a mut W {
121        self.variant(ADTS_A::FREE)
122    }
123    #[doc = "Analog Comparator"]
124    #[inline(always)]
125    pub fn ac(self) -> &'a mut W {
126        self.variant(ADTS_A::AC)
127    }
128    #[doc = "External Interrupt Request 0"]
129    #[inline(always)]
130    pub fn int0(self) -> &'a mut W {
131        self.variant(ADTS_A::INT0)
132    }
133    #[doc = "Timer/Counter0 Compare Match A"]
134    #[inline(always)]
135    pub fn tc0_cma(self) -> &'a mut W {
136        self.variant(ADTS_A::TC0_CMA)
137    }
138    #[doc = "Timer/Counter0 Overflow"]
139    #[inline(always)]
140    pub fn tc0_ovf(self) -> &'a mut W {
141        self.variant(ADTS_A::TC0_OVF)
142    }
143    #[doc = "Timer/Counter0 Compare Match B"]
144    #[inline(always)]
145    pub fn tc0_cmb(self) -> &'a mut W {
146        self.variant(ADTS_A::TC0_CMB)
147    }
148    #[doc = "Pin Change Interrupt Request"]
149    #[inline(always)]
150    pub fn pcir(self) -> &'a mut W {
151        self.variant(ADTS_A::PCIR)
152    }
153}
154#[doc = "Field `IPR` reader - Input Polarity Mode"]
155pub type IPR_R = crate::BitReader<bool>;
156#[doc = "Field `IPR` writer - Input Polarity Mode"]
157pub type IPR_W<'a, const O: u8> = crate::BitWriter<'a, u8, ADCSRB_SPEC, bool, O>;
158#[doc = "Field `BIN` reader - Bipolar Input Mode"]
159pub type BIN_R = crate::BitReader<bool>;
160#[doc = "Field `BIN` writer - Bipolar Input Mode"]
161pub type BIN_W<'a, const O: u8> = crate::BitWriter<'a, u8, ADCSRB_SPEC, bool, O>;
162impl R {
163    #[doc = "Bits 0:2 - ADC Auto Trigger Sources"]
164    #[inline(always)]
165    pub fn adts(&self) -> ADTS_R {
166        ADTS_R::new(self.bits & 7)
167    }
168    #[doc = "Bit 5 - Input Polarity Mode"]
169    #[inline(always)]
170    pub fn ipr(&self) -> IPR_R {
171        IPR_R::new(((self.bits >> 5) & 1) != 0)
172    }
173    #[doc = "Bit 7 - Bipolar Input Mode"]
174    #[inline(always)]
175    pub fn bin(&self) -> BIN_R {
176        BIN_R::new(((self.bits >> 7) & 1) != 0)
177    }
178}
179impl W {
180    #[doc = "Bits 0:2 - ADC Auto Trigger Sources"]
181    #[inline(always)]
182    #[must_use]
183    pub fn adts(&mut self) -> ADTS_W<0> {
184        ADTS_W::new(self)
185    }
186    #[doc = "Bit 5 - Input Polarity Mode"]
187    #[inline(always)]
188    #[must_use]
189    pub fn ipr(&mut self) -> IPR_W<5> {
190        IPR_W::new(self)
191    }
192    #[doc = "Bit 7 - Bipolar Input Mode"]
193    #[inline(always)]
194    #[must_use]
195    pub fn bin(&mut self) -> BIN_W<7> {
196        BIN_W::new(self)
197    }
198    #[doc = "Writes raw bits to the register."]
199    #[inline(always)]
200    pub unsafe fn bits(&mut self, bits: u8) -> &mut Self {
201        self.0.bits(bits);
202        self
203    }
204}
205#[doc = "ADC Control and Status Register 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 [adcsrb](index.html) module"]
206pub struct ADCSRB_SPEC;
207impl crate::RegisterSpec for ADCSRB_SPEC {
208    type Ux = u8;
209}
210#[doc = "`read()` method returns [adcsrb::R](R) reader structure"]
211impl crate::Readable for ADCSRB_SPEC {
212    type Reader = R;
213}
214#[doc = "`write(|w| ..)` method takes [adcsrb::W](W) writer structure"]
215impl crate::Writable for ADCSRB_SPEC {
216    type Writer = W;
217    const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
218    const ONE_TO_MODIFY_FIELDS_BITMAP: Self::Ux = 0;
219}
220#[doc = "`reset()` method sets ADCSRB to value 0"]
221impl crate::Resettable for ADCSRB_SPEC {
222    const RESET_VALUE: Self::Ux = 0;
223}