diff options
Diffstat (limited to 'app/src/behaviors/behavior_hid.c')
-rw-r--r-- | app/src/behaviors/behavior_hid.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/src/behaviors/behavior_hid.c b/app/src/behaviors/behavior_hid.c new file mode 100644 index 0000000..2779568 --- /dev/null +++ b/app/src/behaviors/behavior_hid.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_hid + +#include <device.h> +#include <power/reboot.h> +#include <drivers/behavior.h> +#include <logging/log.h> + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include <zmk/hid.h> +#include <zmk/endpoints.h> + +struct behavior_hid_config { }; +struct behavior_hid_data { }; + +static int behavior_hid_init(struct device *dev) +{ + return 0; +}; + +static int on_keycode_pressed(struct device *dev, u32_t keycode) +{ + enum zmk_hid_report_changes changes; + LOG_DBG("keycode %d", keycode); + + changes = zmk_hid_press_key(keycode); + return zmk_endpoints_send_report(changes); +} + +static int on_keycode_released(struct device *dev, u32_t keycode) +{ + enum zmk_hid_report_changes changes; + LOG_DBG("keycode %d", keycode); + + changes = zmk_hid_release_key(keycode); + return zmk_endpoints_send_report(changes); +} + +static const struct behavior_driver_api behavior_hid_driver_api = { + .keycode_pressed = on_keycode_pressed, + .keycode_released = on_keycode_released +}; + + +static const struct behavior_hid_config behavior_hid_config = {}; + +static struct behavior_hid_data behavior_hid_data; + +DEVICE_AND_API_INIT(behavior_hid, DT_INST_LABEL(0), behavior_hid_init, + &behavior_hid_data, + &behavior_hid_config, + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &behavior_hid_driver_api);
\ No newline at end of file |