Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
590 changes: 590 additions & 0 deletions include/bluetooth/services/ble_hids.h

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions include/bluetooth/services/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#ifndef BLE_SERVICES_COMMON_H__
#define BLE_SERVICES_COMMON_H__


#include <ble.h>
#include <ble_gap.h>
#include <zephyr/sys/byteorder.h>

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

static inline bool ble_gap_conn_sec_mode_equal(const ble_gap_conn_sec_mode_t *a,
const ble_gap_conn_sec_mode_t *b)
{
return (a->sm == b->sm) && (a->lv == b->lv);
}

/**
* @brief Set sec_mode to have no access rights.
*/
#define BLE_GAP_CONN_SEC_MODE_NO_ACCESS \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 0, .lv = 0 \
}

/**
* @brief Set sec_mode to require no protection, open link.
*/
#define BLE_GAP_CONN_SEC_MODE_OPEN \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 1, .lv = 1 \
}

/**
* @brief Set sec_mode to require encryption, but no MITM protection.
*/
#define BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 1, .lv = 2 \
}

/**
* @brief Set sec_mode to require encryption and MITM protection.
*/
#define BLE_GAP_CONN_SEC_MODE_ENC_WITH_MITM \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 1, .lv = 3 \
}

/**
* @brief Set sec_mode to require LESC encryption and MITM protection.
*/
#define BLE_GAP_CONN_SEC_MODE_LESC_ENC_WITH_MITM \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 1, .lv = 4 \
}

/**
* @brief Set sec_mode to require signing or encryption, no MITM protection needed.
*/
#define BLE_GAP_CONN_SEC_MODE_SIGNED_NO_MITM \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 2, .lv = 1 \
}

/**
* @brief Set sec_mode to require signing or encryption with MITM protection.
*/
#define BLE_GAP_CONN_SEC_MODE_SIGNED_WITH_MITM \
(ble_gap_conn_sec_mode_t) \
{ \
.sm = 2, .lv = 2 \
}

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 12 additions & 0 deletions samples/bluetooth/ble_hids_keyboard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ble_hids_keyboard)

target_sources(app PRIVATE src/main.c)
16 changes: 16 additions & 0 deletions samples/bluetooth/ble_hids_keyboard/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "BLE HIDS Keyboard sample"

module=BLE_HIDS_KEYBOARD_SAMPLE
module-dep=LOG
module-str=BLE HIDS Kayboard Sample
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

endmenu # "BLE HIDS Mouse sample"

source "Kconfig.zephyr"
88 changes: 88 additions & 0 deletions samples/bluetooth/ble_hids_keyboard/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.. _ble_hids_keyboard_sample:

Bluetooth: Human Interface Device Service Keyboard
##################################################

.. contents::
:local:
:depth: 2

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.

Requirements
************

The sample supports the following development kits:

.. list-table::
:header-rows: 1

* - Hardware platform
- PCA
- SoftDevice
- Board target
* - `nRF54L15 DK`_
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l15/cpuapp/softdevice_s115
* - `nRF54L15 DK`_ (emulating nRF54L10)
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l10/cpuapp/softdevice_s115
* - `nRF54L15 DK`_ (emulating nRF54L05)
- PCA10156
- S115
- bm_nrf54l15dk/nrf54l05/cpuapp/softdevice_s115

Overview
********

The sample uses the buttons on a development kit to simulate keys on a keyboard.
One button simulates the letter keys by generating letter keystrokes for a predefined string.
A second button simulates the Shift button and shows how to modify the letter keystrokes.
An LED displays the Caps Lock state, which can be modified by another connected keyboard.

This sample exposes the HID GATT Service.
It uses a report map for a generic keyboard.

User interface
**************

Button 0:
Sends one character of the predefined input ("hello\\n") to the computer.

Button 1:
Simulates the Shift key.

LED 0:
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.

LED 1:
Lit when at least one device is connected.

LED 2:
Indicates if Caps Lock is enabled.

Programming the S115 SoftDevice
*******************************

.. include:: /includes/softdevice_flash.txt

.. _ble_hids_keyboard_sample_testing:


Building and running
********************

This sample can be found under :file:`samples/bluetooth/ble_hids_keyboard/` in the |BMshort| folder structure.

.. include:: /includes/create_sample.txt

.. include:: /includes/configure_and_build_sample.txt

.. include:: /includes/program_sample.txt

Testing
=======

TODO
37 changes: 37 additions & 0 deletions samples/bluetooth/ble_hids_keyboard/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CONFIG_LOG=y
CONFIG_LOG_BACKEND_BM_UARTE=y

CONFIG_BLE_ADV=y
CONFIG_BLE_ADV_NAME="nRF_BM_HIDS_KB"
CONFIG_BLE_ADV_EXTENDED_ADVERTISING=n
CONFIG_BLE_ADV_DIRECTED_ADVERTISING=n

CONFIG_SOFTDEVICE=y
CONFIG_NRF_SDH=y

# Enable RNG
CONFIG_NRF_SECURITY=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_PSA_WANT_GENERATE_RANDOM=y

# BLE connection parameter
CONFIG_BLE_CONN_PARAMS=y

# Device information service
CONFIG_BLE_DIS=y
CONFIG_BLE_DIS_SERIAL_NUMBER="ABCD"
CONFIG_BLE_DIS_HW_REVISION="hw 54.15.0"
CONFIG_BLE_DIS_FW_REVISION="fw 17.2.0"
CONFIG_BLE_DIS_SW_REVISION="sw 1.0.0"

# Battery service
CONFIG_BLE_BAS=y

# Buttons and timer
CONFIG_BM_TIMER=y
CONFIG_BM_BUTTONS=y

# HIDS service
CONFIG_BLE_HIDS=y
CONFIG_BLE_HIDS_BOOT_KEYBOARD=y
CONFIG_BLE_HIDS_LOG_LEVEL_DBG=y
15 changes: 15 additions & 0 deletions samples/bluetooth/ble_hids_keyboard/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sample:
name: BLE HIDS Keyboard
tests:
sample.ble_hids_keyboard:
sysbuild: true
build_only: true
integration_platforms:
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
platform_allow:
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
tags: ci_build
Loading
Loading