Skip to content

Commit

Permalink
Multi touch kind of works
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Aug 14, 2023
1 parent 047c927 commit 25eff5c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
8 changes: 8 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ config ZMK_TRACKPAD_PHYSICAL_Y
int "Maximum Y size of trackpad in 0.1cm increments"
default 600

config ZMK_TRACKPAD_LOGICAL_X
int "Maximum X coordinate value trackpad can report"
default 4095

config ZMK_TRACKPAD_LOGICAL_Y
int "Maximum Y coordinate value trackpad can report"
default 4095


if ZMK_TRACKPAD

Expand Down
4 changes: 3 additions & 1 deletion app/boards/arm/bt60/bt60_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ CONFIG_PINCTRL=y
CONFIG_ZMK_USB_LOGGING=y

CONFIG_ZMK_TRACKPAD=y
CONFIG_ZMK_TRACKPAD_TICK_DURATION=4
CONFIG_ZMK_TRACKPAD_PHYSICAL_X=650
CONFIG_ZMK_TRACKPAD_PHYSICAL_Y=1065
CONFIG_ZMK_TRACKPAD_LOGICAL_X=700
CONFIG_ZMK_TRACKPAD_LOGICAL_Y=1200
CONFIG_I2C=y
CONFIG_GEN4=y
CONFIG_GEN4_TRIGGER_GLOBAL_THREAD=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y


CONFIG_USE_DT_CODE_PARTITION=y
Expand Down
8 changes: 5 additions & 3 deletions app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_INPUT(0x00),
HID_END_COLLECTION,
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
// PTP Touchpad HID from osmakari
// PTP Touchpad HID with inspiration from osmakari
/* USAGE_PAGE (Digitizers) */
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
/* USAGE (Touch Pad) */
Expand Down Expand Up @@ -154,7 +154,8 @@ static const uint8_t zmk_hid_report_desc[] = {
/* LOGICAL_MINIMUM (0) */
HID_LOGICAL_MIN8(0),
/* LOGICAL_MAXIMUM (4095) */
HID_LOGICAL_MAX16(0xFF, 0x0F),
HID_LOGICAL_MAX16((CONFIG_ZMK_TRACKPAD_LOGICAL_X & 0xFF),
((CONFIG_ZMK_TRACKPAD_LOGICAL_X >> 8) & 0xFF)),
/* REPORT_SIZE (16) */
HID_REPORT_SIZE(16),
/* UNIT_EXPONENT (-2) */
Expand All @@ -177,7 +178,8 @@ static const uint8_t zmk_hid_report_desc[] = {
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
// Logimax
HID_LOGICAL_MAX16(0xFF, 0x0F),
HID_LOGICAL_MAX16((CONFIG_ZMK_TRACKPAD_LOGICAL_Y & 0xFF),
((CONFIG_ZMK_TRACKPAD_LOGICAL_Y >> 8) & 0xFF)),
/* PHYSICAL_MAXIMUM (Defined in config) */
0x46,
(CONFIG_ZMK_TRACKPAD_PHYSICAL_Y & 0xFF),
Expand Down
18 changes: 11 additions & 7 deletions app/src/trackpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
const struct device *trackpad = DEVICE_DT_GET(DT_INST(0, cirque_gen4));

static zmk_trackpad_finger_contacts_t present_contacts = 0;
static bool changes = 0;
static zmk_trackpad_finger_contacts_t contacts_to_send = 0;

static struct zmk_ptp_finger fingers[CONFIG_ZMK_TRACKPAD_MAX_FINGERS];

Expand Down Expand Up @@ -51,16 +51,20 @@ static void handle_trackpad(const struct device *dev, const struct sensor_trigge
fingers[id.val1].contact_id = id.val1;
fingers[id.val1].x = x.val1;
fingers[id.val1].y = y.val1;
changes = true;
contacts_to_send |= BIT(id.val1);
}

static void zmk_trackpad_tick(struct k_work *work) {
if (changes) {
if (contacts_to_send) {
// LOG_DBG("Trackpad sendy thing trigd %d", 0);

zmk_hid_ptp_set(fingers[0], present_contacts, 0);
zmk_endpoints_send_ptp_report();
changes = false;
for (int i = 0; i < CONFIG_ZMK_TRACKPAD_MAX_FINGERS; i++)
if (contacts_to_send & BIT(i)) {
LOG_DBG("Trackpad sendy thing trigd %d", i);
zmk_hid_ptp_set(fingers[i], present_contacts, 0);
zmk_endpoints_send_ptp_report();
contacts_to_send &= !BIT(i);
return;
}
}
}

Expand Down

0 comments on commit 25eff5c

Please sign in to comment.