Mercurial > louis > kiibohd-controller
comparison Output/pjrcUSB/output_com.c @ 429:970dab727f47
Adding basic mouse button support
- Full Mouse support will have to wait for KLL 0.6
* This will include dynamic HID descriptor generation for many wheels and axis depending on the KLL needs
- HID descriptor is currently limited to 8 buttons
- Technically mouse movement also works (tested by accident), but it's disable for now (needs some API thought)
- Adding additional udev rules
- Added KRO mode default define
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Mon, 21 Mar 2016 00:43:19 -0700 |
parents | 23a1868b4ac2 |
children | d3cef419c849 |
comparison
equal
deleted
inserted
replaced
428:b5746c43904e | 429:970dab727f47 |
---|---|
35 #include "avr/usb_keyboard_serial.h" | 35 #include "avr/usb_keyboard_serial.h" |
36 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) | 36 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) |
37 #include "arm/usb_dev.h" | 37 #include "arm/usb_dev.h" |
38 #include "arm/usb_keyboard.h" | 38 #include "arm/usb_keyboard.h" |
39 #include "arm/usb_serial.h" | 39 #include "arm/usb_serial.h" |
40 #include "arm/usb_mouse.h" | |
40 #endif | 41 #endif |
42 | |
43 // KLL | |
44 #include <kll_defs.h> | |
41 | 45 |
42 // Local Includes | 46 // Local Includes |
43 #include "output_com.h" | 47 #include "output_com.h" |
44 | 48 |
45 | 49 |
46 | 50 |
47 // ----- Macros ----- | 51 // ----- Macros ----- |
48 | 52 |
49 // Used to build a bitmap lookup table from a byte addressable array | 53 // Used to build a bitmap lookup table from a byte addressable array |
50 #define byteLookup( byte ) case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \ | 54 #define byteLookup( byte ) \ |
51 case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \ | 55 case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \ |
52 case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \ | 56 case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \ |
53 case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \ | 57 case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \ |
54 case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \ | 58 case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \ |
55 case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \ | 59 case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \ |
56 case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \ | 60 case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \ |
57 case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break | 61 case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \ |
62 case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break | |
58 | 63 |
59 | 64 |
60 | 65 |
61 // ----- Function Declarations ----- | 66 // ----- Function Declarations ----- |
62 | 67 |
109 uint8_t USBKeys_SentCLI = 0; | 114 uint8_t USBKeys_SentCLI = 0; |
110 | 115 |
111 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana | 116 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana |
112 volatile uint8_t USBKeys_LEDs = 0; | 117 volatile uint8_t USBKeys_LEDs = 0; |
113 | 118 |
119 // Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed | |
120 volatile uint16_t USBMouse_Buttons = 0; | |
121 | |
114 // Protocol setting from the host. | 122 // Protocol setting from the host. |
115 // 0 - Boot Mode | 123 // 0 - Boot Mode |
116 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) | 124 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) |
117 volatile uint8_t USBKeys_Protocol = 1; | 125 volatile uint8_t USBKeys_Protocol = USBProtocol_define; |
118 | 126 |
119 // Indicate if USB should send update | 127 // Indicate if USB should send update |
120 // OS only needs update if there has been a change in state | 128 // OS only needs update if there has been a change in state |
121 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; | 129 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; |
130 | |
131 // Indicate if USB should send update | |
132 uint8_t USBMouse_Changed = 0; | |
122 | 133 |
123 // the idle configuration, how often we send the report to the | 134 // the idle configuration, how often we send the report to the |
124 // host (ms * 4) even when it hasn't changed | 135 // host (ms * 4) even when it hasn't changed |
125 uint8_t USBKeys_Idle_Config = 125; | 136 uint8_t USBKeys_Idle_Config = 125; |
126 | 137 |
503 | 514 |
504 // Start flash mode | 515 // Start flash mode |
505 Output_firmwareReload(); | 516 Output_firmwareReload(); |
506 } | 517 } |
507 | 518 |
519 // Sends a mouse command over the USB Output buffer | |
520 // 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) | |
522 // Argument #1: USB Mouse Button # | |
523 void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args ) | |
524 { | |
525 // Display capability name | |
526 if ( stateType == 0xFF && state == 0xFF ) | |
527 { | |
528 print("Output_usbMouse(mouseButton)"); | |
529 return; | |
530 } | |
531 | |
532 // Determine which mouse button was sent | |
533 // The USB spec defines up to a max of 0xFFFF buttons | |
534 // The usual are: | |
535 // 1 - Button 1 - (Primary) | |
536 // 2 - Button 2 - (Secondary) | |
537 // 3 - Button 3 - (Tertiary) | |
538 uint16_t mouse_button = *(uint16_t*)(&args[0]); | |
539 | |
540 // If set to zero, ignore | |
541 if ( mouse_button == 0 ) | |
542 return; | |
543 | |
544 // Adjust for bit shift | |
545 mouse_button -= 1; | |
546 | |
547 // Only send mouse button if in press or hold state | |
548 if ( stateType == 0x00 && state == 0x03 ) // Release state | |
549 { | |
550 USBMouse_Buttons &= ~(1 << mouse_button); | |
551 } | |
552 else | |
553 { | |
554 USBMouse_Buttons |= (1 << mouse_button); | |
555 } | |
556 | |
557 // TODO Add more states when adding full support | |
558 USBMouse_Changed = 1; | |
559 } | |
560 | |
508 | 561 |
509 | 562 |
510 // ----- Functions ----- | 563 // ----- Functions ----- |
511 | 564 |
512 // Flush Key buffers | 565 // Flush Key buffers |
549 | 602 |
550 // Boot Mode Only, unset stale keys | 603 // Boot Mode Only, unset stale keys |
551 if ( USBKeys_Protocol == 0 ) | 604 if ( USBKeys_Protocol == 0 ) |
552 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) | 605 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) |
553 USBKeys_Keys[c] = 0; | 606 USBKeys_Keys[c] = 0; |
607 | |
608 // Process mouse actions | |
609 while ( USBMouse_Changed ) | |
610 usb_mouse_send(); | |
554 | 611 |
555 // Send keypresses while there are pending changes | 612 // Send keypresses while there are pending changes |
556 while ( USBKeys_Changed ) | 613 while ( USBKeys_Changed ) |
557 usb_keyboard_send(); | 614 usb_keyboard_send(); |
558 | 615 |