2023-05-29 21:29:13 +02:00
#[ cfg(feature = " nightly " ) ]
mod asynch ;
mod blocking ;
2023-05-30 13:36:42 +02:00
#[ cfg(feature = " nightly " ) ]
pub use asynch ::FirmwareUpdater ;
pub use blocking ::BlockingFirmwareUpdater ;
2023-05-29 21:29:13 +02:00
use embedded_storage ::nor_flash ::{ NorFlashError , NorFlashErrorKind } ;
2023-05-30 13:36:42 +02:00
/// Firmware updater flash configuration holding the two flashes used by the updater
///
/// If only a single flash is actually used, then that flash should be partitioned into two partitions before use.
/// The easiest way to do this is to use [`FirmwareUpdaterConfig::from_linkerfile`] or [`FirmwareUpdaterConfig::from_linkerfile_blocking`] which will partition
/// the provided flash according to symbols defined in the linkerfile.
pub struct FirmwareUpdaterConfig < DFU , STATE > {
/// The dfu flash partition
pub dfu : DFU ,
/// The state flash partition
pub state : STATE ,
}
2023-05-29 21:29:13 +02:00
/// Errors returned by FirmwareUpdater
#[ derive(Debug) ]
pub enum FirmwareUpdaterError {
/// Error from flash.
Flash ( NorFlashErrorKind ) ,
/// Signature errors.
Signature ( signature ::Error ) ,
2023-06-19 22:37:23 +02:00
/// Bad state.
BadState ,
2023-05-29 21:29:13 +02:00
}
#[ 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(_) " ) ,
2023-06-19 22:37:23 +02:00
FirmwareUpdaterError ::BadState = > defmt ::write! ( fmt , " FirmwareUpdaterError::BadState " ) ,
2023-05-29 21:29:13 +02:00
}
}
}
impl < E > From < E > for FirmwareUpdaterError
where
E : NorFlashError ,
{
fn from ( error : E ) -> Self {
FirmwareUpdaterError ::Flash ( error . kind ( ) )
}
}