Skip to content

Commit

Permalink
Merge pull request #2 from ibutra/master
Browse files Browse the repository at this point in the history
Add more error conditions to I2C busy_wait to prevent endless loop
  • Loading branch information
little-arhat authored Jun 23, 2019
2 parents 0b81198 + 818fb46 commit e03086f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ use hal::blocking::i2c::{Read, Write, WriteRead};
/// I2C error
#[derive(Debug)]
pub enum Error {
/// Stop condition detected
Stop,
/// NACK received, i.e. communication not acknowledged by peripheral
NACK,
/// Bus error
Bus,
/// Arbitration loss
Expand Down Expand Up @@ -57,6 +61,10 @@ macro_rules! busy_wait {
return Err(Error::Bus);
} else if isr.arlo().bit_is_set() {
return Err(Error::Arbitration);
} else if isr.nackf().bit_is_set() {
return Err(Error::NACK);
} else if isr.stopf().bit_is_set() {
return Err(Error::Stop);
} else if isr.$flag().bit_is_set() {
break;
} else {
Expand Down

0 comments on commit e03086f

Please sign in to comment.