SmartSnippets DA1459x SDK
ble_common.h
Go to the documentation of this file.
1 
39 #ifndef BLE_COMMON_H_
40 #define BLE_COMMON_H_
41 
42 #include <stdbool.h>
43 #include <stdint.h>
44 #include <string.h>
45 #include "cmsis_compiler.h"
46 
50 #define BLE_APP_NOTIFY_MASK (1 << 0)
51 
53 typedef enum {
54  BLE_STATUS_OK = 0x00,
63  BLE_ERROR_BUSY = 0x09,
75 } ble_error_t;
76 
78 typedef enum {
142 
145  BLE_EVT_CAT_COMMON,
146  BLE_EVT_CAT_GAP,
147  BLE_EVT_CAT_GATTS,
148  BLE_EVT_CAT_GATTC,
149  BLE_EVT_CAT_L2CAP,
150 };
151 
153 #define BLE_EVT_CAT_FIRST(CAT) (CAT << 8)
154 
156 typedef struct {
157  uint16_t evt_code;
158  uint16_t length;
159 } ble_evt_hdr_t;
160 
167 };
168 
170 typedef enum {
171  BLE_IS_DISABLED = 0x00,
172  BLE_IS_ENABLED = 0x01,
173  BLE_IS_BUSY = 0x02,
174  BLE_IS_RESET = 0x03,
175 } ble_status_t;
176 
178 typedef enum addr_types {
179  PUBLIC_ADDRESS = 0x00,
181 } addr_type_t;
182 
184 typedef enum own_addr_types {
189 #if (dg_configBLE_PRIVACY_1_2 == 1)
190  PRIVATE_CNTL
191 #endif /* (dg_configBLE_PRIVACY_1_2 == 1) */
193 
195 typedef struct bd_address {
196  addr_type_t addr_type;
197  uint8_t addr[6];
198 } bd_address_t;
199 
201 typedef struct own_address {
202  own_addr_type_t addr_type;
203  uint8_t addr[6];
204 } own_address_t;
205 
207 typedef enum {
208  TX_POWER_LEVEL_MAX = 0x00,
209  TX_POWER_LEVEL_CURRENT = 0x01,
211 
213 #define LOW_POWER_ALL_PHYS ( 0x01 )
214 #define HIGH_PERFORMANCE_ALL_PHYS ( 0x02 )
217 typedef struct {
218  uint8_t key[16];
219 } irk_t;
220 
222 typedef struct {
224  uint16_t status;
226 
234 
241 ble_error_t ble_enable(void);
242 
249 ble_error_t ble_reset(void);
250 
258 
266 
275 ble_evt_hdr_t *ble_get_event(bool wait);
276 
282 bool ble_has_event(void);
283 
294 
304 ble_error_t ble_read_tx_power(uint16_t conn_idx, tx_power_level_type_t type, uint8_t *tx_power);
305 
306 #if (dg_configBLE_EVENT_NOTIF_TYPE == BLE_EVENT_NOTIF_USER_TASK) && \
307  (dg_configBLE_EVENT_NOTIF_RUNTIME_CONTROL == 1)
308 
312 void ble_event_notif_enable_end_event(void);
313 
317 void ble_event_notif_enable_cscnt_event(void);
318 
322 void ble_event_notif_enable_fine_event(void);
323 
327 void ble_event_notif_disable_end_event(void);
328 
332 void ble_event_notif_disable_cscnt_event(void);
333 
337 void ble_event_notif_disable_fine_event(void);
338 
339 #endif
340 
350 __STATIC_INLINE bool ble_address_cmp(const bd_address_t *addr1, const bd_address_t *addr2)
351 {
352  return (addr1->addr_type == addr2->addr_type &&
353  !memcmp(addr1->addr, addr2->addr, sizeof(addr2->addr)));
354 }
355 
366 const char *ble_address_to_string(const bd_address_t *address);
367 
378 bool ble_address_from_string(const char *str, addr_type_t addr_type, bd_address_t *address);
379 
395 ble_error_t ble_set_fem_voltage_trim(uint8_t channel, uint8_t value);
396 
397 
398 #endif /* BLE_COMMON_H_ */
399 
BLE_HCI_ERROR_UNSUPPORTED_REMOTE_FEATURE
Definition: ble_common.h:105
ble_evt_reset_completed_t::status
uint16_t status
Status.
Definition: ble_common.h:224
ble_evt_cat
ble_evt_cat
Definition: ble_common.h:144
BLE_HCI_ERROR_UNACCEPTABLE_CONN_INT
Definition: ble_common.h:135
bd_address_t
struct bd_address bd_address_t
ble_reset
ble_error_t ble_reset(void)
Reset BLE module.
ble_handle_event_default
void ble_handle_event_default(ble_evt_hdr_t *hdr)
Execute default event handler.
BLE_HCI_ERROR_REMOTE_DEV_TERM_LOW_RESOURCES
Definition: ble_common.h:99
BLE_HCI_ERROR_QOS_UNACCEPTABLE_PARAM
Definition: ble_common.h:122
BLE_HCI_ERROR_INVALID_HCI_PARAM
Definition: ble_common.h:97
BLE_EVT_RESET_COMPLETED
Definition: ble_common.h:166
BLE_HCI_ERROR_PAGE_TIMEOUT
Definition: ble_common.h:83
ble_central_start
ble_error_t ble_central_start(void)
Start the BLE module as a central device.
BLE_ERROR_LMP_COLLISION
Definition: ble_common.h:73
BLE_HCI_ERROR_UNSUPPORTED_LMP_PARAM_VALUE
Definition: ble_common.h:111
BLE_STATUS_OK
Definition: ble_common.h:54
BLE_HCI_ERROR_DIRECT_ADV_TO
Definition: ble_common.h:136
BLE_ERROR_INS_BANDWIDTH
Definition: ble_common.h:72
own_address
Definition: ble_common.h:201
BLE_HCI_ERROR_ENC_MODE_NOT_ACCEPT
Definition: ble_common.h:116
BLE_HCI_ERROR_DIFF_TRANSACTION_COLLISION
Definition: ble_common.h:121
BLE_HCI_ERROR_COARSE_CLK_ADJUST_REJECTED
Definition: ble_common.h:140
ble_evt_reset_completed_t
Definition: ble_common.h:222
BLE_ERROR_ALREADY_DONE
Definition: ble_common.h:56
BLE_ERROR_NOT_SUPPORTED
Definition: ble_common.h:61
BLE_ERROR_FAILED
Definition: ble_common.h:55
BLE_HCI_ERROR_PIN_MISSING
Definition: ble_common.h:85
BLE_HCI_ERROR_REMOTE_DEV_POWER_OFF
Definition: ble_common.h:100
BLE_HCI_ERROR_INSUFFICIENT_SECURITY
Definition: ble_common.h:125
BLE_HCI_ERROR_CON_TIMEOUT
Definition: ble_common.h:87
BLE_HCI_ERROR_LMP_COLLISION
Definition: ble_common.h:114
BLE_HCI_ERROR_EIR_TOO_LARGE
Definition: ble_common.h:130
tx_power_level_type_t
tx_power_level_type_t
Definition: ble_common.h:207
BLE_ERROR_DIFF_TRANS_COLLISION
Definition: ble_common.h:74
BLE_HCI_ERROR_PAIRING_NOT_ALLOWED
Definition: ble_common.h:103
BLE_ERROR_L2CAP_NO_CREDITS
Definition: ble_common.h:70
BLE_HCI_ERROR_SCO_OFFSET_REJECTED
Definition: ble_common.h:106
BLE_HCI_ERROR_CONN_REJ_SECURITY_REASONS
Definition: ble_common.h:93
BLE_HCI_ERROR_SCO_INTERVAL_REJECTED
Definition: ble_common.h:107
BLE_HCI_ERROR_UNKNOWN_CONNECTION_ID
Definition: ble_common.h:81
own_address_t
struct own_address own_address_t
PRIVATE_STATIC_ADDRESS
Definition: ble_common.h:186
ble_get_event
ble_evt_hdr_t * ble_get_event(bool wait)
Get event from BLE event queue.
BLE_HCI_ERROR_INSTANT_PASSED
Definition: ble_common.h:119
BLE_HCI_ERROR_LINK_KEY_CANT_CHANGE
Definition: ble_common.h:117
BLE_ERROR_INS_RESOURCES
Definition: ble_common.h:68
BLE_ERROR_INVALID_PARAM
Definition: ble_common.h:58
ble_read_tx_power
ble_error_t ble_read_tx_power(uint16_t conn_idx, tx_power_level_type_t type, uint8_t *tx_power)
Read controller TX power.
BLE_ERROR_NOT_ALLOWED
Definition: ble_common.h:59
own_addr_type_t
enum own_addr_types own_addr_type_t
BLE_HCI_ERROR_ROLE_SWITCH_FAIL
Definition: ble_common.h:129
ble_evt_reset_completed_t::hdr
ble_evt_hdr_t hdr
Event header.
Definition: ble_common.h:223
BLE_HCI_ERROR_ROLE_CHANGE_NOT_ALLOWED
Definition: ble_common.h:112
BLE_HCI_ERROR_CON_TERM_BY_LOCAL_HOST
Definition: ble_common.h:101
ble_address_from_string
bool ble_address_from_string(const char *str, addr_type_t addr_type, bd_address_t *address)
Convert string to bd_address.
BLE_HCI_ERROR_ROLE_SWITCH_PEND
Definition: ble_common.h:127
ble_register_app
ble_error_t ble_register_app(void)
Register application in BLE framework.
BLE_HCI_ERROR_CONTROLLER_BUSY
Definition: ble_common.h:134
BLE_ERROR_NOT_ACCEPTED
Definition: ble_common.h:62
BLE_ERROR_IN_PROGRESS
Definition: ble_common.h:57
BLE_HCI_ERROR_INVALID_LMP_PARAM
Definition: ble_common.h:109
BLE_HCI_ERROR_QOS_NOT_SUPPORTED
Definition: ble_common.h:118
BLE_ERROR_CANCELED
Definition: ble_common.h:66
ble_peripheral_start
ble_error_t ble_peripheral_start(void)
Start the BLE module as a peripheral device.
BLE_HCI_ERROR_PARAM_OUT_OF_MAND_RANGE
Definition: ble_common.h:126
BLE_ERROR_ENC_KEY_MISSING
Definition: ble_common.h:67
PRIVATE_RANDOM_RESOLVABLE_ADDRESS
Definition: ble_common.h:187
BLE_HCI_ERROR_ACL_CON_EXISTS
Definition: ble_common.h:90
addr_type_t
enum addr_types addr_type_t
BLE_HCI_ERROR_CONN_REJ_UNACCEPTABLE_BDADDR
Definition: ble_common.h:94
PRIVATE_RANDOM_NONRESOLVABLE_ADDRESS
Definition: ble_common.h:188
BLE_HCI_ERROR_REMOTE_USER_TERM_CON
Definition: ble_common.h:98
own_addr_types
own_addr_types
Definition: ble_common.h:184
BLE_ERROR_TIMEOUT
Definition: ble_common.h:64
ble_has_event
bool ble_has_event(void)
Checks if there's event pending in event queue.
BLE_HCI_ERROR_CONN_FAILED_TO_BE_EST
Definition: ble_common.h:138
BLE_HCI_ERROR_CONN_ACCEPT_TIMEOUT_EXCEED
Definition: ble_common.h:95
BLE_HCI_ERROR_HARDWARE_FAILURE
Definition: ble_common.h:82
ble_evt_hdr_t
Definition: ble_common.h:156
addr_types
addr_types
Definition: ble_common.h:178
BLE_HCI_ERROR_LMP_PDU_NOT_ALLOWED
Definition: ble_common.h:115
ble_set_fem_voltage_trim
ble_error_t ble_set_fem_voltage_trim(uint8_t channel, uint8_t value)
Set FEM Voltage GPIO values for a specific channel.
BLE_HCI_ERROR_LMP_RSP_TIMEOUT
Definition: ble_common.h:113
BLE_HCI_ERROR_UNKNOWN_LMP_PDU
Definition: ble_common.h:104
BLE_HCI_ERROR_UNSUPPORTED
Definition: ble_common.h:96
BLE_HCI_ERROR_CHANNEL_CLASS_NOT_SUP
Definition: ble_common.h:124
ble_evt_common
ble_evt_common
Common events.
Definition: ble_common.h:164
BLE_HCI_ERROR_TERMINATED_MIC_FAILURE
Definition: ble_common.h:137
BLE_EVT_CAT_FIRST
#define BLE_EVT_CAT_FIRST(CAT)
Definition: ble_common.h:153
BLE_HCI_ERROR_UNKNOWN_HCI_COMMAND
Definition: ble_common.h:80
ble_hci_error_t
ble_hci_error_t
Definition: ble_common.h:78
PUBLIC_ADDRESS
Definition: ble_common.h:179
BLE_HCI_ERROR_QOS_REJECTED
Definition: ble_common.h:123
BLE_HCI_ERROR_CONN_REJ_NO_SUITABLE_CHANNEL
Definition: ble_common.h:133
BLE_HCI_ERROR_MAC_CONNECTION_FAILED
Definition: ble_common.h:139
BLE_HCI_ERROR_UNSPECIFIED_ERROR
Definition: ble_common.h:110
BLE_HCI_ERROR_SP_NOT_SUPPORTED_HOST
Definition: ble_common.h:131
ble_address_to_string
const char * ble_address_to_string(const bd_address_t *address)
Convert bd_address to string.
BLE_HCI_ERROR_NO_ERROR
Definition: ble_common.h:79
BLE_HCI_ERROR_CONN_REJ_LIMITED_RESOURCES
Definition: ble_common.h:92
cmsis_compiler.h
CMSIS compiler generic header file.
BLE_HCI_ERROR_RESERVED_SLOT_VIOLATION
Definition: ble_common.h:128
BLE_HCI_ERROR_SCO_AIR_MODE_REJECTED
Definition: ble_common.h:108
ble_error_t
ble_error_t
Definition: ble_common.h:53
ble_enable
ble_error_t ble_enable(void)
Enable BLE module.
BLE_ERROR_NOT_CONNECTED
Definition: ble_common.h:60
BLE_HCI_ERROR_REPEATED_ATTEMPTS
Definition: ble_common.h:102
ble_status_t
ble_status_t
Definition: ble_common.h:170
BLE_HCI_ERROR_AUTH_FAILURE
Definition: ble_common.h:84
BLE_HCI_ERROR_SYNC_CON_LIMIT_DEV_EXCEED
Definition: ble_common.h:89
BLE_HCI_ERROR_CON_LIMIT_EXCEED
Definition: ble_common.h:88
ble_address_cmp
__STATIC_INLINE bool ble_address_cmp(const bd_address_t *addr1, const bd_address_t *addr2)
Compare two BD Addresses.
Definition: ble_common.h:350
irk_t
Definition: ble_common.h:217
BLE_ERROR_NOT_SUPPORTED_BY_PEER
Definition: ble_common.h:65
BLE_ERROR_BUSY
Definition: ble_common.h:63
BLE_HCI_ERROR_HOST_BUSY_PAIRING
Definition: ble_common.h:132
BLE_HCI_ERROR_PAIRING_WITH_UNIT_KEY_NOT_SUP
Definition: ble_common.h:120
PRIVATE_ADDRESS
Definition: ble_common.h:180
BLE_HCI_ERROR_MEMORY_CAPA_EXCEED
Definition: ble_common.h:86
BLE_HCI_ERROR_COMMAND_DISALLOWED
Definition: ble_common.h:91
bd_address
Definition: ble_common.h:195
BLE_ERROR_L2CAP_MTU_EXCEEDED
Definition: ble_common.h:71
BLE_ERROR_NOT_FOUND
Definition: ble_common.h:69
PUBLIC_STATIC_ADDRESS
Definition: ble_common.h:185