Mercurial > louis > kiibohd-controller
annotate Output/usbMuxUart/output_com.c @ 309:4f47971c45c2
Merge remote-tracking branch 'upstream/master'
author | Rowan Decker <Smasher816@gmail.com> |
---|---|
date | Sun, 08 Mar 2015 20:17:39 -0700 |
parents | ab4515606277 7119c2149abb |
children | a6bafeb5fecf |
rev | line source |
---|---|
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
263
diff
changeset
|
1 /* Copyright (C) 2014-2015 by Jacob Alexander |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * Permission is hereby granted, free of charge, to any person obtaining a copy |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 * of this software and associated documentation files (the "Software"), to deal |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * in the Software without restriction, including without limitation the rights |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * copies of the Software, and to permit persons to whom the Software is |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * furnished to do so, subject to the following conditions: |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * The above copyright notice and this permission notice shall be included in |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * all copies or substantial portions of the Software. |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 * THE SOFTWARE. |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 */ |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 // ----- Includes ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 // Compiler Includes |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 #include <Lib/OutputLib.h> |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 // Project Includes |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 #include <cli.h> |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
29 #include <led.h> |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 #include <print.h> |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 #include <scan_loop.h> |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 // USB Includes |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) |
263
9afed592bcb5
Preparing for mk20dx256vlh7
Jacob Alexander <haata@kiibohd.com>
parents:
239
diff
changeset
|
35 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
36 #include <arm/uart_serial.h> |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
37 #include <arm/usb_dev.h> |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
38 #include <arm/usb_keyboard.h> |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
39 #include <arm/usb_serial.h> |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
40 #endif |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
41 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 // Local Includes |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 #include "output_com.h" |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
47 // ----- Macros ----- |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
48 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
49 // Used to build a bitmap lookup table from a byte addressable array |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
50 #define byteLookup( byte ) case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \ |
308 | 51 case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \ |
52 case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \ | |
53 case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \ | |
54 case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \ | |
55 case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \ | |
56 case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \ | |
57 case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break | |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
58 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
59 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
60 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 // ----- Function Declarations ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 void cliFunc_kbdProtocol( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 void cliFunc_readLEDs ( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 void cliFunc_readUART ( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
66 void cliFunc_sendKeys ( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 void cliFunc_sendUART ( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 void cliFunc_setKeys ( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 void cliFunc_setMod ( char* args ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
72 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 // ----- Variables ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 // Output Module command dictionary |
239
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
76 CLIDict_Entry( kbdProtocol, "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode" ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
77 CLIDict_Entry( readLEDs, "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc." ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
78 CLIDict_Entry( readUART, "Read UART buffer until empty." ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
79 CLIDict_Entry( sendKeys, "Send the prepared list of USB codes and modifier byte." ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
80 CLIDict_Entry( sendUART, "Send characters over UART0." ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
81 CLIDict_Entry( setKeys, "Prepare a space separated list of USB codes (decimal). Waits until \033[35msendKeys\033[0m." ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
82 CLIDict_Entry( setMod, "Set the modfier byte:" NL "\t\t1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI" ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
83 |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
84 CLIDict_Def( outputCLIDict, "USB Module Commands" ) = { |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
85 CLIDict_Item( kbdProtocol ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
86 CLIDict_Item( readLEDs ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
87 CLIDict_Item( readUART ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
88 CLIDict_Item( sendKeys ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
89 CLIDict_Item( sendUART ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
90 CLIDict_Item( setKeys ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
230
diff
changeset
|
91 CLIDict_Item( setMod ), |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
92 { 0, 0, 0 } // Null entry for dictionary end |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
93 }; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
95 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
96 // Which modifier keys are currently pressed |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
97 // 1=left ctrl, 2=left shift, 4=left alt, 8=left gui |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
98 // 16=right ctrl, 32=right shift, 64=right alt, 128=right gui |
308 | 99 uint8_t USBKeys_Modifiers = 0; |
100 uint8_t USBKeys_ModifiersCLI = 0; // Separate CLI send buffer | |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
101 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
102 // Currently pressed keys, max is defined by USB_MAX_KEY_SEND |
308 | 103 uint8_t USBKeys_Keys [USB_NKRO_BITFIELD_SIZE_KEYS]; |
104 uint8_t USBKeys_KeysCLI[USB_NKRO_BITFIELD_SIZE_KEYS]; // Separate CLI send buffer | |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
105 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
106 // System Control and Consumer Control 1KRO containers |
308 | 107 uint8_t USBKeys_SysCtrl; |
108 uint16_t USBKeys_ConsCtrl; | |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
110 // The number of keys sent to the usb in the array |
308 | 111 uint8_t USBKeys_Sent = 0; |
112 uint8_t USBKeys_SentCLI = 0; | |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
113 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
114 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
115 volatile uint8_t USBKeys_LEDs = 0; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
117 // Protocol setting from the host. |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
118 // 0 - Boot Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
119 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
120 volatile uint8_t USBKeys_Protocol = 0; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
121 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
122 // Indicate if USB should send update |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
123 // OS only needs update if there has been a change in state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
124 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
125 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
126 // the idle configuration, how often we send the report to the |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
127 // host (ms * 4) even when it hasn't changed |
308 | 128 uint8_t USBKeys_Idle_Config = 125; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
129 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
130 // count until idle timeout |
308 | 131 uint8_t USBKeys_Idle_Count = 0; |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
132 |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
263
diff
changeset
|
133 // Indicates whether the Output module is fully functional |
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
263
diff
changeset
|
134 // 0 - Not fully functional, 1 - Fully functional |
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
263
diff
changeset
|
135 // 0 is often used to show that a USB cable is not plugged in (but has power) |
308 | 136 uint8_t Output_Available = 0; |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
263
diff
changeset
|
137 |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
138 // Debug control variable for Output modules |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
139 // 0 - Debug disabled (default) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
140 // 1 - Debug enabled |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
141 uint8_t Output_DebugMode = 0; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
142 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
143 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
144 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
145 // ----- Capabilities ----- |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
146 |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
147 // Set Boot Keyboard Protocol |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
148 void Output_kbdProtocolBoot_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
149 { |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
150 // Display capability name |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
151 if ( stateType == 0xFF && state == 0xFF ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
152 { |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
153 print("Output_kbdProtocolBoot()"); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
154 return; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
155 } |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
156 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
157 // Only set if necessary |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
158 if ( USBKeys_Protocol == 0 ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
159 return; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
160 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
161 // TODO Analog inputs |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
162 // Only set on key press |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
163 if ( stateType != 0x01 ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
164 return; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
165 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
166 // Flush the key buffers |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
167 Output_flushBuffers(); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
168 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
169 // Set the keyboard protocol to Boot Mode |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
170 USBKeys_Protocol = 0; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
171 } |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
172 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
173 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
174 // Set NKRO Keyboard Protocol |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
175 void Output_kbdProtocolNKRO_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
176 { |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
177 // Display capability name |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
178 if ( stateType == 0xFF && state == 0xFF ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
179 { |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
180 print("Output_kbdProtocolNKRO()"); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
181 return; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
182 } |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
183 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
184 // Only set if necessary |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
185 if ( USBKeys_Protocol == 1 ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
186 return; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
187 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
188 // TODO Analog inputs |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
189 // Only set on key press |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
190 if ( stateType != 0x01 ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
191 return; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
192 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
193 // Flush the key buffers |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
194 Output_flushBuffers(); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
195 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
196 // Set the keyboard protocol to NKRO Mode |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
197 USBKeys_Protocol = 1; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
198 } |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
199 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
200 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
201 // Sends a Consumer Control code to the USB Output buffer |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
202 void Output_consCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
203 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
204 // Display capability name |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
205 if ( stateType == 0xFF && state == 0xFF ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
206 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
207 print("Output_consCtrlSend(consCode)"); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
208 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
209 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
210 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
211 // Not implemented in Boot Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
212 if ( USBKeys_Protocol == 0 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
213 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
214 warn_print("Consumer Control is not implemented for Boot Mode"); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
215 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
216 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
217 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
218 // TODO Analog inputs |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
219 // Only indicate USB has changed if either a press or release has occured |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
220 if ( state == 0x01 || state == 0x03 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
221 USBKeys_Changed |= USBKeyChangeState_Consumer; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
222 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
223 // Only send keypresses if press or hold state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
224 if ( stateType == 0x00 && state == 0x03 ) // Release state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
225 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
226 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
227 // Set consumer control code |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
228 USBKeys_ConsCtrl = *(uint16_t*)(&args[0]); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
229 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
230 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
231 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
232 // Sends a System Control code to the USB Output buffer |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
233 void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
234 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
235 // Display capability name |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
236 if ( stateType == 0xFF && state == 0xFF ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
237 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
238 print("Output_sysCtrlSend(sysCode)"); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
239 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
240 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
241 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
242 // Not implemented in Boot Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
243 if ( USBKeys_Protocol == 0 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
244 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
245 warn_print("System Control is not implemented for Boot Mode"); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
246 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
247 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
248 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
249 // TODO Analog inputs |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
250 // Only indicate USB has changed if either a press or release has occured |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
251 if ( state == 0x01 || state == 0x03 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
252 USBKeys_Changed |= USBKeyChangeState_System; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
253 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
254 // Only send keypresses if press or hold state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
255 if ( stateType == 0x00 && state == 0x03 ) // Release state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
256 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
257 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
258 // Set system control code |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
259 USBKeys_SysCtrl = args[0]; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
260 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
261 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
262 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
263 // Adds a single USB Code to the USB Output buffer |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
264 // Argument #1: USB Code |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
265 void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
266 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
267 // Display capability name |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
268 if ( stateType == 0xFF && state == 0xFF ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
269 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
270 print("Output_usbCodeSend(usbCode)"); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
271 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
272 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
273 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
274 // Depending on which mode the keyboard is in the USB needs Press/Hold/Release events |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
275 uint8_t keyPress = 0; // Default to key release, only used for NKRO |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
276 switch ( USBKeys_Protocol ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
277 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
278 case 0: // Boot Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
279 // TODO Analog inputs |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
280 // Only indicate USB has changed if either a press or release has occured |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
281 if ( state == 0x01 || state == 0x03 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
282 USBKeys_Changed = USBKeyChangeState_MainKeys; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
283 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
284 // Only send keypresses if press or hold state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
285 if ( stateType == 0x00 && state == 0x03 ) // Release state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
286 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
287 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
288 case 1: // NKRO Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
289 // Only send press and release events |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
290 if ( stateType == 0x00 && state == 0x02 ) // Hold state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
291 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
292 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
293 // Determine if setting or unsetting the bitfield (press == set) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
294 if ( stateType == 0x00 && state == 0x01 ) // Press state |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
295 keyPress = 1; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
296 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
297 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
298 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
299 // Get the keycode from arguments |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
300 uint8_t key = args[0]; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
301 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
302 // Depending on which mode the keyboard is in, USBKeys_Keys array is used differently |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
303 // Boot mode - Maximum of 6 byte codes |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
304 // NKRO mode - Each bit of the 26 byte corresponds to a key |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
305 // Bits 0 - 160 (first 20 bytes) correspond to USB Codes 4 - 164 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
306 // Bits 161 - 205 (last 6 bytes) correspond to USB Codes 176 - 221 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
307 // Bits 206 - 208 (last byte) correspond to the 3 padded bits in USB (unused) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
308 uint8_t bytePosition = 0; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
309 uint8_t byteShift = 0; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
310 switch ( USBKeys_Protocol ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
311 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
312 case 0: // Boot Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
313 // Set the modifier bit if this key is a modifier |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
314 if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
315 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
316 USBKeys_Modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
317 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
318 // Normal USB Code |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
319 else |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
320 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
321 // USB Key limit reached |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
322 if ( USBKeys_Sent >= USB_BOOT_MAX_KEYS ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
323 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
324 warn_print("USB Key limit reached"); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
325 return; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
326 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
327 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
328 // Make sure key is within the USB HID range |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
329 if ( key <= 104 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
330 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
331 USBKeys_Keys[USBKeys_Sent++] = key; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
332 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
333 // Invalid key |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
334 else |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
335 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
336 warn_msg("USB Code above 104/0x68 in Boot Mode: "); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
337 printHex( key ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
338 print( NL ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
339 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
340 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
341 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
342 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
343 case 1: // NKRO Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
344 // Set the modifier bit if this key is a modifier |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
345 if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
346 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
347 if ( keyPress ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
348 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
349 USBKeys_Modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
350 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
351 else // Release |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
352 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
353 USBKeys_Modifiers &= ~(1 << (key ^ 0xE0)); // Left shift 1 by key XOR 0xE0 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
354 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
355 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
356 USBKeys_Changed |= USBKeyChangeState_Modifiers; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
357 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
358 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
359 // First 20 bytes |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
360 else if ( key >= 4 && key <= 164 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
361 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
362 // Lookup (otherwise division or multiple checks are needed to do alignment) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
363 uint8_t keyPos = key - 4; // Starting position in array |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
364 switch ( keyPos ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
365 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
366 byteLookup( 0 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
367 byteLookup( 1 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
368 byteLookup( 2 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
369 byteLookup( 3 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
370 byteLookup( 4 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
371 byteLookup( 5 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
372 byteLookup( 6 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
373 byteLookup( 7 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
374 byteLookup( 8 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
375 byteLookup( 9 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
376 byteLookup( 10 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
377 byteLookup( 11 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
378 byteLookup( 12 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
379 byteLookup( 13 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
380 byteLookup( 14 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
381 byteLookup( 15 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
382 byteLookup( 16 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
383 byteLookup( 17 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
384 byteLookup( 18 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
385 byteLookup( 19 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
386 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
387 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
388 USBKeys_Changed |= USBKeyChangeState_MainKeys; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
389 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
390 // Last 6 bytes |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
391 else if ( key >= 176 && key <= 221 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
392 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
393 // Lookup (otherwise division or multiple checks are needed to do alignment) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
394 uint8_t keyPos = key - 176; // Starting position in array |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
395 switch ( keyPos ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
396 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
397 byteLookup( 20 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
398 byteLookup( 21 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
399 byteLookup( 22 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
400 byteLookup( 23 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
401 byteLookup( 24 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
402 byteLookup( 25 ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
403 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
404 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
405 USBKeys_Changed |= USBKeyChangeState_SecondaryKeys; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
406 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
407 // Invalid key |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
408 else |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
409 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
410 warn_msg("USB Code not within 4-164 (0x4-0xA4) or 176-221 (0xB0-0xDD) NKRO Mode: "); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
411 printHex( key ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
412 print( NL ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
413 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
414 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
415 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
416 // Set/Unset |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
417 if ( keyPress ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
418 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
419 USBKeys_Keys[bytePosition] |= (1 << byteShift); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
420 USBKeys_Sent++; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
421 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
422 else // Release |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
423 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
424 USBKeys_Keys[bytePosition] &= ~(1 << byteShift); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
425 USBKeys_Sent++; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
426 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
427 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
428 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
429 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
430 } |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
431 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
432 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
433 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
434 // ----- Functions ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
435 |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
436 // Flush Key buffers |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
437 void Output_flushBuffers() |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
438 { |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
439 // Zero out USBKeys_Keys array |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
440 for ( uint8_t c = 0; c < USB_NKRO_BITFIELD_SIZE_KEYS; c++ ) |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
441 USBKeys_Keys[ c ] = 0; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
442 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
443 // Zero out other key buffers |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
444 USBKeys_ConsCtrl = 0; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
445 USBKeys_Modifiers = 0; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
446 USBKeys_SysCtrl = 0; |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
447 } |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
448 |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
449 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
450 // USB Module Setup |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
451 inline void Output_setup() |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
452 { |
230
d81ad399c14f
Adding clear screen before usb initializes
Jacob Alexander <haata@kiibohd.com>
parents:
227
diff
changeset
|
453 // Setup UART |
d81ad399c14f
Adding clear screen before usb initializes
Jacob Alexander <haata@kiibohd.com>
parents:
227
diff
changeset
|
454 uart_serial_setup(); |
d81ad399c14f
Adding clear screen before usb initializes
Jacob Alexander <haata@kiibohd.com>
parents:
227
diff
changeset
|
455 print("\033[2J"); // Clear screen |
d81ad399c14f
Adding clear screen before usb initializes
Jacob Alexander <haata@kiibohd.com>
parents:
227
diff
changeset
|
456 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
457 // Initialize the USB, and then wait for the host to set configuration. |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
458 // This will hang forever if USB does not initialize |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
459 usb_init(); |
175 | 460 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
461 while ( !usb_configured() ); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
462 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
463 // Register USB Output CLI dictionary |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
464 CLI_registerDictionary( outputCLIDict, outputCLIDictName ); |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
465 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
466 // Zero out USBKeys_Keys array |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
467 for ( uint8_t c = 0; c < USB_NKRO_BITFIELD_SIZE_KEYS; c++ ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
468 USBKeys_Keys[ c ] = 0; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
469 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
470 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 // USB Data Send |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
473 inline void Output_send() |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
474 { |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
475 // Boot Mode Only, unset stale keys |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
476 if ( USBKeys_Protocol == 0 ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
477 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
478 USBKeys_Keys[c] = 0; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
479 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
480 // Send keypresses while there are pending changes |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
481 while ( USBKeys_Changed ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
482 usb_keyboard_send(); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
483 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
484 // Clear modifiers and keys |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
485 USBKeys_Modifiers = 0; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
486 USBKeys_Sent = 0; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
487 |
186
50702debf278
Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
178
diff
changeset
|
488 // Signal Scan Module we are finished |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
489 switch ( USBKeys_Protocol ) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
490 { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
491 case 0: // Boot Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
492 Scan_finishedWithOutput( USBKeys_Sent <= USB_BOOT_MAX_KEYS ? USBKeys_Sent : USB_BOOT_MAX_KEYS ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
493 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
494 case 1: // NKRO Mode |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
495 Scan_finishedWithOutput( USBKeys_Sent ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
496 break; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
497 } |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
498 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
499 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
500 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
501 // Sets the device into firmware reload mode |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
502 inline void Output_firmwareReload() |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
503 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
504 uart_device_reload(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
505 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
506 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
507 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
508 // USB Input buffer available |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
509 inline unsigned int Output_availablechar() |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
510 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
511 return usb_serial_available() + uart_serial_available(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
512 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
513 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
514 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
515 // USB Get Character from input buffer |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
516 inline int Output_getchar() |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
517 { |
178
555d70c6764d
Removing unnecessary ifdefs
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
518 // XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes) (AVR) |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
519 if ( usb_serial_available() > 0 ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
520 { |
178
555d70c6764d
Removing unnecessary ifdefs
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
521 return (int)usb_serial_getchar(); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
522 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
523 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
524 if ( uart_serial_available() > 0 ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
525 { |
178
555d70c6764d
Removing unnecessary ifdefs
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
526 return (int)uart_serial_getchar(); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
527 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
528 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
529 return -1; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
530 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
531 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
532 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
533 // USB Send Character to output buffer |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
534 inline int Output_putchar( char c ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
535 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
536 // First send to UART |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
537 uart_serial_putchar( c ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
538 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
539 // Then send to USB |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
540 return usb_serial_putchar( c ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
541 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
543 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
544 // USB Send String to output buffer, null terminated |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
545 inline int Output_putstr( char* str ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
546 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
547 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR |
178
555d70c6764d
Removing unnecessary ifdefs
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
548 uint16_t count = 0; |
263
9afed592bcb5
Preparing for mk20dx256vlh7
Jacob Alexander <haata@kiibohd.com>
parents:
239
diff
changeset
|
549 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
550 uint32_t count = 0; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
551 #endif |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
552 // Count characters until NULL character, then send the amount counted |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
553 while ( str[count] != '\0' ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
554 count++; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
555 |
173
afd0f94023ff
Fixed bug with standalone UART CLI
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
556 // First send to UART |
afd0f94023ff
Fixed bug with standalone UART CLI
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
557 uart_serial_write( str, count ); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
558 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
559 // Then send to USB |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
560 return usb_serial_write( str, count ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
561 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
562 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
563 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
564 // Soft Chip Reset |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
565 inline void Output_softReset() |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
566 { |
178
555d70c6764d
Removing unnecessary ifdefs
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
567 usb_device_software_reset(); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
568 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
569 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
570 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
571 // ----- CLI Command Functions ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
572 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
573 void cliFunc_kbdProtocol( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
574 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
575 print( NL ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
576 info_msg("Keyboard Protocol: "); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
577 printInt8( USBKeys_Protocol ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
578 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
579 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
580 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
581 void cliFunc_readLEDs( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
582 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
583 print( NL ); |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
584 info_msg("LED State: "); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
585 printInt8( USBKeys_LEDs ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
586 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
587 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
588 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
589 void cliFunc_readUART( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
590 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
591 print( NL ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
592 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
593 // Read UART buffer until empty |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
594 while ( uart_serial_available() > 0 ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
595 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
596 char out[] = { (char)uart_serial_getchar(), '\0' }; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 dPrint( out ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
598 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
599 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
600 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
601 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
602 void cliFunc_sendKeys( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
603 { |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
604 // Copy USBKeys_KeysCLI to USBKeys_Keys |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
605 for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
606 { |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
607 // TODO |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
608 //USBKeys_Keys[key] = USBKeys_KeysCLI[key]; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
609 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
610 USBKeys_Sent = USBKeys_SentCLI; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
611 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
612 // Set modifier byte |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
613 USBKeys_Modifiers = USBKeys_ModifiersCLI; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
614 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
615 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
616 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
617 void cliFunc_sendUART( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
618 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
619 // Write all args to UART |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
620 uart_serial_write( args, lenStr( args ) ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
621 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
622 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
623 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
624 void cliFunc_setKeys( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
625 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
626 char* curArgs; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 char* arg1Ptr; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
628 char* arg2Ptr = args; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
629 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
630 // Parse up to USBKeys_MaxSize args (whichever is least) |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
631 for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USB_BOOT_MAX_KEYS; ++USBKeys_SentCLI ) |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
632 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
633 curArgs = arg2Ptr; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
634 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
635 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
636 // Stop processing args if no more are found |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
637 if ( *arg1Ptr == '\0' ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
638 break; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
639 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
640 // Add the USB code to be sent |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
641 // TODO |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
195
diff
changeset
|
642 //USBKeys_KeysCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
643 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
644 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
645 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
646 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
647 void cliFunc_setMod( char* args ) |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 { |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
649 // Parse number from argument |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
650 // NOTE: Only first argument is used |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
651 char* arg1Ptr; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
652 char* arg2Ptr; |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
653 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
654 |
195
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
655 USBKeys_ModifiersCLI = numToInt( arg1Ptr ); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
656 } |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
657 |