#ble #bluetooth

no-std bluetooth-hci

Implementation of the Bluetooth HCI

4 releases

0.1.0 May 8, 2020
0.0.3 Sep 16, 2018
0.0.2 Sep 4, 2018
0.0.1 Sep 3, 2018

#161 in Embedded development

Download history 52/week @ 2021-08-07 69/week @ 2021-08-14 76/week @ 2021-08-21 52/week @ 2021-08-28 27/week @ 2021-09-04 37/week @ 2021-09-11 62/week @ 2021-09-18 74/week @ 2021-09-25 61/week @ 2021-10-02 67/week @ 2021-10-09 36/week @ 2021-10-16 51/week @ 2021-10-23 54/week @ 2021-10-30 68/week @ 2021-11-06 38/week @ 2021-11-13 59/week @ 2021-11-20

172 downloads per month
Used in bluenrg

MIT/Apache

305KB
3.5K SLoC

Bluetooth HCI

Build Status

This crate defines a pure Rust implementation of the Bluetooth Host-Controller Interface for bare metal devices. It defines commands and events from the specification, and requires specific chips to define vendor-specific commands and events.

Version

This crate can support versions 4.1, 4.2, and 5.0 of the Bluetooth specification. By default, it supports version 4.1. To enable another version, add the following to your Cargo.toml:

[dependencies.bluetooth-hci]
features = "version-4-2"

or

[dependencies.bluetooth-hci]
features = "version-5-0"

Implementation

This crate defines a trait (Controller) that should be implemented for a specific BLE chip. Any implementor can then be used as a host::uart::Hci to read and write to the chip.

impl bluetooth_hci::Controller for MyController {
    type Error = BusError;
    type Header = bluetooth_hci::host::uart::CommandHeader;
    fn write(&mut self, header: &[u8], payload: &[u8]) ->
        nb::Result<(), Self::Error> {
        // implementation...
    }
    fn read_into(&mut self, buffer: &mut [u8]) ->
        nb::Result<(), Self::Error> {
        // implementation...
    }
    fn peek(&mut self, n: usize) -> nb::Result<u8, Self::Error> {
        // implementation...
    }
}

The entire Bluetooth HCI is implemented in terms of these functions that handle the low-level I/O. To read events, you can use the host::uart::Hci trait, which defines a read function. The easiest way to specify the vendor-specific event type is via type inference:

fn process_event(e: hci::event::Event<MyVendorEvent>) {
    // do stuff with e
}
// elsewhere...
process_event(controller.read()?)

Supported Commands and Events

This crate contains only partial support for commands and events right now. The only commands and events (as of September 2018) are those used by the BlueNRG chip. Support for HCI ACL Data Packets and HCI Synchronous Data Packets still needs to be determined.

See the Bluetooth Specification for more (many, many more) details on what this crate should eventually support. Volume 2, Part E, section 7 is the most relevant portion for this crate.

Dependencies

~160KB

۴^