Fix embassy migration guide (#2393)

This commit is contained in:
Dániel Buga 2024-10-23 15:49:20 +02:00 committed by GitHub
parent 4c1c6131df
commit 5f6ca8d252
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,8 +21,43 @@ You no longer have to set up clocks and pass them to `esp_hal_embassy::init`.
let timg0 = TimerGroup::new(peripherals.TIMG0); let timg0 = TimerGroup::new(peripherals.TIMG0);
- esp_hal_embassy::init(&clocks, timg0); - esp_hal_embassy::init(&clocks, timg0);
+ esp_hal_embassy::init(timg0); + esp_hal_embassy::init(timg0.timer0);
// ... // ...
} }
``` ```
You have to specify a timer instance (that may be a `TimerGroup` timer unit
or a `SystemTimer` alarm) or an array of `AnyTimer`s when calling `init`.
An example of how you can set multiple timers (for example when using
multiple executors):
```rust
use esp_hal::{
prelude::*,
timer::{
AnyTimer,
systimer::SystemTimer
}
};
#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0);
let timer0: AnyTimer = timg0.timer0.into();
let timer1: AnyTimer = timg0.timer1.into();
// You can use either a TimerGroup timer, a SystemTimer alarm,
// or you can mix and match them as well.
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
let timer2: AnyTimer = systimer.alarm0;
esp_hal_embassy::init([timer0, timer1, timer2]);
// ...
}
```
Note that you only have to convert into `AnyTimer` if you want to use multiple timers.