@@ -12,7 +12,7 @@ use crate::{
12
12
gpio:: { gpioa, gpiob, OpenDrain , AF4 } ,
13
13
hal:: blocking:: i2c:: { Read , Write , WriteRead } ,
14
14
pac:: { i2c1:: RegisterBlock , rcc:: cfgr3:: I2C1SW_A , I2C1 , RCC } ,
15
- rcc:: { Clocks , APB1 } ,
15
+ rcc:: { self , Clocks } ,
16
16
time:: rate:: * ,
17
17
} ;
18
18
@@ -111,15 +111,22 @@ macro_rules! busy_wait {
111
111
112
112
impl < I2C , SCL , SDA > I2c < I2C , ( SCL , SDA ) > {
113
113
/// Configures the I2C peripheral to work in master mode
114
- pub fn new ( i2c : I2C , pins : ( SCL , SDA ) , freq : Hertz , clocks : Clocks , apb1 : & mut APB1 ) -> Self
114
+ pub fn new (
115
+ i2c : I2C ,
116
+ pins : ( SCL , SDA ) ,
117
+ freq : Hertz ,
118
+ clocks : Clocks ,
119
+ bus : & mut <I2C as rcc:: RccBus >:: Bus ,
120
+ ) -> Self
115
121
where
116
122
I2C : Instance ,
117
123
SCL : SclPin < I2C > ,
118
124
SDA : SdaPin < I2C > ,
119
125
{
120
126
crate :: assert!( freq. integer( ) <= 1_000_000 ) ;
121
127
122
- I2C :: enable_clock ( apb1) ;
128
+ I2C :: enable ( bus) ;
129
+ I2C :: reset ( bus) ;
123
130
124
131
// TODO review compliance with the timing requirements of I2C
125
132
// t_I2CCLK = 1 / PCLK1
@@ -441,24 +448,17 @@ where
441
448
}
442
449
443
450
/// I2C instance
444
- pub trait Instance : Deref < Target = RegisterBlock > + crate :: private :: Sealed {
445
- # [ doc ( hidden ) ]
446
- fn enable_clock ( apb1 : & mut APB1 ) ;
451
+ pub trait Instance :
452
+ Deref < Target = RegisterBlock > + crate :: private :: Sealed + rcc :: Enable + rcc :: Reset
453
+ {
447
454
#[ doc( hidden) ]
448
455
fn clock ( clocks : & Clocks ) -> Hertz ;
449
456
}
450
457
451
458
macro_rules! i2c {
452
- ( $( $I2CX: ident: ( $i2cXen : ident , $i2cXrst : ident , $ i2cXsw: ident) , ) +) => {
459
+ ( $( $I2CX: ident: ( $i2cXsw: ident) , ) +) => {
453
460
$(
454
- impl crate :: private:: Sealed for $I2CX { }
455
461
impl Instance for $I2CX {
456
- fn enable_clock( apb1: & mut APB1 ) {
457
- apb1. enr( ) . modify( |_, w| w. $i2cXen( ) . enabled( ) ) ;
458
- apb1. rstr( ) . modify( |_, w| w. $i2cXrst( ) . reset( ) ) ;
459
- apb1. rstr( ) . modify( |_, w| w. $i2cXrst( ) . clear_bit( ) ) ;
460
- }
461
-
462
462
fn clock( clocks: & Clocks ) -> Hertz {
463
463
// NOTE(unsafe) atomic read with no side effects
464
464
match unsafe { ( * RCC :: ptr( ) ) . cfgr3. read( ) . $i2cXsw( ) . variant( ) } {
@@ -473,7 +473,7 @@ macro_rules! i2c {
473
473
( [ $( $X: literal) ,+ ] ) => {
474
474
paste:: paste! {
475
475
i2c!(
476
- $( [ <I2C $X>] : ( [ <i2c $X en> ] , [ <i2c $X rst> ] , [ <i2c $X sw>] ) , ) +
476
+ $( [ <I2C $X>] : ( [ <i2c $X sw>] ) , ) +
477
477
) ;
478
478
}
479
479
} ;
0 commit comments