Once up on a time I've emulated a usb touchscreen using USB HID gadget driver. I captured and configured report descriptor and wrote sample application to just move cursor. Sources are attached. -- Constantine Shulyupin http://www.MakeLinux.com/ Embedded Linux Systems, Device Drivers, TI DaVinci
#include <linux/module.h> #include <linux/platform_device.h> #include <linux/usb/g_hid.h> #include <linux/hid.h> static struct hidg_func_descriptor hidg_touchscreen_dev_data = { .subclass = 0, /* No subclass */ .protocol = USB_INTERFACE_PROTOCOL_MOUSE, .report_length = 64, .report_desc_length = 249, .report_desc = { 0x06, 0xff, 0xff, 0x09, 0xff, 0xa1, 0x01, 0x85, 0x01, 0x09, 0xff, 0x15, 0x80, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x20, 0x81, 0x00, 0x85, 0x02, 0x09, 0xff, 0x91, 0x00, 0xc0, 0x05, 0x0d, 0x09, 0x04, 0xa1, 0x01, 0x85, 0x04, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x09, 0x32, 0x81, 0x02, 0x09, 0x47, 0x81, 0x02, 0x95, 0x05, 0x81, 0x03, 0x75, 0x08, 0x09, 0x51, 0x95, 0x01, 0x81, 0x02, 0x05, 0x01, 0x26, 0xff, 0x7f, 0x75, 0x10, 0x55, 0x00, 0x65, 0x00, 0x09, 0x30, 0x35, 0x00, 0x46, 0x00, 0x00, 0x81, 0x02, 0x09, 0x31, 0x26, 0xff, 0x7f, 0x46, 0x00, 0x00, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x05, 0x0d, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x09, 0x32, 0x81, 0x02, 0x09, 0x47, 0x81, 0x02, 0x95, 0x05, 0x81, 0x03, 0x75, 0x08, 0x09, 0x51, 0x95, 0x01, 0x81, 0x02, 0x05, 0x01, 0x26, 0xff, 0x7f, 0x75, 0x10, 0x55, 0x00, 0x65, 0x00, 0x09, 0x30, 0x35, 0x00, 0x46, 0x00, 0x00, 0x81, 0x02, 0x09, 0x31, 0x26, 0xff, 0x7f, 0x46, 0x00, 0x00, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x54, 0x95, 0x01, 0x75, 0x08, 0x15, 0x00, 0x25, 0x08, 0x81, 0x02, 0x09, 0x55, 0xb1, 0x02, 0xc0, 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x05, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x15, 0x00, 0x26, 0xff, 0x7f, 0x35, 0x00, 0x46, 0xff, 0x7f, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0x09, 0x31, 0x81, 0x02, 0xc0, 0xc0, } }; static struct platform_device hidg_pdev = { .name = "hidg", .dev.platform_data = &hidg_touchscreen_dev_data, }; static int __init hidg_pdev_init(void) { return platform_device_register(&hidg_pdev); } module_init(hidg_pdev_init); static void __exit hidg_pdev_cleanup(void) { platform_device_unregister(&hidg_pdev); } module_exit(hidg_pdev_cleanup); MODULE_LICENSE("GPL");
#include <string.h> #include <stdio.h> #include <ctype.h> #include <fcntl.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <arpa/inet.h> #define BUF_LEN 512 int main(int argc, const char *argv[]) { int fd = 0; char buf[BUF_LEN]; int cmd_len; struct report { short a; short b; unsigned xyz; } report; int to_send; int hold = 1; fd_set rfds; int retval, i; if ((fd = open("/dev/hidg0", O_RDWR, 0666)) == -1) { perror("open"); return -1; } report.xyz = htonl(0x12345678); write(fd, &report, sizeof(report)); // conversion test for (i = 0x1000; i < 0x6000; i += 0x1111) { // finger move memset(&report, 0x0, sizeof(report)); report.a = htons(0x0407); report.b = htons(0x0110); report.xyz = htonl((i << 16) | (i << 4) | 7); to_send = sizeof(report); sleep(1); write(fd, &report, sizeof(report)); } { // finger up memset(&report, 0x0, sizeof(report)); report.a = htons(0x0400); write(fd, &report, sizeof(report)); } close(fd); }
Attachment:
Makefile
Description: Binary data