Skip to content

Commit 221ef90

Browse files
Move i2c mappings to pin_mappings
1 parent fde2dba commit 221ef90

File tree

2 files changed

+64
-130
lines changed

2 files changed

+64
-130
lines changed

src/i2c.rs

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -17,134 +17,6 @@ pub struct I2c<I2C, SCLPIN, SDAPIN> {
1717
pub trait SclPin<I2C> {}
1818
pub trait SdaPin<I2C> {}
1919

20-
macro_rules! i2c_pins {
21-
($($I2C:ident => {
22-
scl => [$($scl:ty),+ $(,)*],
23-
sda => [$($sda:ty),+ $(,)*],
24-
})+) => {
25-
$(
26-
$(
27-
impl SclPin<crate::stm32::$I2C> for $scl {}
28-
)+
29-
$(
30-
impl SdaPin<crate::stm32::$I2C> for $sda {}
31-
)+
32-
)+
33-
}
34-
}
35-
36-
#[cfg(any(
37-
feature = "stm32f030",
38-
feature = "stm32f031",
39-
feature = "stm32f038",
40-
feature = "stm32f042",
41-
feature = "stm32f048",
42-
feature = "stm32f051",
43-
feature = "stm32f058",
44-
feature = "stm32f070",
45-
feature = "stm32f071",
46-
feature = "stm32f072",
47-
feature = "stm32f078",
48-
feature = "stm32f091",
49-
feature = "stm32f098",
50-
))]
51-
i2c_pins! {
52-
I2C1 => {
53-
scl => [gpiob::PB6<Alternate<AF1>>, gpiob::PB8<Alternate<AF1>>],
54-
sda => [gpiob::PB7<Alternate<AF1>>, gpiob::PB9<Alternate<AF1>>],
55-
}
56-
}
57-
#[cfg(any(
58-
feature = "stm32f030x4",
59-
feature = "stm32f030x6",
60-
feature = "stm32f030xc",
61-
feature = "stm32f031",
62-
feature = "stm32f038",
63-
feature = "stm32f042",
64-
feature = "stm32f048",
65-
feature = "stm32f070x6",
66-
feature = "stm32f091",
67-
feature = "stm32f098",
68-
))]
69-
i2c_pins! {
70-
I2C1 => {
71-
scl => [gpioa::PA9<Alternate<AF4>>],
72-
sda => [gpioa::PA10<Alternate<AF4>>],
73-
}
74-
}
75-
#[cfg(any(feature = "stm32f030", feature = "stm32f042", feature = "stm32f048"))]
76-
i2c_pins! {
77-
I2C1 => {
78-
scl => [gpioa::PA11<Alternate<AF5>>],
79-
sda => [gpioa::PA12<Alternate<AF5>>],
80-
}
81-
}
82-
#[cfg(any(
83-
feature = "stm32f030x4",
84-
feature = "stm32f030x6",
85-
feature = "stm32f031",
86-
feature = "stm32f038",
87-
feature = "stm32f042",
88-
feature = "stm32f048",
89-
))]
90-
i2c_pins! {
91-
I2C1 => {
92-
scl => [gpiob::PB10<Alternate<AF1>>],
93-
sda => [gpiob::PB11<Alternate<AF1>>],
94-
}
95-
}
96-
#[cfg(any(feature = "stm32f030xc", feature = "stm32f042", feature = "stm32f048"))]
97-
i2c_pins! {
98-
I2C1 => {
99-
scl => [gpiob::PB13<Alternate<AF5>>],
100-
sda => [gpiob::PB14<Alternate<AF5>>],
101-
}
102-
}
103-
#[cfg(any(
104-
feature = "stm32f030xc",
105-
feature = "stm32f042",
106-
feature = "stm32f048",
107-
feature = "stm32f070x6",
108-
feature = "stm32f091",
109-
feature = "stm32f098",
110-
))]
111-
i2c_pins! {
112-
I2C1 => {
113-
scl => [gpiof::PF1<Alternate<AF1>>],
114-
sda => [gpiof::PF0<Alternate<AF1>>],
115-
}
116-
}
117-
118-
#[cfg(any(feature = "stm32f030x8", feature = "stm32f051", feature = "stm32f058"))]
119-
i2c_pins! {
120-
I2C2 => {
121-
scl => [gpiob::PB10<Alternate<AF1>>],
122-
sda => [gpiob::PB11<Alternate<AF1>>],
123-
}
124-
}
125-
#[cfg(any(
126-
feature = "stm32f030xc",
127-
feature = "stm32f070xb",
128-
feature = "stm32f071",
129-
feature = "stm32f072",
130-
feature = "stm32f078",
131-
feature = "stm32f091",
132-
feature = "stm32f098",
133-
))]
134-
i2c_pins! {
135-
I2C2 => {
136-
scl => [gpiob::PB10<Alternate<AF1>>, gpiob::PB13<Alternate<AF5>>],
137-
sda => [gpiob::PB11<Alternate<AF1>>, gpiob::PB14<Alternate<AF5>>],
138-
}
139-
}
140-
#[cfg(any(feature = "stm32f091", feature = "stm32f098"))]
141-
i2c_pins! {
142-
I2C2 => {
143-
scl => [gpioa::PA11<Alternate<AF5>>],
144-
sda => [gpioa::PA12<Alternate<AF5>>],
145-
}
146-
}
147-
14820
#[derive(Debug)]
14921
pub enum Error {
15022
OVERRUN,

src/pin_mappings.rs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ use crate::gpio::gpioc::*;
88
#[cfg(feature = "stm32f030xc")]
99
use crate::gpio::gpiod::*;
1010
#[allow(unused)]
11+
#[cfg(feature = "device-selected")]
12+
use crate::gpio::gpiof::*;
13+
#[allow(unused)]
1114
use crate::gpio::{Alternate, AF0, AF1, AF2, AF4, AF5};
15+
use crate::i2c::*;
1216
use crate::serial::*;
1317
use crate::spi::*;
1418
#[cfg(feature = "device-selected")]
@@ -36,8 +40,22 @@ pins! {
3640
PB3 => {AF0: SckPin<SPI1>},
3741
PB4 => {AF0: MisoPin<SPI1>},
3842
PB5 => {AF0: MosiPin<SPI1>},
39-
PB6 => {AF0: TxPin<USART1>},
40-
PB7 => {AF0: RxPin<USART1>}
43+
PB6 => {
44+
AF0: TxPin<USART1>,
45+
AF1: SclPin<I2C1>
46+
},
47+
PB7 => {
48+
AF0: RxPin<USART1>,
49+
AF1: SdaPin<I2C1>
50+
},
51+
PB8 => {AF1: SclPin<I2C1>},
52+
PB9 => {AF1: SdaPin<I2C1>}
53+
}
54+
55+
#[cfg(any(feature = "stm32f030", feature = "stm32f042"))]
56+
pins! {
57+
PA11 => {AF5: SclPin<I2C1>},
58+
PA12 => {AF5: SdaPin<I2C1>}
4159
}
4260

4361
#[cfg(feature = "stm32f030x6")]
@@ -109,3 +127,47 @@ pins! {
109127
PB14 => {AF0: MisoPin<SPI2>},
110128
PB15 => {AF0: MosiPin<SPI2>}
111129
}
130+
131+
#[cfg(any(
132+
feature = "stm32f030x6",
133+
feature = "stm32f030xc",
134+
feature = "stm32f042",
135+
feature = "stm32f070x6",
136+
))]
137+
pins! {
138+
PA9 => {AF4: SclPin<I2C1>},
139+
PA10 => {AF4: SdaPin<I2C1>}
140+
}
141+
142+
#[cfg(any(
143+
feature = "stm32f042",
144+
feature = "stm32f030x6",
145+
feature = "stm32f030x8",
146+
feature = "stm32f030xc",
147+
feature = "stm32f070xb"
148+
))]
149+
pins! {
150+
PB10 => {AF1: SclPin<I2C1>},
151+
PB11 => {AF1: SdaPin<I2C1>}
152+
}
153+
154+
#[cfg(any(
155+
feature = "stm32f042",
156+
feature = "stm32f030xc",
157+
feature = "stm32f070x6",
158+
))]
159+
pins! {
160+
PF1 => {AF1: SclPin<I2C1>},
161+
PF0 => {AF1: SdaPin<I2C1>}
162+
}
163+
164+
#[cfg(any(
165+
feature = "stm32f042",
166+
feature = "stm32f030xc",
167+
feature = "stm32f030xc",
168+
feature = "stm32f070xb"
169+
))]
170+
pins! {
171+
PB13 => {AF5: SclPin<I2C1>},
172+
PB14 => {AF5: SdaPin<I2C1>}
173+
}

0 commit comments

Comments
 (0)