Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the need to manually pass clocks around #1999

Merged
merged 8 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions esp-hal-embassy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- Removed the `clocks` parameter from `esp_hal_embassy::init`. (#1999)

## 0.3.0 - 2024-08-29

### Added
Expand Down
30 changes: 30 additions & 0 deletions esp-hal-embassy/MIGRATING-0.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Migration Guide from 0.3.x to vNext
====================================

Initialsation
-------------

You no longer have to set up clocks and pass them to `esp_hal_embassy::init`.

```diff
use esp_hal::{
- clock::ClockControl,
- peripherals::Peripherals,
prelude::*,
- system::SystemControl,
};

#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) -> ! {
- let peripherals = Peripherals::take();
- let system = SystemControl::new(peripherals.SYSTEM);
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
+ let peripherals = esp_hal::init(esp_hal::Config::default());

let timg0 = TimerGroup::new(peripherals.TIMG0);
- esp_hal_embassy::init(&clocks, timg0);
+ esp_hal_embassy::init(timg0);

// ...
}
```
13 changes: 5 additions & 8 deletions esp-hal-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ mod fmt;

#[cfg(not(feature = "esp32"))]
use esp_hal::timer::systimer::Alarm;
use esp_hal::{
clock::Clocks,
timer::{timg::Timer as TimgTimer, ErasedTimer},
};
use esp_hal::timer::{timg::Timer as TimgTimer, ErasedTimer};
pub use macros::main;

#[cfg(feature = "executors")]
Expand Down Expand Up @@ -158,12 +155,12 @@ impl_array!(4);
#[doc = esp_hal::before_snippet!()]
/// use esp_hal::timg::TimerGroup;
///
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
/// esp_hal_embassy::init(&clocks, timg0.timer0);
/// let timg0 = TimerGroup::new(peripherals.TIMG0);
/// esp_hal_embassy::init(timg0.timer0);
///
/// // ... now you can spawn embassy tasks or use `Timer::after` etc.
/// # }
/// ```
pub fn init(clocks: &Clocks, time_driver: impl TimerCollection) {
EmbassyTimer::init(clocks, time_driver.timers())
pub fn init(time_driver: impl TimerCollection) {
EmbassyTimer::init(time_driver.timers())
}
3 changes: 1 addition & 2 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use core::cell::{Cell, RefCell};
use critical_section::Mutex;
use embassy_time_driver::{AlarmHandle, Driver};
use esp_hal::{
clock::Clocks,
interrupt::{InterruptHandler, Priority},
prelude::*,
time::current_time,
Expand Down Expand Up @@ -45,7 +44,7 @@ embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTime
});

impl EmbassyTimer {
pub(super) fn init(_clocks: &Clocks, timers: &'static mut [Timer]) {
pub(super) fn init(timers: &'static mut [Timer]) {
if timers.len() > MAX_SUPPORTED_ALARM_COUNT {
panic!(
"Maximum of {} timers can be used.",
Expand Down
2 changes: 2 additions & 0 deletions esp-hal-smartled/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- Removed the `clocks` parameter from `SmartLedsAdapter::new` (#1999)

## 0.13.0 - 2024-08-29

## 0.12.0 - 2024-07-15
Expand Down
6 changes: 3 additions & 3 deletions esp-hal-smartled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
//!
//! ```rust,ignore
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks, None).unwrap();
//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), None).unwrap();
//!
//! let rmt_buffer = smartLedBuffer!(1);
//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer, &clocks);
//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer);
//! ```
//!
//! ## Feature Flags
Expand Down Expand Up @@ -89,7 +89,6 @@ where
channel: C,
pin: impl Peripheral<P = O> + 'd,
rmt_buffer: [u32; BUFFER_SIZE],
clocks: &Clocks,
) -> SmartLedsAdapter<TX, BUFFER_SIZE>
where
O: OutputPin + 'd,
Expand All @@ -107,6 +106,7 @@ where
let channel = channel.configure(pin, config).unwrap();

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

Self {
Expand Down
5 changes: 4 additions & 1 deletion esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

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

### Changed

- `Delay::new()` is now a `const` function (#1999)

### Fixed

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

## [0.20.1] - 2024-08-30

Expand Down
1 change: 1 addition & 0 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ defmt = [
"esp32h2?/defmt",
"esp32s2?/defmt",
"esp32s3?/defmt",
"fugit/defmt",
]

#! ### PSRAM Feature Flags
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/MIGRATING-0.20.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
- let peripherals = Peripherals::take();
- let system = SystemControl::new(peripherals.SYSTEM);
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
+ let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
+ let peripherals = esp_hal::init(esp_hal::Config::default());

// ...
}
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/analog/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! );
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
//!
//! let mut delay = Delay::new(&clocks);
//! let mut delay = Delay::new();
//!
//! loop {
//! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/analog/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#![cfg_attr(esp32s2, doc = "let dac1_pin = io.pins.gpio17;")]
//! let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin);
//!
//! let mut delay = Delay::new(&clocks);
//! let mut delay = Delay::new();
//!
//! let mut voltage_dac1 = 200u8;
//!
Expand Down
Loading