Added Contact Count to Teensy3 multi touch reportteensy4-core
| 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 16 | |||||
| #define MULTITOUCH_FINGERS 10 | #define MULTITOUCH_FINGERS 10 | ||||
| #define ENDPOINT1_CONFIG ENDPOINT_TRANSMIT_ONLY | #define ENDPOINT1_CONFIG ENDPOINT_TRANSMIT_ONLY | ||||
| #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY | #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY | ||||
| #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 16 | |||||
| #define MULTITOUCH_FINGERS 10 | #define MULTITOUCH_FINGERS 10 | ||||
| #define ENDPOINT1_CONFIG ENDPOINT_TRANSMIT_ONLY | #define ENDPOINT1_CONFIG ENDPOINT_TRANSMIT_ONLY | ||||
| #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY | #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY |
| // 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) | ||||
| { | { | ||||
| uint8_t contact_count = 0; | |||||
| if (scan_index == 0) { | if (scan_index == 0) { | ||||
| if (usb_tx_packet_count(MULTITOUCH_ENDPOINT) > 1) { | if (usb_tx_packet_count(MULTITOUCH_ENDPOINT) > 1) { | ||||
| // wait to begin another scan if if more than | // wait to begin another scan if if more than | ||||
| } | } | ||||
| 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]; | ||||
| uint32_t id = contactid[scan_index]; | uint32_t id = contactid[scan_index]; | ||||
| *(tx_packet->buf + 5) = ypos[scan_index] >> 8; | *(tx_packet->buf + 5) = ypos[scan_index] >> 8; | ||||
| *(tx_packet->buf + 6) = scan_timestamp; | *(tx_packet->buf + 6) = scan_timestamp; | ||||
| *(tx_packet->buf + 7) = scan_timestamp >> 8; | *(tx_packet->buf + 7) = scan_timestamp >> 8; | ||||
| tx_packet->len = 8; | |||||
| *(tx_packet->buf + 8) = contact_count; | |||||
| tx_packet->len = 9; | |||||
| usb_tx(MULTITOUCH_ENDPOINT, tx_packet); | usb_tx(MULTITOUCH_ENDPOINT, tx_packet); | ||||
| scan_index++; | scan_index++; | ||||
| return; | return; |