nRF Connect SDK Bare Metal API 2.0.99
Loading...
Searching...
No Matches
ble_bas.h
1/*
2 * Copyright (c) 2012 - 2024 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
12#ifndef BLE_BAS_H__
13#define BLE_BAS_H__
14
15#include <stdint.h>
16#include <stdbool.h>
17#include <ble.h>
18#include <bm/bluetooth/ble_common.h>
19#include <bm/softdevice_handler/nrf_sdh_ble.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
30#define BLE_BAS_DEF(_name) \
31 static struct ble_bas _name; \
32 NRF_SDH_BLE_OBSERVER(_name##_obs, ble_bas_on_ble_evt, &_name, HIGH)
33
35#define BLE_BAS_CONFIG_SEC_MODE_DEFAULT \
36 { \
37 .battery_lvl_char = { \
38 .read = BLE_GAP_CONN_SEC_MODE_OPEN, \
39 .cccd_write = BLE_GAP_CONN_SEC_MODE_OPEN, \
40 }, \
41 .battery_report_ref.read = BLE_GAP_CONN_SEC_MODE_OPEN, \
42 }
43
50#define BLE_BAS_BATTERY_LEVEL_LAST ((uint8_t)0xFF)
51
69
81 uint16_t conn_handle;
82 union {
84 struct {
86 uint32_t reason;
88 };
89};
90
91/* Forward declaration */
92struct ble_bas;
93
97typedef void (*ble_bas_evt_handler_t)(struct ble_bas *bas, const struct ble_bas_evt *evt);
98
113 struct {
120 uint8_t report_id;
124 uint8_t report_type;
135 struct {
137 struct {
139 ble_gap_conn_sec_mode_t read;
141 ble_gap_conn_sec_mode_t cccd_write;
144 struct {
146 ble_gap_conn_sec_mode_t read;
149};
150
180
195uint32_t ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *bas_config);
196
217uint32_t ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle,
218 uint8_t battery_level);
219
233void ble_bas_on_ble_evt(const ble_evt_t *ble_evt, void *ble_bas);
234
235#ifdef __cplusplus
236}
237#endif
238
239#endif /* BLE_BAS_H__ */
240
void ble_bas_on_ble_evt(const ble_evt_t *ble_evt, void *ble_bas)
Bluetooth LE event handler for the Battery Service.
uint32_t ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *bas_config)
Initialize the battery service.
void(* ble_bas_evt_handler_t)(struct ble_bas *bas, const struct ble_bas_evt *evt)
Battery service event handler type.
Definition ble_bas.h:97
uint32_t ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint8_t battery_level)
Update battery level.
ble_bas_evt_type
Battery service event types.
Definition ble_bas.h:55
@ BLE_BAS_EVT_NOTIFICATION_ENABLED
Battery level notification enabled.
Definition ble_bas.h:59
@ BLE_BAS_EVT_ERROR
Error event.
Definition ble_bas.h:67
@ BLE_BAS_EVT_NOTIFICATION_DISABLED
Battery level notification disabled.
Definition ble_bas.h:63
ble_bas_evt_handler_t evt_handler
Battery service event handler.
Definition ble_bas.h:106
struct ble_bas_config::@47::@48 battery_lvl_char
uint8_t report_type
Report type.
Definition ble_bas.h:124
bool can_notify
Allow notifications.
Definition ble_bas.h:129
uint8_t battery_level
Initial battery level.
Definition ble_bas.h:133
struct ble_bas_config::@47 sec_mode
ble_gap_conn_sec_mode_t cccd_write
Definition ble_bas.h:141
struct ble_bas_config::@47::@49 battery_report_ref
ble_gap_conn_sec_mode_t read
Definition ble_bas.h:139
uint8_t report_id
Report ID.
Definition ble_bas.h:120
struct ble_bas_config::@46 * report_ref
Report Reference Descriptor.
Battery service configuration.
Definition ble_bas.h:102
struct ble_bas_evt::@43::@45 error
uint16_t conn_handle
Connection handle for which the event applies.
Definition ble_bas.h:81
uint32_t reason
Definition ble_bas.h:86
enum ble_bas_evt_type evt_type
Event type.
Definition ble_bas.h:77
Battery service event.
Definition ble_bas.h:73
uint16_t report_ref_handle
Report reference descriptor handler.
Definition ble_bas.h:166
ble_bas_evt_handler_t evt_handler
Battery Service event handler.
Definition ble_bas.h:158
bool can_notify
Whether notifications of battery level changes are supported.
Definition ble_bas.h:178
uint8_t battery_level
Battery level.
Definition ble_bas.h:174
uint16_t service_handle
Battery service handle.
Definition ble_bas.h:162
ble_gatts_char_handles_t battery_level_handles
Battery level characteristic handles.
Definition ble_bas.h:170
Battery Service structure.
Definition ble_bas.h:154