mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-28 21:00:59 +00:00
Derive Builder Lite pattern for HAL configuration, update examples/tests (#2645)
* Derive Builder Lite pattern for `esp_hal::Config` and `WatchdogConfig` * User builder pattern for `esp_hal::Config` in examples/tests * Update `CHANGELOG.md`
This commit is contained in:
parent
9f3476b006
commit
891a12e13f
@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Configuration structs in the I2C, SPI, and UART drivers now implement the Builder Lite pattern (#2614)
|
||||
- Added `I8080::apply_config`, `DPI::apply_config` and `Camera::apply_config` (#2610)
|
||||
- Introduced the `unstable` feature which will be used to restrict stable APIs to a subset of esp-hal. (#2628)
|
||||
- HAL configuration structs now implement the Builder Lite pattern (#2645)
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -38,26 +38,8 @@
|
||||
//! ```rust, no_run
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! // Initialize with the highest possible frequency for this chip
|
||||
//! let peripherals = esp_hal::init({
|
||||
//! let mut config = esp_hal::Config::default();
|
||||
//! config.cpu_clock = CpuClock::max();
|
||||
//! config
|
||||
//! });
|
||||
//!
|
||||
//! // Initialize with custom clock frequency
|
||||
//! // let peripherals = esp_hal::init({
|
||||
//! // let mut config = esp_hal::Config::default();
|
||||
#![cfg_attr(
|
||||
not(any(esp32c2, esp32h2)),
|
||||
doc = "// config.cpu_clock = CpuClock::Clock160MHz;"
|
||||
)]
|
||||
#![cfg_attr(esp32c2, doc = "// config.cpu_clock = CpuClock::Clock120MHz;")]
|
||||
#![cfg_attr(esp32h2, doc = "// config.cpu_clock = CpuClock::Clock96MHz;")]
|
||||
//! // config
|
||||
//! // });
|
||||
//! //
|
||||
//! // Initialize with default clock frequency for this chip
|
||||
//! // let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
//! let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
//! let peripherals = esp_hal::init(config);
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
|
@ -22,10 +22,10 @@
|
||||
//! ### Custom initialization
|
||||
//! ```rust, no_run
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! let mut config = esp_hal::Config::default();
|
||||
//! config.cpu_clock = CpuClock::max();
|
||||
//! config.watchdog.rwdt =
|
||||
//! esp_hal::config::WatchdogStatus::Enabled(fugit::MicrosDurationU64::millis(1000 as u64));
|
||||
//! 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);
|
||||
//! # }
|
||||
//! ```
|
||||
@ -42,7 +42,7 @@ pub enum WatchdogStatus {
|
||||
|
||||
/// Watchdog configuration.
|
||||
#[non_exhaustive]
|
||||
#[derive(Default)]
|
||||
#[derive(Default, procmacros::BuilderLite)]
|
||||
pub struct WatchdogConfig {
|
||||
#[cfg(not(any(esp32, esp32s2)))]
|
||||
/// Enable the super watchdog timer, which has a trigger time of slightly
|
||||
|
@ -75,12 +75,8 @@
|
||||
//!
|
||||
//! #[entry]
|
||||
//! fn main() -> ! {
|
||||
//! let peripherals = esp_hal::init({
|
||||
//! let mut config = esp_hal::Config::default();
|
||||
//! // Configure the CPU to run at the maximum frequency.
|
||||
//! config.cpu_clock = CpuClock::max();
|
||||
//! config
|
||||
//! });
|
||||
//! let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
//! let peripherals = esp_hal::init(config);
|
||||
//!
|
||||
//! // Set GPIO0 as an output, and set its state high initially.
|
||||
//! let mut led = Output::new(peripherals.GPIO0, Level::High);
|
||||
@ -482,7 +478,7 @@ use crate::{
|
||||
///
|
||||
/// For usage examples, see the [config module documentation](crate::config).
|
||||
#[non_exhaustive]
|
||||
#[derive(Default)]
|
||||
#[derive(Default, procmacros::BuilderLite)]
|
||||
pub struct Config {
|
||||
/// The CPU clock configuration.
|
||||
pub cpu_clock: CpuClock,
|
||||
|
@ -31,11 +31,8 @@ const MAC_ADDRESS: [u8; 6] = [0x00, 0x80, 0x41, 0x13, 0x37, 0x42];
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -40,11 +40,8 @@ use smoltcp::iface::{SocketSet, SocketStorage};
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -46,11 +46,8 @@ const PASSWORD: &str = env!("PASSWORD");
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger(log::LevelFilter::Info);
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -57,11 +57,8 @@ const UPLOAD_DOWNLOAD_PORT: u16 = 4323;
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -37,11 +37,8 @@ use esp_wifi::{ble::controller::BleConnector, init};
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -53,11 +53,8 @@ const PASSWORD: &str = env!("PASSWORD");
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
static mut HEAP: core::mem::MaybeUninit<[u8; 72 * 1024]> = core::mem::MaybeUninit::uninit();
|
||||
|
||||
|
@ -45,11 +45,8 @@ const PASSWORD: &str = env!("PASSWORD");
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -47,11 +47,8 @@ const PASSWORD: &str = env!("PASSWORD");
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -49,11 +49,8 @@ const PASSWORD: &str = env!("PASSWORD");
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -57,11 +57,8 @@ macro_rules! mk_static {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -65,11 +65,8 @@ macro_rules! mk_static {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -68,11 +68,8 @@ static mut TX_BUFFER: [u8; TX_BUFFER_SIZE] = [0; TX_BUFFER_SIZE];
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
static mut HEAP: core::mem::MaybeUninit<[u8; 32 * 1024]> = core::mem::MaybeUninit::uninit();
|
||||
|
||||
|
@ -50,11 +50,8 @@ macro_rules! mk_static {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -50,11 +50,8 @@ const PASSWORD: &str = env!("PASSWORD");
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -36,11 +36,8 @@ macro_rules! mk_static {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -36,11 +36,8 @@ macro_rules! mk_static {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -44,11 +44,8 @@ macro_rules! mk_static {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_s: Spawner) {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -25,11 +25,8 @@ use esp_wifi::{
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -29,11 +29,8 @@ static KNOWN_SSIDS: Mutex<RefCell<BTreeSet<String>>> = Mutex::new(RefCell::new(B
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -45,11 +45,8 @@ const GATEWAY_IP: &str = env!("GATEWAY_IP");
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
|
@ -22,11 +22,8 @@ mod tests {
|
||||
|
||||
#[init]
|
||||
fn init() -> Context<'static> {
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let aes = Aes::new(peripherals.AES);
|
||||
|
||||
Context { aes }
|
||||
|
@ -54,11 +54,8 @@ mod tests {
|
||||
|
||||
#[init]
|
||||
fn init() -> Context<'static> {
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
let ecc = Ecc::new(peripherals.ECC);
|
||||
let rng = Rng::new(peripherals.RNG);
|
||||
|
@ -58,11 +58,8 @@ mod tests {
|
||||
fn test_init() -> Peripherals {
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
})
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
esp_hal::init(config)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -64,11 +64,8 @@ mod tests {
|
||||
|
||||
#[init]
|
||||
fn init() -> Context {
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
|
@ -169,8 +169,7 @@ mod tests {
|
||||
// FIXME: max speed fails...?
|
||||
let config = esp_hal::Config::default();
|
||||
} else {
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CpuClock::max();
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,8 @@ static TASK1: TaskStorage<Task1> = TaskStorage::new();
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let peripherals = esp_hal::init({
|
||||
let mut config = esp_hal::Config::default();
|
||||
config.cpu_clock = CLOCK;
|
||||
config
|
||||
});
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let systimer = SystemTimer::new(peripherals.SYSTIMER);
|
||||
esp_hal_embassy::init(systimer.alarm0);
|
||||
println!("Embassy initialized!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user