comparison Output/pjrcUSB/output_com.c @ 430:d3cef419c849

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)
author Jacob Alexander <haata@kiibohd.com>
date Mon, 21 Mar 2016 22:23:57 -0700
parents 970dab727f47
children 68e19d7c953e
comparison
equal deleted inserted replaced
429:970dab727f47 430:d3cef419c849
117 volatile uint8_t USBKeys_LEDs = 0; 117 volatile uint8_t USBKeys_LEDs = 0;
118 118
119 // Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed 119 // Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed
120 volatile uint16_t USBMouse_Buttons = 0; 120 volatile uint16_t USBMouse_Buttons = 0;
121 121
122 // Relative mouse axis movement, stores pending movement
123 volatile uint16_t USBMouse_Relative_x = 0;
124 volatile uint16_t USBMouse_Relative_y = 0;
125
122 // Protocol setting from the host. 126 // Protocol setting from the host.
123 // 0 - Boot Mode 127 // 0 - Boot Mode
124 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) 128 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface)
125 volatile uint8_t USBKeys_Protocol = USBProtocol_define; 129 volatile uint8_t USBKeys_Protocol = USBProtocol_define;
126 130
127 // Indicate if USB should send update 131 // Indicate if USB should send update
128 // OS only needs update if there has been a change in state 132 // OS only needs update if there has been a change in state
129 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; 133 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None;
130 134
131 // Indicate if USB should send update 135 // Indicate if USB should send update
132 uint8_t USBMouse_Changed = 0; 136 USBMouseChangeState USBMouse_Changed = 0;
133 137
134 // the idle configuration, how often we send the report to the 138 // the idle configuration, how often we send the report to the
135 // host (ms * 4) even when it hasn't changed 139 // host (ms * 4) even when it hasn't changed
136 uint8_t USBKeys_Idle_Config = 125; 140 uint8_t USBKeys_Idle_Config = 125;
137 141
517 } 521 }
518 522
519 // Sends a mouse command over the USB Output buffer 523 // Sends a mouse command over the USB Output buffer
520 // XXX This function *will* be changing in the future 524 // XXX This function *will* be changing in the future
521 // If you use it, be prepared that your .kll files will break in the future (post KLL 0.5) 525 // If you use it, be prepared that your .kll files will break in the future (post KLL 0.5)
522 // Argument #1: USB Mouse Button # 526 // Argument #1: USB Mouse Button (16 bit)
527 // Argument #2: USB X Axis (16 bit) relative
528 // Argument #3: USB Y Axis (16 bit) relative
523 void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args ) 529 void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args )
524 { 530 {
525 // Display capability name 531 // Display capability name
526 if ( stateType == 0xFF && state == 0xFF ) 532 if ( stateType == 0xFF && state == 0xFF )
527 { 533 {
528 print("Output_usbMouse(mouseButton)"); 534 print("Output_usbMouse(mouseButton,relX,relY)");
529 return; 535 return;
530 } 536 }
531 537
532 // Determine which mouse button was sent 538 // Determine which mouse button was sent
533 // The USB spec defines up to a max of 0xFFFF buttons 539 // The USB spec defines up to a max of 0xFFFF buttons
535 // 1 - Button 1 - (Primary) 541 // 1 - Button 1 - (Primary)
536 // 2 - Button 2 - (Secondary) 542 // 2 - Button 2 - (Secondary)
537 // 3 - Button 3 - (Tertiary) 543 // 3 - Button 3 - (Tertiary)
538 uint16_t mouse_button = *(uint16_t*)(&args[0]); 544 uint16_t mouse_button = *(uint16_t*)(&args[0]);
539 545
540 // If set to zero, ignore 546 // X/Y Relative Axis
541 if ( mouse_button == 0 ) 547 uint16_t mouse_x = *(uint16_t*)(&args[2]);
542 return; 548 uint16_t mouse_y = *(uint16_t*)(&args[4]);
543 549
544 // Adjust for bit shift 550 // Adjust for bit shift
545 mouse_button -= 1; 551 uint16_t mouse_button_shift = mouse_button - 1;
546 552
547 // Only send mouse button if in press or hold state 553 // Only send mouse button if in press or hold state
548 if ( stateType == 0x00 && state == 0x03 ) // Release state 554 if ( stateType == 0x00 && state == 0x03 ) // Release state
549 { 555 {
550 USBMouse_Buttons &= ~(1 << mouse_button); 556 // Release
557 if ( mouse_button )
558 USBMouse_Buttons &= ~(1 << mouse_button_shift);
551 } 559 }
552 else 560 else
553 { 561 {
554 USBMouse_Buttons |= (1 << mouse_button); 562 // Press or hold
555 } 563 if ( mouse_button )
556 564 USBMouse_Buttons |= (1 << mouse_button_shift);
557 // TODO Add more states when adding full support 565
558 USBMouse_Changed = 1; 566 if ( mouse_x )
567 USBMouse_Relative_x = mouse_x;
568 if ( mouse_y )
569 USBMouse_Relative_y = mouse_y;
570 }
571
572 // Trigger updates
573 if ( mouse_button )
574 USBMouse_Changed |= USBMouseChangeState_Buttons;
575
576 if ( mouse_x || mouse_y )
577 USBMouse_Changed |= USBMouseChangeState_Relative;
559 } 578 }
560 579
561 580
562 581
563 // ----- Functions ----- 582 // ----- Functions -----