2020-05-13 04:15:33 +10:00
|
|
|
|
2020-05-18 23:11:46 +10:00
|
|
|
#include <zmk/endpoints.h>
|
|
|
|
#include <zmk/hid.h>
|
|
|
|
#include <zmk/usb_hid.h>
|
|
|
|
#include <zmk/hog.h>
|
2020-05-15 23:41:06 +10:00
|
|
|
|
2020-05-25 08:22:16 +10:00
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|
|
|
|
2020-05-15 23:41:06 +10:00
|
|
|
int zmk_endpoints_init()
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2020-05-25 08:22:16 +10:00
|
|
|
LOG_DBG("");
|
|
|
|
|
2020-05-15 23:41:06 +10:00
|
|
|
err = zmk_usb_hid_init();
|
|
|
|
if (err)
|
|
|
|
{
|
2020-05-25 08:22:16 +10:00
|
|
|
LOG_ERR("USB HID Init Failed\n");
|
2020-05-15 23:41:06 +10:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:11:46 +10:00
|
|
|
#ifdef CONFIG_ZMK_BLE
|
2020-05-15 23:41:06 +10:00
|
|
|
err = zmk_hog_init();
|
|
|
|
if (err)
|
|
|
|
{
|
2020-05-25 08:22:16 +10:00
|
|
|
LOG_ERR("HOG Init Failed\n");
|
2020-05-15 23:41:06 +10:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:11:46 +10:00
|
|
|
#endif /* CONFIG_ZMK_BLE */
|
|
|
|
|
2020-05-15 23:41:06 +10:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-13 04:15:33 +10:00
|
|
|
|
2020-05-23 12:47:03 +10:00
|
|
|
int zmk_endpoints_send_report()
|
2020-05-13 04:15:33 +10:00
|
|
|
{
|
2020-05-16 01:39:16 +10:00
|
|
|
int err;
|
2020-05-23 12:47:03 +10:00
|
|
|
struct zmk_hid_report *report = zmk_hid_get_report();
|
2020-05-15 23:41:06 +10:00
|
|
|
|
|
|
|
// if (zmk_usb_hid_send_report(report) != 0)
|
|
|
|
// {
|
|
|
|
// // LOG_DBG("USB Send Failed");
|
|
|
|
// }
|
|
|
|
|
2020-05-18 23:11:46 +10:00
|
|
|
#ifdef CONFIG_ZMK_BLE
|
2020-05-16 01:39:16 +10:00
|
|
|
err = zmk_hog_send_report(report);
|
|
|
|
if (err)
|
2020-05-15 23:41:06 +10:00
|
|
|
{
|
2020-05-25 08:22:16 +10:00
|
|
|
LOG_ERR("FAILED TO SEND OVER HOG: %d", err);
|
2020-05-13 04:15:33 +10:00
|
|
|
}
|
2020-05-18 23:11:46 +10:00
|
|
|
#endif /* CONFIG_ZMK_BLE */
|
2020-05-13 04:15:33 +10:00
|
|
|
|
|
|
|
return 0;
|
2020-05-18 23:11:46 +10:00
|
|
|
}
|
2020-05-23 12:47:03 +10:00
|
|
|
|
|
|
|
int zmk_endpoints_send_key_event(struct zmk_key_event key_event)
|
|
|
|
{
|
|
|
|
LOG_DBG("key %d, state %d\n", key_event.key, key_event.pressed);
|
|
|
|
|
|
|
|
if (key_event.pressed)
|
|
|
|
{
|
|
|
|
zmk_hid_press_key(key_event.key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zmk_hid_release_key(key_event.key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return zmk_endpoints_send_report();
|
|
|
|
}
|