From c23d752917774bc740c791e2f7eeef6f8f9e1033 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 19 Jun 2020 15:32:33 -0400 Subject: Some initial work on behavior bindings for keymaps --- app/include/drivers/behavior.h | 88 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 app/include/drivers/behavior.h (limited to 'app/include/drivers/behavior.h') diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h new file mode 100644 index 0000000..84b11ce --- /dev/null +++ b/app/include/drivers/behavior.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @cond INTERNAL_HIDDEN + * + * Behavior driver API definition and system call entry points. + * + * (Internal use only.) + */ + +typedef int (*behavior_position_pressed_t)(struct device *dev, u32_t param1, u32_t param2); +typedef int (*behavior_position_released_t)(struct device *dev, u32_t param1, u32_t param2); + +__subsystem struct behavior_driver_api { + behavior_position_pressed_t position_pressed; + behavior_position_released_t position_released; +}; +/** + * @endcond + */ + +/** + * @brief Handle the assigned position being pressed + * @param dev Pointer to the device structure for the driver instance. + * @param param1 User parameter specified at time of behavior assignment. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_position_pressed(struct device *dev, u32_t param1, u32_t param2); + +static inline int z_impl_behavior_position_pressed(struct device *dev, u32_t param1, u32_t param2) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->position_pressed == NULL) { + return -ENOTSUP; + } + + return api->position_pressed(dev, param1, param2); +} + +/** + * @brief Handle the assigned position being pressed + * @param dev Pointer to the device structure for the driver instance. + * @param param1 User parameter specified at time of behavior assignment. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_position_released(struct device *dev, u32_t param1, u32_t param2); + +static inline int z_impl_behavior_position_released(struct device *dev, u32_t param1, u32_t param2) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->position_released == NULL) { + return -ENOTSUP; + } + + return api->position_released(dev, param1, param2); +} + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#include -- cgit v1.2.3 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/include/drivers/behavior.h | 55 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'app/include/drivers/behavior.h') diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h index 84b11ce..f5f5f53 100644 --- a/app/include/drivers/behavior.h +++ b/app/include/drivers/behavior.h @@ -22,12 +22,14 @@ extern "C" { * (Internal use only.) */ -typedef int (*behavior_position_pressed_t)(struct device *dev, u32_t param1, u32_t param2); -typedef int (*behavior_position_released_t)(struct device *dev, u32_t param1, u32_t param2); +typedef int (*behavior_position_callback_t)(struct device *dev, u32_t param1, u32_t param2); +typedef int (*behavior_keycode_callback_t)(struct device *dev, u32_t keycode); __subsystem struct behavior_driver_api { - behavior_position_pressed_t position_pressed; - behavior_position_released_t position_released; + behavior_position_callback_t position_pressed; + behavior_position_callback_t position_released; + behavior_keycode_callback_t keycode_pressed; + behavior_keycode_callback_t keycode_released; }; /** * @endcond @@ -77,6 +79,51 @@ static inline int z_impl_behavior_position_released(struct device *dev, u32_t pa return api->position_released(dev, param1, param2); } +/** + * @brief Handle the keycode being pressed + * @param dev Pointer to the device structure for the driver instance. + * @param keycode The keycode that is being pressed. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_keycode_pressed(struct device *dev, u32_t keycode); + +static inline int z_impl_behavior_keycode_pressed(struct device *dev, u32_t keycode) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->keycode_pressed == NULL) { + return -ENOTSUP; + } + + return api->keycode_pressed(dev, keycode); +} + + +/** + * @brief Handle the keycode being released + * @param dev Pointer to the device structure for the driver instance. + * @param keycode The keycode that is being pressed. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_keycode_released(struct device *dev, u32_t keycode); + +static inline int z_impl_behavior_keycode_released(struct device *dev, u32_t keycode) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->keycode_released == NULL) { + return -ENOTSUP; + } + + return api->keycode_released(dev, keycode); +} + #ifdef __cplusplus } #endif -- cgit v1.2.3 From 223edf05ad08938b066f9187668ebfae43c5e91a Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 21 Jun 2020 21:43:44 -0400 Subject: Refactor global bindings, implement mod-tap. * Use extra comptible = "zmk,behavior-global" to add behaviors to global bindings for event notification. * Implement mod-tap, as a keymap binding and global one to skip tap if other keycode pressed while held. --- app/include/drivers/behavior.h | 119 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 109 insertions(+), 10 deletions(-) (limited to 'app/include/drivers/behavior.h') diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h index f5f5f53..b3c6ad2 100644 --- a/app/include/drivers/behavior.h +++ b/app/include/drivers/behavior.h @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -22,30 +23,36 @@ extern "C" { * (Internal use only.) */ -typedef int (*behavior_position_callback_t)(struct device *dev, u32_t param1, u32_t param2); +typedef int (*behavior_position_callback_t)(struct device *dev, u32_t position); +typedef int (*behavior_keymap_binding_callback_t)(struct device *dev, u32_t position, u32_t param1, u32_t param2); typedef int (*behavior_keycode_callback_t)(struct device *dev, u32_t keycode); +typedef int (*behavior_modifiers_callback_t)(struct device *dev, zmk_mod_flags modifiers); __subsystem struct behavior_driver_api { behavior_position_callback_t position_pressed; behavior_position_callback_t position_released; + behavior_keymap_binding_callback_t binding_pressed; + behavior_keymap_binding_callback_t binding_released; behavior_keycode_callback_t keycode_pressed; behavior_keycode_callback_t keycode_released; + behavior_modifiers_callback_t modifiers_pressed; + behavior_modifiers_callback_t modifiers_released; }; /** * @endcond */ /** - * @brief Handle the assigned position being pressed + * @brief Handle the key position being pressed * @param dev Pointer to the device structure for the driver instance. - * @param param1 User parameter specified at time of behavior assignment. + * @param position They key position that was pressed * * @retval 0 If successful. * @retval Negative errno code if failure. */ -__syscall int behavior_position_pressed(struct device *dev, u32_t param1, u32_t param2); +__syscall int behavior_position_pressed(struct device *dev, u32_t position); -static inline int z_impl_behavior_position_pressed(struct device *dev, u32_t param1, u32_t param2) +static inline int z_impl_behavior_position_pressed(struct device *dev, u32_t position) { const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api; @@ -54,7 +61,52 @@ static inline int z_impl_behavior_position_pressed(struct device *dev, u32_t par return -ENOTSUP; } - return api->position_pressed(dev, param1, param2); + return api->position_pressed(dev, position); +} + +/** + * @brief Handle the key position being released + * @param dev Pointer to the device structure for the driver instance. + * @param position They key position that was released + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_position_released(struct device *dev, u32_t position); + +static inline int z_impl_behavior_position_released(struct device *dev, u32_t position) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->position_released == NULL) { + return -ENOTSUP; + } + + return api->position_released(dev, position); +} + +/** + * @brief Handle the keymap binding being pressed + * @param dev Pointer to the device structure for the driver instance. + * @param param1 User parameter specified at time of behavior binding. + * @param param2 User parameter specified at time of behavior binding. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_keymap_binding_pressed(struct device *dev, u32_t position, u32_t param1, u32_t param2); + +static inline int z_impl_behavior_keymap_binding_pressed(struct device *dev, u32_t position, u32_t param1, u32_t param2) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->binding_pressed == NULL) { + return -ENOTSUP; + } + + return api->binding_pressed(dev, position, param1, param2); } /** @@ -65,20 +117,21 @@ static inline int z_impl_behavior_position_pressed(struct device *dev, u32_t par * @retval 0 If successful. * @retval Negative errno code if failure. */ -__syscall int behavior_position_released(struct device *dev, u32_t param1, u32_t param2); +__syscall int behavior_keymap_binding_released(struct device *dev, u32_t position, u32_t param1, u32_t param2); -static inline int z_impl_behavior_position_released(struct device *dev, u32_t param1, u32_t param2) +static inline int z_impl_behavior_keymap_binding_released(struct device *dev, u32_t position, u32_t param1, u32_t param2) { const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api; - if (api->position_released == NULL) { + if (api->binding_released == NULL) { return -ENOTSUP; } - return api->position_released(dev, param1, param2); + return api->binding_released(dev, position, param1, param2); } + /** * @brief Handle the keycode being pressed * @param dev Pointer to the device structure for the driver instance. @@ -124,6 +177,52 @@ static inline int z_impl_behavior_keycode_released(struct device *dev, u32_t key return api->keycode_released(dev, keycode); } + +/** + * @brief Handle the keycode being pressed + * @param dev Pointer to the device structure for the driver instance. + * @param keycode The keycode that is being pressed. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_modifiers_pressed(struct device *dev, zmk_mod_flags modifiers); + +static inline int z_impl_behavior_modifiers_pressed(struct device *dev, zmk_mod_flags modifiers) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->modifiers_pressed == NULL) { + return -ENOTSUP; + } + + return api->modifiers_pressed(dev, modifiers); +} + + +/** + * @brief Handle the keycode being released + * @param dev Pointer to the device structure for the driver instance. + * @param keycode The keycode that is being pressed. + * + * @retval 0 If successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_modifiers_released(struct device *dev, zmk_mod_flags modifiers); + +static inline int z_impl_behavior_modifiers_released(struct device *dev, zmk_mod_flags modifiers) +{ + const struct behavior_driver_api *api = + (const struct behavior_driver_api *)dev->driver_api; + + if (api->modifiers_released == NULL) { + return -ENOTSUP; + } + + return api->modifiers_released(dev, modifiers); +} + #ifdef __cplusplus } #endif -- cgit v1.2.3 From 55cf9db564e66e2804f2d3f2201c55c3c86a90d7 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 22 Jun 2020 11:06:01 -0400 Subject: Fix consumer keys w/ refactored behaviors. --- app/include/drivers/behavior.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'app/include/drivers/behavior.h') diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h index b3c6ad2..cca9272 100644 --- a/app/include/drivers/behavior.h +++ b/app/include/drivers/behavior.h @@ -25,7 +25,7 @@ extern "C" { typedef int (*behavior_position_callback_t)(struct device *dev, u32_t position); typedef int (*behavior_keymap_binding_callback_t)(struct device *dev, u32_t position, u32_t param1, u32_t param2); -typedef int (*behavior_keycode_callback_t)(struct device *dev, u32_t keycode); +typedef int (*behavior_keycode_callback_t)(struct device *dev, u8_t usage_page, u32_t keycode); typedef int (*behavior_modifiers_callback_t)(struct device *dev, zmk_mod_flags modifiers); __subsystem struct behavior_driver_api { @@ -135,14 +135,15 @@ static inline int z_impl_behavior_keymap_binding_released(struct device *dev, u3 /** * @brief Handle the keycode being pressed * @param dev Pointer to the device structure for the driver instance. + * @param usage_page The usage page for the keycode. * @param keycode The keycode that is being pressed. * * @retval 0 If successful. * @retval Negative errno code if failure. */ -__syscall int behavior_keycode_pressed(struct device *dev, u32_t keycode); +__syscall int behavior_keycode_pressed(struct device *dev, u8_t usage_page, u32_t keycode); -static inline int z_impl_behavior_keycode_pressed(struct device *dev, u32_t keycode) +static inline int z_impl_behavior_keycode_pressed(struct device *dev, u8_t usage_page, u32_t keycode) { const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api; @@ -151,21 +152,22 @@ static inline int z_impl_behavior_keycode_pressed(struct device *dev, u32_t keyc return -ENOTSUP; } - return api->keycode_pressed(dev, keycode); + return api->keycode_pressed(dev, usage_page, keycode); } /** * @brief Handle the keycode being released * @param dev Pointer to the device structure for the driver instance. + * @param usage_page The usage page for the keycode. * @param keycode The keycode that is being pressed. * * @retval 0 If successful. * @retval Negative errno code if failure. */ -__syscall int behavior_keycode_released(struct device *dev, u32_t keycode); +__syscall int behavior_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode); -static inline int z_impl_behavior_keycode_released(struct device *dev, u32_t keycode) +static inline int z_impl_behavior_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode) { const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api; @@ -174,7 +176,7 @@ static inline int z_impl_behavior_keycode_released(struct device *dev, u32_t key return -ENOTSUP; } - return api->keycode_released(dev, keycode); + return api->keycode_released(dev, usage_page, keycode); } -- cgit v1.2.3