bt_hci/controller/
blocking.rs

1//! Blocking controller types and traits.
2use crate::controller::ErrorType;
3use crate::{data, ControllerToHostPacket};
4
5/// Trait representing a HCI controller which supports blocking and non-blocking operations.
6pub trait Controller: ErrorType {
7    /// Write ACL data to the controller. Blocks until done.
8    fn write_acl_data(&self, packet: &data::AclPacket) -> Result<(), Self::Error>;
9
10    /// Write Sync data to the controller. Blocks until done.
11    fn write_sync_data(&self, packet: &data::SyncPacket) -> Result<(), Self::Error>;
12
13    /// Write Iso data to the controller. Blocks until done.
14    fn write_iso_data(&self, packet: &data::IsoPacket) -> Result<(), Self::Error>;
15
16    /// Attempt to write ACL data to the controller.
17    ///
18    /// Returns a TryError if the operation would block.
19    fn try_write_acl_data(&self, packet: &data::AclPacket) -> Result<(), TryError<Self::Error>>;
20
21    /// Attempt to write Sync data to the controller.
22    ///
23    /// Returns a TryError if the operation would block.
24    fn try_write_sync_data(&self, packet: &data::SyncPacket) -> Result<(), TryError<Self::Error>>;
25
26    /// Attempt to write Iso data to the controller.
27    ///
28    /// Returns a TryError if the operation would block.
29    fn try_write_iso_data(&self, packet: &data::IsoPacket) -> Result<(), TryError<Self::Error>>;
30
31    /// Read a valid HCI packet from the controller. Blocks until done.
32    fn read<'a>(&self, buf: &'a mut [u8]) -> Result<ControllerToHostPacket<'a>, Self::Error>;
33
34    /// Read a valid HCI packet from the controller.
35    ///
36    /// Returns a TryError if the operation would block.
37    fn try_read<'a>(&self, buf: &'a mut [u8]) -> Result<ControllerToHostPacket<'a>, TryError<Self::Error>>;
38}
39
40/// Error for representing an operation that blocks or fails
41/// with an error.
42#[derive(Debug)]
43#[cfg_attr(feature = "defmt", derive(defmt::Format))]
44pub enum TryError<E> {
45    /// Underlying controller error.
46    Error(E),
47    /// Operation would block.
48    Busy,
49}