Skip to content

Commit

Permalink
Update mouse-ftc for PR1793
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanforbes committed Nov 5, 2023
1 parent c7483c7 commit c1b6924
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/include/zmk/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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) */
Expand Down
3 changes: 3 additions & 0 deletions app/include/zmk/usb_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 2 additions & 3 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/src/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c1b6924

Please sign in to comment.