summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/CMakeLists.txt3
-rw-r--r--app/boards/arm/nice_nano/nice_nano.dts1
-rw-r--r--app/boards/native_posix.overlay22
-rw-r--r--app/boards/shields/petejohanson_handwire/keymap/keymap.overlay7
-rw-r--r--app/dts/behaviors/hid.dtsi9
-rw-r--r--app/dts/behaviors/keymap.dtsi9
-rw-r--r--app/dts/bindings/behaviors/zmk,behavior-hid.yaml8
-rw-r--r--app/dts/bindings/behaviors/zmk,behavior-keymap.yaml8
-rw-r--r--app/dts/bindings/zmk,global-bindings.yaml9
-rw-r--r--app/include/drivers/behavior.h55
-rw-r--r--app/include/zmk/behavior.h8
-rw-r--r--app/include/zmk/events.h13
-rw-r--r--app/src/behaviors/behavior_hid.c59
-rw-r--r--app/src/behaviors/behavior_key_press.c13
-rw-r--r--app/src/behaviors/behavior_keymap.c50
-rw-r--r--app/src/endpoints.c1
-rw-r--r--app/src/events.c72
-rw-r--r--app/src/kscan.c11
-rw-r--r--app/src/kscan_mock.c1
19 files changed, 346 insertions, 13 deletions
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 89f4055..6f4217a 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -28,8 +28,11 @@ endif()
# find_package(Zephyr) which defines the target.
target_include_directories(app PRIVATE include)
target_sources(app PRIVATE src/kscan.c)
+target_sources(app PRIVATE src/events.c)
target_sources(app PRIVATE src/keymap.c)
target_sources(app PRIVATE src/hid.c)
+target_sources(app PRIVATE src/behaviors/behavior_keymap.c)
+target_sources(app PRIVATE src/behaviors/behavior_hid.c)
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/ble.c)
diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts
index 4604e9a..9d3b484 100644
--- a/app/boards/arm/nice_nano/nice_nano.dts
+++ b/app/boards/arm/nice_nano/nice_nano.dts
@@ -8,6 +8,7 @@
#include <nordic/nrf52840_qiaa.dtsi>
#include <behaviors/key_press.dtsi>
#include <behaviors/reset.dtsi>
+#include <behaviors/keymap.dtsi>
#include "arduino_pro_micro_pins.dtsi"
/ {
diff --git a/app/boards/native_posix.overlay b/app/boards/native_posix.overlay
index 9d92bee..3f2eead 100644
--- a/app/boards/native_posix.overlay
+++ b/app/boards/native_posix.overlay
@@ -1,10 +1,20 @@
#include <dt-bindings/zmk/keys.h>
+#include <behaviors/key_press.dtsi>
+#include <behaviors/reset.dtsi>
+#include <behaviors/keymap.dtsi>
+#include <behaviors/hid.dtsi>
#include <zmk/kscan-mock.h>
/ {
chosen {
zmk,kscan = &kscan0;
zmk,keymap = &keymap0;
+ zmk,global_bindings = &bindings;
+ };
+
+ bindings: global_bindings {
+ compatible = "zmk,global-bindings";
+ bindings = <&keymap_behavior &hid_behavior>;
};
kscan0: kscan_0 {
@@ -58,6 +68,10 @@
KC_A MT(MOD_LSFT, KC_B) KC_C KC_D
KC_E KC_F KC_G KC_H
>;
+
+ bindings = <
+ &kp 5 &kp 0 &kp 10 &kp 11
+ &kp 1 &kp 2 &kp 4 &kp 89>;
};
lower: layer_1 {
@@ -66,6 +80,10 @@
KC_A KC_B KC_C KC_D
KC_E KC_F KC_G KC_H
>;
+
+ bindings = <
+ &kp 5 &kp 0 &kp 10 &kp 11
+ &kp 1 &kp 2 &kp 4 &kp 89>;
};
raise: layer_2 {
@@ -74,6 +92,10 @@
KC_E KC_F KC_G KC_H
KC_A KC_B KC_C KC_D
>;
+
+ bindings = <
+ &kp 5 &kp 0 &kp 10 &kp 11
+ &kp 1 &kp 2 &kp 4 &kp 89>;
};
};
};
diff --git a/app/boards/shields/petejohanson_handwire/keymap/keymap.overlay b/app/boards/shields/petejohanson_handwire/keymap/keymap.overlay
index 8cb7654..5ae78cf 100644
--- a/app/boards/shields/petejohanson_handwire/keymap/keymap.overlay
+++ b/app/boards/shields/petejohanson_handwire/keymap/keymap.overlay
@@ -1,11 +1,18 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors/key_press.dtsi>
#include <behaviors/reset.dtsi>
+#include <behaviors/keymap.dtsi>
#include <keymap.h>
/ {
chosen {
zmk,keymap = &keymap0;
+ zmk,global_bindings = &bindings;
+ };
+
+ bindings: global_bindings {
+ compatible = "zmk,global-bindings";
+ bindings = <&reset>;
};
keymap0: keymap {
compatible = "zmk,keymap";
diff --git a/app/dts/behaviors/hid.dtsi b/app/dts/behaviors/hid.dtsi
new file mode 100644
index 0000000..d859c37
--- /dev/null
+++ b/app/dts/behaviors/hid.dtsi
@@ -0,0 +1,9 @@
+/ {
+ behaviors {
+ hid_behavior: behavior_hid {
+ compatible = "zmk,behavior-hid";
+ label = "HID";
+ #binding-cells = <0>;
+ };
+ };
+};
diff --git a/app/dts/behaviors/keymap.dtsi b/app/dts/behaviors/keymap.dtsi
new file mode 100644
index 0000000..87b2f41
--- /dev/null
+++ b/app/dts/behaviors/keymap.dtsi
@@ -0,0 +1,9 @@
+/ {
+ behaviors {
+ keymap_behavior: behavior_keymap {
+ compatible = "zmk,behavior-keymap";
+ label = "KEYMAP";
+ #binding-cells = <0>;
+ };
+ };
+};
diff --git a/app/dts/bindings/behaviors/zmk,behavior-hid.yaml b/app/dts/bindings/behaviors/zmk,behavior-hid.yaml
new file mode 100644
index 0000000..f3e0603
--- /dev/null
+++ b/app/dts/bindings/behaviors/zmk,behavior-hid.yaml
@@ -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
diff --git a/app/dts/bindings/behaviors/zmk,behavior-keymap.yaml b/app/dts/bindings/behaviors/zmk,behavior-keymap.yaml
new file mode 100644
index 0000000..1d8a51f
--- /dev/null
+++ b/app/dts/bindings/behaviors/zmk,behavior-keymap.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
diff --git a/app/dts/bindings/zmk,global-bindings.yaml b/app/dts/bindings/zmk,global-bindings.yaml
new file mode 100644
index 0000000..69e79cd
--- /dev/null
+++ b/app/dts/bindings/zmk,global-bindings.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
diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h
index 84b11ce..f5f5f53 100644
--- a/app/include/drivers/behavior.h
+++ b/app/include/drivers/behavior.h
@@ -22,12 +22,14 @@ extern "C" {
* (Internal use only.)
*/
-typedef int (*behavior_position_pressed_t)(struct device *dev, u32_t param1, u32_t param2);
-typedef int (*behavior_position_released_t)(struct device *dev, u32_t param1, u32_t param2);
+typedef int (*behavior_position_callback_t)(struct device *dev, u32_t param1, u32_t param2);
+typedef int (*behavior_keycode_callback_t)(struct device *dev, u32_t keycode);
__subsystem struct behavior_driver_api {
- behavior_position_pressed_t position_pressed;
- behavior_position_released_t position_released;
+ behavior_position_callback_t position_pressed;
+ behavior_position_callback_t position_released;
+ behavior_keycode_callback_t keycode_pressed;
+ behavior_keycode_callback_t keycode_released;
};
/**
* @endcond
@@ -77,6 +79,51 @@ static inline int z_impl_behavior_position_released(struct device *dev, u32_t pa
return api->position_released(dev, param1, param2);
}
+/**
+ * @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_keycode_pressed(struct device *dev, u32_t keycode);
+
+static inline int z_impl_behavior_keycode_pressed(struct device *dev, 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, keycode);
+}
+
+
+/**
+ * @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_keycode_released(struct device *dev, u32_t keycode);
+
+static inline int z_impl_behavior_keycode_released(struct device *dev, 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, keycode);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/app/include/zmk/behavior.h b/app/include/zmk/behavior.h
new file mode 100644
index 0000000..63edcc9
--- /dev/null
+++ b/app/include/zmk/behavior.h
@@ -0,0 +1,8 @@
+
+#pragma once
+
+struct zmk_behavior_binding {
+ char *behavior_dev;
+ u32_t param1;
+ u32_t param2;
+}; \ No newline at end of file
diff --git a/app/include/zmk/events.h b/app/include/zmk/events.h
new file mode 100644
index 0000000..9314b9d
--- /dev/null
+++ b/app/include/zmk/events.h
@@ -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? \ No newline at end of file
diff --git a/app/src/behaviors/behavior_hid.c b/app/src/behaviors/behavior_hid.c
new file mode 100644
index 0000000..2779568
--- /dev/null
+++ b/app/src/behaviors/behavior_hid.c
@@ -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); \ No newline at end of file
diff --git a/app/src/behaviors/behavior_key_press.c b/app/src/behaviors/behavior_key_press.c
index b9d0ff0..3c57c51 100644
--- a/app/src/behaviors/behavior_key_press.c
+++ b/app/src/behaviors/behavior_key_press.c
@@ -10,6 +10,8 @@
#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 { };
@@ -29,19 +31,16 @@ static int behavior_key_press_init(struct device *dev)
// * < 0 - Indicate error processing, report and halt further propagation.
static int on_position_pressed(struct device *dev, u32_t keycode, u32_t _)
{
- // Invoking this triggers a *new* event, that can be linked to other behaviours.
- //return zmk_key_state_press(u32_t keycode);
- return 0;
+ LOG_DBG("pressing: %d", keycode);
+ return zmk_events_keycode_pressed(keycode);
}
// They keycode is passed by the "keymap" based on the parameter created as part of the assignment.
static int on_position_released(struct device *dev, u32_t keycode, u32_t _)
{
- // Invoking this triggers a *new* event, that can will be handled by other behaviors
- // This is the "command" piece. Which could be better/richer, but captures essence here.
- // return zmk_key_state_release(u32_t keycode);
- return 0;
+ LOG_DBG("releasing: %d", keycode);
+ return zmk_events_keycode_released(keycode);
}
static const struct behavior_driver_api behavior_key_press_driver_api = {
diff --git a/app/src/behaviors/behavior_keymap.c b/app/src/behaviors/behavior_keymap.c
new file mode 100644
index 0000000..48f8547
--- /dev/null
+++ b/app/src/behaviors/behavior_keymap.c
@@ -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); \ No newline at end of file
diff --git a/app/src/endpoints.c b/app/src/endpoints.c
index f46d42d..2f31e10 100644
--- a/app/src/endpoints.c
+++ b/app/src/endpoints.c
@@ -40,6 +40,7 @@ int zmk_endpoints_send_report(enum zmk_hid_report_changes report_type)
int err;
struct zmk_hid_keypad_report *keypad_report;
struct zmk_hid_consumer_report *consumer_report;
+ LOG_DBG("");
switch (report_type)
{
case Keypad:
diff --git a/app/src/events.c b/app/src/events.c
new file mode 100644
index 0000000..c3e8d84
--- /dev/null
+++ b/app/src/events.c
@@ -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;
+}; \ No newline at end of file
diff --git a/app/src/kscan.c b/app/src/kscan.c
index d1ed621..781824d 100644
--- a/app/src/kscan.c
+++ b/app/src/kscan.c
@@ -11,7 +11,7 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
-#include <zmk/keymap.h>
+#include <zmk/events.h>
#include <zmk/handlers.h>
#define ZMK_KSCAN_EVENT_STATE_PRESSED 0
@@ -49,7 +49,14 @@ void zmk_kscan_process_msgq(struct k_work *item)
while (k_msgq_get(&zmk_kscan_msgq, &ev, K_NO_WAIT) == 0)
{
bool pressed = (ev.state == ZMK_KSCAN_EVENT_STATE_PRESSED);
- zmk_keymap_position_state_changed(ev.row, ev.column, pressed);
+ if (pressed) {
+ LOG_DBG("PRESSING");
+ zmk_events_position_pressed(ev.row, ev.column);
+ } else {
+ LOG_DBG("RELEASSING");
+ zmk_events_position_released(ev.row, ev.column);
+ }
+ // zmk_keymap_position_state_changed(ev.row, ev.column, pressed);
// zmk_key key = zmk_keymap_keycode_from_position(ev.row, ev.column);
// struct zmk_key_event kev = (struct zmk_key_event){.row = ev.row, .column = ev.column, .key = key, .pressed = pressed};
diff --git a/app/src/kscan_mock.c b/app/src/kscan_mock.c
index 7d2d24d..b0ba90b 100644
--- a/app/src/kscan_mock.c
+++ b/app/src/kscan_mock.c
@@ -9,6 +9,7 @@
#include <device.h>
#include <drivers/kscan.h>
#include <logging/log.h>
+
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/kscan-mock.h>