- Still very basic (lots of room for improvement) - Capability format will likely change at some point - 16 bit movement control, however repeat rate limits usability (will need KLL 0.4 to make better)capsense
@@ -309,32 +309,33 @@ static uint8_t sys_ctrl_report_desc[] = { | |||
static uint8_t mouse_report_desc[] = { | |||
0x05, 0x01, // Usage Page (Generic Desktop) | |||
0x09, 0x02, // Usage (Mouse) | |||
0xa1, 0x01, // Collection (Application) | |||
0xA1, 0x01, // Collection (Application) | |||
0x09, 0x02, // Usage (Mouse) | |||
0xa1, 0x02, // Collection (Logical) | |||
0xA1, 0x02, // Collection (Logical) | |||
0x09, 0x01, // Usage (Pointer) | |||
// Buttons (8 bits) | |||
0xa1, 0x00, // Collection (Physical) - Buttons | |||
// Buttons (16 bits) | |||
0xA1, 0x00, // Collection (Physical) - Buttons | |||
0x05, 0x09, // Usage Page (Button) | |||
0x19, 0x01, // Usage Minimum (Button 1) | |||
0x29, 0x08, // Usage Maximum (Button 8) | |||
0x29, 0x10, // Usage Maximum (Button 16) | |||
0x15, 0x00, // Logical Minimum (0) | |||
0x25, 0x01, // Logical Maximum (1) | |||
0x75, 0x01, // Report Size (1) | |||
0x95, 0x08, // Report Count (8) | |||
0x95, 0x10, // Report Count (16) | |||
0x81, 0x02, // Input (Data,Var,Abs) | |||
// Pointer (16 bits) | |||
// Pointer (32 bits) | |||
0x05, 0x01, // Usage PAGE (Generic Desktop) | |||
0x09, 0x30, // Usage (X) | |||
0x09, 0x31, // Usage (Y) | |||
0x15, 0x81, // Logical Minimum (-127) | |||
0x25, 0x7f, // Logical Maximum (127) | |||
0x75, 0x08, // Report Size (8) | |||
0x16, 0x01, 0x80, // Logical Minimum (-32 767) | |||
0x26, 0xFF, 0x7F, // Logical Maximum (32 767) | |||
0x75, 0x10, // Report Size (16) | |||
0x95, 0x02, // Report Count (2) | |||
0x81, 0x06, // Input (Data,Var,Rel) | |||
/* | |||
// Vertical Wheel | |||
// - Multiplier (2 bits) | |||
0xa1, 0x02, // Collection (Logical) | |||
@@ -377,6 +378,7 @@ static uint8_t mouse_report_desc[] = { | |||
0x81, 0x06, // Input (Data,Var,Rel) | |||
0xc0, // End Collection - Horizontal Wheel | |||
*/ | |||
0xc0, // End Collection - Buttons | |||
0xc0, // End Collection - Mouse Logical | |||
0xc0 // End Collection - Mouse Application |
@@ -171,18 +171,18 @@ void usb_mouse_send() | |||
transmit_previous_timeout = 0; | |||
// Prepare USB Mouse Packet | |||
// TODO Document each byte | |||
// TODO Dynamically generate this code based on KLL requirements | |||
*(tx_packet->buf + 0) = USBMouse_Buttons; | |||
*(tx_packet->buf + 1) = 0; | |||
*(tx_packet->buf + 2) = 0; | |||
*(tx_packet->buf + 3) = 0; | |||
*(tx_packet->buf + 4) = 0; | |||
tx_packet->len = 5; | |||
uint16_t *packet_data = (uint16_t*)(&tx_packet->buf[0]); | |||
packet_data[0] = USBMouse_Buttons; | |||
packet_data[1] = USBMouse_Relative_x; | |||
packet_data[2] = USBMouse_Relative_y; | |||
tx_packet->len = 6; | |||
usb_tx( MOUSE_ENDPOINT, tx_packet ); | |||
// Clear status and state | |||
USBMouse_Buttons = 0; | |||
USBMouse_Relative_x = 0; | |||
USBMouse_Relative_y = 0; | |||
USBMouse_Changed = 0; | |||
} | |||
@@ -1,10 +1,10 @@ | |||
Name = pjrcUSBCapabilities; | |||
Version = 0.7; | |||
Version = 0.8; | |||
Author = "HaaTa (Jacob Alexander) 2014-2016"; | |||
KLL = 0.3d; | |||
# Modified Date | |||
Date = 2016-03-20; | |||
Date = 2016-03-21; | |||
# Output capabilities | |||
@@ -12,7 +12,7 @@ consCtrlOut => Output_consCtrlSend_capability( consCode : 2 ); | |||
noneOut => Output_noneSend_capability(); | |||
sysCtrlOut => Output_sysCtrlSend_capability( sysCode : 1 ); | |||
usbKeyOut => Output_usbCodeSend_capability( usbCode : 1 ); | |||
mouseOut => Output_usbMouse_capability( mouseCode : 2 ); | |||
mouseOut => Output_usbMouse_capability( mouseCode : 2, relative_x : 2, relative_y : 2 ); | |||
# Configuration capabilities | |||
kbdProtocolBoot => Output_kbdProtocolBoot_capability(); |
@@ -119,6 +119,10 @@ volatile uint8_t USBKeys_LEDs = 0; | |||
// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed | |||
volatile uint16_t USBMouse_Buttons = 0; | |||
// Relative mouse axis movement, stores pending movement | |||
volatile uint16_t USBMouse_Relative_x = 0; | |||
volatile uint16_t USBMouse_Relative_y = 0; | |||
// Protocol setting from the host. | |||
// 0 - Boot Mode | |||
// 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) | |||
@@ -129,7 +133,7 @@ volatile uint8_t USBKeys_Protocol = USBProtocol_define; | |||
USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; | |||
// Indicate if USB should send update | |||
uint8_t USBMouse_Changed = 0; | |||
USBMouseChangeState USBMouse_Changed = 0; | |||
// the idle configuration, how often we send the report to the | |||
// host (ms * 4) even when it hasn't changed | |||
@@ -519,13 +523,15 @@ void Output_flashMode_capability( uint8_t state, uint8_t stateType, uint8_t *arg | |||
// Sends a mouse command over the USB Output buffer | |||
// XXX This function *will* be changing in the future | |||
// If you use it, be prepared that your .kll files will break in the future (post KLL 0.5) | |||
// Argument #1: USB Mouse Button # | |||
// Argument #1: USB Mouse Button (16 bit) | |||
// Argument #2: USB X Axis (16 bit) relative | |||
// Argument #3: USB Y Axis (16 bit) relative | |||
void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args ) | |||
{ | |||
// Display capability name | |||
if ( stateType == 0xFF && state == 0xFF ) | |||
{ | |||
print("Output_usbMouse(mouseButton)"); | |||
print("Output_usbMouse(mouseButton,relX,relY)"); | |||
return; | |||
} | |||
@@ -537,25 +543,38 @@ void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args | |||
// 3 - Button 3 - (Tertiary) | |||
uint16_t mouse_button = *(uint16_t*)(&args[0]); | |||
// If set to zero, ignore | |||
if ( mouse_button == 0 ) | |||
return; | |||
// X/Y Relative Axis | |||
uint16_t mouse_x = *(uint16_t*)(&args[2]); | |||
uint16_t mouse_y = *(uint16_t*)(&args[4]); | |||
// Adjust for bit shift | |||
mouse_button -= 1; | |||
uint16_t mouse_button_shift = mouse_button - 1; | |||
// Only send mouse button if in press or hold state | |||
if ( stateType == 0x00 && state == 0x03 ) // Release state | |||
{ | |||
USBMouse_Buttons &= ~(1 << mouse_button); | |||
// Release | |||
if ( mouse_button ) | |||
USBMouse_Buttons &= ~(1 << mouse_button_shift); | |||
} | |||
else | |||
{ | |||
USBMouse_Buttons |= (1 << mouse_button); | |||
// Press or hold | |||
if ( mouse_button ) | |||
USBMouse_Buttons |= (1 << mouse_button_shift); | |||
if ( mouse_x ) | |||
USBMouse_Relative_x = mouse_x; | |||
if ( mouse_y ) | |||
USBMouse_Relative_y = mouse_y; | |||
} | |||
// TODO Add more states when adding full support | |||
USBMouse_Changed = 1; | |||
// Trigger updates | |||
if ( mouse_button ) | |||
USBMouse_Changed |= USBMouseChangeState_Buttons; | |||
if ( mouse_x || mouse_y ) | |||
USBMouse_Changed |= USBMouseChangeState_Relative; | |||
} | |||
@@ -56,6 +56,14 @@ typedef enum USBKeyChangeState { | |||
USBKeyChangeState_All = 0x7F, | |||
} USBKeyChangeState; | |||
// Allows for selective USB descriptor pushes | |||
// However, in most cases everything is updated for each packet push | |||
typedef enum USBMouseChangeState { | |||
USBMouseChangeState_None = 0x00, | |||
USBMouseChangeState_Buttons = 0x01, | |||
USBMouseChangeState_Relative = 0x02, | |||
} USBMouseChangeState; | |||
// ----- Variables ----- | |||
@@ -73,13 +81,15 @@ extern uint16_t USBKeys_ConsCtrl; // 1KRO container for Consumer Contro | |||
extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode | |||
extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons | |||
extern volatile uint16_t USBMouse_Relative_x; | |||
extern volatile uint16_t USBMouse_Relative_y; | |||
// Misc variables (XXX Some are only properly utilized using AVR) | |||
extern uint8_t USBKeys_Idle_Config; | |||
extern uint8_t USBKeys_Idle_Count; | |||
extern USBKeyChangeState USBKeys_Changed; | |||
extern uint8_t USBMouse_Changed; | |||
extern USBKeyChangeState USBKeys_Changed; | |||
extern USBMouseChangeState USBMouse_Changed; | |||
extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working | |||