Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Commit 4e661fa

Browse files
committed
Move is_i2c0 to i2c::Instance trait
1 parent 6f21f54 commit 4e661fa

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/i2c.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where
2929
let mut i2c = I2C(i2c);
3030

3131
// 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() {
3333
(
3434
OutputSignal::I2CEXT0_SDA,
3535
InputSignal::I2CEXT0_SDA,
@@ -108,7 +108,7 @@ where
108108

109109
/// Resets the interface
110110
fn reset(&mut self, dport: &mut DPORT) {
111-
if self.is_i2c0() {
111+
if self.0.is_i2c0() {
112112
dport.perip_rst_en.modify(|_, w| w.i2c0().set_bit());
113113
dport.perip_rst_en.modify(|_, w| w.i2c0().clear_bit());
114114
} else {
@@ -119,7 +119,7 @@ where
119119

120120
/// Enables the interface
121121
fn enable(&mut self, dport: &mut DPORT) {
122-
if self.is_i2c0() {
122+
if self.0.is_i2c0() {
123123
dport.perip_clk_en.modify(|_, w| w.i2c0().set_bit());
124124
dport.perip_rst_en.modify(|_, w| w.i2c0().clear_bit());
125125
} else {
@@ -206,16 +206,11 @@ where
206206
}
207207
}
208208

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-
214209
/// Gets the FIFO address given the operation type (R/W)
215210
fn fifo_addr(&self, operation_type: OperationType) -> u32 {
216211
// Errata 3.3: When written via DPORT, consecutive writes to the same address may be lost.
217212
// 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()) {
219214
(OperationType::READ, true) => DPORT_I2C0_ADDR,
220215
(OperationType::READ, false) => DPORT_I2C1_ADDR,
221216
(OperationType::WRITE, true) => AHB_I2C0_ADDR,
@@ -631,7 +626,12 @@ enum Opcode {
631626
END = 4,
632627
}
633628

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+
}
635635

636636
impl Instance for I2C0 {}
637637

0 commit comments

Comments
 (0)