Skip to content

Commit

Permalink
Add basic Embassy support
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii-the-Dev committed Sep 8, 2024
1 parent 5c7269c commit 261b79f
Show file tree
Hide file tree
Showing 6 changed files with 475 additions and 0 deletions.
File renamed without changes.
24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ default-target = "x86_64-unknown-linux-gnu"
[dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.3"
critical-section = { version = "1.1.3", optional = true }
embedded-dma = "0.2.0"
embedded-hal = "1.0.0"
embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = [
Expand All @@ -26,6 +27,14 @@ embedded-io = "0.6.1"
gd32f1 = { version = "0.9.1", features = ["critical-section"] }
nb = "1.1.0"
void = { version = "1.0.2", default-features = false, optional = true }
embassy-executor = { version = "0.6", features = [
"arch-cortex-m",
"executor-thread",
"integrated-timers",
], optional = true }
embassy-time = { version = "0.3.2", optional = true }
embassy-time-driver = { version = "0.1.0", optional = true }
embassy-sync = { version = "0.6.0", optional = true }

[dev-dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
Expand Down Expand Up @@ -56,6 +65,17 @@ gd32f190 = ["gd32f1/gd32f190", "device-selected"]
gd32f190x4 = ["gd32f190"]
gd32f190x6 = ["gd32f190"]
gd32f190x8 = ["gd32f190"]
embassy = [
"rt",
"dep:critical-section",
"dep:embassy-executor",
"dep:embassy-sync",
"dep:embassy-time",
"dep:embassy-time-driver",
]
time-driver-tim1=["embassy"]
time-driver-tim2=["embassy"]
time-driver-tim14=["embassy"]

[profile.dev]
incremental = false
Expand Down Expand Up @@ -109,3 +129,7 @@ required-features = ["rt"]
#[[example]]
#name = "can-rtic"
#required-features = ["has-can", "rt"]

[[example]]
name = "embassy"
required-features = ["time-driver-tim1"]
38 changes: 38 additions & 0 deletions examples/embassy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#![deny(unsafe_code)]
#![no_std]
#![no_main]

use panic_halt as _;

use embassy_executor::{self, Spawner};
use embassy_time::Timer;
use embedded_hal::digital::OutputPin;
use gd32f1x0_hal::{embassy, pac, prelude::*};

#[embassy_executor::task]
async fn blink_task(mut led: impl OutputPin + 'static) {
loop {
Timer::after_millis(1_000).await;
led.set_high().unwrap();
Timer::after_millis(1_000).await;
led.set_low().unwrap();
}
}

#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = pac::Peripherals::take().unwrap();
let mut rcu = p.rcu.constrain();
let mut flash = p.fmc.constrain();
let clocks = rcu.cfgr.freeze(&mut flash.ws);

embassy::init(p.timer1, &clocks, &mut rcu.apb1);

let mut gpioc = p.gpioc.split(&mut rcu.ahb);
let led = gpioc
.pc13
.into_push_pull_output(&mut gpioc.config)
.downgrade();

spawner.must_spawn(blink_task(led));
}
9 changes: 9 additions & 0 deletions src/embassy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use time_driver::{Bus, EmbassyTimeDriver, Timer};

use crate::rcu::Clocks;

mod time_driver;

pub fn init(timer: Timer, clocks: &Clocks, apb: &mut Bus) {
EmbassyTimeDriver::init(timer, clocks, apb)
}
Loading

0 comments on commit 261b79f

Please sign in to comment.