89 lines
2.4 KiB
Rust
89 lines
2.4 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
use embassy_executor::Executor;
|
|
use embassy_time::{Duration, Timer};
|
|
use esp32c3_hal::{clock::ClockControl, prelude::*, timer::TimerGroup, Rtc, embassy};
|
|
use esp_backtrace as _;
|
|
use esp_hal_common::{Bank0GpioRegisterAccess, GpioPin, InputOutputAnalogPinType, Unknown, IO, pac::Peripherals};
|
|
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;
|
|
esp_println::println!("Just woke up");
|
|
}
|
|
}
|
|
|
|
#[embassy_executor::task]
|
|
async fn run2() {
|
|
loop {
|
|
esp_println::println!("Bing!");
|
|
Timer::after(Duration::from_millis(5_000)).await;
|
|
}
|
|
}
|
|
|
|
#[embassy_executor::task]
|
|
async fn run_io(io: IO) {
|
|
let led = io.pins.gpio1;
|
|
blink_led(led).await;
|
|
}
|
|
|
|
async fn blink_led<const N: u8>(
|
|
pin: GpioPin<Unknown, Bank0GpioRegisterAccess, InputOutputAnalogPinType, N>,
|
|
) {
|
|
let mut led = pin.into_push_pull_output();
|
|
let mut on = true;
|
|
loop {
|
|
if on {
|
|
esp_println::println!("On!");
|
|
} else {
|
|
esp_println::println!("Off!");
|
|
}
|
|
Timer::after(Duration::from_millis(5_00)).await;
|
|
on = !on;
|
|
}
|
|
}
|
|
|
|
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
|
|
|
#[riscv_rt::entry]
|
|
fn main() -> ! {
|
|
esp_println::println!("Init!");
|
|
let peripherals = Peripherals::take().unwrap();
|
|
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();
|
|
|
|
// embassy::init(
|
|
// &clocks,
|
|
// esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER),
|
|
// );
|
|
|
|
embassy::init(&clocks, timer_group0.timer0);
|
|
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
|
|
let executor = EXECUTOR.init(Executor::new());
|
|
executor.run(move |spawner| {
|
|
spawner.spawn(run1()).ok();
|
|
spawner.spawn(run2()).ok();
|
|
let res = spawner.spawn(run_io(io));
|
|
esp_println::println!("{res:?}");
|
|
});
|
|
}
|