diff options
Diffstat (limited to 'examples/rp/src/bin')
| -rw-r--r-- | examples/rp/src/bin/blinky.rs | 31 | ||||
| -rw-r--r-- | examples/rp/src/bin/button.rs | 29 | ||||
| -rw-r--r-- | examples/rp/src/bin/uart.rs | 25 |
3 files changed, 85 insertions, 0 deletions
diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs new file mode 100644 index 000000000..e42999912 --- /dev/null +++ b/examples/rp/src/bin/blinky.rs | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(asm)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | |||
| 12 | use defmt::*; | ||
| 13 | use embassy::executor::Spawner; | ||
| 14 | use embassy_rp::{gpio, Peripherals}; | ||
| 15 | use embedded_hal::digital::v2::OutputPin; | ||
| 16 | use gpio::{Level, Output}; | ||
| 17 | |||
| 18 | #[embassy::main] | ||
| 19 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 20 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 21 | |||
| 22 | loop { | ||
| 23 | info!("led on!"); | ||
| 24 | led.set_high().unwrap(); | ||
| 25 | cortex_m::asm::delay(1_000_000); | ||
| 26 | |||
| 27 | info!("led off!"); | ||
| 28 | led.set_low().unwrap(); | ||
| 29 | cortex_m::asm::delay(1_000_000); | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs new file mode 100644 index 000000000..c4d942ff5 --- /dev/null +++ b/examples/rp/src/bin/button.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(asm)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | |||
| 12 | use embassy::executor::Spawner; | ||
| 13 | use embassy_rp::gpio::{Input, Level, Output, Pull}; | ||
| 14 | use embassy_rp::Peripherals; | ||
| 15 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 19 | let button = Input::new(p.PIN_28, Pull::Up); | ||
| 20 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 21 | |||
| 22 | loop { | ||
| 23 | if button.is_high().unwrap() { | ||
| 24 | led.set_high().unwrap(); | ||
| 25 | } else { | ||
| 26 | led.set_low().unwrap(); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs new file mode 100644 index 000000000..8b5f2a53b --- /dev/null +++ b/examples/rp/src/bin/uart.rs | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(asm)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | |||
| 12 | use embassy::executor::Spawner; | ||
| 13 | use embassy_rp::{uart, Peripherals}; | ||
| 14 | |||
| 15 | #[embassy::main] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | let config = uart::Config::default(); | ||
| 18 | let mut uart = uart::Uart::new(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config); | ||
| 19 | uart.send("Hello World!\r\n".as_bytes()); | ||
| 20 | |||
| 21 | loop { | ||
| 22 | uart.send("hello there!\r\n".as_bytes()); | ||
| 23 | cortex_m::asm::delay(1_000_000); | ||
| 24 | } | ||
| 25 | } | ||
