clang-format

This commit is contained in:
krikun98 2021-05-02 13:52:23 +03:00 committed by Alexander Krikun
parent a339a9a082
commit 141a52554a
9 changed files with 111 additions and 149 deletions

View file

@ -10,23 +10,21 @@
#include <zephyr.h> #include <zephyr.h>
#include <zmk/event_manager.h> #include <zmk/event_manager.h>
struct zmk_mouse_state_changed { struct zmk_mouse_state_changed {
uint32_t x; uint32_t x;
uint32_t y; uint32_t y;
bool state; bool state;
int64_t timestamp; int64_t timestamp;
}; };
ZMK_EVENT_DECLARE(zmk_mouse_state_changed); ZMK_EVENT_DECLARE(zmk_mouse_state_changed);
static inline struct zmk_mouse_state_changed_event * static inline struct zmk_mouse_state_changed_event *
zmk_mouse_state_changed_from_encoded(uint32_t encoded, bool pressed, zmk_mouse_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
int64_t timestamp) {
uint32_t x = (encoded & 0xFFFF0000) >> 16; uint32_t x = (encoded & 0xFFFF0000) >> 16;
uint32_t y = encoded & 0x0000FFFF; uint32_t y = encoded & 0x0000FFFF;
return new_zmk_mouse_state_changed((struct zmk_mouse_state_changed){ return new_zmk_mouse_state_changed(
.x = x, .y = y, .state = pressed, .timestamp = timestamp}); (struct zmk_mouse_state_changed){.x = x, .y = y, .state = pressed, .timestamp = timestamp});
} }

View file

