diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-06-21 21:43:44 -0400 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2020-06-21 21:43:44 -0400 |
commit | 223edf05ad08938b066f9187668ebfae43c5e91a (patch) | |
tree | e2719b609c701a72b9185b371d3824edf3af8620 /app/include | |
parent | 7e659851c80bf2819554d93ad9971f56aa5b225b (diff) |
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.
Diffstat (limited to 'app/include')
-rw-r--r-- | app/include/drivers/behavior.h | 119 | ||||
-rw-r--r-- | app/include/zmk/events.h | 6 | ||||
-rw-r--r-- | app/include/zmk/keymap.h | 8 | ||||
-rw-r--r-- | app/include/zmk/matrix.h | 2 |
4 files changed, 115 insertions, 20 deletions
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 <zephyr/types.h> #include <stddef.h> #include <device.h> +#include <zmk/keys.h> #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 diff --git a/app/include/zmk/events.h b/app/include/zmk/events.h index ac4815a..8d1ae6a 100644 --- a/app/include/zmk/events.h +++ b/app/include/zmk/events.h @@ -1,11 +1,13 @@ #pragma once +#include <zmk/keys.h> + int zmk_events_position_pressed(u32_t position); int zmk_events_position_released(u32_t position); int zmk_events_keycode_pressed(u32_t keycode); int zmk_events_keycode_released(u32_t keycode); -int zmk_events_mod_pressed(u32_t modifier); -int zmk_events_mod_released(u32_t modifier); +int zmk_events_modifiers_pressed(zmk_mod_flags modifiers); +int zmk_events_modifiers_released(zmk_mod_flags modifiers); int zmk_events_consumer_key_pressed(u32_t usage); int zmk_events_consumer_key_released(u32_t usage); diff --git a/app/include/zmk/keymap.h b/app/include/zmk/keymap.h index cf38904..38c1249 100644 --- a/app/include/zmk/keymap.h +++ b/app/include/zmk/keymap.h @@ -1,13 +1,5 @@ #pragma once -#include <devicetree.h> -#include <usb/usb_device.h> -#include <usb/class/usb_hid.h> -#include <dt-bindings/zmk/keys.h> - -#include <zmk/matrix.h> -// #include <zmk/keys.h> - bool zmk_keymap_layer_activate(u8_t layer); bool zmk_keymap_layer_deactivate(u8_t layer); diff --git a/app/include/zmk/matrix.h b/app/include/zmk/matrix.h index 783c98e..9cabb7e 100644 --- a/app/include/zmk/matrix.h +++ b/app/include/zmk/matrix.h @@ -1,5 +1,7 @@ #pragma once +#include <devicetree.h> + #define ZMK_MATRIX_NODE_ID DT_CHOSEN(zmk_kscan) #if DT_NODE_HAS_PROP(ZMK_MATRIX_NODE_ID,row_gpios) |