You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.0 KiB
59 lines
1.0 KiB
5 years ago
|
|
||
|
#include <device.h>
|
||
|
|
||
|
#include <usb/usb_device.h>
|
||
|
#include <usb/class/usb_hid.h>
|
||
5 years ago
|
#include <dt-bindings/zmk/keys.h>
|
||
|
|
||
5 years ago
|
#include <zmk/hid.h>
|
||
|
#include <zmk/keymap.h>
|
||
5 years ago
|
|
||
5 years ago
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||
5 years ago
|
|
||
|
static enum usb_dc_status_code usb_status;
|
||
|
|
||
|
static struct device *hid_dev;
|
||
5 years ago
|
|
||
4 years ago
|
int zmk_usb_hid_send_report(const u8_t *report, size_t len)
|
||
5 years ago
|
{
|
||
5 years ago
|
if (usb_status == USB_DC_SUSPEND)
|
||
|
{
|
||
5 years ago
|
return usb_wakeup_request();
|
||
|
}
|
||
|
|
||
4 years ago
|
return hid_int_ep_write(hid_dev, report, len, NULL);
|
||
5 years ago
|
}
|
||
|
|
||
|
void usb_hid_status_cb(enum usb_dc_status_code status, const u8_t *params)
|
||
|
{
|
||
|
usb_status = status;
|
||
|
};
|
||
|
|
||
|
int zmk_usb_hid_init()
|
||
|
{
|
||
|
int usb_enable_ret;
|
||
|
|
||
|
hid_dev = device_get_binding("HID_0");
|
||
5 years ago
|
if (hid_dev == NULL)
|
||
|
{
|
||
5 years ago
|
LOG_ERR("Unable to locate HID device");
|
||
|
return -EINVAL;
|
||
|
}
|
||
|
|
||
|
usb_hid_register_device(hid_dev,
|
||
5 years ago
|
zmk_hid_report_desc, sizeof(zmk_hid_report_desc),
|
||
5 years ago
|
NULL);
|
||
5 years ago
|
|
||
|
usb_hid_init(hid_dev);
|
||
|
|
||
|
usb_enable_ret = usb_enable(usb_hid_status_cb);
|
||
|
|
||
5 years ago
|
if (usb_enable_ret != 0)
|
||
|
{
|
||
5 years ago
|
LOG_ERR("Unable to enable USB");
|
||
|
return -EINVAL;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|