add hid stylus pen device.

this works with android, for bypassing that absmouse does not support android.
note that, to hide cursor on android for every touch signal, find cursor option in android settings menu.

references:
1. https://stackoverflow.com/questions/28536602/hid-digitizer-descriptor-doesnt-perform-well-with-landscape-orientation
2. https://github.com/jonathanedgecombe/absmouse/blob/master/src/AbsMouse.cpp
This commit is contained in:
Jay
2024-12-23 22:03:37 +09:00
parent 7c1afa837a
commit 15b1623aa3
6 changed files with 121 additions and 1 deletions

View File

@@ -79,6 +79,9 @@ bool tud_hid_n_abs_mouse_report(uint8_t instance, uint8_t report_id, uint8_t but
// use template layout report TUD_HID_REPORT_DESC_GAMEPAD
bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons);
// STYLUS PEN: convenient helper to send absolute stylus pen report if application
bool tud_hid_n_stylus_report(uint8_t instance, uint8_t report_id, uint8_t attrs, uint16_t x, uint16_t y);
//--------------------------------------------------------------------+
// Application API (Single Port)
//--------------------------------------------------------------------+
@@ -114,6 +117,10 @@ TU_ATTR_ALWAYS_INLINE static inline bool tud_hid_gamepad_report(uint8_t report_i
return tud_hid_n_gamepad_report(0, report_id, x, y, z, rz, rx, ry, hat, buttons);
}
TU_ATTR_ALWAYS_INLINE static inline bool tud_hid_stylus_report(uint8_t report_id, uint8_t attrs, uint16_t x, uint16_t y) {
return tud_hid_n_stylus_report(0, report_id, attrs, x, y);
}
//--------------------------------------------------------------------+
// Application Callbacks
//--------------------------------------------------------------------+
@@ -257,6 +264,41 @@ void tud_hid_report_failed_cb(uint8_t instance, hid_report_type_t report_type, u
HID_COLLECTION_END , \
HID_COLLECTION_END \
// Stylus Pen Report Descriptor Template
#define TUD_HID_REPORT_DESC_STYLUS_PEN(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DIGITIZER ) , \
HID_USAGE ( HID_USAGE_DIGITIZER_TOUCH_SCREEN ) , \
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) , \
/* Report ID if any */\
__VA_ARGS__ \
HID_USAGE ( HID_USAGE_DIGITIZER_STYLUS ) , \
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) , \
HID_USAGE_PAGE ( HID_USAGE_PAGE_TIP_SWITCH ) , \
HID_USAGE_PAGE ( HID_USAGE_PAGE_IN_RANGE ) , \
HID_LOGICAL_MIN ( 0 ), \
HID_LOGICAL_MAX ( 1 ), \
HID_REPORT_SIZE ( 1 ), \
HID_REPORT_COUNT( 2 ), \
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), \
HID_REPORT_SIZE ( 1 ), \
HID_REPORT_COUNT( 6 ), \
HID_INPUT ( HID_CONSTANT | HID_ARRAY | HID_ABSOLUTE), \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ), \
HID_PHYSICAL_MAX( 0x7fff ), \
HID_LOGICAL_MAX ( 0x7fff ), \
HID_REPORT_SIZE ( 16 ), \
HID_REPORT_COUNT( 1 ), \
HID_UNIT_EXPONENT( -1 ), \
HID_UNIT ( HID_VARIABLE | HID_NONLINEAR ), \
HID_PHYSICAL_MIN( 0 ), \
HID_PHYSICAL_MAX( 0 ), \
HID_USAGE ( HID_USAGE_DESKTOP_X ), \
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), \
HID_USAGE ( HID_USAGE_DESKTOP_Y ), \
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), \
HID_COLLECTION_END , \
HID_COLLECTION_END \
// Absolute Mouse Report Descriptor Template
#define TUD_HID_REPORT_DESC_ABSMOUSE(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\