Mercurial > louis > kiibohd-controller
annotate Scan/MicroSwitch8304/scan_loop.c @ 308:ab4515606277
Fix whitespace
Use a consistent standard - Tabs in front for indenting, spaces after for anything else. This way everything stays nice and lined up while also letting users change there prefered indent level. Most of the new files from Haata where already in this format.
author | Rowan Decker <Smasher816@gmail.com> |
---|---|
date | Sun, 08 Mar 2015 18:40:01 -0700 |
parents | 8dab4014c398 |
children |
rev | line source |
---|---|
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
1 /* Copyright (C) 2011,2014 by Jacob Alexander |
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
2 * |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
3 * Permission is hereby granted, free of charge, to any person obtaining a copy |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
4 * of this software and associated documentation files (the "Software"), to deal |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
5 * in the Software without restriction, including without limitation the rights |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
7 * copies of the Software, and to permit persons to whom the Software is |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
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:
67
diff
changeset
|
9 * |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
10 * The above copyright notice and this permission notice shall be included in |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
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:
67
diff
changeset
|
12 * |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
19 * THE SOFTWARE. |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
20 */ |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
21 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
22 // ----- Includes ----- |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
23 |
67
9ad7c1a28661
Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents:
64
diff
changeset
|
24 // Compiler Includes |
9ad7c1a28661
Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents:
64
diff
changeset
|
25 #include <Lib/ScanLib.h> |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
26 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
27 // Project Includes |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
28 #include <led.h> |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
29 #include <print.h> |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
30 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
31 // Local Includes |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
32 #include "scan_loop.h" |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
33 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
34 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
35 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
36 // ----- Defines ----- |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
37 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
38 // Pinout Defines |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
39 #define RESET_PORT PORTB |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
40 #define RESET_DDR DDRD |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
41 #define RESET_PIN 0 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
42 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
43 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
44 // ----- Macros ----- |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
45 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
46 #define UNSET_RESET() RESET_DDR &= ~(1 << RESET_PIN) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
47 #define SET_RESET() RESET_DDR |= (1 << RESET_PIN) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
48 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
49 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
50 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
51 // ----- Variables ----- |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
52 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
53 // Buffer used to inform the macro processing module which keys have been detected as pressed |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
54 volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER]; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
55 volatile uint8_t KeyIndex_BufferUsed; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
56 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
57 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
58 // Buffer Signals |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
59 volatile uint8_t BufferReadyToClear; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
60 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
61 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
62 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
63 // ----- Functions ----- |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
64 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
65 // Setup |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
66 inline void Scan_setup() |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
67 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
68 // Setup the the USART interface for keyboard data input |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
69 // NOTE: The input data signal needs to be inverted for the Teensy USART to properly work |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
70 |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
71 // Setup baud rate |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
72 // 16 MHz / ( 16 * Baud ) = UBRR |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
73 // Baud <- 0.82020 ms per bit, thus 1000 / 0.82020 = 1219.2 |
37
7f65034538ea
Intial commit of the SonyNEWS scan module
Jacob Alexander <triplehaata@gmail.com>
parents:
36
diff
changeset
|
74 // Thus baud setting = 820 |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
75 uint16_t baud = 820; // Max setting of 4095 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
76 UBRR1H = (uint8_t)(baud >> 8); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
77 UBRR1L = (uint8_t)baud; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
78 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
79 // Enable the receiver, transitter, and RX Complete Interrupt |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
80 UCSR1B = 0x98; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
81 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
82 // Set frame format: 8 data, no stop bits or parity |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
83 // Asynchrounous USART mode |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
84 // 8304 sends encoded scancodes (for example Alphanumeric 0-9 follows their keypad encoding scheme) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
85 // Separate line is for reset |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
86 UCSR1C = 0x06; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
87 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
88 // Initially buffer doesn't need to be cleared (it's empty...) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
89 BufferReadyToClear = 0; |
36
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
90 |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
91 // Reset the keyboard before scanning, we might be in a wierd state |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
92 // Note: This should be run asap, but we need the USART setup to run this command on the 8304 |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
93 scan_resetKeyboard(); |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
94 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
95 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
96 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
97 // Main Detection Loop |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
98 // Not needed for the Micro Switch 8304, this is just a busy loop |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
99 inline uint8_t Scan_loop() |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
100 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
101 return 0; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
102 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
103 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
104 void processKeyValue( uint8_t keyValue ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
105 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
106 // Finalize output buffer |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
107 // Mask 8th bit |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
108 keyValue &= 0x7F; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
109 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
110 // Interpret scan code |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
111 switch ( keyValue ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
112 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
113 case 0x40: // Clear buffer command |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
114 info_print("CLEAR!"); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
115 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
116 BufferReadyToClear = 1; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
117 break; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
118 case 0x7F: |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
119 scan_lockKeyboard(); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
120 _delay_ms(3000); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
121 scan_unlockKeyboard(); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
122 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
123 default: |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
124 // Make sure the key isn't already in the buffer |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
125 for ( uint8_t c = 0; c < KeyIndex_BufferUsed + 1; c++ ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
126 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
127 // Key isn't in the buffer yet |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
128 if ( c == KeyIndex_BufferUsed ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
129 { |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
130 Macro_bufferAdd( keyValue ); |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
131 break; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
132 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
133 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
134 // Key already in the buffer |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
135 if ( KeyIndex_Buffer[c] == keyValue ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
136 break; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
137 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
138 break; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
139 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
140 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
141 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
142 // USART Receive Buffer Full Interrupt |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
143 ISR(USART1_RX_vect) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
144 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
145 cli(); // Disable Interrupts |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
146 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
147 uint8_t keyValue = 0x00; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
148 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
149 // The interrupt is always for the first item of the packet set, reset the buffer |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
150 KeyIndex_BufferUsed = 0; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
151 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
152 // Only the first 7 bits have scancode data |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
153 // The last packet of the packet set has the 8th bit high, all the others are low |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
154 // |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
155 // Interrupts are too slow for the rest of the packet set, poll for the rest |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
156 while ( 1 ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
157 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
158 // Read the raw packet from the USART |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
159 keyValue = UDR1; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
160 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
161 // Debug |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
162 char tmpStr[6]; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
163 hexToStr( keyValue, tmpStr ); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
164 dPrintStrs( tmpStr, " " ); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
165 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
166 // Process the scancode |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
167 processKeyValue( keyValue ); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
168 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
169 // Last packet of the set |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
170 if ( keyValue & 0x80 ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
171 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
172 dPrintStrs( "**" ); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
173 break; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
174 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
175 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
176 // Delay enough so we don't run into the same packet (or the previous buffered packet) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
177 _delay_us(10000); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
178 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
179 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
180 sei(); // Re-enable Interrupts |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
181 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
182 |
308 | 183 // Send data |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
184 // |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
185 // Keyboard Input Guide for Micro Switch 8304 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
186 // 0xBX is for LED F1,F2,Over Type,Lock |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
187 // 0xAX is for LED F3,F8,F9,F10 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
188 // 0x92 resets keyboard (LED off, echo scancode mode off) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
189 // 0x9E sets echo scancode mode from (0x81 to 0xFF; translates to 0x01 to 0x7F) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
190 // Other echos: 0x15~0x19 send 0x15~0x19, 0x40 sends 0x40 (as well as 0x44,0x45, 0x80) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
191 // 0x8C Acks the keyboard and gets 0x70 sent back (delayed) |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
192 uint8_t Scan_sendData( uint8_t dataPayload ) |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
193 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
194 UDR1 = dataPayload; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
195 return 0; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
196 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
197 |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
198 // Signal KeyIndex_Buffer that it has been properly read |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
199 // In the case of the Micro Switch 8304, we leave the buffer alone until more scancode data comes in |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
200 void Scan_finishedWithBuffer( uint8_t sentKeys ) |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
201 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
202 // We received a Clear code from the 8304, clear the buffer now that we've used it |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
203 if ( BufferReadyToClear ) |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
204 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
205 KeyIndex_BufferUsed = 0; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
206 BufferReadyToClear = 0; |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
207 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
208 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
209 |
61
fed6681dc35f
Adding API update to the MicroSwitch8304 code.
Jacob Alexander <triplehaata@gmail.com>
parents:
37
diff
changeset
|
210 // 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:
67
diff
changeset
|
211 void Scan_finishedWithUSBBuffer( uint8_t sentKeys ) |
61
fed6681dc35f
Adding API update to the MicroSwitch8304 code.
Jacob Alexander <triplehaata@gmail.com>
parents:
37
diff
changeset
|
212 { |
fed6681dc35f
Adding API update to the MicroSwitch8304 code.
Jacob Alexander <triplehaata@gmail.com>
parents:
37
diff
changeset
|
213 } |
fed6681dc35f
Adding API update to the MicroSwitch8304 code.
Jacob Alexander <triplehaata@gmail.com>
parents:
37
diff
changeset
|
214 |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
215 // Reset/Hold keyboard |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
216 // Warning! This will cause the keyboard to not send any data, so you can't disable with a keypress |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
217 // The Micro Switch 8304 has a dedicated reset line |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
218 void Scan_lockKeyboard( void ) |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
219 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
220 UNSET_RESET(); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
221 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
222 |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
223 void Scan_unlockKeyboard( void ) |
34
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
224 { |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
225 SET_RESET(); |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
226 } |
5425548818d3
Adding support for the Micro Switch 8304 Hall Effect Keyboard
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
227 |
36
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
228 // Reset Keyboard |
125
8dab4014c398
Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
67
diff
changeset
|
229 void Scan_resetKeyboard( void ) |
36
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
230 { |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
231 // Reset command for the 8304 |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
232 scan_sendData( 0x92 ); |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
233 } |
00a06e011158
Pre Tandy1000 overhaul
Jacob Alexander <triplehaata@gmail.com>
parents:
34
diff
changeset
|
234 |