forked from kofal.net/zmk
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user