Skip to content

Commit 99bf346

Browse files
authored
Remove the need to manually pass clocks around (#1999)
* Clean up passing clocks to drivers * Update changelog * Initialise Clocks in a critical section * Fix calling now() before init * Fix doc * Fix esp-wifi migration guide * Add safety comment * Update tests
1 parent 7688504 commit 99bf346

File tree

186 files changed

+745
-880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+745
-880
lines changed

esp-hal-embassy/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Removed
1717

18+
- Removed the `clocks` parameter from `esp_hal_embassy::init`. (#1999)
19+
1820
## 0.3.0 - 2024-08-29
1921

2022
### Added

esp-hal-embassy/MIGRATING-0.3.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Migration Guide from 0.3.x to vNext
2+
====================================
3+
4+
Initialsation
5+
-------------
6+
7+
You no longer have to set up clocks and pass them to `esp_hal_embassy::init`.
8+
9+
```diff
10+
use esp_hal::{
11+
- clock::ClockControl,
12+
- peripherals::Peripherals,
13+
prelude::*,
14+
- system::SystemControl,
15+
};
16+
17+
#[esp_hal_embassy::main]
18+
async fn main(_spawner: Spawner) -> ! {
19+
- let peripherals = Peripherals::take();
20+
- let system = SystemControl::new(peripherals.SYSTEM);
21+
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
22+
+ let peripherals = esp_hal::init(esp_hal::Config::default());
23+
24+
let timg0 = TimerGroup::new(peripherals.TIMG0);
25+
- esp_hal_embassy::init(&clocks, timg0);
26+
+ esp_hal_embassy::init(timg0);
27+
28+
// ...
29+
}
30+
```

esp-hal-embassy/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ mod fmt;
3838

3939
#[cfg(not(feature = "esp32"))]
4040
use esp_hal::timer::systimer::Alarm;
41-
use esp_hal::{
42-
clock::Clocks,
43-
timer::{timg::Timer as TimgTimer, ErasedTimer},
44-
};
41+
use esp_hal::timer::{timg::Timer as TimgTimer, ErasedTimer};
4542
pub use macros::main;
4643

4744
#[cfg(feature = "executors")]
@@ -158,12 +155,12 @@ impl_array!(4);
158155
#[doc = esp_hal::before_snippet!()]
159156
/// use esp_hal::timg::TimerGroup;
160157
///
161-
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
162-
/// esp_hal_embassy::init(&clocks, timg0.timer0);
158+
/// let timg0 = TimerGroup::new(peripherals.TIMG0);
159+
/// esp_hal_embassy::init(timg0.timer0);
163160
///
164161
/// // ... now you can spawn embassy tasks or use `Timer::after` etc.
165162
/// # }
166163
/// ```
167-
pub fn init(clocks: &Clocks, time_driver: impl TimerCollection) {
168-
EmbassyTimer::init(clocks, time_driver.timers())
164+
pub fn init(time_driver: impl TimerCollection) {
165+
EmbassyTimer::init(time_driver.timers())
169166
}

esp-hal-embassy/src/time_driver.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use core::cell::{Cell, RefCell};
33
use critical_section::Mutex;
44
use embassy_time_driver::{AlarmHandle, Driver};
55
use esp_hal::{
6-
clock::Clocks,
76
interrupt::{InterruptHandler, Priority},
87
prelude::*,
98
time::current_time,
@@ -45,7 +44,7 @@ embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTime
4544
});
4645

4746
impl EmbassyTimer {
48-
pub(super) fn init(_clocks: &Clocks, timers: &'static mut [Timer]) {
47+
pub(super) fn init(timers: &'static mut [Timer]) {
4948
if timers.len() > MAX_SUPPORTED_ALARM_COUNT {
5049
panic!(
5150
"Maximum of {} timers can be used.",

esp-hal-smartled/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Removed
1717

18+
- Removed the `clocks` parameter from `SmartLedsAdapter::new` (#1999)
19+
1820
## 0.13.0 - 2024-08-29
1921

2022
## 0.12.0 - 2024-07-15

esp-hal-smartled/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//!
1313
//! ```rust,ignore
1414
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
15-
//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks, None).unwrap();
15+
//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), None).unwrap();
1616
//!
1717
//! let rmt_buffer = smartLedBuffer!(1);
18-
//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer, &clocks);
18+
//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer);
1919
//! ```
2020
//!
2121
//! ## Feature Flags
@@ -89,7 +89,6 @@ where
8989
channel: C,
9090
pin: impl Peripheral<P = O> + 'd,
9191
rmt_buffer: [u32; BUFFER_SIZE],
92-
clocks: &Clocks,
9392
) -> SmartLedsAdapter<TX, BUFFER_SIZE>
9493
where
9594
O: OutputPin + 'd,
@@ -107,6 +106,7 @@ where
107106
let channel = channel.configure(pin, config).unwrap();
108107

109108
// Assume the RMT peripheral is set up to use the APB clock
109+
let clocks = Clocks::get();
110110
let src_clock = clocks.apb_clock.to_MHz();
111111

112112
Self {

esp-hal/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Implement `embedded-hal` output pin traits for `DummyPin` (#2019)
13-
- Added `esp_hal::init` to simplify HAL initialisation (#1970)
13+
- Added `esp_hal::init` to simplify HAL initialisation (#1970, #1999)
1414

1515
### Changed
1616

17+
- `Delay::new()` is now a `const` function (#1999)
18+
1719
### Fixed
1820

1921
- Fixed an issue with DMA transfers potentially not waking up the correct async task (#2065)
@@ -23,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2325
- Removed `NoPinType` in favour of `DummyPin`. (#2068)
2426
- Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070)
2527
- Removed the `GpioN` type aliasses. Use `GpioPin<N>` instead. (#2073)
28+
- Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999)
2629

2730
## [0.20.1] - 2024-08-30
2831

esp-hal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ defmt = [
139139
"esp32h2?/defmt",
140140
"esp32s2?/defmt",
141141
"esp32s3?/defmt",
142+
"fugit/defmt",
142143
]
143144

144145
#! ### PSRAM Feature Flags

esp-hal/MIGRATING-0.20.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
3030
- let peripherals = Peripherals::take();
3131
- let system = SystemControl::new(peripherals.SYSTEM);
3232
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
33-
+ let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
33+
+ let peripherals = esp_hal::init(esp_hal::Config::default());
3434

3535
// ...
3636
}

esp-hal/src/analog/adc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//! );
4747
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
4848
//!
49-
//! let mut delay = Delay::new(&clocks);
49+
//! let mut delay = Delay::new();
5050
//!
5151
//! loop {
5252
//! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap();

0 commit comments

Comments
 (0)