-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a4787a
commit cde1238
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! embassy hello world | ||
//! | ||
//! This is an example of running the embassy executor with multiple tasks | ||
//! concurrently. | ||
|
||
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 | ||
//% FEATURES: embassy esp-hal-embassy/integrated-timers | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use embassy_executor::Spawner; | ||
use embassy_time::{Duration, Timer}; | ||
use esp_backtrace as _; | ||
use esp_hal::timer::timg::TimerGroup; | ||
|
||
#[embassy_executor::task] | ||
async fn run() { | ||
loop { | ||
esp_println::println!("Hello world from embassy using esp-hal-async!"); | ||
Timer::after(Duration::from_millis(1_000)).await; | ||
} | ||
} | ||
|
||
#[esp_hal_embassy::main] | ||
async fn main(spawner: Spawner) { | ||
esp_println::logger::init_logger_from_env(); | ||
let peripherals = esp_hal::init(esp_hal::Config::default()); | ||
|
||
esp_println::println!("Init!"); | ||
|
||
let timg0 = TimerGroup::new(peripherals.TIMG0); | ||
esp_hal_embassy::init(timg0.timer0); | ||
|
||
spawner.spawn(run()).ok(); | ||
|
||
loop { | ||
esp_println::println!("Bing!"); | ||
Timer::after(Duration::from_millis(5_000)).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Demonstrates deep sleep with timer wakeup | ||
|
||
//% CHIPS: esp32 esp32c3 esp32c6 esp32s3 esp32c2 | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use core::time::Duration; | ||
|
||
use esp_backtrace as _; | ||
use esp_hal::{ | ||
delay::Delay, | ||
entry, | ||
rtc_cntl::{reset_reason, sleep::TimerWakeupSource, wakeup_cause, Rtc, SocResetReason}, | ||
Cpu, | ||
}; | ||
use esp_println::println; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let peripherals = esp_hal::init(esp_hal::Config::default()); | ||
|
||
let delay = Delay::new(); | ||
let mut rtc = Rtc::new(peripherals.LPWR); | ||
|
||
println!("up and runnning!"); | ||
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); | ||
println!("reset reason: {:?}", reason); | ||
let wake_reason = wakeup_cause(); | ||
println!("wake reason: {:?}", wake_reason); | ||
|
||
let timer = TimerWakeupSource::new(Duration::from_secs(5)); | ||
println!("sleeping!"); | ||
delay.delay_millis(100); | ||
rtc.sleep_deep(&[&timer]); | ||
} |