Skip to content

Commit

Permalink
chore: move to rust edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Feb 25, 2025
1 parent b6694cf commit 3c8d15c
Show file tree
Hide file tree
Showing 28 changed files with 102 additions and 110 deletions.
2 changes: 1 addition & 1 deletion examples/apache-nimble/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-apache-nimble-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
defmt = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-example-apps"
version = "0.1.0"
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions examples/esp32/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-esp32-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
Expand Down Expand Up @@ -45,4 +45,4 @@ esp-backtrace = {git = "https://github.com/esp-rs/esp-hal.git", rev = "5d0145eca
esp-hal = {git = "https://github.com/esp-rs/esp-hal.git", rev = "5d0145eca901f42cbebe1e41cde10e79afba3af8"}
esp-hal-embassy = {git = "https://github.com/esp-rs/esp-hal.git", rev = "5d0145eca901f42cbebe1e41cde10e79afba3af8"}
esp-alloc = {git = "https://github.com/esp-rs/esp-hal.git", rev = "5d0145eca901f42cbebe1e41cde10e79afba3af8"}
esp-println = {git = "https://github.com/esp-rs/esp-hal.git", rev = "5d0145eca901f42cbebe1e41cde10e79afba3af8"}
esp-println = {git = "https://github.com/esp-rs/esp-hal.git", rev = "5d0145eca901f42cbebe1e41cde10e79afba3af8"}
2 changes: 1 addition & 1 deletion examples/nrf-sdc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-nrf-sdc-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"
resolver = "2"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/rp-pico-2-w/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-rp23-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"
resolver = "2"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/rp-pico-w/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-rp-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"
resolver = "2"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/serial-hci/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "serial-hci"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
env_logger = "0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-example-tests"
version = "0.1.0"
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion host-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-host-macros"
version = "0.1.0"
edition = "2021"
edition = "2024"
license = "Apache-2.0 OR MIT"
description = "An async Rust BLE host - Derive macros crate"
keywords = ["no-std"]
Expand Down
2 changes: 1 addition & 1 deletion host/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "trouble-host"
version = "0.1.0"
edition = "2021"
edition = "2024"
description = "An async Rust BLE host"
license = "Apache-2.0 OR MIT"
keywords = ["no-std"]
Expand Down
1 change: 1 addition & 0 deletions host/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn main() {

// only rebuild if build.rs changed. Otherwise Cargo will rebuild if any
// other file changed.
println!("cargo::rustc-check-cfg=cfg(test)");
println!("cargo:rerun-if-changed=build.rs");

// Rebuild if config envvar changed.
Expand Down
22 changes: 12 additions & 10 deletions host/src/advertise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use embassy_time::Duration;

use crate::cursor::{ReadCursor, WriteCursor};
use crate::types::uuid::Uuid;
use crate::{codec, Address};
use crate::{Address, codec};

/// Transmit power levels.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down Expand Up @@ -513,14 +513,16 @@ mod tests {
#[test]
fn adv_name_truncate() {
let mut adv_data = [0; 31];
assert!(AdStructure::encode_slice(
&[
AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED),
AdStructure::ServiceUuids16(&[Uuid::Uuid16([0x0f, 0x18])]),
AdStructure::CompleteLocalName(b"12345678901234567890123"),
],
&mut adv_data[..],
)
.is_err());
assert!(
AdStructure::encode_slice(
&[
AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED),
AdStructure::ServiceUuids16(&[Uuid::Uuid16([0x0f, 0x18])]),
AdStructure::CompleteLocalName(b"12345678901234567890123"),
],
&mut adv_data[..],
)
.is_err()
);
}
}
6 changes: 3 additions & 3 deletions host/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use core::marker::PhantomData;

use bt_hci::uuid::declarations::{CHARACTERISTIC, PRIMARY_SERVICE};
use bt_hci::uuid::descriptors::CLIENT_CHARACTERISTIC_CONFIGURATION;
use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_sync::blocking_mutex::Mutex;
use embassy_sync::blocking_mutex::raw::RawMutex;
use heapless::Vec;

use crate::Error;
use crate::att::AttErrorCode;
use crate::attribute_server::AttributeServer;
use crate::cursor::{ReadCursor, WriteCursor};
use crate::prelude::Connection;
use crate::types::gatt_traits::{AsGatt, FromGatt};
pub use crate::types::uuid::Uuid;
use crate::Error;
use heapless::Vec;

/// Characteristic properties
#[derive(Debug, Clone, Copy)]
Expand Down
10 changes: 3 additions & 7 deletions host/src/attribute_server.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use core::cell::RefCell;

use bt_hci::param::ConnHandle;
use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_sync::blocking_mutex::Mutex;
use embassy_sync::blocking_mutex::raw::RawMutex;

