annotate Output/pjrcUSB/output_com.c @ 123:0c5d1fe99302

Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++ - Includes serial putchar and getchar cleanup (overall) - Moved avr-capsense to DPH (renaming) - Basic cleanup for including CLI on the avr architecture
author Jacob Alexander <haata@kiibohd.com>
date Mon, 31 Mar 2014 01:07:48 -0700
parents 2bb16439e6ca
children 2b81083dcaef
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>
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
29 #include <print.h>
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
30 #include <scan_loop.h>
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
31
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
32 // USB Includes
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33 #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
34 #include "avr/usb_keyboard_serial.h"
119
814b5d3d7da6 Finished USB for Teensy 3.1 (Now 3.1 compatible!)
Jacob Alexander <haata@kiibohd.com>
parents: 118
diff changeset
35 #elif defined(_mk20dx128_) || defined(_mk20dx256_)
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
36 #include "arm/usb_keyboard.h"
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37 #include "arm/usb_dev.h"
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38 #endif
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
39
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40 // Local Includes
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41 #include "output_com.h"
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44
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
45 // ----- 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
46
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 void cliFunc_holdKey ( 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
48 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
49 void cliFunc_releaseKey( 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
50 void cliFunc_sendKey ( 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
51 void cliFunc_setLEDs ( 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
52 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
53
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
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55 // ----- Variables -----
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56
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
57 // Output Module command dictionary
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 char* outputCLIDictName = "USB Module Commands";
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
59 CLIDictItem outputCLIDict[] = {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
60 { "holdKey", "Hold a space separated list of USB codes. Ignores already pressed keys.", cliFunc_holdKey },
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
61 { "readLEDs", "Read LED byte. See setLEDs.", cliFunc_readLEDs },
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
62 { "releaseKey", "Release a space separated list of USB codes. Ignores unpressed keys.", cliFunc_releaseKey },
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
63 { "sendKey", "Send a space separated list of USB codes. Press/Release.", cliFunc_sendKey },
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
64 { "setLEDs", "Set LED byte: 1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc.", cliFunc_setLEDs },
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
65 { "setMod", "Set the modfier byte: 1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI", cliFunc_setMod },
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
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
70 // which modifier keys are currently pressed
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
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
73 uint8_t USBKeys_Modifiers = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
74
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75 // which keys are currently pressed, up to 6 keys may be down at once
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
76 uint8_t USBKeys_Array[USB_MAX_KEY_SEND] = {0,0,0,0,0,0};
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
77
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
78 // The number of keys sent to the usb in the array
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
79 uint8_t USBKeys_Sent;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
80
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
81 // 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
82 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
83
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84 // protocol setting from the host. We use exactly the same report
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85 // either way, so this variable only stores the setting since we
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86 // are required to be able to report which setting is in use.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87 uint8_t USBKeys_Protocol = 1;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
88
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
89 // 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
90 // 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
91 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
92
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
93 // count until idle timeout
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
94 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
95
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
96
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97 // ----- Functions -----
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99 // USB Module Setup
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
100 inline void output_setup()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
102 // 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
103 // 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
104 // this will wait forever.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
105 usb_init();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
106 while ( !usb_configured() ) /* wait */ ;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
107
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
108 // Register USB Output dictionary
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
109 registerDictionary_cli( outputCLIDict, outputCLIDictName );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
110
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
111 // 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
112 // 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
113 //_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
114 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
115
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
116
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
117 // USB Data Send
122
2bb16439e6ca Preparing Teensy 3.1 and CLI merge for DPH controller code.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
118 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
119 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
120 // TODO undo potentially old keys
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
121 for ( uint8_t c = USBKeys_Sent; c < USBKeys_MaxSize; c++ )
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
122 USBKeys_Array[c] = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
123
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
124 // Send keypresses
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
125 usb_keyboard_send();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
126
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
127 // Clear modifiers and keys
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
128 USBKeys_Modifiers = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
129 USBKeys_Sent = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
130
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
131 // Signal Scan Module we are finishedA
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
132 scan_finishedWithUSBBuffer( USBKeys_Sent <= USBKeys_MaxSize ? USBKeys_Sent : USBKeys_MaxSize );
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
133 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
134
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
135
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
136 // Sets the device into firmware reload mode
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
137 inline void output_firmwareReload()
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
138 {
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
139 #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
140 usb_debug_reload();
119
814b5d3d7da6 Finished USB for Teensy 3.1 (Now 3.1 compatible!)
Jacob Alexander <haata@kiibohd.com>
parents: 118
diff changeset
141 #elif defined(_mk20dx128_) || defined(_mk20dx256_)
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
142 usb_device_reload();
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
143 #endif
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
144 }
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
145
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
146
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
147 // USB Input buffer 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
148 inline unsigned int output_availablechar()
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
149 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
150 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
151 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
152
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
153
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
154 // USB Get Character from input buffer
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
155 inline int output_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
156 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
157 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
158 // XXX Make sure to check output_availablechar() first! Information is lost with the cast (error codes)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
159 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
160 #elif defined(_mk20dx128_) || defined(_mk20dx256_)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
161 return 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
162 #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
163 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
164
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
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
166 // USB Send Character to output buffer
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
167 inline int output_putchar( char 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
168 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
169 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
170 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
171
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
172
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
173 // USB Send String to output buffer, null terminated
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
174 inline int output_putstr( char* str )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
175 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
176 #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
177 uint16_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
178 #elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
179 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
180 #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
181 // 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
182 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
183 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
184
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
185 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
186 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
187
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
188
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
189 // Soft Chip Reset
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
190 inline void output_softReset()
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
191 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
192 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
193 usb_debug_software_reset();
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
194 #elif defined(_mk20dx128_) || defined(_mk20dx256_)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
195 SOFTWARE_RESET();
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
196 #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
197 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
198
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
199
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
200 // ----- 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
201
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
202 void cliFunc_holdKey( 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
203 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
204 // TODO
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
205 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
206
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
207
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 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
209 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
210 // TODO
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
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 void cliFunc_releaseKey( 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
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 // TODO
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
217 }
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
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
219
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 void cliFunc_sendKey( 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
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 // TODO Argument handling
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 USBKeys_Array[0] = 4; // KEY_A
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 USBKeys_Sent = 1;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
225 }
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
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 void cliFunc_setLEDs( 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
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 // TODO
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 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
232
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 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
235 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
236 // TODO
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 }
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