Skip to content

Commit 3e7ac70

Browse files
committed
samples: bluetooth: classic: add HID Device mouse sample
Add a Bluetooth Classic HID Device sample that demonstrates a mouse peripheral. The sample registers an SDP HID service record with a standard mouse report descriptor (3 buttons + X/Y + wheel), waits for an incoming HID Host connection, and sends periodic input reports simulating circular cursor movement at 10 Hz. Features demonstrated: - HID Device callback registration and SDP service setup - Boot Protocol and Report Protocol mode support - Get_Report, Set_Report and Set_Protocol request handling - Periodic input report transmission on the interrupt channel - Suspend/Exit-Suspend and Virtual Cable Unplug handling Tested with a real USB HCI dongle (CSR 4.2) on native_sim, verified end-to-end with an Android phone as HID Host. Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
1 parent d806fc8 commit 3e7ac70

5 files changed

Lines changed: 751 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.28.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(hid_device)
6+
7+
target_sources(app PRIVATE src/main.c)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.. zephyr:code-sample:: bluetooth_hid_device
2+
:name: Bluetooth: HID Device (Mouse)
3+
:relevant-api: bt_hid_device
4+
5+
Demonstrate a Bluetooth Classic HID Device acting as a mouse.
6+
7+
Overview
8+
********
9+
10+
This sample implements a Bluetooth Classic HID Device (mouse) that
11+
advertises itself via SDP and waits for an incoming HID Host connection.
12+
Once connected, it periodically sends mouse input reports simulating
13+
circular cursor movement.
14+
15+
The sample demonstrates:
16+
17+
- Registering HID Device callbacks and the HID SDP service record
18+
- Handling Get_Report, Set_Report and Set_Protocol requests
19+
- Sending periodic input reports on the interrupt channel
20+
- Boot Protocol and Report Protocol mode support
21+
- Suspend/Exit-Suspend and Virtual Cable Unplug handling
22+
23+
Get_Protocol is answered by the host stack and needs no application
24+
callback.
25+
26+
Requirements
27+
************
28+
29+
- A board with Bluetooth BR/EDR support
30+
- A Bluetooth HID Host (e.g., a PC or phone) to connect to the device
31+
32+
Building and Running
33+
********************
34+
35+
.. zephyr-app-commands::
36+
:zephyr-app: samples/bluetooth/classic/hid_device
37+
:board: <board>
38+
:goals: build flash
39+
:compact:
40+
41+
After flashing, the device will initialize Bluetooth, register the HID
42+
service, and become discoverable. Pair with it from a HID Host to see
43+
the mouse cursor move in a circle.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_CLASSIC=y
3+
CONFIG_BT_HID_DEVICE=y
4+
CONFIG_BT_DEVICE_NAME="hid-mouse"
5+
CONFIG_BT_COD=0x002580
6+
CONFIG_BT_PAGE_TIMEOUT=0xFFFF

0 commit comments

Comments
 (0)