nRF Connect SDK Bare Metal API 2.0.99
Loading...
Searching...
No Matches
ble_hrs.h
1/*
2 * Copyright (c) 2012 - 2024 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
12#ifndef BLE_HRS_H__
13#define BLE_HRS_H__
14
15#include <stdint.h>
16#include <stdbool.h>
17#include <ble.h>
18#include <bm/bluetooth/ble_conn_params.h>
19#include <bm/softdevice_handler/nrf_sdh_ble.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
30#define BLE_HRS_DEF(_name) \
31 static struct ble_hrs _name; \
32 NRF_SDH_BLE_OBSERVER(_name##_obs, ble_hrs_on_ble_evt, &_name, HIGH)
33
35#define BLE_HRS_CONFIG_SEC_MODE_DEFAULT \
36 { \
37 .hrm_char = { \
38 .cccd_write = BLE_GAP_CONN_SEC_MODE_OPEN, \
39 }, \
40 .bsl_char.read = BLE_GAP_CONN_SEC_MODE_OPEN, \
41 }
42
47#define BLE_HRS_BODY_SENSOR_LOCATION_OTHER 0
48#define BLE_HRS_BODY_SENSOR_LOCATION_CHEST 1
49#define BLE_HRS_BODY_SENSOR_LOCATION_WRIST 2
50#define BLE_HRS_BODY_SENSOR_LOCATION_FINGER 3
51#define BLE_HRS_BODY_SENSOR_LOCATION_HAND 4
52#define BLE_HRS_BODY_SENSOR_LOCATION_EAR_LOBE 5
53#define BLE_HRS_BODY_SENSOR_LOCATION_FOOT 6
73
85 uint16_t conn_handle;
86 union {
88 struct {
90 uint32_t reason;
92 };
93};
94
95/* Forward declaration */
96struct ble_hrs;
97
101typedef void (*ble_hrs_evt_handler_t)(struct ble_hrs *hrs, const struct ble_hrs_evt *evt);
102
122 struct {
126 struct {
131 ble_gap_conn_sec_mode_t cccd_write;
136 struct {
141 ble_gap_conn_sec_mode_t read;
144};
145
149struct ble_hrs {
163 uint16_t conn_handle;
167 ble_gatts_char_handles_t hrm_handles;
171 ble_gatts_char_handles_t bsl_handles;
176 uint16_t rr_interval[CONFIG_BLE_HRS_MAX_BUFFERED_RR_INTERVALS];
187 uint8_t max_hrm_len;
196};
197
211uint32_t ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *hrs_config);
212
221void ble_hrs_conn_params_evt(struct ble_hrs *hrs, const struct ble_conn_params_evt *conn_param_evt);
222
242uint32_t ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate);
243
257uint32_t ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval);
258
267
281 bool is_sensor_contact_supported);
282
293 bool is_sensor_contact_detected);
294
310uint32_t ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_location);
311
325void ble_hrs_on_ble_evt(const ble_evt_t *ble_evt, void *ble_hrs);
326
327#ifdef __cplusplus
328}
329#endif
330
331#endif /* BLE_HRS_H__ */
332
uint32_t ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval)
Function for adding a RR Interval measurement to the RR Interval buffer.
uint32_t ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_location)
Function for setting the Body Sensor Location.
bool ble_hrs_rr_interval_buffer_is_full(struct ble_hrs *hrs)
Function for checking if RR Interval buffer is full.
void ble_hrs_conn_params_evt(struct ble_hrs *hrs, const struct ble_conn_params_evt *conn_param_evt)
Connection parameters event handler.
uint32_t ble_hrs_sensor_contact_detected_update(struct ble_hrs *hrs, bool is_sensor_contact_detected)
Function for setting the state of the sensor contact detected bit.
ble_hrs_evt_type
Heart rate service event types.
Definition ble_hrs.h:59
@ BLE_HRS_EVT_NOTIFICATION_ENABLED
Heart rate value notification enabled.
Definition ble_hrs.h:63
@ BLE_HRS_EVT_NOTIFICATION_DISABLED
Heart rate value notifcation disabled.
Definition ble_hrs.h:67
@ BLE_HRS_EVT_ERROR
Error event.
Definition ble_hrs.h:71
uint32_t ble_hrs_sensor_contact_supported_set(struct ble_hrs *hrs, bool is_sensor_contact_supported)
Function for setting the state of the sensor contact supported bit.
uint32_t ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate)
Send a heart rate measurement notification.
uint32_t ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *hrs_config)
Initialize the heart rate service.
void ble_hrs_on_ble_evt(const ble_evt_t *ble_evt, void *ble_hrs)
Bluetooth LE event handler for the Heart Rate Service.
void(* ble_hrs_evt_handler_t)(struct ble_hrs *hrs, const struct ble_hrs_evt *evt)
Heart rate service event handler type.
Definition ble_hrs.h:101
Bluetooth LE connection parameter event.
Definition ble_conn_params.h:71
struct ble_hrs_config::@95::@97 bsl_char
Security requirement for the body sensor location characteristic.
ble_gap_conn_sec_mode_t cccd_write
Security requirement for writing the heart rate monitor characteristic CCCD.
Definition ble_hrs.h:131
ble_hrs_evt_handler_t evt_handler
Heart rate service event handler.
Definition ble_hrs.h:110
bool is_sensor_contact_supported
If sensor contact detection is to be supported or not.
Definition ble_hrs.h:114
ble_gap_conn_sec_mode_t read
Security requirement for reading the body sensor location characteristic value.
Definition ble_hrs.h:141
struct ble_hrs_config::@95 sec_mode
Security configuration.
struct ble_hrs_config::@95::@96 hrm_char
Security requirement for the heart rate monitor characteristic.
uint8_t * body_sensor_location
Initial value of the Body Sensor Location characteristic, if not NULL.
Definition ble_hrs.h:118
Heart rate service configuration.
Definition ble_hrs.h:106
uint32_t reason
Definition ble_hrs.h:90
struct ble_hrs_evt::@92::@94 error
uint16_t conn_handle
Connection handle for which the event applies.
Definition ble_hrs.h:85
enum ble_hrs_evt_type evt_type
Event type.
Definition ble_hrs.h:81
Heart rate service event.
Definition ble_hrs.h:77
uint16_t service_handle
Heart rate service handle.
Definition ble_hrs.h:157
bool is_sensor_contact_detected
Whether sensor contact has been detected.
Definition ble_hrs.h:195
uint16_t conn_handle
Handle of the current connection.
Definition ble_hrs.h:163
ble_hrs_evt_handler_t evt_handler
Heart rate service event handler.
Definition ble_hrs.h:153
ble_gatts_char_handles_t hrm_handles
Handles related to the heart rate measurement characteristic.
Definition ble_hrs.h:167
uint16_t rr_interval_count
Number of RR interval measurements since the last heart rate measurement transmission.
Definition ble_hrs.h:181
ble_gatts_char_handles_t bsl_handles
Handles related to the body sensor location characteristic.
Definition ble_hrs.h:171
bool is_sensor_contact_supported
Whether sensor contact detection is supported or not.
Definition ble_hrs.h:191
uint8_t max_hrm_len
Current maximum heart rate measurement length.
Definition ble_hrs.h:187
uint16_t rr_interval[CONFIG_BLE_HRS_MAX_BUFFERED_RR_INTERVALS]
Set of RR interval measurements since the last heart rate measurement transmission.
Definition ble_hrs.h:176
Heart rate service structure.
Definition ble_hrs.h:149