fix(ble): Fix HID BLE permissions, add examples and fix characteristic handle#12260
Conversation
👋 Hello lucasssvaz, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Test Results 90 files 90 suites 33m 42s ⏱️ Results for commit 10e6aba. ♻️ This comment has been updated with latest results. |
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
aed191c to
aadf360
Compare
aadf360 to
fb73892
Compare
fb73892 to
4f7839e
Compare
There was a problem hiding this comment.
Pull request overview
This pull request enhances the BLE HID implementation to ensure compliance with the HID over GATT Profile (HOGP) specification and adds comprehensive gamepad examples demonstrating BLE HID functionality on ESP32. The changes address permission requirements for HID enumeration, improve callback robustness, optimize characteristic lookup, and provide well-documented examples for both server and client implementations.
Changes:
- Fixed HID descriptor and CCCD permissions to allow enumeration without encryption per HOGP specification
- Added
isStarted()method to BLEServer to safely check server state before notifications - Added null pointer checks in BLEDescriptor callbacks to prevent potential crashes
- Optimized BLEClient notification handling using handle-based characteristic lookup
- Added comprehensive BLE HID gamepad server and client examples with CI configuration
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/BLE/src/BLEServer.h | Added isStarted() method declaration |
| libraries/BLE/src/BLEServer.cpp | Implemented isStarted() method with documentation |
| libraries/BLE/src/BLEHIDDevice.h | Added private m_server member variable |
| libraries/BLE/src/BLEHIDDevice.cpp | Fixed HOGP compliance by adjusting permissions, added server pointer initialization, conditional battery notification |
| libraries/BLE/src/BLEDescriptor.cpp | Added null pointer checks before invoking callbacks |
| libraries/BLE/src/BLEClient.cpp | Optimized characteristic lookup using handle-based map for O(log n) performance |
| libraries/BLE/examples/Server_Gamepad/Server_Gamepad.ino | New comprehensive BLE HID gamepad server example with secure pairing |
| libraries/BLE/examples/Server_Gamepad/ci.yml | CI configuration for gamepad server example |
| libraries/BLE/examples/Client_Gamepad/Client_Gamepad.ino | New BLE HID gamepad client example with report parsing |
| libraries/BLE/examples/Client_Gamepad/ci.yml | CI configuration for gamepad client example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description of Change
This pull request adds robust BLE HID Gamepad client and server examples for ESP32, and improves the BLE HID implementation for better compatibility with the HID over GATT Profile (HOGP) specification. The changes ensure that HID report characteristics and descriptors are accessible as required for enumeration and pairing, and enhance the reliability of BLE descriptor callbacks.
New BLE HID Gamepad Examples:
Server_Gamepad.ino) that implements an 8-button, 2-axis gamepad with secure pairing, battery reporting, and automatic reconnection.Client_Gamepad.ino) that scans for HID gamepads, connects, and displays input reports in the serial monitor.BLE HID Device Implementation Improvements:
BLEHIDDevice.cppso that Report Reference Descriptors and Client Characteristic Configuration Descriptors (CCCD) are readable and writable without encryption, as required by the HID over GATT Profile for device enumeration and notification enabling. [1] [2] [3] [4]BLEHIDDeviceconstructor.Descriptor Callback Robustness:
onReadandonWritecallbacks, preventing potential crashes. [1] [2]Summary of Most Important Changes:
1. New BLE HID Gamepad Examples
Server_Gamepad.inoandClient_Gamepad.inoto demonstrate BLE HID gamepad server and client functionality, including secure pairing, HID report handling, and user-friendly serial output. [1] [2]2. BLE HID Device API and HID Compliance
BLEHIDDevice.cppso HID report characteristics and descriptors (including Report Reference and CCCD) are readable/writable without encryption, as required for HID device discovery and notification enabling, ensuring compatibility with standard HID hosts. [1] [2] [3] [4]BLEHIDDeviceconstructor for correct internal usage.3. BLE Descriptor Callback Safety
onReadandonWritecallbacks inBLEDescriptor.cppto prevent crashes if callbacks are not set. [1] [2]Test Scenarios
Tested locally with ESP32-C6 and ESP32
Related links
#8838