From 0ed49584a5d9a0117909b7e0fc2e786b6fda2b0e Mon Sep 17 00:00:00 2001 From: Robert Zieba Date: Wed, 12 Feb 2025 14:51:40 -0700 Subject: [PATCH] asynchronous/fw_update: Change generic Error arguments Change the FW update error type to directly accept it's generic argument instead of indirectly using traits. This puts the trait restrictions on those types instead of on the traits. --- src/asynchronous/fw_update.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/asynchronous/fw_update.rs b/src/asynchronous/fw_update.rs index e5fe5fc..cef6126 100644 --- a/src/asynchronous/fw_update.rs +++ b/src/asynchronous/fw_update.rs @@ -66,15 +66,15 @@ pub trait Image: Read + Seek {} /// Error type for the firmware update process #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum Error { - Bus(T::BusError), +pub enum Error { + Bus(BE), Pd(PdError), - Io(I::Error), - ReadExact(ReadExactError), + Io(IE), + ReadExact(ReadExactError), } -impl From> for Error { - fn from(e: DeviceError) -> Self { +impl From> for Error { + fn from(e: DeviceError) -> Self { match e { DeviceError::Bus(e) => Error::Bus(e), DeviceError::Pd(e) => Error::Pd(e), @@ -134,7 +134,7 @@ async fn fw_update_init( delay: &mut impl DelayNs, controllers: &mut [&mut T], image: &mut I, -) -> Result> { +) -> Result> { if controllers.is_empty() { return Err(Error::Pd(PdError::InvalidParams)); } @@ -241,7 +241,7 @@ async fn fw_update_stream_data( block_index: usize, metadata_offset: usize, metadata_size: usize, -) -> Result<(), Error> { +) -> Result<(), Error> { if controllers.is_empty() { return Err(Error::Pd(PdError::InvalidParams)); } @@ -312,7 +312,7 @@ async fn fw_update_load_app_image( controllers: &mut [&mut T], image: &mut I, num_data_blocks: usize, -) -> Result<(), Error> { +) -> Result<(), Error> { for i in 0..num_data_blocks { info!("Broadcasting block {}", i + 1); fw_update_stream_data( @@ -335,7 +335,7 @@ async fn fw_update_load_app_config( controllers: &mut [&mut T], image: &mut I, num_data_blocks: usize, -) -> Result<(), Error> { +) -> Result<(), Error> { let app_size = get_image_size(image).await.map_err(Error::ReadExact)? as usize; let metadata_offset = app_config_block_metadata_offset(num_data_blocks, app_size); info!("Broadcasting app config block"); @@ -354,7 +354,7 @@ async fn fw_update_load_app_config( async fn fw_update_complete( delay: &mut impl DelayNs, controllers: &mut [&mut T], -) -> Result<(), Error> { +) -> Result<(), Error> { for (i, controller) in controllers.iter_mut().enumerate() { info!("Controller {}: Completing FW update", i); if controller.fw_update_complete(delay).await.is_err() { @@ -372,7 +372,7 @@ pub async fn perform_fw_update( delay: &mut impl DelayNs, mut controllers: [&mut T; N], image: &mut I, -) -> Result<(), Error> { +) -> Result<(), Error> { info!("Starting FW update"); // Disable all interrupts during the reset into FW update mode @@ -409,7 +409,7 @@ pub async fn perform_fw_update( tfui_args.num_data_blocks_tx as usize, ) .await?; - fw_update_complete(delay, controllers.as_mut_slice()).await?; + fw_update_complete::(delay, controllers.as_mut_slice()).await?; info!("FW update complete"); @@ -475,6 +475,8 @@ impl Seek for SliceImage<'_> { } } +impl Image for SliceImage<'_> {} + #[cfg(test)] mod test { use super::*;