4.2.8 BLE HID over GATT Profile Service

Getting Started

Getting Started with Peripheral Building Blocks

Introduction

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.

Hardware Requirement

Table 4-54. Hardware Requirement
Tool Qty
WBZ351 Curiosity Board1
Micro USB cable1

Current measured in Extreme Deep Sleep mode as per Wireless_ble v 1.1.0 and Wireless_pic32cxbz_wbz v1.2.0 in A2 version of the WBZ351 module is around 131 nA.

Figure 4-248. Extreme Deep Sleep mode Current Measurement

SDK Setup

Programming the Precompiled Hex File or Application Example

Programming the .hex File using MPLAB X IPE:

  1. Precompiled .hex file is located in <Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\advanced_applications\ble_hogps_app\hex folder.
  2. Follow the steps mentioned here.
Note: Users must choose the correct device and tool information.

Programming the Application using MPLAB X IDE:

  1. Follow steps mentioned in the Running a Precompiled Example section.
  2. Open and program the application example ble_hogps_app.X located in <Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\advanced_applications\ble_hogps_app\firmware\ble_hogps_app.X using MPLAB X IDE.

For more details on finding the Harmony content path, refer to Installing the MCC Plugin.

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

In the context of HOGP, the GATT Server role is typically assumed by the HID device. The GATT Server exposes HID services and characteristics, making the device accessible to GATT Clients. It supports
  • 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 Client Role

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

Initial Power OFF and ON:
  • 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 of timeout_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 Button 1 is not pressed for 3 minutes, the device enters the APP_HOGPS_STATE_IDLE (Extreme Deep Sleep) state to conserve power.
    • Long Press Button 1: In the connected state, if Button 1 is long-pressed:
      • The device starts a new pairing process.
      • The device enters the APP_HOGPS_STATE_ADV state.
    • Button 1 Press (Device): In the connected state, pressing Button 1 on the device results in showing "abcde" as output.
    • Button 1 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 of timeout_adv_dir seconds.
  • Reconnection State (APP_HOGPS_STATE_ADV_DIR):
    • Long Press Button 1: While in the APP_HOGPS_STATE_ADV_DIR, a long press of Button 1 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.
  • 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 the APP_HOGPS_STATE_ADV state.

States and their Descriptions

  1. 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.
  2. APP_HOGPS_STATE_ADV: When in this state, the application is waiting for pairing to occur, and it does so for a duration specified by timeout_adv (60 seconds by default).
  3. 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 by timeout_adv_dir (30 seconds by default).
  4. APP_HOGPS_STATE_CONN: The application enters this state when it is ready to send keys or receive events. It responds to Button 1 presses in this state.

Button 1 Interactions

  • Press Button 1 (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 Button 1 in APP_HOGPS_STATE_CONN: A long press of Button 1 in the connected state leads to the disconnection of the device from the computer and initiates a new pairing process.
  • Long Press Button 1 in APP_HOGPS_STATE_ADV_DIR: A long press of Button 1 in the ADV_DIR state starts a new pairing process.
  • Press Button 1 in APP_HOGPS_STATE_IDLE: Pressing Button 1 in the Idle state wakes the device up from Extreme Deep Sleep mode.

LED Indications

The LEDs on the Curiosity Board indicate the current state of the application:
  • 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 Button 1 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 WBZ351 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.

Steps:
  1. On the computer:
    1. Remove the existing “Microchip Keyboard” pairing over BLE if it exists.
  2. On the WBZ351 Curiosity board:
    1. Compile and program the application.
    2. The curiosity board will enter APP_HOGPS_STATE_ADV and wait for pairing for timeout_adv seconds.
  3. On the computer:
    • Open Settings>Bluetooth & other devices>Add a device>Bluetooth.
    • Click Microchip Keyboard to connect and pair with the WBZ351 Curiosity Board.
  4. On the WBZ351 Curiosity board:
    1. It will enter APP_HOGPS_STATE_CONN when the connection is established.
  5. On the computer:
    1. Open a text editor (for example, Notepad) and click the left mouse button to focus on it.
  6. On the WBZ351 Curiosity board:
    1. Press Button 1
  7. On the computer:
    1. The text editor will display “abcde”.
    2. Turn ON Caps Lock, and the text editor will display “CAPON”.
  8. On the WBZ351 Curiosity board:
    1. Press Button 1
  9. On the computer:
    1. The text editor will display “ABCDE”.
    2. Turn OFF Caps Lock, and the text editor will display “capof”.
  10. On the WBZ351 Curiosity board:
    1. Unplug the USB cable to power OFF.
  11. On the computer:
    1. The status of “Microchip Keyboard” must show as “Paired” (disconnected).
  12. On the WBZ351 Curiosity board:
    1. Plug the USB cable to power ON
    2. The curiosity board enters APP_HOGPS_STATE_ADV_DIR and wait for reconnection for timeout_adv_dir seconds.
  13. On the computer:
    1. The status of “Microchip Keyboard” must show as “Connected”.
  14. On the WBZ351 Curiosity board:
    1. It enters APP_HOGPS_STATE_CONN once the reconnection is successful.

Test 2: Reconnecting to the Curiosity Board

Objective: Demonstration on re-establishing a connection with the curiosity board after it has disconnected.

Steps:
  1. On the WBZ351 Curiosity board:
    1. Move it far away from the computer to disconnect.
    2. The curiosity board will enter APP_HOGPS_STATE_ADV_DIR and wait for reconnection for timeout_adv_dir seconds.
  2. On the computer:
    1. The status of “Microchip Keyboard” must show as “Paired”.
  3. On the WBZ351 Curiosity board:
    1. Move it close back to the computer and press Button 1 to wake it up.
    2. It will automatically reconnect to the computer after successful disconnection.
    3. The curiosity board will enter APP_HOGPS_STATE_CONN when the reconnection is successful.
  4. On the computer:
    1. 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.

Steps:
  1. On the computer:
    1. Remove the existing “Microchip Keyboard”.
  2. On the WBZ351 Curiosity board:
    1. Unplug the USB cable to power OFF.
    2. Plug the USB cable to power ON.
    3. The Curiosity board enters APP_HOGPS_STATE_ADV_DIR and wait for reconnection for timeout_adv_dir seconds.
    4. Long-press Button 1.
  3. On the computer:
    1. Open Settings>Bluetooth & other devices>Add a device>Bluetooth.
    2. Click Microchip Keyboard to connect and pair with the Curiosity board.
  4. On the WBZ351 Curiosity board:
    1. It will enter APP_HOGPS_STATE_CONN when the connection is established.

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.