From 5673352eb39009dd6afd7eb69b0cd0b9140242b3 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 3 May 2024 15:56:26 +0200 Subject: [PATCH 1/7] Add try* variants of traits for controllers that support non-blocking operation --- src/cmd.rs | 14 +++++++++++++ src/controller.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index a09695a..69d66b0 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -115,6 +115,13 @@ pub trait AsyncCmd: Cmd { ) -> impl Future::Error>>> { controller.exec(self) } + + fn try_exec>( + &self, + controller: &C, + ) -> Result<(), TryError::Error>>> { + controller.try_exec(self) + } } pub trait CmdReturnBuf: Copy + AsRef<[u8]> + AsMut<[u8]> { @@ -158,6 +165,13 @@ pub trait SyncCmd: Cmd { ) -> impl Future::Error>>> { controller.exec(self) } + + fn try_exec>( + &self, + controller: &C, + ) -> Result::Error>>> { + controller.try_exec(self) + } } #[doc(hidden)] diff --git a/src/controller.rs b/src/controller.rs index 7b14598..7a512de 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -17,9 +17,11 @@ use crate::param::{RemainingBytes, Status}; use crate::transport::Transport; use crate::{cmd, data, ControllerToHostPacket, FixedSizeValue, FromHciBytes, HostToControllerPacket}; -pub trait Controller { +pub trait ErrorType { type Error: embedded_io::Error; +} +pub trait Controller: ErrorType { fn write_acl_data(&self, packet: &data::AclPacket) -> impl Future>; fn write_sync_data(&self, packet: &data::SyncPacket) -> impl Future>; fn write_iso_data(&self, packet: &data::IsoPacket) -> impl Future>; @@ -27,6 +29,36 @@ pub trait Controller { fn read<'a>(&self, buf: &'a mut [u8]) -> impl Future, Self::Error>>; } +pub trait TryController: ErrorType { + fn try_write_acl_data(&self, packet: &data::AclPacket) -> Result<(), TryError>; + fn try_write_sync_data(&self, packet: &data::SyncPacket) -> Result<(), TryError>; + fn try_write_iso_data(&self, packet: &data::IsoPacket) -> Result<(), TryError>; + + fn try_read<'a>(&self, buf: &'a mut [u8]) -> Result, TryError>; +} + +/// An error type for Bluetooth HCI commands. +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum CmdError { + Hci(param::Error), + Io(E), +} + +/// An error type for try operations. +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum TryError { + Error(E), + Busy, +} + +impl From for CmdError { + fn from(e: param::Error) -> Self { + Self::Hci(e) + } +} + pub trait ControllerCmdSync: Controller { /// Note: Some implementations may require [`Controller::read()`] to be polled for this to return. fn exec(&self, cmd: &C) -> impl Future>>; @@ -38,6 +70,15 @@ pub trait ControllerCmdAsync: Controller { } /// An external [`Controller`] with communication via [`Transport`] type `T`. +pub trait TryControllerCmdSync: TryController { + fn try_exec(&self, cmd: &C) -> Result>>; +} + +pub trait TryControllerCmdAsync: TryController { + fn try_exec(&self, cmd: &C) -> Result<(), TryError>>; +} + +/// An external Bluetooth controller with communication via [`Transport`] type `T`. /// /// The controller state holds a number of command slots that can be used /// to issue commands and await responses from an underlying controller. @@ -68,11 +109,17 @@ where } } -impl Controller for ExternalController +impl ErrorType for ExternalController where T: Transport, { type Error = T::Error; +} + +impl Controller for ExternalController +where + T: Transport, +{ async fn write_acl_data(&self, packet: &data::AclPacket<'_>) -> Result<(), Self::Error> { self.write(packet).await?; Ok(()) From 4a70bdcd0d81b95f883627f0be2b74576ad0e72f Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sat, 4 May 2024 20:24:12 +0200 Subject: [PATCH 2/7] move traits to blocking module --- src/cmd.rs | 16 ++++++++-------- src/controller.rs | 17 ++--------------- src/controller/blocking.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 src/controller/blocking.rs diff --git a/src/cmd.rs b/src/cmd.rs index 69d66b0..7044a0d 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -2,8 +2,8 @@ use core::future::Future; -use crate::controller::{Controller, ControllerCmdAsync, ControllerCmdSync}; -use crate::param::{self, param}; +use crate::controller::{blocking, CmdError, ControllerCmdAsync, ControllerCmdSync, ErrorType}; +use crate::param::param; use crate::{FixedSizeValue, FromHciBytes, HostToControllerPacket, PacketKind, WriteHci}; pub mod controller_baseband; @@ -116,11 +116,11 @@ pub trait AsyncCmd: Cmd { controller.exec(self) } - fn try_exec>( + fn exec_blocking>( &self, controller: &C, - ) -> Result<(), TryError::Error>>> { - controller.try_exec(self) + ) -> Result<(), blocking::TryError::Error>>> { + controller.exec(self) } } @@ -166,11 +166,11 @@ pub trait SyncCmd: Cmd { controller.exec(self) } - fn try_exec>( + fn exec_blocking>( &self, controller: &C, - ) -> Result::Error>>> { - controller.try_exec(self) + ) -> Result::Error>>> { + controller.exec(self) } } diff --git a/src/controller.rs b/src/controller.rs index 7a512de..fe14bda 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -17,6 +17,8 @@ use crate::param::{RemainingBytes, Status}; use crate::transport::Transport; use crate::{cmd, data, ControllerToHostPacket, FixedSizeValue, FromHciBytes, HostToControllerPacket}; +pub mod blocking; + pub trait ErrorType { type Error: embedded_io::Error; } @@ -29,14 +31,6 @@ pub trait Controller: ErrorType { fn read<'a>(&self, buf: &'a mut [u8]) -> impl Future, Self::Error>>; } -pub trait TryController: ErrorType { - fn try_write_acl_data(&self, packet: &data::AclPacket) -> Result<(), TryError>; - fn try_write_sync_data(&self, packet: &data::SyncPacket) -> Result<(), TryError>; - fn try_write_iso_data(&self, packet: &data::IsoPacket) -> Result<(), TryError>; - - fn try_read<'a>(&self, buf: &'a mut [u8]) -> Result, TryError>; -} - /// An error type for Bluetooth HCI commands. #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -46,13 +40,6 @@ pub enum CmdError { } /// An error type for try operations. -#[derive(Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum TryError { - Error(E), - Busy, -} - impl From for CmdError { fn from(e: param::Error) -> Self { Self::Hci(e) diff --git a/src/controller/blocking.rs b/src/controller/blocking.rs new file mode 100644 index 0000000..8c02cf0 --- /dev/null +++ b/src/controller/blocking.rs @@ -0,0 +1,33 @@ +use crate::{ + cmd, + controller::{CmdError, ErrorType}, + data, ControllerToHostPacket, +}; + +pub trait Controller: ErrorType { + fn write_acl_data(&self, packet: &data::AclPacket) -> Result<(), Self::Error>; + fn write_sync_data(&self, packet: &data::SyncPacket) -> Result<(), Self::Error>; + fn write_iso_data(&self, packet: &data::IsoPacket) -> Result<(), Self::Error>; + + fn try_write_acl_data(&self, packet: &data::AclPacket) -> Result<(), TryError>; + fn try_write_sync_data(&self, packet: &data::SyncPacket) -> Result<(), TryError>; + fn try_write_iso_data(&self, packet: &data::IsoPacket) -> Result<(), TryError>; + + fn read<'a>(&self, buf: &'a mut [u8]) -> Result, Self::Error>; + fn try_read<'a>(&self, buf: &'a mut [u8]) -> Result, TryError>; +} + +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum TryError { + Error(E), + Busy, +} + +pub trait ControllerCmdSync: Controller { + fn exec(&self, cmd: &C) -> Result>>; +} + +pub trait ControllerCmdAsync: Controller { + fn exec(&self, cmd: &C) -> Result<(), TryError>>; +} From 5d41b0c758404880394df49126566b71a2980f91 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 6 May 2024 09:45:06 +0200 Subject: [PATCH 3/7] remove blocking command support --- src/cmd.rs | 16 +--------------- src/controller/blocking.rs | 14 +------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index 7044a0d..fc087b8 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -2,7 +2,7 @@ use core::future::Future; -use crate::controller::{blocking, CmdError, ControllerCmdAsync, ControllerCmdSync, ErrorType}; +use crate::controller::{CmdError, ControllerCmdAsync, ControllerCmdSync, ErrorType}; use crate::param::param; use crate::{FixedSizeValue, FromHciBytes, HostToControllerPacket, PacketKind, WriteHci}; @@ -115,13 +115,6 @@ pub trait AsyncCmd: Cmd { ) -> impl Future::Error>>> { controller.exec(self) } - - fn exec_blocking>( - &self, - controller: &C, - ) -> Result<(), blocking::TryError::Error>>> { - controller.exec(self) - } } pub trait CmdReturnBuf: Copy + AsRef<[u8]> + AsMut<[u8]> { @@ -165,13 +158,6 @@ pub trait SyncCmd: Cmd { ) -> impl Future::Error>>> { controller.exec(self) } - - fn exec_blocking>( - &self, - controller: &C, - ) -> Result::Error>>> { - controller.exec(self) - } } #[doc(hidden)] diff --git a/src/controller/blocking.rs b/src/controller/blocking.rs index 8c02cf0..2b1c4e1 100644 --- a/src/controller/blocking.rs +++ b/src/controller/blocking.rs @@ -1,8 +1,4 @@ -use crate::{ - cmd, - controller::{CmdError, ErrorType}, - data, ControllerToHostPacket, -}; +use crate::{controller::ErrorType, data, ControllerToHostPacket}; pub trait Controller: ErrorType { fn write_acl_data(&self, packet: &data::AclPacket) -> Result<(), Self::Error>; @@ -23,11 +19,3 @@ pub enum TryError { Error(E), Busy, } - -pub trait ControllerCmdSync: Controller { - fn exec(&self, cmd: &C) -> Result>>; -} - -pub trait ControllerCmdAsync: Controller { - fn exec(&self, cmd: &C) -> Result<(), TryError>>; -} From 29b51a3bd2e08e4d1afd1fb378c1ecc01eed2544 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 6 May 2024 10:01:02 +0200 Subject: [PATCH 4/7] rustfmt --- src/controller/blocking.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controller/blocking.rs b/src/controller/blocking.rs index 2b1c4e1..14b5230 100644 --- a/src/controller/blocking.rs +++ b/src/controller/blocking.rs @@ -1,4 +1,5 @@ -use crate::{controller::ErrorType, data, ControllerToHostPacket}; +use crate::controller::ErrorType; +use crate::{data, ControllerToHostPacket}; pub trait Controller: ErrorType { fn write_acl_data(&self, packet: &data::AclPacket) -> Result<(), Self::Error>; From db427d523f8e41c83d3facf2cad0480dad43e2e0 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 10 May 2024 12:03:58 +0200 Subject: [PATCH 5/7] Add trait and impl of blocking transports --- src/cmd.rs | 10 ++++----- src/controller.rs | 29 +------------------------- src/transport.rs | 53 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index fc087b8..2d2adb5 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -2,9 +2,9 @@ use core::future::Future; -use crate::controller::{CmdError, ControllerCmdAsync, ControllerCmdSync, ErrorType}; -use crate::param::param; -use crate::{FixedSizeValue, FromHciBytes, HostToControllerPacket, PacketKind, WriteHci}; +use crate::controller::{ControllerCmdAsync, ControllerCmdSync}; +use crate::{param, FixedSizeValue, FromHciBytes, HostToControllerPacket, PacketKind, WriteHci}; +use embedded_io::ErrorType; pub mod controller_baseband; pub mod info; @@ -112,7 +112,7 @@ pub trait AsyncCmd: Cmd { fn exec>( &self, controller: &C, - ) -> impl Future::Error>>> { + ) -> impl Future::Error>>> { controller.exec(self) } } @@ -155,7 +155,7 @@ pub trait SyncCmd: Cmd { fn exec>( &self, controller: &C, - ) -> impl Future::Error>>> { + ) -> impl Future::Error>>> { controller.exec(self) } } diff --git a/src/controller.rs b/src/controller.rs index fe14bda..00e5d0e 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -9,6 +9,7 @@ use cmd::controller_baseband::Reset; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::signal::Signal; use embassy_sync::waitqueue::AtomicWaker; +use embedded_io::ErrorType; use futures_intrusive::sync::LocalSemaphore; use crate::cmd::{Cmd, CmdReturnBuf}; @@ -19,10 +20,6 @@ use crate::{cmd, data, ControllerToHostPacket, FixedSizeValue, FromHciBytes, Hos pub mod blocking; -pub trait ErrorType { - type Error: embedded_io::Error; -} - pub trait Controller: ErrorType { fn write_acl_data(&self, packet: &data::AclPacket) -> impl Future>; fn write_sync_data(&self, packet: &data::SyncPacket) -> impl Future>; @@ -31,21 +28,6 @@ pub trait Controller: ErrorType { fn read<'a>(&self, buf: &'a mut [u8]) -> impl Future, Self::Error>>; } -/// An error type for Bluetooth HCI commands. -#[derive(Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CmdError { - Hci(param::Error), - Io(E), -} - -/// An error type for try operations. -impl From for CmdError { - fn from(e: param::Error) -> Self { - Self::Hci(e) - } -} - pub trait ControllerCmdSync: Controller { /// Note: Some implementations may require [`Controller::read()`] to be polled for this to return. fn exec(&self, cmd: &C) -> impl Future>>; @@ -56,15 +38,6 @@ pub trait ControllerCmdAsync: Controller { fn exec(&self, cmd: &C) -> impl Future>>; } -/// An external [`Controller`] with communication via [`Transport`] type `T`. -pub trait TryControllerCmdSync: TryController { - fn try_exec(&self, cmd: &C) -> Result>>; -} - -pub trait TryControllerCmdAsync: TryController { - fn try_exec(&self, cmd: &C) -> Result<(), TryError>>; -} - /// An external Bluetooth controller with communication via [`Transport`] type `T`. /// /// The controller state holds a number of command slots that can be used diff --git a/src/transport.rs b/src/transport.rs index 52dd518..4fd1f72 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -4,13 +4,15 @@ use core::future::Future; use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::mutex::Mutex; -use embedded_io::ReadExactError; +use embedded_io::{ErrorType, ReadExactError}; -use crate::{ControllerToHostPacket, FromHciBytesError, HostToControllerPacket, ReadHci, ReadHciError, WriteHci}; +use crate::{ + controller::blocking::TryError, ControllerToHostPacket, FromHciBytesError, HostToControllerPacket, ReadHci, + ReadHciError, WriteHci, +}; /// A packet-oriented HCI Transport Layer -pub trait Transport { - type Error: embedded_io::Error; +pub trait Transport: embedded_io::ErrorType { /// Read a complete HCI packet into the rx buffer fn read<'a>(&self, rx: &'a mut [u8]) -> impl Future, Self::Error>>; /// Write a complete HCI packet from the tx buffer @@ -73,6 +75,16 @@ impl Seria } } +impl< + M: RawMutex, + R: embedded_io::ErrorType, + W: embedded_io::ErrorType, + E: embedded_io::Error, + > ErrorType for SerialTransport +{ + type Error = Error; +} + impl< M: RawMutex, R: embedded_io_async::Read, @@ -80,7 +92,6 @@ impl< E: embedded_io::Error, > Transport for SerialTransport { - type Error = Error; async fn read<'a>(&self, rx: &'a mut [u8]) -> Result, Self::Error> { let mut r = self.reader.lock().await; ControllerToHostPacket::read_hci_async(&mut *r, rx) @@ -97,6 +108,25 @@ impl< } } +impl, W: embedded_io::Write, E: embedded_io::Error> + blocking::Transport for SerialTransport +{ + fn read<'a>(&self, rx: &'a mut [u8]) -> Result, TryError> { + let mut r = self.reader.try_lock().map_err(|_| TryError::Busy)?; + ControllerToHostPacket::read_hci(&mut *r, rx) + .map_err(Error::Read) + .map_err(TryError::Error) + } + + fn write(&self, tx: &T) -> Result<(), TryError> { + let mut w = self.writer.try_lock().map_err(|_| TryError::Busy)?; + WithIndicator(tx) + .write_hci(&mut *w) + .map_err(|e| Error::Write(e)) + .map_err(TryError::Error) + } +} + /// Wrapper for a [`HostToControllerPacket`] that will write the [`PacketKind`](crate::PacketKind) indicator byte before the packet itself /// when serialized with [`WriteHci`]. /// @@ -127,3 +157,16 @@ impl<'a, T: HostToControllerPacket> WriteHci for WithIndicator<'a, T> { self.0.write_hci_async(writer).await } } + +pub mod blocking { + use super::*; + use crate::controller::blocking::TryError; + + /// A packet-oriented HCI Transport Layer + pub trait Transport: embedded_io::ErrorType { + /// Read a complete HCI packet into the rx buffer + fn read<'a>(&self, rx: &'a mut [u8]) -> Result, TryError>; + /// Write a complete HCI packet from the tx buffer + fn write(&self, val: &T) -> Result<(), TryError>; + } +} From b2f1a1f8ff0673eef8aaed0703269dc82679895b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 13 May 2024 09:23:16 +0200 Subject: [PATCH 6/7] implement blocking trait for external controller --- src/controller.rs | 120 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 19 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index 00e5d0e..3e64663 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -16,7 +16,7 @@ use crate::cmd::{Cmd, CmdReturnBuf}; use crate::event::{CommandComplete, Event}; use crate::param::{RemainingBytes, Status}; use crate::transport::Transport; -use crate::{cmd, data, ControllerToHostPacket, FixedSizeValue, FromHciBytes, HostToControllerPacket}; +use crate::{cmd, data, ControllerToHostPacket, FixedSizeValue, FromHciBytes}; pub mod blocking; @@ -45,33 +45,23 @@ pub trait ControllerCmdAsync: Controller { /// /// The contract is that before sending a command, a slot is reserved, which /// returns a signal handle that can be used to await a response. -pub struct ExternalController -where - T: Transport, -{ +pub struct ExternalController { transport: T, slots: ControllerState, } -impl ExternalController -where - T: Transport, -{ +impl ExternalController { pub fn new(transport: T) -> Self { Self { slots: ControllerState::new(), transport, } } - - async fn write(&self, data: &W) -> Result<(), T::Error> { - self.transport.write(data).await - } } impl ErrorType for ExternalController where - T: Transport, + T: ErrorType, { type Error = T::Error; } @@ -81,17 +71,17 @@ where T: Transport, { async fn write_acl_data(&self, packet: &data::AclPacket<'_>) -> Result<(), Self::Error> { - self.write(packet).await?; + self.transport.write(packet).await?; Ok(()) } async fn write_sync_data(&self, packet: &data::SyncPacket<'_>) -> Result<(), Self::Error> { - self.write(packet).await?; + self.transport.write(packet).await?; Ok(()) } async fn write_iso_data(&self, packet: &data::IsoPacket<'_>) -> Result<(), Self::Error> { - self.write(packet).await?; + self.transport.write(packet).await?; Ok(()) } @@ -126,6 +116,98 @@ where } } +impl blocking::Controller for ExternalController +where + T: crate::transport::blocking::Transport, +{ + fn write_acl_data(&self, packet: &data::AclPacket<'_>) -> Result<(), Self::Error> { + loop { + match self.try_write_acl_data(packet) { + Err(blocking::TryError::Busy) => {} + Err(blocking::TryError::Error(e)) => return Err(e), + Ok(r) => return Ok(r), + } + } + } + + fn write_sync_data(&self, packet: &data::SyncPacket<'_>) -> Result<(), Self::Error> { + loop { + match self.try_write_sync_data(packet) { + Err(blocking::TryError::Busy) => {} + Err(blocking::TryError::Error(e)) => return Err(e), + Ok(r) => return Ok(r), + } + } + } + + fn write_iso_data(&self, packet: &data::IsoPacket<'_>) -> Result<(), Self::Error> { + loop { + match self.try_write_iso_data(packet) { + Err(blocking::TryError::Busy) => {} + Err(blocking::TryError::Error(e)) => return Err(e), + Ok(r) => return Ok(r), + } + } + } + + fn read<'a>(&self, buf: &'a mut [u8]) -> Result, Self::Error> { + loop { + // Safety: we will not hold references across loop iterations. + let buf = unsafe { core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()) }; + match self.try_read(buf) { + Err(blocking::TryError::Busy) => {} + Err(blocking::TryError::Error(e)) => return Err(e), + Ok(r) => return Ok(r), + } + } + } + + fn try_write_acl_data(&self, packet: &data::AclPacket<'_>) -> Result<(), blocking::TryError> { + self.transport.write(packet)?; + Ok(()) + } + + fn try_write_sync_data(&self, packet: &data::SyncPacket<'_>) -> Result<(), blocking::TryError> { + self.transport.write(packet)?; + Ok(()) + } + + fn try_write_iso_data(&self, packet: &data::IsoPacket<'_>) -> Result<(), blocking::TryError> { + self.transport.write(packet)?; + Ok(()) + } + + fn try_read<'a>(&self, buf: &'a mut [u8]) -> Result, blocking::TryError> { + loop { + { + // Safety: we will not hold references across loop iterations. + let buf = unsafe { core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()) }; + let value = self.transport.read(&mut buf[..])?; + match value { + ControllerToHostPacket::Event(ref event) => match &event { + Event::CommandComplete(e) => { + self.slots.complete( + e.cmd_opcode, + e.status, + e.num_hci_cmd_pkts as usize, + e.return_param_bytes.as_ref(), + ); + continue; + } + Event::CommandStatus(e) => { + self.slots + .complete(e.cmd_opcode, e.status, e.num_hci_cmd_pkts as usize, &[]); + continue; + } + _ => return Ok(value), + }, + _ => return Ok(value), + } + } + } + } +} + impl ControllerCmdSync for ExternalController where T: Transport, @@ -141,7 +223,7 @@ where self.slots.release_slot(idx); }); - self.write(cmd).await.map_err(cmd::Error::Io)?; + self.transport.write(cmd).await.map_err(cmd::Error::Io)?; let result = slot.wait().await; let return_param_bytes = RemainingBytes::from_hci_bytes_complete(&retval.as_ref()[..result.len]).unwrap(); @@ -168,7 +250,7 @@ where self.slots.release_slot(idx); }); - self.write(cmd).await.map_err(cmd::Error::Io)?; + self.transport.write(cmd).await.map_err(cmd::Error::Io)?; let result = slot.wait().await; result.status.to_result()?; From cb2b1307dd34ea00009fcab72b0047e513b161d9 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 13 May 2024 09:24:12 +0200 Subject: [PATCH 7/7] rustfmt --- src/cmd.rs | 3 ++- src/transport.rs | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index 2d2adb5..1163c9a 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -2,9 +2,10 @@ use core::future::Future; +use embedded_io::ErrorType; + use crate::controller::{ControllerCmdAsync, ControllerCmdSync}; use crate::{param, FixedSizeValue, FromHciBytes, HostToControllerPacket, PacketKind, WriteHci}; -use embedded_io::ErrorType; pub mod controller_baseband; pub mod info; diff --git a/src/transport.rs b/src/transport.rs index 4fd1f72..6d20904 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -6,10 +6,8 @@ use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::mutex::Mutex; use embedded_io::{ErrorType, ReadExactError}; -use crate::{ - controller::blocking::TryError, ControllerToHostPacket, FromHciBytesError, HostToControllerPacket, ReadHci, - ReadHciError, WriteHci, -}; +use crate::controller::blocking::TryError; +use crate::{ControllerToHostPacket, FromHciBytesError, HostToControllerPacket, ReadHci, ReadHciError, WriteHci}; /// A packet-oriented HCI Transport Layer pub trait Transport: embedded_io::ErrorType {