mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
modify user mode i2c lib calls to return nacks
Note that a NACK is returned as an Ok(I2cResult::Nack) - this is because the Err() path is still reserved for "OS failure" errors. A Nack isn't a terminal failure, it is a recoverable fault, and so it's handled in the Ok() path.
This commit is contained in:
parent
63c1d975b4
commit
d17f9881b2
1 changed files with 10 additions and 11 deletions
|
|
@ -33,7 +33,7 @@ impl I2cApi for I2c {
|
|||
adr: u8,
|
||||
buf: &mut [u8],
|
||||
repeated_start: bool,
|
||||
) -> Result<usize, xous::Error> {
|
||||
) -> Result<I2cResult, xous::Error> {
|
||||
let r = I2cTransaction {
|
||||
i2c_type: if repeated_start {
|
||||
I2cTransactionType::ReadRepeatedStart
|
||||
|
|
@ -46,16 +46,14 @@ impl I2cApi for I2c {
|
|||
result: I2cResult::Pending,
|
||||
};
|
||||
let result = self.i2c_transactions(I2cTransactions::from(vec![r]))?;
|
||||
match result.transactions[0].result {
|
||||
I2cResult::Ack(b) => {
|
||||
buf.copy_from_slice(&result.transactions[0].data);
|
||||
Ok(b)
|
||||
}
|
||||
_ => Err(xous::Error::InternalError),
|
||||
if result.transactions[0].result == I2cResult::InternalError {
|
||||
Err(xous::Error::InternalError)
|
||||
} else {
|
||||
Ok(result.transactions[0].result)
|
||||
}
|
||||
}
|
||||
|
||||
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<usize, xous::Error> {
|
||||
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<I2cResult, xous::Error> {
|
||||
let w = I2cTransaction {
|
||||
i2c_type: I2cTransactionType::Write,
|
||||
device: dev,
|
||||
|
|
@ -64,9 +62,10 @@ impl I2cApi for I2c {
|
|||
result: I2cResult::Pending,
|
||||
};
|
||||
let result = self.i2c_transactions(I2cTransactions::from(vec![w]))?;
|
||||
match result.transactions[0].result {
|
||||
I2cResult::Ack(b) => Ok(b),
|
||||
_ => Err(xous::Error::InternalError),
|
||||
if result.transactions[0].result == I2cResult::InternalError {
|
||||
Err(xous::Error::InternalError)
|
||||
} else {
|
||||
Ok(result.transactions[0].result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue