mirror of
https://github.com/hathach/tinyusb.git
synced 2025-10-14 10:33:35 +08:00
Fix HIS stylus descriptor and hid_composite example
Signed-off-by: HiFiPhile <admin@hifiphile.com>
This commit is contained in:
@@ -195,41 +195,30 @@ static void send_hid_report(uint8_t report_id, uint32_t btn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* use this to send stylus touch signal through USB. */
|
case REPORT_ID_STYLUS_PEN: {
|
||||||
static void send_stylus_touch(uint16_t x, uint16_t y, bool state)
|
static bool touch_state = false;
|
||||||
{
|
hid_stylus_report_t report = {
|
||||||
// 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,
|
.attr = 0,
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = 0
|
.y = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
report.x = x;
|
if (btn) {
|
||||||
report.y = y;
|
|
||||||
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
report.attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE;
|
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));
|
tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
|
||||||
|
touch_state = true;
|
||||||
has_stylus_pen = true;
|
} else {
|
||||||
}else
|
|
||||||
{
|
|
||||||
report.attr = 0;
|
report.attr = 0;
|
||||||
if (has_stylus_pen) tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
|
if (touch_state) tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
|
||||||
has_stylus_pen = false;
|
touch_state = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..)
|
// 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
|
// Poll every 10ms
|
||||||
const uint32_t interval_ms = 10;
|
const uint32_t interval_ms = 10;
|
||||||
static uint32_t start_ms = 0;
|
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
|
if ( board_millis() - start_ms < interval_ms) return; // not enough time
|
||||||
start_ms += interval_ms;
|
start_ms += interval_ms;
|
||||||
|
@@ -267,14 +267,14 @@ void tud_hid_report_failed_cb(uint8_t instance, hid_report_type_t report_type, u
|
|||||||
// Stylus Pen Report Descriptor Template
|
// Stylus Pen Report Descriptor Template
|
||||||
#define TUD_HID_REPORT_DESC_STYLUS_PEN(...) \
|
#define TUD_HID_REPORT_DESC_STYLUS_PEN(...) \
|
||||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DIGITIZER ) , \
|
HID_USAGE_PAGE ( HID_USAGE_PAGE_DIGITIZER ) , \
|
||||||
HID_USAGE ( HID_USAGE_DIGITIZER_TOUCH_SCREEN ) , \
|
HID_USAGE ( HID_USAGE_DIGITIZER_PEN ) , \
|
||||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) , \
|
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) , \
|
||||||
/* Report ID if any */\
|
/* Report ID if any */\
|
||||||
__VA_ARGS__ \
|
__VA_ARGS__ \
|
||||||
HID_USAGE ( HID_USAGE_DIGITIZER_STYLUS ), \
|
HID_USAGE ( HID_USAGE_DIGITIZER_STYLUS ), \
|
||||||
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ), \
|
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ), \
|
||||||
HID_USAGE_PAGE ( HID_USAGE_DIGITIZER_TIP_SWITCH ) , \
|
HID_USAGE ( HID_USAGE_DIGITIZER_TIP_SWITCH ), \
|
||||||
HID_USAGE_PAGE ( HID_USAGE_DIGITIZER_IN_RANGE ) , \
|
HID_USAGE ( HID_USAGE_DIGITIZER_IN_RANGE ), \
|
||||||
HID_LOGICAL_MIN ( 0 ), \
|
HID_LOGICAL_MIN ( 0 ), \
|
||||||
HID_LOGICAL_MAX ( 1 ), \
|
HID_LOGICAL_MAX ( 1 ), \
|
||||||
HID_REPORT_SIZE ( 1 ), \
|
HID_REPORT_SIZE ( 1 ), \
|
||||||
|
Reference in New Issue
Block a user