Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/qingke v4 delay #28

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions examples/ch32v307/src/bin/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,19 @@
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]

use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use hal::gpio::{AnyPin, Level, Output, Pin};
use hal::delay::Delay;
use hal::gpio::{Level, Output};
use {ch32_hal as hal, panic_halt as _};

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

loop {
led.set_high();
Timer::after(Duration::from_millis(interval_ms)).await;
led.set_low();
Timer::after(Duration::from_millis(interval_ms)).await;
}
}

#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) -> ! {
hal::debug::SDIPrint::enable();
#[qingke_rt::entry]
fn main() -> ! {
let p = hal::init(Default::default());
hal::println!("init embassy");

hal::embassy::init();

hal::println!("init ok");
let mut led = Output::new(p.PA15, Level::Low, Default::default());
let mut delay = Delay;

// GPIO
spawner.spawn(blink(p.PA15.degrade(), 1000)).unwrap();
spawner.spawn(blink(p.PB4.degrade(), 500)).unwrap();
// spawner.spawn(blink(p.PB8.degrade(), 100)).unwrap();
loop {
Timer::after_millis(2000).await;
hal::println!("tick");
led.toggle();
delay.delay_ms(1000);
}
}
35 changes: 35 additions & 0 deletions examples/ch32v307/src/bin/embassy_blinky.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]

use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use hal::gpio::{AnyPin, Level, Output, Pin};
use {ch32_hal as hal, panic_halt as _};

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

loop {
led.set_high();
Timer::after(Duration::from_millis(interval_ms)).await;
led.set_low();
Timer::after(Duration::from_millis(interval_ms)).await;
}
}

#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) -> ! {
let p = hal::init(Default::default());
hal::embassy::init();

// GPIO
spawner.spawn(blink(p.PA15.degrade(), 1000)).unwrap();
spawner.spawn(blink(p.PB4.degrade(), 100)).unwrap();
// spawner.spawn(blink(p.PB8.degrade(), 100)).unwrap();
loop {
Timer::after_millis(2000).await;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! SYSTICK based delay implementation for Qingke V2
//! SYSTICK based delay implementation for Qingke V2 and V4

use pac::systick::vals;

Expand Down
4 changes: 2 additions & 2 deletions src/delay/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(qingke_v2)]
#[path = "./impl_qingke_v2.rs"]
#[cfg(any(qingke_v2, qingke_v4))]
#[path = "./impl_qingke_v2_v4.rs"]
mod delay_impl;

#[cfg(qingke_v3)]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod interrupt_ext;

pub use crate::_generated::{peripherals, Peripherals};

#[cfg(any(systick_rv2, systick_rv3))]
#[cfg(not(time_driver_systick))]
pub mod delay;
pub mod dma;

Expand Down Expand Up @@ -115,7 +115,7 @@ pub fn init(config: Config) -> Peripherals {
unsafe {
rcc::init(config.rcc);

#[cfg(any(systick_rv2, systick_rv3))]
#[cfg(any(systick_rv2, systick_rv3, systick_rv4))]
delay::Delay::init();
}

Expand Down
Loading