refactor(firmware): simplify configuration and diagnostics
This commit is contained in:
1 parent
ba9c97ed3b
commit
fdf82a5114
96 files changed
+1612
-2772
No files matched your search
@@ -9,7 +9,7 @@ version.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
kaptan-log = { path = "../kaptan-log" }
|
||||
kaptan-err-propagate = { path = "../kaptan-err-propagate" }
|
||||
kaptan-sensor = { path = "../kaptan-sensor" }
|
||||
kaptan-i2c = { path = "../kaptan-i2c" }
|
||||
kaptan-spi = { path = "../kaptan-spi" }
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
//! ICM-42688-P operation errors.
|
||||
|
||||
use kaptan_log::KaptanError;
|
||||
use kaptan_err_propagate::KaptanError;
|
||||
|
||||
/// ICM-42688-P operation failure.
|
||||
#[derive(Debug, Eq, PartialEq, KaptanError)]
|
||||
pub enum Error<BusError> {
|
||||
/// The selected SPI route rejected a transfer submission.
|
||||
#[kaptan_error(id = 5101)]
|
||||
Start(BusError),
|
||||
/// The responding device does not identify as an ICM-42688-P.
|
||||
#[kaptan_error(id = 5102)]
|
||||
UnexpectedIdentity(u8),
|
||||
/// An acquisition request arrived before initialization completed or while
|
||||
/// another transfer still owned the selected route.
|
||||
#[kaptan_error(id = 5103)]
|
||||
NotReady,
|
||||
/// The selected SPI route reported a terminal transfer fault.
|
||||
#[kaptan_error(id = 5104)]
|
||||
TransferFault,
|
||||
}
|
||||
@@ -1,25 +1,33 @@
|
||||
//! LIDAR-Lite v3 operation errors.
|
||||
|
||||
use kaptan_log::KaptanError;
|
||||
use kaptan_err_propagate::KaptanError;
|
||||
|
||||
/// LIDAR-Lite v3 operation failure.
|
||||
#[derive(Debug, Eq, PartialEq, KaptanError)]
|
||||
pub enum Error<BusError> {
|
||||
/// The selected I²C route rejected a transaction submission.
|
||||
#[kaptan_error(id = 5201)]
|
||||
Start(BusError),
|
||||
/// An acquisition request arrived while another measurement was active.
|
||||
#[kaptan_error(id = 5202)]
|
||||
NotReady,
|
||||
/// The selected I²C route reported a terminal transaction fault.
|
||||
#[kaptan_error(id = 5203)]
|
||||
TransferFault,
|
||||
/// The device reported a process error for the completed measurement.
|
||||
#[kaptan_error(id = 5204)]
|
||||
ProcessError,
|
||||
/// The device reported that its reference or receiver bias is unhealthy.
|
||||
#[kaptan_error(id = 5205)]
|
||||
Unhealthy,
|
||||
/// The device reported that no usable signal peak was detected.
|
||||
#[kaptan_error(id = 5206)]
|
||||
InvalidSignal,
|
||||
/// A measurement remained busy beyond the driver's bounded acquisition interval.
|
||||
#[kaptan_error(id = 5207)]
|
||||
MeasurementTimeout,
|
||||
/// The device reported a documented no-signal sentinel distance of zero or one centimetre.
|
||||
#[kaptan_error(id = 5208)]
|
||||
NoSignal,
|
||||
}
|
||||
|
||||
@@ -27,5 +35,6 @@ pub enum Error<BusError> {
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, KaptanError)]
|
||||
pub enum StartupError {
|
||||
/// Startup completion was reported when the driver was not settling.
|
||||
#[kaptan_error(id = 5301)]
|
||||
NotSettling,
|
||||
}
|
||||
@@ -55,11 +55,7 @@ impl<Clock: MonotonicClock, Bus: I2cBus> LidarLiteV3Service<Clock, Bus> {
|
||||
&mut self,
|
||||
completion: I2cCompletion,
|
||||
) -> LidarLiteV3ServiceEvent<Bus::StartError> {
|
||||
match self.lidar.on_transaction_complete(completion) {
|
||||
LidarLiteV3Event::Measurement(sample) => LidarLiteV3ServiceEvent::Measurement(sample),
|
||||
LidarLiteV3Event::Fault(error) => LidarLiteV3ServiceEvent::Fault(error),
|
||||
_ => LidarLiteV3ServiceEvent::Idle,
|
||||
}
|
||||
service_event(self.lidar.on_transaction_complete(completion))
|
||||
}
|
||||
|
||||
/// Acknowledges a board-controller interrupt and advances the acquisition.
|
||||
@@ -78,10 +74,21 @@ impl<Clock: MonotonicClock, Bus: I2cBus> LidarLiteV3Service<Clock, Bus> {
|
||||
}
|
||||
}
|
||||
|
||||
fn service_event<BusError>(event: LidarLiteV3Event<BusError>) -> LidarLiteV3ServiceEvent<BusError> {
|
||||
match event {
|
||||
LidarLiteV3Event::Measurement(sample) => LidarLiteV3ServiceEvent::Measurement(sample),
|
||||
LidarLiteV3Event::Fault(Error::InvalidSignal | Error::NoSignal) => {
|
||||
LidarLiteV3ServiceEvent::Idle
|
||||
}
|
||||
LidarLiteV3Event::Fault(error) => LidarLiteV3ServiceEvent::Fault(error),
|
||||
_ => LidarLiteV3ServiceEvent::Idle,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{LidarLiteV3Service, LidarLiteV3ServiceEvent};
|
||||
use crate::lidar_lite_v3::{AcquisitionMode, LidarLiteV3};
|
||||
use super::{LidarLiteV3Service, LidarLiteV3ServiceEvent, service_event};
|
||||
use crate::lidar_lite_v3::{AcquisitionMode, Error, LidarLiteV3, LidarLiteV3Event};
|
||||
use kaptan_i2c::{I2cBus, I2cCompletion};
|
||||
use kaptan_time::{MonotonicClock, Timestamp};
|
||||
|
||||
@@ -177,4 +184,20 @@ mod tests {
|
||||
&& sample.distance_millimetres == 2_910
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unavailable_measurements_are_not_terminal_service_faults() {
|
||||
assert!(matches!(
|
||||
service_event::<()>(LidarLiteV3Event::Fault(Error::InvalidSignal)),
|
||||
LidarLiteV3ServiceEvent::Idle
|
||||
));
|
||||
assert!(matches!(
|
||||
service_event::<()>(LidarLiteV3Event::Fault(Error::NoSignal)),
|
||||
LidarLiteV3ServiceEvent::Idle
|
||||
));
|
||||
assert!(matches!(
|
||||
service_event::<()>(LidarLiteV3Event::Fault(Error::Unhealthy)),
|
||||
LidarLiteV3ServiceEvent::Fault(Error::Unhealthy)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,21 @@
|
||||
//! MPU6000 operation errors.
|
||||
|
||||
use kaptan_log::KaptanError;
|
||||
use kaptan_err_propagate::KaptanError;
|
||||
|
||||
/// MPU6000 operation failure.
|
||||
#[derive(Debug, Eq, PartialEq, KaptanError)]
|
||||
pub enum Error<BusError> {
|
||||
/// The selected SPI route rejected a transfer submission.
|
||||
#[kaptan_error(id = 5001)]
|
||||
Start(BusError),
|
||||
/// The responding device does not identify as an MPU6000.
|
||||
#[kaptan_error(id = 5002)]
|
||||
UnexpectedIdentity(u8),
|
||||
/// An acquisition request arrived before initialization completed or while
|
||||
/// another transfer still owned the selected route.
|
||||
#[kaptan_error(id = 5003)]
|
||||
NotReady,
|
||||
/// The selected SPI route reported a terminal transfer fault.
|
||||
#[kaptan_error(id = 5004)]
|
||||
TransferFault,
|
||||
}
|
||||
Reference in new issue
Block a user