Skip to content

Commit

Permalink
added transfer queue sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
hlord2000 committed Jul 24, 2024
1 parent 3379559 commit cb47217
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 12 deletions.
38 changes: 38 additions & 0 deletions app/boards/shields/jazz_hands/jazz_hands.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define STD_123_L 1
#define CMD_L 2
#define FN_L 3
#define MOUSE_L 4

#define LP 0
#define LR 1
Expand Down Expand Up @@ -221,6 +222,7 @@
keymap {
compatible = "zmk,keymap";

/*
standard_layer {
bindings = <
&kp A &kp S &kp E &kp T &kp N &kp I &kp O &kp P
Expand Down Expand Up @@ -249,6 +251,42 @@
>;
};

mouse_layer {
bindings = <
&none &none &none &none &none &none &none &none
&none &none
>;
};
*/

standard_layer {
bindings = <
&to CMD_L &kp S &kp E &kp T &kp N &kp I &kp O &kp P
&kp LSHIFT &kp SPACE
>;
};

standard_123_layer {
bindings = <
&kp N1 &kp N2 &kp N3 &kp N4 &kp N7 &kp N8 &kp N9 &kp N0
&trans &trans
>;
};

cmd_layer {
bindings = <
&to STD_L &sk LSFT &sk LALT &sk LGUI &kp LEFT &kp DOWN &kp UP &kp RIGHT
&kp PGDN &kp PGUP
>;
};

fn_layer {
bindings = <
&none &none &none &bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3
&trans &trans
>;
};

mouse_layer {
bindings = <
&none &none &none &none &none &none &none &none
Expand Down
6 changes: 3 additions & 3 deletions app/boards/shields/jazz_hands/jazz_hands_left.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ CONFIG_INPUT_IMU_REPORT_INTERVAL_MS=10
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=16384

CONFIG_FPU=y
CONFIG_ZSL=y
CONFIG_ZSL_SINGLE_PRECISION=y
CONFIG_ZSL_PLATFORM_OPT=2

CONFIG_INPUT=y
CONFIG_INPUT_LOG_LEVEL_INF=y
Expand All @@ -55,3 +52,6 @@ CONFIG_ZMK_BLE_CONSUMER_REPORT_QUEUE_SIZE=100
#DEBUG
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=16384
CONFIG_ZMK_BLE_EXPERIMENTAL_CONN=y

CONFIG_ZMK_SPLIT_BLE_CENTRAL_DATA_XFER_STACK_SIZE=1024
CONFIG_ZMK_SPLIT_BLE_CENTRAL_DATA_XFER_QUEUE_SIZE=16
6 changes: 3 additions & 3 deletions app/boards/shields/jazz_hands/jazz_hands_right.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ CONFIG_INPUT_IMU_REPORT_INTERVAL_MS=10
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=16384

CONFIG_FPU=y
CONFIG_ZSL=y
CONFIG_ZSL_SINGLE_PRECISION=y
CONFIG_ZSL_PLATFORM_OPT=2

CONFIG_INPUT=y
CONFIG_INPUT_LOG_LEVEL_INF=y
Expand All @@ -53,3 +50,6 @@ CONFIG_ZMK_BLE_CONSUMER_REPORT_QUEUE_SIZE=100
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096
CONFIG_ZMK_BLE_EXPERIMENTAL_CONN=y
CONFIG_ZMK_SETTINGS_RESET_ON_START=y

CONFIG_ZMK_SPLIT_BLE_CENTRAL_DATA_XFER_STACK_SIZE=1024
CONFIG_ZMK_SPLIT_BLE_CENTRAL_DATA_XFER_QUEUE_SIZE=16
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ K_WORK_DEFINE(layer_send_state_work, zmk_layer_send_state);

static int layer_state_changed_listener(const zmk_event_t *eh) {
index = zmk_keymap_highest_layer_active();
k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &layer_indicator_update_work);
k_work_submit(&layer_send_state_work);
k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &layer_indicator_update_work);
return 0;
}

Expand Down
10 changes: 10 additions & 0 deletions app/include/zmk/events/mouse_movement_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <zmk/event_manager.h>

struct mouse_movement_event {
uint8_t axis;
int8_t movement;
};

