Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HID customized touchscreen in conflict with mouse #2804

Closed
1 task done
0cococ opened this issue Sep 15, 2024 · 1 comment
Closed
1 task done

HID customized touchscreen in conflict with mouse #2804

0cococ opened this issue Sep 15, 2024 · 1 comment
Labels

Comments

@0cococ
Copy link

0cococ commented Sep 15, 2024

Operating System

Others

Board

ESP32S3

Firmware

const uint8_t hid_report_descriptor[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE)),
0x05, 0x0d, /* USAGE_PAGE (Digitizer) /
0x09, 0x04, /
USAGE (Touch Screen) /
0xa1, 0x01, /
COLLECTION (Application) /
0x85, HID_ITF_PROTOCOL_ABSMOUSE, /
REPORT_ID */

/* declare a finger collection */
0x09, 0x20, /*   Usage (Stylus) */
0xA1, 0x00, /*   Collection (Physical) */

/* Declare a finger touch (finger up/down) */
0x09, 0x42, /*     Usage (Tip Switch) */
0x09, 0x32, /*     USAGE (In Range) */
0x15, 0x00, /*     LOGICAL_MINIMUM (0) */
0x25, 0x01, /*     LOGICAL_MAXIMUM (1) */
0x75, 0x01, /*     REPORT_SIZE (1) */
0x95, 0x02, /*     REPORT_COUNT (2) */
0x81, 0x02, /*     INPUT (Data,Var,Abs) */

/* Declare the remaining 6 bits of the first data byte as constant -> the driver will ignore them */
0x75, 0x01, /*     REPORT_SIZE (1) */
0x95, 0x06, /*     REPORT_COUNT (6) */
0x81, 0x01, /*     INPUT (Cnst,Ary,Abs) */

/* Define absolute X and Y coordinates of 16 bit each (percent values multiplied with 100) */
/* http://www.usb.org/developers/hidpage/Hut1_12v2.pdf */
/* Chapter 16.2 says: "In the Stylus collection a Pointer physical collection will contain the axes reported by the stylus." */
0x05, 0x01,       /*     Usage Page (Generic Desktop) */
0x09, 0x01,       /*     Usage (Pointer) */
0xA1, 0x00,       /*     Collection (Physical) */
0x09, 0x30,       /*        Usage (X) */
0x09, 0x31,       /*        Usage (Y) */
0x16, 0x00, 0x00, /*        Logical Minimum (0) */
0x26, 0x10, 0x27, /*        Logical Maximum (10000) */
0x36, 0x00, 0x00, /*        Physical Minimum (0) */
0x46, 0x10, 0x27, /*        Physical Maximum (10000) */
0x66, 0x00, 0x00, /*        UNIT (None) */
0x75, 0x10,       /*        Report Size (16), */
0x95, 0x02,       /*        Report Count (2), */
0x81, 0x02,       /*        Input (Data,Var,Abs) */
0xc0,             /*     END_COLLECTION */
0xc0,             /*   END_COLLECTION */
0xc0              /* END_COLLECTION */

};

What happened ?

#include "tinyusb.h"

enum
{
ITF_NUM_HID,
ITF_NUM_CDC,
};
#define LSB(v) ((v) & 0xFF)
#define MSB(v) (((v) >> 8) & 0xFF)

#define ITF_NUM_TOTAL 3
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_DESC_LEN + TUD_CDC_DESC_LEN)
#define EPNUM_CDC_NOTIF 0x81
#define EPNUM_CDC_OUT 0x02
#define EPNUM_CDC_IN 0x82
#define EPNUM_HID 0x83
const uint8_t hid_report_descriptor[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE)),
0x05, 0x0d, /* USAGE_PAGE (Digitizer) /
0x09, 0x04, /
USAGE (Touch Screen) /
0xa1, 0x01, /
COLLECTION (Application) /
0x85, HID_ITF_PROTOCOL_ABSMOUSE, /
REPORT_ID */

/* declare a finger collection */
0x09, 0x20, /*   Usage (Stylus) */
0xA1, 0x00, /*   Collection (Physical) */

