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:   BLENano_HID BLE_HID_MouseScrollDemo BLE_HID_KeyboardStreamDemo Shervs_TestKeyboard_TinyBLE ... more

The development repository is currently hosted on github. It contains examples and documentation. This is a snapshot of the library. The documentation can be read on github, or on docs.mbed.com.

Files at this revision

API Documentation at this revision

Comitter:
Jean-Philippe Brucker
Date:
Thu Nov 19 15:00:39 2015 +0000
Parent:
2:3d9adb26bdc5
Commit message:
Version 0.3

Changed in this revision

HIDDeviceInformationService.h Show diff for this revision Revisions of this file
HIDServiceBase.h Show annotated file Show diff for this revision Revisions of this file
HID_types.h Show diff for this revision Revisions of this file
USBHID_Types.h Show annotated file Show diff for this revision Revisions of this file
version Show annotated file Show diff for this revision Revisions of this file
--- a/HIDDeviceInformationService.h	Thu Oct 29 16:48:26 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __BLE_HID_DEVICE_INFORMATION_SERVICE_H__
-#define __BLE_HID_DEVICE_INFORMATION_SERVICE_H__
-
-#include "ble/BLE.h"
-
-#include "HID_types.h"
-
-/**
-* @class HIDDeviceInformationService
-* @brief BLE Device Information Service <br>
-* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml <br>
-* Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml
-*/
-class HIDDeviceInformationService {
-public:
-    /**
-     * @brief Device Information Service Constructor.
-     *
-     * @param[ref] _ble
-     *                BLE object for the underlying controller.
-     * @param[in] manufacturersName
-     *                This characteristic represents the name of the
-     *                manufacturer of the device. The name is copied into the
-     *                BLE stack during this constructor.
-     * @param[in] modelNumber
-     *                This characteristic represents the model number that is
-     *                assigned by the device vendor. The value is copied into
-     *                the BLE stack during this constructor.
-     * @param[in] serialNumber
-     *                This characteristic represents the serial number for a
-     *                particular instance of the device.  The value is copied
-     *                into the BLE stack during this constructor.
-     * @param[in] hardwareRevision
-     *                This characteristic represents the hardware revision for
-     *                the hardware within the device. The value is copied
-     *                into the BLE stack during this constructor.
-     * @param[in] firmwareRevision
-     *                This characteristic represents the firmware revision for
-     *                the firmware within the device. The value is copied
-     *                into the BLE stack during this constructor.
-     * @param[in] softwareRevision
-     *                This characteristic represents the software revision for
-     *                the software within the device. The value is copied
-     *                into the BLE stack during this constructor.
-     * @param[in] pnpID
-     *                This characteristic represents HID-specific information,
-     *                such as vendor id, product id and version.
-     */
-    HIDDeviceInformationService(BLE            &_ble,
-                             const char     *manufacturersName = NULL,
-                             const char     *modelNumber       = NULL,
-                             const char     *serialNumber      = NULL,
-                             const char     *hardwareRevision  = NULL,
-                             const char     *firmwareRevision  = NULL,
-                             const char     *softwareRevision  = NULL,
-                             PnPID_t        *PnPID             = NULL) :
-        ble(_ble),
-        manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
-                                              (uint8_t *)manufacturersName,
-                                              (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */
-                                              (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */
-                                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
-        modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
-                                        (uint8_t *)modelNumber,
-                                        (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */
-                                        (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */
-                                        GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
-        serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
-                                         (uint8_t *)serialNumber,
-                                         (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */
-                                         (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */
-                                         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
-        hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
-                                             (uint8_t *)hardwareRevision,
-                                             (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */
-                                             (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */
-                                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
-        firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
-                                             (uint8_t *)firmwareRevision,
-                                             (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */
-                                             (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */
-                                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
-        softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
-                                             (uint8_t *)softwareRevision,
-                                             (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */
-                                             (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */
-                                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
-        pnpIDCharacteristic(GattCharacteristic::UUID_PNP_ID_CHAR,
-                            PnPID)
-    {
-        static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
-        if (serviceAdded) {
-            return;
-        }
-
-        GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic,
-                                           &modelNumberStringCharacteristic,
-                                           &serialNumberStringCharacteristic,
-                                           &hardwareRevisionStringCharacteristic,
-                                           &firmwareRevisionStringCharacteristic,
-                                           &softwareRevisionStringCharacteristic,
-                                           &pnpIDCharacteristic};
-        GattService         deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
-                                                     sizeof(charTable) / sizeof(GattCharacteristic *));
-
-        /*
-         * This is a hack to make things work on MacOSX 10.10. I don't have the details, but MacOSX
-         * 10.10 gets confused when only characteristics from HID Service require security...
-         */
-        pnpIDCharacteristic.requireSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM);
-        ble.addService(deviceInformationService);
-        serviceAdded = true;
-    }
-
-protected:
-    BLE                 &ble;
-    GattCharacteristic  manufacturersNameStringCharacteristic;
-    GattCharacteristic  modelNumberStringCharacteristic;
-    GattCharacteristic  serialNumberStringCharacteristic;
-    GattCharacteristic  hardwareRevisionStringCharacteristic;
-    GattCharacteristic  firmwareRevisionStringCharacteristic;
-    GattCharacteristic  softwareRevisionStringCharacteristic;
-    ReadOnlyGattCharacteristic<PnPID_t>  pnpIDCharacteristic;
-};
-
-#endif /* #ifndef __BLE_HID_DEVICE_INFORMATION_SERVICE_H__*/
-
--- a/HIDServiceBase.h	Thu Oct 29 16:48:26 2015 +0000
+++ b/HIDServiceBase.h	Thu Nov 19 15:00:39 2015 +0000
@@ -20,7 +20,7 @@
 #include "mbed.h"
 
 #include "ble/BLE.h"
-#include "HID_types.h"
+#include "USBHID_Types.h"
 
 #define BLE_UUID_DESCRIPTOR_REPORT_REFERENCE 0x2908
 
--- a/HID_types.h	Thu Oct 29 16:48:26 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-/* Copyright (c) 2015 mbed.org, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Note: this file was pulled from the USBHID library, in mbed SDK
- */
-
-#ifndef USBCLASS_HID_TYPES
-#define USBCLASS_HID_TYPES
-
-#include <stdint.h>
-
-#pragma pack(push, 1)
-typedef struct {
-    uint8_t vendorID_source;
-    uint16_t vendorID;
-    uint16_t productID;
-    uint16_t productVersion;
-} PnPID_t;
-#pragma pack(pop)
-
-/* */
-#define HID_VERSION_1_11    (0x0111)
-
-/* HID Class */
-#define HID_CLASS           (3)
-#define HID_SUBCLASS_NONE   (0)
-#define HID_PROTOCOL_NONE   (0)
-
-/* Descriptors */
-#define HID_DESCRIPTOR          (33)
-#define HID_DESCRIPTOR_LENGTH   (0x09)
-#define REPORT_DESCRIPTOR       (34)
-
-/* Class requests */
-#define GET_REPORT (0x1)
-#define GET_IDLE   (0x2)
-#define SET_REPORT (0x9)
-#define SET_IDLE   (0xa)
-
-/* HID Class Report Descriptor */
-/* Short items: size is 0, 1, 2 or 3 specifying 0, 1, 2 or 4 (four) bytes */
-/* of data as per HID Class standard */
-
-/* Main items */
-#define INPUT(size)             (0x80 | size)
-#define OUTPUT(size)            (0x90 | size)
-#define FEATURE(size)           (0xb0 | size)
-#define COLLECTION(size)        (0xa0 | size)
-#define END_COLLECTION(size)    (0xc0 | size)
-
-/* Global items */
-#define USAGE_PAGE(size)        (0x04 | size)
-#define LOGICAL_MINIMUM(size)   (0x14 | size)
-#define LOGICAL_MAXIMUM(size)   (0x24 | size)
-#define PHYSICAL_MINIMUM(size)  (0x34 | size)
-#define PHYSICAL_MAXIMUM(size)  (0x44 | size)
-#define UNIT_EXPONENT(size)     (0x54 | size)
-#define UNIT(size)              (0x64 | size)
-#define REPORT_SIZE(size)       (0x74 | size)
-#define REPORT_ID(size)         (0x84 | size)
-#define REPORT_COUNT(size)      (0x94 | size)
-#define PUSH(size)              (0xa4 | size)
-#define POP(size)               (0xb4 | size)
-
-/* Local items */
-#define USAGE(size)                 (0x08 | size)
-#define USAGE_MINIMUM(size)         (0x18 | size)
-#define USAGE_MAXIMUM(size)         (0x28 | size)
-#define DESIGNATOR_INDEX(size)      (0x38 | size)
-#define DESIGNATOR_MINIMUM(size)    (0x48 | size)
-#define DESIGNATOR_MAXIMUM(size)    (0x58 | size)
-#define STRING_INDEX(size)          (0x78 | size)
-#define STRING_MINIMUM(size)        (0x88 | size)
-#define STRING_MAXIMUM(size)        (0x98 | size)
-#define DELIMITER(size)             (0xa8 | size)
-
-/* HID Report */
-/* Where report IDs are used the first byte of 'data' will be the */
-/* report ID and 'length' will include this report ID byte. */
-
-#define MAX_HID_REPORT_SIZE (64)
-
-typedef struct {
-    uint32_t length;
-    uint8_t data[MAX_HID_REPORT_SIZE];
-} HID_REPORT;
-
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHID_Types.h	Thu Nov 19 15:00:39 2015 +0000
@@ -0,0 +1,91 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef USBCLASS_HID_TYPES
+#define USBCLASS_HID_TYPES
+
+#include <stdint.h>
+
+/* */
+#define HID_VERSION_1_11    (0x0111)
+
+/* HID Class */
+#define HID_CLASS           (3)
+#define HID_SUBCLASS_NONE   (0)
+#define HID_PROTOCOL_NONE   (0)
+
+/* Descriptors */
+#define HID_DESCRIPTOR          (33)
+#define HID_DESCRIPTOR_LENGTH   (0x09)
+#define REPORT_DESCRIPTOR       (34)
+
+/* Class requests */
+#define GET_REPORT (0x1)
+#define GET_IDLE   (0x2)
+#define SET_REPORT (0x9)
+#define SET_IDLE   (0xa)
+
+/* HID Class Report Descriptor */
+/* Short items: size is 0, 1, 2 or 3 specifying 0, 1, 2 or 4 (four) bytes */
+/* of data as per HID Class standard */
+
+/* Main items */
+#define INPUT(size)             (0x80 | size)
+#define OUTPUT(size)            (0x90 | size)
+#define FEATURE(size)           (0xb0 | size)
+#define COLLECTION(size)        (0xa0 | size)
+#define END_COLLECTION(size)    (0xc0 | size)
+
+/* Global items */
+#define USAGE_PAGE(size)        (0x04 | size)
+#define LOGICAL_MINIMUM(size)   (0x14 | size)
+#define LOGICAL_MAXIMUM(size)   (0x24 | size)
+#define PHYSICAL_MINIMUM(size)  (0x34 | size)
+#define PHYSICAL_MAXIMUM(size)  (0x44 | size)
+#define UNIT_EXPONENT(size)     (0x54 | size)
+#define UNIT(size)              (0x64 | size)
+#define REPORT_SIZE(size)       (0x74 | size)
+#define REPORT_ID(size)         (0x84 | size)
+#define REPORT_COUNT(size)      (0x94 | size)
+#define PUSH(size)              (0xa4 | size)
+#define POP(size)               (0xb4 | size)
+
+/* Local items */
+#define USAGE(size)                 (0x08 | size)
+#define USAGE_MINIMUM(size)         (0x18 | size)
+#define USAGE_MAXIMUM(size)         (0x28 | size)
+#define DESIGNATOR_INDEX(size)      (0x38 | size)
+#define DESIGNATOR_MINIMUM(size)    (0x48 | size)
+#define DESIGNATOR_MAXIMUM(size)    (0x58 | size)
+#define STRING_INDEX(size)          (0x78 | size)
+#define STRING_MINIMUM(size)        (0x88 | size)
+#define STRING_MAXIMUM(size)        (0x98 | size)
+#define DELIMITER(size)             (0xa8 | size)
+
+/* HID Report */
+/* Where report IDs are used the first byte of 'data' will be the */
+/* report ID and 'length' will include this report ID byte. */
+
+#define MAX_HID_REPORT_SIZE (64)
+
+typedef struct {
+    uint32_t length;
+    uint8_t data[MAX_HID_REPORT_SIZE];
+} HID_REPORT;
+
+#endif
--- a/version	Thu Oct 29 16:48:26 2015 +0000
+++ b/version	Thu Nov 19 15:00:39 2015 +0000
@@ -1,1 +1,1 @@
-0.2
+0.3