use crate::att::{self, AttClient, AttCmd, AttErrorCode, AttReq};
use crate::attribute::{AttributeData, AttributeTable};
use crate::cursor::WriteCursor;
use crate::prelude::Connection;
use crate::types::uuid::Uuid;
use crate::{codec, Error};
use crate::{Error, codec};

const MAX_NOTIFICATIONS: usize = 4;
pub(crate) struct NotificationTable<const ENTRIES: usize> {
Expand Down Expand Up @@ -495,11 +495,7 @@ impl<'values, M: RawMutex, const MAX: usize> AttributeServer<'values, M, MAX> {

AttClient::Confirmation(_) => 0,
};
if len > 0 {
Ok(Some(len))
} else {
Ok(None)
}
if len > 0 { Ok(Some(len)) } else { Ok(None) }
}

/// Get a reference to the attribute table
Expand Down
7 changes: 4 additions & 3 deletions host/src/central.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Functionality for the BLE central role.
use crate::connection::{ConnectConfig, Connection, PhySet};
use crate::{BleHostError, Error, Stack};
use bt_hci::cmd::le::{LeAddDeviceToFilterAcceptList, LeClearFilterAcceptList, LeCreateConn, LeExtCreateConn};
use bt_hci::controller::{Controller, ControllerCmdAsync, ControllerCmdSync};
use bt_hci::param::{AddrKind, BdAddr, InitiatingPhy, LeConnRole, PhyParams};
#[cfg(feature = "controller-host-flow-control")]
use bt_hci::param::{ConnHandleCompletedPackets, ControllerToHostFlowControl};
use embassy_futures::select::{select, Either};
use embassy_futures::select::{Either, select};

use crate::connection::{ConnectConfig, Connection, PhySet};
use crate::{BleHostError, Error, Stack};

/// A type implementing the BLE central role.
pub struct Central<'stack, C> {
Expand Down
14 changes: 6 additions & 8 deletions host/src/channel_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use core::cell::RefCell;
use core::future::poll_fn;
use core::task::{Context, Poll};

use bt_hci::controller::{blocking, Controller};
use bt_hci::param::ConnHandle;
use bt_hci::FromHciBytes;
use bt_hci::controller::{Controller, blocking};
use bt_hci::param::ConnHandle;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_sync::channel::Channel;
use embassy_sync::waitqueue::WakerRegistration;
Expand All @@ -18,7 +18,7 @@ use crate::types::l2cap::{
CommandRejectRes, ConnParamUpdateReq, ConnParamUpdateRes, DisconnectionReq, DisconnectionRes, L2capHeader,
L2capSignalCode, L2capSignalHeader, LeCreditConnReq, LeCreditConnRes, LeCreditConnResultCode, LeCreditFlowInd,
};
use crate::{config, BleHostError, Error};
use crate::{BleHostError, Error, config};

const BASE_ID: u16 = 0x40;

