Skip to content

Commit

Permalink
it seems to work?
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Aug 14, 2023
1 parent 0d5c1d8 commit 047c927
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 123 deletions.
4 changes: 4 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ config ZMK_BLE_CONSUMER_REPORT_QUEUE_SIZE
int "Max number of consumer HID reports to queue for sending over BLE"
default 5

config ZMK_BLE_PTP_REPORT_QUEUE_SIZE
int "Max number of trackpad HID reports to queue for sending over BLE"
default 20

config ZMK_BLE_CLEAR_BONDS_ON_START
bool "Configuration that clears all bond information from the keyboard on startup."
default n
Expand Down
1 change: 0 additions & 1 deletion app/boards/arm/bt60/bt60.dts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,5 @@
reg = <0x2C>;
dr-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;
rotate-90;
sleep;
};
};
17 changes: 7 additions & 10 deletions app/drivers/sensor/gen4/gen4.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static int gen4_channel_get(const struct device *dev, enum sensor_channel chan,
}

static int gen4_sample_fetch(const struct device *dev, enum sensor_channel) {
uint8_t packet[54];
uint8_t packet[53];
int ret;
ret = gen4_normal_read(dev, packet, 52);
if (ret < 0) {
Expand All @@ -88,12 +88,12 @@ static int gen4_sample_fetch(const struct device *dev, enum sensor_channel) {

data->finger_id = (packet[3] & 0xFC) >> 2;
LOG_DBG("FINGER ID: %d", data->finger_id);
// Finger data
// Finger data
data->finger.confidence_tip = (packet[3] & 0x03);
data->finger.x = (uint16_t)packet[4] | (uint16_t)(packet[5] << 8);
data->finger.y = (uint16_t)packet[6] | (uint16_t)(packet[7] << 8);

LOG_DBG("Finger palm/detected: %h", data->finger.confidence_tip);
LOG_DBG("Finger palm/detected: %d", data->finger.confidence_tip);
LOG_DBG("Finger x: %d", data->finger.x);
LOG_DBG("Finger y: %d", data->finger.y);

Expand Down Expand Up @@ -126,18 +126,18 @@ static int gen4_trigger_set(const struct device *dev, const struct sensor_trigge

static void gen4_int_cb(const struct device *dev) {
struct gen4_data *data = dev->data;
set_int(dev, false);

LOG_DBG("Gen4 interrupt trigd: %d", 0);
// LOG_DBG("Gen4 interrupt trigd: %d", 0);
data->data_ready_handler(dev, data->data_ready_trigger);
LOG_DBG("Setting int on %d", 0);
set_int(dev, true);
}

#ifdef CONFIG_GEN4_TRIGGER_OWN_THREAD
static void gen4_thread(void *arg) {
const struct device *dev = arg;
struct gen4_data *data = dev->data;

// set_int(dev, false);
while (1) {
k_sem_take(&data->gpio_sem, K_FOREVER);
gen4_int_cb(dev);
Expand All @@ -152,7 +152,7 @@ static void gen4_work_cb(struct k_work *work) {

static void gen4_gpio_cb(const struct device *port, struct gpio_callback *cb, uint32_t pins) {
struct gen4_data *data = CONTAINER_OF(cb, struct gen4_data, gpio_cb);
data->in_int = true;
// set_int(data->dev, false);
LOG_DBG("Interrupt trigd");
#if defined(CONFIG_GEN4_TRIGGER_OWN_THREAD)
k_sem_give(&data->gpio_sem);
Expand Down Expand Up @@ -189,7 +189,6 @@ static int gen4_init(const struct device *dev) {
#endif
set_int(dev, true);
#endif
LOG_WRN("inited");
return 0;
}

Expand All @@ -206,8 +205,6 @@ static const struct sensor_driver_api gen4_driver_api = {
static const struct gen4_config gen4_config_##n = { \
.bus = I2C_DT_SPEC_INST_GET(n), \
.rotate_90 = DT_INST_PROP(0, rotate_90), \
.sleep_en = DT_INST_PROP(0, sleep), \
.no_taps = DT_INST_PROP(0, no_taps), \
COND_CODE_1(CONFIG_GEN4_TRIGGER, (.dr = GPIO_DT_SPEC_GET(DT_DRV_INST(0), dr_gpios), ), \
())}; \
DEVICE_DT_INST_DEFINE(n, gen4_init, NULL, &gen4_data_##n, &gen4_config_##n, POST_KERNEL, \
Expand Down
3 changes: 3 additions & 0 deletions app/include/zmk/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ int zmk_endpoints_toggle();
enum zmk_endpoint zmk_endpoints_selected();

int zmk_endpoints_send_report(uint16_t usage_page);
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
int zmk_endpoints_send_ptp_report();
#endif
64 changes: 28 additions & 36 deletions app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static const uint8_t zmk_hid_report_desc[] = {

/* Windows Precision Touchpad Input Reports */

/* REPORT_ID (0x06) */
/* REPORT_ID (0x05) */
HID_REPORT_ID(ZMK_REPORT_ID_TRACKPAD),
/* USAGE (Finger) */
HID_USAGE(HID_USAGE_DIGITIZERS_FINGER),
Expand All @@ -129,20 +129,24 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_REPORT_SIZE(1),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
// Padding for bytes
HID_REPORT_COUNT(6),
/* INPUT (Cnst,Var,Abs) */
HID_INPUT(0x03),
/* REPORT_COUNT (1) */
HID_REPORT_COUNT(1),
/* REPORT_SIZE (2) */
HID_REPORT_SIZE(2),
/* LOGICAL_MAXIMUM (2) */
HID_LOGICAL_MAX8(2),
/* REPORT_SIZE (3) */
HID_REPORT_SIZE(3),
/* LOGICAL_MAXIMUM (24 */
HID_LOGICAL_MAX8(5),
/* USAGE (Contact Identifier) */
HID_USAGE(HID_USAGE_DIGITIZERS_CONTACT_IDENTIFIER),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
/* REPORT_SIZE (1) */
HID_REPORT_SIZE(1),
/* REPORT_COUNT (4) */
HID_REPORT_COUNT(4),
/* REPORT_COUNT (byte padding) */
HID_REPORT_COUNT(5),
/* INPUT (Cnst,Var,Abs) */
HID_INPUT(0x03),
/* USAGE_PAGE(Generic Desktop) */
Expand Down Expand Up @@ -172,6 +176,8 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_REPORT_COUNT(1),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
// Logimax
HID_LOGICAL_MAX16(0xFF, 0x0F),
/* PHYSICAL_MAXIMUM (Defined in config) */
0x46,
(CONFIG_ZMK_TRACKPAD_PHYSICAL_Y & 0xFF),
Expand All @@ -182,8 +188,6 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_INPUT(0x02),
/* END_COLLECTION */
HID_END_COLLECTION,
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
/* USAGE_PAGE (Digitizers) */
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
/* USAGE (Contact count) */
Expand All @@ -196,22 +200,6 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_REPORT_SIZE(8),
/* INPUT(Data, Var, Abs) */
HID_INPUT(0x02),
/* USAGE_PAGE (Button) */
HID_USAGE_PAGE(HID_USAGE_BUTTON),
/* USAGE (Button 1) */
HID_USAGE(0x01),
/* LOGICAL_MAXIMUM (1) */
HID_LOGICAL_MAX8(1),
/* REPORT_SIZE (1) */
HID_REPORT_SIZE(1),
/* REPORT_COUNT (1) */
HID_REPORT_COUNT(1),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
/* REPORT_COUNT (7) */
HID_REPORT_COUNT(7),
/* INPUT (Cnst, Var, Abs) */
HID_INPUT(0x03),

/* Device Capabilities Feature Report */

Expand Down Expand Up @@ -265,7 +253,7 @@ static const uint8_t zmk_hid_report_desc[] = {
/* HID_COLLECTION */
HID_COLLECTION(HID_COLLECTION_APPLICATION),
/* REPORT_ID (Feature 0x09) */
HID_REPORT_ID(ZMK_REPORT_ID_FEATURE_CONFIGURATION),
HID_REPORT_ID(ZMK_REPORT_ID_FEATURE_PTP_CONFIGURATION),
/* USAGE (Finger) */
HID_USAGE(HID_USAGE_DIGITIZERS_FINGER),
/* COLLECTION (Logical) */
Expand Down Expand Up @@ -350,7 +338,7 @@ struct zmk_hid_consumer_report {
struct zmk_hid_consumer_report_body body;
} __packed;

#ifdef IS_ENABLED(CONFIG_ZMK_TRACKPAD)
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
// Reporting structure from osmakari
// Report for single finger
struct zmk_ptp_finger {
Expand All @@ -364,16 +352,21 @@ struct zmk_ptp_finger {
uint16_t y;
} __packed;

// Report containing finger data
struct zmk_ptp_report {
// 0x05
uint8_t report_id;
struct zmk_hid_ptp_report_body {
// Finger reporting
struct zmk_ptp_finger fingers[CONFIG_ZMK_TRACKPAD_MAX_FINGERS];
struct zmk_ptp_finger finger;
// Contact count
uint8_t contact_count;
// Buttons
uint8_t buttons;
// uint8_t buttons;
} __packed;

// Report containing finger data
struct zmk_hid_ptp_report {
// 0x05
uint8_t report_id;
struct zmk_hid_ptp_report_body body;

} __packed;

// Feature report for configuration
Expand All @@ -387,7 +380,7 @@ struct zmk_ptp_feature_configuration {

// Feature report for certification
struct zmk_ptp_feature_certification {
uint8_t[256] ptphqa_blob;
uint8_t ptphqa_blob[256];
} __packed;

#define PTP_PAD_TYPE_DEPRESSIBLE 0x00
Expand Down Expand Up @@ -433,8 +426,7 @@ int zmk_hid_release(uint32_t usage);
bool zmk_hid_is_pressed(uint32_t usage);

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
void zmk_hid_ptp_set(struct zmk_ptp_finger fingers[CONFIG_ZMK_TRACKPAD_MAX_FINGERS],
uint8_t contact_count, uint8_t buttons);
void zmk_hid_ptp_set(struct zmk_ptp_finger finger, uint8_t contact_count, uint8_t buttons);
#endif

struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
Expand Down
1 change: 1 addition & 0 deletions app/include/zmk/hog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ int zmk_hog_init();

int zmk_hog_send_keyboard_report(struct zmk_hid_keyboard_report_body *body);
int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *body);
int zmk_hog_send_ptp_report(struct zmk_hid_ptp_report_body *body);
2 changes: 1 addition & 1 deletion app/include/zmk/trackpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include <zephyr.h>
#include <zephyr/kernel.h>

typedef uint8_t zmk_trackpad_finger_contacts_t;

Expand Down
39 changes: 39 additions & 0 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,45 @@ int zmk_endpoints_send_report(uint16_t usage_page) {
}
}

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
int zmk_endpoints_send_ptp_report() {

// LOG_DBG("Trying to sent report %d", 0);

struct zmk_hid_ptp_report *ptp_report = zmk_hid_get_ptp_report();

switch (current_endpoint) {
#if IS_ENABLED(CONFIG_ZMK_USB)
case ZMK_ENDPOINT_USB: {
int err = zmk_usb_hid_send_report((uint8_t *)ptp_report, sizeof(*ptp_report));
if (err) {
LOG_ERR("FAILED TO SEND OVER USB: %d", err);
}
return err;
}
#endif /* IS_ENABLED(CONFIG_ZMK_USB) */

#if IS_ENABLED(CONFIG_ZMK_BLE)
case ZMK_ENDPOINT_BLE: {
#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED)
int err = zmk_hog_send_ptp_report_direct(&ptp_report->body);
#else
int err = zmk_hog_send_ptp_report(&ptp_report->body);
#endif
if (err) {
LOG_ERR("FAILED TO SEND OVER HOG: %d", err);
}
return err;
}
#endif /* IS_ENABLED(CONFIG_ZMK_BLE) */

default:
LOG_ERR("Unsupported endpoint %d", current_endpoint);
return -ENOTSUP;
}
}
#endif

#if IS_ENABLED(CONFIG_SETTINGS)

static int endpoints_handle_set(const char *name, size_t len, settings_read_cb read_cb,
Expand Down
62 changes: 24 additions & 38 deletions app/src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,11 @@ static struct zmk_hid_keyboard_report keyboard_report = {
static struct zmk_hid_consumer_report consumer_report = {.report_id = 2, .body = {.keys = {0}}};

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
const uint8_t PTPHQA_BLOB[] = {
0xfc, 0x28, 0xfe, 0x84, 0x40, 0xcb, 0x9a, 0x87, 0x0d, 0xbe, 0x57, 0x3c, 0x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09, 0x78, 0x62, 0xbc, 0x80, 0xe3, 0x0f, 0xbd, 0x65, 0x20, 0x08, 0x13,
0xc1, 0xe2, 0xee, 0x53, 0x2d, 0x86, 0x7e, 0xa7, 0x5a, 0xc5, 0xd3, 0x7d, 0x98, 0xbe, 0x31, 0x48,
0x1f, 0xfb, 0xda, 0xaf, 0xa2, 0xa8, 0x6a, 0x89, 0xd6, 0xbf, 0xf2, 0xd3, 0x32, 0x2a, 0x9a, 0xe4,
0xcf, 0x17, 0xb7, 0xb8, 0xf4, 0xe1, 0x33, 0x08, 0x24, 0x8b, 0xc4, 0x43, 0xa5, 0xe5, 0x24, 0xc2};

// Report containing finger data
struct zmk_hid_ptp_report ptp_report = {
.report_id = ZMK_REPORT_ID_TOUCHPAD,
.fingers = {{.confidence_tip = 0, .contact_id = 0, .x = 0, .y = 0},
{.confidence_tip = 0, .contact_id = 0, .x = 0, .y = 0},
{.confidence_tip = 0, .contact_id = 0, .x = 0, .y = 0}
#if (CONFIG_ZMK_TRACKPAD_MAX_FINGERS > 3)
,
{.confidence_tip = 0, .contact_id = 0, .x = 0, .y = 0}
#endif
#if (CONFIG_ZMK_TRACKPAD_MAX_FINGERS > 4)
,
{.confidence_tip = 0, .contact_id = 0, .x = 0, .y = 0}
#endif },
.scan_time = 0,
.contact_count = 0,
.buttons = 0};
.report_id = ZMK_REPORT_ID_TRACKPAD,
.body = {.finger = {.confidence_tip = 0, .contact_id = 0, .x = 0, .y = 0}, .contact_count = 0}};

// Feature report for configuration
struct zmk_ptp_feature_configuration ptp_feature_configuration = {
Expand All @@ -60,7 +30,26 @@ struct zmk_ptp_feature_configuration ptp_feature_configuration = {
.selective_reporting = 0};

// Feature report for ptphqa
struct zmk_ptp_feature_certification ptp_feature_certification = {.ptphqa_blob = PTPHQA_BLOB};
struct zmk_ptp_feature_certification ptp_feature_certification = {
.ptphqa_blob = {
0xfc, 0x28, 0xfe, 0x84, 0x40, 0xcb, 0x9a, 0x87, 0x0d, 0xbe, 0x57,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
0x1f, 0x09, 0x78, 0x62, 0xbc, 0x80, 0xe3, 0x0f, 0xbd, 0x65, 0x20, 0x08, 0x13, 0xc1, 0xe2,
0xee, 0x53, 0x2d, 0x86, 0x7e, 0xa7, 0x5a, 0xc5, 0xd3, 0x7d, 0x98, 0xbe, 0x31, 0x48, 0x1f,
0xfb, 0xda, 0xaf, 0xa2, 0xa8, 0x6a, 0x89, 0xd6, 0xbf, 0xf2, 0xd3, 0x32, 0x2a, 0x9a, 0xe4,
0xcf, 0x17, 0xb7, 0xb8, 0xf4, 0xe1, 0x33, 0x08, 0x24, 0x8b, 0xc4, 0x43, 0xa5, 0xe5, 0x24,
0xc2}};

// Feature report for device capabilities
struct zmk_ptp_feature_capabilities ptp_feature_capabilities = {
Expand Down Expand Up @@ -315,12 +304,9 @@ bool zmk_hid_is_pressed(uint32_t usage) {
return false;
}
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
void zmk_hid_ptp_set(struct zmk_ptp_finger fingers[CONFIG_ZMK_TRACKPAD_MAX_FINGERS],
uint8_t contact_count, uint8_t buttons) {
memcpy(ptp_report.body.fingers, fingers,
sizeof(struct zmk_ptp_finger) * CONFIG_ZMK_TRACKPAD_MAX_FINGERS);
void zmk_hid_ptp_set(struct zmk_ptp_finger finger, uint8_t contact_count, uint8_t buttons) {
ptp_report.body.finger = finger;
ptp_report.body.contact_count = contact_count;
ptp_report.body.buttons = buttons;
}
#endif

Expand Down
Loading

0 comments on commit 047c927

Please sign in to comment.