Bluetooth Remote Additions (#1330)
* Update the HID Keycodes to pull from the library * Composite BLE Report Map, add consumer & mouse HID * Add Mouse & keyboard bt remote, fixed media remote * BT Keyboard remove long press shift * Fix usb hid modifier keys * Fixed misaligned bad usb keys * Fix keyboard app keys * Partial fix for bt app and linux * Update to work across platforms * Fix for report ids * BtHidApp: move variable from bss to model, cleanup naming. * FuriHal: add const to immutable data declaration Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -218,8 +218,8 @@ bool furi_hal_bt_start_app(FuriHalBtProfile profile, GapEventCallback event_cb,
|
||||
} else if(profile == FuriHalBtProfileHidKeyboard) {
|
||||
// Change MAC address for HID profile
|
||||
config->mac_address[2]++;
|
||||
// Change name Flipper -> Keynote
|
||||
const char* clicker_str = "Keynote";
|
||||
// Change name Flipper -> Control
|
||||
const char* clicker_str = "Control";
|
||||
memcpy(&config->adv_name[1], clicker_str, strlen(clicker_str));
|
||||
}
|
||||
if(!gap_init(config, event_cb, context)) {
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#include "furi_hal_bt_hid.h"
|
||||
#include "furi_hal_usb_hid.h"
|
||||
#include "usb_hid.h"
|
||||
#include "dev_info_service.h"
|
||||
#include "battery_service.h"
|
||||
#include "hid_service.h"
|
||||
@@ -10,128 +12,118 @@
|
||||
#define FURI_HAL_BT_HID_INFO_FLAG_REMOTE_WAKE_MSK (0x01)
|
||||
#define FURI_HAL_BT_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK (0x02)
|
||||
|
||||
#define FURI_HAL_BT_HID_KB_KEYS_MAX (6)
|
||||
#define FURI_HAL_BT_HID_KB_MAX_KEYS 6
|
||||
#define FURI_HAL_BT_HID_CONSUMER_MAX_KEYS 1
|
||||
|
||||
typedef struct {
|
||||
// uint8_t report_id;
|
||||
uint8_t mods;
|
||||
uint8_t reserved;
|
||||
uint8_t key[FURI_HAL_BT_HID_KB_KEYS_MAX];
|
||||
} FuriHalBtHidKbReport;
|
||||
|
||||
typedef struct {
|
||||
uint8_t report_id;
|
||||
uint8_t key;
|
||||
} FuriHalBtHidMediaReport;
|
||||
|
||||
// TODO make composite HID device
|
||||
static uint8_t furi_hal_bt_hid_report_map_data[] = {
|
||||
0x05,
|
||||
0x01, // Usage Page (Generic Desktop)
|
||||
0x09,
|
||||
0x06, // Usage (Keyboard)
|
||||
0xA1,
|
||||
0x01, // Collection (Application)
|
||||
// 0x85, 0x01, // Report ID (1)
|
||||
0x05,
|
||||
0x07, // Usage Page (Key Codes)
|
||||
0x19,
|
||||
0xe0, // Usage Minimum (224)
|
||||
0x29,
|
||||
0xe7, // Usage Maximum (231)
|
||||
0x15,
|
||||
0x00, // Logical Minimum (0)
|
||||
0x25,
|
||||
0x01, // Logical Maximum (1)
|
||||
0x75,
|
||||
0x01, // Report Size (1)
|
||||
0x95,
|
||||
0x08, // Report Count (8)
|
||||
0x81,
|
||||
0x02, // Input (Data, Variable, Absolute)
|
||||
|
||||
0x95,
|
||||
0x01, // Report Count (1)
|
||||
0x75,
|
||||
0x08, // Report Size (8)
|
||||
0x81,
|
||||
0x01, // Input (Constant) reserved byte(1)
|
||||
|
||||
0x95,
|
||||
0x05, // Report Count (5)
|
||||
0x75,
|
||||
0x01, // Report Size (1)
|
||||
0x05,
|
||||
0x08, // Usage Page (Page# for LEDs)
|
||||
0x19,
|
||||
0x01, // Usage Minimum (1)
|
||||
0x29,
|
||||
0x05, // Usage Maximum (5)
|
||||
0x91,
|
||||
0x02, // Output (Data, Variable, Absolute), Led report
|
||||
0x95,
|
||||
0x01, // Report Count (1)
|
||||
0x75,
|
||||
0x03, // Report Size (3)
|
||||
0x91,
|
||||
0x01, // Output (Data, Variable, Absolute), Led report padding
|
||||
|
||||
0x95,
|
||||
0x06, // Report Count (6)
|
||||
0x75,
|
||||
0x08, // Report Size (8)
|
||||
0x15,
|
||||
0x00, // Logical Minimum (0)
|
||||
0x25,
|
||||
0x65, // Logical Maximum (101)
|
||||
0x05,
|
||||
0x07, // Usage Page (Key codes)
|
||||
0x19,
|
||||
0x00, // Usage Minimum (0)
|
||||
0x29,
|
||||
0x65, // Usage Maximum (101)
|
||||
0x81,
|
||||
0x00, // Input (Data, Array) Key array(6 bytes)
|
||||
|
||||
0x09,
|
||||
0x05, // Usage (Vendor Defined)
|
||||
0x15,
|
||||
0x00, // Logical Minimum (0)
|
||||
0x26,
|
||||
0xFF,
|
||||
0x00, // Logical Maximum (255)
|
||||
0x75,
|
||||
0x08, // Report Size (8 bit)
|
||||
0x95,
|
||||
0x02, // Report Count (2)
|
||||
0xB1,
|
||||
0x02, // Feature (Data, Variable, Absolute)
|
||||
|
||||
0xC0, // End Collection (Application)
|
||||
|
||||
// 0x05, 0x0C, // Usage Page (Consumer)
|
||||
// 0x09, 0x01, // Usage (Consumer Control)
|
||||
// 0xA1, 0x01, // Collection (Application)
|
||||
// 0x85, 0x02, // Report ID (2)
|
||||
// 0x05, 0x0C, // Usage Page (Consumer)
|
||||
// 0x15, 0x00, // Logical Minimum (0)
|
||||
// 0x25, 0x01, // Logical Maximum (1)
|
||||
// 0x75, 0x01, // Report Size (1)
|
||||
// 0x95, 0x07, // Report Count (7)
|
||||
// 0x09, 0xB5, // Usage (Scan Next Track)
|
||||
// 0x09, 0xB6, // Usage (Scan Previous Track)
|
||||
// 0x09, 0xB7, // Usage (Stop)
|
||||
// 0x09, 0xB8, // Usage (Eject)
|
||||
// 0x09, 0xCD, // Usage (Play/Pause)
|
||||
// 0x09, 0xE2, // Usage (Mute)
|
||||
// 0x09, 0xE9, // Usage (Volume Increment)
|
||||
// 0x09, 0xEA, // Usage (Volume Decrement)
|
||||
// 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
|
||||
// 0xC0, // End Collection
|
||||
// Report ids cant be 0
|
||||
enum HidReportId {
|
||||
ReportIdKeyboard = 1,
|
||||
ReportIdMouse = 2,
|
||||
ReportIdConsumer = 3,
|
||||
};
|
||||
// Report numbers corresponded to the report id with an offset of 1
|
||||
enum HidInputNumber {
|
||||
ReportNumberKeyboard = 0,
|
||||
ReportNumberMouse = 1,
|
||||
ReportNumberConsumer = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t mods;
|
||||
uint8_t reserved;
|
||||
uint8_t key[FURI_HAL_BT_HID_KB_MAX_KEYS];
|
||||
} __attribute__((__packed__)) FuriHalBtHidKbReport;
|
||||
|
||||
typedef struct {
|
||||
uint8_t btn;
|
||||
int8_t x;
|
||||
int8_t y;
|
||||
int8_t wheel;
|
||||
} __attribute__((__packed__)) FuriHalBtHidMouseReport;
|
||||
|
||||
typedef struct {
|
||||
uint16_t key[FURI_HAL_BT_HID_CONSUMER_MAX_KEYS];
|
||||
} __attribute__((__packed__)) FuriHalBtHidConsumerReport;
|
||||
|
||||
// keyboard+mouse+consumer hid report
|
||||
static const uint8_t furi_hal_bt_hid_report_map_data[] = {
|
||||
// Keyboard Report
|
||||
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||
HID_USAGE(HID_DESKTOP_KEYBOARD),
|
||||
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||
HID_REPORT_ID(ReportIdKeyboard),
|
||||
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||
HID_USAGE_MINIMUM(HID_KEYBOARD_L_CTRL),
|
||||
HID_USAGE_MAXIMUM(HID_KEYBOARD_R_GUI),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_LOGICAL_MAXIMUM(1),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_REPORT_COUNT(8),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_REPORT_COUNT(1),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_USAGE_PAGE(HID_PAGE_LED),
|
||||
HID_REPORT_COUNT(8),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_USAGE_MINIMUM(1),
|
||||
HID_USAGE_MAXIMUM(8),
|
||||
HID_OUTPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_REPORT_COUNT(FURI_HAL_BT_HID_KB_MAX_KEYS),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_LOGICAL_MAXIMUM(101),
|
||||
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||
HID_USAGE_MINIMUM(0),
|
||||
HID_USAGE_MAXIMUM(101),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||
HID_END_COLLECTION,
|
||||
// Mouse Report
|
||||
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||
HID_USAGE(HID_DESKTOP_MOUSE),
|
||||
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||
HID_USAGE(HID_DESKTOP_POINTER),
|
||||
HID_COLLECTION(HID_PHYSICAL_COLLECTION),
|
||||
HID_REPORT_ID(ReportIdMouse),
|
||||
HID_USAGE_PAGE(HID_PAGE_BUTTON),
|
||||
HID_USAGE_MINIMUM(1),
|
||||
HID_USAGE_MAXIMUM(3),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_LOGICAL_MAXIMUM(1),
|
||||
HID_REPORT_COUNT(3),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_REPORT_SIZE(1),
|
||||
HID_REPORT_COUNT(5),
|
||||
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||
HID_USAGE(HID_DESKTOP_X),
|
||||
HID_USAGE(HID_DESKTOP_Y),
|
||||
HID_USAGE(HID_DESKTOP_WHEEL),
|
||||
HID_LOGICAL_MINIMUM(-127),
|
||||
HID_LOGICAL_MAXIMUM(127),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_REPORT_COUNT(3),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||
HID_END_COLLECTION,
|
||||
HID_END_COLLECTION,
|
||||
// Consumer Report
|
||||
HID_USAGE_PAGE(HID_PAGE_CONSUMER),
|
||||
HID_USAGE(HID_CONSUMER_CONTROL),
|
||||
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||
HID_REPORT_ID(ReportIdConsumer),
|
||||
HID_LOGICAL_MINIMUM(0),
|
||||
HID_RI_LOGICAL_MAXIMUM(16, 0x3FF),
|
||||
HID_USAGE_MINIMUM(0),
|
||||
HID_RI_USAGE_MAXIMUM(16, 0x3FF),
|
||||
HID_REPORT_COUNT(FURI_HAL_BT_HID_CONSUMER_MAX_KEYS),
|
||||
HID_REPORT_SIZE(16),
|
||||
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||
HID_END_COLLECTION,
|
||||
};
|
||||
FuriHalBtHidKbReport* kb_report = NULL;
|
||||
FuriHalBtHidMediaReport* media_report = NULL;
|
||||
FuriHalBtHidMouseReport* mouse_report = NULL;
|
||||
FuriHalBtHidConsumerReport* consumer_report = NULL;
|
||||
|
||||
void furi_hal_bt_hid_start() {
|
||||
// Start device info
|
||||
@@ -148,7 +140,8 @@ void furi_hal_bt_hid_start() {
|
||||
}
|
||||
// Configure HID Keyboard
|
||||
kb_report = malloc(sizeof(FuriHalBtHidKbReport));
|
||||
media_report = malloc(sizeof(FuriHalBtHidMediaReport));
|
||||
mouse_report = malloc(sizeof(FuriHalBtHidMouseReport));
|
||||
consumer_report = malloc(sizeof(FuriHalBtHidConsumerReport));
|
||||
// Configure Report Map characteristic
|
||||
hid_svc_update_report_map(
|
||||
furi_hal_bt_hid_report_map_data, sizeof(furi_hal_bt_hid_report_map_data));
|
||||
@@ -165,6 +158,8 @@ void furi_hal_bt_hid_start() {
|
||||
|
||||
void furi_hal_bt_hid_stop() {
|
||||
furi_assert(kb_report);
|
||||
furi_assert(mouse_report);
|
||||
furi_assert(consumer_report);
|
||||
// Stop all services
|
||||
if(dev_info_svc_is_started()) {
|
||||
dev_info_svc_stop();
|
||||
@@ -176,61 +171,119 @@ void furi_hal_bt_hid_stop() {
|
||||
hid_svc_stop();
|
||||
}
|
||||
free(kb_report);
|
||||
free(media_report);
|
||||
media_report = NULL;
|
||||
free(mouse_report);
|
||||
free(consumer_report);
|
||||
kb_report = NULL;
|
||||
mouse_report = NULL;
|
||||
consumer_report = NULL;
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_kb_press(uint16_t button) {
|
||||
furi_assert(kb_report);
|
||||
// kb_report->report_id = 0x01;
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_KB_KEYS_MAX; i++) {
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_KB_MAX_KEYS; i++) {
|
||||
if(kb_report->key[i] == 0) {
|
||||
kb_report->key[i] = button & 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
kb_report->mods |= (button >> 8);
|
||||
return hid_svc_update_input_report((uint8_t*)kb_report, sizeof(FuriHalBtHidKbReport));
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberKeyboard, (uint8_t*)kb_report, sizeof(FuriHalBtHidKbReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_kb_release(uint16_t button) {
|
||||
furi_assert(kb_report);
|
||||
// kb_report->report_id = 0x01;
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_KB_KEYS_MAX; i++) {
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_KB_MAX_KEYS; i++) {
|
||||
if(kb_report->key[i] == (button & 0xFF)) {
|
||||
kb_report->key[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
kb_report->mods &= ~(button >> 8);
|
||||
return hid_svc_update_input_report((uint8_t*)kb_report, sizeof(FuriHalBtHidKbReport));
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberKeyboard, (uint8_t*)kb_report, sizeof(FuriHalBtHidKbReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_kb_release_all() {
|
||||
furi_assert(kb_report);
|
||||
// kb_report->report_id = 0x01;
|
||||
memset(kb_report, 0, sizeof(FuriHalBtHidKbReport));
|
||||
return hid_svc_update_input_report((uint8_t*)kb_report, sizeof(FuriHalBtHidKbReport));
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_KB_MAX_KEYS; i++) {
|
||||
kb_report->key[i] = 0;
|
||||
}
|
||||
kb_report->mods = 0;
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberKeyboard, (uint8_t*)kb_report, sizeof(FuriHalBtHidKbReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_media_press(uint8_t button) {
|
||||
furi_assert(media_report);
|
||||
media_report->report_id = 0x02;
|
||||
media_report->key |= (0x01 << button);
|
||||
return hid_svc_update_input_report((uint8_t*)media_report, sizeof(FuriHalBtHidMediaReport));
|
||||
bool furi_hal_bt_hid_consumer_key_press(uint16_t button) {
|
||||
furi_assert(consumer_report);
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) {
|
||||
if(consumer_report->key[i] == 0) {
|
||||
consumer_report->key[i] = button;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberConsumer, (uint8_t*)consumer_report, sizeof(FuriHalBtHidConsumerReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_media_release(uint8_t button) {
|
||||
furi_assert(media_report);
|
||||
media_report->report_id = 0x02;
|
||||
media_report->key &= ~(0x01 << button);
|
||||
return hid_svc_update_input_report((uint8_t*)media_report, sizeof(FuriHalBtHidMediaReport));
|
||||
bool furi_hal_bt_hid_consumer_key_release(uint16_t button) {
|
||||
furi_assert(consumer_report);
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) {
|
||||
if(consumer_report->key[i] == button) {
|
||||
consumer_report->key[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberConsumer, (uint8_t*)consumer_report, sizeof(FuriHalBtHidConsumerReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_media_release_all() {
|
||||
furi_assert(media_report);
|
||||
media_report->report_id = 0x02;
|
||||
media_report->key = 0x00;
|
||||
return hid_svc_update_input_report((uint8_t*)media_report, sizeof(FuriHalBtHidMediaReport));
|
||||
bool furi_hal_bt_hid_consumer_key_release_all() {
|
||||
furi_assert(consumer_report);
|
||||
for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) {
|
||||
consumer_report->key[i] = 0;
|
||||
}
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberConsumer, (uint8_t*)consumer_report, sizeof(FuriHalBtHidConsumerReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_mouse_move(int8_t dx, int8_t dy) {
|
||||
furi_assert(mouse_report);
|
||||
mouse_report->x = dx;
|
||||
mouse_report->y = dy;
|
||||
bool state = hid_svc_update_input_report(
|
||||
ReportNumberMouse, (uint8_t*)mouse_report, sizeof(FuriHalBtHidMouseReport));
|
||||
mouse_report->x = 0;
|
||||
mouse_report->y = 0;
|
||||
return state;
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_mouse_press(uint8_t button) {
|
||||
furi_assert(mouse_report);
|
||||
mouse_report->btn |= button;
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberMouse, (uint8_t*)mouse_report, sizeof(FuriHalBtHidMouseReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_mouse_release(uint8_t button) {
|
||||
furi_assert(mouse_report);
|
||||
mouse_report->btn &= ~button;
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberMouse, (uint8_t*)mouse_report, sizeof(FuriHalBtHidMouseReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_mouse_release_all() {
|
||||
furi_assert(mouse_report);
|
||||
mouse_report->btn = 0;
|
||||
return hid_svc_update_input_report(
|
||||
ReportNumberMouse, (uint8_t*)mouse_report, sizeof(FuriHalBtHidMouseReport));
|
||||
}
|
||||
|
||||
bool furi_hal_bt_hid_mouse_scroll(int8_t delta) {
|
||||
furi_assert(mouse_report);
|
||||
mouse_report->wheel = delta;
|
||||
bool state = hid_svc_update_input_report(
|
||||
ReportNumberMouse, (uint8_t*)mouse_report, sizeof(FuriHalBtHidMouseReport));
|
||||
mouse_report->wheel = 0;
|
||||
return state;
|
||||
}
|
||||
|
@@ -6,11 +6,6 @@
|
||||
|
||||
#include "usb.h"
|
||||
#include "usb_hid.h"
|
||||
#include "hid_usage_desktop.h"
|
||||
#include "hid_usage_button.h"
|
||||
#include "hid_usage_keyboard.h"
|
||||
#include "hid_usage_consumer.h"
|
||||
#include "hid_usage_led.h"
|
||||
|
||||
#define HID_EP_IN 0x81
|
||||
#define HID_EP_OUT 0x01
|
||||
|
Reference in New Issue
Block a user