Skip to content

Commit 1db87b8

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 0d44371 commit 1db87b8

File tree

19 files changed

+3266
-0
lines changed

19 files changed

+3266
-0
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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#ifndef BLE_SERVICES_COMMON_H__
88
#define BLE_SERVICES_COMMON_H__
99

10+
1011
#include <ble.h>
12+
#include <ble_gap.h>
1113
#include <zephyr/sys/byteorder.h>
1214

1315
#ifdef __cplusplus
@@ -34,6 +36,75 @@ static inline uint16_t is_indication_enabled(const uint8_t *gatts_write_data)
3436
.sm = ((x) >> 4) & 0xf, .lv = (x) & 0xf, \
3537
}
3638

39+
static inline bool ble_gap_conn_sec_mode_equal(const ble_gap_conn_sec_mode_t *a,
40+
const ble_gap_conn_sec_mode_t *b)
41+
{
42+
return (a->sm == b->sm) && (a->lv == b->lv);
43+
}
44+
45+
/**
46+
* @brief Set sec_mode to have no access rights.
47+
*/
48+
#define BLE_GAP_CONN_SEC_MODE_NO_ACCESS \
49+
(ble_gap_conn_sec_mode_t) \
50+
{ \
51+
.sm = 0, .lv = 0 \
52+
}
53+
54+
/**
55+
* @brief Set sec_mode to require no protection, open link.
56+
*/
57+
#define BLE_GAP_CONN_SEC_MODE_OPEN \
58+
(ble_gap_conn_sec_mode_t) \
59+
{ \
60+
.sm = 1, .lv = 1 \
61+
}
62+
63+
/**
64+
* @brief Set sec_mode to require encryption, but no MITM protection.
65+
*/
66+
#define BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM \
67+
(ble_gap_conn_sec_mode_t) \
68+
{ \
69+
.sm = 1, .lv = 2 \
70+
}
71+
72+
/**
73+
* @brief Set sec_mode to require encryption and MITM protection.
74+
*/
75+
#define BLE_GAP_CONN_SEC_MODE_ENC_WITH_MITM \
76+
(ble_gap_conn_sec_mode_t) \
77+
{ \
78+
.sm = 1, .lv = 3 \
79+
}
80+
81+
/**
82+
* @brief Set sec_mode to require LESC encryption and MITM protection.
83+
*/
84+
#define BLE_GAP_CONN_SEC_MODE_LESC_ENC_WITH_MITM \
85+
(ble_gap_conn_sec_mode_t) \
86+
{ \
87+
.sm = 1, .lv = 4 \
88+
}
89+
90+
/**
91+
* @brief Set sec_mode to require signing or encryption, no MITM protection needed.
92+
*/
93+
#define BLE_GAP_CONN_SEC_MODE_SIGNED_NO_MITM \
94+
(ble_gap_conn_sec_mode_t) \
95+
{ \
96+
.sm = 2, .lv = 1 \
97+
}
98+
99+
/**
100+
* @brief Set sec_mode to require signing or encryption with MITM protection.
101+
*/
102+
#define BLE_GAP_CONN_SEC_MODE_SIGNED_WITH_MITM \
103+
(ble_gap_conn_sec_mode_t) \
104+
{ \
105+
.sm = 2, .lv = 2 \
106+
}
107+
37108
#ifdef __cplusplus
38109
}
39110
#endif
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_hids_keyboard)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "BLE HIDS Keyboard sample"
8+
9+
module=BLE_HIDS_KEYBOARD_SAMPLE
10+
module-dep=LOG
11+
module-str=BLE HIDS Kayboard Sample
12+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
13+
14+
endmenu # "BLE HIDS Mouse sample"
15+
16+
source "Kconfig.zephyr"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
.. _ble_hids_keyboard_sample:
2+
3+
Bluetooth: Human Interface Device Service Keyboard
4+
##################################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Peripheral HIDS keyboard sample demonstrates how to use the Human Interface Device (HID) Service to implement a keyboard input device that you can connect to your computer.
11+
12+
Requirements
13+
************
14+
15+
The sample supports the following development kits:
16+
17+
.. list-table::
18+
:header-rows: 1
19+
20+
* - Hardware platform
21+
- PCA
22+
- SoftDevice
23+
- Board target
24+
* - `nRF54L15 DK`_
25+
- PCA10156
26+
- S115
27+
- bm_nrf54l15dk/nrf54l15/cpuapp/softdevice_s115
28+
* - `nRF54L15 DK`_ (emulating nRF54L10)
29+
- PCA10156
30+
- S115
31+
- bm_nrf54l15dk/nrf54l10/cpuapp/softdevice_s115
32+
* - `nRF54L15 DK`_ (emulating nRF54L05)
33+
- PCA10156
34+
- S115
35+
- bm_nrf54l15dk/nrf54l05/cpuapp/softdevice_s115
36+
37+
Overview
38+
********
39+
40+
The sample uses the buttons on a development kit to simulate keys on a keyboard.
41+
One button simulates the letter keys by generating letter keystrokes for a predefined string.
42+
A second button simulates the Shift button and shows how to modify the letter keystrokes.
43+
An LED displays the Caps Lock state, which can be modified by another connected keyboard. (TODO Match this behaviour from NCS sample)
44+
45+
This sample exposes the HID GATT Service. It uses a report map for a generic keyboard.
46+
47+
User interface
48+
**************
49+
50+
Button 0:
51+
Sends one character of the predefined input ("hello\\n") to the computer.
52+
53+
Button 1:
54+
Simulates the Shift key.
55+
56+
LED 0:
57+
Blinks with a period of two seconds with the duty cycle set to 50% when the main loop is running and the device is advertising.
58+
59+
LED 1:
60+
Lit when at least one device is connected.
61+
62+
LED 2:
63+
Indicates if Caps Lock is enabled.
64+
65+
Programming the S115 SoftDevice
66+
*******************************
67+
68+
.. include:: /includes/softdevice_flash.txt
69+
70+
.. _ble_hids_keyboard_sample_testing:
71+
72+
73+
Building and running
74+
********************
75+
76+
This sample can be found under :file:`samples/bluetooth/ble_hids_keyboard/` in the |BMshort| folder structure.
77+
78+
.. include:: /includes/create_sample.txt
79+
80+
.. include:: /includes/configure_and_build_sample.txt
81+
82+
.. include:: /includes/program_sample.txt
83+
84+
Testing
85+
=======
86+
87+
TODO
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
CONFIG_LOG=y
2+
CONFIG_LOG_BACKEND_BM_UARTE=y
3+
4+
CONFIG_BLE_ADV=y
5+
CONFIG_BLE_ADV_NAME="nRF_BM_HIDS_KB"
6+
CONFIG_BLE_ADV_EXTENDED_ADVERTISING=n
7+
CONFIG_BLE_ADV_DIRECTED_ADVERTISING=n
8+
9+
CONFIG_SOFTDEVICE=y
10+
CONFIG_NRF_SDH=y
11+
12+
# BLE connection parameter
13+
CONFIG_BLE_CONN_PARAMS=y
14+
15+
# Device information service
16+
CONFIG_BLE_DIS=y
17+
CONFIG_BLE_DIS_SERIAL_NUMBER="ABCD"
18+
CONFIG_BLE_DIS_HW_REVISION="hw 54.15.0"
19+
CONFIG_BLE_DIS_FW_REVISION="fw 17.2.0"
20+
CONFIG_BLE_DIS_SW_REVISION="sw 1.0.0"
21+
22+
# Battery service
23+
CONFIG_BLE_BAS=y
24+
25+
# Buttons and timer
26+
CONFIG_BM_TIMER=y
27+
CONFIG_BM_BUTTONS=y
28+
29+
# HIDS service
30+
CONFIG_BLE_HIDS=y
31+
CONFIG_BLE_HIDS_BOOT_KEYBOARD=y
32+
CONFIG_BLE_HIDS_LOG_LEVEL_DBG=y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sample:
2+
name: BLE HIDS Keyboard
3+
tests:
4+
sample.ble_hids_keyboard:
5+
sysbuild: true
6+
build_only: true
7+
integration_platforms:
8+
- bm_nrf54l15dk/nrf54l05/cpuapp/softdevice_s115
9+
- bm_nrf54l15dk/nrf54l10/cpuapp/softdevice_s115
10+
- bm_nrf54l15dk/nrf54l15/cpuapp/softdevice_s115
11+
platform_allow:
12+
- bm_nrf54l15dk/nrf54l05/cpuapp/softdevice_s115
13+
- bm_nrf54l15dk/nrf54l10/cpuapp/softdevice_s115
14+
- bm_nrf54l15dk/nrf54l15/cpuapp/softdevice_s115
15+
tags: ci_build

0 commit comments

Comments
 (0)