From b54310ece09141d116c94f64ff8559810c64b6be Mon Sep 17 00:00:00 2001 From: Juraj Sadel Date: Thu, 21 Sep 2023 14:34:16 +0800 Subject: [PATCH] Update READMEs and clean up `examples-esp32c6` root (#269) * Remove the note that says we don't support BLE for C6 * Remove white space in README * Remove async_ble.rs and ble.rs files from examples-esp32c6 root --- README.md | 2 +- examples-esp32c6/async_ble.rs | 169 ---------------------------------- examples-esp32c6/ble.rs | 155 ------------------------------- examples.md | 12 +-- 4 files changed, 7 insertions(+), 331 deletions(-) delete mode 100644 examples-esp32c6/async_ble.rs delete mode 100644 examples-esp32c6/ble.rs diff --git a/README.md b/README.md index f51c5312..89041611 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Ensure that the right features are enabled for your chip. See the examples for m ```toml [dependencies.esp-wifi] -# A supported chip needs to be specified, as well as specific use-case features +# A supported chip needs to be specified, as well as specific use-case features features = ["esp32s3", "wifi", "esp-now"] ``` diff --git a/examples-esp32c6/async_ble.rs b/examples-esp32c6/async_ble.rs deleted file mode 100644 index 76a984d6..00000000 --- a/examples-esp32c6/async_ble.rs +++ /dev/null @@ -1,169 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] -#![feature(async_closure)] - -use core::cell::RefCell; - -use bleps::{ - ad_structure::{ - create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE, - }, - async_attribute_server::AttributeServer, - asynch::Ble, - attribute_server::NotificationData, - gatt, -}; -use embassy_executor::Executor; -use embassy_executor::_export::StaticCell; -use embedded_hal_async::digital::Wait; -use esp_backtrace as _; -use esp_println::println; -use esp_wifi::{ - ble::controller::asynch::BleConnector, initialize, EspWifiInitFor, EspWifiInitialization, -}; -use examples_util::hal; -use examples_util::BootButton; -use hal::{ - clock::{ClockControl, CpuClock}, - embassy, - peripherals::*, - prelude::*, - radio::Bluetooth, - timer::TimerGroup, - Rng, Rtc, IO, -}; - -#[embassy_executor::task] -async fn run(init: EspWifiInitialization, mut bluetooth: Bluetooth, pin: BootButton) { - let connector = BleConnector::new(&init, &mut bluetooth); - let mut ble = Ble::new(connector, esp_wifi::current_millis); - println!("Connector created"); - - let pin_ref = RefCell::new(pin); - - loop { - println!("{:?}", ble.init().await); - println!("{:?}", ble.cmd_set_le_advertising_parameters().await); - println!( - "{:?}", - ble.cmd_set_le_advertising_data( - create_advertising_data(&[ - AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED), - AdStructure::ServiceUuids16(&[Uuid::Uuid16(0x1809)]), - AdStructure::CompleteLocalName(examples_util::SOC_NAME), - ]) - .unwrap() - ) - .await - ); - println!("{:?}", ble.cmd_set_le_advertise_enable(true).await); - - println!("started advertising"); - - let mut rf = |_offset: usize, data: &mut [u8]| { - data[..20].copy_from_slice(&b"Hello Bare-Metal BLE"[..]); - 17 - }; - let mut wf = |offset: usize, data: &[u8]| { - println!("RECEIVED: {} {:?}", offset, data); - }; - - let mut wf2 = |offset: usize, data: &[u8]| { - println!("RECEIVED: {} {:?}", offset, data); - }; - - let mut rf3 = |_offset: usize, data: &mut [u8]| { - data[..5].copy_from_slice(&b"Hola!"[..]); - 5 - }; - let mut wf3 = |offset: usize, data: &[u8]| { - println!("RECEIVED: Offset {}, data {:?}", offset, data); - }; - - gatt!([service { - uuid: "937312e0-2354-11eb-9f10-fbc30a62cf38", - characteristics: [ - characteristic { - uuid: "937312e0-2354-11eb-9f10-fbc30a62cf38", - read: rf, - write: wf, - }, - characteristic { - uuid: "957312e0-2354-11eb-9f10-fbc30a62cf38", - write: wf2, - }, - characteristic { - name: "my_characteristic", - uuid: "987312e0-2354-11eb-9f10-fbc30a62cf38", - notify: true, - read: rf3, - write: wf3, - }, - ], - },]); - - let mut srv = AttributeServer::new(&mut ble, &mut gatt_attributes); - - let counter = RefCell::new(0u8); - let mut notifier = async || { - // TODO how to check if notifications are enabled for the characteristic? - // maybe pass something into the closure which just can query the characterisic value - // probably passing in the attribute server won't work? - pin_ref.borrow_mut().wait_for_rising_edge().await.unwrap(); - let mut data = [0u8; 13]; - data.copy_from_slice(b"Notification0"); - { - let mut counter = counter.borrow_mut(); - data[data.len() - 1] += *counter; - *counter = (*counter + 1) % 10; - } - NotificationData::new(my_characteristic_handle, &data) - }; - - srv.run(&mut notifier).await.unwrap(); - } -} - -static EXECUTOR: StaticCell = StaticCell::new(); - -#[entry] -fn main() -> ! { - #[cfg(feature = "log")] - esp_println::logger::init_logger(log::LevelFilter::Info); - - let peripherals = Peripherals::take(); - - let system = examples_util::system!(peripherals); - let mut peripheral_clock_control = system.peripheral_clock_control; - let clocks = examples_util::clocks!(system); - examples_util::rtc!(peripherals); - - let timer = examples_util::timer!(peripherals, clocks, peripheral_clock_control); - let init = initialize( - EspWifiInitFor::Ble, - timer, - Rng::new(peripherals.RNG), - system.radio_clock_control, - &clocks, - ) - .unwrap(); - - let button = examples_util::boot_button!(peripherals); - - // Async requires the GPIO interrupt to wake futures - hal::interrupt::enable( - hal::peripherals::Interrupt::GPIO, - hal::interrupt::Priority::Priority1, - ) - .unwrap(); - - let bluetooth = examples_util::get_bluetooth!(peripherals); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut peripheral_clock_control); - embassy::init(&clocks, timer_group0.timer0); - let executor = EXECUTOR.init(Executor::new()); - executor.run(|spawner| { - spawner.spawn(run(init, bluetooth, button)).ok(); - }); -} diff --git a/examples-esp32c6/ble.rs b/examples-esp32c6/ble.rs deleted file mode 100644 index ec55bcc8..00000000 --- a/examples-esp32c6/ble.rs +++ /dev/null @@ -1,155 +0,0 @@ -#![no_std] -#![no_main] - -use bleps::{ - ad_structure::{ - create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE, - }, - attribute_server::{AttributeServer, NotificationData, WorkResult}, - gatt, Ble, HciConnector, -}; -use esp_backtrace as _; -use esp_println::println; -use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor}; -use examples_util::hal; -use hal::{ - clock::{ClockControl, CpuClock}, - peripherals::*, - prelude::*, - Rng, Rtc, IO, -}; - -#[entry] -fn main() -> ! { - #[cfg(feature = "log")] - esp_println::logger::init_logger(log::LevelFilter::Info); - - let peripherals = Peripherals::take(); - - let system = examples_util::system!(peripherals); - let mut peripheral_clock_control = system.peripheral_clock_control; - let clocks = examples_util::clocks!(system); - examples_util::rtc!(peripherals); - - let timer = examples_util::timer!(peripherals, clocks, peripheral_clock_control); - let init = initialize( - EspWifiInitFor::Ble, - timer, - Rng::new(peripherals.RNG), - system.radio_clock_control, - &clocks, - ) - .unwrap(); - - let button = examples_util::boot_button!(peripherals); - - let mut debounce_cnt = 500; - - let mut bluetooth = examples_util::get_bluetooth!(peripherals); - - loop { - let connector = BleConnector::new(&init, &mut bluetooth); - let hci = HciConnector::new(connector, esp_wifi::current_millis); - let mut ble = Ble::new(&hci); - - println!("{:?}", ble.init()); - println!("{:?}", ble.cmd_set_le_advertising_parameters()); - println!( - "{:?}", - ble.cmd_set_le_advertising_data( - create_advertising_data(&[ - AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED), - AdStructure::ServiceUuids16(&[Uuid::Uuid16(0x1809)]), - AdStructure::CompleteLocalName(examples_util::SOC_NAME), - ]) - .unwrap() - ) - ); - println!("{:?}", ble.cmd_set_le_advertise_enable(true)); - - println!("started advertising"); - - let mut rf = |_offset: usize, data: &mut [u8]| { - data[..20].copy_from_slice(&b"Hello Bare-Metal BLE"[..]); - 17 - }; - let mut wf = |offset: usize, data: &[u8]| { - println!("RECEIVED: {} {:?}", offset, data); - }; - - let mut wf2 = |offset: usize, data: &[u8]| { - println!("RECEIVED: {} {:?}", offset, data); - }; - - let mut rf3 = |_offset: usize, data: &mut [u8]| { - data[..5].copy_from_slice(&b"Hola!"[..]); - 5 - }; - let mut wf3 = |offset: usize, data: &[u8]| { - println!("RECEIVED: Offset {}, data {:?}", offset, data); - }; - - gatt!([service { - uuid: "937312e0-2354-11eb-9f10-fbc30a62cf38", - characteristics: [ - characteristic { - uuid: "937312e0-2354-11eb-9f10-fbc30a62cf38", - read: rf, - write: wf, - }, - characteristic { - uuid: "957312e0-2354-11eb-9f10-fbc30a62cf38", - write: wf2, - }, - characteristic { - name: "my_characteristic", - uuid: "987312e0-2354-11eb-9f10-fbc30a62cf38", - notify: true, - read: rf3, - write: wf3, - }, - ], - },]); - - let mut srv = AttributeServer::new(&mut ble, &mut gatt_attributes); - - loop { - let mut notification = None; - - if button.is_low().unwrap() && debounce_cnt > 0 { - debounce_cnt -= 1; - if debounce_cnt == 0 { - let mut cccd = [0u8; 1]; - if let Some(1) = srv.get_characteristic_value( - my_characteristic_notify_enable_handle, - 0, - &mut cccd, - ) { - // if notifications enabled - if cccd[0] == 1 { - notification = Some(NotificationData::new( - my_characteristic_handle, - &b"Notification"[..], - )); - } - } - } - }; - - if button.is_high().unwrap() { - debounce_cnt = 500; - } - - match srv.do_work_with_notification(notification) { - Ok(res) => { - if let WorkResult::GotDisconnected = res { - break; - } - } - Err(err) => { - println!("{:?}", err); - } - } - } - } -} diff --git a/examples.md b/examples.md index 43c392f7..4c1f690c 100644 --- a/examples.md +++ b/examples.md @@ -27,17 +27,17 @@ To build these ensure you are in the `examples-esp32XXX` directory matching your - pressing the boot-button on a dev-board will send a notification if it is subscribed - this uses a toy level BLE stack - might not work with every BLE central device (tested with Android and Windows Bluetooth LE Explorer) -`cargo run --example ble --release --features "ble"` +`cargo run --example ble --release --features "ble"` -**NOTE:** ESP32-S2 doesn't support bluetooth, for ESP32-C6 bluetooth support isn't implemented yet +**NOTE:** ESP32-S2 doesn't support bluetooth ### async_ble - same as `ble` but async -`cargo run --example async_ble --release --features "async,ble"` +`cargo run --example async_ble --release --features "async,ble"` -**NOTE:** ESP32-S2 doesn't support bluetooth, for ESP32-C6 bluetooth support isn't implemented yet +**NOTE:** ESP32-S2 doesn't support bluetooth ### coex @@ -61,13 +61,13 @@ To build these ensure you are in the `examples-esp32XXX` directory matching your - broadcasts, receives and sends messages via esp-now in an async way -`cargo run --example embassy_esp_now --release --features "async,esp-now"` +`cargo run --example embassy_esp_now --release --features "async,esp-now"` ### embassy_esp_now_duplex - asynchronously broadcasts, receives and sends messages via esp-now in multiple embassy tasks -`cargo run --example embassy_esp_now_duplex --release --features "async,esp-now"` +`cargo run --example embassy_esp_now_duplex --release --features "async,esp-now"` ### embassy_dhcp