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

Use embassy-executor instead of nostd_async #850

Merged
merged 4 commits into from
Sep 15, 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
5 changes: 4 additions & 1 deletion rp2040-hal-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fugit = "0.3.6"
futures = {version = "0.3.30", default-features = false, features = ["async-await"]}
hd44780-driver = "0.4.0"
nb = "1.0"
nostd_async = {version = "0.6.1", features = ["cortex_m"]}
panic-halt = "0.2.0"
panic-probe = {version = "0.3.1", features = ["print-defmt"]}
pio = "0.2.0"
Expand All @@ -39,3 +38,7 @@ pio-proc = "0.2.0"
portable-atomic = {version = "1.7.0", features = ["critical-section"]}
rp2040-boot2 = "0.3.0"
rp2040-hal = {path = "../rp2040-hal", version = "0.10.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"]}
static_cell = "2.1.0"

[target.'cfg( target_arch = "arm" )'.dependencies]
embassy-executor = {version = "0.5", features = ["arch-cortex-m", "executor-thread"]}
11 changes: 6 additions & 5 deletions rp2040-hal-examples/src/bin/i2c_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ use hal::{
};

// Import required types & traits.
use embassy_executor::Executor;
use embedded_hal_async::i2c::I2c;
use hal::{
gpio::{FunctionI2C, Pin, PullUp},
pac::{self, interrupt},
Clock,
};
use static_cell::StaticCell;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand All @@ -54,6 +56,7 @@ unsafe fn I2C0_IRQ() {

/// The function configures the RP2040 peripherals, then performs a single I²C
/// write to a fixed address.
#[embassy_executor::task]
async fn demo() {
let mut pac = pac::Peripherals::take().unwrap();

Expand Down Expand Up @@ -118,9 +121,7 @@ async fn demo() {
/// Entry point to our bare-metal application.
#[rp2040_hal::entry]
fn main() -> ! {
let runtime = nostd_async::Runtime::new();
let mut task = nostd_async::Task::new(demo());
let handle = task.spawn(&runtime);
handle.join();
unreachable!()
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| spawner.spawn(demo()).unwrap());
}
11 changes: 6 additions & 5 deletions rp2040-hal-examples/src/bin/i2c_async_cancelled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ use hal::{
};

use defmt_rtt as _;
use embassy_executor::Executor;
use panic_probe as _;
use static_cell::StaticCell;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand All @@ -60,6 +62,7 @@ unsafe fn I2C0_IRQ() {

/// The function configures the RP2040 peripherals, then performs a single I²C
/// write to a fixed address.
#[embassy_executor::task]
async fn demo() {
let mut pac = pac::Peripherals::take().unwrap();

Expand Down Expand Up @@ -142,9 +145,7 @@ async fn demo() {
/// Entry point to our bare-metal application.
#[rp2040_hal::entry]
fn main() -> ! {
let runtime = nostd_async::Runtime::new();
let mut task = nostd_async::Task::new(demo());
let handle = task.spawn(&runtime);
handle.join();
unreachable!()
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| spawner.spawn(demo()).unwrap());
}
8 changes: 7 additions & 1 deletion rp235x-hal-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ futures = {version = "0.3.30", default-features = false, features = ["async-awai
hd44780-driver = "0.4.0"
heapless = "0.8.0"
nb = "1.0"
nostd_async = {version = "0.6.1", features = ["cortex_m"]}
panic-halt = "0.2.0"
pio = "0.2.0"
pio-proc = "0.2.0"
rp235x-hal = {path = "../rp235x-hal", version = "0.2.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"]}
usb-device = "0.3.2"
usbd-serial = "0.2.2"
static_cell = "2.1.0"

[target.'cfg( target_arch = "arm" )'.dependencies]
embassy-executor = {version = "0.5", features = ["arch-cortex-m", "executor-thread"]}

[target.'cfg( target_arch = "riscv32" )'.dependencies]
embassy-executor = {version = "0.5", features = ["arch-riscv32", "executor-thread"]}
11 changes: 6 additions & 5 deletions rp235x-hal-examples/src/bin/i2c_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use hal::{
};

// Import required types & traits.
use embassy_executor::Executor;
use embedded_hal_async::i2c::I2c;
use static_cell::StaticCell;

/// Tell the Boot ROM about our application
#[link_section = ".start_block"]
Expand All @@ -48,6 +50,7 @@ unsafe fn I2C0_IRQ() {

/// The function configures the RP235x peripherals, then performs a single I²C
/// write to a fixed address.
#[embassy_executor::task]
async fn demo() {
let mut pac = hal::pac::Peripherals::take().unwrap();

Expand Down Expand Up @@ -112,11 +115,9 @@ async fn demo() {
/// Entry point to our bare-metal application.
#[hal::entry]
fn main() -> ! {
let runtime = nostd_async::Runtime::new();
let mut task = nostd_async::Task::new(demo());
let handle = task.spawn(&runtime);
handle.join();
unreachable!()
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| spawner.spawn(demo()).unwrap());
}

/// Program metadata for `picotool info`
Expand Down
11 changes: 6 additions & 5 deletions rp235x-hal-examples/src/bin/i2c_async_cancelled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use hal::{
};

use defmt_rtt as _;
use embassy_executor::Executor;
use static_cell::StaticCell;

/// Tell the Boot ROM about our application
#[link_section = ".start_block"]
Expand All @@ -50,6 +52,7 @@ unsafe fn I2C0_IRQ() {

/// The function configures the RP235x peripherals, then performs a single I²C
/// write to a fixed address.
#[embassy_executor::task]
async fn demo() {
let mut pac = hal::pac::Peripherals::take().unwrap();

Expand Down Expand Up @@ -132,11 +135,9 @@ async fn demo() {
/// Entry point to our bare-metal application.
#[hal::entry]
fn main() -> ! {
let runtime = nostd_async::Runtime::new();
let mut task = nostd_async::Task::new(demo());
let handle = task.spawn(&runtime);
handle.join();
unreachable!()
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| spawner.spawn(demo()).unwrap());
}

/// Program metadata for `picotool info`
Expand Down