aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-dfu/src/application.rs
diff options
context:
space:
mode:
authorKaitlyn Kenwell <[email protected]>2023-12-14 13:29:26 -0500
committerKaitlyn Kenwell <[email protected]>2023-12-14 13:29:26 -0500
commit9f9f6e75bb3ef6d285ebed88a20ab57fb55f3d07 (patch)
tree2a40c219cee9f20cd3b4e3d2b0067b0ba89c4a63 /embassy-usb-dfu/src/application.rs
parentcbc8ccc51e8e747fab51ac377225495cd24eb447 (diff)
Abstract chip reset logic, add Reset impls for cortex-m and esp32c3
Diffstat (limited to 'embassy-usb-dfu/src/application.rs')
-rw-r--r--embassy-usb-dfu/src/application.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs
index 5ff8f90f8..75689db26 100644
--- a/embassy-usb-dfu/src/application.rs
+++ b/embassy-usb-dfu/src/application.rs
@@ -1,3 +1,5 @@
1use core::marker::PhantomData;
2
1use embassy_boot::BlockingFirmwareState; 3use embassy_boot::BlockingFirmwareState;
2use embassy_time::{Duration, Instant}; 4use embassy_time::{Duration, Instant};
3use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; 5use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType};
@@ -9,17 +11,19 @@ use crate::consts::{
9 DfuAttributes, Request, State, Status, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_RT, 11 DfuAttributes, Request, State, Status, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_RT,
10 USB_CLASS_APPN_SPEC, 12 USB_CLASS_APPN_SPEC,
11}; 13};
14use crate::Reset;
12 15
13/// Internal state for the DFU class 16/// Internal state for the DFU class
14pub struct Control<'d, STATE: NorFlash> { 17pub struct Control<'d, STATE: NorFlash, RST: Reset> {
15 firmware_state: BlockingFirmwareState<'d, STATE>, 18 firmware_state: BlockingFirmwareState<'d, STATE>,
16 attrs: DfuAttributes, 19 attrs: DfuAttributes,
17 state: State, 20 state: State,
18 timeout: Option<Duration>, 21 timeout: Option<Duration>,
19 detach_start: Option<Instant>, 22 detach_start: Option<Instant>,
23 _rst: PhantomData<RST>,
20} 24}
21 25
22impl<'d, STATE: NorFlash> Control<'d, STATE> { 26impl<'d, STATE: NorFlash, RST: Reset> Control<'d, STATE, RST> {
23 pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self { 27 pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self {
24 Control { 28 Control {
25 firmware_state, 29 firmware_state,
@@ -27,11 +31,12 @@ impl<'d, STATE: NorFlash> Control<'d, STATE> {
27 state: State::AppIdle, 31 state: State::AppIdle,
28 detach_start: None, 32 detach_start: None,
29 timeout: None, 33 timeout: None,
34 _rst: PhantomData,
30 } 35 }
31 } 36 }
32} 37}
33 38
34impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> { 39impl<'d, STATE: NorFlash, RST: Reset> Handler for Control<'d, STATE, RST> {
35 fn reset(&mut self) { 40 fn reset(&mut self) {
36 if let Some(start) = self.detach_start { 41 if let Some(start) = self.detach_start {
37 let delta = Instant::now() - start; 42 let delta = Instant::now() - start;
@@ -45,7 +50,7 @@ impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> {
45 self.firmware_state 50 self.firmware_state
46 .mark_dfu() 51 .mark_dfu()
47 .expect("Failed to mark DFU mode in bootloader"); 52 .expect("Failed to mark DFU mode in bootloader");
48 cortex_m::peripheral::SCB::sys_reset(); 53 RST::sys_reset()
49 } 54 }
50 } 55 }
51 } 56 }
@@ -103,9 +108,9 @@ impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> {
103/// it should expose a DFU device, and a software reset will be issued. 108/// it should expose a DFU device, and a software reset will be issued.
104/// 109///
105/// To apply USB DFU updates, the bootloader must be capable of recognizing the DFU magic and exposing a device to handle the full DFU transaction with the host. 110/// To apply USB DFU updates, the bootloader must be capable of recognizing the DFU magic and exposing a device to handle the full DFU transaction with the host.
106pub fn usb_dfu<'d, D: Driver<'d>, STATE: NorFlash>( 111pub fn usb_dfu<'d, D: Driver<'d>, STATE: NorFlash, RST: Reset>(
107 builder: &mut Builder<'d, D>, 112 builder: &mut Builder<'d, D>,
108 handler: &'d mut Control<'d, STATE>, 113 handler: &'d mut Control<'d, STATE, RST>,
109 timeout: Duration, 114 timeout: Duration,
110) { 115) {
111 let mut func = builder.function(0x00, 0x00, 0x00); 116 let mut func = builder.function(0x00, 0x00, 0x00);