esp-hal/esp32s3-hal/examples/embassy_hello_world.rs
Scott Mabin 0eac22eba1
Async: GPIO (#333)
* Add `is_listening` to `Pin` trait

* Add `Wait` impl for Gpio Input

* Add GPIO wait example for C3

* Ensure correct bank is accessed in interrupt

* Add esp32c2 wait example

* Add esp32s3 wait example

* Add esp32s2 wait example

* Add esp32 wait example

* Run fmt

* Add example to cargo tomls

* Add top level docs for embassy examples

* Mention the higher MSRV for async in the README

---------

Co-authored-by: Jesse Braham <jesse@beta7.io>
2023-01-27 10:44:08 -08:00

75 lines
1.9 KiB
Rust

//! embassy hello world
//!
//! This is an example of running the embassy executor with multiple tasks
//! concurrently.
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use embassy_executor::Executor;
use embassy_time::{Duration, Timer};
use esp32s3_hal::{
clock::ClockControl,
embassy,
peripherals::Peripherals,
prelude::*,
timer::TimerGroup,
Rtc,
};
use esp_backtrace as _;
use static_cell::StaticCell;
#[embassy_executor::task]
async fn run1() {
loop {
esp_println::println!("Hello world from embassy using esp-hal-async!");
Timer::after(Duration::from_millis(1_000)).await;
}
}
#[embassy_executor::task]
async fn run2() {
loop {
esp_println::println!("Bing!");
Timer::after(Duration::from_millis(5_000)).await;
}
}
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
#[xtensa_lx_rt::entry]
fn main() -> ! {
esp_println::println!("Init!");
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let mut wdt1 = timer_group1.wdt;
// Disable watchdog timers
rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();
#[cfg(feature = "embassy-time-systick")]
embassy::init(
&clocks,
esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER),
);
#[cfg(feature = "embassy-time-timg0")]
embassy::init(&clocks, timer_group0.timer0);
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
spawner.spawn(run1()).ok();
spawner.spawn(run2()).ok();
});
}