Expand Down Expand Up @@ -371,16 +371,14 @@ impl<'d> ChannelManager<'d> {
let req = ConnParamUpdateReq::from_hci_bytes_complete(data)?;
trace!(
"[l2cap][conn = {:?}] connection param update request: {:?}, ignored",
conn,
req
conn, req
);
}
L2capSignalCode::ConnParamUpdateRes => {
let res = ConnParamUpdateRes::from_hci_bytes_complete(data)?;
trace!(
"[l2cap][conn = {:?}] connection param update response: {}",
conn,
res.result,
conn, res.result,
);
}
r => {
Expand Down Expand Up @@ -1011,8 +1009,8 @@ mod tests {
use bt_hci::param::{AddrKind, BdAddr, LeConnRole, Status};

use super::*;
use crate::mock_controller::MockController;
use crate::HostResources;
use crate::mock_controller::MockController;

#[test]
fn channel_refcount() {
Expand Down
8 changes: 3 additions & 5 deletions host/src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::connection::{Connection, ConnectionEventData};
#[cfg(feature = "gatt")]
use crate::packet_pool::{Packet, Pool};
use crate::pdu::Pdu;
use crate::{config, Error};
use crate::{Error, config};

struct State<'d> {
connections: &'d mut [ConnectionStorage],
Expand Down Expand Up @@ -314,8 +314,7 @@ impl<'d> ConnectionManager<'d> {
storage.state = ConnectionState::Connected;
trace!(
"[link][poll_accept] connection handle {:?} in role {:?} accepted",
handle,
role
handle, role
);
assert_eq!(storage.refcount, 0);
state.inc_ref(idx as u8);
Expand All @@ -327,8 +326,7 @@ impl<'d> ConnectionManager<'d> {
assert_eq!(storage.refcount, 0);
trace!(
"[link][poll_accept] connection handle {:?} in role {:?} accepted",
handle,
role
handle, role
);

assert_eq!(storage.refcount, 0);
Expand Down
9 changes: 4 additions & 5 deletions host/src/gatt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ use bt_hci::controller::Controller;
use bt_hci::param::ConnHandle;
use bt_hci::uuid::declarations::{CHARACTERISTIC, PRIMARY_SERVICE};
use bt_hci::uuid::descriptors::CLIENT_CHARACTERISTIC_CONFIGURATION;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_sync::blocking_mutex::raw::{NoopRawMutex, RawMutex};
use embassy_sync::channel::{Channel, DynamicReceiver};
use embassy_sync::pubsub::{self, PubSubChannel, WaitResult};
use heapless::Vec;

use crate::att::{self, Att, AttClient, AttCmd, AttReq, AttRsp, AttServer, AttUns, ATT_HANDLE_VALUE_NTF};
use crate::attribute::{AttributeData, Characteristic, CharacteristicProp, Uuid, CCCD};
use crate::att::{self, ATT_HANDLE_VALUE_NTF, Att, AttClient, AttCmd, AttReq, AttRsp, AttServer, AttUns};
use crate::attribute::{AttributeData, CCCD, Characteristic, CharacteristicProp, Uuid};
use crate::attribute_server::{AttributeServer, DynamicAttributeServer};
use crate::connection::Connection;
use crate::cursor::{ReadCursor, WriteCursor};
use crate::pdu::Pdu;
use crate::types::gatt_traits::{AsGatt, FromGatt, FromGattError};
use crate::types::l2cap::L2capHeader;
use crate::{config, BleHostError, Error, Stack};
use crate::{BleHostError, Error, Stack, config};

/// A GATT payload ready for processing.
pub struct GattData<'stack> {
Expand Down
14 changes: 6 additions & 8 deletions host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bt_hci::cmd::le::{
};
use bt_hci::cmd::link_control::Disconnect;
use bt_hci::cmd::{AsyncCmd, SyncCmd};
use bt_hci::controller::{blocking, Controller, ControllerCmdAsync, ControllerCmdSync};
use bt_hci::controller::{Controller, ControllerCmdAsync, ControllerCmdSync, blocking};
use bt_hci::data::{AclBroadcastFlag, AclPacket, AclPacketBoundary};
use bt_hci::event::le::LeEvent;
use bt_hci::event::{Event, Vendor};
Expand All @@ -26,7 +26,7 @@ use bt_hci::param::{
#[cfg(feature = "controller-host-flow-control")]
use bt_hci::param::{ConnHandleCompletedPackets, ControllerToHostFlowControl};
use bt_hci::{ControllerToHostPacket, FromHciBytes, WriteHci};
use embassy_futures::select::{select3, Either3};
use embassy_futures::select::{Either3, select3};
use embassy_sync::once_lock::OnceLock;
use embassy_sync::waitqueue::WakerRegistration;
#[cfg(feature = "gatt")]
Expand All @@ -44,9 +44,9 @@ use crate::l2cap::sar::{PacketReassembly, SarType};
use crate::packet_pool::Pool;
use crate::pdu::Pdu;
use crate::types::l2cap::{
L2capHeader, L2capSignal, L2capSignalHeader, L2CAP_CID_ATT, L2CAP_CID_DYN_START, L2CAP_CID_LE_U_SIGNAL,
L2CAP_CID_ATT, L2CAP_CID_DYN_START, L2CAP_CID_LE_U_SIGNAL, L2capHeader, L2capSignal, L2capSignalHeader,
};
use crate::{att, config, Address, BleHostError, Error, Stack};
use crate::{Address, BleHostError, Error, Stack, att, config};

/// A BLE Host.
///
Expand Down Expand Up @@ -266,15 +266,13 @@ where
#[cfg(feature = "defmt")]
trace!(
"[host] connection with handle {:?} established to {:02x}",
handle,
peer_addr
handle, peer_addr
);

#[cfg(feature = "log")]
trace!(
"[host] connection with handle {:?} established to {:02x?}",
handle,
peer_addr
handle, peer_addr
);
let mut m = self.metrics.borrow_mut();
m.connect_events = m.connect_events.wrapping_add(1);
Expand Down
2 changes: 1 addition & 1 deletion host/src/l2cap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! L2CAP channels.
use bt_hci::controller::{blocking, Controller};
use bt_hci::controller::{Controller, blocking};

pub use crate::channel_manager::CreditFlowPolicy;
use crate::channel_manager::{ChannelIndex, DynamicChannelManager};
Expand Down
2 changes: 1 addition & 1 deletion host/src/l2cap/sar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use core::cell::RefCell;

use bt_hci::param::ConnHandle;

use crate::Error;
use crate::packet_pool::Packet;
use crate::types::l2cap::L2capHeader;
use crate::Error;

pub(crate) struct AssembledPacket {
packet: Packet,
Expand Down
Loading

0 comments on commit 3c8d15c

Please sign in to comment.