Bluetooth Low Energy
Voltix has limited support for BLE. You can use the API to send advertisement packets with a custom payload on the three advertising channels.
The implementation is not standard-conformant. You may only use it for evaluation purposes in dedicated facilities where it cannot interfere with other spectrum users.
Important
Always check the return code of voltix_ble_advertise(...) to distinguish between a power failure (VOLTIX_ERR_RESET) and successful advertising (VOLTIX_SUCCESS).
Example usage
1
2#include "voltix.h"
3#include "voltix_ble.h"
4#include "voltix_timing.h"
5
6const uint8_t adv_address[] = {0x01, 0xEE, 0xC0, 0xFF, 0x03, 0x02};
7const char adv_name[] = "VOLTIX";
8
9static struct {
10 unsigned int counter;
11} ble_data;
12
13void lateinit(void) {
14 voltix_ble_init();
15}
16
17int main() {
18 voltix_ble_adv_cfg_t adv_cfg = {.addr = adv_address,
19 .name = adv_name,
20 .name_len = 6,
21 .data = &ble_data,
22 .data_len = sizeof(ble_data),
23 .manufacturer_id = VOLTIX_BLE_ADV_MNF_NORDIC};
24 voltix_ble_adv_cfg(&adv_cfg);
25 ble_data.counter = 0;
26 for (;;) {
27 voltix_wait_cap_charged();
28 voltix_ble_advertise(ADV_CH_ALL);
29 ble_data.counter++;
30 /* Sleep at least 250ms before next advertising round */
31 voltix_sleep_ms(250);
32 }
33}
API reference
-
enum voltix_adv_pdu_type_t
Type of advertisement.
Values:
-
enumerator ADV_IND
Undirected, connectable advertisement.
-
enumerator ADV_DIRECT_IND
Directed, connectable advertisement.
-
enumerator ADV_NONCONN_IND
Undirected, unconnectable advertisement.
-
enumerator SCAN_REQ
Scan request.
-
enumerator SCAN_RSP
Scan response.
-
enumerator CONNECT_REQ
Connection request.
-
enumerator ADV_SCAN_IND
Scannable undirected advertisement.
-
enumerator ADV_IND
-
enum voltix_adv_ch_t
Values:
-
enumerator ADV_CH_37
-
enumerator ADV_CH_38
-
enumerator ADV_CH_39
-
enumerator ADV_CH_ALL
-
enumerator ADV_CH_37
-
voltix_rc_t voltix_ble_adv_cfg(voltix_ble_adv_cfg_t *cfg)
Sets up the internal packet buffer for advertisting with given name, address and payload size.
- Parameters:
adv_addr – Pointer to address buffer.
adv_name – Advertising name of the device.
data – Pointer to payload.
data_len – Size of the payload.
- Return values:
VOLTIX_SUCCESS – Successfully prepared advertisement.
VOLTIX_ERR_OVERFLOW – At least one argument is too long.
-
voltix_rc_t voltix_ble_advertise(voltix_adv_ch_t ch)
Advertises the given payload on the selected channel(s)
- Parameters:
ch – Channel(s) on which advertisement should be sent.
- Return values:
VOLTIX_SUCCESS – Advertisement successfully sent.
VOLTIX_ERR_RESET – Reset occured while sending advertisement.
VOLTIX_ERR_TEARDOWN – Teardown occured while sending advertisement.
-
void voltix_ble_init(void)
Initializes BLE driver.
-
VOLTIX_BLE_ADV_MNF_NORDIC
-
struct voltix_ble_adv_addr_t
-
struct voltix_ble_adv_header_t
-
struct voltix_adv_pck_t
- #include <voltix_ble.h>
Common packet format for some ADV PDU types.
-
struct voltix_ble_adv_cfg_t
- #include <voltix_ble.h>
BLE advertising configuration.