zmk_mf68/src/endpoints.c

72 lines
1.2 KiB
C
Raw Normal View History

#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
#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;
LOG_DBG("");
2020-05-15 23:41:06 +10:00
err = zmk_usb_hid_init();
if (err)
{
LOG_ERR("USB HID Init Failed\n");
2020-05-15 23:41:06 +10:00
return err;
}
#ifdef CONFIG_ZMK_BLE
2020-05-15 23:41:06 +10:00
err = zmk_hog_init();
if (err)
{
LOG_ERR("HOG Init Failed\n");
2020-05-15 23:41:06 +10:00
return err;
}
#endif /* CONFIG_ZMK_BLE */
2020-05-15 23:41:06 +10:00
return 0;
}
2020-05-23 12:47:03 +10:00
int zmk_endpoints_send_report()
{
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");
// }
#ifdef CONFIG_ZMK_BLE
err = zmk_hog_send_report(report);
if (err)
2020-05-15 23:41:06 +10:00
{
LOG_ERR("FAILED TO SEND OVER HOG: %d", err);
}
#endif /* CONFIG_ZMK_BLE */
return 0;
}
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();
}