Smart Remote 3 nRF52 v1.2
Copy URL
Source
Modules
m_coms_ble.h
1
/*$$$LICENCE_NORDIC_STANDARD<2016>$$$*/
2
11
#ifndef __M_COMS_BLE_H__
12
#define __M_COMS_BLE_H__
13
14
#include <stdbool.h>
15
#include <stdint.h>
16
17
#include "app_scheduler.h"
18
#include "app_util.h"
19
#include "ble_types.h"
20
#include "ble_hids.h"
21
#include "ble_gap.h"
22
#include "ble_gatts.h"
23
#include "peer_manager.h"
24
25
struct
ble_hid_db_s
;
26
27
#define BOOT_KEYBOARD_LEN 8
30
typedef enum
31
{
32
M_COMS_BLE_EVT_CONNECTED
,
33
M_COMS_BLE_EVT_DISCONNECTED
,
34
M_COMS_BLE_EVT_DATA_RECEIVED
,
35
M_COMS_BLE_EVT_READ_REQ
,
36
M_COMS_BLE_EVT_CONN_UPDATE
,
37
M_COMS_BLE_EVT_CONN_SECURED
,
38
M_COMS_BLE_EVT_ADV
,
39
M_COMS_BLE_EVT_ADV_BONDABLE
,
40
M_COMS_BLE_EVT_ADV_TIMEOUT
,
41
M_COMS_BLE_EVT_ADDR_CHANGED
,
42
M_COMS_BLE_EVT_PASSKEY_REQ
,
43
M_COMS_BLE_EVT_OOBKEY_REQ
,
44
M_COMS_BLE_EVT_ALERT
,
45
M_COMS_BLE_EVT_TX_COMPLETE
,
46
M_COMS_BLE_EVT_MTU_CHANGED
,
47
M_COMS_BLE_EVT_SHUTDOWN
48
}
m_coms_ble_evt_type_t
;
49
51
typedef
struct
52
{
53
uint8_t
interface_idx
;
54
uint8_t
report_type
;
55
uint8_t
report_idx
;
56
uint8_t
len
;
57
uint8_t *
data
;
58
}
m_coms_ble_evt_data_recv_t
;
59
61
typedef
struct
62
{
63
uint8_t
interface_idx
;
64
uint8_t
report_idx
;
65
}
m_coms_ble_evt_read_req_t
;
66
68
typedef
struct
69
{
70
uint16_t
min_conn_interval
;
71
uint16_t
max_conn_interval
;
72
uint16_t
slave_latency
;
73
uint16_t
supervision_timeout
;
74
}
m_coms_ble_evt_conn_update_t
;
75
77
typedef
struct
78
{
79
uint8_t
level
;
80
uint16_t
conn_handle
;
81
}
m_coms_ble_evt_alert_t
;
82
84
typedef
struct
85
{
86
uint8_t
count
;
87
}
m_coms_ble_evt_tx_complete_t
;
88
90
typedef
struct
91
{
92
uint8_t
effective_mtu
;
93
}
m_coms_ble_evt_mtu_changed_t
;
94
96
typedef
struct
97
{
98
uint16_t
conn_handle
;
99
pm_peer_id_t
peer_id
;
100
}
m_coms_ble_evt_conn_data_t
;
101
103
typedef
struct
104
{
105
pm_peer_id_t
peer_id
;
106
}
m_coms_ble_evt_adv_data_t
;
107
109
typedef
struct
110
{
111
m_coms_ble_evt_type_t
type;
112
union
113
{
114
m_coms_ble_evt_data_recv_t
data_received;
115
m_coms_ble_evt_read_req_t
read_req;
116
m_coms_ble_evt_conn_update_t
conn_update;
117
m_coms_ble_evt_alert_t
alert;
118
m_coms_ble_evt_tx_complete_t
tx_complete;
119
m_coms_ble_evt_mtu_changed_t
mtu_changed;
120
m_coms_ble_evt_conn_data_t
conn_data;
121
m_coms_ble_evt_adv_data_t
adv_data;
122
} data;
123
}
m_coms_ble_evt_t
;
124
129
typedef
enum
130
{
131
ble_boot_pkt_keyboard
= 0x01,
132
ble_boot_pkt_mouse
= 0x02,
133
ble_boot_pkt_none
= 0x80,
134
}
m_coms_ble_hid_boot_type_t
;
135
137
typedef
enum
138
{
139
hid_report_type_input = BLE_HIDS_REP_TYPE_INPUT,
140
hid_report_type_output = BLE_HIDS_REP_TYPE_OUTPUT,
141
hid_report_type_feature = BLE_HIDS_REP_TYPE_FEATURE
142
}
m_coms_hid_report_type_t
;
143
147
typedef
union
148
{
149
struct
150
{
151
uint8_t keys[BOOT_KEYBOARD_LEN];
152
} keyboard_data;
153
struct
154
{
155
uint8_t
buttons
;
156
int8_t
x_delta
;
157
int8_t
y_delta
;
158
} mouse_data;
159
}
m_coms_hid_boot_pkt_t
;
160
173
typedef
void (*
m_coms_ble_boot_mode_callback
)(
m_coms_hid_boot_pkt_t
* p_boot_pkt,
174
m_coms_ble_hid_boot_type_t
* p_pkt_type,
175
const
uint8_t * p_data,
176
uint8_t p_len,
177
uint8_t p_hid_interface,
178
uint8_t p_report_idx);
179
181
typedef
struct
182
{
183
uint16_t
interval
;
184
uint16_t
timeout
;
185
}
m_coms_ble_adv_params_t
;
186
188
typedef
struct
189
{
190
bool
directed_adv;
192
bool
change_address
;
193
bool
reconnect_all
;
195
bool
bond_reconnect_all
;
197
}
m_coms_ble_bond_params_t
;
198
200
typedef
struct
201
{
202
uint8_t
io_capabilities
;
203
}
m_coms_ble_sec_params_t
;
204
210
typedef
struct
211
{
212
char
*
device_name
;
213
char
*
manufacturer_name
;
214
char
*
hw_revision
;
215
char
*
fw_revision
;
216
char
*
serial_number
;
217
uint16_t
pnp_vendor_id
;
218
uint8_t
pnp_vendor_id_src
;
219
uint16_t
pnp_product_id
;
220
uint16_t
pnp_product_version
;
221
}
m_coms_ble_device_info_t
;
222
224
typedef
struct
225
{
226
m_coms_ble_device_info_t
device_info
;
227
m_coms_ble_adv_params_t
adv_params
;
228
m_coms_ble_bond_params_t
bond_params
;
229
m_coms_ble_sec_params_t
sec_params
;
230
uint16_t
appearance
;
231
ble_gap_conn_params_t
conn_params
;
233
uint16_t
base_hid_version
;
234
uint8_t
hid_country_code
;
235
uint8_t
hids_flags
;
237
app_sched_event_handler_t
event_handler
;
238
m_coms_ble_boot_mode_callback
boot_mode_callback
;
239
}
m_coms_ble_params_t
;
240
257
ret_code_t
m_coms_ble_init
(
const
m_coms_ble_params_t
* p_ble_params,
258
const
struct
ble_hid_db_s
* p_hid_db,
259
bool
delete_bonds);
260
271
ret_code_t
m_coms_ble_oobkey_set
(uint8_t * p_key);
272
284
ret_code_t
m_coms_ble_bonding_start
(
void
);
285
300
ret_code_t
m_coms_ble_hid_report_send
(uint8_t * p_data,
301
uint8_t p_len,
302
uint8_t p_hid_interface,
303
uint8_t p_report_idx);
304
314
ret_code_t
m_coms_ble_read_respond
(uint8_t *p_data, uint8_t p_len);
315
323
ret_code_t
m_coms_ble_battery_level_update
(uint8_t p_batt_level);
324
333
ret_code_t
m_coms_ble_disconnect
(
void
);
334
342
ret_code_t
m_coms_ble_shutdown
(
void
);
343
350
bool
m_coms_ble_bond_stored
(
void
);
351
357
ret_code_t
m_coms_ble_bond_clear
(
void
);
358
365
ret_code_t
m_coms_ble_advertise
(
bool
bondable);
366
370
ret_code_t
m_coms_ble_sl_disable
(
void
);
371
375
ret_code_t
m_coms_ble_sl_enable
(
void
);
376
377
#endif
/* __M_COMS_BLE_H__ */
378