summaryrefslogtreecommitdiff
path: root/examples/src/bin/ble_peripheral_onoff.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2021-02-26 00:43:20 +0100
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2021-02-26 00:43:20 +0100
commitfe0d6510a4aa767b0c2e7b5b0d01f8b93b29e5e5 (patch)
tree91a92da5dfc9e22cee6164862760797c3c1d9178 /examples/src/bin/ble_peripheral_onoff.rs
parenteb0994c1a0824d385c0bcbd378b302ca697fb575 (diff)
downloadnrf-softdevice-fe0d6510a4aa767b0c2e7b5b0d01f8b93b29e5e5.zip
Updat examples to defmt 0.2
Diffstat (limited to 'examples/src/bin/ble_peripheral_onoff.rs')
-rw-r--r--examples/src/bin/ble_peripheral_onoff.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/examples/src/bin/ble_peripheral_onoff.rs b/examples/src/bin/ble_peripheral_onoff.rs
index cad1145..83686f4 100644
--- a/examples/src/bin/ble_peripheral_onoff.rs
+++ b/examples/src/bin/ble_peripheral_onoff.rs
@@ -11,8 +11,9 @@ use core::mem;
use cortex_m_rt::entry;
use defmt::{panic, *};
use embassy::executor::{task, Executor};
+use embassy::gpio::WaitForLow;
use embassy::util::Forever;
-use embassy_nrf::gpiote::{Gpiote, PortInputPolarity};
+use embassy_nrf::gpiote::{Gpiote, GpiotePin};
use embassy_nrf::interrupt;
use futures::pin_mut;
use nrf52840_hal::gpio;
@@ -57,7 +58,7 @@ async fn run_bluetooth(sd: &'static Softdevice, server: &FooService) {
let res = gatt_server::run(&conn, server, |e| match e {
FooServiceEvent::FooWrite(val) => {
- info!("wrote foo level: {:u16}", val);
+ info!("wrote foo level: {}", val);
if let Err(e) = server.foo_notify(&conn, val + 1) {
info!("send notification error: {:?}", e);
}
@@ -78,18 +79,17 @@ async fn bluetooth_task(sd: &'static Softdevice, gpiote: pac::GPIOTE, p0: pac::P
let server: FooService = unwrap!(gatt_server::register(sd));
let port0 = gpio::p0::Parts::new(p0);
- let gpiote = Gpiote::new(gpiote, interrupt::take!(GPIOTE));
+ let (gpiote, _) = Gpiote::new(gpiote, interrupt::take!(GPIOTE));
info!("Bluetooth is OFF");
info!("Press nrf52840-dk button 1 to enable, button 2 to disable");
- let button1 = port0.p0_11.into_pullup_input().degrade();
- let button2 = port0.p0_12.into_pullup_input().degrade();
-
+ let button1 = GpiotePin::new(gpiote, port0.p0_11.into_pullup_input().degrade());
+ let button2 = GpiotePin::new(gpiote, port0.p0_12.into_pullup_input().degrade());
+ pin_mut!(button1);
+ pin_mut!(button2);
loop {
- gpiote
- .wait_port_input(&button1, PortInputPolarity::Low)
- .await;
+ button1.as_mut().wait_for_low().await;
info!("Bluetooth ON!");
// Create a future that will run the bluetooth loop.
@@ -98,9 +98,7 @@ async fn bluetooth_task(sd: &'static Softdevice, gpiote: pac::GPIOTE, p0: pac::P
// Create a future that will resolve when the OFF button is pressed.
let off_fut = async {
- gpiote
- .wait_port_input(&button2, PortInputPolarity::Low)
- .await;
+ button2.as_mut().wait_for_low().await;
info!("Bluetooth OFF!");
};