| 0x95, 0x01, // Report Count (1) | 0x95, 0x01, // Report Count (1) | ||||
| 0x09, 0x56, // Usage (Scan Time) | 0x09, 0x56, // Usage (Scan Time) | ||||
| 0x81, 0x02, // Input (variable,absolute) | 0x81, 0x02, // Input (variable,absolute) | ||||
| 0x09, 0x54, // USAGE (Contact count) | |||||
| 0x25, 0x7f, // LOGICAL_MAXIMUM (127) | |||||
| 0x95, 0x01, // REPORT_COUNT (1) | |||||
| 0x75, 0x08, // REPORT_SIZE (8) | |||||
| 0x81, 0x02, // INPUT (Data,Var,Abs) | |||||
| 0x05, 0x0D, // Usage Page (Digitizers) | 0x05, 0x0D, // Usage Page (Digitizers) | ||||
| 0x09, 0x55, // Usage (Contact Count Maximum) | 0x09, 0x55, // Usage (Contact Count Maximum) | ||||
| 0x25, MULTITOUCH_FINGERS, // Logical Maximum (10) | 0x25, MULTITOUCH_FINGERS, // Logical Maximum (10) |
| #define KEYMEDIA_INTERVAL 4 | #define KEYMEDIA_INTERVAL 4 | ||||
| #define MULTITOUCH_INTERFACE 3 // Touchscreen | #define MULTITOUCH_INTERFACE 3 // Touchscreen | ||||
| #define MULTITOUCH_ENDPOINT 5 | #define MULTITOUCH_ENDPOINT 5 | ||||
| #define MULTITOUCH_SIZE 8 | |||||
| #define MULTITOUCH_SIZE 9 | |||||
| #define MULTITOUCH_FINGERS 10 | #define MULTITOUCH_FINGERS 10 | ||||
| #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT | #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT | ||||
| #define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT | #define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT | ||||
| #define MOUSE_INTERVAL 2 | #define MOUSE_INTERVAL 2 | ||||
| #define MULTITOUCH_INTERFACE 4 // Touchscreen | #define MULTITOUCH_INTERFACE 4 // Touchscreen | ||||
| #define MULTITOUCH_ENDPOINT 5 | #define MULTITOUCH_ENDPOINT 5 | ||||
| #define MULTITOUCH_SIZE 8 | |||||
| #define MULTITOUCH_SIZE 9 | |||||
| #define MULTITOUCH_FINGERS 10 | #define MULTITOUCH_FINGERS 10 | ||||
| #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT | #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT | ||||
| #define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT | #define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT | ||||
| #define AUDIO_SYNC_ENDPOINT 14 | #define AUDIO_SYNC_ENDPOINT 14 | ||||
| #define MULTITOUCH_INTERFACE 12 // Touchscreen | #define MULTITOUCH_INTERFACE 12 // Touchscreen | ||||
| #define MULTITOUCH_ENDPOINT 15 | #define MULTITOUCH_ENDPOINT 15 | ||||
| #define MULTITOUCH_SIZE 8 | |||||
| #define MULTITOUCH_SIZE 9 | |||||
| #define MULTITOUCH_FINGERS 10 | #define MULTITOUCH_FINGERS 10 | ||||
| #define ENDPOINT1_CONFIG ENDPOINT_TRANSMIT_ONLY | #define ENDPOINT1_CONFIG ENDPOINT_TRANSMIT_ONLY | ||||
| #define ENDPOINT2_CONFIG ENDPOINT_TRANSMIT_AND_RECEIVE | #define ENDPOINT2_CONFIG ENDPOINT_TRANSMIT_AND_RECEIVE |
| // 5: Y msb | // 5: Y msb | ||||
| // 6: scan time lsb | // 6: scan time lsb | ||||
| // 7: scan time msb | // 7: scan time msb | ||||
| // 8: contact count | |||||
| // Called by the start-of-frame interrupt. | // Called by the start-of-frame interrupt. | ||||
| // | // | ||||
| void usb_touchscreen_update_callback(void) | void usb_touchscreen_update_callback(void) | ||||
| { | { | ||||
| static uint8_t microframe_count=0; | static uint8_t microframe_count=0; | ||||
| uint8_t contact_count = 0; | |||||
| if (usb_high_speed) { | if (usb_high_speed) { | ||||
| // if 480 speed, run only every 8th micro-frame | // if 480 speed, run only every 8th micro-frame | ||||
| if (scan_index == 0) { | if (scan_index == 0) { | ||||
| scan_timestamp = millis() * 10; | scan_timestamp = millis() * 10; | ||||
| scan_count = 0; | scan_count = 0; | ||||
| // Get the contact count (usage 0x54) | |||||
| // Only set this value on first contact | |||||
| // Subsequent concurrent contacts should report 0 | |||||
| for (uint8_t i = 0; i < MULTITOUCH_FINGERS; i++) { | |||||
| if (contactid[i]) contact_count++; | |||||
| } | |||||
| } | } | ||||
| while (scan_index < MULTITOUCH_FINGERS) { | while (scan_index < MULTITOUCH_FINGERS) { | ||||
| uint32_t press = pressure[scan_index]; | uint32_t press = pressure[scan_index]; | ||||
| id &= 0xFE; | id &= 0xFE; | ||||
| contactid[scan_index] = 0; | contactid[scan_index] = 0; | ||||
| } | } | ||||
| uint8_t buffer[MULTITOUCH_SIZE]; // MULTITOUCH_SIZE = 8 | |||||
| //uint8_t buffer[MULTITOUCH_SIZE]; // MULTITOUCH_SIZE = 8 | |||||
| txbuffer[0] = id; | txbuffer[0] = id; | ||||
| txbuffer[1] = press; | txbuffer[1] = press; | ||||
| txbuffer[2] = xpos[scan_index]; | txbuffer[2] = xpos[scan_index]; | ||||
| txbuffer[5] = ypos[scan_index] >> 8; | txbuffer[5] = ypos[scan_index] >> 8; | ||||
| txbuffer[6] = scan_timestamp; | txbuffer[6] = scan_timestamp; | ||||
| txbuffer[7] = scan_timestamp >> 8; | txbuffer[7] = scan_timestamp >> 8; | ||||
| txbuffer[8] = contact_count; | |||||
| //delayNanoseconds(30); | //delayNanoseconds(30); | ||||
| usb_prepare_transfer(&tx_transfer, txbuffer, MULTITOUCH_SIZE, 0); | usb_prepare_transfer(&tx_transfer, txbuffer, MULTITOUCH_SIZE, 0); | ||||
| arm_dcache_flush_delete(txbuffer, TX_BUFSIZE); | arm_dcache_flush_delete(txbuffer, TX_BUFSIZE); |