summaryrefslogtreecommitdiff
path: root/app/include/drivers
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-06-21 21:43:44 -0400
committerPete Johanson <peter@peterjohanson.com>2020-06-21 21:43:44 -0400
commit223edf05ad08938b066f9187668ebfae43c5e91a (patch)
treee2719b609c701a72b9185b371d3824edf3af8620 /app/include/drivers
parent7e659851c80bf2819554d93ad9971f56aa5b225b (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/drivers')
-rw-r--r--app/include/drivers/behavior.h119
1 files changed, 109 insertions, 10 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