firmware: turn errors into &str for remote_i2c as well

should resolve breakage on a few targets/variants introduced by PR #1351
This commit is contained in:
Astro 2019-08-28 22:46:00 +02:00 committed by Sébastien Bourdeauducq
parent 71b3c66af9
commit 90e8e074cd

View File

@ -14,67 +14,67 @@ mod remote_i2c {
use rtio_mgt::drtio; use rtio_mgt::drtio;
use sched::{Io, Mutex}; use sched::{Io, Mutex};
pub fn start(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8) -> Result<(), ()> { pub fn start(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8) -> Result<(), &'static str> {
let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cStartRequest { let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cStartRequest {
destination: destination, destination: destination,
busno: busno busno: busno
}); });
match reply { match reply {
Ok(drtioaux::Packet::I2cBasicReply { succeeded }) => { Ok(drtioaux::Packet::I2cBasicReply { succeeded }) => {
if succeeded { Ok(()) } else { Err(()) } if succeeded { Ok(()) } else { Err("i2c basic reply error") }
} }
Ok(packet) => { Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet); error!("received unexpected aux packet: {:?}", packet);
Err(()) Err("received unexpected aux packet")
} }
Err(e) => { Err(e) => {
error!("aux packet error ({})", e); error!("aux packet error ({})", e);
Err(()) Err(e)
} }
} }
} }
pub fn restart(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8) -> Result<(), ()> { pub fn restart(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8) -> Result<(), &'static str> {
let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cRestartRequest { let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cRestartRequest {
destination: destination, destination: destination,
busno: busno busno: busno
}); });
match reply { match reply {
Ok(drtioaux::Packet::I2cBasicReply { succeeded }) => { Ok(drtioaux::Packet::I2cBasicReply { succeeded }) => {
if succeeded { Ok(()) } else { Err(()) } if succeeded { Ok(()) } else { Err("i2c basic reply error") }
} }
Ok(packet) => { Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet); error!("received unexpected aux packet: {:?}", packet);
Err(()) Err("received unexpected aux packet")
} }
Err(e) => { Err(e) => {
error!("aux packet error ({})", e); error!("aux packet error ({})", e);
Err(()) Err(e)
} }
} }
} }
pub fn stop(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8) -> Result<(), ()> { pub fn stop(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8) -> Result<(), &'static str> {
let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cStopRequest { let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cStopRequest {
destination: destination, destination: destination,
busno: busno busno: busno
}); });
match reply { match reply {
Ok(drtioaux::Packet::I2cBasicReply { succeeded }) => { Ok(drtioaux::Packet::I2cBasicReply { succeeded }) => {
if succeeded { Ok(()) } else { Err(()) } if succeeded { Ok(()) } else { Err("i2c basic reply error") }
} }
Ok(packet) => { Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet); error!("received unexpected aux packet: {:?}", packet);
Err(()) Err("received unexpected aux packet")
} }
Err(e) => { Err(e) => {
error!("aux packet error ({})", e); error!("aux packet error ({})", e);
Err(()) Err(e)
} }
} }
} }
pub fn write(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8, data: u8) -> Result<bool, ()> { pub fn write(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8, data: u8) -> Result<bool, &'static str> {
let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cWriteRequest { let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cWriteRequest {
destination: destination, destination: destination,
busno: busno, busno: busno,
@ -82,20 +82,20 @@ mod remote_i2c {
}); });
match reply { match reply {
Ok(drtioaux::Packet::I2cWriteReply { succeeded, ack }) => { Ok(drtioaux::Packet::I2cWriteReply { succeeded, ack }) => {
if succeeded { Ok(ack) } else { Err(()) } if succeeded { Ok(ack) } else { Err("i2c write reply error") }
} }
Ok(_) => { Ok(_) => {
error!("received unexpected aux packet"); error!("received unexpected aux packet");
Err(()) Err("received unexpected aux packet")
} }
Err(e) => { Err(e) => {
error!("aux packet error ({})", e); error!("aux packet error ({})", e);
Err(()) Err(e)
} }
} }
} }
pub fn read(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8, ack: bool) -> Result<u8, ()> { pub fn read(io: &Io, aux_mutex: &Mutex, linkno: u8, destination: u8, busno: u8, ack: bool) -> Result<u8, &'static str> {
let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cReadRequest { let reply = drtio::aux_transact(io, aux_mutex, linkno, &drtioaux::Packet::I2cReadRequest {
destination: destination, destination: destination,
busno: busno, busno: busno,
@ -103,15 +103,15 @@ mod remote_i2c {
}); });
match reply { match reply {
Ok(drtioaux::Packet::I2cReadReply { succeeded, data }) => { Ok(drtioaux::Packet::I2cReadReply { succeeded, data }) => {
if succeeded { Ok(data) } else { Err(()) } if succeeded { Ok(data) } else { Err("i2c read reply error") }
} }
Ok(_) => { Ok(_) => {
error!("received unexpected aux packet"); error!("received unexpected aux packet");
Err(()) Err("received unexpected aux packet")
} }
Err(e) => { Err(e) => {
error!("aux packet error ({})", e); error!("aux packet error ({})", e);
Err(()) Err(e)
} }
} }
} }