Skip to content

Commit

Permalink
enhance: refine v003 embassy example, 2 tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed May 11, 2024
1 parent b9f3fcd commit f5da1c9
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions examples/ch32v003/src/bin/embassy_blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

use ch32_hal as hal;
use embassy_executor::Spawner;
use embassy_time::{Instant, Timer};
use embedded_hal::delay::DelayNs;
use hal::delay::Delay;
use hal::gpio::{Level, Output};
use embassy_time::Timer;
use hal::gpio::{AnyPin, Level, Output, Pin};
use hal::println;
use qingke::riscv;

#[embassy_executor::task(pool_size = 2)]
async fn blink(pin: AnyPin, interval_ms: u64) {
let mut led = Output::new(pin, Level::Low, Default::default());

loop {
led.set_high();
Timer::after_millis(interval_ms).await;
led.set_low();
Timer::after_millis(interval_ms).await;
}
}

#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) -> ! {
Expand All @@ -19,12 +28,17 @@ async fn main(spawner: Spawner) -> ! {
let p = hal::init(config);
hal::embassy::init();

let mut led = Output::new(p.PC4, Level::Low, Default::default());
println!("CHIP signature => {}", hal::signature::chip_id().name());
println!("Clocks {:?}", hal::rcc::clocks());

loop {
led.toggle();
// let mut led = Output::new(p.PC4, Level::Low, Default::default());

Timer::after_millis(100).await;
spawner.spawn(blink(p.PC4.degrade(), 110)).unwrap();
spawner.spawn(blink(p.PA2.degrade(), 270)).unwrap();

loop {
Timer::after_millis(1000).await;
println!("tick");
}
}

Expand Down

0 comments on commit f5da1c9

Please sign in to comment.