Skip to content

Commit

Permalink
Switch to mouse mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Nov 4, 2023
1 parent cb6eb19 commit eafda39
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 605 deletions.
2 changes: 1 addition & 1 deletion app/boards/arm/bt60/bt60_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_GEN4=y
CONFIG_GEN4_TRIGGER_GLOBAL_THREAD=y
#CONFIG_SENSOR_LOG_LEVEL_DBG=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y

CONFIG_USE_DT_CODE_PARTITION=y

Expand Down
11 changes: 4 additions & 7 deletions app/include/drivers/sensor/gen4.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ extern "C" {
#include <zephyr/drivers/sensor.h>

enum sensor_channel_gen4 {
SENSOR_CHAN_FINGER = SENSOR_CHAN_PRIV_START,
SENSOR_CHAN_X,
SENSOR_CHAN_Y,
SENSOR_CHAN_CONFIDENCE_TIP,
SENSOR_CHAN_CONTACTS,
SENSOR_CHAN_SCAN_TIME,
SENSOR_CHAN_BUTTONS,
SENSOR_CHAN_BUTTONS = SENSOR_CHAN_PRIV_START,
SENSOR_CHAN_WHEEL,
SENSOR_CHAN_XDELTA,
SENSOR_CHAN_YDELTA,
};

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion app/include/zmk/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ struct zmk_endpoint_instance zmk_endpoints_selected(void);

int zmk_endpoints_send_report(uint16_t usage_page);
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
int zmk_endpoints_send_ptp_report();
int zmk_endpoints_send_trackpad_mouse_report();
#endif
302 changes: 26 additions & 276 deletions app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
#define ZMK_REPORT_ID_LEDS 0x01
#define ZMK_REPORT_ID_CONSUMER 0x02

#define ZMK_REPORT_ID_TRACKPAD 0x05
#define ZMK_REPORT_ID_FEATURE_PTP_CAPABILITIES 0x06
#define ZMK_REPORT_ID_FEATURE_PTPHQA 0x07
#define ZMK_REPORT_ID_FEATURE_PTP_CONFIGURATION 0x08
#define ZMK_REPORT_ID_FEATURE_PTP_SELECTIVE 0x09
#define ZMK_REPORT_ID_TOUCHPAD_MOUSE 0x05

static const uint8_t zmk_hid_report_desc[] = {
HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP),
Expand Down Expand Up @@ -114,226 +110,35 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_INPUT(0x00),
HID_END_COLLECTION,
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
// PTP Touchpad HID with inspiration from osmakari
/* USAGE_PAGE (Digitizers) */
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
/* USAGE (Touch Pad) */
HID_USAGE(HID_USAGE_DIGITIZERS_TOUCH_PAD),
/* COLLECTION (Application) */
HID_USAGE_PAGE(HID_USAGE_GD),
HID_USAGE(HID_USAGE_GD_MOUSE),
HID_COLLECTION(HID_COLLECTION_APPLICATION),

/* Windows Precision Touchpad Input Reports */

/* REPORT_ID (0x05) */
HID_REPORT_ID(ZMK_REPORT_ID_TRACKPAD),
/* USAGE (Finger) */
HID_USAGE(HID_USAGE_DIGITIZERS_FINGER),
/* COLLECTION (Logical) */
HID_COLLECTION(HID_COLLECTION_LOGICAL),
/* LOGICAL_MINIMUM (0) */
HID_REPORT_ID(ZMK_REPORT_ID_TOUCHPAD_MOUSE),
HID_USAGE(HID_USAGE_GD_POINTER),
HID_COLLECTION(HID_COLLECTION_PHYSICAL),
// Button
HID_USAGE_PAGE(HID_USAGE_GEN_BUTTON),
HID_USAGE_MIN8(1),
HID_USAGE_MAX8(2),
HID_LOGICAL_MIN8(0),
/* LOGICAL_MAXIMUM (1) */
HID_LOGICAL_MAX8(1),
/* USAGE (Confidence) */
HID_USAGE(0x47),
/* USAGE (Tip switch) */
HID_USAGE(0x42),
/* REPORT_COUNT (2) */
HID_REPORT_COUNT(2),
/* REPORT_SIZE (1) */
HID_REPORT_SIZE(1),
/* INPUT (Data, Var, Abs) */
HID_REPORT_COUNT(2),
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 (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 (byte padding) */
HID_REPORT_COUNT(5),
/* INPUT (Cnst,Var,Abs) */
HID_INPUT(0x03),
/* USAGE_PAGE(Generic Desktop) */
// Axes
HID_USAGE_PAGE(HID_USAGE_GD),
/* LOGICAL_MINIMUM (0) */
HID_LOGICAL_MIN8(0),
/* LOGICAL_MAXIMUM (defined inkconfic) */
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) */
0x55,
0x0e,
/* UNIT (CM, EngLinear) */
0x65,
0x11,
/* USAGE (X) */
HID_USAGE(HID_USAGE_GD_X),
/* PHYSICAL_MINIMUM (0) */
0x35,
0x00,
/* PHYSICAL_MAXIMUM (defined in config) */
0x46,
(CONFIG_ZMK_TRACKPAD_PHYSICAL_X & 0xFF),
((CONFIG_ZMK_TRACKPAD_PHYSICAL_X >> 8) & 0xFF),
/* REPORT_COUNT (1) */
HID_REPORT_COUNT(1),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
// Logimax
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),
((CONFIG_ZMK_TRACKPAD_PHYSICAL_Y >> 8) & 0xFF),
/* USAGE (Y) */
HID_USAGE(HID_USAGE_GD_Y),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
/* END_COLLECTION */
HID_END_COLLECTION,
/* USAGE_PAGE (Digitizers) */
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
// Usage scan time
HID_USAGE(HID_USAGE_DIGITIZERS_SCAN_TIME),
//
0x55,
0x0C, // UNIT_EXPONENT (-4)
0x66,
0x01,
0x10, // UNIT (Seconds)
0x47,
0xff,
0xff,
0x00,
0x00, // PHYSICAL_MAXIMUM (65535)
0x27,
0xff,
0xff,
0x00,
0x00, // Logical Maximum
HID_REPORT_SIZE(16),
HID_REPORT_COUNT(1),

