From d65629b9a0b79b6e294419fe9a4118fb09491c91 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sat, 20 Jun 2020 00:11:39 -0400 Subject: Lots more pieces toward HID working again. --- app/src/behaviors/behavior_hid.c | 59 ++++++++++++++++++++++++++++++++++ app/src/behaviors/behavior_key_press.c | 13 ++++---- app/src/behaviors/behavior_keymap.c | 50 ++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 app/src/behaviors/behavior_hid.c create mode 100644 app/src/behaviors/behavior_keymap.c (limited to 'app/src/behaviors') 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 + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_hid + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include +#include + +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 diff --git a/app/src/behaviors/behavior_key_press.c b/app/src/behaviors/behavior_key_press.c index b9d0ff0..3c57c51 100644 --- a/app/src/behaviors/behavior_key_press.c +++ b/app/src/behaviors/behavior_key_press.c @@ -10,6 +10,8 @@ #include #include +#include + LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct behavior_key_press_config { }; @@ -29,19 +31,16 @@ static int behavior_key_press_init(struct device *dev) // * < 0 - Indicate error processing, report and halt further propagation. static int on_position_pressed(struct device *dev, u32_t keycode, u32_t _) { - // Invoking this triggers a *new* event, that can be linked to other behaviours. - //return zmk_key_state_press(u32_t keycode); - return 0; + LOG_DBG("pressing: %d", keycode); + return zmk_events_keycode_pressed(keycode); } // They keycode is passed by the "keymap" based on the parameter created as part of the assignment. static int on_position_released(struct device *dev, u32_t keycode, u32_t _) { - // Invoking this triggers a *new* event, that can will be handled by other behaviors - // This is the "command" piece. Which could be better/richer, but captures essence here. - // return zmk_key_state_release(u32_t keycode); - return 0; + LOG_DBG("releasing: %d", keycode); + return zmk_events_keycode_released(keycode); } static const struct behavior_driver_api behavior_key_press_driver_api = { diff --git a/app/src/behaviors/behavior_keymap.c b/app/src/behaviors/behavior_keymap.c new file mode 100644 index 0000000..48f8547 --- /dev/null +++ b/app/src/behaviors/behavior_keymap.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_keymap + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include + +struct behavior_keymap_config { }; +struct behavior_keymap_data { }; + +static int behavior_keymap_init(struct device *dev) +{ + return 0; +}; + +static int on_position_pressed(struct device *dev, u32_t row, u32_t column) +{ + return zmk_keymap_position_state_changed(row, column, true); +} + +static int on_position_released(struct device *dev, u32_t row, u32_t column) +{ + return zmk_keymap_position_state_changed(row, column, false); +} + +static const struct behavior_driver_api behavior_keymap_driver_api = { + .position_pressed = on_position_pressed, + .position_released = on_position_released +}; + + +static const struct behavior_keymap_config behavior_keymap_config = {}; + +static struct behavior_keymap_data behavior_keymap_data; + +DEVICE_AND_API_INIT(behavior_keymap, DT_INST_LABEL(0), behavior_keymap_init, + &behavior_keymap_data, + &behavior_keymap_config, + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &behavior_keymap_driver_api); \ No newline at end of file -- cgit v1.2.3