mod asynch;
mod blocking;
pub use asynch::{FirmwareState, FirmwareUpdater};
pub use blocking::{BlockingFirmwareState, BlockingFirmwareUpdater};
use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
use crate::verification::VerificationError;
pub struct FirmwareUpdaterConfig<DFU, STATE> {
pub dfu: DFU,
pub state: STATE,
}
#[derive(Debug)]
pub enum FirmwareUpdaterError {
Flash(NorFlashErrorKind),
Signature(hazard3_crypto::Error),
BadState,
}
#[cfg(feature = "defmt")]
impl defmt::Format for FirmwareUpdaterError {
fn format(&self, fmt: defmt::Formatter) {
match self {
FirmwareUpdaterError::Flash(_) => defmt::write!(fmt, "FirmwareUpdaterError::Flash(_)"),
FirmwareUpdaterError::Signature(_) => defmt::write!(fmt, "FirmwareUpdaterError::Signature(_)"),
FirmwareUpdaterError::BadState => defmt::write!(fmt, "FirmwareUpdaterError::BadState"),
}
}
}
impl<E> From<E> for FirmwareUpdaterError
where
E: NorFlashError,
{
fn from(error: E) -> Self {
FirmwareUpdaterError::Flash(error.kind())
}
}
impl From<VerificationError> for FirmwareUpdaterError {
fn from(error: VerificationError) -> Self {
match error {
VerificationError::Flash(e) => FirmwareUpdaterError::Flash(e),
VerificationError::Signature(e) => FirmwareUpdaterError::Signature(e),
}
}
}