HID_INPUT(0x02),
// Physmax 0
0x45,
0x00,
/* USAGE (Contact count) */
HID_USAGE(HID_USAGE_DIGITIZERS_CONTACT_COUNT),
/* LOGICAL_MAXIMUM (5) */
HID_LOGICAL_MAX8(0x05),
/* REPORT_COUNT (1) */
HID_REPORT_COUNT(1),
/* REPORT_SIZE (8) */
HID_USAGE(HID_USAGE_GD_WHEEL),
// -127 -> 127
HID_LOGICAL_MIN8(0x81),
HID_LOGICAL_MAX8(0x7f),
HID_REPORT_SIZE(8),
/* INPUT(Data, Var, Abs) */
HID_INPUT(0x02),

// Button report
HID_USAGE_PAGE(HID_USAGE_GEN_BUTTON),
/* USAGE (Button 1) */
HID_USAGE(0x01),
HID_USAGE(0x02),
HID_USAGE(0x03), /* LOGICAL_MAXIMUM (1) */
HID_LOGICAL_MAX8(1),
/* REPORT_SIZE (1) */
HID_REPORT_SIZE(1),
/* REPORT_COUNT (1) */
HID_REPORT_COUNT(3),
/* INPUT (Data, Var, Abs) */
HID_INPUT(0x02),
/* REPORT_SIZE (1) */
HID_REPORT_SIZE(1),
/* REPORT_COUNT (byte padding) */
HID_REPORT_COUNT(5),
/* INPUT (Cnst,Var,Abs) */
HID_INPUT(0x03),

/* Device Capabilities Feature Report */

/* USAGE_PAGE (Digitizer) */
HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),
/* REPORT_ID (0x07) */
HID_REPORT_ID(ZMK_REPORT_ID_FEATURE_PTP_CAPABILITIES),
/* USAGE (Contact Count Maximum) */
HID_USAGE(HID_USAGE_DIGITIZERS_CONTACT_COUNT_MAXIMUM),
HID_REPORT_SIZE(8),
HID_REPORT_COUNT(1),
HID_LOGICAL_MAX8(0x05),
HID_FEATURE(0x02),
/* USAGE (Pad Type) */
HID_USAGE(HID_USAGE_DIGITIZERS_PAD_TYPE),
/* FEATURE (Data, Var, Abs) */
HID_FEATURE(0x02),

/* PTPHQA Blob: Necessary for < Windows 10 */

/* USAGE_PAGE (Vendor Defined) */
0x06,
0x00,
0xff,
/* REPORT_ID (0x08) */
HID_REPORT_ID(ZMK_REPORT_ID_FEATURE_PTPHQA),
/* HID_USAGE (Vendor Usage 0xC5) */
HID_USAGE(0xC5),
/* LOGICAL_MINIMUM (0) */
HID_LOGICAL_MIN8(0),
/* LOGICAL_MAXIMUM (0xFF) */
HID_LOGICAL_MAX16(0xFF, 0x00),
/* REPORT_SIZE (8) */
HID_REPORT_SIZE(8),
/* REPORT_COUNT (256) */
0x96,
0x00,
0x01,
/* FEATURE (Data, Var, Abs) */
HID_FEATURE(0x02),
/* END_COLLECTION */
HID_END_COLLECTION,

