Skip to content

Commit

Permalink
Modify Pete pointer PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Apr 16, 2024
1 parent c09486a commit 11d71c7
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 23 deletions.
5 changes: 5 additions & 0 deletions app/include/zmk/mouse/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,18 @@ void zmk_hid_mouse_movement_set(int16_t x, int16_t y);
void zmk_hid_mouse_scroll_set(int8_t x, int8_t y);
void zmk_hid_mouse_movement_update(int16_t x, int16_t y);
void zmk_hid_mouse_scroll_update(int8_t x, int8_t y);
void zmk_hid_mouse_set(uint8_t buttons, int8_t xDelta, int8_t yDelta, int8_t scrollDelta);
void zmk_hid_mouse_clear(void);

struct zmk_hid_mouse_report *zmk_mouse_hid_get_mouse_report();
#endif // IS_ENABLED(CONFIG_ZMK_MOUSE)

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)

void zmk_hid_ptp_set(struct zmk_ptp_finger finger0, struct zmk_ptp_finger finger1,
struct zmk_ptp_finger finger2, struct zmk_ptp_finger finger3,
struct zmk_ptp_finger finger4, uint8_t contact_count, uint16_t scan_time,
uint8_t buttons);
int zmk_mouse_hid_set_ptp_finger(struct zmk_ptp_finger finger);
void zmk_mouse_hid_ptp_update_scan_time(void);
void zmk_mouse_hid_ptp_clear_lifted_fingers(void);
Expand Down
39 changes: 36 additions & 3 deletions app/src/mouse/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ void zmk_hid_mouse_clear(void) {
memset(&mouse_report.body, 0, sizeof(mouse_report.body));
}

void zmk_hid_mouse_set(uint8_t buttons, int8_t xDelta, int8_t yDelta, int8_t scrollDelta) {
mouse_report.body.buttons = buttons;
mouse_report.body.d_x = xDelta;
mouse_report.body.d_y = yDelta;
mouse_report.body.d_scroll_y = scrollDelta;
}

struct zmk_hid_mouse_report *zmk_mouse_hid_get_mouse_report(void) {
return &mouse_report;
}
Expand All @@ -114,13 +121,35 @@ struct zmk_hid_mouse_report *zmk_mouse_hid_get_mouse_report(void) {

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)

#include <zmk/mouse/trackpad.h>

#define FINGER_INIT(idx, _rest) \
{ .contact_id = idx }

static struct zmk_hid_ptp_report ptp_report = {
.report_id = ZMK_MOUSE_HID_REPORT_ID_DIGITIZER,
};

void zmk_hid_ptp_set(struct zmk_ptp_finger finger0, struct zmk_ptp_finger finger1,
struct zmk_ptp_finger finger2, struct zmk_ptp_finger finger3,
struct zmk_ptp_finger finger4, uint8_t contact_count, uint16_t scan_time,
uint8_t buttons) {
ptp_report.body.fingers[0] = finger0;
ptp_report.body.fingers[1] = finger1;
ptp_report.body.fingers[2] = finger2;
#if CONFIG_ZMK_TRACKPAD_FINGERS > 3
ptp_report.body.fingers[3] = finger3;
#endif
#if CONFIG_ZMK_TRACKPAD_FINGERS > 4
ptp_report.body.fingers[4] = finger4;
#endif
ptp_report.body.contact_count = contact_count;
ptp_report.body.scan_time = scan_time;
ptp_report.body.button1 = buttons & BIT(0);
ptp_report.body.button2 = buttons & BIT(1);
ptp_report.body.button3 = buttons & BIT(2);
}

