annotate Scan/MBC-55X/scan_loop.c @ 412:e7a3be42ae1e

Debug code for interconnect cable debugging
author Jacob Alexander <haata@kiibohd.com>
date Sat, 20 Feb 2016 13:27:49 -0800
parents 9afed592bcb5
children 48ede6680396
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
1 /* Copyright (C) 2013,2014 by Jacob Alexander
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
2 *
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
9 *
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
12 *
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
19 * THE SOFTWARE.
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
20 */
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
21
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
22 // ----- Includes -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
23
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
24 // Compiler Includes
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
25 #include <Lib/ScanLib.h>
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
26
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
27 // Project Includes
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
28 #include <led.h>
149
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
29 #include <macro.h>
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
30 #include <print.h>
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
31
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
32 // Local Includes
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
33 #include "scan_loop.h"
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
34
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
35
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
36
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
37 // ----- Defines -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
38
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
39
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
40 // ----- Macros -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
41
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
42
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
43
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
44 // ----- Variables -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
45
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
46 // Buffer used to inform the macro processing module which keys have been detected as pressed
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
47 volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
48 volatile uint8_t KeyIndex_BufferUsed;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
49
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
50
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
51
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
52 // ----- Function Declarations -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
53
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
54 void processKeyValue( uint8_t valueType );
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
55 void removeKeyValue( uint8_t keyValue );
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
56
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
57
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
58
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
59 // ----- Interrupt Functions -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
60
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
61 // UART Receive Buffer Full Interrupt
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
62 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
63 ISR(USART1_RX_vect)
263
9afed592bcb5 Preparing for mk20dx256vlh7
Jacob Alexander <haata@kiibohd.com>
parents: 149
diff changeset
64 #elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
65 void uart0_status_isr(void)
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
66 #endif
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
67 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
68 cli(); // Disable Interrupts
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
69
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
70 // Variable for UART data read
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
71 uint8_t keyValue = 0x00;
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
72
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
73 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
74 keyValue = UDR1;
263
9afed592bcb5 Preparing for mk20dx256vlh7
Jacob Alexander <haata@kiibohd.com>
parents: 149
diff changeset
75 #elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
76 // UART0_S1 must be read for the interrupt to be cleared
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
77 if ( UART0_S1 & UART_S1_RDRF )
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
78 {
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
79 // Only doing single byte FIFO here
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
80 keyValue = UART0_D;
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
81 }
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
82 #endif
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
83
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
84 // Debug
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
85 char tmpStr[6];
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
86 hexToStr( keyValue, tmpStr );
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
87 dPrintStrs( tmpStr, " " ); // Debug
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
88
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
89 // Decipher scan value
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
90 processKeyValue( keyValue );
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
91
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
92 sei(); // Re-enable Interrupts
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
93 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
94
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
95
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
96
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
97 // ----- Functions -----
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
98
149
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
99 // Reset Keyboard
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
100 void Scan_resetKeyboard( void )
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
101 {
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
102 // Not a calculated valued...
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
103 _delay_ms( 50 );
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
104
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
105 KeyIndex_BufferUsed = 0;
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
106 }
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
107
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
108 // Setup
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
109 inline void Scan_setup()
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
110 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
111 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
112 // Setup the the USART interface for keyboard data input
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
113
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
114 // Setup baud rate - 1205 Baud
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
115 // 16 MHz / ( 16 * Baud ) = UBRR
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
116 // Baud: 1205 -> 16 MHz / ( 16 * 1205 ) = 829.8755
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
117 // Thus baud setting = 830
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
118 uint16_t baud = 830; // Max setting of 4095
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
119 UBRR1H = (uint8_t)(baud >> 8);
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
120 UBRR1L = (uint8_t)baud;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
121
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
122 // Enable the receiver, and RX Complete Interrupt
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
123 UCSR1B = 0x90;
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
124
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
125 // Set frame format: 8 data, 1 stop bit, even parity
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
126 // Asynchrounous USART mode
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
127 UCSR1C = 0x26;
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
128
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
129 // Reset the keyboard before scanning, we might be in a wierd state
149
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
130 Scan_resetKeyboard();
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
131 }
263
9afed592bcb5 Preparing for mk20dx256vlh7
Jacob Alexander <haata@kiibohd.com>
parents: 149
diff changeset
132 #elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
133 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
134 // Setup the the UART interface for keyboard data input
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
135 SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
136
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
137 // Pin Setup for UART0
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
138 PORTB_PCR16 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3); // RX Pin
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
139 PORTB_PCR17 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
140
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
141 // Setup baud rate - 1205 Baud
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
142 // 48 MHz / ( 16 * Baud ) = BDH/L
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
143 // Baud: 1205 -> 48 MHz / ( 16 * 1205 ) = 2489.6266
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
144 // Thus baud setting = 2490
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
145 // NOTE: If finer baud adjustment is needed see UARTx_C4 -> BRFA in the datasheet
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
146 uint16_t baud = 2490; // Max setting of 8191
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
147 UART0_BDH = (uint8_t)(baud >> 8);
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
148 UART0_BDL = (uint8_t)baud;
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
149
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
150 // 8 bit, Even Parity, Idle Character bit after stop
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
151 // NOTE: For 8 bit with Parity you must enable 9 bit transmission (pg. 1065)
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
152 // You only need to use UART0_D for 8 bit reading/writing though
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
153 // UART_C1_M UART_C1_PE UART_C1_PT UART_C1_ILT
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
154 UART0_C1 = UART_C1_M | UART_C1_PE | UART_C1_ILT;
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
155
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
156 // Number of bytes in FIFO before TX Interrupt
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
157 UART0_TWFIFO = 1;
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
158
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
159 // Number of bytes in FIFO before RX Interrupt
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
160 UART0_RWFIFO = 1;
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
161
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
162 // TX FIFO Disabled, TX FIFO Size 1 (Max 8 datawords), RX FIFO Enabled, RX FIFO Size 1 (Max 8 datawords)
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
163 // TX/RX FIFO Size:
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
164 // 0x0 - 1 dataword
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
165 // 0x1 - 4 dataword
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
166 // 0x2 - 8 dataword
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
167 //UART0_PFIFO = UART_PFIFO_TXFE | /*TXFIFOSIZE*/ (0x0 << 4) | UART_PFIFO_RXFE | /*RXFIFOSIZE*/ (0x0);
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
168
74
91c9eb3967b1 Adding the MSBF register enable flag.
Jacob Alexander <triplehaata@gmail.com>
parents: 73
diff changeset
169 // Reciever Inversion Disabled, LSBF
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
170 // UART_S2_RXINV UART_S2_MSBF
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
171 UART0_S2 |= 0x00;
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
172
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
173 // Transmit Inversion Disabled
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
174 // UART_C3_TXINV
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
175 UART0_C3 |= 0x00;
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
176
74
91c9eb3967b1 Adding the MSBF register enable flag.
Jacob Alexander <triplehaata@gmail.com>
parents: 73
diff changeset
177 // TX Disabled, RX Enabled, RX Interrupt Enabled
75
108076064e6c UART0 on Teensy 3.0 now functional
Jacob Alexander <triplehaata@gmail.com>
parents: 74
diff changeset
178 // UART_C2_TE UART_C2_RE UART_C2_RIE
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
179 UART0_C2 = UART_C2_RE | UART_C2_RIE;
74
91c9eb3967b1 Adding the MSBF register enable flag.
Jacob Alexander <triplehaata@gmail.com>
parents: 73
diff changeset
180
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
181 // Add interrupt to the vector table
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
182 NVIC_ENABLE_IRQ( IRQ_UART0_STATUS );
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
183
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
184 // Reset the keyboard before scanning, we might be in a wierd state
149
c127188dcc80 Adding compiler change detection.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
185 Scan_resetKeyboard();
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
186 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
187 #endif
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
188
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
189
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
190 // Main Detection Loop
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
191 inline uint8_t Scan_loop()
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
192 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
193 return 0;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
194 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
195
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
196 void processKeyValue( uint8_t keyValue )
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
197 {
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
198 // XXX NOTE: The key processing is not complete for this keyboard
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
199 // Mostly due to laziness, and that the keyboard can't really be useful on a modern computer
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
200 // Basic typing will work, but some of the keys and the Graph mode changes things around
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
201
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
202 // Add key(s) to processing buffer
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
203 // First split out Shift and Ctrl
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
204 // Reserved Codes:
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
205 // Shift - 0xF5
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
206 // Ctrl - 0xF6
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
207 switch ( keyValue )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
208 {
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
209 // - Ctrl Keys -
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
210 // Exception keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
211 case 0x08: // ^H
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
212 case 0x09: // ^I
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
213 case 0x0D: // ^M
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
214 case 0x1B: // ^[
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
215 Macro_bufferAdd( keyValue );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
216 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
217 // 0x40 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
218 // Add Ctrl key and offset to the lower alphabet
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
219 case 0x00: // ^@
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
220 case 0x1C: // "^\"
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
221 case 0x1D: // ^]
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
222 case 0x1E: // ^^
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
223 case 0x1F: // ^_
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
224 Macro_bufferAdd( 0xF6 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
225 Macro_bufferAdd( keyValue + 0x40 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
226 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
227
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
228 // - Add Shift key and offset to non-shifted key -
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
229 // 0x10 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
230 case 0x21: // !
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
231 case 0x23: // #
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
232 case 0x24: // $
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
233 case 0x25: // %
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
234 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
235 Macro_bufferAdd( keyValue + 0x10 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
236 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
237 // 0x11 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
238 case 0x26: // &
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
239 case 0x28: // (
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
240 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
241 Macro_bufferAdd( keyValue + 0x11 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
242 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
243 // 0x07 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
244 case 0x29: // )
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
245 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
246 Macro_bufferAdd( keyValue + 0x07 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
247 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
248 // -0x0E Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
249 case 0x40: // @
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
250 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
251 Macro_bufferAdd( keyValue - 0x0E );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
252 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
253 // 0x0E Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
254 case 0x2A: // *
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
255 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
256 Macro_bufferAdd( keyValue + 0x0E );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
257 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
258 // 0x12 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
259 case 0x2B: // +
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
260 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
261 Macro_bufferAdd( keyValue + 0x12 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
262 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
263 // 0x05 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
264 case 0x22: // "
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
265 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
266 Macro_bufferAdd( keyValue + 0x05 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
267 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
268 // 0x01 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
269 case 0x3A: // :
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
270 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
271 Macro_bufferAdd( keyValue + 0x01 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
272 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
273 // -0x10 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
274 case 0x3C: // <
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
275 case 0x3E: // >
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
276 case 0x3F: // ?
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
277 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
278 Macro_bufferAdd( keyValue - 0x10 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
279 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
280 // -0x28 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
281 case 0x5E: // ^
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
282 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
283 Macro_bufferAdd( keyValue - 0x28 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
284 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
285 // -0x32 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
286 case 0x5F: // _
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
287 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
288 Macro_bufferAdd( keyValue - 0x32 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
289 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
290 // -0x20 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
291 case 0x7B: // {
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
292 case 0x7C: // |
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
293 case 0x7D: // }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
294 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
295 Macro_bufferAdd( keyValue - 0x20 );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
296 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
297 // -0x1E Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
298 case 0x7E: // ~
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
299 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
300 Macro_bufferAdd( keyValue - 0x1E );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
301 break;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
302 // All other keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
303 default:
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
304 // Ctrl Characters are from 0x00 to 0x1F, excluding:
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
305 // 0x08 - Backspace
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
306 // 0x09 - [Horizontal] Tab
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
307 // 0x0D - [Carriage] Return
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
308 // 0x1B - Escape
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
309 // 0x7F - Delete (^?) (Doesn't need to be split out)
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
310
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
311 // 0x60 Offset Keys
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
312 // Add Ctrl key and offset to the lower alphabet
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
313 if ( keyValue >= 0x00 && keyValue <= 0x1F )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
314 {
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
315 Macro_bufferAdd( 0xF6 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
316 Macro_bufferAdd( keyValue + 0x60 );
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
317 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
318
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
319 // Shift Characters are from 0x41 to 0x59
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
320 // No exceptions here :D
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
321 // Add Shift key and offset to the lower alphabet
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
322 else if ( keyValue >= 0x41 && keyValue <= 0x5A )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
323 {
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
324 Macro_bufferAdd( 0xF5 );
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
325 Macro_bufferAdd( keyValue + 0x20 );
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
326 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
327
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
328 // Everything else
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
329 else
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
330 {
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
331 Macro_bufferAdd( keyValue );
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
332 }
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
333 break;
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
334 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
335 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
336
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
337 // Send data
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
338 // NOTE: Example only, MBC-55X cannot receive user data
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
339 uint8_t Scan_sendData( uint8_t dataPayload )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
340 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
341 // Debug
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
342 char tmpStr[6];
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
343 hexToStr( dataPayload, tmpStr );
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
344 info_dPrint( "Sending - ", tmpStr );
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
345
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
346 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
347 UDR1 = dataPayload;
263
9afed592bcb5 Preparing for mk20dx256vlh7
Jacob Alexander <haata@kiibohd.com>
parents: 149
diff changeset
348 #elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
73
872273398943 Adding initial ARM UART structure for UART0
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
349 UART0_D = dataPayload;
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
350 #endif
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
351
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
352 return 0;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
353 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
354
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
355 // Signal KeyIndex_Buffer that it has been properly read
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
356 void Scan_finishedWithBuffer( uint8_t sentKeys )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
357 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
358 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
359
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
360 // Signal that the keys have been properly sent over USB
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
361 void Scan_finishedWithUSBBuffer( uint8_t sentKeys )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
362 {
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
363 cli(); // Disable Interrupts
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
364
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
365 // Reset the buffer counter
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
366 KeyIndex_BufferUsed = 0;
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
367
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
368 sei(); // Re-enable Interrupts
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
369 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
370
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
371 // Reset/Hold keyboard
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
372 // NOTE: Does nothing with the MBC-55x
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
373 void Scan_lockKeyboard( void )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
374 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
375 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
376
77
a977fbfdb7a5 MBC-55x support virtually complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 75
diff changeset
377 // NOTE: Does nothing with the MBC-55x
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 77
diff changeset
378 void Scan_unlockKeyboard( void )
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
379 {
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
380 }
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
381