Pete Johanson
4 years ago
19 changed files with 346 additions and 13 deletions
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
hid_behavior: behavior_hid { |
||||||
|
compatible = "zmk,behavior-hid"; |
||||||
|
label = "HID"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
keymap_behavior: behavior_keymap { |
||||||
|
compatible = "zmk,behavior-keymap"; |
||||||
|
label = "KEYMAP"; |
||||||
|
#binding-cells = <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,8 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Keymap Behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-keymap" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,9 @@ |
|||||||
|
description: | |
||||||
|
Specify the the global behaviors bound to state changes |
||||||
|
|
||||||
|
compatible: "zmk,global-bindings" |
||||||
|
|
||||||
|
properties: |
||||||
|
bindings: |
||||||
|
type: phandles |
||||||
|
required: true |
@ -0,0 +1,8 @@ |
|||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
struct zmk_behavior_binding { |
||||||
|
char *behavior_dev; |
||||||
|
u32_t param1; |
||||||
|
u32_t param2; |
||||||
|
}; |
@ -0,0 +1,13 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
int zmk_events_position_pressed(u32_t row, u32_t column); |
||||||
|
int zmk_events_position_released(u32_t row, u32_t column); |
||||||
|
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_consumer_key_pressed(u32_t usage); |
||||||
|
int zmk_events_consumer_key_released(u32_t usage); |
||||||
|
|
||||||
|
// TODO: Encoders?
|
||||||
|
// TODO: Sensors?
|
@ -0,0 +1,59 @@ |
|||||||
|
/*
|
||||||
|
* 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, u32_t keycode) |
||||||
|
{ |
||||||
|
enum zmk_hid_report_changes changes; |
||||||
|
LOG_DBG("keycode %d", keycode); |
||||||
|
|
||||||
|
changes = zmk_hid_press_key(keycode); |
||||||
|
return zmk_endpoints_send_report(changes); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_keycode_released(struct device *dev, u32_t keycode) |
||||||
|
{ |
||||||
|
enum zmk_hid_report_changes changes; |
||||||
|
LOG_DBG("keycode %d", keycode); |
||||||
|
|
||||||
|
changes = zmk_hid_release_key(keycode); |
||||||
|
return zmk_endpoints_send_report(changes); |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_hid_driver_api = { |
||||||
|
.keycode_pressed = on_keycode_pressed, |
||||||
|
.keycode_released = on_keycode_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,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 row, u32_t column) |
||||||
|
{ |
||||||
|
return zmk_keymap_position_state_changed(row, column, true); |
||||||
|
} |
||||||
|
|
||||||
|
static int on_position_released(struct device *dev, u32_t row, u32_t column) |
||||||
|
{ |
||||||
|
return zmk_keymap_position_state_changed(row, column, 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,72 @@ |
|||||||
|
|
||||||
|
#include <zephyr.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <zmk/behavior.h> |
||||||
|
#include <zmk/events.h> |
||||||
|
#include <sys/util.h> |
||||||
|
|
||||||
|
#define BINDINGS_NODE DT_CHOSEN(zmk_global_bindings) |
||||||
|
#define BINDING_COUNT DT_PROP_LEN(BINDINGS_NODE, bindings) |
||||||
|
|
||||||
|
#define BINDING_GEN(idx,_) \ |
||||||
|
{ .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(BINDINGS_NODE, bindings, idx)), \
|
||||||
|
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(BINDINGS_NODE, bindings, idx, param1), (0), (DT_PHA_BY_IDX(BINDINGS_NODE, bindings, idx, param1))), \
|
||||||
|
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(BINDINGS_NODE, bindings, idx, param2), (0), (DT_PHA_BY_IDX(BINDINGS_NODE, bindings, idx, param2))), \
|
||||||
|
}, |
||||||
|
|
||||||
|
static const struct zmk_behavior_binding bindings[] = |
||||||
|
{ UTIL_LISTIFY(BINDING_COUNT, BINDING_GEN, 0) }; |
||||||
|
|
||||||
|
int zmk_events_position_pressed(u32_t row, u32_t column) |
||||||
|
{ |
||||||
|
for (int i = 0; i < BINDING_COUNT; i++) { |
||||||
|
const struct zmk_behavior_binding *b = &bindings[i]; |
||||||
|
struct device *dev = device_get_binding(b->behavior_dev); |
||||||
|
behavior_position_pressed(dev, row, column); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_events_position_released(u32_t row, u32_t column) |
||||||
|
{ |
||||||
|
for (int i = 0; i < BINDING_COUNT; i++) { |
||||||
|
const struct zmk_behavior_binding *b = &bindings[i]; |
||||||
|
struct device *dev = device_get_binding(b->behavior_dev); |
||||||
|
behavior_position_released(dev, row, column); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
int zmk_events_keycode_pressed(u32_t keycode) |
||||||
|
{ |
||||||
|
for (int i = 0; i < BINDING_COUNT; i++) { |
||||||
|
const struct zmk_behavior_binding *b = &bindings[i]; |
||||||
|
struct device *dev = device_get_binding(b->behavior_dev); |
||||||
|
behavior_keycode_pressed(dev, keycode); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
int zmk_events_keycode_released(u32_t keycode) |
||||||
|
{ |
||||||
|
for (int i = 0; i < BINDING_COUNT; i++) { |
||||||
|
const struct zmk_behavior_binding *b = &bindings[i]; |
||||||
|
struct device *dev = device_get_binding(b->behavior_dev); |
||||||
|
behavior_keycode_released(dev, keycode); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
int zmk_events_mod_pressed(u32_t modifier) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
int zmk_events_mod_released(u32_t modifier) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
int zmk_events_consumer_key_pressed(u32_t usage) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
int zmk_events_consumer_key_released(u32_t usage) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
Loading…
Reference in new issue