annotate Output/pjrcUSB/output_com.c @ 218:78e89528487f

Fixing USB send rate. - Only send USB events when something changes (rather than every ms)
author Jacob Alexander <haata@kiibohd.com>
date Fri, 19 Sep 2014 19:11:37 -0700
parents 2794931a4d30
children fc3b9cb190cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
122
2bb16439e6ca Preparing Teensy 3.1 and CLI merge for DPH controller code.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
1 /* Copyright (C) 2011-2014 by Jacob Alexander
2bb16439e6ca Preparing Teensy 3.1 and CLI merge for DPH controller code.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
2 *
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
122
2bb16439e6ca Preparing Teensy 3.1 and CLI merge for DPH controller code.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
9 *
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
122
2bb16439e6ca Preparing Teensy 3.1 and CLI merge for DPH controller code.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
12 *
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
19 * THE SOFTWARE.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
20 */
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22 // ----- Includes -----
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
24 // Compiler Includes
118
b61ca96b7c24 File and macro modifications for supporting Teensy 3.1
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
25 #include <Lib/OutputLib.h>
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27 // Project Includes
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
28 #include <cli.h>
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
29 #include <led.h>
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
30 #include <print.h>
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
31 #include <scan_loop.h>
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
32
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33 // USB Includes
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
35 #include "avr/usb_keyboard_serial.h"
169
7962a42dbda0 Initial work for McHCK mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 165
diff changeset
36 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
132
e08d7b586ea3 Adding analog.c lib from teensyduino.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
37 #include "arm/usb_dev.h"
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38 #include "arm/usb_keyboard.h"
132
e08d7b586ea3 Adding analog.c lib from teensyduino.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
39 #include "arm/usb_serial.h"
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40 #endif
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42 // Local Includes
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43 #include "output_com.h"
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
45
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
47 // ----- Function Declarations -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
48
165
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
49 void cliFunc_kbdProtocol( char* args );
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
50 void cliFunc_readLEDs ( char* args );
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
51 void cliFunc_sendKeys ( char* args );
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
52 void cliFunc_setKeys ( char* args );
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
53 void cliFunc_setMod ( char* args );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
54
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
55
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56 // ----- Variables -----
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
57
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
58 // Output Module command dictionary
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
59 const char outputCLIDictName[] = "USB Module Commands";
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
60 const CLIDictItem outputCLIDict[] = {
165
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
61 { "kbdProtocol", "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode", cliFunc_kbdProtocol },
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
62 { "readLEDs", "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc.", cliFunc_readLEDs },
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
63 { "sendKeys", "Send the prepared list of USB codes and modifier byte.", cliFunc_sendKeys },
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
64 { "setKeys", "Prepare a space separated list of USB codes (decimal). Waits until \033[35msendKeys\033[0m.", cliFunc_setKeys },
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
65 { "setMod", "Set the modfier byte:" NL "\t\t1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI", cliFunc_setMod },
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
66 { 0, 0, 0 } // Null entry for dictionary end
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
67 };
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
68
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
69
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
70 // Which modifier keys are currently pressed
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
71 // 1=left ctrl, 2=left shift, 4=left alt, 8=left gui
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
72 // 16=right ctrl, 32=right shift, 64=right alt, 128=right gui
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
73 uint8_t USBKeys_Modifiers = 0;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
74 uint8_t USBKeys_ModifiersCLI = 0; // Separate CLI send buffer
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
76 // Currently pressed keys, max is defined by USB_MAX_KEY_SEND
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
77 uint8_t USBKeys_Array [USB_MAX_KEY_SEND];
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
78 uint8_t USBKeys_ArrayCLI[USB_MAX_KEY_SEND]; // Separate CLI send buffer
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
79
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
80 // The number of keys sent to the usb in the array
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
81 uint8_t USBKeys_Sent = 0;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
82 uint8_t USBKeys_SentCLI = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
83
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85 volatile uint8_t USBKeys_LEDs = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86
165
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
87 // Protocol setting from the host.
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
88 // 0 - Boot Mode (Default, until set by the host)
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
89 // 1 - NKRO Mode
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
90 volatile uint8_t USBKeys_Protocol = 1;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
91
218
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
92 // Indicate if USB should send update
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
93 // OS only needs update if there has been a change in state
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
94 uint8_t USBKeys_Changed = 0;
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
95
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
96 // the idle configuration, how often we send the report to the
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97 // host (ms * 4) even when it hasn't changed
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98 uint8_t USBKeys_Idle_Config = 125;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
100 // count until idle timeout
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101 uint8_t USBKeys_Idle_Count = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
102
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
103
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
104 // ----- Capabilities -----
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
105
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
106 // Adds a single USB Code to the USB Output buffer
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
107 // Argument #1: USB Code
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
108 void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
109 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
110 // Display capability name
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
111 if ( stateType == 0xFF && state == 0xFF )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
112 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
113 print("Output_usbCodeSend(usbCode)");
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
114 return;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
115 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
116
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 195
diff changeset
117 // TODO Analog inputs
218
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
118 // Only indicate USB has changed if either a press or release has occured
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
119 if ( state == 0x01 || state == 0x03 )
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
120 USBKeys_Changed = 1;
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
121
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 195
diff changeset
122 // Only send keypresses if press or hold state
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 195
diff changeset
123 if ( stateType == 0x00 && state == 0x03 ) // Release state
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 195
diff changeset
124 return;
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 195
diff changeset
125
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
126 // Get the keycode from arguments
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
127 uint8_t key = args[0];
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
128
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
129 // Set the modifier bit if this key is a modifier
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
130 if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier)
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
131 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
132 USBKeys_Modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
133 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
134 // Normal USB Code
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
135 else
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
136 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
137 // USB Key limit reached (important for Boot Mode)
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
138 if ( USBKeys_Sent >= USBKeys_MaxSize )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
139 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
140 warn_msg("USB Key limit reached");
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
141 errorLED( 1 );
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
142 return;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
143 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
144
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
145 USBKeys_Array[USBKeys_Sent++] = key;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
146 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
147 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
148
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
149
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
150
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
151 // ----- Functions -----
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
152
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
153 // USB Module Setup
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
154 inline void Output_setup()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
155 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
156 // Initialize the USB, and then wait for the host to set configuration.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
157 // If the Teensy is powered without a PC connected to the USB port,
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
158 // this will wait forever.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
159 usb_init();
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
160
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
161 while ( !usb_configured() ) /* wait */ ;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
162
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
163 // Register USB Output CLI dictionary
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
164 CLI_registerDictionary( outputCLIDict, outputCLIDictName );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
165
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
166 // Wait an extra second for the PC's operating system to load drivers
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
167 // and do whatever it does to actually be ready for input
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
168 //_delay_ms(1000); // TODO (is this actually necessary?)
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
169 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
170
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
171
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
172 // USB Data Send
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
173 inline void Output_send(void)
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
174 {
218
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
175 // Don't send update if USB has not changed
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
176 if ( !USBKeys_Changed )
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
177 {
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
178 // Clear modifiers and keys
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
179 USBKeys_Modifiers = 0;
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
180 USBKeys_Sent = 0;
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
181
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
182 return;
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
183 }
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
184 USBKeys_Changed = 0;
78e89528487f Fixing USB send rate.
Jacob Alexander <haata@kiibohd.com>
parents: 212
diff changeset
185
171
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
186 // TODO undo potentially old keys
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
187 for ( uint8_t c = USBKeys_Sent; c < USBKeys_MaxSize; c++ )
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
188 USBKeys_Array[c] = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
189
171
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
190 // Send keypresses
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
191 usb_keyboard_send();
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
192
171
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
193 // Clear modifiers and keys
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
194 USBKeys_Modifiers = 0;
aeac00164f2e Initial code for ARM UART output module (mainly for CLI)
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
195 USBKeys_Sent = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
196
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents: 177
diff changeset
197 // Signal Scan Module we are finished
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents: 177
diff changeset
198 Scan_finishedWithOutput( USBKeys_Sent <= USBKeys_MaxSize ? USBKeys_Sent : USBKeys_MaxSize );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
199 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
200
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
201
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
202 // Sets the device into firmware reload mode
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
203 inline void Output_firmwareReload()
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
204 {
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
205 usb_device_reload();
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
206 }
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
207
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
208
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
209 // USB Input buffer available
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
210 inline unsigned int Output_availablechar()
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
211 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
212 return usb_serial_available();
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
213 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
214
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
215
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
216 // USB Get Character from input buffer
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
217 inline int Output_getchar()
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
218 {
177
3420e018ffbc Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
219 // XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes) (AVR)
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
220 return (int)usb_serial_getchar();
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
221 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
222
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
223
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
224 // USB Send Character to output buffer
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
225 inline int Output_putchar( char c )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
226 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
227 return usb_serial_putchar( c );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
228 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
229
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
230
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
231 // USB Send String to output buffer, null terminated
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
232 inline int Output_putstr( char* str )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
233 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
234 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
235 uint16_t count = 0;
169
7962a42dbda0 Initial work for McHCK mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 165
diff changeset
236 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
237 uint32_t count = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
238 #endif
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
239 // Count characters until NULL character, then send the amount counted
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
240 while ( str[count] != '\0' )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
241 count++;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
242
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
243 return usb_serial_write( str, count );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
244 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
245
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
246
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
247 // Soft Chip Reset
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
248 inline void Output_softReset()
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
249 {
177
3420e018ffbc Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
250 usb_device_software_reset();
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
251 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
252
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
253
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
254 // ----- CLI Command Functions -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
255
165
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
256 void cliFunc_kbdProtocol( char* args )
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
257 {
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
258 print( NL );
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
259 info_msg("Keyboard Protocol: ");
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
260 printInt8( USBKeys_Protocol );
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
261 }
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
262
0d992d26114f Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
263
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
264 void cliFunc_readLEDs( char* args )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
265 {
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
266 print( NL );
212
2794931a4d30 DPH controller now working with macros/layers
Jacob Alexander <haata@kiibohd.com>
parents: 201
diff changeset
267 info_msg("LED State: ");
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
268 printInt8( USBKeys_LEDs );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
269 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
270
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
271
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
272 void cliFunc_sendKeys( char* args )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
273 {
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
274 // Copy USBKeys_ArrayCLI to USBKeys_Array
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
275 for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key )
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
276 {
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
277 USBKeys_Array[key] = USBKeys_ArrayCLI[key];
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
278 }
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
279 USBKeys_Sent = USBKeys_SentCLI;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
280
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
281 // Set modifier byte
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
282 USBKeys_Modifiers = USBKeys_ModifiersCLI;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
283 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
284
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
285
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
286 void cliFunc_setKeys( char* args )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
287 {
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
288 char* curArgs;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
289 char* arg1Ptr;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
290 char* arg2Ptr = args;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
291
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
292 // Parse up to USBKeys_MaxSize args (whichever is least)
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
293 for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USBKeys_MaxSize; ++USBKeys_SentCLI )
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
294 {
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
295 curArgs = arg2Ptr;
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
296 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
297
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
298 // Stop processing args if no more are found
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
299 if ( *arg1Ptr == '\0' )
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
300 break;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
301
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
302 // Add the USB code to be sent
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
303 USBKeys_ArrayCLI[USBKeys_SentCLI] = numToInt( arg1Ptr );
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
304 }
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
305 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
306
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
307
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
308 void cliFunc_setMod( char* args )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
309 {
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
310 // Parse number from argument
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
311 // NOTE: Only first argument is used
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
312 char* arg1Ptr;
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
313 char* arg2Ptr;
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 124
diff changeset
314 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
124
2b81083dcaef Adding the CLI commands to the USB output module.
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
315
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
316 USBKeys_ModifiersCLI = numToInt( arg1Ptr );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
317 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
318