Archived
1
0

Adding relative movement mouse key support

- 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)
This commit is contained in:
Jacob Alexander 2016-03-21 22:23:57 -07:00
parent 3c9a97d51a
commit 18aef02a1f
5 changed files with 64 additions and 33 deletions

View File

@ -309,32 +309,33 @@ static uint8_t sys_ctrl_report_desc[] = {
static uint8_t mouse_report_desc[] = { static uint8_t mouse_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop) 0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x02, // Usage (Mouse) 0x09, 0x02, // Usage (Mouse)
0xa1, 0x01, // Collection (Application) 0xA1, 0x01, // Collection (Application)
0x09, 0x02, // Usage (Mouse) 0x09, 0x02, // Usage (Mouse)
0xa1, 0x02, // Collection (Logical) 0xA1, 0x02, // Collection (Logical)
0x09, 0x01, // Usage (Pointer) 0x09, 0x01, // Usage (Pointer)
// Buttons (8 bits) // Buttons (16 bits)
0xa1, 0x00, // Collection (Physical) - Buttons 0xA1, 0x00, // Collection (Physical) - Buttons
0x05, 0x09, // Usage Page (Button) 0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button 1) 0x19, 0x01, // Usage Minimum (Button 1)
0x29, 0x08, // Usage Maximum (Button 8) 0x29, 0x10, // Usage Maximum (Button 16)
0x15, 0x00, // Logical Minimum (0) 0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1) 0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1) 0x75, 0x01, // Report Size (1)
0x95, 0x08, // Report Count (8) 0x95, 0x10, // Report Count (16)
0x81, 0x02, // Input (Data,Var,Abs) 0x81, 0x02, // Input (Data,Var,Abs)
// Pointer (16 bits) // Pointer (32 bits)
0x05, 0x01, // Usage PAGE (Generic Desktop) 0x05, 0x01, // Usage PAGE (Generic Desktop)
0x09, 0x30, // Usage (X) 0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y) 0x09, 0x31, // Usage (Y)
0x15, 0x81, // Logical Minimum (-127) 0x16, 0x01, 0x80, // Logical Minimum (-32 767)
0x25, 0x7f, // Logical Maximum (127) 0x26, 0xFF, 0x7F, // Logical Maximum (32 767)
0x75, 0x08, // Report Size (8) 0x75, 0x10, // Report Size (16)
0x95, 0x02, // Report Count (2) 0x95, 0x02, // Report Count (2)
0x81, 0x06, // Input (Data,Var,Rel) 0x81, 0x06, // Input (Data,Var,Rel)
/*
// Vertical Wheel // Vertical Wheel
// - Multiplier (2 bits) // - Multiplier (2 bits)
0xa1, 0x02, // Collection (Logical) 0xa1, 0x02, // Collection (Logical)
@ -377,6 +378,7 @@ static uint8_t mouse_report_desc[] = {
0x81, 0x06, // Input (Data,Var,Rel) 0x81, 0x06, // Input (Data,Var,Rel)
0xc0, // End Collection - Horizontal Wheel 0xc0, // End Collection - Horizontal Wheel
*/
0xc0, // End Collection - Buttons 0xc0, // End Collection - Buttons
0xc0, // End Collection - Mouse Logical 0xc0, // End Collection - Mouse Logical
0xc0 // End Collection - Mouse Application 0xc0 // End Collection - Mouse Application

View File

@ -171,18 +171,18 @@ void usb_mouse_send()
transmit_previous_timeout = 0; transmit_previous_timeout = 0;
// Prepare USB Mouse Packet // Prepare USB Mouse Packet
// TODO Document each byte
// TODO Dynamically generate this code based on KLL requirements // TODO Dynamically generate this code based on KLL requirements
*(tx_packet->buf + 0) = USBMouse_Buttons; uint16_t *packet_data = (uint16_t*)(&tx_packet->buf[0]);
*(tx_packet->buf + 1) = 0; packet_data[0] = USBMouse_Buttons;
*(tx_packet->buf + 2) = 0; packet_data[1] = USBMouse_Relative_x;
*(tx_packet->buf + 3) = 0; packet_data[2] = USBMouse_Relative_y;
*(tx_packet->buf + 4) = 0; tx_packet->len = 6;
tx_packet->len = 5;
usb_tx( MOUSE_ENDPOINT, tx_packet ); usb_tx( MOUSE_ENDPOINT, tx_packet );
// Clear status and state // Clear status and state
USBMouse_Buttons = 0; USBMouse_Buttons = 0;
USBMouse_Relative_x = 0;
USBMouse_Relative_y = 0;
USBMouse_Changed = 0; USBMouse_Changed = 0;
} }