ZMK_EVENT_DECLARE(mouse_movement_event);
1 change: 1 addition & 0 deletions app/include/zmk/split/bluetooth/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ int zmk_split_bt_position_released(uint8_t position);
int zmk_split_bt_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size);
int zmk_split_bt_mouse_movement(uint8_t axis, int8_t movement);
19 changes: 19 additions & 0 deletions app/src/mouse/input_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/mouse/types.h>
#include <zmk/mouse/hid.h>

#if !CONFIG_ZMK_SPLIT_ROLE_CENTRAL
#include <zmk/split/bluetooth/service.h>
#include <zmk/split/bluetooth/central.h>
#include <zmk/events/mouse_movement_event.h>
#endif

#define ONE_IF_DEV_OK(n) \
COND_CODE_1(DT_NODE_HAS_STATUS(DT_INST_PHANDLE(n, device), okay), (1 +), (0 +))

Expand Down Expand Up @@ -200,6 +206,19 @@ static void input_handler(const struct input_listener_config *config,
}
}

#if !CONFIG_ZMK_SPLIT_ROLE_CENTRAL
static int mouse_listener_callback(const zmk_event_t *eh) {
const struct mouse_movement_event *event = (struct mouse_movement_event *)eh;
if (event) {
return zmk_split_bt_mouse_movement(event->axis, event->movement);
}
return 0;
}

ZMK_LISTENER(mouse_listener, mouse_listener_callback);
ZMK_SUBSCRIPTION(mouse_listener, mouse_movement_event);
#endif

#endif // VALID_LISTENER_COUNT > 0

#define IL_INST(n) \
Expand Down
50 changes: 45 additions & 5 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,54 @@ int zmk_split_bt_sensor_triggered(uint8_t sensor_index,
#endif /* ZMK_KEYMAP_HAS_SENSORS */

#if IS_ENABLED(CONFIG_ZMK_MOUSE)
int zmk_split_bt_mouse_movement_notify(const struct mouse_event *event) {
int err = bt_gatt_notify(NULL, &split_svc.attrs[10], event, sizeof(*event));
K_MSGQ_DEFINE(mouse_movement_msgq, sizeof(struct mouse_event),
CONFIG_ZMK_SPLIT_BLE_PERIPHERAL_POSITION_QUEUE_SIZE, 4);

void send_mouse_movement_callback(struct k_work *work) {
while (k_msgq_get(&mouse_movement_msgq, &last_mouse_event, K_NO_WAIT) == 0) {
#if ZMK_KEYMAP_HAS_SENSORS
int err = bt_gatt_notify(NULL, &split_svc.attrs[9], &last_mouse_event,
sizeof(last_mouse_event));
#else
int err = bt_gatt_notify(NULL, &split_svc.attrs[7], &last_mouse_event,
sizeof(last_mouse_event));
#endif
if (err) {
LOG_DBG("Error notifying mouse movement %d", err);
}
}
};

K_WORK_DEFINE(service_mouse_movement_notify_work, send_mouse_movement_callback);

int send_mouse_movement(struct mouse_event ev) {
int err = k_msgq_put(&mouse_movement_msgq, &ev, K_MSEC(100));
if (err) {
LOG_ERR("Failed to notify mouse movement (err %d)", err);
switch (err) {
case -EAGAIN: {
LOG_WRN("Mouse movement message queue full, popping first message and queueing again");
struct mouse_event discarded_event;
k_msgq_get(&mouse_movement_msgq, &discarded_event, K_NO_WAIT);
return send_mouse_movement(ev);
}
default:
LOG_WRN("Failed to queue mouse movement to send (%d)", err);
return err;
}
}
return err;

k_work_submit_to_queue(&service_work_q, &service_mouse_movement_notify_work);
return 0;
}
#endif

int zmk_split_bt_mouse_movement(uint8_t axis, int8_t movement) {
struct mouse_event ev = {
.axis = axis,
.movement = movement
};
return send_mouse_movement(ev);
}
#endif /* CONFIG_ZMK_MOUSE */

static int service_init(void) {
static const struct k_work_queue_config queue_config = {
Expand Down

0 comments on commit cb47217

Please sign in to comment.