esp_hal/
config.rs

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
51
52
53
54
55
56
57
58
59
60
61
62
//! # Configuration
//!
//! ## Overview
//! This module contains the initial configuration for the system.
//!
//! ## Configuration
//! In the [`esp_hal::init()`][crate::init] method, we can configure different
//! parameters for the system:
//! - CPU clock configuration.
//! - Watchdog configuration.
//!
//! ## Examples
//!
//! ### Default initialization
//!
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! let peripherals = esp_hal::init(esp_hal::Config::default());
//! # }
//! ```
//! 
//! ### Custom initialization
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! use esp_hal::clock::CpuClock;
//!
//! let config =
//! esp_hal::Config::default().with_cpu_clock(CpuClock::max()).
//!     with_watchdog(esp_hal::config::WatchdogConfig::default().
//!     with_rwdt(esp_hal::config::WatchdogStatus::Enabled(fugit::MicrosDurationU64::millis(1000u64))));
//! let peripherals = esp_hal::init(config);
//! # }
//! ```

/// Watchdog status.
#[derive(Default, PartialEq)]
pub enum WatchdogStatus {
    /// Enables a watchdog timer with the specified timeout.
    Enabled(fugit::MicrosDurationU64),
    /// Disables the watchdog timer.
    #[default]
    Disabled,
}

/// Watchdog configuration.
#[non_exhaustive]
#[derive(Default, procmacros::BuilderLite)]
pub struct WatchdogConfig {
    #[cfg(not(any(esp32, esp32s2)))]
    /// Enable the super watchdog timer, which has a trigger time of slightly
    /// less than one second.
    pub swd: bool,
    /// Configures the reset watchdog timer.
    pub rwdt: WatchdogStatus,
    /// Configures the `timg0` watchdog timer.
    pub timg0: WatchdogStatus,
    #[cfg(timg1)]
    /// Configures the `timg1` watchdog timer.
    ///
    /// By default, the bootloader does not enable this watchdog timer.
    pub timg1: WatchdogStatus,
}