annotate Scan/DPH/scan_loop.c @ 421:ad693d70c292

As per request of original author, updating license to MIT
author Jacob Alexander <jacob@datrium.com>
date Tue, 23 Feb 2016 14:35:08 -0800
parents ab4515606277
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
421
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
1 /* Copyright (C) 2011-2013 by Joseph Makuch (jmakuch+f@gmail.com)
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
2 * Additions by Jacob Alexander (2013-2014) (haata@kiibohd.com)
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
3 *
421
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
5 * of this software and associated documentation files (the "Software"), to deal
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
6 * in the Software without restriction, including without limitation the rights
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
8 * copies of the Software, and to permit persons to whom the Software is
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
9 * furnished to do so, subject to the following conditions:
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
10 *
421
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
11 * The above copyright notice and this permission notice shall be included in
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
12 * all copies or substantial portions of the Software.
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
13 *
421
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ad693d70c292 As per request of original author, updating license to MIT
Jacob Alexander <jacob@datrium.com>
parents: 308
diff changeset
20 * THE SOFTWARE.
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21 */
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23 // ----- Includes -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
24
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
25 // Compiler Includes
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26 #include <Lib/ScanLib.h>
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
28 // Project Includes
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
29 #include <cli.h>
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
30 #include <led.h>
157
f27d8e591ba1 Enabling USB keycodes.
Jacob Alexander <haata@kiibohd.com>
parents: 156
diff changeset
31 #include <macro.h>
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
32 #include <print.h>
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34 // Local Includes
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
35 #include "scan_loop.h"
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
36
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
39 // ----- Defines -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41 // TODO dfj defines...needs commenting and maybe some cleaning...
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42 #define MAX_PRESS_DELTA_MV 450 // As measured from the Teensy ADC pin
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43 #define THRESHOLD_MV (MAX_PRESS_DELTA_MV >> 1)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44 //(2560 / (0x3ff/2)) ~= 5
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
45 #define MV_PER_ADC 5
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46 #define THRESHOLD (THRESHOLD_MV / MV_PER_ADC)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
47
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
48 #define STROBE_SETTLE 1
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
49
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
50 #define ADHSM 7
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
51
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
52 // Right justification of ADLAR
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
53 #define ADLAR_BITS 0
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
54
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55 // full muxmask
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56 #define FULL_MUX_MASK ((1 << MUX0) | (1 << MUX1) | (1 << MUX2) | (1 << MUX3) | (1 << MUX4))
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
57
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
58 // F0-f7 pins only muxmask.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
59 #define MUX_MASK ((1 << MUX0) | (1 << MUX1) | (1 << MUX2))
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
60
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
61 // Strobe Masks
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
62 #define D_MASK (0xff)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
63 #define E_MASK (0x03)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
64 #define C_MASK (0xff)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
65
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
66 // set ADC clock prescale
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
67 #define PRESCALE_MASK ((1 << ADPS0) | (1 << ADPS1) | (1 << ADPS2))
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
68 #define PRESCALE_SHIFT (ADPS0)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
69 #define PRESCALE 3
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
70
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
71 // Max number of strobes supported by the hardware
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
72 // Strobe lines are detected at startup, extra strobes cause anomalies like phantom keypresses
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
73 #define MAX_STROBES 18
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
74
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75 // Number of consecutive samples required to pass debounce
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
76 #define DEBOUNCE_THRESHOLD 5
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
77
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
78 // Scans to remain idle after all keys were release before starting averaging
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
79 // XXX So this makes the initial keypresses fast,
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
80 // but it's still possible to lose a keypress if you press at the wrong time -HaaTa
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
81 #define KEY_IDLE_SCANS 30000
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
82
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
83 // Total number of muxes/sense lines available
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84 #define MUXES_COUNT 8
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85 #define MUXES_COUNT_XSHIFT 3
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
87 // Number of warm-up loops before starting to scan keys
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
88 #define WARMUP_LOOPS ( 1024 )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
89 #define WARMUP_STOP (WARMUP_LOOPS - 1)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
90
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
91 #define SAMPLE_CONTROL 3
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
92
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
93 #define KEY_COUNT ((MAX_STROBES) * (MUXES_COUNT))
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
94
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
95 #define RECOVERY_CONTROL 1
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
96 #define RECOVERY_SOURCE 0
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97 #define RECOVERY_SINK 2
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99 #define ON 1
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
100 #define OFF 0
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
102 // mix in 1/4 of the current average to the running average. -> (@mux_mix = 2)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
103 #define MUX_MIX 2
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
104
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
105 #define IDLE_COUNT_SHIFT 8
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
106
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
107 // av = (av << shift) - av + sample; av >>= shift
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
108 // e.g. 1 -> (av + sample) / 2 simple average of new and old
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
109 // 2 -> (3 * av + sample) / 4 i.e. 3:1 mix of old to new.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
110 // 3 -> (7 * av + sample) / 8 i.e. 7:1 mix of old to new.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
111 #define KEYS_AVERAGES_MIX_SHIFT 3
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
112
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
113
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
114
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
115 // ----- Macros -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
116
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
117 // Select mux
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
118 #define SET_FULL_MUX(X) ((ADMUX) = (((ADMUX) & ~(FULL_MUX_MASK)) | ((X) & (FULL_MUX_MASK))))
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
119
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
120
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
121
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
122 // ----- Function Declarations -----
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
123
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
124 // CLI Functions
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
125 void cliFunc_avgDebug ( char* args );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
126 void cliFunc_echo ( char* args );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
127 void cliFunc_keyDebug ( char* args );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
128 void cliFunc_pressDebug ( char* args );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
129 void cliFunc_problemKeys( char* args );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
130 void cliFunc_senseDebug ( char* args );
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
131
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
132 // Debug Functions
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
133 void dumpSenseTable();
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
134
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
135 // High-level Capsense Functions
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
136 void setup_ADC();
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
137 void capsense_scan();
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
138
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
139 // Capsense Sense Functions
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
140 void testColumn ( uint8_t strobe );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
141 void sampleColumn( uint8_t column );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
142
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
143 // Low-level Capsense Functions
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
144 void strobe_w( uint8_t strobe_num );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
145 void recovery( uint8_t on );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
146
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
147
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
148
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
149 // ----- Variables -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
150
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
151 // Scan Module command dictionary
239
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
152 CLIDict_Entry( echo, "Example command, echos the arguments." );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
153 CLIDict_Entry( avgDebug, "Enables/Disables averaging results." NL "\t\tDisplays each average, starting from Key 0x00, ignoring 0 valued averages." );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
154 CLIDict_Entry( keyDebug, "Enables/Disables long debug for each keypress." NL "\t\tkeycode - [strobe:mux] : sense val : threshold+delta=total : margin" );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
155 CLIDict_Entry( pressDebug, "Enables/Disables short debug for each keypress." );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
156 CLIDict_Entry( problemKeys, "Display current list of problem keys," );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
157 CLIDict_Entry( senseDebug, "Prints out the current sense table N times." NL "\t\tsense:max sense:delta" );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
158
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
159 CLIDict_Def( scanCLIDict, "DPH Module Commands" ) = {
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
160 CLIDict_Item( echo ),
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
161 CLIDict_Item( avgDebug ),
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
162 CLIDict_Item( keyDebug ),
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
163 CLIDict_Item( pressDebug ),
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
164 CLIDict_Item( problemKeys ),
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
165 CLIDict_Item( senseDebug ),
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
166 { 0, 0, 0 } // Null entry for dictionary end
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
167 };
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
168
239
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 213
diff changeset
169
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
170 // CLI Control Variables
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
171 uint8_t enableAvgDebug = 0;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
172 uint8_t enableKeyDebug = 0;
213
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
173 uint8_t enablePressDebug = 0;
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
174 uint8_t senseDebugCount = 3; // In order to get boot-time oddities
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
175
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
176
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
177 // Variables used to calculate the starting sense value (averaging)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
178 uint32_t full_avg = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
179 uint32_t high_avg = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
180 uint32_t low_avg = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
181
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
182 uint8_t high_count = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
183 uint8_t low_count = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
184
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
185
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
186 uint16_t samples[MAX_STROBES][MUXES_COUNT]; // Overall table of cap sense ADC values
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
187 uint16_t sampleMax[MAX_STROBES][MUXES_COUNT]; // Records the max seen ADC value
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
188
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
189 uint8_t key_activity = 0; // Increments for each detected key per each full scan of the keyboard, it is reset before each full scan
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
190 uint16_t key_idle = 0; // Defines how scans after all keys were released before starting averaging again
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
191 uint8_t key_release = 0; // Indicates if going from key press state to release state (some keys pressed to no keys pressed)
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
192
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
193 uint16_t threshold = THRESHOLD;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
194
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
195 uint16_t keys_averages_acc[KEY_COUNT];
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
196 uint16_t keys_averages [KEY_COUNT];
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
197 uint8_t keys_debounce [KEY_COUNT]; // Contains debounce statistics
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
198 uint8_t keys_problem [KEY_COUNT]; // Marks keys that should be ignored (determined by averaging at startup)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
199
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
200 // TODO: change this to 'booting', then count down.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
201 uint16_t boot_count = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
202
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
203 uint8_t total_strobes = MAX_STROBES;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
204 uint8_t strobe_map[MAX_STROBES];
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
205
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
206
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
207
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
208 // ----- Functions -----
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
209
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
210 // Initial setup for cap sense controller
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
211 inline void Scan_setup()
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
212 {
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
213 // Register Scan CLI dictionary
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
214 CLI_registerDictionary( scanCLIDict, scanCLIDictName );
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
215
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
216 // Scan for active strobes
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
217 // NOTE1: On IBM PCBs, each strobe line that is *NOT* used is connected to GND.
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
218 // This means, the strobe GPIO can be set to Tri-State pull-up to detect which strobe lines are not used.
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
219 // NOTE2: This will *NOT* detect floating strobes.
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
220 // NOTE3: Rev 0.4, the strobe numbers are reversed, so D0 is actually strobe 0 and C7 is strobe 17
155
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
221 info_msg("Detecting Strobes...");
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
222
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
223 DDRC = 0;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
224 PORTC = C_MASK;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
225 DDRD = 0;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
226 PORTD = D_MASK;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
227 DDRE = 0;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
228 PORTE = E_MASK;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
229
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
230 // Initially there are 0 strobes
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
231 total_strobes = 0;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
232
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
233 // Iterate over each the strobes
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
234 for ( uint8_t strobe = 0; strobe < MAX_STROBES; strobe++ )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
235 {
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
236 uint8_t detected = 0;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
237
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
238 // If PIN is high, then strobe is *NOT* connected to GND and may be a strobe
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
239 switch ( strobe )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
240 {
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
241
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
242 // Strobe Mappings
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
243 // Rev Rev
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
244 // 0.2 0.4
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
245 #ifndef REV0_4_DEBUG // XXX These pins should be reworked, and connect to GND on Rev 0.4
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
246 case 0: // D0 0 n/c
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
247 case 1: // D1 1 n/c
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
248 #endif
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
249 case 2: // D2 2 15
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
250 case 3: // D3 3 14
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
251 case 4: // D4 4 13
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
252 case 5: // D5 5 12
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
253 case 6: // D6 6 11
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
254 case 7: // D7 7 10
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
255 detected = PIND & (1 << strobe);
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
256 break;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
257
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
258 case 8: // E0 8 9
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
259 case 9: // E1 9 8
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
260 detected = PINE & (1 << (strobe - 8));
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
261 break;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
262
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
263 case 10: // C0 10 7
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
264 case 11: // C1 11 6
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
265 case 12: // C2 12 5
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
266 case 13: // C3 13 4
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
267 case 14: // C4 14 3
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
268 case 15: // C5 15 2
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
269 #ifndef REV0_2_DEBUG // XXX If not using the 18 pin connector on Rev 0.2, rework these pins to GND
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
270 case 16: // C6 16 1
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
271 case 17: // C7 17 0
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
272 #endif
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
273 detected = PINC & (1 << (strobe - 10));
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
274 break;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
275
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
276 default:
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
277 break;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
278 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
279
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
280 // Potential strobe line detected
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
281 if ( detected )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
282 {
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
283 strobe_map[total_strobes] = strobe;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
284 total_strobes++;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
285 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
286 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
287
155
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
288 printInt8( total_strobes );
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
289 print( " strobes found." NL );
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
290
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
291 // Setup Pins for Strobing
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
292 DDRC = C_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
293 PORTC = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
294 DDRD = D_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
295 PORTD = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
296 DDRE = E_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
297 PORTE = 0 ;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
298
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
299 // Initialize ADC
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
300 setup_ADC();
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
301
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
302 // Reset debounce table
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
303 for ( int i = 0; i < KEY_COUNT; ++i )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
304 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
305 keys_debounce[i] = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
306 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
307
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
308 // Warm things up a bit before we start collecting data, taking real samples.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
309 for ( uint8_t i = 0; i < total_strobes; ++i )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
310 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
311 sampleColumn( strobe_map[i] );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
312 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
313 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
314
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
315
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
316 // Main Detection Loop
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
317 // This is where the important stuff happens
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
318 inline uint8_t Scan_loop()
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
319 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
320 capsense_scan();
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
321
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
322 // Return non-zero if macro and USB processing should be delayed
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
323 // Macro processing will always run if returning 0
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
324 // USB processing only happens once the USB send timer expires, if it has not, Scan_loop will be called
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
325 // after the macro processing has been completed
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
326 return 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
327 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
328
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
329
213
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
330 // Signal from macro module that keys have been processed
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
331 // NOTE: Only really required for implementing "tricks" in converters for odd protocols
200
048c8a266a08 Updating DPH to compile with PartialLayer module
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
332 void Scan_finishedWithMacro( uint8_t sentKeys )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
333 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
334 return;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
335 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
336
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
337
213
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
338 // Signal from output module that keys have been processed/sent
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
339 // NOTE: Only really required for implementing "tricks" in converters for odd protocols
200
048c8a266a08 Updating DPH to compile with PartialLayer module
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
340 void Scan_finishedWithOutput( uint8_t sentKeys )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
341 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
342 return;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
343 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
344
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
345
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
346 inline void capsense_scan()
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
347 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
348 // Accumulated average used for the next scan
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
349 uint32_t cur_full_avg = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
350 uint32_t cur_high_avg = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
351
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
352 // Reset average counters
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
353 low_avg = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
354 low_count = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
355
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
356 high_count = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
357
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
358 // Reset key activity, if there is no key activity, averages will accumulate for sense deltas, otherwise they will be reset
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
359 key_activity = 0;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
360
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
361 // Scan each of the mapped strobes in the matrix
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
362 for ( uint8_t strober = 0; strober < total_strobes; ++strober )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
363 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
364 uint8_t map_strobe = strobe_map[strober];
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
365
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
366 // Sample the ADCs for the given column/strobe
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
367 sampleColumn( map_strobe );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
368
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
369 // Only process sense data if warmup is finished
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
370 if ( boot_count >= WARMUP_LOOPS )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
371 {
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
372 testColumn( map_strobe );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
373 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
374
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
375 uint8_t strobe_line = map_strobe << MUXES_COUNT_XSHIFT;
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
376 for ( int mux = 0; mux < MUXES_COUNT; ++mux )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
377 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
378 // discard sketchy low bit, and meaningless high bits.
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
379 uint8_t sample = samples[map_strobe][mux] >> 1;
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
380 keys_averages_acc[strobe_line + mux] += sample;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
381 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
382
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
383 // Accumulate 3 total averages (used for determining starting average during warmup)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
384 // full_avg - Average of all sampled lines on the previous scan set
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
385 // cur_full_avg - Average of all sampled lines for this scan set
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
386 // high_avg - Average of all sampled lines above full_avg on the previous scan set
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
387 // cur_high_avg - Average of all sampled lines above full_avg
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
388 // low_avg - Average of all sampled lines below or equal to full_avg
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
389 if ( boot_count < WARMUP_LOOPS )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
390 {
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
391 for ( uint8_t mux = 0; mux < MUXES_COUNT; ++mux )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
392 {
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
393 uint8_t sample = samples[map_strobe][mux] >> 1;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
394
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
395 // Sample is high, add it to high avg
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
396 if ( sample > full_avg )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
397 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
398 high_count++;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
399 cur_high_avg += sample;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
400 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
401 // Sample is low, add it to low avg
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
402 else
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
403 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
404 low_count++;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
405 low_avg += sample;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
406 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
407
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
408 // If sample is higher than previous high_avg, then mark as "problem key"
155
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
409 // XXX Giving a bit more margin to pass (high_avg vs. high_avg + high_avg - full_avg) -HaaTa
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
410 keys_problem[strobe_line + mux] = sample > high_avg + (high_avg - full_avg) ? sample : 0;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
411
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
412 // Prepare for next average
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
413 cur_full_avg += sample;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
414 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
415 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
416 } // for strober
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
417
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
418 // Update total sense average (only during warm-up)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
419 if ( boot_count < WARMUP_LOOPS )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
420 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
421 full_avg = cur_full_avg / (total_strobes * MUXES_COUNT);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
422 high_avg = cur_high_avg / high_count;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
423 low_avg /= low_count;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
424
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
425 // Update the base average value using the low_avg (best chance of not ignoring a keypress)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
426 for ( int i = 0; i < KEY_COUNT; ++i )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
427 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
428 keys_averages[i] = low_avg;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
429 keys_averages_acc[i] = low_avg;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
430 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
431 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
432
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
433 // Warm up voltage references
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
434 if ( boot_count < WARMUP_LOOPS )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
435 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
436 boot_count++;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
437
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
438 switch ( boot_count )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
439 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
440 // First loop
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
441 case 1:
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
442 // Show msg at first iteration only
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
443 info_msg("Warming up the voltage references");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
444 break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
445 // Middle iterations
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
446 case 300:
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
447 case 600:
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
448 case 900:
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
449 case 1200:
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
450 print(".");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
451 break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
452 // Last loop
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
453 case WARMUP_STOP:
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
454 print( NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
455 info_msg("Warmup finished using ");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
456 printInt16( WARMUP_LOOPS );
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
457 print(" iterations" NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
458
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
459 // Display the final calculated averages of all the sensed strobes
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
460 info_msg("Full average (");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
461 printInt8( total_strobes * MUXES_COUNT );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
462 print("): ");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
463 printHex( full_avg );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
464
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
465 print(" High average (");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
466 printInt8( high_count );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
467 print("): ");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
468 printHex( high_avg );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
469
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
470 print(" Low average (");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
471 printInt8( low_count );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
472 print("): ");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
473 printHex( low_avg );
155
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
474
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
475 print(" Rejection threshold: ");
7b4155f3b1b7 Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents: 154
diff changeset
476 printHex( high_avg + (high_avg - full_avg) );
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
477 print( NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
478
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
479 // Display problem keys, and the sense value at the time
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
480 for ( uint8_t key = 0; key < KEY_COUNT; key++ )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
481 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
482 if ( keys_problem[key] )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
483 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
484 warn_msg("Problem key detected: ");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
485 printHex( key );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
486 print(" (");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
487 printHex( keys_problem[key] );
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
488 print(")" NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
489 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
490 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
491
158
0e3038f30819 Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents: 157
diff changeset
492 info_print("If problem keys were detected, and were being held down, they will be reset as soon as let go.");
0e3038f30819 Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents: 157
diff changeset
493 info_print("Some keys have unusually high sense values, on the first press they should be re-enabled.");
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
494 break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
495 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
496 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
497 else
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
498 {
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
499 // No keypress, accumulate averages
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
500 if( !key_activity )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
501 {
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
502 // Only start averaging once the idle counter has counted down to 0
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
503 if ( key_idle == 0 )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
504 {
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
505 // Average Debugging
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
506 if ( enableAvgDebug )
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
507 {
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
508 print("\033[1mAvg\033[0m: ");
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
509 }
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
510
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
511 // aggregate
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
512 for ( uint8_t i = 0; i < KEY_COUNT; ++i )
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
513 {
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
514 uint16_t acc = keys_averages_acc[i];
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
515 //uint16_t acc = keys_averages_acc[i] >> IDLE_COUNT_SHIFT; // XXX This fixes things... -HaaTa
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
516 uint32_t av = keys_averages[i];
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
517
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
518 av = (av << KEYS_AVERAGES_MIX_SHIFT) - av + acc;
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
519 av >>= KEYS_AVERAGES_MIX_SHIFT;
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
520
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
521 keys_averages[i] = av;
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
522 keys_averages_acc[i] = 0;
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
523
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
524 // Average Debugging
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
525 if ( enableAvgDebug && av > 0 )
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
526 {
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
527 printHex( av );
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
528 print(" ");
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
529 }
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
530 }
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
531
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
532 // Average Debugging
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
533 if ( enableAvgDebug )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
534 {
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
535 print( NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
536 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
537
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
538 // No key presses detected, set key_release indicator
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
539 key_release = 1;
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
540 }
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
541 // Otherwise decrement the idle counter
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
542 else
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
543 {
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
544 key_idle--;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
545 }
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
546 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
547 // Keypresses, reset accumulators
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
548 else if ( key_release )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
549 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
550 for ( uint8_t c = 0; c < KEY_COUNT; ++c ) { keys_averages_acc[c] = 0; }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
551
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
552 key_release = 0;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
553 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
554
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
555 // If the debugging sense table is non-zero, display
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
556 if ( senseDebugCount > 0 )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
557 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
558 senseDebugCount--;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
559 print( NL );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
560 dumpSenseTable();
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
561 }
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
562 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
563 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
564
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
565
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
566 void setup_ADC()
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
567 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
568 // disable adc digital pins.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
569 DIDR1 |= (1 << AIN0D) | (1<<AIN1D); // set disable on pins 1,0.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
570 DDRF = 0x0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
571 PORTF = 0x0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
572 uint8_t mux = 0 & 0x1f; // 0 == first. // 0x1e = 1.1V ref.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
573
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
574 // 0 = external aref 1,1 = 2.56V internal ref
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
575 uint8_t aref = ((1 << REFS1) | (1 << REFS0)) & ((1 << REFS1) | (1 << REFS0));
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
576 uint8_t adate = (1 << ADATE) & (1 << ADATE); // trigger enable
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
577 uint8_t trig = 0 & ((1 << ADTS0) | (1 << ADTS1) | (1 << ADTS2)); // 0 = free running
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
578 // ps2, ps1 := /64 ( 2^6 ) ps2 := /16 (2^4), ps1 := 4, ps0 :=2, PS1,PS0 := 8 (2^8)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
579 uint8_t prescale = ( ((PRESCALE) << PRESCALE_SHIFT) & PRESCALE_MASK ); // 001 == 2^1 == 2
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
580 uint8_t hispeed = (1 << ADHSM);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
581 uint8_t en_mux = (1 << ACME);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
582
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
583 ADCSRA = (1 << ADEN) | prescale; // ADC enable
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
584
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
585 // select ref.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
586 //ADMUX |= ((1 << REFS1) | (1 << REFS0)); // 2.56 V internal.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
587 //ADMUX |= ((1 << REFS0) ); // Vcc with external cap.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
588 //ADMUX &= ~((1 << REFS1) | (1 << REFS0)); // 0,0 : aref.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
589 ADMUX = aref | mux | ADLAR_BITS;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
590
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
591 // set free-running
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
592 ADCSRA |= adate; // trigger enable
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
593 ADCSRB = en_mux | hispeed | trig | (ADCSRB & ~((1 << ADTS0) | (1 << ADTS1) | (1 << ADTS2))); // trigger select free running
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
594
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
595 ADCSRA |= (1 << ADEN); // ADC enable
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
596 ADCSRA |= (1 << ADSC); // start conversions q
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
597 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
598
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
599
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
600 void recovery( uint8_t on )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
601 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
602 DDRB |= (1 << RECOVERY_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
603 PORTB &= ~(1 << RECOVERY_SINK); // SINK always zero
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
604 DDRB &= ~(1 << RECOVERY_SOURCE); // SOURCE high imp
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
605
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
606 if ( on )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
607 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
608 // set strobes to sink to gnd.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
609 DDRC |= C_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
610 DDRD |= D_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
611 DDRE |= E_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
612
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
613 PORTC &= ~C_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
614 PORTD &= ~D_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
615 PORTE &= ~E_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
616
308
ab4515606277 Fix whitespace
Rowan Decker <Smasher816@gmail.com>
parents: 239
diff changeset
617 DDRB |= (1 << RECOVERY_SINK); // SINK pull
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
618 PORTB |= (1 << RECOVERY_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
619 PORTB |= (1 << RECOVERY_SOURCE); // SOURCE high
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
620 DDRB |= (1 << RECOVERY_SOURCE);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
621 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
622 else
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
623 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
624 PORTB &= ~(1 << RECOVERY_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
625 DDRB &= ~(1 << RECOVERY_SOURCE);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
626 PORTB &= ~(1 << RECOVERY_SOURCE); // SOURCE low
308
ab4515606277 Fix whitespace
Rowan Decker <Smasher816@gmail.com>
parents: 239
diff changeset
627 DDRB &= ~(1 << RECOVERY_SINK); // SINK high-imp
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
628 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
629 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
630
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
631
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
632 void hold_sample( uint8_t on )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
633 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
634 if ( !on )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
635 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
636 PORTB |= (1 << SAMPLE_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
637 DDRB |= (1 << SAMPLE_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
638 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
639 else
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
640 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
641 DDRB |= (1 << SAMPLE_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
642 PORTB &= ~(1 << SAMPLE_CONTROL);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
643 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
644 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
645
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
646
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
647 void strobe_w( uint8_t strobe_num )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
648 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
649 PORTC &= ~(C_MASK);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
650 PORTD &= ~(D_MASK);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
651 PORTE &= ~(E_MASK);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
652
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
653 // Strobe table
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
654 // Not all strobes are used depending on which are detected
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
655 switch ( strobe_num )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
656 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
657
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
658 case 0: PORTD |= (1 << 0); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
659 case 1: PORTD |= (1 << 1); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
660 case 2: PORTD |= (1 << 2); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
661 case 3: PORTD |= (1 << 3); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
662 case 4: PORTD |= (1 << 4); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
663 case 5: PORTD |= (1 << 5); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
664 case 6: PORTD |= (1 << 6); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
665 case 7: PORTD |= (1 << 7); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
666
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
667 case 8: PORTE |= (1 << 0); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
668 case 9: PORTE |= (1 << 1); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
669
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
670 case 10: PORTC |= (1 << 0); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
671 case 11: PORTC |= (1 << 1); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
672 case 12: PORTC |= (1 << 2); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
673 case 13: PORTC |= (1 << 3); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
674 case 14: PORTC |= (1 << 4); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
675 case 15: PORTC |= (1 << 5); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
676 case 16: PORTC |= (1 << 6); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
677 case 17: PORTC |= (1 << 7); break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
678
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
679 default:
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
680 break;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
681 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
682 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
683
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
684
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
685 inline uint16_t getADC(void)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
686 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
687 ADCSRA |= (1 << ADIF); // clear int flag by writing 1.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
688
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
689 //wait for last read to complete.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
690 while ( !( ADCSRA & (1 << ADIF) ) );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
691
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
692 return ADC; // return sample
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
693 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
694
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
695
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
696 void sampleColumn( uint8_t column )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
697 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
698 // ensure all probe lines are driven low, and chill for recovery delay.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
699 ADCSRA |= (1 << ADEN) | (1 << ADSC); // enable and start conversions
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
700
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
701 PORTC &= ~C_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
702 PORTD &= ~D_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
703 PORTE &= ~E_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
704
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
705 PORTF = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
706 DDRF = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
707
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
708 recovery( OFF );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
709 strobe_w( column );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
710
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
711 hold_sample( OFF );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
712 SET_FULL_MUX( 0 );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
713
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
714 // Allow strobes to settle
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
715 for ( uint8_t i = 0; i < STROBE_SETTLE; ++i ) { getADC(); }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
716
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
717 hold_sample( ON );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
718
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
719 uint8_t mux = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
720 SET_FULL_MUX( mux );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
721 getADC(); // throw away; unknown mux.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
722 do {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
723 SET_FULL_MUX( mux + 1 ); // our *next* sample will use this
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
724
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
725 // retrieve current read.
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
726 uint16_t readVal = getADC();
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
727 samples[column][mux] = readVal;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
728
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
729 // Update max sense sample table
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
730 if ( readVal > sampleMax[column][mux] )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
731 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
732 sampleMax[column][mux] = readVal;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
733 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
734
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
735 mux++;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
736
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
737 } while ( mux < 8 );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
738
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
739 hold_sample( OFF );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
740 recovery( ON );
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
741
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
742 // turn off adc.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
743 ADCSRA &= ~(1 << ADEN);
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
744
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
745 // pull all columns' strobe-lines low.
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
746 DDRC |= C_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
747 DDRD |= D_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
748 DDRE |= E_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
749
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
750 PORTC &= ~C_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
751 PORTD &= ~D_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
752 PORTE &= ~E_MASK;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
753 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
754
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
755
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
756 void testColumn( uint8_t strobe )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
757 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
758 uint16_t db_delta = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
759 uint8_t db_sample = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
760 uint16_t db_threshold = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
761
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
762 uint8_t column = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
763 uint8_t bit = 1;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
764
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
765 for ( uint8_t mux = 0; mux < MUXES_COUNT; ++mux )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
766 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
767 uint16_t delta = keys_averages[(strobe << MUXES_COUNT_XSHIFT) + mux];
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
768
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
769 uint8_t key = (strobe << MUXES_COUNT_XSHIFT) + mux;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
770
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
771 // Check if this is a bad key (e.g. test point, or non-existent key)
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
772 if ( keys_problem[key] )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
773 {
158
0e3038f30819 Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents: 157
diff changeset
774 // If the sample value of the problem key goes above initally recorded result + threshold
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
775 // re-enable the key
158
0e3038f30819 Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents: 157
diff changeset
776 if ( (db_sample = samples[strobe][mux] >> 1) > keys_problem[key] + threshold )
0e3038f30819 Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents: 157
diff changeset
777 //if ( (db_sample = samples[strobe][mux] >> 1) < high_avg )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
778 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
779 info_msg("Re-enabling problem key: ");
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
780 printHex( key );
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
781 print( NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
782
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
783 keys_problem[key] = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
784 }
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
785
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
786 // Do not waste any more cycles processing, regardless, a keypress cannot be detected
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
787 continue;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
788 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
789
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
790 // Keypress detected
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
791 // db_sample (uint8_t), discard meaningless high bit, and garbage low bit
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
792 if ( (db_sample = samples[strobe][mux] >> 1) > (db_threshold = threshold) + (db_delta = delta) )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
793 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
794 column |= bit;
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
795 key_activity++; // No longer idle, stop averaging ADC data
156
f663391a20f1 Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents: 155
diff changeset
796 key_idle = KEY_IDLE_SCANS; // Reset idle count-down
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
797
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
798 // Only register keypresses once the warmup is complete, or not enough debounce info
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
799 if ( keys_debounce[key] <= DEBOUNCE_THRESHOLD )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
800 {
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
801 // Add to the Macro processing buffer if debounce criteria met
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
802 // Automatically handles converting to a USB code and sending off to the PC
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
803 if ( keys_debounce[key] == DEBOUNCE_THRESHOLD )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
804 {
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
805 // Debug message, pressDebug CLI
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
806 if ( enablePressDebug )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
807 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
808 print("0x");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
809 printHex_op( key, 2 );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
810 print(" ");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
811 }
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
812
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
813 // Initial Keypress
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
814 Macro_keyState( key, 0x01 );
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
815 }
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
816
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
817 keys_debounce[key]++;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
818
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
819 }
213
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
820 else if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD )
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
821 {
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
822 // Held Key
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
823 Macro_keyState( key, 0x02 );
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
824 }
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
825
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
826 // Long form key debugging
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
827 if ( enableKeyDebug )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
828 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
829 // Debug message
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
830 // <key> [<strobe>:<mux>] : <sense val> : <delta + threshold> : <margin>
213
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
831 dbug_msg("");
159
84beeecd2c94 Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents: 158
diff changeset
832 printHex_op( key, 1 );
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
833 print(" [");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
834 printInt8( strobe );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
835 print(":");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
836 printInt8( mux );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
837 print("] : ");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
838 printHex( db_sample ); // Sense
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
839 print(" : ");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
840 printHex( db_threshold );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
841 print("+");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
842 printHex( db_delta );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
843 print("=");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
844 printHex( db_threshold + db_delta ); // Sense compare
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
845 print(" : ");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
846 printHex( db_sample - ( db_threshold + db_delta ) ); // Margin
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
847 print( NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
848 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
849 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
850 // Clear debounce entry if no keypress detected
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
851 else
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
852 {
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
853 // Release Key
213
2f6ec276a678 More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents: 200
diff changeset
854 if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD )
159
84beeecd2c94 Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents: 158
diff changeset
855 {
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
856 Macro_keyState( key, 0x03 );
159
84beeecd2c94 Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents: 158
diff changeset
857 }
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
858
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
859 // Clear debounce entry
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
860 keys_debounce[key] = 0;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
861 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
862
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
863 bit <<= 1;
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
864 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
865 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
866
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
867
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
868 void dumpSenseTable()
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
869 {
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
870 // Initial table alignment, with base threshold used for every key
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
871 print("\033[1m");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
872 printHex( threshold );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
873 print("\033[0m ");
141
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
874
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
875 // Print out headers first
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
876 for ( uint8_t mux = 0; mux < MUXES_COUNT; ++mux )
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
877 {
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
878 print(" Mux \033[1m");
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
879 printInt8( mux );
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
880 print("\033[0m ");
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
881 }
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
882
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
883 print( NL );
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
884
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
885 // Display the full strobe/sense table
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
886 for ( uint8_t strober = 0; strober < total_strobes; ++strober )
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
887 {
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
888 uint8_t strobe = strobe_map[strober];
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
889
141
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
890 // Display the strobe
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
891 print("Strobe \033[1m");
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
892 printHex( strobe );
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
893 print("\033[0m ");
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
894
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
895 // For each mux, display sense:threshold:delta
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
896 for ( uint8_t mux = 0; mux < MUXES_COUNT; ++mux )
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
897 {
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
898 uint8_t delta = keys_averages[(strobe << MUXES_COUNT_XSHIFT) + mux];
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
899 uint8_t sample = samples[strobe][mux] >> 1;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
900 uint8_t max = sampleMax[strobe][mux] >> 1;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
901
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
902 // Indicate if the key is being pressed by displaying green
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
903 if ( sample > delta + threshold )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
904 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
905 print("\033[1;32m");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
906 }
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
907
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
908 printHex_op( sample, 2 );
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
909 print(":");
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
910 printHex_op( max, 2 );
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
911 print(":");
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
912 printHex_op( delta, 2 );
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
913 print("\033[0m ");
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
914 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
915
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
916 // New line for each strobe
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
917 print( NL );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
918 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
919 }
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
920
139
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
921
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
922 // ----- CLI Command Functions -----
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
923
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
924 // XXX Just an example command showing how to parse arguments (more complex than generally needed)
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
925 void cliFunc_echo( char* args )
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
926 {
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
927 char* curArgs;
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
928 char* arg1Ptr;
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
929 char* arg2Ptr = args;
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
930
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
931 // Parse args until a \0 is found
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
932 while ( 1 )
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
933 {
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
934 print( NL ); // No \r\n by default after the command is entered
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
935
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
936 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
937 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
938
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
939 // Stop processing args if no more are found
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
940 if ( *arg1Ptr == '\0' )
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
941 break;
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
942
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
943 // Print out the arg
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
944 dPrint( arg1Ptr );
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
945 }
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
946 }
1ab045ef4266 Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents: 138
diff changeset
947
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
948 void cliFunc_avgDebug( char* args )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
949 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
950 print( NL );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
951
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
952 // Args ignored, just toggling
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
953 if ( enableAvgDebug )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
954 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
955 info_print("Cap Sense averaging debug disabled.");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
956 enableAvgDebug = 0;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
957 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
958 else
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
959 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
960 info_print("Cap Sense averaging debug enabled.");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
961 enableAvgDebug = 1;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
962 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
963 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
964
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
965 void cliFunc_keyDebug( char* args )
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
966 {
141
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
967 print( NL );
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
968
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
969 // Args ignored, just toggling
141
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
970 if ( enableKeyDebug )
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
971 {
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
972 info_print("Cap Sense key long debug disabled - pre debounce.");
141
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
973 enableKeyDebug = 0;
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
974 }
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
975 else
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
976 {
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
977 info_print("Cap Sense key long debug enabled - pre debounce.");
141
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
978 enableKeyDebug = 1;
6e09a82d15ee Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
979 }
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
980 }
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
981
153
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
982 void cliFunc_pressDebug( char* args )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
983 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
984 print( NL );
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
985
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
986 // Args ignored, just toggling
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
987 if ( enablePressDebug )
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
988 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
989 info_print("Cap Sense key debug disabled - post debounce.");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
990 enablePressDebug = 0;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
991 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
992 else
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
993 {
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
994 info_print("Cap Sense key debug enabled - post debounce.");
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
995 enablePressDebug = 1;
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
996 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
997 }
0f8218554421 Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents: 141
diff changeset
998
154
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
999 void cliFunc_problemKeys( char* args )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1000 {
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1001 print( NL );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1002
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1003 uint8_t count = 0;
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1004
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1005 // Args ignored, just displaying
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1006 // Display problem keys, and the sense value at the time
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1007 for ( uint8_t key = 0; key < KEY_COUNT; key++ )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1008 {
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1009 if ( keys_problem[key] )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1010 {
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1011 if ( count++ == 0 )
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1012 {
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1013 warn_msg("Problem keys: ");
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1014 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1015 printHex( key );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1016 print(" (");
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1017 printHex( keys_problem[key] );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1018 print(") " );
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1019 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1020 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1021 }
a2be5e8fc3d7 Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents: 153
diff changeset
1022
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1023 void cliFunc_senseDebug( char* args )
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1024 {
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1025 // Parse code from argument
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1026 // NOTE: Only first argument is used
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1027 char* arg1Ptr;
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1028 char* arg2Ptr;
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1029 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1030
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1031 // Default to a single print
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1032 senseDebugCount = 1;
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1033
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1034 // If there was an argument, use that instead
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1035 if ( *arg1Ptr != '\0' )
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1036 {
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1037 senseDebugCount = numToInt( arg1Ptr );
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1038 }
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1039 }
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 139
diff changeset
1040