/* Declare a finger touch (finger up/down) */
0x09, 0x42, /*     Usage (Tip Switch) */
0x09, 0x32, /*     USAGE (In Range) */
0x15, 0x00, /*     LOGICAL_MINIMUM (0) */
0x25, 0x01, /*     LOGICAL_MAXIMUM (1) */
0x75, 0x01, /*     REPORT_SIZE (1) */
0x95, 0x02, /*     REPORT_COUNT (2) */
0x81, 0x02, /*     INPUT (Data,Var,Abs) */

/* Declare the remaining 6 bits of the first data byte as constant -> the driver will ignore them */
0x75, 0x01, /*     REPORT_SIZE (1) */
0x95, 0x06, /*     REPORT_COUNT (6) */
0x81, 0x01, /*     INPUT (Cnst,Ary,Abs) */

/* Define absolute X and Y coordinates of 16 bit each (percent values multiplied with 100) */
/* http://www.usb.org/developers/hidpage/Hut1_12v2.pdf */
/* Chapter 16.2 says: "In the Stylus collection a Pointer physical collection will contain the axes reported by the stylus." */
0x05, 0x01,       /*     Usage Page (Generic Desktop) */
0x09, 0x01,       /*     Usage (Pointer) */
0xA1, 0x00,       /*     Collection (Physical) */
0x09, 0x30,       /*        Usage (X) */
0x09, 0x31,       /*        Usage (Y) */
0x16, 0x00, 0x00, /*        Logical Minimum (0) */
0x26, 0x10, 0x27, /*        Logical Maximum (10000) */
0x36, 0x00, 0x00, /*        Physical Minimum (0) */
0x46, 0x10, 0x27, /*        Physical Maximum (10000) */
0x66, 0x00, 0x00, /*        UNIT (None) */
0x75, 0x10,       /*        Report Size (16), */
0x95, 0x02,       /*        Report Count (2), */
0x81, 0x02,       /*        Input (Data,Var,Abs) */
0xc0,             /*     END_COLLECTION */
0xc0,             /*   END_COLLECTION */
0xc0              /* END_COLLECTION */

};

const size_t hid_report_descriptor_size = sizeof(hid_report_descriptor);
// Invoked when received GET HID REPORT DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance)
{
// We use only one interface and one HID report descriptor, so we can ignore parameter 'instance'
return hid_report_descriptor;
}

/**

  • This is a simple configuration descriptor that defines 1 configuration and 1 HID interface
    */
    static const uint8_t configuration_descriptor[] = {
    // Configuration number, interface count, string index, total length, attribute, power in mA
    TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 200),

    // Interface number, string index, boot protocol, report descriptor len, EP In address, size & polling interval
    TUD_HID_DESCRIPTOR(ITF_NUM_HID, 5, HID_ITF_PROTOCOL_NONE, sizeof(hid_report_descriptor), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10),

    // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
    TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
    };

