nRF Connect SDK Bare Metal API 2.0.99
Loading...
Searching...
No Matches
ble_lbs.h
1/*
2 * Copyright (c) 2013 - 2025 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
12#ifndef BLE_LBS_H__
13#define BLE_LBS_H__
14
15#include <stdint.h>
16#include <ble.h>
17#include <bm/bluetooth/ble_common.h>
18#include <bm/softdevice_handler/nrf_sdh_ble.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define BLE_UUID_LBS_BASE { 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, \
25 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00 }
26#define BLE_UUID_LBS_SERVICE 0x1523
27#define BLE_UUID_LBS_BUTTON_CHAR 0x1524
28#define BLE_UUID_LBS_LED_CHAR 0x1525
29
30/* Forward declaration */
31struct ble_lbs;
32
38#define BLE_LBS_DEF(_name) \
39 static struct ble_lbs _name; \
40 NRF_SDH_BLE_OBSERVER(_name##_obs, ble_lbs_on_ble_evt, &_name, HIGH)
41
43#define BLE_LBS_CONFIG_SEC_MODE_DEFAULT \
44 { \
45 .lbs_button_char = { \
46 .read = BLE_GAP_CONN_SEC_MODE_OPEN, \
47 .cccd_write = BLE_GAP_CONN_SEC_MODE_OPEN, \
48 }, \
49 .lbs_led_char = { \
50 .read = BLE_GAP_CONN_SEC_MODE_OPEN, \
51 .write = BLE_GAP_CONN_SEC_MODE_OPEN, \
52 }, \
53 }
54
65
71 uint16_t conn_handle;
72 union {
74 struct {
76 uint8_t value;
79 struct {
81 uint32_t reason;
83 };
84};
85
87typedef void (*lbs_evt_handler_t)(struct ble_lbs *lbs, const struct ble_lbs_evt *lbs_evt);
88
97 struct {
99 struct {
101 ble_gap_conn_sec_mode_t read;
103 ble_gap_conn_sec_mode_t cccd_write;
105 struct {
107 ble_gap_conn_sec_mode_t read;
109 ble_gap_conn_sec_mode_t write;
112};
113
117struct ble_lbs {
121 ble_gatts_char_handles_t led_char_handles;
123 ble_gatts_char_handles_t button_char_handles;
125 uint8_t uuid_type;
128};
129
146uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg);
147
161void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *ble_lbs);
162
177uint32_t ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state);
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif /* BLE_LBS_H__ */
184
void(* lbs_evt_handler_t)(struct ble_lbs *lbs, const struct ble_lbs_evt *lbs_evt)
LED button Service event handler.
Definition ble_lbs.h:87
uint32_t ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state)
Function for sending a button state notification.
ble_lbs_evt_type
Definition ble_lbs.h:55
@ BLE_LBS_EVT_LED_WRITE
LED write event.
Definition ble_lbs.h:59
@ BLE_LBS_EVT_ERROR
Error event.
Definition ble_lbs.h:63
void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *ble_lbs)
Bluetooth LE event handler for the LED Button Service.
uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
Function for initializing the LED Button Service.
ble_gap_conn_sec_mode_t write
Definition ble_lbs.h:109
struct ble_lbs_config::@106 sec_mode
ble_gap_conn_sec_mode_t read
Definition ble_lbs.h:101
lbs_evt_handler_t evt_handler
Event handler to be called when the LED Characteristic is written.
Definition ble_lbs.h:95
struct ble_lbs_config::@106::@107 lbs_button_char
ble_gap_conn_sec_mode_t cccd_write
Definition ble_lbs.h:103
struct ble_lbs_config::@106::@108 lbs_led_char
LED Button Service init structure. This structure contains all options and data needed for initializa...
Definition ble_lbs.h:93
uint8_t value
Definition ble_lbs.h:76
struct ble_lbs_evt::@102::@105 error
enum ble_lbs_evt_type evt_type
Definition ble_lbs.h:67
struct ble_lbs_evt::@102::@104 led_write
uint32_t reason
Definition ble_lbs.h:81
uint16_t conn_handle
Connection handle for which the event applies.
Definition ble_lbs.h:71
Definition ble_lbs.h:66
ble_gatts_char_handles_t button_char_handles
Handles related to the Button Characteristic.
Definition ble_lbs.h:123
uint8_t uuid_type
UUID type for the LED Button Service.
Definition ble_lbs.h:125
lbs_evt_handler_t evt_handler
Event handler to be called when the LED Characteristic is written.
Definition ble_lbs.h:127
ble_gatts_char_handles_t led_char_handles
Handles related to the LED Characteristic.
Definition ble_lbs.h:121
uint16_t service_handle
Handle of LED Button Service (as provided by the Bluetooth LE stack).
Definition ble_lbs.h:119
Bluetooth LE Button Service structure.
Definition ble_lbs.h:117