Skip to content

Commit 4a8e60f

Browse files
committed
The i2c module requires an io-* feature
1 parent 47c2ece commit 4a8e60f

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ stm32l082 = ["stm32l0x2"]
6565

6666
# Features based on the GPIO peripheral version.
6767
# This determines the pin function mapping of the MCU.
68+
# Note: The easiest way to pick the proper io-* feature is to apply
69+
# the matching mcu-* feature for your MCU!
6870
io-STM32L021 = []
6971
io-STM32L031 = []
7072
io-STM32L051 = []
@@ -302,9 +304,13 @@ required-features = ["rt"]
302304
name = "flash"
303305
required-features = ["rt","stm32l082"]
304306

307+
[[example]]
308+
name = "i2c"
309+
required-features = ["rt","stm32l0x2","io-STM32L071"]
310+
305311
[[example]]
306312
name = "i2c_dma"
307-
required-features = ["rt","stm32l0x2"]
313+
required-features = ["rt","stm32l0x2","io-STM32L071"]
308314

309315
[[example]]
310316
name = "rng"

src/dma.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,24 @@ use as_slice::AsSlice;
2828

2929
use crate::{
3030
adc,
31-
i2c,
3231
pac::{
3332
self,
3433
dma1::ch::cr,
35-
I2C1,
36-
I2C2,
37-
I2C3,
3834
USART1,
3935
USART2,
4036
},
4137
rcc::Rcc,
4238
serial,
4339
};
4440

41+
#[cfg(any(
42+
feature = "io-STM32L021",
43+
feature = "io-STM32L031",
44+
feature = "io-STM32L051",
45+
feature = "io-STM32L071",
46+
))]
47+
use crate::{i2c, pac::{I2C1, I2C2, I2C3}};
48+
4549
#[cfg(feature = "stm32l082")]
4650
use crate::aes;
4751

@@ -536,6 +540,12 @@ impl_target!(
536540
);
537541

538542
#[cfg(feature = "stm32l0x2")]
543+
#[cfg(any(
544+
feature = "io-STM32L021",
545+
feature = "io-STM32L031",
546+
feature = "io-STM32L051",
547+
feature = "io-STM32L071",
548+
))]
539549
impl_target!(
540550
// I2C1
541551
i2c::Tx<I2C1>, Channel2, 6;

src/i2c.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use as_slice::{
1515
AsMutSlice,
1616
};
1717

18-
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
1918

2019
#[cfg(feature = "stm32l0x2")]
2120
use crate::dma::{
@@ -32,6 +31,9 @@ use crate::rcc::Rcc;
3231
use crate::time::Hertz;
3332
use cast::u8;
3433

34+
// I²C traits
35+
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
36+
3537
// I/O Imports
3638
use crate::gpio::{AltMode, OpenDrain, Output};
3739
#[cfg(feature = "io-STM32L021")]

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pub mod exti;
2323
#[cfg(feature = "stm32l0x2")]
2424
pub mod flash;
2525
pub mod gpio;
26+
#[cfg(any(
27+
feature = "io-STM32L021",
28+
feature = "io-STM32L031",
29+
feature = "io-STM32L051",
30+
feature = "io-STM32L071",
31+
))]
2632
pub mod i2c;
2733
pub mod lptim;
2834
pub mod prelude;

src/prelude.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub use crate::{
1313
adc::AdcExt as _,
1414
delay::DelayExt as _,
1515
gpio::GpioExt as _,
16-
i2c::I2cExt as _,
1716
pwr::PowerMode as _,
1817
rcc::RccExt as _,
1918
serial::{
@@ -28,3 +27,11 @@ pub use crate::{
2827
WindowWatchdogExt as _,
2928
},
3029
};
30+
31+
#[cfg(any(
32+
feature = "io-STM32L021",
33+
feature = "io-STM32L031",
34+
feature = "io-STM32L051",
35+
feature = "io-STM32L071",
36+
))]
37+
pub use crate::i2c::I2cExt as _;

0 commit comments

Comments
 (0)