diff --git a/app/include/zmk/endpoints.h b/app/include/zmk/endpoints.h index 555d14fa2df..082ab729f44 100644 --- a/app/include/zmk/endpoints.h +++ b/app/include/zmk/endpoints.h @@ -71,4 +71,6 @@ struct zmk_endpoint_instance zmk_endpoints_selected(void); bool zmk_endpoints_preferred_transport_is_active(); int zmk_endpoints_send_report(uint16_t usage_page); +#ifdef CONFIG_ZMK_MOUSE int zmk_endpoints_send_mouse_report(); +#endif diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 799599ba809..27d67dfa71f 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -21,6 +21,7 @@ #define HID_REPORT_ID_KEYBOARD 0x01 #define HID_REPORT_ID_LEDS 0x01 #define HID_REPORT_ID_CONSUMER 0x02 +#define HID_REPORT_ID_MOUSE 0x04 static const uint8_t zmk_hid_report_desc[] = { HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), @@ -117,7 +118,7 @@ static const uint8_t zmk_hid_report_desc[] = { /* COLLECTION (Application) */ HID_COLLECTION(HID_COLLECTION_APPLICATION), /* REPORT ID (4) */ - HID_REPORT_ID(0x04), + HID_REPORT_ID(HID_REPORT_ID_MOUSE), /* USAGE (Pointer) */ HID_USAGE(HID_USAGE_GD_POINTER), /* COLLECTION (Physical) */ diff --git a/app/include/zmk/usb_hid.h b/app/include/zmk/usb_hid.h index 777f2b48a03..ce0d4af8f7b 100644 --- a/app/include/zmk/usb_hid.h +++ b/app/include/zmk/usb_hid.h @@ -10,4 +10,7 @@ int zmk_usb_hid_send_keyboard_report(); int zmk_usb_hid_send_consumer_report(); +#ifdef CONFIG_ZMK_MOUSE +int zmk_usb_hid_send_mouse_report(); +#endif void zmk_usb_hid_set_protocol(uint8_t protocol); diff --git a/app/src/endpoints.c b/app/src/endpoints.c index 74f01d80225..adf6bff55b7 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -191,12 +191,10 @@ int zmk_endpoints_send_report(uint16_t usage_page) { #if IS_ENABLED(CONFIG_ZMK_MOUSE) int zmk_endpoints_send_mouse_report() { - struct zmk_hid_mouse_report *mouse_report = zmk_hid_get_mouse_report(); - switch (current_instance.transport) { #if IS_ENABLED(CONFIG_ZMK_USB) case ZMK_TRANSPORT_USB: { - int err = zmk_usb_hid_send_report((uint8_t *)mouse_report, sizeof(*mouse_report)); + int err = zmk_usb_hid_send_mouse_report(); if (err) { LOG_ERR("FAILED TO SEND OVER USB: %d", err); } @@ -206,6 +204,7 @@ int zmk_endpoints_send_mouse_report() { #if IS_ENABLED(CONFIG_ZMK_BLE) case ZMK_TRANSPORT_BLE: { + struct zmk_hid_mouse_report *mouse_report = zmk_hid_get_mouse_report(); int err = zmk_hog_send_mouse_report(&mouse_report->body); if (err) { LOG_ERR("FAILED TO SEND OVER HOG: %d", err); diff --git a/app/src/hog.c b/app/src/hog.c index 3af19913334..1e54db8ad55 100644 --- a/app/src/hog.c +++ b/app/src/hog.c @@ -66,7 +66,7 @@ static struct hids_report consumer_input = { #if IS_ENABLED(CONFIG_ZMK_MOUSE) static struct hids_report mouse_input = { - .id = 0x04, + .id = HID_REPORT_ID_MOUSE, .type = HIDS_INPUT, }; #endif diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index e79245c4f03..c5650fa9a2a 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -76,6 +76,13 @@ static int get_report_cb(const struct device *dev, struct usb_setup_packet *setu *len = sizeof(*report); break; } +#if IS_ENABLED(CONFIG_ZMK_MOUSE) + case HID_REPORT_ID_MOUSE: { + struct zmk_hid_mouse_report *report = zmk_hid_get_mouse_report(); + *data = (uint8_t *)report; + *len = sizeof(*report); + } +#endif /* IS_ENABLED(CONFIG_ZMK_MOUSE) */ default: LOG_ERR("Invalid report ID %d requested", setup->wValue & HID_GET_REPORT_ID_MASK); return -EINVAL; @@ -160,6 +167,13 @@ int zmk_usb_hid_send_consumer_report() { return zmk_usb_hid_send_report((uint8_t *)report, sizeof(*report)); } +#if IS_ENABLED(CONFIG_ZMK_MOUSE) +int zmk_usb_hid_send_mouse_report() { + struct zmk_hid_mouse_report *report = zmk_hid_get_mouse_report(); + return zmk_usb_hid_send_report((uint8_t *)report, sizeof(*report)); +} +#endif /* IS_ENABLED(CONFIG_ZMK_MOUSE) */ + static int zmk_usb_hid_init(const struct device *_arg) { hid_dev = device_get_binding("HID_0"); if (hid_dev == NULL) {