From fe0d6510a4aa767b0c2e7b5b0d01f8b93b29e5e5 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 26 Feb 2021 00:43:20 +0100 Subject: Updat examples to defmt 0.2 --- examples/Cargo.toml | 2 +- examples/src/bin/ble_bas_central.rs | 4 ++-- examples/src/bin/ble_bas_peripheral.rs | 4 ++-- examples/src/bin/ble_l2cap_peripheral.rs | 8 ++++---- examples/src/bin/ble_peripheral_onoff.rs | 22 ++++++++++------------ examples/src/bin/ble_scan.rs | 6 +++--- examples/src/bin/rtic.rs | 2 +- 7 files changed, 23 insertions(+), 25 deletions(-) (limited to 'examples') diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 95a6d48..b5b5bfa 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -28,7 +28,7 @@ embassy-nrf = { version = "0.1.0", features = [ "defmt", "52840" ]} cortex-m = { version = "0.6.4" } cortex-m-rt = "0.6.13" cortex-m-rtic = { version = "0.5.5", optional = true } -defmt = "0.2.0" +defmt = { version = "0.2.0", features = ["alloc"] } nrf-softdevice-defmt-rtt = { path = "../nrf-softdevice-defmt-rtt", version = "0.1.0" } panic-probe = "0.1.0" nrf52840-hal = { version = "0.12.0" } diff --git a/examples/src/bin/ble_bas_central.rs b/examples/src/bin/ble_bas_central.rs index eabc539..d601cb8 100644 --- a/examples/src/bin/ble_bas_central.rs +++ b/examples/src/bin/ble_bas_central.rs @@ -46,7 +46,7 @@ async fn ble_central_task(sd: &'static Softdevice) { // Read let val = unwrap!(client.battery_level_read().await); - info!("read battery level: {:u8}", val); + info!("read battery level: {}", val); // Write, set it to 42 unwrap!(client.battery_level_write(42).await); @@ -54,7 +54,7 @@ async fn ble_central_task(sd: &'static Softdevice) { // Read to check it's changed let val = unwrap!(client.battery_level_read().await); - info!("read battery level: {:u8}", val); + info!("read battery level: {}", val); } #[entry] diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs index 7d754b0..89c4621 100644 --- a/examples/src/bin/ble_bas_peripheral.rs +++ b/examples/src/bin/ble_bas_peripheral.rs @@ -59,13 +59,13 @@ async fn bluetooth_task(sd: &'static Softdevice, config: peripheral::Config) { // Run the GATT server on the connection. This returns when the connection gets disconnected. let res = gatt_server::run(&conn, &server, |e| match e { BatteryServiceEvent::BatteryLevelWrite(val) => { - info!("wrote battery level: {:u8}", val); + info!("wrote battery level: {}", val); if let Err(e) = server.battery_level_notify(&conn, val + 1) { info!("send notification error: {:?}", e); } } BatteryServiceEvent::FooWrite(val) => { - info!("wrote battery level: {:u16}", val); + info!("wrote battery level: {}", val); if let Err(e) = server.foo_notify(&conn, val + 1) { info!("send notification error: {:?}", e); } diff --git a/examples/src/bin/ble_l2cap_peripheral.rs b/examples/src/bin/ble_l2cap_peripheral.rs index 54716af..3418cc7 100644 --- a/examples/src/bin/ble_l2cap_peripheral.rs +++ b/examples/src/bin/ble_l2cap_peripheral.rs @@ -62,7 +62,7 @@ async fn bluetooth_task(sd: &'static Softdevice) { loop { let pkt = unwrap!(ch.rx().await); - info!("rx: {:[u8]}", pkt.0); + info!("rx: {:x}", pkt.0); } futures::future::pending::<()>().await; @@ -78,7 +78,7 @@ impl l2cap::Packet for Packet { let mut v = Vec::with_capacity(Self::MTU); let ptr = v.as_mut_ptr(); mem::forget(v); - info!("allocate {:u32}", ptr as u32); + info!("allocate {}", ptr as u32); NonNull::new(ptr) } @@ -86,12 +86,12 @@ impl l2cap::Packet for Packet { let ptr = self.0.as_mut_ptr(); let len = self.0.len(); mem::forget(self); - info!("into_raw_parts {:u32}", ptr as u32); + info!("into_raw_parts {}", ptr as u32); (unwrap!(NonNull::new(ptr)), len) } unsafe fn from_raw_parts(ptr: NonNull, len: usize) -> Self { - info!("from_raw_parts {:u32}", ptr.as_ptr() as u32); + info!("from_raw_parts {}", ptr.as_ptr() as u32); Self(Vec::from_raw_parts(ptr.as_ptr(), len, Self::MTU)) } } 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!"); }; diff --git a/examples/src/bin/ble_scan.rs b/examples/src/bin/ble_scan.rs index c8b71e3..74e2d62 100644 --- a/examples/src/bin/ble_scan.rs +++ b/examples/src/bin/ble_scan.rs @@ -31,7 +31,7 @@ async fn ble_task(sd: &'static Softdevice) { let res = central::scan(sd, &config, |params| unsafe { info!("AdvReport!"); info!( - "type: connectable={:u16} scannable={:u16} directed={:u16} scan_response={:u16} extended_pdu={:u16} status={:u16}", + "type: connectable={} scannable={} directed={} scan_response={} extended_pdu={} status={}", params.type_.connectable(), params.type_.scannable(), params.type_.directed(), @@ -40,7 +40,7 @@ async fn ble_task(sd: &'static Softdevice) { params.type_.status() ); info!( - "addr: resolved={:u8} type={:u8} addr={:[u8]}", + "addr: resolved={} type={} addr={:x}", params.peer_addr.addr_id_peer(), params.peer_addr.addr_type(), params.peer_addr.addr @@ -58,7 +58,7 @@ async fn ble_task(sd: &'static Softdevice) { } let key = data[1]; let value = &data[2..len+1]; - info!("value {:u8}: {:[u8]}", key, value); + info!("value {}: {:x}", key, value); data = &data[len+1..]; } None diff --git a/examples/src/bin/rtic.rs b/examples/src/bin/rtic.rs index 583325e..7fd34b5 100644 --- a/examples/src/bin/rtic.rs +++ b/examples/src/bin/rtic.rs @@ -124,7 +124,7 @@ const APP: () = { let sd = Softdevice::enable(sdp, &config); let temp = unwrap!(temperature_celsius(&sd)); - info!("{:i32}°C", temp.to_num::()); + info!("{}°C", temp.to_num::()); let executor = EXECUTOR.put(Executor::new()); executor.run(|spawner| { -- cgit v1.2.3