aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-dfu/src/lib.rs
blob: e9f4278b6ab0b9bc881ee7ff33bafa12a6a5cd83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![no_std]
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
mod fmt;

pub mod consts;

#[cfg(feature = "dfu")]
pub mod dfu;
#[cfg(all(feature = "dfu", not(feature = "application")))]
pub use self::dfu::*;

#[cfg(feature = "application")]
pub mod application;
#[cfg(all(feature = "application", not(feature = "dfu")))]
pub use self::application::*;

/// Provides a platform-agnostic interface for initiating a system reset.
///
/// This crate exposes `ResetImmediate` when compiled with cortex-m or esp32c3 support, which immediately issues a
/// reset request without interfacing with any other peripherals.
///
/// If alternate behaviour is desired, a custom implementation of Reset can be provided as an argument to the usb_dfu function.
pub trait Reset {
    /// Reset the device.
    fn sys_reset(&self);
}

/// Reset immediately.
#[cfg(feature = "esp32c3-hal")]
pub struct ResetImmediate;

#[cfg(feature = "esp32c3-hal")]
impl Reset for ResetImmediate {
    fn sys_reset(&self) {
        esp32c3_hal::reset::software_reset();
        loop {}
    }
}

/// Reset immediately.
#[cfg(feature = "cortex-m")]
pub struct ResetImmediate;

#[cfg(feature = "cortex-m")]
impl Reset for ResetImmediate {
    fn sys_reset(&self) {
        cortex_m::peripheral::SCB::sys_reset()
    }
}