Skip to content

Commit 239c476

Browse files
committed
Seal I2C traits
1 parent 111531d commit 239c476

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/i2c.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,37 @@ pub enum Error {
4545
// Alert, // SMBUS mode only
4646
}
4747

48-
// FIXME these should be "closed" traits
49-
/// SCL pin -- DO NOT IMPLEMENT THIS TRAIT
50-
pub unsafe trait SclPin<I2C> {}
48+
/// SCL pin
49+
pub trait SclPin<I2C>: crate::private::Sealed {}
5150

52-
/// SDA pin -- DO NOT IMPLEMENT THIS TRAIT
53-
pub unsafe trait SdaPin<I2C> {}
51+
/// SDA pin
52+
pub trait SdaPin<I2C>: crate::private::Sealed {}
5453

55-
unsafe impl SclPin<I2C1> for gpioa::PA15<AF4<OpenDrain>> {}
56-
unsafe impl SclPin<I2C1> for gpiob::PB6<AF4<OpenDrain>> {}
57-
unsafe impl SclPin<I2C1> for gpiob::PB8<AF4<OpenDrain>> {}
58-
unsafe impl SdaPin<I2C1> for gpioa::PA14<AF4<OpenDrain>> {}
59-
unsafe impl SdaPin<I2C1> for gpiob::PB7<AF4<OpenDrain>> {}
60-
unsafe impl SdaPin<I2C1> for gpiob::PB9<AF4<OpenDrain>> {}
54+
impl SclPin<I2C1> for gpioa::PA15<AF4<OpenDrain>> {}
55+
impl SclPin<I2C1> for gpiob::PB6<AF4<OpenDrain>> {}
56+
impl SclPin<I2C1> for gpiob::PB8<AF4<OpenDrain>> {}
57+
impl SdaPin<I2C1> for gpioa::PA14<AF4<OpenDrain>> {}
58+
impl SdaPin<I2C1> for gpiob::PB7<AF4<OpenDrain>> {}
59+
impl SdaPin<I2C1> for gpiob::PB9<AF4<OpenDrain>> {}
6160

6261
cfg_if! {
6362
if #[cfg(not(feature = "gpio-f333"))] {
64-
unsafe impl SclPin<I2C2> for gpioa::PA9<AF4<OpenDrain>> {}
65-
unsafe impl SclPin<I2C2> for gpiof::PF1<AF4<OpenDrain>> {}
63+
impl SclPin<I2C2> for gpioa::PA9<AF4<OpenDrain>> {}
64+
impl SclPin<I2C2> for gpiof::PF1<AF4<OpenDrain>> {}
6665
#[cfg(any(feature = "gpio-f303", feature = "gpio-f303e", feature = "gpio-f373"))]
67-
unsafe impl SclPin<I2C2> for gpiof::PF6<AF4<OpenDrain>> {}
68-
unsafe impl SdaPin<I2C2> for gpioa::PA10<AF4<OpenDrain>> {}
69-
unsafe impl SdaPin<I2C2> for gpiof::PF0<AF4<OpenDrain>> {}
66+
impl SclPin<I2C2> for gpiof::PF6<AF4<OpenDrain>> {}
67+
impl SdaPin<I2C2> for gpioa::PA10<AF4<OpenDrain>> {}
68+
impl SdaPin<I2C2> for gpiof::PF0<AF4<OpenDrain>> {}
7069
#[cfg(feature = "gpio-f373")]
71-
unsafe impl SdaPin<I2C2> for gpiof::PF7<AF4<OpenDrain>> {}
70+
impl SdaPin<I2C2> for gpiof::PF7<AF4<OpenDrain>> {}
7271
}
7372
}
7473

7574
cfg_if! {
7675
if #[cfg(any(feature = "gpio-f302", feature = "gpio-f303e"))] {
77-
unsafe impl SclPin<I2C3> for gpioa::PA8<AF3<OpenDrain>> {}
78-
unsafe impl SdaPin<I2C3> for gpiob::PB5<AF8<OpenDrain>> {}
79-
unsafe impl SdaPin<I2C3> for gpioc::PC9<AF3<OpenDrain>> {}
76+
impl SclPin<I2C3> for gpioa::PA8<AF3<OpenDrain>> {}
77+
impl SdaPin<I2C3> for gpiob::PB5<AF8<OpenDrain>> {}
78+
impl SdaPin<I2C3> for gpioc::PC9<AF3<OpenDrain>> {}
8079
}
8180
}
8281

@@ -428,8 +427,8 @@ where
428427
}
429428
}
430429

431-
/// I2C instance -- DO NOT IMPLEMENT THIS TRAIT
432-
pub unsafe trait Instance: Deref<Target = RegisterBlock> {
430+
/// I2C instance
431+
pub trait Instance: Deref<Target = RegisterBlock> + crate::private::Sealed {
433432
#[doc(hidden)]
434433
fn enable_clock(apb1: &mut APB1);
435434
#[doc(hidden)]
@@ -439,7 +438,8 @@ pub unsafe trait Instance: Deref<Target = RegisterBlock> {
439438
macro_rules! i2c {
440439
($($I2CX:ident: ($i2cXen:ident, $i2cXrst:ident, $i2cXsw:ident),)+) => {
441440
$(
442-
unsafe impl Instance for $I2CX {
441+
impl crate::private::Sealed for $I2CX {}
442+
impl Instance for $I2CX {
443443
fn enable_clock(apb1: &mut APB1) {
444444
apb1.enr().modify(|_, w| w.$i2cXen().enabled());
445445
apb1.rstr().modify(|_, w| w.$i2cXrst().reset());

0 commit comments

Comments
 (0)