summaryrefslogtreecommitdiff
path: root/app/src/usb_hid.c
diff options
context:
space:
mode:
authorNick <nick.win999@gmail.com>2020-09-07 12:22:18 -0500
committerNick <nick.win999@gmail.com>2020-09-07 12:22:18 -0500
commitfa40558f73ae0b7f693d93ec931aecf9d52167a1 (patch)
tree3ab362de33ea29d2489d8a4414f88044b4e7137c /app/src/usb_hid.c
parentbc282a0a4f1af4f6f78a0dd63e5b022eb76a603c (diff)
parent61b249666b13f7f356c0e77ee5eb500d672d7dce (diff)
Merge commit '61b249666b13f7f356c0e77ee5eb500d672d7dce' into boards/dz60rgb
Diffstat (limited to 'app/src/usb_hid.c')
-rw-r--r--app/src/usb_hid.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c
index 4c6dd4b..784fc25 100644
--- a/app/src/usb_hid.c
+++ b/app/src/usb_hid.c
@@ -11,18 +11,42 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
-static enum usb_dc_status_code usb_status;
+static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
static struct device *hid_dev;
+static K_SEM_DEFINE(hid_sem, 1, 1);
+
+static void in_ready_cb(void)
+{
+ k_sem_give(&hid_sem);
+}
+
+static const struct hid_ops ops =
+{
+ .int_in_ready = in_ready_cb,
+};
+
int zmk_usb_hid_send_report(const u8_t *report, size_t len)
{
- if (usb_status == USB_DC_SUSPEND)
- {
+ switch(usb_status) {
+ case USB_DC_SUSPEND:
return usb_wakeup_request();
+ case USB_DC_ERROR:
+ case USB_DC_RESET:
+ case USB_DC_DISCONNECTED:
+ case USB_DC_UNKNOWN:
+ return -ENODEV;
+ default:
+ k_sem_take(&hid_sem, K_MSEC(30));
+ int err = hid_int_ep_write(hid_dev, report, len, NULL);
+
+ if (err) {
+ k_sem_give(&hid_sem);
+ }
+
+ return err;
}
-
- return hid_int_ep_write(hid_dev, report, len, NULL);
}
void usb_hid_status_cb(enum usb_dc_status_code status, const u8_t *params)
@@ -43,7 +67,7 @@ static int zmk_usb_hid_init(struct device *_arg)
usb_hid_register_device(hid_dev,
zmk_hid_report_desc, sizeof(zmk_hid_report_desc),
- NULL);
+ &ops);
usb_hid_init(hid_dev);