diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf52840/Cargo.toml | 8 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/radio_ble_advertising.rs | 42 |
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" | |||
| 8 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 8 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 9 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } | 9 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } |
| 10 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 10 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 11 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 11 | embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime"] } |
| 12 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } | 12 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time", "radio"]} |
| 13 | embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } | 13 | embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } |
| 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 15 | embedded-io = { version = "0.6.0", features = ["defmt-03"] } | 15 | embedded-io = { version = "0.6.0", features = ["defmt-03"] } |
| @@ -35,6 +35,10 @@ embedded-hal-async = { version = "1.0" } | |||
| 35 | embedded-hal-bus = { version = "0.1", features = ["async"] } | 35 | embedded-hal-bus = { version = "0.1", features = ["async"] } |
| 36 | num-integer = { version = "0.1.45", default-features = false } | 36 | num-integer = { version = "0.1.45", default-features = false } |
| 37 | microfft = "0.5.0" | 37 | microfft = "0.5.0" |
| 38 | jewel = { version = "0.1.0", git = "https://github.com/jewel-rs/jewel"} | ||
| 39 | |||
| 40 | [patch.crates-io] | ||
| 41 | embassy-time = { version = "0.3.0", path = "../../embassy-time"} | ||
| 38 | 42 | ||
| 39 | [profile.release] | 43 | [profile.release] |
| 40 | debug = 2 | 44 | 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 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::{info, unwrap}; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nrf::{bind_interrupts, peripherals, radio}; | ||
| 7 | use embassy_time::Timer; | ||
| 8 | use jewel::phy::Radio; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | bind_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] | ||
| 17 | async 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 | } | ||
