Skip to content

Commit

Permalink
tuning and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Aug 14, 2023
1 parent 25eff5c commit d0692a9
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ if ZMK_TRACKPAD_WORK_QUEUE_DEDICATED

config ZMK_TRACKPAD_DEDICATED_THREAD_STACK_SIZE
int "Stack size for dedicated trackpad thread/queue"
default 2048
default 8192

config ZMK_TRACKPAD_DEDICATED_THREAD_PRIORITY
int "Thread priority for dedicated trackpad thread/queue"
Expand Down
3 changes: 2 additions & 1 deletion app/boards/arm/bt60/bt60.keymap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/outputs.h>

/ {
keymap {
Expand All @@ -14,7 +15,7 @@
// | CTL | WIN | ALT | SPACE | ALT | MO(1) | <- | v | -> |
// ------------------------------------------------------------------------------------------
bindings = <
&kp ESC
&out OUT_TOG
>;
};
};
Expand Down
6 changes: 1 addition & 5 deletions app/boards/arm/bt60/bt60_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CONFIG_GPIO=y

CONFIG_PINCTRL=y

CONFIG_ZMK_USB_LOGGING=y
#CONFIG_ZMK_USB_LOGGING=y

CONFIG_ZMK_TRACKPAD=y
CONFIG_ZMK_TRACKPAD_TICK_DURATION=4
Expand All @@ -34,10 +34,6 @@ CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y

CONFIG_LOG_BUFFER_SIZE=38000
CONFIG_USB_CDC_ACM_RINGBUF_SIZE=38000
CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS=8000

CONFIG_BT_CTLR_TX_PWR_PLUS_8=y

CONFIG_BUILD_OUTPUT_UF2=y
2 changes: 1 addition & 1 deletion app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,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 finger, uint8_t contact_count, uint8_t buttons);
void zmk_hid_ptp_set(struct zmk_ptp_finger finger, uint8_t contact_count);
#endif

struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
Expand Down
3 changes: 3 additions & 0 deletions app/include/zmk/hog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ 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);
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
int zmk_hog_send_ptp_report(struct zmk_hid_ptp_report_body *body);
int zmk_hog_send_ptp_report_direct(struct zmk_hid_ptp_report_body *report);
#endif
2 changes: 1 addition & 1 deletion app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int zmk_endpoints_send_ptp_report() {

#if IS_ENABLED(CONFIG_ZMK_BLE)
case ZMK_ENDPOINT_BLE: {
#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED)
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD_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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ 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 finger, uint8_t contact_count, uint8_t buttons) {
void zmk_hid_ptp_set(struct zmk_ptp_finger finger, uint8_t contact_count) {
ptp_report.body.finger = finger;
ptp_report.body.contact_count = contact_count;
}
Expand Down
53 changes: 29 additions & 24 deletions app/src/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ static ssize_t read_hids_consumer_input_report(struct bt_conn *conn,
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body,
sizeof(struct zmk_hid_consumer_report_body));
}

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
static ssize_t read_hids_trackpad_input_report(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset) {
struct zmk_hid_ptp_report_body *report_body = &zmk_hid_get_ptp_report()->body;
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body,
sizeof(struct zmk_hid_consumer_report_body));
sizeof(struct zmk_hid_ptp_report_body));
}
#endif
// TODO
/*
static ssize_t read_hids_trackpad_capabilities_input_report(struct bt_conn *conn,
Expand Down Expand Up @@ -208,31 +209,33 @@ BT_GATT_SERVICE_DEFINE(
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &consumer_input),
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_ENCRYPT, read_hids_trackpad_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &trackpad_report), /*
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &consumer_input),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &consumer_input),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &consumer_input),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &consumer_input),*/
NULL, &trackpad_report),
#endif /* \
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL), \
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), \
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref, \
NULL, &consumer_input), \
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL), \
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), \
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref, \
NULL, &consumer_input), \
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL), \
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), \
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref, \
NULL, &consumer_input), \
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
BT_GATT_PERM_READ_ENCRYPT, read_hids_consumer_input_report, NULL, NULL), \
BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), \
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref, \
NULL, &consumer_input),*/
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_CTRL_POINT, BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_WRITE, NULL, write_ctrl_point, &ctrl_point));

Expand Down Expand Up @@ -355,6 +358,7 @@ int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report) {
return 0;
};

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
K_MSGQ_DEFINE(zmk_hog_ptp_msgq, sizeof(struct zmk_hid_ptp_report_body),
CONFIG_ZMK_BLE_PTP_REPORT_QUEUE_SIZE, 4);

Expand Down Expand Up @@ -388,7 +392,7 @@ int zmk_hog_send_ptp_report(struct zmk_hid_ptp_report_body *report) {
if (err) {
switch (err) {
case -EAGAIN: {
LOG_WRN("Mouse message queue full, dropping report");
LOG_WRN("PTP message queue full, dropping report");
return err;
}
default:
Expand Down Expand Up @@ -424,6 +428,7 @@ int zmk_hog_send_ptp_report_direct(struct zmk_hid_ptp_report_body *report) {

return 0;
};
#endif

int zmk_hog_init(const struct device *_arg) {
static const struct k_work_queue_config queue_config = {.name = "HID Over GATT Send Work"};
Expand Down
2 changes: 1 addition & 1 deletion app/src/trackpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void zmk_trackpad_tick(struct k_work *work) {
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_hid_ptp_set(fingers[i], present_contacts);
zmk_endpoints_send_ptp_report();
contacts_to_send &= !BIT(i);
return;
Expand Down

0 comments on commit d0692a9

Please sign in to comment.