BLE

Common API

group BLE

The BLE driver provides support for wireless data transfer between the host and an external peripheral such as a smartphone, using Bluetooth connection.

Typedefs

typedef struct pi_ble_api_s pi_ble_api_t

BLE specific API.

Structure holding BLE specific API.

Functions

int32_t pi_ble_open(struct pi_device *device)

Open a BLE device.

This function opens and intializes a BLE device. This function must be called before using device.

Parameters:
  • device – Pointer to the BLE device structure.

Return values:
  • 0 – If the operation is successful.

  • ERRNO – Error code otherwise.

void pi_ble_close(struct pi_device *device)

Close a BLE device.

This function closes an opened BLE device. It frees all allocated objects and interfaces used.

Parameters:
  • device – Pointer to the BLE device structure.

int32_t pi_ble_ioctl(struct pi_device *device, uint32_t cmd, void *arg)

IOctl commands.

This function is used to send special command to BLE device.

Parameters:
  • device – Pointer to the BLE device structure.

  • cmd – Ioctl command.

  • arg – Ioctl command arg.

Returns:

Value Value depends on ioctl command.

int32_t pi_ble_at_cmd(struct pi_device *device, const char *cmd, char *resp, uint32_t size)

Send AT command to BLE device.

This function is used to send AT commands to BLE device.

Note

The command string should be plain command, i.e. without the “AT” part.

Note

The command may or may not return a response.

Parameters:
  • device – Pointer to the BLE device structure.

  • cmd – Command string to send.

  • resp – Buffer to store response.

  • size – Size of the response to store, in Bytes.

Return values:
  • 0 – If operation is successful.

  • ERRNO – Error code otherwise.

int32_t pi_ble_peer_connect(struct pi_device *device, const char *addr)

Connect to a peer.

This function should be used to connect to a remote peer.

Parameters:
  • device – Pointer to the BLE device structure.

  • addr – Address in string format.

Return values:
  • 0 – If operation is successful.

  • ERRNO – Error code otherwise.

int32_t pi_ble_peer_disconnect(struct pi_device *device, const char *addr)

Close a connection to a peer.

This function closes an existing peer connection.

Parameters:
  • device – Pointer to the BLE device structure.

  • addr – Address in string format.

Return values:
  • 0 – If operation is successful.

  • ERRNO – Error code otherwise.

void pi_ble_data_send(struct pi_device *device, uint8_t *buffer, uint32_t size)

Send data to BLE device. Blocking API.

This function is used to send data to BLE device.

Note

This function is synchronous, caller is blocked until transfer is finished. The pending asynchronous function is below : pi_ble_data_send_async().

Parameters:
  • device – Pointer to the BLE structure.

  • buffer – Buffer to send.

  • size – Size of data to send.

void pi_ble_data_send_async(struct pi_device *device, uint8_t *buffer, uint32_t size, pi_evt_t *task)

Send data to BLE device. Blocking API.

This function is used to send data to BLE device.

Note

This function is asynchronous. The pending synchronous function is : pi_ble_data_send().

Parameters:
  • device – Pointer to the BLE structure.

  • buffer – Buffer to send.

  • size – Size of data to send.

  • task – Event task used to check end of transfer.

void pi_ble_data_get(struct pi_device *device, uint8_t *buffer, uint32_t size)

Get data from BLE device. Blocking API.

This function is used to retrieve data from BLE device.

Note

This function is synchronous, caller is blocked until transfer is finished. The pending asynchronous function is below : pi_ble_data_get_async().

Parameters:
  • device – Pointer to the BLE structure.

  • buffer – Buffer to store data.

  • size – Size of data.

void pi_ble_data_get_async(struct pi_device *device, uint8_t *buffer, uint32_t size, pi_evt_t *task)

Get data from BLE device. Non blocking API.

This function is used to retrieve data from BLE device.

Note

This function is asynchronous. The pending synchronous function is : pi_ble_data_get().

Parameters:
  • device – Pointer to the BLE structure.

  • buffer – Buffer to store data.

  • size – Size of data.

  • task – Event task used to check end of transfer.

int8_t pi_ble_catch_peer_event_async(struct pi_device *device, char *resp, pi_evt_t *callback)

Manage events received from peer.

Note

Asynchronous.

Parameters:
  • device

  • resp – NOT NULL. Buffer to store the event.

  • callback – NOT NULL. Triggered when we received an event.

Return values:
  • 0 – if success

  • -1 – if error

Returns:

int8_t Process status code.

struct pi_ble_api_s
#include <ble.h>

BLE specific API.

Structure holding BLE specific API.

Public Members

int32_t (*at_cmd)(struct pi_device *device, const char *cmd, char *resp, uint32_t size)

Function to send AT command.

int32_t (*peer_connect)(struct pi_device *device, const char *addr)

Function to connect BLE device to a remote peer.

int32_t (*peer_disconnect)(struct pi_device *device, const char *addr)

Function to disconnect BLE device to a remote peer.

Nina B312

group NINA_B312

The nina_b312 driver provides support for data transfer using a BLE module, here a NINA B312 BLE module. This module is interfaced on GAP9_EVK through UART.

Defines

PI_AT_RESP_ARRAY_LENGTH

RESP array length.

Enums

enum pi_ble_ioctl_cmd_e

IOCTL commands for Nina B312 module.

Values:

enumerator PI_NINA_B112_MODEL_INFO = 0

BLE device info.

enumerator PI_NINA_B112_SERVER_CONFIGURE

Configure BLE device as a server.

enumerator PI_NINA_B112_CLIENT_CONFIGURE

Configure BLE device as a client.

enumerator PI_NINA_B112_UART_CONFIGURE

Configure HCI UART.

enumerator PI_NINA_B112_DATA_MODE_ENTER

Enter Data Mode.

enumerator PI_NINA_B112_DATA_MODE_EXIT

Exit Data Mode.

enumerator PI_NINA_B112_WAIT_FOR_EVENT

Wait for some responses/events from BLE device.

enumerator PI_NINA_B312_MODEL_INFO = 0

BLE device info.

enumerator PI_NINA_B312_SERVER_CONFIGURE

Configure BLE device as a server.

enumerator PI_NINA_B312_CLIENT_CONFIGURE

Configure BLE device as a client.

enumerator PI_NINA_B312_UART_CONFIGURE

Configure HCI UART.

enumerator PI_NINA_B312_DATA_MODE_ENTER

Enter Data Mode.

enumerator PI_NINA_B312_DATA_MODE_EXIT

Exit Data Mode.

enumerator PI_NINA_B312_CATCH_PEER_EVENT

Catch events received from peer.

Functions

void pi_ble_nina_b312_conf_init(struct pi_device *device, struct pi_nina_b312_conf *conf)

Initialize NINA_B312 configuration structure.

Parameters:
  • device – Pointer to the BLE device structure.

  • conf – Pointer to NINA_B312 configuration structure.

struct pi_nina_b312_conf
#include <nina_b312.h>

NINA_B312 configuration structure.

This structure holds BLE configuration(interface used, baudrate,…).

Public Members

uint8_t uart_itf

UART interface used to connect BLE device.

uint32_t baudrate

UART baudrate.

char local_name[30]

BLE device name (visible by others).