wasefire_board_api/radio/
ble.rs

1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Bluetooth Low Energy (BLE) interface.
16
17use wasefire_applet_api::radio::ble::Advertisement;
18
19use crate::{Error, Support};
20
21/// BLE event.
22#[cfg_attr(feature = "defmt", derive(defmt::Format))]
23#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
24pub enum Event {
25    /// Received an advertisement packet.
26    Advertisement,
27}
28
29impl<B: crate::Api> From<Event> for crate::Event<B> {
30    fn from(event: Event) -> Self {
31        super::Event::Ble(event).into()
32    }
33}
34
35/// BLE interface.
36pub trait Api: Support<bool> {
37    /// Enables BLE events.
38    fn enable(event: &Event) -> Result<(), Error>;
39
40    /// Disables BLE events.
41    fn disable(event: &Event) -> Result<(), Error>;
42
43    /// Reads the next advertisement packet, if any.
44    ///
45    /// Returns whether a packet was read.
46    fn read_advertisement(packet: &mut Advertisement) -> Result<bool, Error>;
47}