esp_hal/
config.rs

1//! # Configuration
2//!
3//! ## Overview
4//! This module contains the initial configuration for the system.
5//!
6//! ## Configuration
7//! In the [`esp_hal::init()`][crate::init] method, we can configure different
8//! parameters for the system:
9//! - CPU clock configuration.
10//! - Watchdog configuration.
11//!
12//! ## Examples
13//!
14//! ### Default initialization
15//!
16//! ```rust, no_run
17#![doc = crate::before_snippet!()]
18//! let peripherals = esp_hal::init(esp_hal::Config::default());
19//! Ok(())
20//! # }
21//! ```
22//! 
23//! ### Custom initialization
24//! ```rust, no_run
25#![doc = crate::before_snippet!()]
26//! use esp_hal::clock::CpuClock;
27//! use esp_hal::time::Duration;
28//!
29//! let config =
30//! esp_hal::Config::default().with_cpu_clock(CpuClock::max()).
31//!     with_watchdog(esp_hal::config::WatchdogConfig::default().
32//!     with_rwdt(esp_hal::config::WatchdogStatus::Enabled(Duration::from_millis(1000u64))));
33//! let peripherals = esp_hal::init(config);
34//! # Ok(())
35//! # }
36//! ```
37
38use crate::time::Duration;
39
40/// Watchdog status.
41#[derive(Default, PartialEq, Clone, Copy)]
42pub enum WatchdogStatus {
43    /// Enables a watchdog timer with the specified timeout.
44    Enabled(Duration),
45    /// Disables the watchdog timer.
46    #[default]
47    Disabled,
48}
49
50/// Watchdog configuration.
51#[non_exhaustive]
52#[derive(Default, Clone, Copy, procmacros::BuilderLite)]
53pub struct WatchdogConfig {
54    #[cfg(not(any(esp32, esp32s2)))]
55    /// Enable the super watchdog timer, which has a trigger time of slightly
56    /// less than one second.
57    swd: bool,
58    /// Configures the reset watchdog timer.
59    rwdt: WatchdogStatus,
60    /// Configures the `timg0` watchdog timer.
61    timg0: WatchdogStatus,
62    #[cfg(timg1)]
63    /// Configures the `timg1` watchdog timer.
64    ///
65    /// By default, the bootloader does not enable this watchdog timer.
66    timg1: WatchdogStatus,
67}