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

#495 in Embedded development

Download history 4749/week @ 2023-11-26 4986/week @ 2023-12-03 5110/week @ 2023-12-10 4594/week @ 2023-12-17 4638/week @ 2023-12-24 4652/week @ 2023-12-31 4488/week @ 2024-01-07 4683/week @ 2024-01-14 5204/week @ 2024-01-21 4656/week @ 2024-01-28 4001/week @ 2024-02-04 4215/week @ 2024-02-11 3768/week @ 2024-02-18 3659/week @ 2024-02-25 3403/week @ 2024-03-03 1169/week @ 2024-03-10

12,586 downloads per month
Used in 2 crates

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

~215KB