From 8979959dd15be496e74a1a670a468d4d5168f0c8 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sun, 10 Jul 2022 06:47:08 +0200 Subject: Add embedded_hal_async support for embassy-rp This commit adds support for embedded-hal-async to the Embassy Raspberry PI crate. --- examples/rp/src/bin/gpio_async.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/rp/src/bin/gpio_async.rs (limited to 'examples') diff --git a/examples/rp/src/bin/gpio_async.rs b/examples/rp/src/bin/gpio_async.rs new file mode 100644 index 000000000..e0f2aa961 --- /dev/null +++ b/examples/rp/src/bin/gpio_async.rs @@ -0,0 +1,38 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_rp::{gpio, Peripherals}; +use gpio::{Input, Level, Output, Pull}; +use {defmt_rtt as _, panic_probe as _}; + +/// This example shows how async gpio can be used with a RP2040. +/// +/// It requires an external signal to be manually triggered on PIN 16. For +/// example, this could be accomplished using an external power source with a +/// button so that it is possible to toggle the signal from low to high. +/// +/// This example will begin with turning on the LED on the board and wait for a +/// high signal on PIN 16. Once the high event/signal occurs the program will +/// continue and turn off the LED, and then wait for 2 seconds before completing +/// the loop and starting over again. +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let mut led = Output::new(p.PIN_25, Level::Low); + let mut async_input = Input::new(p.PIN_16, Pull::None); + + loop { + info!("wait_for_high. Turn on LED"); + led.set_high(); + + async_input.wait_for_high().await; + + info!("done wait_for_high. Turn off LED"); + led.set_low(); + + Timer::after(Duration::from_secs(2)).await; + } +} -- cgit