Skip to content

Commit a2dd816

Browse files
committed
The i2c module requires an io-* feature
1 parent 4192978 commit a2dd816

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
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: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ 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
},
3935
rcc::Rcc,
4036
};
@@ -48,15 +44,11 @@ use crate::pac::USART1;
4844
feature = "io-STM32L051",
4945
feature = "io-STM32L071",
5046
))]
51-
use crate::pac::USART2;
52-
53-
#[cfg(any(
54-
feature = "io-STM32L021",
55-
feature = "io-STM32L031",
56-
feature = "io-STM32L051",
57-
feature = "io-STM32L071",
58-
))]
59-
use crate::serial;
47+
use crate::{
48+
i2c,
49+
serial,
50+
pac::{I2C1, I2C2, I2C3, USART2},
51+
};
6052

6153
#[cfg(feature = "stm32l082")]
6254
use crate::aes;
@@ -563,6 +555,12 @@ impl_target!(
563555
);
564556

565557
#[cfg(feature = "stm32l0x2")]
558+
#[cfg(any(
559+
feature = "io-STM32L021",
560+
feature = "io-STM32L031",
561+
feature = "io-STM32L051",
562+
feature = "io-STM32L071",
563+
))]
566564
impl_target!(
567565
// I2C1
568566
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
spi::SpiExt as _,
@@ -25,6 +24,14 @@ pub use crate::{
2524
},
2625
};
2726

27+
#[cfg(any(
28+
feature = "io-STM32L021",
29+
feature = "io-STM32L031",
30+
feature = "io-STM32L051",
31+
feature = "io-STM32L071",
32+
))]
33+
pub use crate::i2c::I2cExt as _;
34+
2835
#[cfg(any(
2936
feature = "io-STM32L021",
3037
feature = "io-STM32L031",

0 commit comments

Comments
 (0)