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.

Committer:
Jean-Philippe Brucker
Date:
Wed Oct 07 11:29:52 2015 +0100
Revision:
1:7a6c2e2c9371
Parent:
0:cfd70fa91663
Publish version 0.1 of the BLE HID lib

This version number is completely arbitrary, and probably won't stick: once the
service is stable, we'll merge it with BLE API.
It is simply used to keep examples in sync with the lib and the github
repository during development.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jean-Philippe Brucker 1:7a6c2e2c9371 1 /* Copyright (c) 2015 mbed.org, MIT License
Jean-Philippe Brucker 0:cfd70fa91663 2 *
Jean-Philippe Brucker 1:7a6c2e2c9371 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Jean-Philippe Brucker 1:7a6c2e2c9371 4 * and associated documentation files (the "Software"), to deal in the Software without
Jean-Philippe Brucker 1:7a6c2e2c9371 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Jean-Philippe Brucker 1:7a6c2e2c9371 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Jean-Philippe Brucker 1:7a6c2e2c9371 7 * Software is furnished to do so, subject to the following conditions:
Jean-Philippe Brucker 0:cfd70fa91663 8 *
Jean-Philippe Brucker 1:7a6c2e2c9371 9 * The above copyright notice and this permission notice shall be included in all copies or
Jean-Philippe Brucker 1:7a6c2e2c9371 10 * substantial portions of the Software.
Jean-Philippe Brucker 0:cfd70fa91663 11 *
Jean-Philippe Brucker 1:7a6c2e2c9371 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Jean-Philippe Brucker 1:7a6c2e2c9371 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Jean-Philippe Brucker 1:7a6c2e2c9371 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Jean-Philippe Brucker 1:7a6c2e2c9371 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Jean-Philippe Brucker 1:7a6c2e2c9371 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Jean-Philippe Brucker 1:7a6c2e2c9371 17 *
Jean-Philippe Brucker 1:7a6c2e2c9371 18 * Note: this file was pulled from the USBHID library, in mbed SDK
Jean-Philippe Brucker 0:cfd70fa91663 19 */
Jean-Philippe Brucker 1:7a6c2e2c9371 20
Jean-Philippe Brucker 0:cfd70fa91663 21 #ifndef USBCLASS_HID_TYPES
Jean-Philippe Brucker 0:cfd70fa91663 22 #define USBCLASS_HID_TYPES
Jean-Philippe Brucker 0:cfd70fa91663 23
Jean-Philippe Brucker 0:cfd70fa91663 24 #include <stdint.h>
Jean-Philippe Brucker 0:cfd70fa91663 25
Jean-Philippe Brucker 0:cfd70fa91663 26 #pragma pack(push, 1)
Jean-Philippe Brucker 0:cfd70fa91663 27 typedef struct {
Jean-Philippe Brucker 0:cfd70fa91663 28 uint8_t vendorID_source;
Jean-Philippe Brucker 0:cfd70fa91663 29 uint16_t vendorID;
Jean-Philippe Brucker 0:cfd70fa91663 30 uint16_t productID;
Jean-Philippe Brucker 0:cfd70fa91663 31 uint16_t productVersion;
Jean-Philippe Brucker 0:cfd70fa91663 32 } PnPID_t;
Jean-Philippe Brucker 0:cfd70fa91663 33 #pragma pack(pop)
Jean-Philippe Brucker 0:cfd70fa91663 34
Jean-Philippe Brucker 0:cfd70fa91663 35 /* */
Jean-Philippe Brucker 0:cfd70fa91663 36 #define HID_VERSION_1_11 (0x0111)
Jean-Philippe Brucker 0:cfd70fa91663 37
Jean-Philippe Brucker 0:cfd70fa91663 38 /* HID Class */
Jean-Philippe Brucker 0:cfd70fa91663 39 #define HID_CLASS (3)
Jean-Philippe Brucker 0:cfd70fa91663 40 #define HID_SUBCLASS_NONE (0)
Jean-Philippe Brucker 0:cfd70fa91663 41 #define HID_PROTOCOL_NONE (0)
Jean-Philippe Brucker 0:cfd70fa91663 42
Jean-Philippe Brucker 0:cfd70fa91663 43 /* Descriptors */
Jean-Philippe Brucker 0:cfd70fa91663 44 #define HID_DESCRIPTOR (33)
Jean-Philippe Brucker 0:cfd70fa91663 45 #define HID_DESCRIPTOR_LENGTH (0x09)
Jean-Philippe Brucker 0:cfd70fa91663 46 #define REPORT_DESCRIPTOR (34)
Jean-Philippe Brucker 0:cfd70fa91663 47
Jean-Philippe Brucker 0:cfd70fa91663 48 /* Class requests */
Jean-Philippe Brucker 0:cfd70fa91663 49 #define GET_REPORT (0x1)
Jean-Philippe Brucker 0:cfd70fa91663 50 #define GET_IDLE (0x2)
Jean-Philippe Brucker 0:cfd70fa91663 51 #define SET_REPORT (0x9)
Jean-Philippe Brucker 0:cfd70fa91663 52 #define SET_IDLE (0xa)
Jean-Philippe Brucker 0:cfd70fa91663 53
Jean-Philippe Brucker 0:cfd70fa91663 54 /* HID Class Report Descriptor */
Jean-Philippe Brucker 0:cfd70fa91663 55 /* Short items: size is 0, 1, 2 or 3 specifying 0, 1, 2 or 4 (four) bytes */
Jean-Philippe Brucker 0:cfd70fa91663 56 /* of data as per HID Class standard */
Jean-Philippe Brucker 0:cfd70fa91663 57
Jean-Philippe Brucker 0:cfd70fa91663 58 /* Main items */
Jean-Philippe Brucker 0:cfd70fa91663 59 #define INPUT(size) (0x80 | size)
Jean-Philippe Brucker 0:cfd70fa91663 60 #define OUTPUT(size) (0x90 | size)
Jean-Philippe Brucker 0:cfd70fa91663 61 #define FEATURE(size) (0xb0 | size)
Jean-Philippe Brucker 0:cfd70fa91663 62 #define COLLECTION(size) (0xa0 | size)
Jean-Philippe Brucker 0:cfd70fa91663 63 #define END_COLLECTION(size) (0xc0 | size)
Jean-Philippe Brucker 0:cfd70fa91663 64
Jean-Philippe Brucker 0:cfd70fa91663 65 /* Global items */
Jean-Philippe Brucker 0:cfd70fa91663 66 #define USAGE_PAGE(size) (0x04 | size)
Jean-Philippe Brucker 0:cfd70fa91663 67 #define LOGICAL_MINIMUM(size) (0x14 | size)
Jean-Philippe Brucker 0:cfd70fa91663 68 #define LOGICAL_MAXIMUM(size) (0x24 | size)
Jean-Philippe Brucker 0:cfd70fa91663 69 #define PHYSICAL_MINIMUM(size) (0x34 | size)
Jean-Philippe Brucker 0:cfd70fa91663 70 #define PHYSICAL_MAXIMUM(size) (0x44 | size)
Jean-Philippe Brucker 0:cfd70fa91663 71 #define UNIT_EXPONENT(size) (0x54 | size)
Jean-Philippe Brucker 0:cfd70fa91663 72 #define UNIT(size) (0x64 | size)
Jean-Philippe Brucker 0:cfd70fa91663 73 #define REPORT_SIZE(size) (0x74 | size)
Jean-Philippe Brucker 0:cfd70fa91663 74 #define REPORT_ID(size) (0x84 | size)
Jean-Philippe Brucker 0:cfd70fa91663 75 #define REPORT_COUNT(size) (0x94 | size)
Jean-Philippe Brucker 0:cfd70fa91663 76 #define PUSH(size) (0xa4 | size)
Jean-Philippe Brucker 0:cfd70fa91663 77 #define POP(size) (0xb4 | size)
Jean-Philippe Brucker 0:cfd70fa91663 78
Jean-Philippe Brucker 0:cfd70fa91663 79 /* Local items */
Jean-Philippe Brucker 0:cfd70fa91663 80 #define USAGE(size) (0x08 | size)
Jean-Philippe Brucker 0:cfd70fa91663 81 #define USAGE_MINIMUM(size) (0x18 | size)
Jean-Philippe Brucker 0:cfd70fa91663 82 #define USAGE_MAXIMUM(size) (0x28 | size)
Jean-Philippe Brucker 0:cfd70fa91663 83 #define DESIGNATOR_INDEX(size) (0x38 | size)
Jean-Philippe Brucker 0:cfd70fa91663 84 #define DESIGNATOR_MINIMUM(size) (0x48 | size)
Jean-Philippe Brucker 0:cfd70fa91663 85 #define DESIGNATOR_MAXIMUM(size) (0x58 | size)
Jean-Philippe Brucker 0:cfd70fa91663 86 #define STRING_INDEX(size) (0x78 | size)
Jean-Philippe Brucker 0:cfd70fa91663 87 #define STRING_MINIMUM(size) (0x88 | size)
Jean-Philippe Brucker 0:cfd70fa91663 88 #define STRING_MAXIMUM(size) (0x98 | size)
Jean-Philippe Brucker 0:cfd70fa91663 89 #define DELIMITER(size) (0xa8 | size)
Jean-Philippe Brucker 0:cfd70fa91663 90
Jean-Philippe Brucker 0:cfd70fa91663 91 /* HID Report */
Jean-Philippe Brucker 0:cfd70fa91663 92 /* Where report IDs are used the first byte of 'data' will be the */
Jean-Philippe Brucker 0:cfd70fa91663 93 /* report ID and 'length' will include this report ID byte. */
Jean-Philippe Brucker 0:cfd70fa91663 94
Jean-Philippe Brucker 0:cfd70fa91663 95 #define MAX_HID_REPORT_SIZE (64)
Jean-Philippe Brucker 0:cfd70fa91663 96
Jean-Philippe Brucker 0:cfd70fa91663 97 typedef struct {
Jean-Philippe Brucker 0:cfd70fa91663 98 uint32_t length;
Jean-Philippe Brucker 0:cfd70fa91663 99 uint8_t data[MAX_HID_REPORT_SIZE];
Jean-Philippe Brucker 0:cfd70fa91663 100 } HID_REPORT;
Jean-Philippe Brucker 0:cfd70fa91663 101
Jean-Philippe Brucker 0:cfd70fa91663 102 #endif
Jean-Philippe Brucker 0:cfd70fa91663 103