diff options
| author | Kaitlyn Kenwell <[email protected]> | 2023-12-14 13:29:26 -0500 |
|---|---|---|
| committer | Kaitlyn Kenwell <[email protected]> | 2023-12-14 13:29:26 -0500 |
| commit | 9f9f6e75bb3ef6d285ebed88a20ab57fb55f3d07 (patch) | |
| tree | 2a40c219cee9f20cd3b4e3d2b0067b0ba89c4a63 /embassy-usb-dfu/src/lib.rs | |
| parent | cbc8ccc51e8e747fab51ac377225495cd24eb447 (diff) | |
Abstract chip reset logic, add Reset impls for cortex-m and esp32c3
Diffstat (limited to 'embassy-usb-dfu/src/lib.rs')
| -rw-r--r-- | embassy-usb-dfu/src/lib.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs index ae0fbbd4c..283905de9 100644 --- a/embassy-usb-dfu/src/lib.rs +++ b/embassy-usb-dfu/src/lib.rs | |||
| @@ -18,3 +18,34 @@ pub use self::application::*; | |||
| 18 | not(any(feature = "bootloader", feature = "application")) | 18 | not(any(feature = "bootloader", feature = "application")) |
| 19 | ))] | 19 | ))] |
| 20 | compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); | 20 | compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); |
| 21 | |||
| 22 | /// Provides a platform-agnostic interface for initiating a system reset. | ||
| 23 | /// | ||
| 24 | /// This crate exposes `ResetImmediate` when compiled with cortex-m or esp32c3 support, which immediately issues a | ||
| 25 | /// reset request without interfacing with any other peripherals. | ||
| 26 | /// | ||
| 27 | /// If alternate behaviour is desired, a custom implementation of Reset can be provided as a type argument to the usb_dfu function. | ||
| 28 | pub trait Reset { | ||
| 29 | fn sys_reset() -> !; | ||
| 30 | } | ||
| 31 | |||
| 32 | #[cfg(feature = "esp32c3-hal")] | ||
| 33 | pub struct ResetImmediate; | ||
| 34 | |||
| 35 | #[cfg(feature = "esp32c3-hal")] | ||
| 36 | impl Reset for ResetImmediate { | ||
| 37 | fn sys_reset() -> ! { | ||
| 38 | esp32c3_hal::reset::software_reset(); | ||
| 39 | loop {} | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | #[cfg(feature = "cortex-m")] | ||
| 44 | pub struct ResetImmediate; | ||
| 45 | |||
| 46 | #[cfg(feature = "cortex-m")] | ||
| 47 | impl Reset for ResetImmediate { | ||
| 48 | fn sys_reset() -> ! { | ||
| 49 | cortex_m::peripheral::SCB::sys_reset() | ||
| 50 | } | ||
| 51 | } | ||
