Skip to content
Snippets Groups Projects
Commit 2a1591ea authored by schneider's avatar schneider
Browse files

change(hid): Clean up epicardium API

parent a0b2edd0
No related branches found
No related tags found
1 merge request!382HID over BLE
...@@ -31,7 +31,7 @@ struct ...@@ -31,7 +31,7 @@ struct
/* clang-format on */ /* clang-format on */
struct report { struct report {
uint8_t reportId; uint8_t report_id;
uint8_t data[8]; uint8_t data[8];
uint8_t len; uint8_t len;
}; };
...@@ -42,10 +42,20 @@ static QueueHandle_t queue; ...@@ -42,10 +42,20 @@ static QueueHandle_t queue;
static uint8_t buffer[sizeof(struct report) * QUEUE_SIZE]; static uint8_t buffer[sizeof(struct report) * QUEUE_SIZE];
static StaticQueue_t queue_data; static StaticQueue_t queue_data;
static int hid_queue_data(uint8_t reportId, uint8_t *data, uint8_t len) static int hid_queue_data(uint8_t report_id, uint8_t *data, uint8_t len)
{ {
struct report report; struct report report;
report.reportId = reportId;
if (report_id < 1 || report_id > 3) {
return -EINVAL;
}
report.report_id = report_id;
if (len > sizeof(report.data)) {
return -EINVAL;
}
memcpy(report.data, data, len); memcpy(report.data, data, len);
report.len = len; report.len = len;
...@@ -76,21 +86,21 @@ static bool hid_dequeue_data(dmConnId_t connId) ...@@ -76,21 +86,21 @@ static bool hid_dequeue_data(dmConnId_t connId)
} }
if (HidGetProtocolMode() == HID_PROTOCOL_MODE_BOOT) { if (HidGetProtocolMode() == HID_PROTOCOL_MODE_BOOT) {
if (report.reportId == HIDAPP_KEYBOARD_REPORT_ID) { if (report.report_id == HIDAPP_KEYBOARD_REPORT_ID) {
report.reportId = HID_KEYBOARD_BOOT_ID; report.report_id = HID_KEYBOARD_BOOT_ID;
cccHandle = HIDAPP_KBI_CCC_HDL; cccHandle = HIDAPP_KBI_CCC_HDL;
} else if (report.reportId == HIDAPP_MOUSE_REPORT_ID) { } else if (report.report_id == HIDAPP_MOUSE_REPORT_ID) {
report.reportId = HID_MOUSE_BOOT_ID; report.report_id = HID_MOUSE_BOOT_ID;
cccHandle = HIDAPP_MBI_CCC_HDL; cccHandle = HIDAPP_MBI_CCC_HDL;
} else { } else {
break; break;
} }
} else { } else {
if (report.reportId == HIDAPP_KEYBOARD_REPORT_ID) { if (report.report_id == HIDAPP_KEYBOARD_REPORT_ID) {
cccHandle = HIDAPP_IN_KEYBOARD_CCC_HDL; cccHandle = HIDAPP_IN_KEYBOARD_CCC_HDL;
} else if (report.reportId == HIDAPP_MOUSE_REPORT_ID) { } else if (report.report_id == HIDAPP_MOUSE_REPORT_ID) {
cccHandle = HIDAPP_IN_MOUSE_CCC_HDL; cccHandle = HIDAPP_IN_MOUSE_CCC_HDL;
} else if (report.reportId == HIDAPP_CONSUMER_REPORT_ID) { } else if (report.report_id == HIDAPP_CONSUMER_REPORT_ID) {
cccHandle = HIDAPP_IN_CONSUMER_CCC_HDL; cccHandle = HIDAPP_IN_CONSUMER_CCC_HDL;
} else { } else {
break; break;
...@@ -102,7 +112,7 @@ static bool hid_dequeue_data(dmConnId_t connId) ...@@ -102,7 +112,7 @@ static bool hid_dequeue_data(dmConnId_t connId)
/* Send the message */ /* Send the message */
HidSendInputReport( HidSendInputReport(
connId, connId,
report.reportId, report.report_id,
report.len, report.len,
report.data report.data
); );
...@@ -114,27 +124,6 @@ static bool hid_dequeue_data(dmConnId_t connId) ...@@ -114,27 +124,6 @@ static bool hid_dequeue_data(dmConnId_t connId)
return true; return true;
} }
int epic_ble_hid_send_report(uint8_t reportId, uint8_t *data, uint8_t len)
{
dmConnId_t connId = AppConnIsOpen();
if (connId == DM_CONN_ID_NONE) {
return -EIO;
}
int ret;
ret = hid_queue_data(reportId, data, len);
if (ret < 0) {
return ret;
}
if (hid_dequeue_data(connId)) {
return 0;
} else {
return 1;
}
}
/*************************************************************************************************/ /*************************************************************************************************/
/*! /*!
* \brief Callback to handle an output report from the host. * \brief Callback to handle an output report from the host.
...@@ -218,6 +207,27 @@ void HidProcMsg(wsfMsgHdr_t *pMsg) ...@@ -218,6 +207,27 @@ void HidProcMsg(wsfMsgHdr_t *pMsg)
} }
} }
int epic_ble_hid_send_report(uint8_t report_id, uint8_t *data, uint8_t len)
{
dmConnId_t connId = AppConnIsOpen();
if (connId == DM_CONN_ID_NONE) {
return -EIO;
}
int ret;
ret = hid_queue_data(report_id, data, len);
if (ret < 0) {
return ret;
}
if (hid_dequeue_data(connId)) {
return 0;
} else {
return 1;
}
}
void hid_work_init(void) void hid_work_init(void)
{ {
queue = xQueueCreateStatic( queue = xQueueCreateStatic(
......
...@@ -2322,28 +2322,22 @@ API(API_BLE_SET_MODE, void epic_ble_set_mode(bool bondable, bool scanner)); ...@@ -2322,28 +2322,22 @@ API(API_BLE_SET_MODE, void epic_ble_set_mode(bool bondable, bool scanner));
*/ */
API(API_BLE_GET_SCAN_REPORT, int epic_ble_get_scan_report(struct epic_scan_report *rpt)); API(API_BLE_GET_SCAN_REPORT, int epic_ble_get_scan_report(struct epic_scan_report *rpt));
/**
* Human Interface Device (HID)
* ==========================
*/
/** /**
* Send an input report to the host. * Send an input report to the host.
* *
* :param uint8_t reportId: The id of the report to use. 0: remote, 1: keyboard, 2: mouse * :param uint8_t report_id: The id of the report to use. 1: keyboard, 2: mouse, 3: consumer control
* :param uint8_t *data: Data to be reported. * :param uint8_t *data: Data to be reported.
* :param uint8_t len: Length in bytes of the data to be reported. Maximum length in 8 bytes. * :param uint8_t len: Length in bytes of the data to be reported. Maximum length is 8 bytes.
* *
* :return: `0` on success, `1` if the report is queued or a negative value if an error occured. Possible * :return: `0` on success, `1` if the report is queued or a negative value if an error occured. Possible
* errors: * errors:
* *
* - ``-EIO``: There is no host device connected * - ``-EIO``: There is no host device connected
* - ``-EAGAIN``: There is no space in the queue available. Try again later. * - ``-EAGAIN``: There is no space in the queue available. Try again later.
* - ``-EINVAL``: Either the report_id is out of range or the data is too long.
* *
*/ */
API(API_BLE_HID_SEND_REPORT, int epic_ble_hid_send_report(uint8_t reportId, uint8_t *data, uint8_t len)); API(API_BLE_HID_SEND_REPORT, int epic_ble_hid_send_report(uint8_t report_id, uint8_t *data, uint8_t len));
#endif /* _EPICARDIUM_H */ #endif /* _EPICARDIUM_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment