From 38960327402a1c35168c220cb8956b5acd122a7d Mon Sep 17 00:00:00 2001 From: Stephen Wan Date: Mon, 15 Mar 2021 11:57:33 -0700 Subject: [PATCH 1/6] refactor(core): read sensor values earlier Reading the values earlier will let us send the sensor values over GATT for split, which will happen in a subsequent commit. --- app/include/drivers/behavior.h | 12 ++++++------ app/include/zmk/events/sensor_event.h | 3 ++- app/src/behaviors/behavior_sensor_rotate_key_press.c | 11 +---------- app/src/keymap.c | 6 +++--- app/src/sensors.c | 9 ++++++++- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h index fcb24f6f..5c78ac21 100644 --- a/app/include/drivers/behavior.h +++ b/app/include/drivers/behavior.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -25,7 +26,7 @@ typedef int (*behavior_keymap_binding_callback_t)(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event); typedef int (*behavior_sensor_keymap_binding_callback_t)(struct zmk_behavior_binding *binding, - const struct device *sensor, + const struct sensor_value value, int64_t timestamp); enum behavior_locality { @@ -159,12 +160,11 @@ static inline int z_impl_behavior_keymap_binding_released(struct zmk_behavior_bi * @retval Negative errno code if failure. */ __syscall int behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding, - const struct device *sensor, + const struct sensor_value value, int64_t timestamp); -static inline int -z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding, - const struct device *sensor, int64_t timestamp) { +static inline int z_impl_behavior_sensor_keymap_binding_triggered( + struct zmk_behavior_binding *binding, const struct sensor_value value, int64_t timestamp) { const struct device *dev = device_get_binding(binding->behavior_dev); if (dev == NULL) { @@ -177,7 +177,7 @@ z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *bin return -ENOTSUP; } - return api->sensor_binding_triggered(binding, sensor, timestamp); + return api->sensor_binding_triggered(binding, value, timestamp); } /** diff --git a/app/include/zmk/events/sensor_event.h b/app/include/zmk/events/sensor_event.h index f579bc39..8a429978 100644 --- a/app/include/zmk/events/sensor_event.h +++ b/app/include/zmk/events/sensor_event.h @@ -6,12 +6,13 @@ #pragma once +#include #include #include #include struct zmk_sensor_event { uint8_t sensor_number; - const struct device *sensor; + struct sensor_value value; int64_t timestamp; }; diff --git a/app/src/behaviors/behavior_sensor_rotate_key_press.c b/app/src/behaviors/behavior_sensor_rotate_key_press.c index c4a34a94..81be3d96 100644 --- a/app/src/behaviors/behavior_sensor_rotate_key_press.c +++ b/app/src/behaviors/behavior_sensor_rotate_key_press.c @@ -21,19 +21,10 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); static int behavior_sensor_rotate_key_press_init(const struct device *dev) { return 0; }; static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding, - const struct device *sensor, int64_t timestamp) { - struct sensor_value value; - int err; + const struct sensor_value value, int64_t timestamp) { uint32_t keycode; LOG_DBG("inc keycode 0x%02X dec keycode 0x%02X", binding->param1, binding->param2); - err = sensor_channel_get(sensor, SENSOR_CHAN_ROTATION, &value); - - if (err) { - LOG_WRN("Failed to ge sensor rotation value: %d", err); - return err; - } - switch (value.val1) { case 1: keycode = binding->param1; diff --git a/app/src/keymap.c b/app/src/keymap.c index e586316f..f3f28ddb 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -251,7 +251,7 @@ int zmk_keymap_position_state_changed(uint8_t source, uint32_t position, bool pr } #if ZMK_KEYMAP_HAS_SENSORS -int zmk_keymap_sensor_triggered(uint8_t sensor_number, const struct device *sensor, +int zmk_keymap_sensor_triggered(uint8_t sensor_number, const struct sensor_value value, int64_t timestamp) { for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= _zmk_keymap_layer_default; layer--) { if (zmk_keymap_layer_active(layer) && zmk_sensor_keymap[layer] != NULL) { @@ -269,7 +269,7 @@ int zmk_keymap_sensor_triggered(uint8_t sensor_number, const struct device *sens continue; } - ret = behavior_sensor_keymap_binding_triggered(binding, sensor, timestamp); + ret = behavior_sensor_keymap_binding_triggered(binding, value, timestamp); if (ret > 0) { LOG_DBG("behavior processing to continue to next layer"); @@ -298,7 +298,7 @@ int keymap_listener(const zmk_event_t *eh) { #if ZMK_KEYMAP_HAS_SENSORS const struct zmk_sensor_event *sensor_ev; if ((sensor_ev = as_zmk_sensor_event(eh)) != NULL) { - return zmk_keymap_sensor_triggered(sensor_ev->sensor_number, sensor_ev->sensor, + return zmk_keymap_sensor_triggered(sensor_ev->sensor_number, sensor_ev->value, sensor_ev->timestamp); } #endif /* ZMK_KEYMAP_HAS_SENSORS */ diff --git a/app/src/sensors.c b/app/src/sensors.c index dd5f4267..02ed5eeb 100644 --- a/app/src/sensors.c +++ b/app/src/sensors.c @@ -44,8 +44,15 @@ static void zmk_sensors_trigger_handler(const struct device *dev, struct sensor_ return; } + struct sensor_value value; + err = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &value); + if (err) { + LOG_WRN("Failed to get sensor rotation value: %d", err); + return; + } + ZMK_EVENT_RAISE(new_zmk_sensor_event((struct zmk_sensor_event){ - .sensor_number = item->sensor_number, .sensor = dev, .timestamp = k_uptime_get()})); + .sensor_number = item->sensor_number, .value = value, .timestamp = k_uptime_get()})); } static void zmk_sensors_init_item(const char *node, uint8_t i, uint8_t abs_i) { From f26d391c22bd89b2a86702ac5b2e93666b5dd472 Mon Sep 17 00:00:00 2001 From: Kim Streich Date: Tue, 15 Mar 2022 20:09:26 +0400 Subject: [PATCH 2/6] refactor(split): take params in subscribe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We'll reuse this function later to subscribe to multiple characteristics. — This commit was originally made by Stephen Wan. I just adjusted it so that it rebases on top of later changes on the zmk main branch. --- app/src/split/bluetooth/central.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 2f02faaf..648c8e45 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -190,14 +190,8 @@ static uint8_t split_central_notify_func(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static void split_central_subscribe(struct bt_conn *conn) { - struct peripheral_slot *slot = peripheral_slot_for_conn(conn); - if (slot == NULL) { - LOG_ERR("No peripheral state found for connection"); - return; - } - - int err = bt_gatt_subscribe(conn, &slot->subscribe_params); +static void split_central_subscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *params) { + int err = bt_gatt_subscribe(conn, params); switch (err) { case -EALREADY: LOG_DBG("[ALREADY SUBSCRIBED]"); @@ -244,7 +238,7 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn, slot->subscribe_params.value_handle = bt_gatt_attr_value_handle(attr); slot->subscribe_params.notify = split_central_notify_func; slot->subscribe_params.value = BT_GATT_CCC_NOTIFY; - split_central_subscribe(conn); + split_central_subscribe(conn, &slot->subscribe_params); } else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID))) { LOG_DBG("Found run behavior handle"); From e58f97d706cdb2ac3f57d327716d7bfe8fef1d44 Mon Sep 17 00:00:00 2001 From: Kim Streich Date: Sun, 3 Apr 2022 12:50:51 +0400 Subject: [PATCH 3/6] feature(split): add support for sensors from peripheral MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new GATT characteristics on the peripheral side and wires it up to read sensor values. The central side subscribes to this new characteristics and replays sensor values on its side. — This commit was originally made by Stephen Wan. I just adjusted it so that it rebases on top of later changes on the zmk main branch. --- app/include/zmk/split/bluetooth/service.h | 6 +- app/include/zmk/split/bluetooth/uuid.h | 1 + app/src/split/bluetooth/central.c | 95 +++++++++++++++++++++++ app/src/split/bluetooth/service.c | 72 ++++++++++++++++- app/src/split_listener.c | 32 ++++++-- 5 files changed, 197 insertions(+), 9 deletions(-) diff --git a/app/include/zmk/split/bluetooth/service.h b/app/include/zmk/split/bluetooth/service.h index f0c1d79f..9acf120c 100644 --- a/app/include/zmk/split/bluetooth/service.h +++ b/app/include/zmk/split/bluetooth/service.h @@ -6,6 +6,8 @@ #pragma once +#include + #define ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN 9 struct zmk_split_run_behavior_data { @@ -20,5 +22,7 @@ struct zmk_split_run_behavior_payload { char behavior_dev[ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN]; } __packed; + int zmk_split_bt_position_pressed(uint8_t position); -int zmk_split_bt_position_released(uint8_t position); \ No newline at end of file +int zmk_split_bt_position_released(uint8_t position); +int zmk_split_bt_sensor_triggered(uint8_t sensor_number, struct sensor_value value); diff --git a/app/include/zmk/split/bluetooth/uuid.h b/app/include/zmk/split/bluetooth/uuid.h index 735f5751..7dac743f 100644 --- a/app/include/zmk/split/bluetooth/uuid.h +++ b/app/include/zmk/split/bluetooth/uuid.h @@ -16,3 +16,4 @@ #define ZMK_SPLIT_BT_SERVICE_UUID ZMK_BT_SPLIT_UUID(0x00000000) #define ZMK_SPLIT_BT_CHAR_POSITION_STATE_UUID ZMK_BT_SPLIT_UUID(0x00000001) #define ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID ZMK_BT_SPLIT_UUID(0x00000002) +#define ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID ZMK_BT_SPLIT_UUID(0x00000002) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 648c8e45..a8eeadc1 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -20,10 +20,12 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include #include #include #include #include +#include #include static int start_scan(void); @@ -146,6 +148,50 @@ void peripheral_event_work_callback(struct k_work *work) { K_WORK_DEFINE(peripheral_event_work, peripheral_event_work_callback); +#if ZMK_KEYMAP_HAS_SENSORS +K_MSGQ_DEFINE(peripheral_sensor_event_msgq, sizeof(struct zmk_sensor_event), + CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4); + +void peripheral_sensor_event_work_callback(struct k_work *work) { + struct zmk_sensor_event ev; + while (k_msgq_get(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT) == 0) { + LOG_DBG("Trigger sensor change for %d", ev.sensor_number); + ZMK_EVENT_RAISE(new_zmk_sensor_event(ev)); + } +} + +K_WORK_DEFINE(peripheral_sensor_event_work, peripheral_sensor_event_work_callback); + +struct sensor_event { + uint8_t sensor_number; + struct sensor_value value; +}; + +static uint8_t split_central_sensor_notify_func(struct bt_conn *conn, + struct bt_gatt_subscribe_params *params, + const void *data, uint16_t length) { + + const struct sensor_event *sensor_event = data; + + if (!data) { + LOG_DBG("[UNSUBSCRIBED]"); + params->value_handle = 0U; + return BT_GATT_ITER_STOP; + } + LOG_DBG("[SENSOR NOTIFICATION] data %p length %u", data, length); + + struct zmk_sensor_event ev = { + .sensor_number = sensor_event->sensor_number, + .value = {.val1 = (sensor_event->value).val1, .val2 = (sensor_event->value).val2}, + .timestamp = k_uptime_get()}; + + k_msgq_put(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT); + k_work_submit(&peripheral_sensor_event_work); + + return BT_GATT_ITER_CONTINUE; +} +#endif /* ZMK_KEYMAP_HAS_SENSORS */ + static uint8_t split_central_notify_func(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length) { @@ -205,6 +251,39 @@ static void split_central_subscribe(struct bt_conn *conn, struct bt_gatt_subscri } } +#if ZMK_KEYMAP_HAS_SENSORS +static struct bt_uuid_128 sensor_uuid = BT_UUID_INIT_128(ZMK_SPLIT_BT_SERVICE_UUID); +static struct bt_gatt_discover_params sensor_discover_params; +static struct bt_gatt_subscribe_params sensor_subscribe_params; +static uint8_t split_central_sensor_desc_discovery_func(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + struct bt_gatt_discover_params *params) { + int err; + + if (!bt_uuid_cmp(sensor_discover_params.uuid, + BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID))) { + memcpy(&sensor_uuid, BT_UUID_GATT_CCC, sizeof(sensor_uuid)); + sensor_discover_params.uuid = &sensor_uuid.uuid; + sensor_discover_params.start_handle = attr->handle; + sensor_discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR; + + sensor_subscribe_params.value_handle = bt_gatt_attr_value_handle(attr); + + err = bt_gatt_discover(conn, &sensor_discover_params); + if (err) { + LOG_ERR("Discover failed (err %d)", err); + } + } else { + sensor_subscribe_params.notify = split_central_sensor_notify_func; + sensor_subscribe_params.value = BT_GATT_CCC_NOTIFY; + sensor_subscribe_params.ccc_handle = attr->handle; + split_central_subscribe(conn, &sensor_subscribe_params); + } + + return BT_GATT_ITER_STOP; +} +#endif /* ZMK_KEYMAP_HAS_SENSORS */ + static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, struct bt_gatt_discover_params *params) { @@ -282,6 +361,22 @@ static uint8_t split_central_service_discovery_func(struct bt_conn *conn, if (err) { LOG_ERR("Failed to start discovering split service characteristics (err %d)", err); } + +#if ZMK_KEYMAP_HAS_SENSORS + memcpy(&sensor_uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID), + sizeof(sensor_uuid)); + sensor_discover_params.uuid = &sensor_uuid.uuid; + sensor_discover_params.start_handle = attr->handle; + sensor_discover_params.end_handle = 0xffff; + sensor_discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; + sensor_discover_params.func = split_central_sensor_desc_discovery_func; + + err = bt_gatt_discover(conn, &sensor_discover_params); + if (err) { + LOG_ERR("Discover failed (err %d)", err); + } +#endif /* ZMK_KEYMAP_HAS_SENSORS */ + return BT_GATT_ITER_STOP; } diff --git a/app/src/split/bluetooth/service.c b/app/src/split/bluetooth/service.c index 5da5401d..730e2603 100644 --- a/app/src/split/bluetooth/service.c +++ b/app/src/split/bluetooth/service.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT */ +#include #include #include #include @@ -20,6 +21,23 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include + +#if ZMK_KEYMAP_HAS_SENSORS +struct sensor_event { + uint8_t sensor_number; + struct sensor_value value; +} sensor_event; + +static ssize_t split_svc_sensor_state(struct bt_conn *conn, const struct bt_gatt_attr *attrs, + void *buf, uint16_t len, uint16_t offset) { + return bt_gatt_attr_read(conn, attrs, buf, len, offset, &sensor_event, sizeof(sensor_event)); +} + +static void split_svc_sensor_state_ccc(const struct bt_gatt_attr *attr, uint16_t value) { + LOG_DBG("value %d", value); +} +#endif /* ZMK_KEYMAP_HAS_SENSORS */ #define POS_STATE_LEN 16 @@ -98,7 +116,14 @@ BT_GATT_SERVICE_DEFINE( BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE_ENCRYPT, NULL, split_svc_run_behavior, &behavior_run_payload), BT_GATT_DESCRIPTOR(BT_UUID_NUM_OF_DIGITALS, BT_GATT_PERM_READ, split_svc_num_of_positions, NULL, - &num_of_positions), ); + &num_of_positions), +#if ZMK_KEYMAP_HAS_SENSORS + BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID), + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT, + split_svc_sensor_state, NULL, &sensor_event), + BT_GATT_CCC(split_svc_sensor_state_ccc, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), +#endif /* ZMK_KEYMAP_HAS_SENSORS */ +); K_THREAD_STACK_DEFINE(service_q_stack, CONFIG_ZMK_SPLIT_BLE_PERIPHERAL_STACK_SIZE); @@ -151,6 +176,51 @@ int zmk_split_bt_position_released(uint8_t position) { return send_position_state(); } +#if ZMK_KEYMAP_HAS_SENSORS +K_MSGQ_DEFINE(sensor_state_msgq, sizeof(sensor_event), + CONFIG_ZMK_SPLIT_BLE_PERIPHERAL_POSITION_QUEUE_SIZE, 4); + +void send_sensor_state_callback(struct k_work *work) { + struct sensor_event ev; + + while (k_msgq_get(&sensor_state_msgq, &ev, K_NO_WAIT) == 0) { + int err = bt_gatt_notify(NULL, &split_svc.attrs[5], &ev, sizeof(ev)); + if (err) { + LOG_DBG("Error notifying %d", err); + } + } +}; + +K_WORK_DEFINE(service_sensor_notify_work, send_sensor_state_callback); + +int send_sensor_state() { + int err = k_msgq_put(&sensor_state_msgq, &sensor_event, K_MSEC(100)); + if (err) { + // retry... + switch (err) { + case -EAGAIN: { + LOG_WRN("Sensor state message queue full, popping first message and queueing again"); + struct sensor_event discarded_state; + k_msgq_get(&sensor_state_msgq, &discarded_state, K_NO_WAIT); + return send_sensor_state(); + } + default: + LOG_WRN("Failed to queue sensor state to send (%d)", err); + return err; + } + } + + k_work_submit_to_queue(&service_work_q, &service_sensor_notify_work); + return 0; +} + +int zmk_split_bt_sensor_triggered(uint8_t sensor_number, struct sensor_value value) { + sensor_event.sensor_number = sensor_number; + sensor_event.value = value; + return send_sensor_state(); +} +#endif /* ZMK_KEYMAP_HAS_SENSORS */ + int service_init(const struct device *_arg) { static const struct k_work_queue_config queue_config = { .name = "Split Peripheral Notification Queue"}; diff --git a/app/src/split_listener.c b/app/src/split_listener.c index 3f3763ae..93e58743 100644 --- a/app/src/split_listener.c +++ b/app/src/split_listener.c @@ -5,6 +5,7 @@ */ #include +#include #include #include @@ -13,21 +14,38 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include +#include #include +#include #include int split_listener(const zmk_event_t *eh) { LOG_DBG(""); - const struct zmk_position_state_changed *ev = as_zmk_position_state_changed(eh); - if (ev != NULL) { - if (ev->state) { - return zmk_split_bt_position_pressed(ev->position); - } else { - return zmk_split_bt_position_released(ev->position); + const struct zmk_position_state_changed *pos_ev; + if ((pos_ev = as_zmk_position_state_changed(eh)) != NULL) { + if (pos_ev != NULL) { + if (pos_ev->state) { + return zmk_split_bt_position_pressed(pos_ev->position); + } else { + return zmk_split_bt_position_released(pos_ev->position); + } } } + +#if ZMK_KEYMAP_HAS_SENSORS + const struct zmk_sensor_event *sensor_ev; + if ((sensor_ev = as_zmk_sensor_event(eh)) != NULL) { + if (sensor_ev != NULL) { + return zmk_split_bt_sensor_triggered(sensor_ev->sensor_number, sensor_ev->value); + } + } +#endif /* ZMK_KEYMAP_HAS_SENSORS */ return ZMK_EV_EVENT_BUBBLE; } ZMK_LISTENER(split_listener, split_listener); -ZMK_SUBSCRIPTION(split_listener, zmk_position_state_changed); \ No newline at end of file +ZMK_SUBSCRIPTION(split_listener, zmk_position_state_changed); + +#if ZMK_KEYMAP_HAS_SENSORS +ZMK_SUBSCRIPTION(split_listener, zmk_sensor_event); +#endif /* ZMK_KEYMAP_HAS_SENSORS */ From 4fa7d3451bcf38907e6c04377db9da222172206e Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 25 Nov 2022 00:20:53 -0500 Subject: [PATCH 4/6] feat(shields): Add splitkb.com Aurora Lily58. --- .../splitkb_aurora_lily58/Kconfig.defconfig | 55 +++++++++++++ .../splitkb_aurora_lily58/Kconfig.shield | 8 ++ .../boards/nice_nano.overlay | 31 ++++++++ .../boards/nice_nano_v2.overlay | 31 ++++++++ .../splitkb_aurora_lily58.conf | 9 +++ .../splitkb_aurora_lily58.dtsi | 78 +++++++++++++++++++ .../splitkb_aurora_lily58.keymap | 70 +++++++++++++++++ .../splitkb_aurora_lily58.zmk.yml | 12 +++ .../splitkb_aurora_lily58_left.overlay | 43 ++++++++++ .../splitkb_aurora_lily58_right.overlay | 45 +++++++++++ 10 files changed, 382 insertions(+) create mode 100644 app/boards/shields/splitkb_aurora_lily58/Kconfig.defconfig create mode 100644 app/boards/shields/splitkb_aurora_lily58/Kconfig.shield create mode 100644 app/boards/shields/splitkb_aurora_lily58/boards/nice_nano.overlay create mode 100644 app/boards/shields/splitkb_aurora_lily58/boards/nice_nano_v2.overlay create mode 100644 app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.conf create mode 100644 app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.dtsi create mode 100644 app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.keymap create mode 100644 app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.zmk.yml create mode 100644 app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay create mode 100644 app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay diff --git a/app/boards/shields/splitkb_aurora_lily58/Kconfig.defconfig b/app/boards/shields/splitkb_aurora_lily58/Kconfig.defconfig new file mode 100644 index 00000000..bbaef0ff --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/Kconfig.defconfig @@ -0,0 +1,55 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +if SHIELD_SPLITKB_AURORA_LILY58_LEFT + +config ZMK_KEYBOARD_NAME + default "Aurora Lily58" + +config ZMK_SPLIT_ROLE_CENTRAL + default y + +endif # SHIELD_SPLITKB_AURORA_LILY58_LEFT + +if SHIELD_SPLITKB_AURORA_LILY58_LEFT || SHIELD_SPLITKB_AURORA_LILY58_RIGHT + +config ZMK_SPLIT + default y + +config ZMK_RGB_UNDERGLOW + select WS2812_STRIP + select SPI + +config ZMK_DISPLAY + +if ZMK_DISPLAY + +config SSD1306 + default y + +config I2C + default y + +config SSD1306_REVERSE_MODE + default y + +endif # ZMK_DISPLAY + +if LVGL + +config LVGL_VDB_SIZE + default 64 + +config LVGL_DPI + default 148 + +config LVGL_BITS_PER_PIXEL + default 1 + +choice LVGL_COLOR_DEPTH + default LVGL_COLOR_DEPTH_1 +endchoice + +endif # LVGL + +endif # SHIELD_SPLITKB_AURORA_LILY58_LEFT || SHIELD_SPLITKB_AURORA_LILY58_RIGHT diff --git a/app/boards/shields/splitkb_aurora_lily58/Kconfig.shield b/app/boards/shields/splitkb_aurora_lily58/Kconfig.shield new file mode 100644 index 00000000..35f8b2d1 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/Kconfig.shield @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +config SHIELD_SPLITKB_AURORA_LILY58_LEFT + def_bool $(shields_list_contains,splitkb_aurora_lily58_left) + +config SHIELD_SPLITKB_AURORA_LILY58_RIGHT + def_bool $(shields_list_contains,splitkb_aurora_lily58_right) diff --git a/app/boards/shields/splitkb_aurora_lily58/boards/nice_nano.overlay b/app/boards/shields/splitkb_aurora_lily58/boards/nice_nano.overlay new file mode 100644 index 00000000..eb838b24 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/boards/nice_nano.overlay @@ -0,0 +1,31 @@ +#include + +&spi1 { + compatible = "nordic,nrf-spim"; + status = "okay"; + mosi-pin = <6>; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + sck-pin = <5>; + miso-pin = <7>; + + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + label = "WS2812"; + + /* SPI */ + reg = <0>; /* ignored, but necessary for SPI bindings */ + spi-max-frequency = <4000000>; + + /* WS2812 */ + chain-length = <5>; /* arbitrary; change at will */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + color-mapping = ; + }; +}; + +/ { + chosen { + zmk,underglow = &led_strip; + }; +}; diff --git a/app/boards/shields/splitkb_aurora_lily58/boards/nice_nano_v2.overlay b/app/boards/shields/splitkb_aurora_lily58/boards/nice_nano_v2.overlay new file mode 100644 index 00000000..eb838b24 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/boards/nice_nano_v2.overlay @@ -0,0 +1,31 @@ +#include + +&spi1 { + compatible = "nordic,nrf-spim"; + status = "okay"; + mosi-pin = <6>; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + sck-pin = <5>; + miso-pin = <7>; + + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + label = "WS2812"; + + /* SPI */ + reg = <0>; /* ignored, but necessary for SPI bindings */ + spi-max-frequency = <4000000>; + + /* WS2812 */ + chain-length = <5>; /* arbitrary; change at will */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + color-mapping = ; + }; +}; + +/ { + chosen { + zmk,underglow = &led_strip; + }; +}; diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.conf b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.conf new file mode 100644 index 00000000..bb2b843d --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.conf @@ -0,0 +1,9 @@ +# Uncomment these two line to add support for encoders to your firmware +# CONFIG_EC11=y +# CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y + +# Uncomment the following line to enable the Kyria OLED Display +# CONFIG_ZMK_DISPLAY=y + +# Uncomment the following lines to enable RGB underglow +# CONFIG_ZMK_RGB_UNDERGLOW=y diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.dtsi b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.dtsi new file mode 100644 index 00000000..b6dc3758 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.dtsi @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + + chosen { + zephyr,display = &oled; + zmk,matrix_transform = &default_transform; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <16>; + rows = <5>; +// | SW6 | SW5 | SW4 | SW3 | SW2 | SW1 | | SW1 | SW2 | SW3 | SW4 | SW5 | SW6 | +// | SW12 | SW11 | SW10 | SW9 | SW8 | SW7 | | SW7 | SW8 | SW9 | SW10 | SW11 | SW12 | +// | SW18 | SW17 | SW16 | SW15 | SW14 | SW13 | | SW13 | SW14 | SW15 | SW16 | SW17 | SW18 | +// | SW24 | SW23 | SW22 | SW21 | SW20 | SW19 | SW25 | | SW25 | SW19 | SW20 | SW21 | SW22 | SW23 | SW24 | +// | SW29 | SW28 | SW27 | SW26 | | SW26 | SW27 | SW28 | SW29 | + map = < +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) +RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) +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(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,1) RC(4,10) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) + RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) RC(4,8) RC(4,9) + >; + }; + + left_encoder: left_encoder { + compatible = "alps,ec11"; + label = "L_ENCODER"; + resolution = <4>; + status = "disabled"; + + a-gpios = <&pro_micro 5 GPIO_PULL_UP>; + b-gpios = <&pro_micro 4 GPIO_PULL_UP>; + }; + + right_encoder: right_encoder { + compatible = "alps,ec11"; + label = "R_ENCODER"; + resolution = <4>; + status = "disabled"; + + a-gpios = <&pro_micro 18 GPIO_PULL_UP>; + b-gpios = <&pro_micro 19 GPIO_PULL_UP>; + }; + + sensors { + compatible = "zmk,keymap-sensors"; + sensors = <&left_encoder &right_encoder>; + }; +}; + +&pro_micro_i2c { + status = "okay"; + + oled: ssd1306@3c { + compatible = "solomon,ssd1306fb"; + reg = <0x3c>; + label = "DISPLAY"; + width = <128>; + height = <32>; + segment-offset = <0>; + page-offset = <0>; + display-offset = <0>; + multiplex-ratio = <31>; + segment-remap; + com-invdir; + com-sequential; + prechargep = <0x22>; + }; +}; diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.keymap b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.keymap new file mode 100644 index 00000000..61198ac1 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.keymap @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { +// ------------------------------------------------------------------------------------------------------------ +// | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ` | +// | TAB | Q | W | E | R | T | | Y | U | I | O | P | - | +// | CTRL | A | S | D | F | G | | H | J | K | L | ; | ' | +// | SHIFT | Z | X | C | V | B | "[" | | "]" | N | M | , | . | / | SHIFT | +// | ALT | GUI | LOWER| SPACE | | ENTER | RAISE| BSPC | GUI | + bindings = < +&kp ESC &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp GRAVE +&kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp MINUS +&kp LCTRL &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT +&kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp LBKT &kp RBKT &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT + &kp LALT &kp LGUI &mo 1 &kp SPACE &kp RET &mo 2 &kp BSPC &kp RGUI + >; + + sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; + }; + + lower_layer { +// ------------------------------------------------------------------------------------------------------------ +// | BTCLR | BT1 | BT2 | BT3 | BT4 | BT5 | | | | | | | | +// | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | F12 | +// | ` | ! | @ | # | $ | % | | ^ | & | * | ( | ) | ~ | +// | | | | | | | | | | | _ | + | { | } | "|" | +// | | | | | | | | | | + bindings = < +&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &trans &trans &trans &trans &trans &trans +&kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 +&kp GRAVE &kp EXCL &kp AT &kp HASH &kp DOLLAR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp TILDE +&trans &ext_power EP_ON &ext_power EP_OFF &ext_power EP_TOG &trans &trans &trans &trans &trans &kp MINUS &kp KP_PLUS &kp LBRC &kp RBRC &kp PIPE + &trans &trans &trans &trans &trans &trans &trans &trans + >; + + sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; + }; + + raise_layer { +// ------------------------------------------------------------------------------------------------------------ +// | | | | | | | | | | | | | | +// | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | | +// | F1 | F2 | F3 | F4 | F5 | F6 | | | <- | v | ^ | -> | | +// | F7 | F8 | F9 | F10 | F11 | F12 | | | | + | - | = | [ | ] | \ | +// | | | | | | | | | | + bindings = < +&trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans +&kp GRAVE &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &trans +&kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &trans &kp LEFT &kp DOWN &kp UP &kp RIGHT &trans +&kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 &trans &trans &kp KP_PLUS &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH + &trans &trans &trans &trans &trans &trans &trans &trans + >; + + sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; + }; + }; +}; diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.zmk.yml b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.zmk.yml new file mode 100644 index 00000000..47d49a4c --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58.zmk.yml @@ -0,0 +1,12 @@ +file_format: "1" +id: splitkb_aurora_lily58 +name: splitkb.com Aurora Lily58 +type: shield +url: https://splitkb.com/products/aurora-lily58-pcb-kit +requires: [pro_micro] +exposes: [i2c_oled] +features: + - keys +siblings: + - splitkb_aurora_lily58_left + - splitkb_aurora_lily58_right diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay new file mode 100644 index 00000000..1fa61286 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include "splitkb_aurora_lily58.dtsi" + +/ { + chosen { + zmk,kscan = &kscan; + }; + + kscan: kscan { + compatible = "zmk,kscan-gpio-matrix"; + + label = "KSCAN"; + diode-direction = "row2col"; + + row-gpios + = <&pro_micro 21 GPIO_ACTIVE_HIGH> + , <&pro_micro 19 GPIO_ACTIVE_HIGH> + , <&pro_micro 6 GPIO_ACTIVE_HIGH> + , <&pro_micro 7 GPIO_ACTIVE_HIGH> + , <&pro_micro 8 GPIO_ACTIVE_HIGH> + ; + + col-gpios + = <&pro_micro 9 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 18 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 14 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 16 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + ; + }; +}; + +&left_encoder { + status = "okay"; +}; + + diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay new file mode 100644 index 00000000..7f281db9 --- /dev/null +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include "splitkb_aurora_lily58.dtsi" + +/ { + chosen { + zmk,kscan = &kscan; + }; + + kscan: kscan { + compatible = "zmk,kscan-gpio-matrix"; + + label = "KSCAN"; + diode-direction = "row2col"; + + row-gpios + = <&pro_micro 21 GPIO_ACTIVE_HIGH> + , <&pro_micro 4 GPIO_ACTIVE_HIGH> + , <&pro_micro 14 GPIO_ACTIVE_HIGH> + , <&pro_micro 16 GPIO_ACTIVE_HIGH> + , <&pro_micro 10 GPIO_ACTIVE_HIGH> + ; + + col-gpios + = <&pro_micro 9 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 8 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 7 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 6 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 5 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + , <&pro_micro 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)> + ; + }; +}; + +&right_encoder { + status = "okay"; +}; + +&default_transform { + col-offset = <6>; +}; From fd65189393a0ed8678859dddad8b8d5506e66a31 Mon Sep 17 00:00:00 2001 From: Manassarn Manoonchai Date: Tue, 3 Jan 2023 23:37:06 +0700 Subject: [PATCH 5/6] Fix formatting --- app/include/zmk/split/bluetooth/service.h | 1 - app/src/split/bluetooth/central.c | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/include/zmk/split/bluetooth/service.h b/app/include/zmk/split/bluetooth/service.h index 9acf120c..b3b3b251 100644 --- a/app/include/zmk/split/bluetooth/service.h +++ b/app/include/zmk/split/bluetooth/service.h @@ -22,7 +22,6 @@ struct zmk_split_run_behavior_payload { char behavior_dev[ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN]; } __packed; - int zmk_split_bt_position_pressed(uint8_t position); int zmk_split_bt_position_released(uint8_t position); int zmk_split_bt_sensor_triggered(uint8_t sensor_number, struct sensor_value value); diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index b6c8b570..eec5b43f 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -379,18 +379,18 @@ static uint8_t split_central_service_discovery_func(struct bt_conn *conn, } #if ZMK_KEYMAP_HAS_SENSORS - memcpy(&sensor_uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID), - sizeof(sensor_uuid)); - sensor_discover_params.uuid = &sensor_uuid.uuid; - sensor_discover_params.start_handle = attr->handle; - sensor_discover_params.end_handle = 0xffff; - sensor_discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; - sensor_discover_params.func = split_central_sensor_desc_discovery_func; + memcpy(&sensor_uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID), + sizeof(sensor_uuid)); + sensor_discover_params.uuid = &sensor_uuid.uuid; + sensor_discover_params.start_handle = attr->handle; + sensor_discover_params.end_handle = 0xffff; + sensor_discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; + sensor_discover_params.func = split_central_sensor_desc_discovery_func; - err = bt_gatt_discover(conn, &sensor_discover_params); - if (err) { - LOG_ERR("Discover failed (err %d)", err); - } + err = bt_gatt_discover(conn, &sensor_discover_params); + if (err) { + LOG_ERR("Discover failed (err %d)", err); + } #endif /* ZMK_KEYMAP_HAS_SENSORS */ return BT_GATT_ITER_STOP; From 1fe89c4c612008976eb6c578f694b547452099fb Mon Sep 17 00:00:00 2001 From: Manassarn Manoonchai Date: Fri, 6 Jan 2023 18:11:50 +0000 Subject: [PATCH 6/6] Add build command --- Makefile | 2 ++ README.md | 4 ++++ build.sh | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 Makefile create mode 100755 build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..9563a681 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +build: build.sh + bash ./build.sh diff --git a/README.md b/README.md index 50cb2817..5e6b096e 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,7 @@ Check out the website to learn more: https://zmk.dev/ You can also come join our [ZMK Discord Server](https://zmk.dev/community/discord/invite) To review features, check out the [feature overview](https://zmk.dev/docs/). ZMK is under active development, and new features are listed with the [enhancement label](https://github.com/zmkfirmware/zmk/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement) in GitHub. Please feel free to add 👍 to the issue description of any requests to upvote the feature. + +## My build command + +For Aurora Lily58 in https://github.com/narze/zmk-config, run `make` in Devcontainer diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..759859b0 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SIDES=(left right) +for side in ${SIDES[@]} +do + west build -b nice_nano_v2 -s /workspaces/zmk/app -d /workspaces/zmk-config/build/aurora_lily58_$side.build -- -DSHIELD="splitkb_aurora_lily58_$side nice_view_adapter nice_view" -DZMK_CONFIG="/workspaces/zmk-config/config" + cp /workspaces/zmk-config/build/aurora_lily58_$side.build/zephyr/zmk.uf2 /workspaces/zmk-config/build/aurora_lily58_$side.uf2 +done