diff --git a/epicardium/ble/ble_main.c b/epicardium/ble/ble_main.c index 12c62f2a9313abe28892f8a6ebc5d46259a8770a..f952c560db75b8cbc95db25366e56dd60817ccc9 100644 --- a/epicardium/ble/ble_main.c +++ b/epicardium/ble/ble_main.c @@ -235,7 +235,7 @@ static const attsCccSet_t bleCccSet[BLE_NUM_CCC_IDX] = {ESS_PRES_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* BLE_ESS_PRES_CCC_IDX */ {HID_MOUSE_BOOT_IN_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* HIDAPP_MBI_CCC_HDL */ {HID_KEYBOARD_BOOT_IN_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* HIDAPP_KBI_CCC_HDL */ - {HID_INPUT_REPORT_1_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* HIDAPP_IN_REMOTE_CCC_HDL */ + {HID_INPUT_REPORT_1_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* HIDAPP_IN_CONSUMER_CCC_HDL */ {HID_INPUT_REPORT_2_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* HIDAPP_IN_KEYBOARD_CCC_HDL */ {HID_INPUT_REPORT_3_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* HIDAPP_IN_MOUSE_CCC_HDL */ }; diff --git a/epicardium/ble/cccd.h b/epicardium/ble/cccd.h index 1f75bc640d27efa41dbc64abd24c2f399d10c0af..d3c063d06a0da1953f2987adcd1523c5bc66c3fd 100644 --- a/epicardium/ble/cccd.h +++ b/epicardium/ble/cccd.h @@ -9,7 +9,7 @@ enum BLE_ESS_PRES_CCC_IDX, /*! Environmental sensing service, pressure characteristic */ HIDAPP_MBI_CCC_HDL, /*! HID Boot Mouse Input characteristic */ HIDAPP_KBI_CCC_HDL, /*! HID Boot Keyboard Input characteristic */ - HIDAPP_IN_REMOTE_CCC_HDL, /*! HID Input Report characteristic for remote inputs */ + HIDAPP_IN_CONSUMER_CCC_HDL, /*! HID Input Report characteristic for consumer control inputs */ HIDAPP_IN_KEYBOARD_CCC_HDL, /*! HID Input Report characteristic for keyboard inputs */ HIDAPP_IN_MOUSE_CCC_HDL, /*! HID Input Report characteristic for mouse inputs */ BLE_NUM_CCC_IDX diff --git a/epicardium/ble/hid.c b/epicardium/ble/hid.c index c5fedf45e8fa95fb729cd624e7f958157a9a0985..be67305bbef87ef6cde3c9472a8fdb13fa0db02e 100644 --- a/epicardium/ble/hid.c +++ b/epicardium/ble/hid.c @@ -21,36 +21,18 @@ /* clang-format off */ const uint8_t hidReportMap[] = { - 0x05, 0x0c, /* Usage Page (Consumer Devices) */ - 0x09, 0x01, /* Usage (Consumer Control) */ - 0xa1, 0x01, /* Collection (Application) */ - 0x85, HIDAPP_REMOTE_REPORT_ID, /* report ID (HIDAPP_REMOTE_REPORT_ID) */ - 0x15, 0x00, /* Logical Minimum (0) */ - 0x25, 0x01, /* Logical Maximum (1) */ - 0x09, 0xe9, /* Usage (Volume Up) */ - 0x09, 0xea, /* Usage (Volume Down) */ - 0x75, 0x01, /* Report Size (1) */ - 0x95, 0x02, /* Report Count (2) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0x09, 0xe2, /* Usage (Mute) */ - 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0x09, 0xb0, /* Usage (Play) */ - 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0x09, 0xb1, /* Usage (Pause) */ - 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0x09, 0xb7, /* Usage (Stop) */ - 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0x09, 0xb5, /* Usage (Next) */ - 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0x09, 0xb6, /* Usage (Previous) */ - 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0xc0, /* End Collection */ + 0x05, 0x0C, /* Usage Page (Consumer) */ + 0x09, 0x01, /* Usage (Consumer Control) */ + 0xA1, 0x01, /* Collection (Application) */ + 0x85, HIDAPP_CONSUMER_REPORT_ID,/* Report ID (HIDAPP_CONSUMER_REPORT_ID) */ + 0x75, 0x10, /* Report Size (16) */ + 0x95, 0x01, /* Report Count (1) */ + 0x15, 0x01, /* Logical Minimum (1) */ + 0x26, 0x8C, 0x02, /* Logical Maximum (652) */ + 0x19, 0x01, /* Usage Minimum (Consumer Control) */ + 0x2A, 0x8C, 0x02, /* Usage Maximum (AC Send) */ + 0x81, 0x00, /* Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) */ + 0xC0, /* End Collection */ 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x06, /* Usage (Keyboard) */ 0xA1, 0x01, /* Collection (Application) */ @@ -121,7 +103,7 @@ const uint16_t hidReportMapLen = sizeof(hidReportMap); static const hidReportIdMap_t hidAppReportIdSet[] = { /* type ID handle */ - {HID_REPORT_TYPE_INPUT, HIDAPP_REMOTE_REPORT_ID, HID_INPUT_REPORT_1_HDL}, /* Remote Input Report */ + {HID_REPORT_TYPE_INPUT, HIDAPP_CONSUMER_REPORT_ID, HID_INPUT_REPORT_1_HDL}, /* Consumer Control Input Report */ {HID_REPORT_TYPE_INPUT, HIDAPP_KEYBOARD_REPORT_ID, HID_INPUT_REPORT_2_HDL}, /* Keyboard Input Report */ {HID_REPORT_TYPE_OUTPUT, HIDAPP_KEYBOARD_REPORT_ID, HID_OUTPUT_REPORT_HDL}, /* Keyboard Output Report */ {HID_REPORT_TYPE_FEATURE, HIDAPP_KEYBOARD_REPORT_ID, HID_FEATURE_REPORT_HDL}, /* Keyboard Feature Report */ @@ -156,16 +138,16 @@ static void hidAppReportInit(void) { uint8_t iKeyboardBuffer[HIDAPP_KEYBOARD_INPUT_REPORT_LEN]; uint8_t iMouseBuffer[HIDAPP_MOUSE_INPUT_REPORT_LEN]; - uint8_t iRemoteBuffer[HIDAPP_REMOTE_INPUT_REPORT_LEN]; + uint8_t iConsumerBuffer[HIDAPP_CONSUMER_INPUT_REPORT_LEN]; uint8_t oBuffer[HIDAPP_OUTPUT_REPORT_LEN]; uint8_t fBuffer[HIDAPP_FEATURE_REPORT_LEN]; - /* Remote Input report */ - memset(iRemoteBuffer, 0, HIDAPP_REMOTE_INPUT_REPORT_LEN); + /* Consumer Control Input report */ + memset(iConsumerBuffer, 0, HIDAPP_CONSUMER_INPUT_REPORT_LEN); AttsSetAttr( HID_INPUT_REPORT_1_HDL, - HIDAPP_REMOTE_INPUT_REPORT_LEN, - iRemoteBuffer + HIDAPP_CONSUMER_INPUT_REPORT_LEN, + iConsumerBuffer ); /* Keyboard Input report */ diff --git a/epicardium/ble/hid.h b/epicardium/ble/hid.h index da489fcbb25a6c647439b011bb7500db6d313ed3..9e41986eb4a7d4ff17ee5826d413956e468f9c99 100644 --- a/epicardium/ble/hid.h +++ b/epicardium/ble/hid.h @@ -3,12 +3,12 @@ /* The input report fits in one byte */ #define HIDAPP_KEYBOARD_INPUT_REPORT_LEN 8 #define HIDAPP_MOUSE_INPUT_REPORT_LEN 3 -#define HIDAPP_REMOTE_INPUT_REPORT_LEN 1 +#define HIDAPP_CONSUMER_INPUT_REPORT_LEN 2 #define HIDAPP_OUTPUT_REPORT_LEN 1 #define HIDAPP_FEATURE_REPORT_LEN 1 /* HID Report IDs */ -#define HIDAPP_REMOTE_REPORT_ID 1 +#define HIDAPP_CONSUMER_REPORT_ID 1 #define HIDAPP_KEYBOARD_REPORT_ID 2 #define HIDAPP_MOUSE_REPORT_ID 3 diff --git a/epicardium/ble/hid_work.c b/epicardium/ble/hid_work.c index 1d529491efecb0a7a1ef3196bc9d4d343e3449cc..4fdd0c1deb2ba0a46638e48a1896fe93b9d7e158 100644 --- a/epicardium/ble/hid_work.c +++ b/epicardium/ble/hid_work.c @@ -90,8 +90,8 @@ static bool hid_dequeue_data(dmConnId_t connId) cccHandle = HIDAPP_IN_KEYBOARD_CCC_HDL; } else if (report.reportId == HIDAPP_MOUSE_REPORT_ID) { cccHandle = HIDAPP_IN_MOUSE_CCC_HDL; - } else if (report.reportId == HIDAPP_REMOTE_REPORT_ID) { - cccHandle = HIDAPP_IN_REMOTE_CCC_HDL; + } else if (report.reportId == HIDAPP_CONSUMER_REPORT_ID) { + cccHandle = HIDAPP_IN_CONSUMER_CCC_HDL; } else { break; }; diff --git a/preload/apps/hid.py b/preload/apps/hid.py index 53587f739c25a470e7a322c06cbcb8c9498b5b12..86c4a84238f1f65fb5c074fe89e37235722f572a 100644 --- a/preload/apps/hid.py +++ b/preload/apps/hid.py @@ -3,9 +3,9 @@ import buttons import color import display -BUTTON_VOLUME_UP = 1 -BUTTON_VOLUME_DOWN = 2 -BUTTON_PLAY = 8 +VOLUME_UP = 0xE9 +VOLUME_DOWN = 0xEA +PLAY_PAUSE = 0xCD disp = display.open() disp.clear() @@ -23,11 +23,11 @@ while True: print(b_new) b_old = b_new if b_new == buttons.TOP_RIGHT: - hid.set_button(BUTTON_VOLUME_UP) - hid.set_button(0) + hid.set_control(VOLUME_UP) + hid.set_control(0) elif b_new == buttons.BOTTOM_RIGHT: - hid.set_button(BUTTON_VOLUME_DOWN) - hid.set_button(0) + hid.set_control(VOLUME_DOWN) + hid.set_control(0) elif b_new == buttons.BOTTOM_LEFT: - hid.set_button(BUTTON_PLAY) - hid.set_button(0) + hid.set_control(PLAY_PAUSE) + hid.set_control(0) diff --git a/pycardium/modules/hid.c b/pycardium/modules/hid.c index 25134d5dc9225c2e57d4522a6927e41495be01bf..f8823b794a97c425c1f2e8488261c6fd0fba950f 100644 --- a/pycardium/modules/hid.c +++ b/pycardium/modules/hid.c @@ -4,18 +4,18 @@ #include "py/obj.h" #include "py/runtime.h" -static mp_obj_t mp_hid_set_button(mp_obj_t button_id) +static mp_obj_t mp_hid_set_control(mp_obj_t control_code) { - int id = mp_obj_get_int(button_id); - uint8_t data[] = { id }; + int code = mp_obj_get_int(control_code); + uint8_t data[] = { code, code >> 8 }; int ret = epic_hid_send_report(1, data, sizeof(data)); return mp_obj_new_int(ret); } -static MP_DEFINE_CONST_FUN_OBJ_1(hid_set_button_obj, mp_hid_set_button); +static MP_DEFINE_CONST_FUN_OBJ_1(hid_set_control_obj, mp_hid_set_control); static const mp_rom_map_elem_t hid_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hid) }, - { MP_ROM_QSTR(MP_QSTR_set_button), MP_ROM_PTR(&hid_set_button_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_control), MP_ROM_PTR(&hid_set_control_obj) }, }; static MP_DEFINE_CONST_DICT(hid_module_globals, hid_module_globals_table); diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index 550d4591aeb12a5c24b64ca94f74e36526d8a995..fd33985e04a083572459c0be961051dd10031717 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -212,7 +212,7 @@ Q(EVENT_PAIRING_COMPLETE) Q(EVENT_PAIRING_FAILED) Q(EVENT_SCAN_REPORT) Q(hid) -Q(set_button) +Q(set_control) /* SpO2 */ Q(spo2_algo)