const char *string_descriptor[] = {
// array of pointer to string descriptors
(char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, // 1: Manufacturer
CONFIG_TINYUSB_DESC_PRODUCT_STRING, // 2: Product
CONFIG_TINYUSB_DESC_SERIAL_STRING, // 3: Serials, should use chip ID
CONFIG_TINYUSB_DESC_CDC_STRING, // 4: CDC Interface
CONFIG_DESC_HID_STRING, // 5: HID Interface
};

// Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen)
{
(void)instance;
(void)report_id;
(void)report_type;
(void)buffer;
(void)reqlen;

return 0;
}

// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize)
{
}

const tinyusb_config_t tusb_cfg = {
.device_descriptor = NULL,
.string_descriptor = string_descriptor,
.string_descriptor_count = sizeof(string_descriptor) / sizeof(string_descriptor[0]),
.external_phy = false,
.configuration_descriptor = configuration_descriptor,
};

How to reproduce ?

I deleted the definition of the mouse, the touch screen works fine, plus the mouse, the touch screen doesn't work, is there something wrong with it?

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

I (27) boot: ESP-IDF v5.3.1 2nd stage bootloader
I (27) boot: compile time Sep 14 2024 15:54:57
I (27) boot: Multicore bootloader
I (30) boot: chip revision: v0.1
I (34) boot.esp32s3: Boot SPI Speed : 80MHz
I (38) boot.esp32s3: SPI Mode : DIO
I (43) boot.esp32s3: SPI Flash Size : 2MB
I (48) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (57) boot: ## Label Usage Type ST Offset Length
I (64) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (72) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (79) boot: 2 factory factory app 00 00 00010000 00100000
I (87) boot: End of partition table
I (91) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=0bfd0h ( 49104) map
I (108) esp_image: segment 1: paddr=0001bff8 vaddr=3fc92500 size=02af4h ( 10996) load
I (111) esp_image: segment 2: paddr=0001eaf4 vaddr=40374000 size=01524h ( 5412) load
I (117) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=1cca4h (117924) map
I (146) esp_image: segment 4: paddr=0003cccc vaddr=40375524 size=0cee0h ( 52960) load
I (163) boot: Loaded app from partition at offset 0x10000
I (164) boot: Disabling RNG early entropy source...
I (176) cpu_start: Multicore app
I (185) cpu_start: Pro cpu start user code
I (185) cpu_start: cpu freq: 160000000 Hz
I (185) app_init: Application information:
I (188) app_init: Project name: hello_world
I (193) app_init: App version: 1
I (197) app_init: Compile time: Sep 14 2024 15:53:32
I (203) app_init: ELF file SHA256: 740cab92b...
I (209) app_init: ESP-IDF: v5.3.1
I (213) efuse_init: Min chip rev: v0.0
I (218) efuse_init: Max chip rev: v0.99
I (223) efuse_init: Chip rev: v0.1
I (228) heap_init: Initializing. RAM available for dynamic allocation:
I (235) heap_init: At 3FC96418 len 000532F8 (332 KiB): RAM
I (241) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (247) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (253) heap_init: At 600FE100 len 00001EE8 (7 KiB): RTCRAM
I (261) spi_flash: detected chip: gd
I (264) spi_flash: flash io: dio
W (268) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (281) sleep: Configure to isolate all GPIO pins in sleep state
I (288) sleep: Enable automatic switching of GPIO sleep configuration
I (295) main_task: Started on CPU0
I (305) main_task: Calling app_main()
I (305) app: USB initialization
W (305) tusb_desc: No Device descriptor provided, using default.
I (365) tusb_desc:
┌─────────────────────────────────┐
│ USB Device Descriptor Summary │
├───────────────────┬─────────────┤
│bDeviceClass │ 239 │
├───────────────────┼─────────────┤
│bDeviceSubClass │ 2 │
├───────────────────┼─────────────┤
│bDeviceProtocol │ 1 │
├───────────────────┼─────────────┤
│bMaxPacketSize0 │ 64 │
├───────────────────┼─────────────┤
│idVendor │ 0x303a │
├───────────────────┼─────────────┤
│idProduct │ 0x4009 │
├───────────────────┼─────────────┤
│bcdDevice │ 0x100 │
├───────────────────┼─────────────┤
│iManufacturer │ 0x1 │
├───────────────────┼─────────────┤
│iProduct │ 0x2 │
├───────────────────┼─────────────┤
│iSerialNumber │ 0x3 │
├───────────────────┼─────────────┤
│bNumConfigurations │ 0x1 │
└───────────────────┴─────────────┘
I (525) TinyUSB: TinyUSB Driver installed
I (525) app: USB initialization DONE

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@HiFiPhile HiFiPhile changed the title 自定义的触摸屏协议会和鼠标冲突 HID customized touchscreen in conflict with mouse Sep 16, 2024
@HiFiPhile
Copy link
Collaborator

Please use English so everyone can understand, also ESP's wrapper layer is not covered by this repo.

Repository owner locked and limited conversation to collaborators Sep 16, 2024
@HiFiPhile HiFiPhile converted this issue into discussion #2807 Sep 16, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

2 participants