@ -20,55 +20,39 @@
static const uint8_t zmk_hid_report_desc[] = { static const uint8_t zmk_hid_report_desc[] = {
/* USAGE_PAGE (Generic Desktop) */ /* USAGE_PAGE (Generic Desktop) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE, HID_USAGE_GD,
HID_USAGE_GD,
/* USAGE (Keyboard) */ /* USAGE (Keyboard) */
HID_LI_USAGE, HID_LI_USAGE, HID_USAGE_GD_KEYBOARD,
HID_USAGE_GD_KEYBOARD,
/* COLLECTION (Application) */ /* COLLECTION (Application) */
HID_MI_COLLECTION, HID_MI_COLLECTION, COLLECTION_APPLICATION,
COLLECTION_APPLICATION,
/* REPORT ID (1) */ /* REPORT ID (1) */
HID_GI_REPORT_ID, HID_GI_REPORT_ID, 0x01,
0x01,
/* USAGE_PAGE (Keyboard/Keypad) */ /* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE, HID_USAGE_KEY,
HID_USAGE_KEY,
/* USAGE_MINIMUM (Keyboard LeftControl) */ /* USAGE_MINIMUM (Keyboard LeftControl) */
HID_LI_USAGE_MIN(1), HID_LI_USAGE_MIN(1), HID_USAGE_KEY_KEYBOARD_LEFTCONTROL,
HID_USAGE_KEY_KEYBOARD_LEFTCONTROL,
/* USAGE_MAXIMUM (Keyboard Right GUI) */ /* USAGE_MAXIMUM (Keyboard Right GUI) */
HID_LI_USAGE_MAX(1), HID_LI_USAGE_MAX(1), HID_USAGE_KEY_KEYBOARD_RIGHT_GUI,
HID_USAGE_KEY_KEYBOARD_RIGHT_GUI,
/* LOGICAL_MINIMUM (0) */ /* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1), HID_GI_LOGICAL_MIN(1), 0x00,
0x00,
/* LOGICAL_MAXIMUM (1) */ /* LOGICAL_MAXIMUM (1) */
HID_GI_LOGICAL_MAX(1), HID_GI_LOGICAL_MAX(1), 0x01,
0x01,
/* REPORT_SIZE (1) */ /* REPORT_SIZE (1) */
HID_GI_REPORT_SIZE, HID_GI_REPORT_SIZE, 0x01,
0x01,
/* REPORT_COUNT (8) */ /* REPORT_COUNT (8) */
HID_GI_REPORT_COUNT, HID_GI_REPORT_COUNT, 0x08,
0x08,
/* INPUT (Data,Var,Abs) */ /* INPUT (Data,Var,Abs) */
HID_MI_INPUT, HID_MI_INPUT, 0x02,
0x02,
/* USAGE_PAGE (Keyboard/Keypad) */ /* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE, HID_USAGE_KEY,
HID_USAGE_KEY,
/* REPORT_SIZE (8) */ /* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE, HID_GI_REPORT_SIZE, 0x08,
0x08,
/* REPORT_COUNT (1) */ /* REPORT_COUNT (1) */
HID_GI_REPORT_COUNT, HID_GI_REPORT_COUNT, 0x01,
0x01,
/* INPUT (Cnst,Var,Abs) */ /* INPUT (Cnst,Var,Abs) */
HID_MI_INPUT, HID_MI_INPUT, 0x03,
0x03,
/* USAGE_PAGE (Keyboard/Keypad) */ /* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE,
@ -98,17 +82,13 @@ static const uint8_t zmk_hid_report_desc[] = {
0x02, 0x02,
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) #elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO)
/* LOGICAL_MINIMUM (0) */ /* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1), HID_GI_LOGICAL_MIN(1), 0x00,
0x00,
/* LOGICAL_MAXIMUM (0xFF) */ /* LOGICAL_MAXIMUM (0xFF) */
HID_GI_LOGICAL_MAX(1), HID_GI_LOGICAL_MAX(1), 0xFF,
0xFF,
/* USAGE_MINIMUM (Reserved) */ /* USAGE_MINIMUM (Reserved) */
HID_LI_USAGE_MIN(1), HID_LI_USAGE_MIN(1), 0x00,
0x00,
/* USAGE_MAXIMUM (Keyboard Application) */ /* USAGE_MAXIMUM (Keyboard Application) */
HID_LI_USAGE_MAX(1), HID_LI_USAGE_MAX(1), 0xFF,
0xFF,
/* REPORT_SIZE (1) */ /* REPORT_SIZE (1) */
HID_GI_REPORT_SIZE, HID_GI_REPORT_SIZE,
0x08, 0x08,
@ -125,17 +105,13 @@ static const uint8_t zmk_hid_report_desc[] = {
/* END_COLLECTION */ /* END_COLLECTION */
HID_MI_COLLECTION_END, HID_MI_COLLECTION_END,
/* USAGE_PAGE (Consumer) */ /* USAGE_PAGE (Consumer) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE, HID_USAGE_CONSUMER,
HID_USAGE_CONSUMER,
/* USAGE (Consumer Control) */ /* USAGE (Consumer Control) */
HID_LI_USAGE, HID_LI_USAGE, HID_USAGE_CONSUMER_CONSUMER_CONTROL,
HID_USAGE_CONSUMER_CONSUMER_CONTROL,
/* Consumer Page */ /* Consumer Page */
HID_MI_COLLECTION, HID_MI_COLLECTION, COLLECTION_APPLICATION,
COLLECTION_APPLICATION,
/* REPORT ID (1) */ /* REPORT ID (1) */
HID_GI_REPORT_ID, HID_GI_REPORT_ID, 0x02,
0x02,
/* USAGE_PAGE (Consumer) */ /* USAGE_PAGE (Consumer) */
HID_GI_USAGE_PAGE, HID_GI_USAGE_PAGE,
HID_USAGE_CONSUMER, HID_USAGE_CONSUMER,
@ -160,18 +136,11 @@ static const uint8_t zmk_hid_report_desc[] = {
0x08, 0x08,
#elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL) #elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL)
/* LOGICAL_MINIMUM (0) */ /* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1), HID_GI_LOGICAL_MIN(1), 0x00,
0x00,
/* LOGICAL_MAXIMUM (0xFFFF) */ /* LOGICAL_MAXIMUM (0xFFFF) */
HID_GI_LOGICAL_MAX(2), HID_GI_LOGICAL_MAX(2), 0xFF, 0xFF, HID_LI_USAGE_MIN(1), 0x00,
0xFF,
0xFF,
HID_LI_USAGE_MIN(1),
0x00,
/* USAGE_MAXIMUM (0xFFFF) */ /* USAGE_MAXIMUM (0xFFFF) */
HID_LI_USAGE_MAX(2), HID_LI_USAGE_MAX(2), 0xFF, 0xFF,
0xFF,
0xFF,
/* INPUT (Data,Ary,Abs) */ /* INPUT (Data,Ary,Abs) */
/* REPORT_SIZE (16) */ /* REPORT_SIZE (16) */
HID_GI_REPORT_SIZE, HID_GI_REPORT_SIZE,
@ -187,42 +156,42 @@ static const uint8_t zmk_hid_report_desc[] = {
/* END COLLECTION */ /* END COLLECTION */
HID_MI_COLLECTION_END, HID_MI_COLLECTION_END,
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x02, /* Usage (Mouse) */ 0x09, 0x02, /* Usage (Mouse) */
0xA1, 0x01, /* Collection (Application) */ 0xA1, 0x01, /* Collection (Application) */
0x85, 0x04, /* Report ID (4) */ 0x85, 0x04, /* Report ID (4) */
0x09, 0x01, /* Usage (Pointer) */ 0x09, 0x01, /* Usage (Pointer) */
0xA1, 0x00, /* Collection (Physical) */ 0xA1, 0x00, /* Collection (Physical) */
0x05, 0x09, /* Usage Page (Button) */ 0x05, 0x09, /* Usage Page (Button) */
0x19, 0x01, /* Usage Minimum (0x01) */ 0x19, 0x01, /* Usage Minimum (0x01) */
0x29, 0x10, /* Usage Maximum (0x10) */ 0x29, 0x10, /* Usage Maximum (0x10) */
0x15, 0x00, /* Logical Minimum (0) */ 0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */ 0x25, 0x01, /* Logical Maximum (1) */
0x95, 0x10, /* Report Count (16) */ 0x95, 0x10, /* Report Count (16) */
0x75, 0x01, /* Report Size (1) */ 0x75, 0x01, /* Report Size (1) */
0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */ 0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x16, 0x01, 0x80, /* Logical Minimum (-32767) */ 0x16, 0x01, 0x80, /* Logical Minimum (-32767) */
0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */ 0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */
0x75, 0x10, /* Report Size (8) */ 0x75, 0x10, /* Report Size (8) */
0x95, 0x02, /* Report Count (2) */ 0x95, 0x02, /* Report Count (2) */
0x09, 0x30, /* Usage (X) */ 0x09, 0x30, /* Usage (X) */
0x09, 0x31, /* Usage (Y) */ 0x09, 0x31, /* Usage (Y) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */ 0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0x15, 0x81, /* Logical Minimum (-127) */ 0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7F, /* Logical Maximum (127) */ 0x25, 0x7F, /* Logical Maximum (127) */
0x75, 0x08, /* Report Count (8) */ 0x75, 0x08, /* Report Count (8) */
0x95, 0x01, /* Report Size (1) */ 0x95, 0x01, /* Report Size (1) */
0x09, 0x38, /* Usage (Wheel) */ 0x09, 0x38, /* Usage (Wheel) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */ 0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0x05, 0x0C, /* Usage Page (Consumer) */ // Horizontal wheel 0x05, 0x0C, /* Usage Page (Consumer) */ // Horizontal wheel
0x0A, 0x38, 0x02, /* Usage (AC Pan) */ 0x0A, 0x38, 0x02, /* Usage (AC Pan) */
0x15, 0x81, /* Logical Minimum (-127) */ 0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7f, /* Logical Maximum (127) */ 0x25, 0x7f, /* Logical Maximum (127) */
0x95, 0x01, /* Report Count (1) */ 0x95, 0x01, /* Report Count (1) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */ 0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0xC0, /* End Collection */ 0xC0, /* End Collection */
0xC0, /* End Collection */ 0xC0, /* End Collection */
}; };
// struct zmk_hid_boot_report // struct zmk_hid_boot_report

View file

@ -38,8 +38,8 @@ static const struct behavior_driver_api behavior_mouse_key_press_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released}; .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
#define KP_INST(n) \ #define KP_INST(n) \
DEVICE_AND_API_INIT(behavior_mouse_key_press_##n, DT_INST_LABEL(n), behavior_mouse_key_press_init, NULL, \ DEVICE_AND_API_INIT( \
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ behavior_mouse_key_press_##n, DT_INST_LABEL(n), behavior_mouse_key_press_init, NULL, NULL, \
&behavior_mouse_key_press_driver_api); APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_mouse_key_press_driver_api);
DT_INST_FOREACH_STATUS_OKAY(KP_INST) DT_INST_FOREACH_STATUS_OKAY(KP_INST)

View file

@ -19,12 +19,11 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_mouse_move_init(const struct device *dev) { return 0; }; static int behavior_mouse_move_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) { struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1); LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
int res = ZMK_EVENT_RAISE(zmk_mouse_state_changed_from_encoded(binding->param1, true, int res = ZMK_EVENT_RAISE(
event.timestamp)); zmk_mouse_state_changed_from_encoded(binding->param1, true, event.timestamp));
return res; return res;
} }
@ -32,8 +31,8 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) { struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1); LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
return ZMK_EVENT_RAISE(zmk_mouse_state_changed_from_encoded(binding->param1, false, return ZMK_EVENT_RAISE(
event.timestamp)); zmk_mouse_state_changed_from_encoded(binding->param1, false, event.timestamp));
} }
static const struct behavior_driver_api behavior_mouse_move_driver_api = { static const struct behavior_driver_api behavior_mouse_move_driver_api = {

View file

@ -41,10 +41,9 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
static const struct behavior_driver_api behavior_mouse_wheel_driver_api = { static const struct behavior_driver_api behavior_mouse_wheel_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released}; .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
#define KP_INST(n) \ #define KP_INST(n) \
DEVICE_AND_API_INIT(behavior_mouse_wheel_##n, DT_INST_LABEL(n), behavior_mouse_wheel_init, NULL, \ DEVICE_AND_API_INIT(behavior_mouse_wheel_##n, DT_INST_LABEL(n), behavior_mouse_wheel_init, \
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ NULL, NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_mouse_wheel_driver_api); &behavior_mouse_wheel_driver_api);
DT_INST_FOREACH_STATUS_OKAY(KP_INST) DT_INST_FOREACH_STATUS_OKAY(KP_INST)

View file

@ -151,7 +151,7 @@ int zmk_endpoints_send_mouse_report() {
switch (current_endpoint) { switch (current_endpoint) {
#if IS_ENABLED(CONFIG_ZMK_USB) #if IS_ENABLED(CONFIG_ZMK_USB)
case ZMK_ENDPOINT_USB: { case ZMK_ENDPOINT_USB: {
int err = zmk_usb_hid_send_report((uint8_t *)mouse_report, sizeof(*mouse_report)); int err = zmk_usb_hid_send_report((uint8_t *)mouse_report, sizeof(*mouse_report));
if (err) { if (err) {
LOG_ERR("FAILED TO SEND OVER USB: %d", err); LOG_ERR("FAILED TO SEND OVER USB: %d", err);
@ -161,7 +161,7 @@ int zmk_endpoints_send_mouse_report() {
#endif /* IS_ENABLED(CONFIG_ZMK_USB) */ #endif /* IS_ENABLED(CONFIG_ZMK_USB) */
#if IS_ENABLED(CONFIG_ZMK_BLE) #if IS_ENABLED(CONFIG_ZMK_BLE)
case ZMK_ENDPOINT_BLE: { case ZMK_ENDPOINT_BLE: {
int err = zmk_hog_send_mouse_report(&mouse_report->body); int err = zmk_hog_send_mouse_report(&mouse_report->body);
if (err) { if (err) {
LOG_ERR("FAILED TO SEND OVER HOG: %d", err); LOG_ERR("FAILED TO SEND OVER HOG: %d", err);

View file

@ -15,8 +15,8 @@ static struct zmk_hid_keyboard_report keyboard_report = {
static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0}}}; static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0}}};
static struct zmk_hid_mouse_report mouse_report = {.report_id = 4, .body = { static struct zmk_hid_mouse_report mouse_report = {
.buttons = 0, .x = 0, .y = 0, .wheel_vert = 0, .wheel_hor = 0}}; .report_id = 4, .body = {.buttons = 0, .x = 0, .y = 0, .wheel_vert = 0, .wheel_hor = 0}};
// Keep track of how often a modifier was pressed. // Keep track of how often a modifier was pressed.
// Only release the modifier if the count is 0. // Only release the modifier if the count is 0.
@ -181,7 +181,6 @@ int zmk_hid_consumer_release(zmk_key_t code) {
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); } void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); }
// Keep track of how often a button was pressed. // Keep track of how often a button was pressed.
// Only release the button if the count is 0. // Only release the button if the count is 0.
static int explicit_button_counts[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; static int explicit_button_counts[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@ -191,10 +190,10 @@ static int16_t curr_y = 0;
static int8_t curr_hor = 0; static int8_t curr_hor = 0;
static int8_t curr_vert = 0; static int8_t curr_vert = 0;
#define SET_MOUSE_BUTTONS(butts) \ #define SET_MOUSE_BUTTONS(butts) \
{ \ { \
mouse_report.body.buttons = butts; \ mouse_report.body.buttons = butts; \
LOG_DBG("Mouse buttons set to 0x%02X", mouse_report.body.buttons); \ LOG_DBG("Mouse buttons set to 0x%02X", mouse_report.body.buttons); \
} }
int zmk_hid_mouse_button_press(zmk_mouse_button_t button) { int zmk_hid_mouse_button_press(zmk_mouse_button_t button) {
@ -238,12 +237,12 @@ int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) {
return 0; return 0;
} }
#define SET_MOUSE_MOVEMENT(coor_x, coor_y) \ #define SET_MOUSE_MOVEMENT(coor_x, coor_y) \
{ \ { \
mouse_report.body.x = coor_x; \ mouse_report.body.x = coor_x; \
LOG_DBG("Mouse movement x set to 0x%02X", mouse_report.body.x); \ LOG_DBG("Mouse movement x set to 0x%02X", mouse_report.body.x); \
mouse_report.body.y = coor_y; \ mouse_report.body.y = coor_y; \
LOG_DBG("Mouse movement y set to 0x%02X", mouse_report.body.y); \ LOG_DBG("Mouse movement y set to 0x%02X", mouse_report.body.y); \
} }
int zmk_hid_mouse_movement_press(uint16_t x, uint16_t y) { int zmk_hid_mouse_movement_press(uint16_t x, uint16_t y) {
@ -260,12 +259,12 @@ int zmk_hid_mouse_movement_release(uint16_t x, uint16_t y) {
return 0; return 0;
} }
#define SET_MOUSE_WHEEL(horiz, vertic) \ #define SET_MOUSE_WHEEL(horiz, vertic) \
{ \ { \
mouse_report.body.wheel_hor = horiz; \ mouse_report.body.wheel_hor = horiz; \
LOG_DBG("Mouse wheel hor set to 0x%02X", mouse_report.body.wheel_hor); \ LOG_DBG("Mouse wheel hor set to 0x%02X", mouse_report.body.wheel_hor); \
mouse_report.body.wheel_vert = vertic; \ mouse_report.body.wheel_vert = vertic; \
LOG_DBG("Mouse wheel vert set to 0x%02X", mouse_report.body.wheel_vert); \ LOG_DBG("Mouse wheel vert set to 0x%02X", mouse_report.body.wheel_vert); \
} }
int zmk_hid_mouse_wheel_press(uint8_t hor, uint8_t vert) { int zmk_hid_mouse_wheel_press(uint8_t hor, uint8_t vert) {

View file

@ -98,8 +98,7 @@ void mouse_timer_cb(struct k_timer *dummy);
K_TIMER_DEFINE(mouse_timer, mouse_timer_cb, NULL); K_TIMER_DEFINE(mouse_timer, mouse_timer_cb, NULL);
void mouse_timer_cb(struct k_timer *dummy) void mouse_timer_cb(struct k_timer *dummy) {
{
if (mouse_is_moving_counter != 0) { if (mouse_is_moving_counter != 0) {
zmk_endpoints_send_mouse_report(); zmk_endpoints_send_mouse_report();
k_timer_start(&mouse_timer, K_MSEC(10), K_NO_WAIT); k_timer_start(&mouse_timer, K_MSEC(10), K_NO_WAIT);
@ -142,14 +141,14 @@ int hid_listener(const zmk_event_t *eh) {
hid_listener_keycode_released(ev); hid_listener_keycode_released(ev);
} }
} else { } else {
const struct zmk_mouse_state_changed *ev = as_zmk_mouse_state_changed(eh); const struct zmk_mouse_state_changed *ev = as_zmk_mouse_state_changed(eh);
if (ev) { if (ev) {
if (ev->state) { if (ev->state) {
hid_listener_mouse_pressed(ev); hid_listener_mouse_pressed(ev);
} else { } else {
hid_listener_mouse_released(ev); hid_listener_mouse_released(ev);
}
} }
}
} }
return 0; return 0;
} }

View file

@ -98,9 +98,8 @@ static ssize_t read_hids_consumer_input_report(struct bt_conn *conn,
sizeof(struct zmk_hid_consumer_report_body)); sizeof(struct zmk_hid_consumer_report_body));
} }
static ssize_t read_hids_mouse_input_report(struct bt_conn *conn, static ssize_t read_hids_mouse_input_report(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const struct bt_gatt_attr *attr, void *buf, void *buf, uint16_t len, uint16_t offset) {
uint16_t len, uint16_t offset) {
struct zmk_hid_mouse_report_body *report_body = &zmk_hid_get_mouse_report()->body; struct zmk_hid_mouse_report_body *report_body = &zmk_hid_get_mouse_report()->body;
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body, return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body,
sizeof(struct zmk_hid_mouse_report_body)); sizeof(struct zmk_hid_mouse_report_body));
@ -154,7 +153,7 @@ BT_GATT_SERVICE_DEFINE(
NULL, &consumer_input), NULL, &consumer_input),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_ENCRYPT, read_hids_mouse_input_report, NULL, NULL), BT_GATT_PERM_READ_ENCRYPT, read_hids_mouse_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref, BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &mouse_input), NULL, &mouse_input),
@ -282,7 +281,7 @@ int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report) {
}; };
K_MSGQ_DEFINE(zmk_hog_mouse_msgq, sizeof(struct zmk_hid_mouse_report_body), K_MSGQ_DEFINE(zmk_hog_mouse_msgq, sizeof(struct zmk_hid_mouse_report_body),
CONFIG_ZMK_BLE_MOUSE_REPORT_QUEUE_SIZE, 4); CONFIG_ZMK_BLE_MOUSE_REPORT_QUEUE_SIZE, 4);
void send_mouse_report_callback(struct k_work *work) { void send_mouse_report_callback(struct k_work *work) {
struct zmk_hid_mouse_report_body report; struct zmk_hid_mouse_report_body report;