stm32f1/stm32f102/i2c1/
ccr.rs

1#[doc = "Register `CCR` reader"]
2pub struct R(crate::R<CCR_SPEC>);
3impl core::ops::Deref for R {
4    type Target = crate::R<CCR_SPEC>;
5    #[inline(always)]
6    fn deref(&self) -> &Self::Target {
7        &self.0
8    }
9}
10impl From<crate::R<CCR_SPEC>> for R {
11    #[inline(always)]
12    fn from(reader: crate::R<CCR_SPEC>) -> Self {
13        R(reader)
14    }
15}
16#[doc = "Register `CCR` writer"]
17pub struct W(crate::W<CCR_SPEC>);
18impl core::ops::Deref for W {
19    type Target = crate::W<CCR_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<CCR_SPEC>> for W {
32    #[inline(always)]
33    fn from(writer: crate::W<CCR_SPEC>) -> Self {
34        W(writer)
35    }
36}
37#[doc = "I2C master mode selection\n\nValue on reset: 0"]
38#[derive(Clone, Copy, Debug, PartialEq)]
39pub enum F_S_A {
40    #[doc = "0: Standard mode I2C"]
41    Standard = 0,
42    #[doc = "1: Fast mode I2C"]
43    Fast = 1,
44}
45impl From<F_S_A> for bool {
46    #[inline(always)]
47    fn from(variant: F_S_A) -> Self {
48        variant as u8 != 0
49    }
50}
51#[doc = "Field `F_S` reader - I2C master mode selection"]
52pub type F_S_R = crate::BitReader<F_S_A>;
53impl F_S_R {
54    #[doc = "Get enumerated values variant"]
55    #[inline(always)]
56    pub fn variant(&self) -> F_S_A {
57        match self.bits {
58            false => F_S_A::Standard,
59            true => F_S_A::Fast,
60        }
61    }
62    #[doc = "Checks if the value of the field is `Standard`"]
63    #[inline(always)]
64    pub fn is_standard(&self) -> bool {
65        *self == F_S_A::Standard
66    }
67    #[doc = "Checks if the value of the field is `Fast`"]
68    #[inline(always)]
69    pub fn is_fast(&self) -> bool {
70        *self == F_S_A::Fast
71    }
72}
73#[doc = "Field `F_S` writer - I2C master mode selection"]
74pub type F_S_W<'a, const O: u8> = crate::BitWriter<'a, u32, CCR_SPEC, F_S_A, O>;
75impl<'a, const O: u8> F_S_W<'a, O> {
76    #[doc = "Standard mode I2C"]
77    #[inline(always)]
78    pub fn standard(self) -> &'a mut W {
79        self.variant(F_S_A::Standard)
80    }
81    #[doc = "Fast mode I2C"]
82    #[inline(always)]
83    pub fn fast(self) -> &'a mut W {
84        self.variant(F_S_A::Fast)
85    }
86}
87#[doc = "Fast mode duty cycle\n\nValue on reset: 0"]
88#[derive(Clone, Copy, Debug, PartialEq)]
89pub enum DUTY_A {
90    #[doc = "0: Duty cycle t_low/t_high = 2/1"]
91    Duty21 = 0,
92    #[doc = "1: Duty cycle t_low/t_high = 16/9"]
93    Duty169 = 1,
94}
95impl From<DUTY_A> for bool {
96    #[inline(always)]
97    fn from(variant: DUTY_A) -> Self {
98        variant as u8 != 0
99    }
100}
101#[doc = "Field `DUTY` reader - Fast mode duty cycle"]
102pub type DUTY_R = crate::BitReader<DUTY_A>;
103impl DUTY_R {
104    #[doc = "Get enumerated values variant"]
105    #[inline(always)]
106    pub fn variant(&self) -> DUTY_A {
107        match self.bits {
108            false => DUTY_A::Duty21,
109            true => DUTY_A::Duty169,
110        }
111    }
112    #[doc = "Checks if the value of the field is `Duty21`"]
113    #[inline(always)]
114    pub fn is_duty2_1(&self) -> bool {
115        *self == DUTY_A::Duty21
116    }
117    #[doc = "Checks if the value of the field is `Duty169`"]
118    #[inline(always)]
119    pub fn is_duty16_9(&self) -> bool {
120        *self == DUTY_A::Duty169
121    }
122}
123#[doc = "Field `DUTY` writer - Fast mode duty cycle"]
124pub type DUTY_W<'a, const O: u8> = crate::BitWriter<'a, u32, CCR_SPEC, DUTY_A, O>;
125impl<'a, const O: u8> DUTY_W<'a, O> {
126    #[doc = "Duty cycle t_low/t_high = 2/1"]
127    #[inline(always)]
128    pub fn duty2_1(self) -> &'a mut W {
129        self.variant(DUTY_A::Duty21)
130    }
131    #[doc = "Duty cycle t_low/t_high = 16/9"]
132    #[inline(always)]
133    pub fn duty16_9(self) -> &'a mut W {
134        self.variant(DUTY_A::Duty169)
135    }
136}
137#[doc = "Field `CCR` reader - Clock control register in Fast/Standard mode (Master mode)"]
138pub type CCR_R = crate::FieldReader<u16, u16>;
139#[doc = "Field `CCR` writer - Clock control register in Fast/Standard mode (Master mode)"]
140pub type CCR_W<'a, const O: u8> = crate::FieldWriter<'a, u32, CCR_SPEC, u16, u16, 12, O>;
141impl R {
142    #[doc = "Bit 15 - I2C master mode selection"]
143    #[inline(always)]
144    pub fn f_s(&self) -> F_S_R {
145        F_S_R::new(((self.bits >> 15) & 1) != 0)
146    }
147    #[doc = "Bit 14 - Fast mode duty cycle"]
148    #[inline(always)]
149    pub fn duty(&self) -> DUTY_R {
150        DUTY_R::new(((self.bits >> 14) & 1) != 0)
151    }
152    #[doc = "Bits 0:11 - Clock control register in Fast/Standard mode (Master mode)"]
153    #[inline(always)]
154    pub fn ccr(&self) -> CCR_R {
155        CCR_R::new((self.bits & 0x0fff) as u16)
156    }
157}
158impl W {
159    #[doc = "Bit 15 - I2C master mode selection"]
160    #[inline(always)]
161    pub fn f_s(&mut self) -> F_S_W<15> {
162        F_S_W::new(self)
163    }
164    #[doc = "Bit 14 - Fast mode duty cycle"]
165    #[inline(always)]
166    pub fn duty(&mut self) -> DUTY_W<14> {
167        DUTY_W::new(self)
168    }
169    #[doc = "Bits 0:11 - Clock control register in Fast/Standard mode (Master mode)"]
170    #[inline(always)]
171    pub fn ccr(&mut self) -> CCR_W<0> {
172        CCR_W::new(self)
173    }
174    #[doc = "Writes raw bits to the register."]
175    #[inline(always)]
176    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
177        self.0.bits(bits);
178        self
179    }
180}
181#[doc = "Clock control 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 [ccr](index.html) module"]
182pub struct CCR_SPEC;
183impl crate::RegisterSpec for CCR_SPEC {
184    type Ux = u32;
185}
186#[doc = "`read()` method returns [ccr::R](R) reader structure"]
187impl crate::Readable for CCR_SPEC {
188    type Reader = R;
189}
190#[doc = "`write(|w| ..)` method takes [ccr::W](W) writer structure"]
191impl crate::Writable for CCR_SPEC {
192    type Writer = W;
193}
194#[doc = "`reset()` method sets CCR to value 0"]
195impl crate::Resettable for CCR_SPEC {
196    #[inline(always)]
197    fn reset_value() -> Self::Ux {
198        0
199    }
200}