summaryrefslogtreecommitdiff
path: root/examples/device/hid_composite/src
diff options
context:
space:
mode:
authorJay <[email protected]>2024-12-23 22:03:37 +0900
committerJay <[email protected]>2024-12-23 22:03:37 +0900
commit15b1623aa3b677100cb7e81bf05f0c3b481d355b (patch)
tree02949b94a96e2073a82dbb6dfbbc581bc1c02bb0 /examples/device/hid_composite/src
parent7c1afa837a28c7bd5210f57eda4afba4e171cad4 (diff)
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
Diffstat (limited to 'examples/device/hid_composite/src')
-rw-r--r--examples/device/hid_composite/src/main.c34
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.c1
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.h1
3 files changed, 35 insertions, 1 deletions
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index 5302af3b8..958d8f4af 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -197,11 +197,43 @@ static void send_hid_report(uint8_t report_id, uint32_t btn)
}
}
break;
-
default: break;
}
}
+/* use this to send stylus touch signal through USB. */
+static void send_stylus_touch(uint16_t x, uint16_t y, bool state)
+{
+ // skip if hid is not ready yet
+ if ( !tud_hid_ready() ) return;
+
+ static bool has_stylus_pen = false;
+
+ hid_stylus_report_t report =
+ {
+ .attr = 0,
+ .x = 0,
+ .y = 0
+ };
+
+ report.x = x;
+ report.y = y;
+
+ if (state)
+ {
+ report.attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE;
+ tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
+
+ has_stylus_pen = true;
+ }else
+ {
+ report.attr = 0;
+ if (has_stylus_pen) tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
+ has_stylus_pen = false;
+ }
+
+}
+
// Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..)
// tud_hid_report_complete_cb() is used to send the next report after previous one is complete
void hid_task(void)
diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c
index e174db46d..15c6e1f73 100644
--- a/examples/device/hid_composite/src/usb_descriptors.c
+++ b/examples/device/hid_composite/src/usb_descriptors.c
@@ -79,6 +79,7 @@ uint8_t const desc_hid_report[] =
{
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )),
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE )),
+ TUD_HID_REPORT_DESC_STYLUS_PEN( HID_REPORT_ID(REPORT_ID_STYLUS_PEN )),
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )),
TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD ))
};
diff --git a/examples/device/hid_composite/src/usb_descriptors.h b/examples/device/hid_composite/src/usb_descriptors.h
index e733d31dd..18d31172b 100644
--- a/examples/device/hid_composite/src/usb_descriptors.h
+++ b/examples/device/hid_composite/src/usb_descriptors.h
@@ -29,6 +29,7 @@ enum
{
REPORT_ID_KEYBOARD = 1,
REPORT_ID_MOUSE,
+ REPORT_ID_STYLUS_PEN,
REPORT_ID_CONSUMER_CONTROL,
REPORT_ID_GAMEPAD,
REPORT_ID_COUNT