Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mouse): Added mouse emulation #778

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b14b024
Preliminary work for mouse click
krikun98 Apr 27, 2021
54ac765
Fine-tuning report, 16 buttons
krikun98 Apr 28, 2021
016256b
Bluetooth tuning, mouse wheel and movement backend
krikun98 Apr 29, 2021
3fb874f
Mouse-related behaviours
Apr 29, 2021
dc2e30d
Add mouse movement event
Apr 29, 2021
ee51487
Continuous mouse movement prototype
Apr 29, 2021
e2b97f1
Add mouse behaviour documentation
May 1, 2021
a339a9a
Cleaning out prototype traces
krikun98 May 2, 2021
141a525
clang-format
krikun98 May 2, 2021
345ef42
Implemented Rinh's suggestion to remove deadlocks
dtsykunov May 2, 2021
58178a7
Raised BLE mouse report queue size
krikun98 May 2, 2021
571e457
Documentation refactor
krikun98 May 2, 2021
0893c76
Add the doc page to the sidebar
krikun98 May 2, 2021
fddadb9
Added new mouse movement macros
krikun98 May 3, 2021
9957b28
Review edits: macro, event override fix, cosmetics
krikun98 May 3, 2021
6de29af
Mouse movement coordinate signedness consistency
krikun98 May 3, 2021
359f35b
Reverted mouse buttons 9-16
krikun98 May 3, 2021
4d08f97
Report refactor (added macros)
krikun98 May 3, 2021
b4ec49e
Simplify binary arithmetic
okke-formsma May 14, 2021
728f42e
Modified mouse_timer_unref to account for errors
krikun98 May 14, 2021
8fc5962
feat(mouse keys): add events, smoothing and acceleration
okke-formsma May 14, 2021
eb089b5
Added dedicated mouse work queue option
krikun98 Aug 26, 2021
96660dc
Simplified tick rate and made it configurable
krikun98 Aug 27, 2021
0bcd44a
Add messages to BLE queue without a waiting interval
krikun98 Aug 30, 2021
992bbc0
Cleanup and acceleration fixes
krikun98 Sep 2, 2021
8088585
Send mouse messages from dedicated thread
krikun98 Sep 21, 2021
cbce1db
Added documentation for new features
krikun98 Sep 23, 2021
ec85b7a
Moved tick duration
krikun98 Sep 23, 2021
2bf5e44
clang-format
krikun98 Sep 23, 2021
ee855f4
prettier
krikun98 Sep 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added dedicated mouse work queue option
  • Loading branch information
krikun98 committed Jan 28, 2022
commit eb089b5f29e9a211496db2d70b88cfef5fac975a
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target_sources(app PRIVATE src/kscan.c)
target_sources(app PRIVATE src/matrix_transform.c)
target_sources(app PRIVATE src/hid.c)
target_sources(app PRIVATE src/mouse/key_listener.c)
target_sources(app PRIVATE src/mouse/main.c)
target_sources(app PRIVATE src/mouse/tick_listener.c)
target_sources(app PRIVATE src/sensors.c)
target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c)
Expand Down
7 changes: 7 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ endif
#Display/LED Options
endmenu

menu "Mouse Options"

rsource "src/mouse/Kconfig"

#Mouse Options
endmenu

menu "Power Management"

config ZMK_IDLE_TIMEOUT
Expand Down
3 changes: 3 additions & 0 deletions app/include/zmk/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ struct vector2d {
float x;
float y;
};

struct k_work_q *zmk_mouse_work_q();
int zmk_mouse_init();
4 changes: 4 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ void main(void) {
#ifdef CONFIG_ZMK_DISPLAY
zmk_display_init();
#endif /* CONFIG_ZMK_DISPLAY */

#ifdef CONFIG_ZMK_MOUSE
zmk_mouse_init();
#endif /* CONFIG_ZMK_MOUSE */
}
34 changes: 34 additions & 0 deletions app/src/mouse/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2021 The ZMK Contributors
# SPDX-License-Identifier: MIT

menuconfig ZMK_MOUSE
bool "Enable ZMK mouse emulation"
default n

if ZMK_MOUSE

choice ZMK_MOUSE_WORK_QUEUE
prompt "Work queue selection for mouse events"
default ZMK_MOUSE_WORK_QUEUE_DEDICATED

config ZMK_MOUSE_WORK_QUEUE_SYSTEM
bool "Use default system work queue for mouse events"

config ZMK_MOUSE_WORK_QUEUE_DEDICATED
bool "Use dedicated work queue for mouse events"

endchoice

if ZMK_MOUSE_WORK_QUEUE_DEDICATED

config ZMK_MOUSE_DEDICATED_THREAD_STACK_SIZE
int "Stack size for dedicated mouse thread/queue"
default 2048

config ZMK_MOUSE_DEDICATED_THREAD_PRIORITY
int "Thread priority for dedicated mouse thread/queue"
default 5

endif # ZMK_MOUSE_WORK_QUEUE_DEDICATED

endif
6 changes: 4 additions & 2 deletions app/src/mouse/key_listener.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 The ZMK Contributors
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
Expand Down Expand Up @@ -37,7 +37,9 @@ static void mouse_tick_timer_handler(struct k_work *work) {

K_WORK_DEFINE(mouse_tick, &mouse_tick_timer_handler);

void mouse_timer_cb(struct k_timer *dummy) { k_work_submit(&mouse_tick); }
void mouse_timer_cb(struct k_timer *dummy) {
k_work_submit_to_queue(zmk_mouse_work_q(), &mouse_tick);
}

K_TIMER_DEFINE(mouse_timer, mouse_timer_cb, mouse_timer_cb);

Expand Down
37 changes: 37 additions & 0 deletions app/src/mouse/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <kernel.h>
#include <init.h>
#include <device.h>
#include <devicetree.h>

#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED)

K_THREAD_STACK_DEFINE(mouse_work_stack_area, CONFIG_ZMK_MOUSE_DEDICATED_THREAD_STACK_SIZE);

static struct k_work_q mouse_work_q;

struct k_work_q *zmk_mouse_work_q() {
return &mouse_work_q;
}

#else

struct k_work_q *zmk_mouse_work_q() {
return &k_sys_work_q;
}

#endif

int zmk_mouse_init() {
#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED)
k_work_q_start(&mouse_work_q, mouse_work_stack_area,
K_THREAD_STACK_SIZEOF(mouse_work_stack_area),
CONFIG_ZMK_MOUSE_DEDICATED_THREAD_PRIORITY);
#endif
return 0;
}