HID_USAGE_PAGE(HID_USAGE_DIGITIZERS),

HID_USAGE(HID_USAGE_DIGITIZERS_DEVICE_CONFIGURATION),

HID_COLLECTION(HID_COLLECTION_APPLICATION),
/* USAGE (Finger) */
HID_USAGE(HID_USAGE_DIGITIZERS_FINGER),
/* COLLECTION (Physical) */
HID_COLLECTION(HID_COLLECTION_PHYSICAL),
/* REPORT_ID (Feature, 0x0A) */
HID_REPORT_ID(ZMK_REPORT_ID_FEATURE_PTP_SELECTIVE),
/* USAGE (Surface switch) */
HID_USAGE(HID_USAGE_DIGITIZERS_SURFACE_SWITCH),
/* USAGE (Button switch) */
HID_USAGE(HID_USAGE_DIGITIZERS_BUTTON_SWITCH),
/* REPORT_SIZE (1) */
HID_REPORT_SIZE(1),
/* REPORT_COUNT (2) */
HID_REPORT_COUNT(2),
/* LOGICAL_MAXIMUM (1) */
HID_LOGICAL_MIN8(0),
HID_LOGICAL_MAX8(1),
/* FEATURE (Data, Var, Abs) */
HID_FEATURE(0x02),
/* REPORT_COUNT (6) */
HID_REPORT_COUNT(6),
/* FEATURE (Cnst, Var, Abs) */
HID_FEATURE(0x03),
/* END_COLLECTION */
// Var rel input
HID_INPUT(0x06),
HID_END_COLLECTION,
HID_END_COLLECTION,
#endif
Expand Down Expand Up @@ -385,66 +190,16 @@ struct zmk_hid_consumer_report {
} __packed;

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
// Reporting structure from osmakari
// Report for single finger
struct zmk_ptp_finger {
// Confidence (bit 0) and tip switch (bit 1)
uint8_t confidence_tip;
// Contact ID
uint8_t contact_id;
// X
uint16_t x;
// Y
uint16_t y;
} __packed;

struct zmk_hid_ptp_report_body {
// Finger reporting
struct zmk_ptp_finger finger;
// scantime
uint16_t scan_time;
// Contact count
uint8_t contact_count;
// Buttons /surfaceswitch
struct zmk_hid_touchpad_mouse_report_body {
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;

int8_t xDelta;
int8_t yDelta;
int8_t scrollDelta;
} __packed;

// Feature report for configuration
struct zmk_hid_ptp_feature_selective_report {
struct zmk_hid_touchpad_mouse_report {
uint8_t report_id;
// Selective reporting: Surface switch (bit 0), Button switch (bit 1)
uint8_t selective_reporting;
} __packed;

// Feature report for certification
struct zmk_hid_ptp_feature_certification_report {
uint8_t report_id;

uint8_t ptphqa_blob[256];
} __packed;

#define PTP_PAD_TYPE_DEPRESSIBLE 0x00
#define PTP_PAD_TYPE_PRESSURE 0x01
#define PTP_PAD_TYPE_NON_CLICKABLE 0x02

// Feature report for device capabilities
struct zmk_hid_ptp_feature_capabilities_report {
uint8_t report_id;
// 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;

struct zmk_hid_touchpad_mouse_report_body body;
} __packed;

#endif
Expand Down Expand Up @@ -476,16 +231,11 @@ 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, uint16_t scan_time,
uint8_t buttons);
void zmk_hid_touchpad_mouse_set(uint8_t buttons, int8_t xDelta, int8_t yDelta, int8_t scrollDelta);
#endif

struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
struct zmk_hid_ptp_report *zmk_hid_get_ptp_report();
struct zmk_hid_ptp_feature_selective_report *zmk_hid_ptp_get_feature_selective_report();
void zmk_hid_ptp_set_feature_selective_report(uint8_t selective_report);
struct zmk_hid_ptp_feature_certification_report *zmk_hid_ptp_get_feature_certification_report();
struct zmk_hid_ptp_feature_capabilities_report *zmk_hid_ptp_get_feature_capabilities_report();
struct zmk_hid_touchpad_mouse_report *zmk_hid_get_touchpad_mouse_report();
#endif
4 changes: 2 additions & 2 deletions app/include/zmk/hog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ 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);
int zmk_hog_send_touchpad_mouse_report(struct zmk_hid_touchpad_mouse_report_body *body);
int zmk_hog_send_touchpad_mouse_report_direct(struct zmk_hid_touchpad_mouse_report_body *report);
#endif
Loading

0 comments on commit eafda39

Please sign in to comment.