From 847b8be81480b249a2e8b1ff502e6188d2dadf04 Mon Sep 17 00:00:00 2001 From: "Guilherme S. Salustiano" Date: Wed, 7 Feb 2024 15:25:07 +0100 Subject: feat/implement ble radio on nrf --- examples/nrf52840/Cargo.toml | 8 +++-- examples/nrf52840/src/bin/radio_ble_advertising.rs | 42 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 examples/nrf52840/src/bin/radio_ble_advertising.rs (limited to 'examples') diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index abb995be6..0239583cd 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } -embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } -embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } +embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time", "radio"]} embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embedded-io = { version = "0.6.0", features = ["defmt-03"] } @@ -35,6 +35,10 @@ embedded-hal-async = { version = "1.0" } embedded-hal-bus = { version = "0.1", features = ["async"] } num-integer = { version = "0.1.45", default-features = false } microfft = "0.5.0" +jewel = { version = "0.1.0", git = "https://github.com/jewel-rs/jewel"} + +[patch.crates-io] +embassy-time = { version = "0.3.0", path = "../../embassy-time"} [profile.release] debug = 2 diff --git a/examples/nrf52840/src/bin/radio_ble_advertising.rs b/examples/nrf52840/src/bin/radio_ble_advertising.rs new file mode 100644 index 000000000..8898c2418 --- /dev/null +++ b/examples/nrf52840/src/bin/radio_ble_advertising.rs @@ -0,0 +1,42 @@ +#![no_std] +#![no_main] + +use defmt::{info, unwrap}; +use embassy_executor::Spawner; +use embassy_nrf::{bind_interrupts, peripherals, radio}; +use embassy_time::Timer; +use jewel::phy::Radio; +use {defmt_rtt as _, panic_probe as _}; + +bind_interrupts!(struct Irqs { + RADIO => radio::InterruptHandler; +}); + +// For a high-level API look on jewel examples +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let mut config = embassy_nrf::config::Config::default(); + config.hfclk_source = embassy_nrf::config::HfclkSource::ExternalXtal; + let p = embassy_nrf::init(config); + + info!("Starting BLE radio"); + let mut radio = radio::ble::Radio::new(p.RADIO, Irqs); + + let pdu = [ + 0x46u8, // ADV_NONCONN_IND, Random address, + 0x18, // Length of payload + 0x27, 0xdc, 0xd0, 0xe8, 0xe1, 0xff, // Adress + 0x02, 0x01, 0x06, // Flags + 0x03, 0x03, 0x09, 0x18, // Complete list of 16-bit UUIDs available + 0x0A, 0x09, // Length, Type: Device name + b'H', b'e', b'l', b'l', b'o', b'R', b'u', b's', b't', + ]; + + unwrap!(radio.set_buffer(pdu.as_ref())); + + loop { + info!("Sending packet"); + radio.transmit().await; + Timer::after_millis(500).await; + } +} -- cgit