View File

@ -1,10 +1,10 @@
Name = pjrcUSBCapabilities; Name = pjrcUSBCapabilities;
Version = 0.7; Version = 0.8;
Author = "HaaTa (Jacob Alexander) 2014-2016"; Author = "HaaTa (Jacob Alexander) 2014-2016";
KLL = 0.3d; KLL = 0.3d;
# Modified Date # Modified Date
Date = 2016-03-20; Date = 2016-03-21;
# Output capabilities # Output capabilities
@ -12,7 +12,7 @@ consCtrlOut => Output_consCtrlSend_capability( consCode : 2 );
noneOut => Output_noneSend_capability(); noneOut => Output_noneSend_capability();
sysCtrlOut => Output_sysCtrlSend_capability( sysCode : 1 ); sysCtrlOut => Output_sysCtrlSend_capability( sysCode : 1 );
usbKeyOut => Output_usbCodeSend_capability( usbCode : 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 # Configuration capabilities
kbdProtocolBoot => Output_kbdProtocolBoot_capability(); kbdProtocolBoot => Output_kbdProtocolBoot_capability();

View File

@ -119,6 +119,10 @@ volatile uint8_t USBKeys_LEDs = 0;
// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed // Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed
volatile uint16_t USBMouse_Buttons = 0; 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. // Protocol setting from the host.
// 0 - Boot Mode // 0 - Boot Mode
// 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) // 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; USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None;
// Indicate if USB should send update // 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 // the idle configuration, how often we send the report to the
// host (ms * 4) even when it hasn't changed // 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 // Sends a mouse command over the USB Output buffer
// XXX This function *will* be changing in the future // 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) // 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 ) void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args )
{ {
// Display capability name // Display capability name
if ( stateType == 0xFF && state == 0xFF ) if ( stateType == 0xFF && state == 0xFF )
{ {
print("Output_usbMouse(mouseButton)"); print("Output_usbMouse(mouseButton,relX,relY)");
return; return;
} }
@ -537,25 +543,38 @@ void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args
// 3 - Button 3 - (Tertiary) // 3 - Button 3 - (Tertiary)
uint16_t mouse_button = *(uint16_t*)(&args[0]); uint16_t mouse_button = *(uint16_t*)(&args[0]);
// If set to zero, ignore // X/Y Relative Axis
if ( mouse_button == 0 ) uint16_t mouse_x = *(uint16_t*)(&args[2]);
return; uint16_t mouse_y = *(uint16_t*)(&args[4]);
// Adjust for bit shift // 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 // Only send mouse button if in press or hold state
if ( stateType == 0x00 && state == 0x03 ) // Release state if ( stateType == 0x00 && state == 0x03 ) // Release state
{ {
USBMouse_Buttons &= ~(1 << mouse_button); // Release
if ( mouse_button )
USBMouse_Buttons &= ~(1 << mouse_button_shift);
} }
else 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 // Trigger updates
USBMouse_Changed = 1; if ( mouse_button )
USBMouse_Changed |= USBMouseChangeState_Buttons;
if ( mouse_x || mouse_y )
USBMouse_Changed |= USBMouseChangeState_Relative;
} }

View File

@ -56,6 +56,14 @@ typedef enum USBKeyChangeState {
USBKeyChangeState_All = 0x7F, USBKeyChangeState_All = 0x7F,
} USBKeyChangeState; } 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 ----- // ----- 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 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_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) // Misc variables (XXX Some are only properly utilized using AVR)
extern uint8_t USBKeys_Idle_Config; extern uint8_t USBKeys_Idle_Config;
extern uint8_t USBKeys_Idle_Count; extern uint8_t USBKeys_Idle_Count;
extern USBKeyChangeState USBKeys_Changed; extern USBKeyChangeState USBKeys_Changed;
extern uint8_t USBMouse_Changed; extern USBMouseChangeState USBMouse_Changed;
extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working