Skip to content

Commit d23a847

Browse files
bluetooth: service: HID service
* Add Bluetooth HID service. * Add HID keyboard sample. * Add HID mouse sample. Co-authored-by: Eivind Jølsgard <[email protected]> Signed-off-by: Emanuele Di Santo <[email protected]>
1 parent ca3ebce commit d23a847

File tree

14 files changed

+3062
-1
lines changed

14 files changed

+3062
-1
lines changed

include/bluetooth/services/ble_hids.h

Lines changed: 590 additions & 0 deletions
Large diffs are not rendered by default.

include/bluetooth/services/common.h

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include "ble_gap.h"
22
#include <ble.h>
33
#include <zephyr/sys/byteorder.h>
44

@@ -13,3 +13,72 @@ static inline uint16_t is_notification_enabled(const uint8_t *gatts_write_data)
1313
{ \
1414
.sm = ((x) >> 4) & 0xf, .lv = (x) & 0xf, \
1515
}
16+
17+
static inline bool ble_gap_conn_sec_mode_equal(const ble_gap_conn_sec_mode_t *a,
18+
const ble_gap_conn_sec_mode_t *b)
19+
{
20+
return (a->sm == b->sm) && (a->lv == b->lv);
21+
}
22+
23+
/**
24+
* @brief Set sec_mode to have no access rights.
25+
*/
26+
#define BLE_GAP_CONN_SEC_MODE_NO_ACCESS \
27+
(ble_gap_conn_sec_mode_t) \
28+
{ \
29+
.sm = 0, .lv = 0 \
30+
}
31+
32+
/**
33+
* @brief Set sec_mode to require no protection, open link.
34+
*/
35+
#define BLE_GAP_CONN_SEC_MODE_OPEN \
36+
(ble_gap_conn_sec_mode_t) \
37+
{ \
38+
.sm = 1, .lv = 1 \
39+
}
40+
41+
/**
42+
* @brief Set sec_mode to require encryption, but no MITM protection.
43+
*/
44+
#define BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM \
45+
(ble_gap_conn_sec_mode_t) \
46+
{ \
47+
.sm = 1, .lv = 2 \
48+
}
49+
50+
/**
51+
* @brief Set sec_mode to require encryption and MITM protection.
52+
*/
53+
#define BLE_GAP_CONN_SEC_MODE_ENC_WITH_MITM \
54+
(ble_gap_conn_sec_mode_t) \
55+
{ \
56+
.sm = 1, .lv = 3 \
57+
}
58+
59+
/**
60+
* @brief Set sec_mode to require LESC encryption and MITM protection.
61+
*/
62+
#define BLE_GAP_CONN_SEC_MODE_LESC_ENC_WITH_MITM \
63+
(ble_gap_conn_sec_mode_t) \
64+
{ \
65+
.sm = 1, .lv = 4 \
66+
}
67+
68+
/**
69+
* @brief Set sec_mode to require signing or encryption, no MITM protection needed.
70+
*/
71+
#define BLE_GAP_CONN_SEC_MODE_SIGNED_NO_MITM \
72+
(ble_gap_conn_sec_mode_t) \
73+
{ \
74+
.sm = 2, .lv = 1 \
75+
}
76+
77+
/**
78+
* @brief Set sec_mode to require signing or encryption with MITM protection.
79+
*/
80+
#define BLE_GAP_CONN_SEC_MODE_SIGNED_WITH_MITM \
81+
(ble_gap_conn_sec_mode_t) \
82+
{ \
83+
.sm = 2, .lv = 2 \
84+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(ble_hid_keyboard)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CONFIG_LOG=y
2+
CONFIG_LOG_MODE_MINIMAL=y
3+
CONFIG_CONSOLE=y
4+
CONFIG_LITE_UARTE_CONSOLE=y
5+
6+
CONFIG_SOFTDEVICE=y
7+
8+
CONFIG_BLE_ADV=y
9+
CONFIG_BLE_ADV_NAME="NCS-Lite HID Keyboard"
10+
CONFIG_BLE_ADV_EXTENDED_ADVERTISING=n
11+
CONFIG_BLE_ADV_DIRECTED_ADVERTISING=n
12+
13+
# BLE connection parameter
14+
CONFIG_BLE_CONN_PARAMS=y
15+
16+
# Device information service
17+
CONFIG_BLE_DIS=y
18+
CONFIG_BLE_DIS_SERIAL_NUMBER="ABCD"
19+
CONFIG_BLE_DIS_HW_REVISION="hw 54.15.0"
20+
CONFIG_BLE_DIS_FW_REVISION="fw 17.2.0"
21+
CONFIG_BLE_DIS_SW_REVISION="sw 1.0.0"
22+
23+
# Battery service
24+
CONFIG_BLE_BAS=y
25+
26+
# Buttons and timer
27+
CONFIG_LITE_TIMER=y
28+
CONFIG_LITE_BUTTONS=y
29+
30+
# HIDS service
31+
CONFIG_BLE_HIDS=y
32+
CONFIG_BLE_HIDS_BOOT_KEYBOARD=y
33+
CONFIG_BLE_HIDS_LOG_LEVEL_DBG=y
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sample:
2+
name: BLE HID Keyboard
3+
tests:
4+
sample.ble_hid_keyboard:
5+
sysbuild: true
6+
build_only: true
7+
integration_platforms:
8+
- lite_nrf54l15/nrf54l15/cpuapp
9+
platform_allow:
10+
- lite_nrf54l15/nrf54l15/cpuapp
11+
tags: ci_build

0 commit comments

Comments
 (0)