29
29
let mut i2c = I2C ( i2c) ;
30
30
31
31
// Configure SDA and SCL pins
32
- let ( sda_out, sda_in, scl_out, scl_in) = if i2c. is_i2c0 ( ) {
32
+ let ( sda_out, sda_in, scl_out, scl_in) = if i2c. 0 . is_i2c0 ( ) {
33
33
(
34
34
OutputSignal :: I2CEXT0_SDA ,
35
35
InputSignal :: I2CEXT0_SDA ,
@@ -108,7 +108,7 @@ where
108
108
109
109
/// Resets the interface
110
110
fn reset ( & mut self , dport : & mut DPORT ) {
111
- if self . is_i2c0 ( ) {
111
+ if self . 0 . is_i2c0 ( ) {
112
112
dport. perip_rst_en . modify ( |_, w| w. i2c0 ( ) . set_bit ( ) ) ;
113
113
dport. perip_rst_en . modify ( |_, w| w. i2c0 ( ) . clear_bit ( ) ) ;
114
114
} else {
@@ -119,7 +119,7 @@ where
119
119
120
120
/// Enables the interface
121
121
fn enable ( & mut self , dport : & mut DPORT ) {
122
- if self . is_i2c0 ( ) {
122
+ if self . 0 . is_i2c0 ( ) {
123
123
dport. perip_clk_en . modify ( |_, w| w. i2c0 ( ) . set_bit ( ) ) ;
124
124
dport. perip_rst_en . modify ( |_, w| w. i2c0 ( ) . clear_bit ( ) ) ;
125
125
} else {
@@ -206,16 +206,11 @@ where
206
206
}
207
207
}
208
208
209
- /// Helper function for determining which interface corresponds to the current instance
210
- fn is_i2c0 ( & self ) -> bool {
211
- ( self . 0 . deref ( ) as * const i2c:: RegisterBlock ) as u32 == DPORT_I2C0_ADDR
212
- }
213
-
214
209
/// Gets the FIFO address given the operation type (R/W)
215
210
fn fifo_addr ( & self , operation_type : OperationType ) -> u32 {
216
211
// Errata 3.3: When written via DPORT, consecutive writes to the same address may be lost.
217
212
// Errata 3.18: FIFO read operations are unpredictable via AHB.
218
- let base_addr = match ( operation_type, self . is_i2c0 ( ) ) {
213
+ let base_addr = match ( operation_type, self . 0 . is_i2c0 ( ) ) {
219
214
( OperationType :: READ , true ) => DPORT_I2C0_ADDR ,
220
215
( OperationType :: READ , false ) => DPORT_I2C1_ADDR ,
221
216
( OperationType :: WRITE , true ) => AHB_I2C0_ADDR ,
@@ -631,7 +626,12 @@ enum Opcode {
631
626
END = 4 ,
632
627
}
633
628
634
- pub trait Instance : Deref < Target = i2c:: RegisterBlock > { }
629
+ pub trait Instance : Deref < Target = i2c:: RegisterBlock > {
630
+ /// Determines which interface corresponds to the current instance
631
+ fn is_i2c0 ( & self ) -> bool {
632
+ self . deref ( ) as * const i2c:: RegisterBlock == I2C0 :: ptr ( )
633
+ }
634
+ }
635
635
636
636
impl Instance for I2C0 { }
637
637
0 commit comments