diff options
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 | } | ||
