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

Add an option to not use embassy #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ license = "MIT OR Apache-2.0"
[dependencies]
ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal.git", features = [
"{{ mcu }}",
{% if embassy -%}
"embassy",
{%- endif %}
"time-driver-tim2",
"rt",
] }
{% if embassy -%}
embassy-executor = { version = "0.5.0", features = [
"nightly",
"integrated-timers",
"arch-riscv32",
"executor-thread",
] }
embassy-time = { version = "0.3.0" }
{%- endif %}
qingke-rt = "0.2.1"
qingke = "0.2.0"
embedded-hal = "1.0.0"
Expand Down
5 changes: 5 additions & 0 deletions cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ ignore = [".git", "README.md"]
pre = ["pre-script.rhai"]
post = ["post-script.rhai"]

[placeholders.embassy]
type = "bool"
prompt = "Enable embassy (async) support?"
default = true

[placeholders.mcu_family]
type = "string"
prompt = "Which MCU family to target?"
Expand Down
26 changes: 25 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![no_main]
#![feature(type_alias_impl_trait)]

{% if embassy -%}
use embassy_executor::Spawner;
use embassy_time::Timer;
use hal::gpio::{AnyPin, Level, Output, Pin};
Expand All @@ -27,10 +28,33 @@ async fn main(spawner: Spawner) -> ! {
hal::embassy::init();

// Adjust the LED GPIO according to your board
spawner.spawn(blink(p.PC13.degrade(), 100)).unwrap();
spawner.spawn(blink(p.PD6.degrade(), 100)).unwrap();

loop {
Timer::after_millis(1000).await;
println!("tick");
}
}
{%- else -%}
use hal::delay::Delay;
use hal::gpio::{Level, Output};
use {ch32_hal as hal, panic_halt as _};

#[qingke_rt::entry]
fn main() -> ! {
hal::debug::SDIPrint::enable();
let p = hal::init(hal::Config::default());

let mut delay = Delay;

// Adjust the LED GPIO according to your board
let mut led = Output::new(p.PD6, Level::Low, Default::default());

loop {
led.toggle();

delay.delay_ms(1000);
hal::println!("toggle!");
}
}
{%- endif %}