HID-over-GATT implementation with the BLE API. This library allows to create devices such as mouse, keyboard or joystick, over Bluetooth Low Energy.

Dependents:   MtConnect04S_Gesture_HID

Fork of BLE_HID by Jean-Philippe Brucker

Revision:
5:dc4e6dbcb79b
Parent:
1:7a6c2e2c9371
--- a/HIDServiceBase.cpp	Fri Dec 16 10:26:25 2016 +0000
+++ b/HIDServiceBase.cpp	Tue Jan 17 03:48:12 2017 +0000
@@ -72,6 +72,18 @@
             | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE,
             featureReportDescriptors(), 1),
 
+    bootKeyboardInputReportCharacteristic(GattCharacteristic::UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR,
+            (uint8_t *)inputReport, inputReportLength, inputReportLength,
+              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ
+            | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY
+            | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
+
+    bootKeyboardOutputReportCharacteristic(GattCharacteristic::UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR,
+            (uint8_t *)outputReport, outputReportLength, outputReportLength,
+              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ
+            | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE
+            | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
+
     /*
      * We need to set reportMap content as const, in order to let the compiler put it into flash
      * instead of RAM. The characteristic is read-only so it won't be written, but
@@ -112,6 +124,10 @@
         characteristics[charIndex++] = &outputReportCharacteristic;
     if (featureReportLength)
         characteristics[charIndex++] = &featureReportCharacteristic;
+    if (inputReportLength)
+        characteristics[charIndex++] = &bootKeyboardInputReportCharacteristic;
+    if (outputReportLength)
+        characteristics[charIndex++] = &bootKeyboardOutputReportCharacteristic;
 
     /* TODO: let children add some more characteristics, namely boot keyboard and mouse (They are
      * mandatory as per HIDS spec.) Ex:
@@ -150,6 +166,8 @@
     inputReportCharacteristic.requireSecurity(securityMode);
     outputReportCharacteristic.requireSecurity(securityMode);
     featureReportCharacteristic.requireSecurity(securityMode);
+    bootKeyboardInputReportCharacteristic.requireSecurity(securityMode);
+    bootKeyboardOutputReportCharacteristic.requireSecurity(securityMode);
 }
 
 void HIDServiceBase::startReportTicker(void) {
@@ -206,9 +224,19 @@
 }
 
 ble_error_t HIDServiceBase::send(const report_t report) {
-    return ble.gattServer().write(inputReportCharacteristic.getValueHandle(),
-                                  report,
-                                  inputReportLength);
+        if (protocolMode == REPORT_PROTOCOL) {
+            return ble.gattServer().write(
+                inputReportCharacteristic.getValueHandle(),
+                report,
+                inputReportLength
+            );
+        } else {
+            return ble.gattServer().write(
+                bootKeyboardInputReportCharacteristic.getValueHandle(),
+                report,
+                inputReportLength
+            );
+        }  
 }
 
 ble_error_t HIDServiceBase::read(report_t report) {