aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGuilherme S. Salustiano <[email protected]>2024-02-07 15:25:07 +0100
committerGuilherme S. Salustiano <[email protected]>2024-02-07 15:38:39 +0100
commit847b8be81480b249a2e8b1ff502e6188d2dadf04 (patch)
treeb85a06f534950ed5db592467da2afd13803de530 /examples
parent2c5426aa5c41563f3b225d99d39793a765ec9204 (diff)
feat/implement ble radio on nrf
Diffstat (limited to 'examples')
-rw-r--r--examples/nrf52840/Cargo.toml8
-rw-r--r--examples/nrf52840/src/bin/radio_ble_advertising.rs42
2 files changed, 48 insertions, 2 deletions
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"
8embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 8embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
9embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } 9embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] }
10embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 10embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
11embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 11embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime"] }
12embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 12embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time", "radio"]}
13embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } 13embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] }
14embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 14embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
15embedded-io = { version = "0.6.0", features = ["defmt-03"] } 15embedded-io = { version = "0.6.0", features = ["defmt-03"] }
@@ -35,6 +35,10 @@ embedded-hal-async = { version = "1.0" }
35embedded-hal-bus = { version = "0.1", features = ["async"] } 35embedded-hal-bus = { version = "0.1", features = ["async"] }
36num-integer = { version = "0.1.45", default-features = false } 36num-integer = { version = "0.1.45", default-features = false }
37microfft = "0.5.0" 37microfft = "0.5.0"
38jewel = { version = "0.1.0", git = "https://github.com/jewel-rs/jewel"}
39
40[patch.crates-io]
41embassy-time = { version = "0.3.0", path = "../../embassy-time"}
38 42
39[profile.release] 43[profile.release]
40debug = 2 44debug = 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 @@
1#![no_std]
2#![no_main]
3
4use defmt::{info, unwrap};
5use embassy_executor::Spawner;
6use embassy_nrf::{bind_interrupts, peripherals, radio};
7use embassy_time::Timer;
8use jewel::phy::Radio;
9use {defmt_rtt as _, panic_probe as _};
10
11bind_interrupts!(struct Irqs {
12 RADIO => radio::InterruptHandler<peripherals::RADIO>;
13});
14
15// For a high-level API look on jewel examples
16#[embassy_executor::main]
17async fn main(_spawner: Spawner) {
18 let mut config = embassy_nrf::config::Config::default();
19 config.hfclk_source = embassy_nrf::config::HfclkSource::ExternalXtal;
20 let p = embassy_nrf::init(config);
21
22 info!("Starting BLE radio");
23 let mut radio = radio::ble::Radio::new(p.RADIO, Irqs);
24
25 let pdu = [
26 0x46u8, // ADV_NONCONN_IND, Random address,
27 0x18, // Length of payload
28 0x27, 0xdc, 0xd0, 0xe8, 0xe1, 0xff, // Adress
29 0x02, 0x01, 0x06, // Flags
30 0x03, 0x03, 0x09, 0x18, // Complete list of 16-bit UUIDs available
31 0x0A, 0x09, // Length, Type: Device name
32 b'H', b'e', b'l', b'l', b'o', b'R', b'u', b's', b't',
33 ];
34
35 unwrap!(radio.set_buffer(pdu.as_ref()));
36
37 loop {
38 info!("Sending packet");
39 radio.transmit().await;
40 Timer::after_millis(500).await;
41 }
42}