Pete Johanson
4 years ago
committed by
GitHub
58 changed files with 1369 additions and 627 deletions
@ -0,0 +1,34 @@ |
|||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <dt-bindings/zmk/matrix-transform.h> |
||||||
|
|
||||||
|
/ { |
||||||
|
chosen { |
||||||
|
zmk,keymap = &keymap0; |
||||||
|
}; |
||||||
|
|
||||||
|
keymap0: keymap { |
||||||
|
compatible = "zmk,keymap"; |
||||||
|
label ="Default Kyria Keymap"; |
||||||
|
layers = <&default>; |
||||||
|
}; |
||||||
|
|
||||||
|
layers { |
||||||
|
compatible = "zmk,layers"; |
||||||
|
|
||||||
|
default: layer_0 { |
||||||
|
label = "DEFAULT"; |
||||||
|
// --------------------------------------------------------------------------------------------------------------------------------- |
||||||
|
// | ESC | Q | W | E | R | T | | Y | U | I | O | P | "|" | |
||||||
|
// | <- | A | S | D | F | G | | H | J | K | L | ; | ' | |
||||||
|
// | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | - | |
||||||
|
// | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT | |
||||||
|
bindings = < |
||||||
|
&kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp PIPE |
||||||
|
&kp BKSP &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp QUOT |
||||||
|
&kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp LSFT &kp LSFT &kp LSFT &kp LSFT &kp N &kp M &kp CMMA &kp DOT &kp BSLH &kp MINUS |
||||||
|
&kp LGUI &kp DEL &kp RET &kp SPC &kp ESC &kp RET &kp SPC &kp TAB &kp BKSP &kp RALT |
||||||
|
>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -1,5 +0,0 @@ |
|||||||
|
|
||||||
#include <dt-bindings/zmk/keys.h> |
|
||||||
|
|
||||||
#define CC_RAIS ZC_CSTM(1) |
|
||||||
#define CC_LOWR ZC_CSTM(2) |
|
@ -1,34 +0,0 @@ |
|||||||
|
|
||||||
#include <zmk/keys.h> |
|
||||||
#include <zmk/keymap.h> |
|
||||||
#include <keymap.h> |
|
||||||
|
|
||||||
bool zmk_handle_key_user(struct zmk_key_event *key_event) |
|
||||||
{ |
|
||||||
switch (key_event->key) |
|
||||||
{ |
|
||||||
case CC_LOWR: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
zmk_keymap_layer_activate(1); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_keymap_layer_deactivate(1); |
|
||||||
} |
|
||||||
|
|
||||||
return false; |
|
||||||
case CC_RAIS: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
zmk_keymap_layer_activate(2); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_keymap_layer_deactivate(2); |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
return true; |
|
||||||
}; |
|
@ -1,63 +0,0 @@ |
|||||||
#include <dt-bindings/zmk/keys.h> |
|
||||||
#include <dt-bindings/zmk/matrix-transform.h> |
|
||||||
#include <keymap.h> |
|
||||||
|
|
||||||
/ { |
|
||||||
chosen { |
|
||||||
zmk,keymap = &keymap0; |
|
||||||
}; |
|
||||||
|
|
||||||
keymap0: keymap { |
|
||||||
compatible = "zmk,keymap"; |
|
||||||
label ="Default Kyria Keymap"; |
|
||||||
layers = <&default>; |
|
||||||
transform = <&default_transform>; |
|
||||||
}; |
|
||||||
|
|
||||||
default_transform: keymap_transform_0 { |
|
||||||
compatible = "zmk,matrix-transform"; |
|
||||||
// | MX6 | MX5 | MX4 | MX3 | MX2 | MX1 | | MX1 | MX2 | MX3 | MX4 | MX5 | MX6 | |
|
||||||
// | MX12 | MX11 | MX10 | MX9 | MX8 | MX7 | | MX7 | MX8 | MX9 | MX10 | MX11 | MX12 | |
|
||||||
// | MX20 | MX19 | MX18 | MX17 | MX16 | MX15 | MX14 | MX13 | | MX13 | MX14 | MX15 | MX16 | MX17 | MX18 | MX19 | MX20 | |
|
||||||
// | MX25 | MX24 | MX23 | MX22 | MX21 | | MX21 | MX22 | MX23 | MX24 | MX25 | |
|
||||||
map = < |
|
||||||
RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,10) RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,15) |
|
||||||
RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,10) RC(1,11) RC(1,12) RC(1,13) RC(1,14) RC(1,15) |
|
||||||
RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,12) RC(2,13) RC(2,14) RC(2,15) |
|
||||||
RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) |
|
||||||
>; |
|
||||||
}; |
|
||||||
|
|
||||||
// | MX5 | MX4 | MX3 | MX2 | MX1 | | MX1 | MX2 | MX3 | MX4 | MX5 | |
|
||||||
// | MX11 | MX10 | MX9 | MX8 | MX7 | | MX7 | MX8 | MX9 | MX10 | MX11 | |
|
||||||
// | MX19 | MX18 | MX17 | MX16 | MX15 | MX14 | MX13 | | MX13 | MX14 | MX15 | MX16 | MX17 | MX18 | MX19 | |
|
||||||
// | MX25 | MX24 | MX23 | MX22 | MX21 | | MX21 | MX22 | MX23 | MX24 | MX25 | |
|
||||||
five_column_transform: keymap_transform_1 { |
|
||||||
compatible = "zmk,matrix-transform"; |
|
||||||
map = < |
|
||||||
RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) |
|
||||||
RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) |
|
||||||
RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,12) RC(2,13) |
|
||||||
RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) |
|
||||||
>; |
|
||||||
}; |
|
||||||
|
|
||||||
layers { |
|
||||||
compatible = "zmk,layers"; |
|
||||||
|
|
||||||
default: layer_0 { |
|
||||||
label = "DEFAULT"; |
|
||||||
// --------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
// | ESC | Q | W | E | R | T | | Y | U | I | O | P | "|" | |
|
||||||
// | <- | A | S | D | F | G | | H | J | K | L | ; | ' | |
|
||||||
// | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | - | |
|
||||||
// | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT | |
|
||||||
keys = < |
|
||||||
KC_ESC KC_Q KC_W KC_E KC_R KC_T KC_Y KC_U KC_I KC_O KC_P KC_PIPE |
|
||||||
KC_BKSP KC_A KC_S KC_D KC_F KC_G KC_H KC_J KC_K KC_L KC_SCLN KC_QUOT |
|
||||||
KC_LSFT KC_Z KC_X KC_C KC_V KC_B KC_LSFT KC_LSFT KC_LSFT KC_LSFT KC_N KC_M KC_CMMA KC_DOT KC_BSLH KC_MIN |
|
||||||
KC_LGUI KC_DEL KC_RET KC_SPC KC_ESC KC_RET KC_SPC KC_TAB KC_BKSP KC_RALT |
|
||||||
>; |
|
||||||
}; |
|
||||||
}; |
|
||||||
}; |
|
@ -1,5 +0,0 @@ |
|||||||
|
|
||||||
#include <dt-bindings/zmk/keys.h> |
|
||||||
|
|
||||||
#define CC_RAIS ZC_CSTM(1) |
|
||||||
#define CC_LOWR ZC_CSTM(2) |
|
@ -1,34 +0,0 @@ |
|||||||
|
|
||||||
#include <zmk/keys.h> |
|
||||||
#include <zmk/keymap.h> |
|
||||||
#include <keymap.h> |
|
||||||
|
|
||||||
bool zmk_handle_key_user(struct zmk_key_event *key_event) |
|
||||||
{ |
|
||||||
switch (key_event->key) |
|
||||||
{ |
|
||||||
case CC_LOWR: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
zmk_keymap_layer_activate(1); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_keymap_layer_deactivate(1); |
|
||||||
} |
|
||||||
|
|
||||||
return false; |
|
||||||
case CC_RAIS: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
zmk_keymap_layer_activate(2); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_keymap_layer_deactivate(2); |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
return true; |
|
||||||
}; |
|
@ -1,9 +0,0 @@ |
|||||||
|
|
||||||
#include <dt-bindings/zmk/keys.h> |
|
||||||
|
|
||||||
#define DEFAULT 0 |
|
||||||
#define RAISE 1 |
|
||||||
#define LOWER 2 |
|
||||||
|
|
||||||
#define CC_RAIS ZC_CSTM(RAISE) |
|
||||||
#define CC_LOWR ZC_CSTM(LOWER) |
|
@ -1,34 +0,0 @@ |
|||||||
|
|
||||||
#include <zmk/keys.h> |
|
||||||
#include <zmk/keymap.h> |
|
||||||
#include <keymap.h> |
|
||||||
|
|
||||||
bool zmk_handle_key_user(struct zmk_key_event *key_event) |
|
||||||
{ |
|
||||||
switch (key_event->key) |
|
||||||
{ |
|
||||||
case CC_LOWR: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
zmk_keymap_layer_activate(LOWER); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_keymap_layer_deactivate(LOWER); |
|
||||||
} |
|
||||||
|
|
||||||
return false; |
|
||||||
case CC_RAIS: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
zmk_keymap_layer_activate(RAISE); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_keymap_layer_deactivate(RAISE); |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
return true; |
|
||||||
}; |
|
@ -0,0 +1,7 @@ |
|||||||
|
#include <behaviors/key_press.dtsi> |
||||||
|
#include <behaviors/transparent.dtsi> |
||||||
|
#include <behaviors/mod_tap.dtsi> |
||||||
|
#include <behaviors/momentary_layer.dtsi> |
||||||
|
#include <behaviors/reset.dtsi> |
||||||
|
#include <behaviors/keymap.dtsi> |
||||||
|
#include <behaviors/hid.dtsi> |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
hid_behavior: behavior_hid { |
||||||
|
compatible = "zmk,behavior-hid", "zmk,behavior-global"; |
||||||
|
label = "HID"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,19 @@ |
|||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
|
||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
kp: behavior_key_press { |
||||||
|
compatible = "zmk,behavior-key-press"; |
||||||
|
label = "KEY_PRESS"; |
||||||
|
usage_page = <USAGE_KEYPAD>; |
||||||
|
#binding-cells = <1>; |
||||||
|
}; |
||||||
|
|
||||||
|
cp: behavior_consumer_press { |
||||||
|
compatible = "zmk,behavior-key-press"; |
||||||
|
label = "CONSUMER_PRESS"; |
||||||
|
usage_page = <USAGE_CONSUMER>; |
||||||
|
#binding-cells = <1>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
keymap_behavior: behavior_keymap { |
||||||
|
compatible = "zmk,behavior-keymap", "zmk,behavior-global"; |
||||||
|
label = "KEYMAP"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
mt: behavior_mod_tap { |
||||||
|
compatible = "zmk,behavior-mod-tap", "zmk,behavior-global"; |
||||||
|
label = "MOD_TAP"; |
||||||
|
#binding-cells = <2>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
mo: behavior_momentary_layer { |
||||||
|
compatible = "zmk,behavior-momentary-layer"; |
||||||
|
label = "MO"; |
||||||
|
#binding-cells = <1>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
reset: behavior_reset { |
||||||
|
compatible = "zmk,behavior-reset"; |
||||||
|
label = "RESET"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
trans: behavior_transparent { |
||||||
|
compatible = "zmk,behavior-transparent"; |
||||||
|
label = "TRANS"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,14 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
properties: |
||||||
|
label: |
||||||
|
type: string |
||||||
|
required: true |
||||||
|
"#binding-cells": |
||||||
|
type: int |
||||||
|
required: true |
||||||
|
const: 1 |
||||||
|
|
||||||
|
binding-cells: |
||||||
|
- param1 |
@ -0,0 +1,15 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
properties: |
||||||
|
label: |
||||||
|
type: string |
||||||
|
required: true |
||||||
|
"#binding-cells": |
||||||
|
type: int |
||||||
|
required: true |
||||||
|
const: 2 |
||||||
|
|
||||||
|
binding-cells: |
||||||
|
- param1 |
||||||
|
- param2 |
@ -0,0 +1,11 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
properties: |
||||||
|
label: |
||||||
|
type: string |
||||||
|
required: true |
||||||
|
"#binding-cells": |
||||||
|
type: int |
||||||
|
required: true |
||||||
|
const: 0 |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: HID Report Behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-hid" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,13 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Key press/release behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-key-press" |
||||||
|
|
||||||
|
include: one_param.yaml |
||||||
|
|
||||||
|
properties: |
||||||
|
usage_page: |
||||||
|
type: int |
||||||
|
default: 0 |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Keymap Behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-keymap" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Mod-Tap Beavhior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-mod-tap" |
||||||
|
|
||||||
|
include: two_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Momentary layer on press/release behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-momentary-layer" |
||||||
|
|
||||||
|
include: one_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Keyboard Reset Behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-reset" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Transparent Binding Behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-transparent" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,236 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <zephyr/types.h> |
||||||
|
#include <stddef.h> |
||||||
|
#include <device.h> |
||||||
|
#include <zmk/keys.h> |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond INTERNAL_HIDDEN |
||||||
|
* |
||||||
|
* Behavior driver API definition and system call entry points. |
||||||
|
* |
||||||
|
* (Internal use only.) |
||||||
|
*/ |
||||||
|
|
||||||
|
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, 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 { |
||||||
|
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 key position being pressed |
||||||
|
* @param dev Pointer to the device structure for the driver instance. |
||||||
|
* @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 position); |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
if (api->position_pressed == NULL) { |
||||||
|
return -ENOTSUP; |
||||||
|
} |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* @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_keymap_binding_released(struct device *dev, u32_t position, 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->binding_released == NULL) { |
||||||
|
return -ENOTSUP; |
||||||
|
} |
||||||
|
|
||||||
|
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. |
||||||
|
* @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, u8_t usage_page, 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; |
||||||
|
|
||||||
|
if (api->keycode_pressed == NULL) { |
||||||
|
return -ENOTSUP; |
||||||
|
} |
||||||
|
|
||||||
|
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, u8_t usage_page, 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; |
||||||
|
|
||||||
|
if (api->keycode_released == NULL) { |
||||||
|
return -ENOTSUP; |
||||||
|
} |
||||||
|
|
||||||
|
return api->keycode_released(dev, usage_page, 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 |
||||||
|
|
||||||
|
/**
|
||||||
|
* @} |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <syscalls/behavior.h> |
@ -0,0 +1,8 @@ |
|||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
struct zmk_behavior_binding { |
||||||
|
char *behavior_dev; |
||||||
|
u32_t param1; |
||||||
|
u32_t param2; |
||||||
|
}; |
@ -0,0 +1,15 @@ |
|||||||
|
#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(u8_t usage_page, u32_t keycode); |
||||||
|
int zmk_events_keycode_released(u8_t usage_page, u32_t keycode); |
||||||
|
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); |
||||||
|
|
||||||
|
// TODO: Encoders?
|
||||||
|
// TODO: Sensors?
|
@ -1,28 +1,6 @@ |
|||||||
#pragma once |
#pragma once |
||||||
|
|
||||||
#include <devicetree.h> |
int zmk_keymap_layer_activate(u8_t layer); |
||||||
#include <usb/usb_device.h> |
int zmk_keymap_layer_deactivate(u8_t layer); |
||||||
#include <usb/class/usb_hid.h> |
|
||||||
#include <dt-bindings/zmk/keys.h> |
|
||||||
|
|
||||||
#include <zmk/matrix.h> |
int zmk_keymap_position_state_changed(u32_t position, bool pressed); |
||||||
#include <zmk/keys.h> |
|
||||||
|
|
||||||
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) |
|
||||||
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers) |
|
||||||
|
|
||||||
/* TODO: Need to actually be able to get a NODELABEL from a node id
|
|
||||||
#define _ZMK_KEYMAP_GENERATE_LAYER_CONST(node_id) \ |
|
||||||
DT_NODELABEL_FOR_NODE(node_id)_layer, |
|
||||||
|
|
||||||
enum zmk_keymap_layer |
|
||||||
{ |
|
||||||
DT_FOREACH_CHILD(DT_INST(0, zmk_layers), _ZMK_KEYMAP_GENERATE_LAYER_CONST) |
|
||||||
}; |
|
||||||
*/ |
|
||||||
|
|
||||||
bool zmk_keymap_layer_activate(u8_t layer); |
|
||||||
bool zmk_keymap_layer_deactivate(u8_t layer); |
|
||||||
|
|
||||||
zmk_key |
|
||||||
zmk_keymap_keycode_from_position(u32_t row, u32_t column); |
|
||||||
|
@ -0,0 +1,3 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
u32_t zmk_matrix_transform_row_column_to_position(u32_t row, u32_t column); |
@ -1,3 +1,4 @@ |
|||||||
# CONFIG_LOG=y |
# CONFIG_LOG=y |
||||||
# CONFIG_ZMK_LOG_LEVEL_DBG=y |
# CONFIG_ZMK_LOG_LEVEL_DBG=y |
||||||
CONFIG_KERNEL_BIN_NAME="zmk" |
CONFIG_KERNEL_BIN_NAME="zmk" |
||||||
|
CONFIG_REBOOT=y |
@ -0,0 +1,108 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_hid |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <power/reboot.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#include <zmk/hid.h> |
||||||
|
#include <zmk/endpoints.h> |
||||||
|
|
||||||
|
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, u8_t usage_page, u32_t keycode) |
||||||
|
{ |
||||||
|
int err; |
||||||
|
LOG_DBG("keycode %d", keycode); |
||||||
|
|
||||||
|
switch (usage_page) { |
||||||
|
case USAGE_KEYPAD: |
||||||
|
err = zmk_hid_keypad_press(keycode); |
||||||
|
if (err) { |
||||||
|
LOG_ERR("Unable to press keycode"); |
||||||
|
return err; |
||||||
|
} |
||||||
|
break; |
||||||
|
case USAGE_CONSUMER: |
||||||
|
err = zmk_hid_consumer_press(keycode); |
||||||
|
if (err) { |
||||||
|
LOG_ERR("Unable to press keycode"); |
||||||
|
return err; |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
return zmk_endpoints_send_report(usage_page); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode) |
||||||
|
{ |
||||||
|
int err; |
||||||
|
LOG_DBG("keycode %d", keycode); |
||||||
|
|
||||||
|
switch (usage_page) { |
||||||
|
case USAGE_KEYPAD: |
||||||
|
err = zmk_hid_keypad_release(keycode); |
||||||
|
if (err) { |
||||||
|
LOG_ERR("Unable to press keycode"); |
||||||
|
return err; |
||||||
|
} |
||||||
|
break; |
||||||
|
case USAGE_CONSUMER: |
||||||
|
err = zmk_hid_consumer_release(keycode); |
||||||
|
if (err) { |
||||||
|
LOG_ERR("Unable to press keycode"); |
||||||
|
return err; |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
return zmk_endpoints_send_report(usage_page); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_modifiers_pressed(struct device *dev, zmk_mod_flags modifiers) |
||||||
|
{ |
||||||
|
LOG_DBG("modifiers %d", modifiers); |
||||||
|
|
||||||
|
zmk_hid_register_mods(modifiers); |
||||||
|
return zmk_endpoints_send_report(USAGE_KEYPAD); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_modifiers_released(struct device *dev, zmk_mod_flags modifiers) |
||||||
|
{ |
||||||
|
LOG_DBG("modifiers %d", modifiers); |
||||||
|
|
||||||
|
zmk_hid_unregister_mods(modifiers); |
||||||
|
return zmk_endpoints_send_report(USAGE_KEYPAD); |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_hid_driver_api = { |
||||||
|
.keycode_pressed = on_keycode_pressed, |
||||||
|
.keycode_released = on_keycode_released, |
||||||
|
.modifiers_pressed = on_modifiers_pressed, |
||||||
|
.modifiers_released = on_modifiers_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); |
@ -0,0 +1,57 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_key_press |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
#include <zmk/events.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
struct behavior_key_press_config { |
||||||
|
u8_t usage_page; |
||||||
|
}; |
||||||
|
struct behavior_key_press_data { }; |
||||||
|
|
||||||
|
static int behavior_key_press_init(struct device *dev) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t keycode, u32_t _) |
||||||
|
{ |
||||||
|
const struct behavior_key_press_config *cfg = dev->config_info; |
||||||
|
LOG_DBG("position %d usage_page 0x%02X keycode 0x%02X", position, cfg->usage_page, keycode); |
||||||
|
return zmk_events_keycode_pressed(cfg->usage_page, keycode); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t keycode, u32_t _) |
||||||
|
{ |
||||||
|
const struct behavior_key_press_config *cfg = dev->config_info; |
||||||
|
LOG_DBG("position %d usage_page 0x%02X keycode 0x%02X", position, cfg->usage_page, keycode); |
||||||
|
return zmk_events_keycode_released(cfg->usage_page, keycode); |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_key_press_driver_api = { |
||||||
|
.binding_pressed = on_keymap_binding_pressed, |
||||||
|
.binding_released = on_keymap_binding_released |
||||||
|
}; |
||||||
|
|
||||||
|
#define KP_INST(n) \ |
||||||
|
static const struct behavior_key_press_config behavior_key_press_config_##n = { \
|
||||||
|
.usage_page = DT_INST_PROP(n, usage_page) \
|
||||||
|
}; \
|
||||||
|
static struct behavior_key_press_data behavior_key_press_data_##n; \
|
||||||
|
DEVICE_AND_API_INIT(behavior_key_press_##n, DT_INST_LABEL(n), behavior_key_press_init, \
|
||||||
|
&behavior_key_press_data_##n, \
|
||||||
|
&behavior_key_press_config_##n, \
|
||||||
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
||||||
|
&behavior_key_press_driver_api); |
||||||
|
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY(KP_INST) |
@ -0,0 +1,50 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_keymap |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <power/reboot.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#include <zmk/keymap.h> |
||||||
|
|
||||||
|
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 position) |
||||||
|
{ |
||||||
|
return zmk_keymap_position_state_changed(position, true); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_position_released(struct device *dev, u32_t position) |
||||||
|
{ |
||||||
|
return zmk_keymap_position_state_changed(position, 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); |
@ -0,0 +1,88 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_mod_tap |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
#include <zmk/events.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
struct behavior_mod_tap_config { }; |
||||||
|
struct behavior_mod_tap_data { |
||||||
|
u16_t pending_press_positions; |
||||||
|
}; |
||||||
|
|
||||||
|
static int behavior_mod_tap_init(struct device *dev) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t mods, u32_t keycode) |
||||||
|
{ |
||||||
|
struct behavior_mod_tap_data *data = dev->driver_data; |
||||||
|
LOG_DBG("mods: %d, keycode: %d", mods, keycode); |
||||||
|
WRITE_BIT(data->pending_press_positions, position, true); |
||||||
|
return zmk_events_modifiers_pressed(mods); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// They keycode is passed by the "keymap" based on the parameter created as part of the assignment.
|
||||||
|
static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t mods, u32_t keycode) |
||||||
|
{ |
||||||
|
struct behavior_mod_tap_data *data = dev->driver_data; |
||||||
|
LOG_DBG("mods: %d, keycode: %d", mods, keycode); |
||||||
|
|
||||||
|
zmk_events_modifiers_released(mods); |
||||||
|
if (data->pending_press_positions & BIT(position)) { |
||||||
|
zmk_events_keycode_pressed(USAGE_KEYPAD, keycode); |
||||||
|
k_msleep(10); |
||||||
|
zmk_events_keycode_released(USAGE_KEYPAD, keycode); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
static int on_keycode_pressed(struct device *dev, u8_t usage_page, u32_t keycode) |
||||||
|
{ |
||||||
|
struct behavior_mod_tap_data *data = dev->driver_data; |
||||||
|
data->pending_press_positions = 0; |
||||||
|
LOG_DBG("pressing: %d", keycode); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
static int on_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode) |
||||||
|
{ |
||||||
|
LOG_DBG("releasing: %d", keycode); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_mod_tap_driver_api = { |
||||||
|
// These callbacks are all optional, and define which kinds of events the behavior can handle.
|
||||||
|
// They can reference local functions defined here, or shared event handlers.
|
||||||
|
.binding_pressed = on_keymap_binding_pressed, |
||||||
|
.binding_released = on_keymap_binding_released, |
||||||
|
.keycode_pressed = on_keycode_pressed, |
||||||
|
.keycode_released = on_keycode_released |
||||||
|
// Other optional callbacks a behavior can implement
|
||||||
|
// .on_mouse_moved
|
||||||
|
// .on_sensor_data - Any behaviour that wants to be linked to a censor can implement this behavior
|
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
static const struct behavior_mod_tap_config behavior_mod_tap_config = {}; |
||||||
|
|
||||||
|
static struct behavior_mod_tap_data behavior_mod_tap_data; |
||||||
|
|
||||||
|
DEVICE_AND_API_INIT(behavior_key_press, DT_INST_LABEL(0), behavior_mod_tap_init, |
||||||
|
&behavior_mod_tap_data, |
||||||
|
&behavior_mod_tap_config, |
||||||
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, |
||||||
|
&behavior_mod_tap_driver_api); |
@ -0,0 +1,55 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_momentary_layer |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
#include <zmk/events.h> |
||||||
|
#include <zmk/keymap.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
struct behavior_mo_config { }; |
||||||
|
struct behavior_mo_data { }; |
||||||
|
|
||||||
|
static int behavior_mo_init(struct device *dev) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
static int mo_keymap_binding_pressed(struct device *dev, u32_t position, u32_t layer, u32_t _) |
||||||
|
{ |
||||||
|
LOG_DBG("position %d layer %d", position, layer); |
||||||
|
|
||||||
|
return zmk_keymap_layer_activate(layer); |
||||||
|
} |
||||||
|
|
||||||
|
static int mo_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _) |
||||||
|
{ |
||||||
|
LOG_DBG("position %d layer %d", position, layer); |
||||||
|
|
||||||
|
return zmk_keymap_layer_deactivate(layer); |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_mo_driver_api = { |
||||||
|
.binding_pressed = mo_keymap_binding_pressed, |
||||||
|
.binding_released = mo_keymap_binding_released |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
static const struct behavior_mo_config behavior_mo_config = {}; |
||||||
|
|
||||||
|
static struct behavior_mo_data behavior_mo_data; |
||||||
|
|
||||||
|
DEVICE_AND_API_INIT(behavior_mo, DT_INST_LABEL(0), behavior_mo_init, |
||||||
|
&behavior_mo_data, |
||||||
|
&behavior_mo_config, |
||||||
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, |
||||||
|
&behavior_mo_driver_api); |
@ -0,0 +1,45 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_reset |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <power/reboot.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
struct behavior_reset_config { }; |
||||||
|
struct behavior_reset_data { }; |
||||||
|
|
||||||
|
static int behavior_reset_init(struct device *dev) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t _param1, u32_t _param2) |
||||||
|
{ |
||||||
|
// TODO: Correct magic code for going into DFU?
|
||||||
|
// See https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107
|
||||||
|
sys_reboot(0); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_reset_driver_api = { |
||||||
|
.binding_pressed = on_keymap_binding_pressed, |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
static const struct behavior_reset_config behavior_reset_config = {}; |
||||||
|
|
||||||
|
static struct behavior_reset_data behavior_reset_data; |
||||||
|
|
||||||
|
DEVICE_AND_API_INIT(behavior_reset, DT_INST_LABEL(0), behavior_reset_init, |
||||||
|
&behavior_reset_data, |
||||||
|
&behavior_reset_config, |
||||||
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, |
||||||
|
&behavior_reset_driver_api); |
@ -0,0 +1,48 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_transparent |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <power/reboot.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
struct behavior_transparent_config { }; |
||||||
|
struct behavior_transparent_data { }; |
||||||
|
|
||||||
|
static int behavior_transparent_init(struct device *dev) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t _param1, u32_t _param2) |
||||||
|
{ |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t _param1, u32_t _param2) |
||||||
|
{ |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_transparent_driver_api = { |
||||||
|
.binding_pressed = on_keymap_binding_pressed, |
||||||
|
.binding_released = on_keymap_binding_released, |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
static const struct behavior_transparent_config behavior_transparent_config = {}; |
||||||
|
|
||||||
|
static struct behavior_transparent_data behavior_transparent_data; |
||||||
|
|
||||||
|
DEVICE_AND_API_INIT(behavior_transparent, DT_INST_LABEL(0), behavior_transparent_init, |
||||||
|
&behavior_transparent_data, |
||||||
|
&behavior_transparent_config, |
||||||
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, |
||||||
|
&behavior_transparent_driver_api); |
@ -0,0 +1,83 @@ |
|||||||
|
|
||||||
|
#include <zephyr.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <zmk/behavior.h> |
||||||
|
#include <zmk/events.h> |
||||||
|
#include <sys/util.h> |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_global |
||||||
|
#define GLOBAL_BEHAVIOR_LEN DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) |
||||||
|
|
||||||
|
#define LABEL_ENTRY(i) DT_INST_LABEL(i), |
||||||
|
static const char *global_behaviors[] = { |
||||||
|
DT_INST_FOREACH_STATUS_OKAY(LABEL_ENTRY) |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_position_pressed(u32_t position) |
||||||
|
{ |
||||||
|
for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { |
||||||
|
const char* label = global_behaviors[i]; |
||||||
|
struct device *dev = device_get_binding(label); |
||||||
|
behavior_position_pressed(dev, position); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_position_released(u32_t position) |
||||||
|
{ |
||||||
|
for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { |
||||||
|
const char* label = global_behaviors[i]; |
||||||
|
struct device *dev = device_get_binding(label); |
||||||
|
behavior_position_released(dev, position); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_keycode_pressed(u8_t usage_page, u32_t keycode) |
||||||
|
{ |
||||||
|
for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { |
||||||
|
const char* label = global_behaviors[i]; |
||||||
|
struct device *dev = device_get_binding(label); |
||||||
|
behavior_keycode_pressed(dev, usage_page, keycode); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_keycode_released(u8_t usage_page, u32_t keycode) |
||||||
|
{ |
||||||
|
for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { |
||||||
|
const char* label = global_behaviors[i]; |
||||||
|
struct device *dev = device_get_binding(label); |
||||||
|
behavior_keycode_released(dev, usage_page, keycode); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_modifiers_pressed(zmk_mod_flags modifiers) |
||||||
|
{ |
||||||
|
for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { |
||||||
|
const char* label = global_behaviors[i]; |
||||||
|
struct device *dev = device_get_binding(label); |
||||||
|
behavior_modifiers_pressed(dev, modifiers); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_modifiers_released(zmk_mod_flags modifiers) |
||||||
|
{ |
||||||
|
for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { |
||||||
|
const char* label = global_behaviors[i]; |
||||||
|
struct device *dev = device_get_binding(label); |
||||||
|
behavior_modifiers_released(dev, modifiers); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_consumer_key_pressed(u32_t usage) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
int zmk_events_consumer_key_released(u32_t usage) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
@ -1,88 +0,0 @@ |
|||||||
|
|
||||||
#include <zmk/ble.h> |
|
||||||
#include <zmk/handlers.h> |
|
||||||
#include <zmk/endpoints.h> |
|
||||||
#include <zmk/hid.h> |
|
||||||
#include <zmk/matrix.h> |
|
||||||
|
|
||||||
#ifdef CONFIG_ZMK_ACTION_MOD_TAP |
|
||||||
u16_t action_effect_pending = 0; |
|
||||||
#endif |
|
||||||
|
|
||||||
__attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event) |
|
||||||
{ |
|
||||||
return true; |
|
||||||
}; |
|
||||||
|
|
||||||
bool zmk_handle_action(zmk_action action, struct zmk_key_event *key_event) |
|
||||||
{ |
|
||||||
zmk_mod mods = ZK_MODS(key_event->key); |
|
||||||
u8_t flattened_index = (key_event->row * ZMK_MATRIX_COLS) + key_event->column; |
|
||||||
switch (action) |
|
||||||
{ |
|
||||||
#ifdef CONFIG_ZMK_ACTION_MOD_TAP |
|
||||||
case ZMK_ACTION_MOD_TAP: |
|
||||||
if (key_event->pressed) |
|
||||||
{ |
|
||||||
WRITE_BIT(action_effect_pending, flattened_index, true); |
|
||||||
zmk_hid_register_mods(mods); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
zmk_hid_unregister_mods(mods); |
|
||||||
if (action_effect_pending & BIT(flattened_index)) |
|
||||||
{ |
|
||||||
struct zmk_key_event non_mod_event = |
|
||||||
{ |
|
||||||
.row = key_event->row, |
|
||||||
.column = key_event->column, |
|
||||||
.key = ZK_KEY(key_event->key), |
|
||||||
.pressed = true}; |
|
||||||
|
|
||||||
zmk_handle_key(non_mod_event); |
|
||||||
// A small sleep is needed to ensure device layer sends initial
|
|
||||||
// key, before we send the release.
|
|
||||||
k_msleep(10); |
|
||||||
non_mod_event.pressed = false; |
|
||||||
zmk_handle_key(non_mod_event); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
// Since not sending a keycode, at least send the report w/ the mod removed
|
|
||||||
zmk_endpoints_send_report(Keypad); |
|
||||||
} |
|
||||||
} |
|
||||||
break; |
|
||||||
#endif |
|
||||||
} |
|
||||||
return false; |
|
||||||
}; |
|
||||||
|
|
||||||
void zmk_handle_key(struct zmk_key_event key_event) |
|
||||||
{ |
|
||||||
zmk_action action = ZK_ACTION(key_event.key); |
|
||||||
|
|
||||||
if (!zmk_handle_key_user(&key_event)) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (action && !zmk_handle_action(action, &key_event)) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
#ifdef CONFIG_ZMK_ACTION_MOD_TAP |
|
||||||
action_effect_pending = 0; |
|
||||||
#endif |
|
||||||
|
|
||||||
#ifdef CONFIG_ZMK_BLE |
|
||||||
/* Used for intercepting key presses when doing passkey verification */ |
|
||||||
if (!zmk_ble_handle_key_user(&key_event)) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
#endif /* CONFIG_ZMK_BLE */ |
|
||||||
|
|
||||||
zmk_endpoints_send_key_event(key_event); |
|
||||||
}; |
|
@ -0,0 +1,30 @@ |
|||||||
|
|
||||||
|
#include <zephyr.h> |
||||||
|
#include <zmk/matrix_transform.h> |
||||||
|
#include <zmk/matrix.h> |
||||||
|
#include <dt-bindings/zmk/matrix-transform.h> |
||||||
|
|
||||||
|
#define HAS_TRANSFORM DT_HAS_CHOSEN(zmk_matrix_transform) |
||||||
|
|
||||||
|
#if HAS_TRANSFORM |
||||||
|
#define ZMK_KEYMAP_TRANSFORM_NODE DT_CHOSEN(zmk_matrix_transform) |
||||||
|
#define ZMK_KEYMAP_LEN DT_PROP_LEN(ZMK_KEYMAP_TRANSFORM_NODE, map) |
||||||
|
|
||||||
|
#define _TRANSFORM_ENTRY(i, _) \ |
||||||
|
[(KT_ROW(DT_PROP_BY_IDX(ZMK_KEYMAP_TRANSFORM_NODE, map, i)) * ZMK_MATRIX_COLS) + KT_COL(DT_PROP_BY_IDX(ZMK_KEYMAP_TRANSFORM_NODE, map, i))] = i, |
||||||
|
|
||||||
|
static u32_t transform[] =
|
||||||
|
{ UTIL_LISTIFY(ZMK_KEYMAP_LEN, _TRANSFORM_ENTRY, 0) }; |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
u32_t zmk_matrix_transform_row_column_to_position(u32_t row, u32_t column) |
||||||
|
{ |
||||||
|
u32_t matrix_index = (row * ZMK_MATRIX_COLS) + column; |
||||||
|
|
||||||
|
#if HAS_TRANSFORM |
||||||
|
return transform[matrix_index]; |
||||||
|
#else |
||||||
|
return matrix_index; |
||||||
|
#endif /* HAS_TRANSFORM */ |
||||||
|
}; |
Loading…
Reference in new issue