Skip to content

Commit 62e15e8

Browse files
engstadPål-Kristian Engstad
andauthored
STM32L4x6 chips have support for I2C3 alternative functions. (#215)
* STM32L4x6 chips have support for I2C3 alternative functions. * Feature gate i2c3() * Fix feature gate. Co-authored-by: Pål-Kristian Engstad <[email protected]>
1 parent e159537 commit 62e15e8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/i2c.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::gpio::{Alternate, OpenDrain, Output, AF4};
66
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
77
use crate::pac::{i2c1, I2C1, I2C2};
88
use crate::rcc::{Clocks, APB1R1};
9-
#[cfg(feature = "stm32l4x5")]
9+
#[cfg(any(feature = "stm32l4x5", feature = "stm32l4x6"))]
1010
use crate::stm32::I2C3;
1111
use crate::time::Hertz;
1212
use cast::{u16, u8};
@@ -147,6 +147,21 @@ impl<SCL, SDA> I2c<I2C2, (SCL, SDA)> {
147147
}
148148
}
149149

150+
#[cfg(any(feature = "stm32l4x5", feature = "stm32l4x6"))]
151+
impl<SCL, SDA> I2c<I2C3, (SCL, SDA)> {
152+
pub fn i2c3<F>(i2c: I2C3, pins: (SCL, SDA), freq: F, clocks: Clocks, apb1: &mut APB1R1) -> Self
153+
where
154+
F: Into<Hertz>,
155+
SCL: SclPin<I2C3>,
156+
SDA: SdaPin<I2C3>,
157+
{
158+
apb1.enr().modify(|_, w| w.i2c3en().set_bit());
159+
apb1.rstr().modify(|_, w| w.i2c3rst().set_bit());
160+
apb1.rstr().modify(|_, w| w.i2c3rst().clear_bit());
161+
Self::new(i2c, pins, freq, clocks)
162+
}
163+
}
164+
150165
impl<SCL, SDA, I2C> I2c<I2C, (SCL, SDA)>
151166
where
152167
I2C: Deref<Target = i2c1::RegisterBlock>,
@@ -460,7 +475,7 @@ where
460475
use crate::gpio::gpioa::{PA10, PA9};
461476
use crate::gpio::gpiob::{PB10, PB11, PB6, PB7};
462477

463-
#[cfg(any(feature = "stm32l4x3", feature = "stm32l4x5"))]
478+
#[cfg(any(feature = "stm32l4x3", feature = "stm32l4x5", feature = "stm32l4x6"))]
464479
use crate::gpio::gpioc::{PC0, PC1};
465480

466481
#[cfg(any(feature = "stm32l4x1", feature = "stm32l4x3", feature = "stm32l4x6"))]
@@ -481,7 +496,7 @@ pins!(I2C1, AF4, SCL: [PB8], SDA: [PB9]);
481496
#[cfg(any(feature = "stm32l4x1", feature = "stm32l4x6"))]
482497
pins!(I2C2, AF4, SCL: [PB13], SDA: [PB14]);
483498

484-
#[cfg(feature = "stm32l4x5")]
499+
#[cfg(any(feature = "stm32l4x5", feature = "stm32l4x6"))]
485500
pins!(I2C3, AF4, SCL: [PC0], SDA: [PC1]);
486501

487502
#[cfg(feature = "stm32l4x3")]

0 commit comments

Comments
 (0)