From afdfb0895f33fd74e81f298e40205b3c521e900b Mon Sep 17 00:00:00 2001 From: HiFiPhile Date: Sun, 5 Oct 2025 18:58:16 +0200 Subject: Fix HIS stylus descriptor and hid_composite example Signed-off-by: HiFiPhile --- examples/device/hid_composite/src/main.c | 61 +++++++++++--------------------- 1 file changed, 21 insertions(+), 40 deletions(-) (limited to 'examples') diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index fa02a1abe..89dab0bdc 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -195,41 +195,30 @@ 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)); + case REPORT_ID_STYLUS_PEN: { + static bool touch_state = false; + hid_stylus_report_t report = { + .attr = 0, + .x = 0, + .y = 0 + }; - 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; + if (btn) { + report.attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE; + report.x = 100; + report.y = 100; + tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report)); + touch_state = true; + } else { + report.attr = 0; + if (touch_state) tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report)); + touch_state = false; + } + } + break; + default: break; } - } // Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..) @@ -239,14 +228,6 @@ void hid_task(void) // Poll every 10ms const uint32_t interval_ms = 10; static uint32_t start_ms = 0; - static uint32_t touch_ms = 0; - static bool touch_state = false; - - if (board_millis() - touch_ms < 100) { - touch_ms = board_millis(); - send_stylus_touch(0, 0, touch_state = !touch_state); - return; - } if ( board_millis() - start_ms < interval_ms) return; // not enough time start_ms += interval_ms; -- cgit v1.3.1 From 044512c4599339a57019def2d4587e9207a0649e Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 6 Oct 2025 13:34:05 +0700 Subject: fix typo --- examples/device/mtp/src/mtp_fs_example.c | 4 ++-- src/common/tusb_common.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/device/mtp/src/mtp_fs_example.c b/examples/device/mtp/src/mtp_fs_example.c index 73722fc4f..b4772f146 100644 --- a/examples/device/mtp/src/mtp_fs_example.c +++ b/examples/device/mtp/src/mtp_fs_example.c @@ -59,11 +59,11 @@ storage_info_t storage_info = { .free_space_in_bytes = 0, // calculated at runtime .free_space_in_objects = 0, // calculated at runtime .storage_description = { - .count = (TU_FIELD_SZIE(storage_info_t, storage_description)-1) / sizeof(uint16_t), + .count = (TU_FIELD_SIZE(storage_info_t, storage_description)-1) / sizeof(uint16_t), .utf16 = STORAGE_DESCRIPTRION }, .volume_identifier = { - .count = (TU_FIELD_SZIE(storage_info_t, volume_identifier)-1) / sizeof(uint16_t), + .count = (TU_FIELD_SIZE(storage_info_t, volume_identifier)-1) / sizeof(uint16_t), .utf16 = VOLUME_IDENTIFIER } }; diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 12dea2183..2b095e238 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -35,7 +35,7 @@ // Macros Helper //--------------------------------------------------------------------+ #define TU_ARRAY_SIZE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) ) -#define TU_FIELD_SZIE(_type, _field) (sizeof(((_type *)0)->_field)) +#define TU_FIELD_SIZE(_type, _field) (sizeof(((_type *)0)->_field)) #define TU_MIN(_x, _y) ( ( (_x) < (_y) ) ? (_x) : (_y) ) #define TU_MAX(_x, _y) ( ( (_x) > (_y) ) ? (_x) : (_y) ) #define TU_DIV_CEIL(n, d) (((n) + (d) - 1) / (d)) -- cgit v1.3.1