5.2.8 BLE HID over GATT Profile Service
The HID over GATT profile defines the procedures and features to be used by BLE HID devices using GATT and Bluetooth® HID Hosts using GATT. This profile is an adaptation of the USB HID specification to operate over a BLE wireless link.
The HID Over GATT Profile (HOGP) is a Bluetooth SIG (Special Interest Group) standard that defines how HID information is exposed and exchanged over the Generic Attribute (GATT) protocol in BLE. HOGP extends the capabilities of BLE devices to support HID functionality.
HOGP is built on top of the BLE protocol stack and uses GATT for communication. It leverages the GATT Server-Client architecture to enable HID devices to send and receive HID reports.
Recommended Readings
-
Getting Started with Application Building Blocks – See Building Block Examples from Related Links.
-
Getting Started with Peripheral Building Blocks – See Peripheral Devices from Related Links.
-
FreeRTOS and BLE Stack Setup – See Peripheral - FreeRTOS BLE Stack and App Initialize from Related Links.
-
BLE Software Specification – See MPLAB® Harmony Wireless BLE in Reference Documentation from Related Links.
Hardware Requirement
S. No. | Tool | Quantity |
---|---|---|
1 | PIC32-BZ6 Curiosity Board | 1 |
2 | Micro USB cable | 1 |
Current measured in Extreme Deep Sleep mode as per Wireless_ble v1.4.0 and Wireless_pic32cxbz_wbz v1.5.0 in A2 version of the PIC32WM-BZ6204UE module is around 131 nA.
SDK Setup
Refer to Getting Started with Software Development from Related Links.
Programming the Precompiled Hex File or Application Example
Using MPLAB® X IPE:
- Import and program the
precompiled hex file:
<Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\advanced_applications\ble_hogps_app\precompiled_hex
. - For detailed steps, refer to Programming a Device in MPLAB® IPE in Reference Documentation from Related Links.Note: Ensure to choose the correct Device and Tool information.
Using MPLAB® X IDE:
- Perform the following the steps mentioned in Running a Precompiled Example. For more information, refer to Running a Precompiled Application Example from Related Links.
- Open and program the application
ble_hogps_app.X
located in<Harmony Content Path>\wireless_apps_pic32_bz6\apps\ble\advanced_applications\ble_hogps_app\firmware\ble_hogps_app.X
. - For more details on how to find the Harmony Content Path, refer to Installing the MCC Plugin from Related Links.
Application Building Component
Below captured are the components used to create the HID Over GATT Profile Service application.
The MCC support the HID profile and services that helps to implement the HID feature. And also the other mandatory components listed earlier is also available as a drag and drop components in the MCC.
Role Descriptions
GATT Server Role
- One or more instances of HID Service
- One or more instances of battery services
- Single instance of device information service
- Optionally, one instance of Scan server role of Scan parameter profile.
GATT Clients, such as smartphones or computers, interact with HID devices by discovering and accessing HID services and characteristics. They initiate actions based on user input or requirements. It supports Scan Client role of the Scan parameter profile.
Pairing and Security
Security is crucial when dealing with HID devices, especially in scenarios where sensitive data may be transmitted.
The HID Host shall bond with the HID Device. The HID Host shall support LE Security Mode 1 and Security Level 2 and optionally Security Level 3.
Demo Description
The HID Over GATT Profile (HOGP) application on the Curiosity board simulates a keyboard and utilizes Device in a state machine. This guide will walk you through the application's key features, states, and interactions, allowing users to harness the power of HID technology on their curiosity board.
This application implements the HID over GATT profile, Human Interface Device Service, Battery Service and Device information in a peripheral role.
Working Flow
- Power OFF: The device is initially powered OFF.
- Power ON:
- Upon powering on, the device checks for the existence of pairing data.
- If pairing data
doesn't exist, the device enters the
APP_HOGPS_STATE_ADV
state with a timeout oftimeout_adv
seconds. - If a connection is
established within the timeout period, the following actions occur
on the computer's side:
- The device stores new pairing data.
- The device removes any previous pairing data if it exists.
- After successful
pairing, the device enters the
APP_HOGPS_STATE_CONN
state. - If the connection
fails to establish within the timeout, the device enters the
APP_HOGPS_STATE_IDLE
(Extreme Deep Sleep) state.
- Connected State
(
APP_HOGPS_STATE_CONN
):- Idle Timeout:
While in the connected state, if USR BTN2 is not pressed for 3
minutes, the device enters the
APP_HOGPS_STATE_IDLE
(Extreme Deep Sleep) state to conserve power. - Long Press USR
BTN2 : In the connected state, if USR BTN2 is
long-pressed:
- The device starts a new pairing process.
- The device enters the APP_HOGPS_STATE_ADV state.
- USR BTN2 Press (Device): In the connected state, pressing USR BTN2 on the device results in showing “abcde” as output.
- USR BTN2 Press (Computer): On the computer side, pressing Caps Lock while in the connected state shows either “capon” or “capof”.
- Connection
Termination: In the connected state, the following events
can lead to disconnection and state transitions:
- If the computer removes the device from its device list or turns OFF Bluetooth.
- If the device goes out of range.
- In either
case, the device enters the
APP_HOGPS_STATE_ADV_DIR
state with a timeout oftimeout_adv_dir
seconds.
- Idle Timeout:
While in the connected state, if USR BTN2 is not pressed for 3
minutes, the device enters the
- Reconnection State
(
APP_HOGPS_STATE_ADV_DIR
):- Long Press USR
BTN2: While in the
APP_HOGPS_STATE_ADV_DIR
, a long press of USR BTN2 by the device starts a new pairing process. - Connection Attempt
Result: Depending on the result of the connection
attempt:
- If the
connection is successful, the device transitions back to the
APP_HOGPS_STATE_CONN
state. - If the
connection attempt fails (for example, due to a timeout or
unsuccessful pairing), the device enters the
APP_HOGPS_STATE_IDLE
(Extreme Deep Sleep) state.
- If the
connection is successful, the device transitions back to the
- Long Press USR
BTN2: While in the
- Direct Transition with
Existing Pairing Data:
- Initial Power On
(With Existing Pairing Data): If pairing data already exists
during the initial power ON, the device directly enters the
APP_HOGPS_STATE_ADV_DIR
state without going through theAPP_HOGPS_STATE_ADV
state.
- Initial Power On
(With Existing Pairing Data): If pairing data already exists
during the initial power ON, the device directly enters the
States and their Descriptions
APP_HOGPS_STATE_IDLE:
In this state, the application enters Extreme Deep Sleep mode to minimize power consumption. It remains in this state when not actively engaged.APP_HOGPS_STATE_ADV:
When in this state, the application is waiting for pairing to occur, and it does so for a duration specified bytimeout_adv
(60 seconds by default).APP_HOGPS_STATE_ADV_DIR:
In this state, the application is waiting for reconnection and awaits the pairing process to start. The duration for this state is determined bytimeout_adv_dir
(30 seconds by default).APP_HOGPS_STATE_CONN:
The application enters this state when it is ready to send keys or receive events. It responds to USR BTN2 presses in this state.
USR BTN2 Interactions
- Press USR BTN2 (Short
Press) in
APP_HOGPS_STATE_CONN:
This action results in the display of “abcde” on the connected computer. It is a basic input action. - Long Press USR BTN2 in
APP_HOGPS_STATE_CONN:
A long press of USR BTN2 in the connected state leads to the disconnection of the device from the computer and initiates a new pairing process. - Long Press USR BTN2 in
APP_HOGPS_STATE_ADV_DIR:
A long press of USR BTN2 in theADV_DIR
state starts a new pairing process. - Press USR BTN2 in
APP_HOGPS_STATE_IDLE:
Pressing USR BTN2 in the Idle state wakes the device up from Extreme Deep Sleep mode.
LED Indications
APP_HOGPS_STATE_IDLE:
In this state, all LEDs are turned OFF to conserve power.APP_HOGPS_STATE_ADV:
A Green LED flashes once every 3 seconds, with an on-time of 50 ms and an off-time of 2950 ms.APP_HOGPS_STATE_ADV_DIR:
A Green LED flashes twice every 3 seconds, with an on-time of 50 ms and an off-time of 50 ms.APP_HOGPS_STATE_CONN:
A Green LED flashes twice every 1.5 seconds, with an on-time of 50 ms and an off-time of 150 ms.
Connection Timeout
The application is designed to terminate the connection and enter Extreme Deep Sleep mode if USR BTN2 is not pressed for 3 minutes during an active connection, likely to save power.
Testing
Environment Setup
- In the subsequent section, the term “the computer” refers to a Microsoft Windows 10 system.
- In the subsequent section, the PIC32-BZ6 Curiosity board is referred to as “the Curiosity board”.
Test 1: Establishing Connection and Simulating Keyboard Behavior
Objective: Demonstrate connection establishment, keyboard simulation, and reconnection with the curiosity board.
- On the computer:
- Remove the existing “Microchip Keyboard” pairing over BLE if it exists.
- On the PIC32-BZ6 Curiosity board:
- Compile and program the application.
- The curiosity board
will enter
APP_HOGPS_STATE_ADV
and wait for pairing fortimeout_adv
seconds.
- On the computer:
- Open Settings>Bluetooth & other devices>Add a device>Bluetooth.
- Click Microchip Keyboard to connect and pair with the PIC32-BZ6 Curiosity Board.
- On the PIC32-BZ6 Curiosity board:
- It will enter
APP_HOGPS_STATE_CONN
when the connection is established.
- It will enter
- On the computer:
- Open a text editor (for example, Notepad) and click the left mouse button to focus on it.
- On the PIC32-BZ6 Curiosity board:
- Press USR BTN2
- On the computer:
- The text editor will display “abcde”.
- Turn ON Caps Lock, and the text editor will display “CAPON”.
- On the PIC32-BZ6 Curiosity board:
- Press USR BTN2.
- On the computer:
- The text editor will display “ABCDE”.
- Turn OFF Caps Lock, and the text editor will display “capof”.
- On the PIC32-BZ6 Curiosity board:
- Unplug the USB cable to power OFF.
- On the computer:
- The status of “Microchip Keyboard” must show as “Paired” (disconnected).
- On the PIC32-BZ6 Curiosity board:
- Plug the USB cable to power ON
- The curiosity board enters
APP_HOGPS_STATE_ADV_DIR
and wait for reconnection fortimeout_adv_dir
seconds.
- On the computer:
- The status of “Microchip Keyboard” must show as “Connected”.
- On the PIC32-BZ6 Curiosity board:
- It enters
APP_HOGPS_STATE_CONN
once the reconnection is successful.
- It enters
Test 2: Reconnecting to the Curiosity Board
Objective: Demonstration on re-establishing a connection with the curiosity board after it has disconnected.
- On the PIC32-BZ6 Curiosity board:
- Move it far away from the computer to disconnect.
- The curiosity board
will enter
APP_HOGPS_STATE_ADV_DIR
and wait for reconnection fortimeout_adv_dir
seconds.
- On the computer:
- The status of “Microchip Keyboard” must show as “Paired”.
- On the PIC32-BZ6 Curiosity board:
- Move it close back to the computer and press USR BTN2 to wake it up.
- It will automatically reconnect to the computer after successful disconnection.
- The curiosity board will enter
APP_HOGPS_STATE_CONN
when the reconnection is successful.
- On the computer:
- The status of “Microchip Keyboard” must show as “Connected”.
Test 3: Removing and Redoing Pairing
Objective: Demonstration on the process of removal of existing pairing data and re-establishing the connection with the Curiosity board.
- On the computer:
- Remove the existing “Microchip Keyboard”.
- On the PIC32-BZ6 Curiosity board:
- Unplug the USB cable to power OFF.
- Plug the USB cable to power ON.
- The Curiosity board
enters
APP_HOGPS_STATE_ADV_DIR
and wait for reconnection fortimeout_adv_dir
seconds. - Long-press USR BTN2.
- On the computer:
- Open Settings>Bluetooth & other devices>Add a device>Bluetooth.
- Click Microchip Keyboard to connect and pair with the Curiosity board.
- On the PIC32-BZ6 Curiosity board:
- It will enter
APP_HOGPS_STATE_CONN
when the connection is established.
- It will enter
These testing procedures provide a step-by-step guide for validating the behavior of the curiosity board in different scenarios, including initial pairing, disconnection, reconnection, and pairing data removal.