Trait Controller

Source
pub trait Controller {
    // Required methods
    async fn controller_write(&mut self, opcode: Opcode, payload: &[u8]);
    async fn controller_read_into(&self, buf: &mut [u8]);
}
Expand description

Interface to the Bluetooth controller from the host’s perspective.

The Bluetooth application host must communicate with a controller (which, in turn, communicates with the link layer) to control the Bluetooth radio. Device crates must implement this trait, which enables full access to all of the functions and events of the HCI through [host::Hci] and [host::uart::Hci], respectively.

Required Methods§

Source

async fn controller_write(&mut self, opcode: Opcode, payload: &[u8])

Writes the bytes to the controller, in a single transaction if possible. All of header shall be written, followed by all of payload.

Source

async fn controller_read_into(&self, buf: &mut [u8])

Reads data from the controller into the provided buffer. The length of the buffer indicates the number of bytes to read. The implementor must not return bytes in an order different from that in which they were received from the controller. For example, the implementor may read all available bytes from the controller and maintain them in an internal buffer, but read_into shall only read the number of bytes requested.

§Example
// Controller sends:
// +------+------+------+------+------+------+------+------+
// | 0x12 | 0x34 | 0x56 | 0x78 | 0x9a | 0xbc | 0xde | 0xf0 |
// +------+------+------+------+------+------+------+------+

// host calls:

let mut buffer = [0; 4];
controller.controller_read_into(&mut buffer);

// buffer contains:
// +------+------+------+------+
// | 0x00 | 0x12 | 0x34 | 0x56 |
// +------+------+------+------+

// now the host calls:
controller.controller_read_into(&mut buffer);  // read 4 bytes into buffer

// buffer contains:
// +------+------+------+------+
// | 0x78 | 0x9a | 0xbc | 0xde |
// +------+------+------+------+

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§