int zmk_mouse_hid_set_ptp_finger(struct zmk_ptp_finger finger) {
// First try to update existing
for (int i = 0; i < ptp_report.body.contact_count; i++) {
Expand Down Expand Up @@ -190,11 +219,15 @@ struct zmk_hid_ptp_feature_selective_report *zmk_mouse_hid_ptp_get_feature_selec
return &selective_report;
}

void zmk_mouse_hid_ptp_set_feature_selective_report(bool surface_switch, bool button_switch);
void zmk_mouse_hid_ptp_set_feature_selective_report(bool surface_switch, bool button_switch) {
selective_report.body.surface_switch = surface_switch;
selective_report.body.button_switch = button_switch;
LOG_DBG("Setting selective reporting to: %d, %d", surface_switch, button_switch);
}

struct zmk_hid_ptp_feature_mode_report mode_report = {
.report_id = ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_MODE,
.mode = 3,
.mode = 0,
};

struct zmk_hid_ptp_feature_mode_report *zmk_mouse_hid_ptp_get_feature_mode_report() {
Expand Down Expand Up @@ -237,7 +270,7 @@ static struct zmk_hid_ptp_feature_capabilities_report cap_report = {
.body =
{
.max_touches = CONFIG_ZMK_TRACKPAD_FINGERS,
.pad_type = PTP_PAD_TYPE_DEPRESSIBLE,
.pad_type = PTP_PAD_TYPE_NON_CLICKABLE,
},
};

Expand Down
29 changes: 25 additions & 4 deletions app/src/mouse/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static struct hids_report mouse_input = {

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)

#include <zmk/mouse/trackpad.h>

// Windows PTP Collection

static struct hids_report ptp_input = {
Expand Down Expand Up @@ -162,9 +164,19 @@ static ssize_t write_hids_ptp_mode(struct bt_conn *conn, const struct bt_gatt_at
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

uint8_t mode = *(uint8_t *)buf;
LOG_DBG("mode: %d", mode);
// TODO: Do something with it!
int profile = zmk_ble_profile_index(bt_conn_get_dst(conn));
if (profile < 0) {
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
}

struct zmk_endpoint_instance endpoint = {.transport = ZMK_TRANSPORT_BLE,
.ble = {
.profile_index = profile,
}};
uint8_t *report = (uint8_t *)buf;

LOG_DBG("Mode report set ble %d", *report);
zmk_trackpad_set_mode_report(report, endpoint);

return len;
}
Expand All @@ -190,10 +202,19 @@ static ssize_t write_hids_ptp_sel_reporting(struct bt_conn *conn, const struct b
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

int profile = zmk_ble_profile_index(bt_conn_get_dst(conn));
if (profile < 0) {
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
}

struct zmk_hid_ptp_feature_selective_report_body *report =
(struct zmk_hid_ptp_feature_selective_report_body *)buf;
LOG_DBG("Selective: surface: %d, button: %d", report->surface_switch, report->button_switch);
// TODO: Do something with it!
struct zmk_endpoint_instance endpoint = {.transport = ZMK_TRANSPORT_BLE,
.ble = {
.profile_index = profile,
}};
zmk_trackpad_set_selective_report(report->surface_switch, report->button_switch, endpoint);

return len;
}
Expand Down
43 changes: 27 additions & 16 deletions app/src/mouse/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <zmk/keymap.h>
#include <zmk/event_manager.h>

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
#include <zmk/mouse/trackpad.h>
#endif

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

static const struct device *hid_dev;
Expand Down Expand Up @@ -64,6 +68,13 @@ static int get_report_cb(const struct device *dev, struct usb_setup_packet *setu
*data = (uint8_t *)ptp_report;
*len = sizeof(*ptp_report);
break;
case ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_SELECTIVE:
struct zmk_hid_ptp_feature_selective_report *sel_report =
zmk_mouse_hid_ptp_get_feature_selective_report();
*data = (uint8_t *)sel_report;
LOG_DBG("Selective report get %d", 0);
*len = sizeof(*sel_report);
break;
case ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_CAPABILITIES:
LOG_WRN("Get CAPABILITIES");
struct zmk_hid_ptp_feature_capabilities_report *cap_report =
Expand All @@ -78,6 +89,13 @@ static int get_report_cb(const struct device *dev, struct usb_setup_packet *setu
*data = (uint8_t *)cert_report;
*len = sizeof(*cert_report);
break;
case ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_MODE:
struct zmk_hid_ptp_feature_mode_report *mode_report =
zmk_mouse_hid_ptp_get_feature_mode_report();
*data = (uint8_t *)mode_report;
LOG_DBG("mode report get %d", 0);
*len = sizeof(*mode_report);
break;
#endif // IS_ENABLED(CONFIG_ZMK_TRACKPAD)
default:
LOG_ERR("Invalid report ID %d requested", setup->wValue & HID_GET_REPORT_ID_MASK);
Expand All @@ -98,28 +116,17 @@ static int set_report_cb(const struct device *dev, struct usb_setup_packet *setu

switch (setup->wValue & HID_GET_REPORT_ID_MASK) {
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
case ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_CAPABILITIES:
LOG_DBG("PTP Capabilities");
// if (*len != sizeof(struct zmk_hid_led_report)) {
// LOG_ERR("LED set report is malformed: length=%d", *len);
// return -EINVAL;
// } else {
// struct zmk_hid_led_report *report = (struct zmk_hid_led_report *)*data;
// struct zmk_endpoint_instance endpoint = {
// .transport = ZMK_TRANSPORT_USB,
// };
// zmk_hid_indicators_process_report(&report->body, endpoint);
// }
break;
case ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_MODE:
if (*len != sizeof(struct zmk_hid_ptp_feature_mode_report)) {
LOG_ERR("Mode set report is malformed: length=%d", *len);
return -EINVAL;
} else {
struct zmk_hid_ptp_feature_mode_report *report =
(struct zmk_hid_ptp_feature_mode_report *)*data;
LOG_DBG("PTP mode: %d", report->mode);
zmk_mouse_hid_ptp_set_feature_mode(report->mode);
struct zmk_endpoint_instance endpoint = {
.transport = ZMK_TRANSPORT_USB,
};
zmk_trackpad_set_mode_report(&report->mode, endpoint);
}
break;
case ZMK_MOUSE_HID_REPORT_ID_FEATURE_PTP_SELECTIVE:
Expand All @@ -131,7 +138,11 @@ static int set_report_cb(const struct device *dev, struct usb_setup_packet *setu
(struct zmk_hid_ptp_feature_selective_report *)*data;
LOG_DBG("PTP selective: surface: %d, button: %d", report->body.surface_switch,
report->body.button_switch);
// TODO: Do something with it!
struct zmk_endpoint_instance endpoint2 = {
.transport = ZMK_TRANSPORT_USB,
};
zmk_trackpad_set_selective_report(report->body.surface_switch,
report->body.button_switch, endpoint2);
}
break;
#endif // IS_ENABLED(CONFIG_ZMK_TRACKPAD)
Expand Down

0 comments on commit 11d71c7

Please sign in to comment.