BSB Developer Docs
Loading...
Searching...
No Matches
ble.h File Reference

Public ble api. More...

#include "ble_callback_types.h"
#include <furi.h>

Go to the source code of this file.

Data Structures

struct  BleState
 Depicts current ble state. More...
 

Macros

#define RECORD_BLE   "ble"
 BLE FURI record identifier.
 
#define MAX_TX_CHUNK_SIZE   (237)
 Defines max data size for characteristics.
 
#define BLE_REMOTE_DEVICE_ADDRESS_STRING_SIZE   (18)
 Ble device address string size.
 

Typedefs

typedef struct Ble Ble
 Opaque Ble type declaration.
 

Enumerations

enum  BleServiceStatus {
  BleServiceStatusReset , BleServiceStatusInitialization , BleServiceStatusReady , BleServiceStatusAdvertising ,
  BleServiceStatusConnectable , BleServiceStatusConnected , BleServiceStatusError , BleServiceStatusCount
}
 Enumeration of ble service statuses. More...
 
enum  BleUartChannel { BleUartChannelNordic , BleUartChannelHM10 , BleUartChannelCount }
 Enumeration of ble uart channels which public ble uart api sets in order to read/write data. More...
 

Functions

bool ble_get_state (Ble *ble, BleState *const output)
 Get ble state.
 
bool ble_start (Ble *ble)
 Enable ble by sending BleCommandEnable.
 
bool ble_stop (Ble *ble)
 Disable ble by sending BleCommandDisable.
 
bool ble_forget (Ble *ble)
 Forget current pairing with remote device.
 
FuriPubSub * ble_get_pubsub (Ble *ble)
 Get pubsub in order to subscribe on ble events.
 
void ble_uart_set_rx_callback (Ble *ble, BleUartChannel channel, BleDataUpdatedCallback rx_cb, void *ctx)
 Register callback function for ble uart rx characteristic.
 
void ble_uart_set_tx_done_callback (Ble *ble, BleUartChannel channel, BleDataTransmitDoneCallback tx_done_cb, void *ctx)
 Register callback function for ble uart tx characteristic.
 
void ble_uart_tx_data (Ble *ble, BleUartChannel channel, const void *data, const size_t data_size)
 Send data over ble uart.
 
void ble_uart_set_session_callback (Ble *ble, BleDataUpdatedCallback session_update_cb, void *ctx)
 Register session callback function for Nordic Uart service.
 
void ble_uart_session_set_value (Ble *ble, const uint32_t session)
 Set session value for Nordic Uart Session characteristic.
 

Detailed Description

Public ble api.

Macro Definition Documentation

◆ MAX_TX_CHUNK_SIZE

#define MAX_TX_CHUNK_SIZE   (237)

Defines max data size for characteristics.

Used by ble_http_repeater.h and ble_streaming.h

Enumeration Type Documentation

◆ BleServiceStatus

Enumeration of ble service statuses.

Enumerator
BleServiceStatusReset 

Service was just created.

Will move to BleServiceStatusInitialization when it will create all inner objects

BleServiceStatusInitialization 

Service performs initialization sequence for all inner ble services.

U5 also sends init data to 917 to help him create its services

BleServiceStatusReady 

All init sequences are done.

All inner services configured, and both u5 and 917 ready to work. But ble is still disabled

BleServiceStatusAdvertising 

Ble enabled, device not paired and is visible to all.

BleServiceStatusConnectable 

Ble enabled, device is paired and waits for remote device to connect.

BleServiceStatusConnected 

Remote device connected to bsb over ble.

BleServiceStatusError 

Error occurred.

BleServiceStatusCount 

Total amount of states.

Used in some cyclic operations

◆ BleUartChannel

Enumeration of ble uart channels which public ble uart api sets in order to read/write data.

Enumerator
BleUartChannelNordic 

Points to Nordic Uart ble service, which is used by ble_http_repeater.h.

BleUartChannelHM10 

Points to HM10 Uart ble service, which is used by ble_streaming.h.

BleUartChannelCount 

Total amount of channels.

Function Documentation

◆ ble_forget()

bool ble_forget ( Ble * ble)

Forget current pairing with remote device.

This is a blocking API.

Parameters
[in]blepointer to the ble instance
Returns
true on success, otherwise false

◆ ble_get_pubsub()

FuriPubSub * ble_get_pubsub ( Ble * ble)

Get pubsub in order to subscribe on ble events.

Parameters
[in]blepointer to the ble instance
Returns
pubsub instance for further use

◆ ble_get_state()

bool ble_get_state ( Ble * ble,
BleState *const output )

Get ble state.

This is a blocking API.

Parameters
[in]blepointer to the ble instance
[in,out]outputstate struct filled with current ble state.
Returns
true on success, otherwise false

◆ ble_start()

bool ble_start ( Ble * ble)

Enable ble by sending BleCommandEnable.

This is a blocking API.

After this command device starts advertising with its name and public or random address depending on pairing state.

Parameters
[in]blepointer to the ble instance
Returns
true on success, otherwise false

◆ ble_stop()

bool ble_stop ( Ble * ble)

Disable ble by sending BleCommandDisable.

This is a blocking API.

Parameters
[in]blepointer to the ble instance
Returns
true on success, otherwise false

◆ ble_uart_session_set_value()

void ble_uart_session_set_value ( Ble * ble,
const uint32_t session )

Set session value for Nordic Uart Session characteristic.

This api is used for Nordic Uart channel. This is non-blocking API, and it works in same way as ble_uart_tx_data

Parameters
[in]blepointer to the ble instance
[in]sessionnew session value

◆ ble_uart_set_rx_callback()

void ble_uart_set_rx_callback ( Ble * ble,
BleUartChannel channel,
BleDataUpdatedCallback rx_cb,
void * ctx )

Register callback function for ble uart rx characteristic.

Callback and context can be set only once, after that any attempts to set new callback will be ignored until NULL value will be provided for callback and context, this will reset callback and new callback can be set after

Parameters
[in]blepointer to the ble instance
[in]channelchannel to which callback will be set
[in]rx_cbpointer to callback function
[in]ctxpointer to callback function context

◆ ble_uart_set_session_callback()

void ble_uart_set_session_callback ( Ble * ble,
BleDataUpdatedCallback session_update_cb,
void * ctx )

Register session callback function for Nordic Uart service.

This api is used for Nordic Uart channel only

Parameters
[in]blepointer to the ble instance
[in]session_update_cbpointer to callback function from ble_callback_types.h
[in]ctxpointer to callback function context

◆ ble_uart_set_tx_done_callback()

void ble_uart_set_tx_done_callback ( Ble * ble,
BleUartChannel channel,
BleDataTransmitDoneCallback tx_done_cb,
void * ctx )

Register callback function for ble uart tx characteristic.

Parameters
[in]blepointer to the ble instance
[in]channelchannel to which callback will be set
[in]tx_done_cbpointer to callback function
[in]ctxpointer to callback function context

◆ ble_uart_tx_data()

void ble_uart_tx_data ( Ble * ble,
BleUartChannel channel,
const void * data,
const size_t data_size )

Send data over ble uart.

Copies payload to tx characteristic of choosen uart channel and triggers ble service to do the rest. This is non-blocking API, synchronisation primitives must be used externally in order to wait for transmission complete. Before that a proper callback must be registered using ble_uart_set_tx_done_callback.

Parameters
[in]blepointer to the ble instance
[in]channelchannel to which callback will be set
[in]datapayload to be send
[in]data_sizepayload size