Compare commits
2 Commits
master
...
fix/i2c-ra
Author | SHA1 | Date | |
---|---|---|---|
88bda0cb7a | |||
91445620ee |
@ -150,16 +150,18 @@ impl I2c {
|
|||||||
self.sda_oe(true);
|
self.sda_oe(true);
|
||||||
self.half_period();
|
self.half_period();
|
||||||
self.scl_oe(true);
|
self.scl_oe(true);
|
||||||
|
while self.scl_i() {} // ensure SCL is low before start() returns
|
||||||
// postcondition: SCL and SDA low
|
// postcondition: SCL and SDA low
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn restart(&mut self) -> Result<(), &'static str> {
|
pub fn restart(&mut self) -> Result<(), &'static str> {
|
||||||
// precondition SCL and SDA low
|
// precondition: any
|
||||||
self.sda_oe(false);
|
self.sda_oe(false);
|
||||||
self.half_period();
|
self.half_period();
|
||||||
self.scl_oe(false);
|
self.scl_oe(false);
|
||||||
self.half_period();
|
self.half_period();
|
||||||
|
// enter the precondition for start(): SCL and SDA high
|
||||||
self.start()?;
|
self.start()?;
|
||||||
// postcondition: SCL and SDA low
|
// postcondition: SCL and SDA low
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -188,6 +190,7 @@ impl I2c {
|
|||||||
self.scl_oe(false);
|
self.scl_oe(false);
|
||||||
self.half_period();
|
self.half_period();
|
||||||
self.scl_oe(true);
|
self.scl_oe(true);
|
||||||
|
while self.scl_i() {} // ensure SCL is low before toggling SDA
|
||||||
}
|
}
|
||||||
self.sda_oe(false);
|
self.sda_oe(false);
|
||||||
self.half_period();
|
self.half_period();
|
||||||
@ -196,6 +199,7 @@ impl I2c {
|
|||||||
// Read ack/nack
|
// Read ack/nack
|
||||||
let ack = !self.sda_i();
|
let ack = !self.sda_i();
|
||||||
self.scl_oe(true);
|
self.scl_oe(true);
|
||||||
|
while self.scl_i() {} // ensure SCL is low before toggling SDA
|
||||||
self.sda_oe(true);
|
self.sda_oe(true);
|
||||||
// postcondition: SCL and SDA low
|
// postcondition: SCL and SDA low
|
||||||
|
|
||||||
@ -215,6 +219,7 @@ impl I2c {
|
|||||||
self.half_period();
|
self.half_period();
|
||||||
if self.sda_i() { data |= 1 << bit }
|
if self.sda_i() { data |= 1 << bit }
|
||||||
self.scl_oe(true);
|
self.scl_oe(true);
|
||||||
|
while self.scl_i() {} // ensure SCL is low so that slave can toggle SDA
|
||||||
}
|
}
|
||||||
// Send ack/nack
|
// Send ack/nack
|
||||||
self.sda_oe(ack);
|
self.sda_oe(ack);
|
||||||
@ -222,6 +227,7 @@ impl I2c {
|
|||||||
self.scl_oe(false);
|
self.scl_oe(false);
|
||||||
self.half_period();
|
self.half_period();
|
||||||
self.scl_oe(true);
|
self.scl_oe(true);
|
||||||
|
while self.scl_i() {} // ensure SCL is low before toggling SDA
|
||||||
self.sda_oe(true);
|
self.sda_oe(true);
|
||||||
// postcondition: SCL and SDA low
|
// postcondition: SCL and SDA low
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user