summaryrefslogtreecommitdiff
path: root/app/src/behaviors/behavior_hid.c
blob: 2779568ed5c4fe78259e13b76bf2d80097a62d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);