From 008ab2b836a4a10bab963dc061340017ec160672 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 19 Aug 2024 22:05:33 +0200 Subject: [PATCH 01/15] Add integration with bt-hci crate Implementing traits from bt-hci allows the BleConnector to be used with the Trouble BLE stack. --- esp-wifi/CHANGELOG.md | 1 + esp-wifi/Cargo.toml | 3 + esp-wifi/src/ble/controller/mod.rs | 46 +++++++ examples/Cargo.toml | 2 + examples/src/bin/wifi_embassy_trouble.rs | 160 +++++++++++++++++++++++ 5 files changed, 212 insertions(+) create mode 100644 examples/src/bin/wifi_embassy_trouble.rs diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index f57e350d5a3..6c7ff555cc0 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implement `embedded_io::{ReadReady, WriteReady}` traits for `WifiStack` (#1882) - Implement `queue_msg_waiting` on the os_adapter (#1925) - Added API for promiscuous mode (#1935) +- Implement `bt_hci::transport::Transport` traits for BLE (#1933) ### Changed diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 41f9968d07a..fd579e12ff5 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -51,6 +51,7 @@ futures-util = { version = "0.3.30", default-features = false, features = [ atomic-waker = { version = "1.1.2", default-features = false, features = [ "portable-atomic", ] } +bt-hci = { version = "0.1.0", optional = true } [build-dependencies] toml-cfg = "0.2.0" @@ -103,6 +104,8 @@ async = [ "dep:embassy-futures", "dep:embedded-io-async", "dep:esp-hal-embassy", + "dep:bt-hci", + "esp-hal/async", ] embassy-net = ["dep:embassy-net-driver", "async"] diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index 0962330fe3b..cee7ae00ae8 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -83,6 +83,13 @@ impl Write for BleConnector<'_> { pub mod asynch { use core::task::Poll; + use bt_hci::{ + transport::{Transport, WithIndicator}, + ControllerToHostPacket, + FromHciBytes, + HostToControllerPacket, + WriteHci, + }; use embassy_sync::waitqueue::AtomicWaker; use embedded_io::ErrorType; @@ -177,4 +184,43 @@ pub mod asynch { } } } + + impl<'d> Transport for BleConnector<'d> { + /// Read a complete HCI packet into the rx buffer + async fn read<'a>( + &self, + rx: &'a mut [u8], + ) -> Result, Self::Error> { + if !have_hci_read_data() { + HciReadyEventFuture.await; + } + + let mut total = 0; + for b in rx.iter_mut() { + let mut buffer = [0u8]; + let len = read_hci(&mut buffer); + + if len == 1 { + *b = buffer[0]; + total += 1; + } else { + let (p, _) = ControllerToHostPacket::from_hci_bytes(&rx[..total]) + .map_err(|_| BleConnectorError::Unknown)?; + return Ok(p); + } + } + Err(BleConnectorError::Unknown) + } + + /// Write a complete HCI packet from the tx buffer + async fn write(&self, val: &T) -> Result<(), Self::Error> { + let mut buf: [u8; 259] = [0; 259]; + let w = WithIndicator::new(val); + let len = w.size(); + w.write_hci(&mut buf[..]) + .map_err(|_| BleConnectorError::Unknown)?; + send_hci(&buf[..len]); + Ok(()) + } + } } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index b2009458a54..d969c97b4d5 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -9,6 +9,7 @@ publish = false aes = "0.8.4" aligned = { version = "0.4.2", optional = true } bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] } +bt-hci = "0.1.0" cfg-if = "1.0.0" critical-section = "1.1.2" crypto-bigint = { version = "0.5.5", default-features = false } @@ -55,6 +56,7 @@ smart-leds = "0.4.0" smoltcp = { version = "0.11.0", default-features = false, features = [ "medium-ethernet", "socket-raw"] } ssd1306 = "0.8.4" static_cell = { version = "2.1.0", features = ["nightly"] } +trouble-host = { git = "https://github.com/embassy-rs/trouble", package = "trouble-host", rev = "75dc087edde312eb1c2fa49dd57b5c16e00ff26b", features = [ "log", "gatt" ] } usb-device = "0.3.2" usbd-serial = "0.2.2" diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs new file mode 100644 index 00000000000..3145314fd1a --- /dev/null +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -0,0 +1,160 @@ +//! Embassy BLE Example using Trouble +//! +//! - starts Bluetooth advertising +//! - offers a GATT service providing a battery percentage reading +//! - automatically notifies subscribers every second +//! + +//% FEATURES: async embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/ble +//% CHIPS: esp32 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 + +#![no_std] +#![no_main] + +use bt_hci::controller::ExternalController; +use embassy_executor::Spawner; +use embassy_futures::join::join3; +use embassy_sync::blocking_mutex::raw::NoopRawMutex; +use embassy_time::{Duration, Timer}; +use esp_backtrace as _; +use esp_hal::{ + clock::ClockControl, + peripherals::Peripherals, + system::SystemControl, + timer::timg::TimerGroup, +}; +use esp_wifi::ble::controller::asynch::BleConnector; +use log::*; +use static_cell::StaticCell; +use trouble_host::{ + advertise::{AdStructure, Advertisement, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE}, + attribute::{AttributeTable, CharacteristicProp, Service, Uuid}, + Address, + BleHost, + BleHostResources, + PacketQos, +}; + +#[esp_hal_embassy::main] +async fn main(_s: Spawner) { + esp_println::logger::init_logger_from_env(); + let peripherals = Peripherals::take(); + let system = SystemControl::new(peripherals.SYSTEM); + let clocks = ClockControl::max(system.clock_control).freeze(); + + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + + let init = esp_wifi::initialize( + esp_wifi::EspWifiInitFor::Ble, + timg0.timer0, + esp_hal::rng::Rng::new(peripherals.RNG), + peripherals.RADIO_CLK, + &clocks, + ) + .unwrap(); + + #[cfg(feature = "esp32")] + { + let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); + esp_hal_embassy::init(&clocks, timg1.timer0); + } + + #[cfg(not(feature = "esp32"))] + { + let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) + .split::(); + esp_hal_embassy::init(&clocks, systimer.alarm0); + } + + let mut bluetooth = peripherals.BT; + let connector = BleConnector::new(&init, &mut bluetooth); + let controller: ExternalController<_, 20> = ExternalController::new(connector); + + static HOST_RESOURCES: StaticCell> = StaticCell::new(); + let host_resources = HOST_RESOURCES.init(BleHostResources::new(PacketQos::None)); + + let mut ble: BleHost<'_, _> = BleHost::new(controller, host_resources); + + ble.set_random_address(Address::random([0xff, 0x9f, 0x1a, 0x05, 0xe4, 0xff])); + let mut table: AttributeTable<'_, NoopRawMutex, 10> = AttributeTable::new(); + + let id = b"Trouble ESP32"; + let appearance = [0x80, 0x07]; + let mut bat_level = [0; 1]; + // Generic Access Service (mandatory) + let mut svc = table.add_service(Service::new(0x1800)); + let _ = svc.add_characteristic_ro(0x2a00, id); + let _ = svc.add_characteristic_ro(0x2a01, &appearance[..]); + svc.build(); + + // Generic attribute service (mandatory) + table.add_service(Service::new(0x1801)); + + // Battery service + let bat_level_handle = table + .add_service(Service::new(0x180f)) + .add_characteristic( + 0x2a19, + &[CharacteristicProp::Read, CharacteristicProp::Notify], + &mut bat_level, + ) + .build(); + + let mut adv_data = [0; 31]; + AdStructure::encode_slice( + &[ + AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED), + AdStructure::ServiceUuids16(&[Uuid::Uuid16([0x0f, 0x18])]), + AdStructure::CompleteLocalName(b"Trouble ESP32"), + ], + &mut adv_data[..], + ) + .unwrap(); + + let server = ble.gatt_server(&table); + + info!("Starting advertising and GATT service"); + // Run all 3 tasks in a join. They can also be separate embassy tasks. + let _ = join3( + // Runs the BLE host task + ble.run(), + // Processing events from GATT server (if an attribute was written) + async { + loop { + match server.next().await { + Ok(_event) => { + info!("Gatt event!"); + } + Err(e) => { + warn!("Error processing GATT events: {:?}", e); + } + } + } + }, + // Advertise our presence to the world. + async { + let mut advertiser = ble + .advertise( + &Default::default(), + Advertisement::ConnectableScannableUndirected { + adv_data: &adv_data[..], + scan_data: &[], + }, + ) + .await + .unwrap(); + let conn = advertiser.accept().await.unwrap(); + // Keep connection alive and notify with value change + let mut tick: u8 = 0; + loop { + Timer::after(Duration::from_secs(10)).await; + tick += 1; + server + .notify(bat_level_handle, &conn, &[tick]) + .await + .unwrap(); + } + }, + ) + .await; +} From ac12453d5c48767b9ff2f9c0915d644a0bfa1d74 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sat, 24 Aug 2024 15:15:24 +0200 Subject: [PATCH 02/15] use packed based read interface --- esp-wifi/src/ble/controller/mod.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index cee7ae00ae8..f77ac9197ad 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -195,21 +195,10 @@ pub mod asynch { HciReadyEventFuture.await; } - let mut total = 0; - for b in rx.iter_mut() { - let mut buffer = [0u8]; - let len = read_hci(&mut buffer); - - if len == 1 { - *b = buffer[0]; - total += 1; - } else { - let (p, _) = ControllerToHostPacket::from_hci_bytes(&rx[..total]) - .map_err(|_| BleConnectorError::Unknown)?; - return Ok(p); - } - } - Err(BleConnectorError::Unknown) + let len = crate::ble::read_next(rx); + let p = ControllerToHostPacket::from_hci_bytes_complete(&rx[..len]) + .map_err(|_| BleConnectorError::Unknown)?; + Ok(p) } /// Write a complete HCI packet from the tx buffer From cb39ced674ee4af24bf6f197fb0841713d60f56a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sat, 24 Aug 2024 15:20:15 +0200 Subject: [PATCH 03/15] Improve example to allow another connection after disconnect --- examples/src/bin/wifi_embassy_trouble.rs | 39 +++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index 3145314fd1a..d5ae8616471 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -133,26 +133,31 @@ async fn main(_s: Spawner) { }, // Advertise our presence to the world. async { - let mut advertiser = ble - .advertise( - &Default::default(), - Advertisement::ConnectableScannableUndirected { - adv_data: &adv_data[..], - scan_data: &[], - }, - ) - .await - .unwrap(); - let conn = advertiser.accept().await.unwrap(); - // Keep connection alive and notify with value change - let mut tick: u8 = 0; loop { - Timer::after(Duration::from_secs(10)).await; - tick += 1; - server - .notify(bat_level_handle, &conn, &[tick]) + let mut advertiser = ble + .advertise( + &Default::default(), + Advertisement::ConnectableScannableUndirected { + adv_data: &adv_data[..], + scan_data: &[], + }, + ) .await .unwrap(); + let conn = advertiser.accept().await.unwrap(); + // Keep connection alive and notify with value change + let mut tick: u8 = 0; + loop { + if !conn.is_connected() { + break; + } + Timer::after(Duration::from_secs(1)).await; + tick = tick.wrapping_add(1); + server + .notify(bat_level_handle, &conn, &[tick]) + .await + .unwrap(); + } } }, ) From a59e38f23cdeb085b5cd8e05680ad08fe14ed4b0 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 26 Aug 2024 18:40:22 +0200 Subject: [PATCH 04/15] update trouble version --- examples/Cargo.toml | 2 +- examples/src/bin/wifi_embassy_trouble.rs | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d969c97b4d5..eeb9e384ac2 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -56,7 +56,7 @@ smart-leds = "0.4.0" smoltcp = { version = "0.11.0", default-features = false, features = [ "medium-ethernet", "socket-raw"] } ssd1306 = "0.8.4" static_cell = { version = "2.1.0", features = ["nightly"] } -trouble-host = { git = "https://github.com/embassy-rs/trouble", package = "trouble-host", rev = "75dc087edde312eb1c2fa49dd57b5c16e00ff26b", features = [ "log", "gatt" ] } +trouble-host = { git = "https://github.com/embassy-rs/trouble", package = "trouble-host", rev = "4f1114ce58e96fe54f5ed7e726f66e1ad8d9ce54", features = [ "log", "gatt" ] } usb-device = "0.3.2" usbd-serial = "0.2.2" diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index d5ae8616471..3f59bd7bf0f 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -91,14 +91,11 @@ async fn main(_s: Spawner) { table.add_service(Service::new(0x1801)); // Battery service - let bat_level_handle = table - .add_service(Service::new(0x180f)) - .add_characteristic( - 0x2a19, - &[CharacteristicProp::Read, CharacteristicProp::Notify], - &mut bat_level, - ) - .build(); + let bat_level_handle = table.add_service(Service::new(0x180f)).add_characteristic( + 0x2a19, + &[CharacteristicProp::Read, CharacteristicProp::Notify], + &mut bat_level, + ); let mut adv_data = [0; 31]; AdStructure::encode_slice( @@ -111,7 +108,7 @@ async fn main(_s: Spawner) { ) .unwrap(); - let server = ble.gatt_server(&table); + let server = ble.gatt_server::(&table); info!("Starting advertising and GATT service"); // Run all 3 tasks in a join. They can also be separate embassy tasks. @@ -154,7 +151,7 @@ async fn main(_s: Spawner) { Timer::after(Duration::from_secs(1)).await; tick = tick.wrapping_add(1); server - .notify(bat_level_handle, &conn, &[tick]) + .notify(&ble, bat_level_handle, &conn, &[tick]) .await .unwrap(); } From 3c773a93593600c1d055d90065bd630e600804b2 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 28 Aug 2024 10:21:42 +0200 Subject: [PATCH 05/15] Workaround for spurious command complete events --- esp-wifi/src/ble/controller/mod.rs | 47 +++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index f77ac9197ad..5200fa8f948 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -185,20 +185,53 @@ pub mod asynch { } } + fn parse_hci<'m>( + data: &'m [u8], + ) -> Result>, BleConnectorError> { + match ControllerToHostPacket::from_hci_bytes_complete(data) { + Ok(p) => Ok(Some(p)), + Err(e) => { + if e == bt_hci::FromHciBytesError::InvalidSize { + use bt_hci::{event::EventPacketHeader, PacketKind}; + + // Some controllers emit a suprious command complete event at startup. + let (kind, data) = + PacketKind::from_hci_bytes(data).map_err(|_| BleConnectorError::Unknown)?; + if kind == PacketKind::Event { + let (header, _) = EventPacketHeader::from_hci_bytes(data) + .map_err(|_| BleConnectorError::Unknown)?; + const COMMAND_COMPLETE: u8 = 0x0E; + if header.code == COMMAND_COMPLETE && header.params_len < 4 { + return Ok(None); + } + } + } + warn!("[hci] error parsing packet: {:?}", e); + Err(BleConnectorError::Unknown) + } + } + } + impl<'d> Transport for BleConnector<'d> { /// Read a complete HCI packet into the rx buffer async fn read<'a>( &self, rx: &'a mut [u8], ) -> Result, Self::Error> { - if !have_hci_read_data() { - HciReadyEventFuture.await; - } + loop { + if !have_hci_read_data() { + HciReadyEventFuture.await; + } - let len = crate::ble::read_next(rx); - let p = ControllerToHostPacket::from_hci_bytes_complete(&rx[..len]) - .map_err(|_| BleConnectorError::Unknown)?; - Ok(p) + // Workaround for borrow checker. + // Safety: we only return a reference to x once, if parsing is successful. + let rx = unsafe { &mut *core::ptr::slice_from_raw_parts_mut(rx.as_mut_ptr(), rx.len()) }; + + let len = crate::ble::read_next(rx); + if let Some(packet) = parse_hci(&rx[..len])? { + return Ok(packet); + } + } } /// Write a complete HCI packet from the tx buffer From 2bb8f45b1ae687f597f5b499bd83ba4cc825f74a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 28 Aug 2024 11:55:48 +0200 Subject: [PATCH 06/15] fix formatting --- esp-wifi/src/ble/controller/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index 5200fa8f948..ed9f56ca488 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -225,7 +225,8 @@ pub mod asynch { // Workaround for borrow checker. // Safety: we only return a reference to x once, if parsing is successful. - let rx = unsafe { &mut *core::ptr::slice_from_raw_parts_mut(rx.as_mut_ptr(), rx.len()) }; + let rx = + unsafe { &mut *core::ptr::slice_from_raw_parts_mut(rx.as_mut_ptr(), rx.len()) }; let len = crate::ble::read_next(rx); if let Some(packet) = parse_hci(&rx[..len])? { From 639e8b18331def41d04f707f4f5c2f1380d3dc40 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 28 Aug 2024 11:55:52 +0200 Subject: [PATCH 07/15] ignore notify errors in example --- examples/src/bin/wifi_embassy_trouble.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index 3f59bd7bf0f..22b6b82bf2f 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -153,7 +153,7 @@ async fn main(_s: Spawner) { server .notify(&ble, bat_level_handle, &conn, &[tick]) .await - .unwrap(); + .ok(); } } }, From c49c0ee9627fbce88010db7479ee7b00f6ecd537 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 28 Aug 2024 14:47:14 +0200 Subject: [PATCH 08/15] fix clippy warnings --- esp-wifi/src/ble/controller/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index ed9f56ca488..45eb991e31b 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -185,9 +185,7 @@ pub mod asynch { } } - fn parse_hci<'m>( - data: &'m [u8], - ) -> Result>, BleConnectorError> { + fn parse_hci(data: &[u8]) -> Result>, BleConnectorError> { match ControllerToHostPacket::from_hci_bytes_complete(data) { Ok(p) => Ok(Some(p)), Err(e) => { From cc7c25e7dcec11dc058c47c496e0dd90818e4681 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 5 Sep 2024 14:51:13 +0200 Subject: [PATCH 09/15] remove async feature from hal dependency --- esp-wifi/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index fd579e12ff5..8253fefece7 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -105,7 +105,6 @@ async = [ "dep:embedded-io-async", "dep:esp-hal-embassy", "dep:bt-hci", - "esp-hal/async", ] embassy-net = ["dep:embassy-net-driver", "async"] From c8caf322514b3a153ddd3596b6f381fea854faf6 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 5 Sep 2024 15:11:19 +0200 Subject: [PATCH 10/15] remove deprecated feature from example --- examples/src/bin/wifi_embassy_trouble.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index 22b6b82bf2f..c6989e7a892 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -5,7 +5,7 @@ //! - automatically notifies subscribers every second //! -//% FEATURES: async embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/ble +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/ble //% CHIPS: esp32 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 #![no_std] From f68b408bc7a4a74fa7b71963de735b25de6e26c4 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 5 Sep 2024 15:16:15 +0200 Subject: [PATCH 11/15] Adopt to api changes --- examples/src/bin/wifi_embassy_trouble.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index c6989e7a892..a1ea4e0096a 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -17,12 +17,7 @@ use embassy_futures::join::join3; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - peripherals::Peripherals, - system::SystemControl, - timer::timg::TimerGroup, -}; +use esp_hal::{prelude::*, timer::timg::TimerGroup}; use esp_wifi::ble::controller::asynch::BleConnector; use log::*; use static_cell::StaticCell; @@ -38,32 +33,32 @@ use trouble_host::{ #[esp_hal_embassy::main] async fn main(_s: Spawner) { esp_println::logger::init_logger_from_env(); - let peripherals = Peripherals::take(); - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); - - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let peripherals = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); + let timg0 = TimerGroup::new(peripherals.TIMG0); let init = esp_wifi::initialize( esp_wifi::EspWifiInitFor::Ble, timg0.timer0, esp_hal::rng::Rng::new(peripherals.RNG), peripherals.RADIO_CLK, - &clocks, ) .unwrap(); #[cfg(feature = "esp32")] { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); - esp_hal_embassy::init(&clocks, timg1.timer0); + esp_hal_embassy::init(timg1.timer0); } #[cfg(not(feature = "esp32"))] { let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) .split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); } let mut bluetooth = peripherals.BT; From 821048c52f6846bcb2247c4a0bd2a495d53f8eaa Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 5 Sep 2024 15:54:59 +0200 Subject: [PATCH 12/15] Api fix for esp32 --- examples/src/bin/wifi_embassy_trouble.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index a1ea4e0096a..ce71add3f70 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -50,7 +50,7 @@ async fn main(_s: Spawner) { #[cfg(feature = "esp32")] { - let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); + let timg1 = TimerGroup::new(peripherals.TIMG1); esp_hal_embassy::init(timg1.timer0); } From dcb0f1984a6ee8d332c67f110cd0233a216a64bf Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 5 Sep 2024 15:58:10 +0200 Subject: [PATCH 13/15] Set rust-version of esp-wifi --- esp-wifi/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 8253fefece7..0224e57b26f 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -2,6 +2,7 @@ name = "esp-wifi" version = "0.9.1" edition = "2021" +rust-version = "1.77.0" authors = ["The ESP-RS team"] description = "A WiFi, Bluetooth and ESP-NOW driver for use with Espressif chips and bare-metal Rust" repository = "https://github.com/esp-rs/esp-hal" From 46402f4b00736cf839ea07d7b3aca7728d6ba272 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 6 Sep 2024 08:44:05 +0200 Subject: [PATCH 14/15] bump MSRV to 1.77 for CI and esp-hal --- .github/workflows/ci.yml | 2 +- esp-hal/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd388c03ff4..683e4ceebf6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ on: env: CARGO_TERM_COLOR: always GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MSRV: "1.76.0" + MSRV: "1.77.0" RUSTDOCFLAGS: -Dwarnings # Cancel any currently running workflows from the same PR, branch, or diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index c935dfd4845..ce9ba0ec8ff 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -2,7 +2,7 @@ name = "esp-hal" version = "0.20.1" edition = "2021" -rust-version = "1.76.0" +rust-version = "1.77.0" description = "Bare-metal HAL for Espressif devices" documentation = "https://docs.esp-rs.org/esp-hal/" repository = "https://github.com/esp-rs/esp-hal" From cbaee281951dfa0fc53924697273f77e3251039e Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 6 Sep 2024 09:15:59 +0200 Subject: [PATCH 15/15] Add changelog entry --- esp-hal/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 6d32881603b..1624d89995d 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Bump MSRV to 1.77.0 (#1971) + ### Added - Implement `embedded-hal` output pin traits for `DummyPin` (#2019)