Mercurial > louis > kiibohd-controller
annotate Output/usbMuxUart/output_com.h @ 340:e8841d3c6db5
mk20dx256vlh7 working!
- Interrupt vector table position fix (affected everything in the firmware)
- Added fault debug messages
- Fixed usbMuxUart
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 13 Jun 2015 20:42:12 -0700 |
parents | 7119c2149abb |
children |
rev | line source |
---|---|
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
245
diff
changeset
|
1 /* Copyright (C) 2013-2015 by Jacob Alexander |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * Permission is hereby granted, free of charge, to any person obtaining a copy |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 * of this software and associated documentation files (the "Software"), to deal |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * in the Software without restriction, including without limitation the rights |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * copies of the Software, and to permit persons to whom the Software is |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * furnished to do so, subject to the following conditions: |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * The above copyright notice and this permission notice shall be included in |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * all copies or substantial portions of the Software. |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 * THE SOFTWARE. |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 */ |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 #ifndef __output_com_h |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 #define __output_com_h |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 // ----- Includes ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 // Compiler Includes |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 #include <stdint.h> |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 // Local Includes |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 #include <buildvars.h> // Defines USB Parameters, partially generated by CMake |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 // ----- Defines ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
37 // Max size of key buffer needed for NKRO |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
38 // Boot mode uses only the first 6 bytes |
340 | 39 #define USB_NKRO_BITFIELD_SIZE_KEYS 27 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
40 #define USB_BOOT_MAX_KEYS 6 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
41 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
42 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
43 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
44 // ----- Enumerations ----- |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
45 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
46 // USB NKRO state transitions (indicates which Report ID's need refreshing) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
47 // Boot mode just checks if any keys were changed (as everything is sent every time) |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
48 typedef enum USBKeyChangeState { |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
49 USBKeyChangeState_None = 0x00, |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
50 USBKeyChangeState_Modifiers = 0x01, |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
51 USBKeyChangeState_MainKeys = 0x02, |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
52 USBKeyChangeState_SecondaryKeys = 0x04, |
245
02cdd66d8856
Fixing pjrc bug affecting Mac OSX CDC driver
Jacob Alexander <haata@kiibohd.com>
parents:
227
diff
changeset
|
53 USBKeyChangeState_TertiaryKeys = 0x08, |
340 | 54 USBKeyChangeState_QuartiaryKeys = 0x10, |
55 USBKeyChangeState_System = 0x20, | |
56 USBKeyChangeState_Consumer = 0x40, | |
57 USBKeyChangeState_All = 0x7F, | |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
58 } USBKeyChangeState; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 // ----- Variables ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 // Variables used to communciate to the output module |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 // XXX Even if the output module is not USB, this is internally understood keymapping scheme |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
66 extern uint8_t USBKeys_Modifiers; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
67 extern uint8_t USBKeys_Keys[USB_NKRO_BITFIELD_SIZE_KEYS]; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
68 extern uint8_t USBKeys_Sent; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
69 extern volatile uint8_t USBKeys_LEDs; |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
71 extern uint8_t USBKeys_SysCtrl; // 1KRO container for System Control HID table |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
72 extern uint16_t USBKeys_ConsCtrl; // 1KRO container for Consumer Control HID table |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
73 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
74 extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 // Misc variables (XXX Some are only properly utilized using AVR) |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
77 extern uint8_t USBKeys_Idle_Config; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
78 extern uint8_t USBKeys_Idle_Count; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
79 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
80 extern USBKeyChangeState USBKeys_Changed; |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
81 |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
245
diff
changeset
|
82 extern uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working |
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
245
diff
changeset
|
83 |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
84 extern uint8_t Output_DebugMode; // 0 - Debug disabled, 1 - Debug enabled |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
85 |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
86 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
87 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
88 // ----- Capabilities ----- |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
89 |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
90 void Output_consCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ); |
340 | 91 void Output_noneSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ); |
227
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
92 void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ); |
ed05fa3555d4
Updating usbMuxUart for NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
172
diff
changeset
|
93 void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ); |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
95 // Configuration capabilities |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
96 void Output_kbdProtocolBoot_capability( uint8_t state, uint8_t stateType, uint8_t *args ); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
97 void Output_kbdProtocolNKRO_capability( uint8_t state, uint8_t stateType, uint8_t *args ); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
98 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
99 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
100 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
101 // ----- Functions ----- |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
102 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
103 void Output_setup(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
104 void Output_send(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
105 |
300
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
106 void Output_flushBuffers(); |
7119c2149abb
Fixing compiler errors for usbMuxUart Output module
Jacob Alexander <haata@kiibohd.com>
parents:
275
diff
changeset
|
107 |
172
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
108 void Output_firmwareReload(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 void Output_softReset(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
110 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
111 // Relies on USB serial module |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
112 unsigned int Output_availablechar(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
113 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
114 int Output_getchar(); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
115 int Output_putchar( char c ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 int Output_putstr( char* str ); |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
117 |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
118 #endif |
a30bddad4115
Adding UART and UART + USB muxed CLI output.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
119 |