diff options
| author | Matthew Tran <[email protected]> | 2025-05-08 00:09:21 -0500 |
|---|---|---|
| committer | Matthew Tran <[email protected]> | 2025-05-08 00:09:21 -0500 |
| commit | d35df5cfbadb0142d4c8fd44b5dcbfa81ab7ac15 (patch) | |
| tree | 4538149cc25bd0a46fee12add5e35bb83737aa2c /embassy-usb-dfu/src/dfu.rs | |
| parent | 6c6ae4f9fca1eaff6cb9f2896de333d9493ea840 (diff) | |
embassy-usb-dfu: Change return of reset to ()
Also adds &self to the Reset trait, which makes it easier to implement
cleanup/delays before actually resetting.
Diffstat (limited to 'embassy-usb-dfu/src/dfu.rs')
| -rw-r--r-- | embassy-usb-dfu/src/dfu.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/embassy-usb-dfu/src/dfu.rs b/embassy-usb-dfu/src/dfu.rs index c23286cf5..a98d6ab40 100644 --- a/embassy-usb-dfu/src/dfu.rs +++ b/embassy-usb-dfu/src/dfu.rs | |||
| @@ -1,5 +1,3 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | |||
| 3 | use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterError}; | 1 | use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterError}; |
| 4 | use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; | 2 | use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; |
| 5 | use embassy_usb::driver::Driver; | 3 | use embassy_usb::driver::Driver; |
| @@ -20,12 +18,12 @@ pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_S | |||
| 20 | status: Status, | 18 | status: Status, |
| 21 | offset: usize, | 19 | offset: usize, |
| 22 | buf: AlignedBuffer<BLOCK_SIZE>, | 20 | buf: AlignedBuffer<BLOCK_SIZE>, |
| 23 | _rst: PhantomData<RST>, | 21 | reset: RST, |
| 24 | } | 22 | } |
| 25 | 23 | ||
| 26 | impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, RST, BLOCK_SIZE> { | 24 | impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, RST, BLOCK_SIZE> { |
| 27 | /// Create a new DFU instance to handle DFU transfers. | 25 | /// Create a new DFU instance to handle DFU transfers. |
| 28 | pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { | 26 | pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes, reset: RST) -> Self { |
| 29 | Self { | 27 | Self { |
| 30 | updater, | 28 | updater, |
| 31 | attrs, | 29 | attrs, |
| @@ -33,7 +31,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Co | |||
| 33 | status: Status::Ok, | 31 | status: Status::Ok, |
| 34 | offset: 0, | 32 | offset: 0, |
| 35 | buf: AlignedBuffer([0; BLOCK_SIZE]), | 33 | buf: AlignedBuffer([0; BLOCK_SIZE]), |
| 36 | _rst: PhantomData, | 34 | reset, |
| 37 | } | 35 | } |
| 38 | } | 36 | } |
| 39 | 37 | ||
| @@ -155,14 +153,14 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Ha | |||
| 155 | } | 153 | } |
| 156 | match Request::try_from(req.request) { | 154 | match Request::try_from(req.request) { |
| 157 | Ok(Request::GetStatus) => { | 155 | Ok(Request::GetStatus) => { |
| 158 | //TODO: Configurable poll timeout, ability to add string for Vendor error | ||
| 159 | buf[0..6].copy_from_slice(&[self.status as u8, 0x32, 0x00, 0x00, self.state as u8, 0x00]); | ||
| 160 | match self.state { | 156 | match self.state { |
| 161 | State::DlSync => self.state = State::Download, | 157 | State::DlSync => self.state = State::Download, |
| 162 | State::ManifestSync => RST::sys_reset(), | 158 | State::ManifestSync => self.reset.sys_reset(), |
| 163 | _ => {} | 159 | _ => {} |
| 164 | } | 160 | } |
| 165 | 161 | ||
| 162 | //TODO: Configurable poll timeout, ability to add string for Vendor error | ||
| 163 | buf[0..6].copy_from_slice(&[self.status as u8, 0x32, 0x00, 0x00, self.state as u8, 0x00]); | ||
| 166 | Some(InResponse::Accepted(&buf[0..6])) | 164 | Some(InResponse::Accepted(&buf[0..6])) |
| 167 | } | 165 | } |
| 168 | Ok(Request::GetState) => { | 166 | Ok(Request::GetState) => { |
