Skip to content

Commit

Permalink
BLE PTP
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Mar 31, 2024
1 parent 89c3762 commit 4a42fa2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
43 changes: 22 additions & 21 deletions app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_USAGE(0x42),
HID_REPORT_COUNT(2),
HID_REPORT_SIZE(1),
HID_INPUT(0x02),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
// Byte Padding
HID_REPORT_COUNT(6),
HID_INPUT(0x03),
Expand All @@ -216,7 +216,7 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_REPORT_COUNT(1),
HID_REPORT_SIZE(3),
HID_LOGICAL_MAX8(5),
HID_INPUT(0x02),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
// Byte padding
HID_REPORT_SIZE(1),
HID_REPORT_COUNT(5),
Expand Down Expand Up @@ -244,7 +244,7 @@ static const uint8_t zmk_hid_report_desc[] = {
(CONFIG_ZMK_TRACKPAD_PHYSICAL_X & 0xFF),
((CONFIG_ZMK_TRACKPAD_PHYSICAL_X >> 8) & 0xFF),
HID_REPORT_COUNT(1),
HID_INPUT(0x02),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),

// Y Usage
HID_USAGE(HID_USAGE_GD_Y),
Expand All @@ -255,12 +255,9 @@ static const uint8_t zmk_hid_report_desc[] = {
0x46,
(CONFIG_ZMK_TRACKPAD_PHYSICAL_Y & 0xFF),
((CONFIG_ZMK_TRACKPAD_PHYSICAL_Y >> 8) & 0xFF),
HID_INPUT(0x02),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
HID_END_COLLECTION,

HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
// Scan Time
HID_USAGE(HID_USAGE_DIGITIZERS_SCAN_TIME),
// Exponent (-4)
0x55,
0x0C,
Expand All @@ -283,7 +280,10 @@ static const uint8_t zmk_hid_report_desc[] = {

HID_REPORT_SIZE(16),
HID_REPORT_COUNT(1),
HID_INPUT(0x02),
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
// Scan Time
HID_USAGE(HID_USAGE_DIGITIZERS_SCAN_TIME),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
// Contact Count
HID_USAGE(HID_USAGE_DIGITIZERS_CONTACT_COUNT),
// Physical Maximum (0)
Expand All @@ -293,7 +293,7 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_LOGICAL_MAX8(0x05),
HID_REPORT_COUNT(1),
HID_REPORT_SIZE(8),
HID_INPUT(0x02),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),

// Button report
HID_USAGE_PAGE(HID_USAGE_GEN_BUTTON),
Expand All @@ -305,7 +305,7 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_LOGICAL_MAX8(1),
HID_REPORT_SIZE(1),
HID_REPORT_COUNT(3),
HID_INPUT(0x02),
HID_INPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
// Byte Padding
HID_REPORT_SIZE(1),
HID_REPORT_COUNT(5),
Expand All @@ -316,14 +316,11 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
HID_REPORT_ID(ZMK_HID_REPORT_ID_FEATURE_PTP_CAPABILITIES),
HID_USAGE(HID_USAGE_DIGITIZERS_CONTACT_COUNT_MAXIMUM),
HID_REPORT_SIZE(8),
HID_REPORT_COUNT(1),
HID_LOGICAL_MAX8(0x05),
HID_FEATURE(0x02),

HID_USAGE(HID_USAGE_DIGITIZERS_PAD_TYPE),
HID_LOGICAL_MAX8(0x7F),
HID_FEATURE(0x02),
HID_REPORT_SIZE(4),
HID_REPORT_COUNT(2),
HID_LOGICAL_MAX8(0x0F),
HID_FEATURE(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),

// PTPHQA Blob: Necessary for < Windows 10

Expand Down Expand Up @@ -516,14 +513,18 @@ struct zmk_hid_ptp_feature_certification_report {
#define PTP_PAD_TYPE_NON_CLICKABLE 0x02

// Feature report for device capabilities
struct zmk_hid_ptp_feature_capabilities_report {
uint8_t report_id;
struct zmk_hid_ptp_feature_capabilities_report_body {
// Max touches (L 4bit) and pad type (H 4bit):
// Max touches: number 3-5
// Pad type: 0 for Depressible, 1 for Non-depressible, 2 for Non-clickable
uint8_t max_touches;
uint8_t pad_type;
uint8_t max_touches : 4;
uint8_t pad_type : 4;
} __packed;

// Feature report for device capabilities
struct zmk_hid_ptp_feature_capabilities_report {
uint8_t report_id;
struct zmk_hid_ptp_feature_capabilities_report_body body;
} __packed;

#endif
Expand Down
10 changes: 7 additions & 3 deletions app/src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ struct zmk_hid_ptp_feature_certification_report ptp_feature_certification_report
0xc2}};

// Feature report for device capabilities
struct zmk_hid_ptp_feature_capabilities_report ptp_feature_capabilities_report = {
static struct zmk_hid_ptp_feature_capabilities_report ptp_feature_capabilities_report = {
.report_id = ZMK_HID_REPORT_ID_FEATURE_PTP_CAPABILITIES,
.max_touches = CONFIG_ZMK_TRACKPAD_MAX_FINGERS,
.pad_type = PTP_PAD_TYPE_DEPRESSIBLE};
.body =
{
.max_touches = CONFIG_ZMK_TRACKPAD_MAX_FINGERS,
.pad_type = PTP_PAD_TYPE_DEPRESSIBLE,
},
};
#endif

// Keep track of how often a modifier was pressed.
Expand Down
15 changes: 9 additions & 6 deletions app/src/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ static ssize_t read_hids_trackpad_capabilities_feature_report(struct bt_conn *co
const struct bt_gatt_attr *attr,
void *buf, uint16_t len,
uint16_t offset) {
uint8_t *report_body = &zmk_hid_ptp_get_feature_capabilities_report()->max_touches;
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body, 2);
struct zmk_hid_ptp_feature_capabilities_report_body *report_body =
&zmk_hid_ptp_get_feature_capabilities_report()->body;
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body,
sizeof(struct zmk_hid_ptp_feature_capabilities_report_body));
}

static ssize_t read_hids_trackpad_certification_feature_report(struct bt_conn *conn,
Expand Down Expand Up @@ -230,8 +232,9 @@ static ssize_t write_hids_trackpad_mode_feature_report(struct bt_conn *conn,
static ssize_t read_hids_trackpad_mode_feature_report(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset) {
uint8_t *report_body = &zmk_hid_ptp_get_feature_mode_report()->mode;
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_body, sizeof(uint8_t));
struct zmk_hid_ptp_feature_mode_report *report = zmk_hid_ptp_get_feature_mode_report();
LOG_DBG("Get PTP MODE at offset %d with len %d", offset, len);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &report->mode, sizeof(uint8_t));
}

static ssize_t write_hids_trackpad_selective_feature_report(struct bt_conn *conn,
Expand Down Expand Up @@ -333,12 +336,12 @@ 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, &trackpad_report),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ,
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT,
read_hids_trackpad_capabilities_feature_report, NULL, NULL),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
NULL, &trackpad_capabilities),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ,
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT,
read_hids_trackpad_certification_feature_report, NULL, NULL),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ_ENCRYPT, read_hids_report_ref,
Expand Down

0 comments on commit 4a42fa2

Please sign in to comment.