From 90a1bebe2c40af94eea77cab34d4287be30751dd Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Jan 2017 00:36:37 +0700 Subject: [PATCH] starting to add BLEHid support --- .../Bluefruit52Lib/src/BLECharacteristic.cpp | 77 +++- .../Bluefruit52Lib/src/BLECharacteristic.h | 11 +- libraries/Bluefruit52Lib/src/bluefruit.cpp | 3 +- libraries/Bluefruit52Lib/src/bluefruit.h | 1 + .../Bluefruit52Lib/src/services/BLEHid.cpp | 69 +++ .../Bluefruit52Lib/src/services/BLEHid.h | 419 ++++++++++++++++++ .../Bluefruit52Lib/src/services/BLEUart.cpp | 6 +- .../nffs/examples/filesystem/filesystem.ino | 29 +- 8 files changed, 567 insertions(+), 48 deletions(-) create mode 100644 libraries/Bluefruit52Lib/src/services/BLEHid.cpp create mode 100644 libraries/Bluefruit52Lib/src/services/BLEHid.h diff --git a/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp b/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp index 5c6e63e3..627c5ce7 100644 --- a/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp +++ b/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp @@ -42,6 +42,8 @@ void BLECharacteristic::init(void) _descriptor = NULL; _max_len = BLE_GATTS_VAR_ATTR_LEN_MAX; + varclr(&_report_ref_desc); + _service = BLEService::lastService; _handles.value_handle = BLE_GATT_HANDLE_INVALID; @@ -132,11 +134,17 @@ void BLECharacteristic::setWriteAuthorizeCallbak(write_authorize_cb_t fp) _wr_authorize_cb = fp; } -void BLECharacteristic::setDescriptor(const char* descriptor) +void BLECharacteristic::setStringDescriptor(const char* descriptor) { _descriptor = descriptor; } +void BLECharacteristic::setReportRefDescriptor(uint8_t id, uint8_t type) +{ + _report_ref_desc.id = id; + _report_ref_desc.type = type; +} + ble_gatts_char_handles_t BLECharacteristic::handles(void) { return _handles; @@ -150,8 +158,18 @@ err_t BLECharacteristic::start(void) // Permission is OPEN if passkey is disabled. // if (!nvm_data.core.passkey_enable) BLE_GAP_CONN_SEC_MODE_SET_OPEN(&p_char_def->permission); + // Correct Read/Write permission according to properties + if ( !(_properties.read || _properties.notify || _properties.indicate ) ) + { + _attr_meta.read_perm = BLE_SECMODE_NO_ACCESS; + } + + if ( !(_properties.write || _properties.write_wo_resp ) ) + { + _attr_meta.write_perm = BLE_SECMODE_NO_ACCESS; + } + /* CCCD attribute metadata */ - /* https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a00269.html */ ble_gatts_attr_md_t cccd_md; if ( _properties.notify || _properties.indicate ) @@ -160,27 +178,22 @@ err_t BLECharacteristic::start(void) memclr( &cccd_md, sizeof(ble_gatts_attr_md_t) ); cccd_md.vloc = BLE_GATTS_VLOC_STACK; - cccd_md.read_perm = BLE_SECMODE_OPEN; - - // TODO enable encryption when bonding is enabled -// cccd_md.write_perm = BLE_SECMODE_ENC_NO_MITM; - cccd_md.write_perm = BLE_SECMODE_OPEN; + cccd_md.read_perm = _attr_meta.read_perm; + cccd_md.write_perm = _attr_meta.read_perm; } /* Characteristic metadata */ - /* https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a00272.html */ ble_gatts_char_md_t char_md; varclr(&char_md); char_md.char_props = _properties; char_md.p_cccd_md = (_properties.notify || _properties.indicate) ? &cccd_md : NULL; - /* Characteristic extended properties (used for the user description) */ - /* https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a00248.html */ + /* Characteristic extended properties (for user description) */ ble_gatts_attr_md_t desc_md = { - .read_perm = { .sm = 1, .lv = 1 }, // open - .write_perm = { .sm = 0, .lv = 0 }, // no access + .read_perm = _attr_meta.read_perm, + .write_perm = BLE_SECMODE_NO_ACCESS, .vlen = 0, .vloc = BLE_GATTS_VLOC_STACK, }; @@ -201,18 +214,7 @@ err_t BLECharacteristic::start(void) // char_md.p_char_pf = &p_char_def->presentation; // } - if ( !(_properties.read || _properties.notify || _properties.indicate ) ) - { - _attr_meta.read_perm = BLE_SECMODE_NO_ACCESS; - } - - if ( !(_properties.write || _properties.write_wo_resp ) ) - { - _attr_meta.write_perm = BLE_SECMODE_NO_ACCESS; - } - /* GATT attribute declaration */ - /* https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a00270.html */ ble_gatts_attr_t attr_char_value = { .p_uuid = &uuid._uuid, @@ -225,6 +227,35 @@ err_t BLECharacteristic::start(void) VERIFY_STATUS( sd_ble_gatts_characteristic_add(BLE_GATT_HANDLE_INVALID, &char_md, &attr_char_value, &_handles) ); + // Report Reference Descriptor if any (required by HID) + if ( _report_ref_desc.type ) + { + // Reference Descriptor + ble_gatts_attr_md_t ref_md = + { + .read_perm = _attr_meta.read_perm, + .write_perm = BLE_SECMODE_NO_ACCESS, + .vlen = 0, + .vloc = BLE_GATTS_VLOC_STACK + }; + + ble_uuid_t ref_uuid = { .uuid = UUID16_REPORT_REF_DESCR, .type = BLE_UUID_TYPE_BLE }; + ble_gatts_attr_t ref_desc = + { + .p_uuid = &ref_uuid, + .p_attr_md = &ref_md, + .init_len = sizeof(_report_ref_desc), + .init_offs = 0, + .max_len = sizeof(_report_ref_desc), + .p_value = (uint8_t*) &_report_ref_desc + }; + + uint16_t ref_hdl; + VERIFY_STATUS ( sd_ble_gatts_descriptor_add(BLE_GATT_HANDLE_INVALID, &ref_desc, &ref_hdl) ); + + (void) ref_hdl; // not used + } + // Only register to Bluefruit when having callback support // The Characteristic must not be temporary memory aka local variable if (_rd_authorize_cb || _wr_authorize_cb || _wr_cb) diff --git a/libraries/Bluefruit52Lib/src/BLECharacteristic.h b/libraries/Bluefruit52Lib/src/BLECharacteristic.h index 0b2fcf93..a5e7a8c4 100644 --- a/libraries/Bluefruit52Lib/src/BLECharacteristic.h +++ b/libraries/Bluefruit52Lib/src/BLECharacteristic.h @@ -81,13 +81,18 @@ class BLECharacteristic const char* _descriptor; uint16_t _max_len; + struct ATTR_PACKED { + uint8_t id; + uint8_t type; + }_report_ref_desc; + /* Characteristic attribute metadata */ /* https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a00269.html */ ble_gatts_attr_md_t _attr_meta; ble_gatts_char_handles_t _handles; - BLEService* _service; + BLEService* _service; // pointer to parent's service // Callback pointer read_authorize_cb_t _rd_authorize_cb; @@ -118,7 +123,9 @@ class BLECharacteristic // Configure void setProperties(uint8_t prop); void setPermission(BleSecurityMode read_perm, BleSecurityMode write_perm); - void setDescriptor(const char* descriptor); + + void setStringDescriptor(const char* descriptor); // aka user descriptor + void setReportRefDescriptor(uint8_t id, uint8_t type); void setMaxLen(uint16_t max_len); void setFixedLen(uint16_t fixed_len); diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 97b373e3..8c4a0b12 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -476,8 +476,7 @@ void AdafruitBluefruit::_poll(void) { case NRF_EVT_FLASH_OPERATION_SUCCESS: case NRF_EVT_FLASH_OPERATION_ERROR: -// PRINT_INT(soc_evt); - hal_flash_event_cb(soc_evt); + if (hal_flash_event_cb) hal_flash_event_cb(soc_evt); break; default: break; diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index ecdc8977..ddca7c3e 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -47,6 +47,7 @@ #include "services/BLEUart.h" #include "services/BLEBas.h" #include "services/BLEBeacon.h" +#include "services/BLEHid.h" #define BLE_MAX_CHARS 50 diff --git a/libraries/Bluefruit52Lib/src/services/BLEHid.cpp b/libraries/Bluefruit52Lib/src/services/BLEHid.cpp new file mode 100644 index 00000000..92d74b16 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEHid.cpp @@ -0,0 +1,69 @@ +/**************************************************************************/ +/*! + @file BLEHid.cpp + @author hathach + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2017, Adafruit Industries (adafruit.com) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "bluefruit.h" + +BLEHid::BLEHid(void) + : BLEService(UUID16_SVC_HUMAN_INTERFACE_DEVICE), + _chr_protocol(), _chr_input() +{ + +} + +err_t BLEHid::start(void) +{ + VERIFY_STATUS( this->addToGatt() ); + + // Protocol Mode + _chr_protocol.setUuid(UUID16_CHR_PROTOCOL_MODE); + _chr_protocol.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE_WO_RESP); + _chr_protocol.setFixedLen(1); + VERIFY_STATUS( _chr_protocol.start() ); + _chr_protocol.write( (uint8_t) 1); + + // Input reports + { + _chr_input.setUuid(UUID16_CHR_REPORT); + _chr_input.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _chr_input.setFixedLen(sizeof(hid_keyboard_report_t)); + //_chr_input.setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS); + _chr_input.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _chr_input.setReportRefDescriptor(0x01, 0x01); + VERIFY_STATUS( _chr_input.start() ); + } + + return NRF_SUCCESS; +} diff --git a/libraries/Bluefruit52Lib/src/services/BLEHid.h b/libraries/Bluefruit52Lib/src/services/BLEHid.h new file mode 100644 index 00000000..77c5ddc9 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEHid.h @@ -0,0 +1,419 @@ +/**************************************************************************/ +/*! + @file BLEHid.h + @author hathach + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2017, Adafruit Industries (adafruit.com) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef BLEHID_H_ +#define BLEHID_H_ + +#include "bluefruit_common.h" +#include "utility/adafruit_fifo.h" + +#include "BLECharacteristic.h" +#include "BLEService.h" + + +class BLEHid : public BLEService +{ + protected: + BLECharacteristic _chr_protocol; + BLECharacteristic _chr_input; + + public: + BLEHid(void); + virtual err_t start(void); + +}; + +//--------------------------------------------------------------------+ +// MOUSE +//--------------------------------------------------------------------+ +/** \addtogroup ClassDriver_HID_Mouse Mouse + * @{ */ + +/// Standard HID Boot Protocol Mouse Report. +typedef ATTR_PACKED_STRUCT(struct) +{ + uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */ + int8_t x; /**< Current delta x movement of the mouse. */ + int8_t y; /**< Current delta y movement on the mouse. */ + int8_t wheel; /**< Current delta vertical wheel movement on the mouse. */ + int8_t pan; /**< Current delta horizontal wheel movement on the mouse. */ +} hid_mouse_report_t; + +/// Standard Mouse Buttons Bitmap +//typedef enum { +// MOUSE_BUTTON_LEFT = BIT(0), ///< Left button +// MOUSE_BUTTON_RIGHT = BIT(1), ///< Right button +// MOUSE_BUTTON_MIDDLE = BIT(2), ///< Middle button, +// MOUSE_BUTTON_BACKWARD = BIT(3), ///< Backward button, +// MOUSE_BUTTON_FORWARD = BIT(4), ///< Forward button, +// +// MOUSE_BUTTON_UNCHANGED = 0xff, ///< Not specified by HID but useful for holding mouse buttons +//}hid_mouse_button_bm_t; + +/// @} + +//--------------------------------------------------------------------+ +// Keyboard +//--------------------------------------------------------------------+ +/** \addtogroup ClassDriver_HID_Keyboard Keyboard + * @{ */ + +/// Standard HID Boot Protocol Keyboard Report. +typedef ATTR_PACKED_STRUCT(struct) +{ + uint8_t modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */ + uint8_t reserved; /**< Reserved for OEM use, always set to 0. */ + uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */ +} hid_keyboard_report_t; + + +/// HID Consumer Control Report +typedef ATTR_PACKED_STRUCT(struct) +{ + uint16_t usage_value; ///< Usage value of the pressed control +} hid_consumer_control_report_t; + +///// Keyboard modifier codes bitmap +//typedef enum { +// KEYBOARD_MODIFIER_LEFTCTRL = BIT(0), ///< Left Control +// KEYBOARD_MODIFIER_LEFTSHIFT = BIT(1), ///< Left Shift +// KEYBOARD_MODIFIER_LEFTALT = BIT(2), ///< Left Alt +// KEYBOARD_MODIFIER_LEFTGUI = BIT(3), ///< Left Window +// KEYBOARD_MODIFIER_RIGHTCTRL = BIT(4), ///< Right Control +// KEYBOARD_MODIFIER_RIGHTSHIFT = BIT(5), ///< Right Shift +// KEYBOARD_MODIFIER_RIGHTALT = BIT(6), ///< Right Alt +// KEYBOARD_MODIFIER_RIGHTGUI = BIT(7) ///< Right Window +//}hid_keyboard_modifier_bm_t; +// +//typedef enum { +// KEYBOARD_LED_NUMLOCK = BIT(0), ///< Num Lock LED +// KEYBOARD_LED_CAPSLOCK = BIT(1), ///< Caps Lock LED +// KEYBOARD_LED_SCROLLLOCK = BIT(2), ///< Scroll Lock LED +// KEYBOARD_LED_COMPOSE = BIT(3), ///< Composition Mode +// KEYBOARD_LED_KANA = BIT(4) ///< Kana mode +//}hid_keyboard_led_bm_t; + +/// @} + +/// Gamepad report +typedef ATTR_PACKED_STRUCT(struct) +{ + ATTR_PACKED_STRUCT(struct){ + uint8_t x : 2; + uint8_t y : 2; + uint8_t : 4; + }; + + uint8_t buttons; +}hid_gamepad_report_t; + +//ASSERT_STATIC(sizeof(hid_gamepad_report_t) == 2,); + +//--------------------------------------------------------------------+ +// REPORT DESCRIPTOR +//--------------------------------------------------------------------+ +//------------- ITEM & TAG -------------// +#define HID_REPORT_DATA_0(data) +#define HID_REPORT_DATA_1(data) , (data) +#define HID_REPORT_DATA_2(data) , U16_TO_U8S_LE(data) +#define HID_REPORT_DATA_3(data) , U32_TO_U8S_LE(data) + +#define HID_REPORT_ITEM(data, tag, type, size) \ + (((tag) << 4) | ((type) << 2) | (size)) HID_REPORT_DATA_##size(data) + +#define RI_TYPE_MAIN 0 +#define RI_TYPE_GLOBAL 1 +#define RI_TYPE_LOCAL 2 + +//------------- MAIN ITEMS 6.2.2.4 -------------// +#define HID_INPUT(x) HID_REPORT_ITEM(x, 8, RI_TYPE_MAIN, 1) +#define HID_OUTPUT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_MAIN, 1) +#define HID_COLLECTION(x) HID_REPORT_ITEM(x, 10, RI_TYPE_MAIN, 1) +#define HID_FEATURE(x) HID_REPORT_ITEM(x, 11, RI_TYPE_MAIN, 1) +#define HID_COLLECTION_END HID_REPORT_ITEM(x, 12, RI_TYPE_MAIN, 0) + +//------------- INPUT, OUTPUT, FEATURE 6.2.2.5 -------------// +#define HID_DATA (0<<0) +#define HID_CONSTANT (1<<0) + +#define HID_ARRAY (0<<1) +#define HID_VARIABLE (1<<1) + +#define HID_ABSOLUTE (0<<2) +#define HID_RELATIVE (1<<2) + +#define HID_WRAP_NO (0<<3) +#define HID_WRAP (1<<3) + +#define HID_LINEAR (0<<4) +#define HID_NONLINEAR (1<<4) + +#define HID_PREFERRED_STATE (0<<5) +#define HID_PREFERRED_NO (1<<5) + +#define HID_NO_NULL_POSITION (0<<6) +#define HID_NULL_STATE (1<<6) + +#define HID_NON_VOLATILE (0<<7) +#define HID_VOLATILE (1<<7) + +#define HID_BITFIELD (0<<8) +#define HID_BUFFERED_BYTES (1<<8) + +//------------- COLLECTION ITEM 6.2.2.6 -------------// +enum { + HID_COLLECTION_PHYSICAL = 0, + HID_COLLECTION_APPLICATION, + HID_COLLECTION_LOGICAL, + HID_COLLECTION_REPORT, + HID_COLLECTION_NAMED_ARRAY, + HID_COLLECTION_USAGE_SWITCH, + HID_COLLECTION_USAGE_MODIFIER +}; + +//------------- GLOBAL ITEMS 6.2.2.7 -------------// +#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, 1) +#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, n) + +#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, 1) +#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, n) + +#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, 1) +#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, n) + +#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, 1) +#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, n) + +#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, 1) +#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, n) + +#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, 1) +#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, n) + +#define HID_UNIT(x) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, 1) +#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, n) + +#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, 1) +#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, n) + +#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, 1) +#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, n) + +#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, 1) +#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, n) + +#define HID_PUSH HID_REPORT_ITEM(x, 10, RI_TYPE_GLOBAL, 0) +#define HID_POP HID_REPORT_ITEM(x, 11, RI_TYPE_GLOBAL, 0) + +//------------- LOCAL ITEMS 6.2.2.8 -------------// +#define HID_USAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, 1) +#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, n) + +#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, 1) +#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, n) + +#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, 1) +#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, n) + +//--------------------------------------------------------------------+ +// Usage Table +//--------------------------------------------------------------------+ + +/// HID Usage Table - Table 1: Usage Page Summary +enum { + HID_USAGE_PAGE_DESKTOP = 0x01, + HID_USAGE_PAGE_SIMULATE = 0x02, + HID_USAGE_PAGE_VIRTUAL_REALITY = 0x03, + HID_USAGE_PAGE_SPORT = 0x04, + HID_USAGE_PAGE_GAME = 0x05, + HID_USAGE_PAGE_GENERIC_DEVICE = 0x06, + HID_USAGE_PAGE_KEYBOARD = 0x07, + HID_USAGE_PAGE_LED = 0x08, + HID_USAGE_PAGE_BUTTON = 0x09, + HID_USAGE_PAGE_ORDINAL = 0x0a, + HID_USAGE_PAGE_TELEPHONY = 0x0b, + HID_USAGE_PAGE_CONSUMER = 0x0c, + HID_USAGE_PAGE_DIGITIZER = 0x0d, + HID_USAGE_PAGE_PID = 0x0f, + HID_USAGE_PAGE_UNICODE = 0x10, + HID_USAGE_PAGE_ALPHA_DISPLAY = 0x14, + HID_USAGE_PAGE_MEDICAL = 0x40, + HID_USAGE_PAGE_MONITOR = 0x80, //0x80 - 0x83 + HID_USAGE_PAGE_POWER = 0x84, // 0x084 - 0x87 + HID_USAGE_PAGE_BARCODE_SCANNER = 0x8c, + HID_USAGE_PAGE_SCALE = 0x8d, + HID_USAGE_PAGE_MSR = 0x8e, + HID_USAGE_PAGE_CAMERA = 0x90, + HID_USAGE_PAGE_ARCADE = 0x91, + HID_USAGE_PAGE_VENDOR = 0xFFFF // 0xFF00 - 0xFFFF +}; + +/// HID Usage Table - Table 6: Generic Desktop Page +enum +{ + HID_USAGE_DESKTOP_POINTER = 0x01, + HID_USAGE_DESKTOP_MOUSE = 0x02, + HID_USAGE_DESKTOP_JOYSTICK = 0x04, + HID_USAGE_DESKTOP_GAMEPAD = 0x05, + HID_USAGE_DESKTOP_KEYBOARD = 0x06, + HID_USAGE_DESKTOP_KEYPAD = 0x07, + HID_USAGE_DESKTOP_MULTI_AXIS_CONTROLLER = 0x08, + HID_USAGE_DESKTOP_TABLET_PC_SYSTEM = 0x09, + HID_USAGE_DESKTOP_X = 0x30, + HID_USAGE_DESKTOP_Y = 0x31, + HID_USAGE_DESKTOP_Z = 0x32, + HID_USAGE_DESKTOP_RX = 0x33, + HID_USAGE_DESKTOP_RY = 0x34, + HID_USAGE_DESKTOP_RZ = 0x35, + HID_USAGE_DESKTOP_SLIDER = 0x36, + HID_USAGE_DESKTOP_DIAL = 0x37, + HID_USAGE_DESKTOP_WHEEL = 0x38, + HID_USAGE_DESKTOP_HAT_SWITCH = 0x39, + HID_USAGE_DESKTOP_COUNTED_BUFFER = 0x3a, + HID_USAGE_DESKTOP_BYTE_COUNT = 0x3b, + HID_USAGE_DESKTOP_MOTION_WAKEUP = 0x3c, + HID_USAGE_DESKTOP_START = 0x3d, + HID_USAGE_DESKTOP_SELECT = 0x3e, + HID_USAGE_DESKTOP_VX = 0x40, + HID_USAGE_DESKTOP_VY = 0x41, + HID_USAGE_DESKTOP_VZ = 0x42, + HID_USAGE_DESKTOP_VBRX = 0x43, + HID_USAGE_DESKTOP_VBRY = 0x44, + HID_USAGE_DESKTOP_VBRZ = 0x45, + HID_USAGE_DESKTOP_VNO = 0x46, + HID_USAGE_DESKTOP_FEATURE_NOTIFICATION = 0x47, + HID_USAGE_DESKTOP_RESOLUTION_MULTIPLIER = 0x48, + HID_USAGE_DESKTOP_SYSTEM_CONTROL = 0x80, + HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN = 0x81, + HID_USAGE_DESKTOP_SYSTEM_SLEEP = 0x82, + HID_USAGE_DESKTOP_SYSTEM_WAKE_UP = 0x83, + HID_USAGE_DESKTOP_SYSTEM_CONTEXT_MENU = 0x84, + HID_USAGE_DESKTOP_SYSTEM_MAIN_MENU = 0x85, + HID_USAGE_DESKTOP_SYSTEM_APP_MENU = 0x86, + HID_USAGE_DESKTOP_SYSTEM_MENU_HELP = 0x87, + HID_USAGE_DESKTOP_SYSTEM_MENU_EXIT = 0x88, + HID_USAGE_DESKTOP_SYSTEM_MENU_SELECT = 0x89, + HID_USAGE_DESKTOP_SYSTEM_MENU_RIGHT = 0x8A, + HID_USAGE_DESKTOP_SYSTEM_MENU_LEFT = 0x8B, + HID_USAGE_DESKTOP_SYSTEM_MENU_UP = 0x8C, + HID_USAGE_DESKTOP_SYSTEM_MENU_DOWN = 0x8D, + HID_USAGE_DESKTOP_SYSTEM_COLD_RESTART = 0x8E, + HID_USAGE_DESKTOP_SYSTEM_WARM_RESTART = 0x8F, + HID_USAGE_DESKTOP_DPAD_UP = 0x90, + HID_USAGE_DESKTOP_DPAD_DOWN = 0x91, + HID_USAGE_DESKTOP_DPAD_RIGHT = 0x92, + HID_USAGE_DESKTOP_DPAD_LEFT = 0x93, + HID_USAGE_DESKTOP_SYSTEM_DOCK = 0xA0, + HID_USAGE_DESKTOP_SYSTEM_UNDOCK = 0xA1, + HID_USAGE_DESKTOP_SYSTEM_SETUP = 0xA2, + HID_USAGE_DESKTOP_SYSTEM_BREAK = 0xA3, + HID_USAGE_DESKTOP_SYSTEM_DEBUGGER_BREAK = 0xA4, + HID_USAGE_DESKTOP_APPLICATION_BREAK = 0xA5, + HID_USAGE_DESKTOP_APPLICATION_DEBUGGER_BREAK = 0xA6, + HID_USAGE_DESKTOP_SYSTEM_SPEAKER_MUTE = 0xA7, + HID_USAGE_DESKTOP_SYSTEM_HIBERNATE = 0xA8, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INVERT = 0xB0, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INTERNAL = 0xB1, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_EXTERNAL = 0xB2, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_BOTH = 0xB3, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_DUAL = 0xB4, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY = 0xB6, + HID_USAGE_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE = 0xB7 +}; + +/// HID Usage Table: Consumer Page (0x0C) +/// Only contains controls that supported by Windows (whole list is too long) +enum +{ + // Generic Control + HID_USAGE_CONSUMER_CONTROL = 0x0001, + + // Power Control + HID_USAGE_CONSUMER_POWER = 0x0030, + HID_USAGE_CONSUMER_RESET = 0x0031, + HID_USAGE_CONSUMER_SLEEP = 0x0032, + + // Screen Brightness + HID_USAGE_CONSUMER_BRIGHTNESS_INCREMENT = 0x006F, + HID_USAGE_CONSUMER_BRIGHTNESS_DECREMENT = 0x0070, + + // These HID usages operate only on mobile systems (battery powered) and + // require Windows 8 (build 8302 or greater). + HID_USAGE_CONSUMER_WIRELESS_RADIO_CONTROLS = 0x000C, + HID_USAGE_CONSUMER_WIRELESS_RADIO_BUTTONS = 0x00C6, + HID_USAGE_CONSUMER_WIRELESS_RADIO_LED = 0x00C7, + HID_USAGE_CONSUMER_WIRELESS_RADIO_SLIDER_SWITCH = 0x00C8, + + // Media Control + HID_USAGE_CONSUMER_PLAY_PAUSE = 0x00CD, + HID_USAGE_CONSUMER_SCAN_NEXT = 0x00B5, + HID_USAGE_CONSUMER_SCAN_PREVIOUS = 0x00B6, + HID_USAGE_CONSUMER_STOP = 0x00B7, + HID_USAGE_CONSUMER_EJECT = 0x00B8, + + HID_USAGE_CONSUMER_VOLUME = 0x00E0, + HID_USAGE_CONSUMER_MUTE = 0x00E2, + HID_USAGE_CONSUMER_BASS = 0x00E3, + HID_USAGE_CONSUMER_TREBLE = 0x00E4, + HID_USAGE_CONSUMER_BASS_BOOST = 0x00E5, + HID_USAGE_CONSUMER_VOLUME_INCREMENT = 0x00E9, + HID_USAGE_CONSUMER_VOLUME_DECREMENT = 0x00EA, + HID_USAGE_CONSUMER_BASS_INCREMENT = 0x0152, + HID_USAGE_CONSUMER_BASS_DECREMENT = 0x0153, + HID_USAGE_CONSUMER_TREBLE_INCREMENT = 0x0154, + HID_USAGE_CONSUMER_TREBLE_DECREMENT = 0x0155, + + // Application Launcher + HID_USAGE_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION = 0x0183, + HID_USAGE_CONSUMER_AL_EMAIL_READER = 0x018A, + HID_USAGE_CONSUMER_AL_CALCULATOR = 0x0192, + HID_USAGE_CONSUMER_AL_LOCAL_BROWSER = 0x0194, + + // Browser/Explorer Specific + HID_USAGE_CONSUMER_AC_SEARCH = 0x0221, + HID_USAGE_CONSUMER_AC_HOME = 0x0223, + HID_USAGE_CONSUMER_AC_BACK = 0x0224, + HID_USAGE_CONSUMER_AC_FORWARD = 0x0225, + HID_USAGE_CONSUMER_AC_STOP = 0x0226, + HID_USAGE_CONSUMER_AC_REFRESH = 0x0227, + HID_USAGE_CONSUMER_AC_BOOKMARKS = 0x022A, + + // Mouse Horizontal scroll + HID_USAGE_CONSUMER_AC_PAN = 0x0238, +}; + + +#endif /* BLEHID_H_ */ diff --git a/libraries/Bluefruit52Lib/src/services/BLEUart.cpp b/libraries/Bluefruit52Lib/src/services/BLEUart.cpp index 6e80e9fd..58153637 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEUart.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEUart.cpp @@ -85,10 +85,9 @@ err_t BLEUart::start(void) // _txd.setMaxLen(BLE_MAX_DATA_PER_MTU); // TODO enable encryption when bonding is enabled -// _txd.setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS); _txd.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); - _txd.setDescriptor("TXD"); + _txd.setStringDescriptor("TXD"); VERIFY_STATUS( _txd.start() ); // Add RXD Characteristic @@ -96,10 +95,9 @@ err_t BLEUart::start(void) _rxd.setWriteCallback(bleuart_rxd_cb); // TODO enable encryption when bonding is enabled -// _rxd.setPermission(SECMODE_NO_ACCESS, SECMODE_ENC_NO_MITM); _rxd.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN); - _rxd.setDescriptor("RXD"); + _rxd.setStringDescriptor("RXD"); VERIFY_STATUS(_rxd.start()); diff --git a/libraries/nffs/examples/filesystem/filesystem.ino b/libraries/nffs/examples/filesystem/filesystem.ino index ad6866a1..d1c63b66 100644 --- a/libraries/nffs/examples/filesystem/filesystem.ino +++ b/libraries/nffs/examples/filesystem/filesystem.ino @@ -1,21 +1,16 @@ -/* - Blink - Turns on an LED on for one second, then off for one second, repeatedly. +/********************************************************************* + This is an example for our nRF52 based Bluefruit LE modules - Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO - it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care - of use the correct LED pin whatever is the board used. - If you want to know what pin the on-board LED is connected to on your Arduino model, check - the Technical Specs of your board at https://www.arduino.cc/en/Main/Products - - This example code is in the public domain. + Pick one up today in the adafruit shop! - modified 8 May 2014 - by Scott Fitzgerald - - modified 2 Sep 2016 - by Arturo Guadalupi -*/ + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + MIT license, check LICENSE for more information + All text above, and the splash screen below must be included in + any redistribution +*********************************************************************/ #include #include @@ -55,7 +50,7 @@ void setup() { fs_close(file); }else { - Serial.println("Failed (hint: paht must start with '/') "); + Serial.println("Failed (hint: paht must start with '//') "); } } }