Mercurial > louis > kiibohd-controller
annotate Scan/DPH/scan_loop.c @ 308:ab4515606277
Fix whitespace
Use a consistent standard - Tabs in front for indenting, spaces after for anything else. This way everything stays nice and lined up while also letting users change there prefered indent level. Most of the new files from Haata where already in this format.
author | Rowan Decker <Smasher816@gmail.com> |
---|---|
date | Sun, 08 Mar 2015 18:40:01 -0700 |
parents | 2a4c99da1276 |
children | ad693d70c292 |
rev | line source |
---|---|
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1 /* Copyright (C) 2011-2013 by Joseph Makuch |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * Additions by Jacob Alexander (2013-2014) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 * This library is free software; you can redistribute it and/or |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * modify it under the terms of the GNU Lesser General Public |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * version 3.0 of the License, or (at your option) any later version. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * This library is distributed in the hope that it will be useful, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * Lesser General Public License for more details. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU Lesser General Public |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 */ |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 // ----- Includes ----- |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 // 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
|
21 #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
|
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 // Project Includes |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
24 #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
|
25 #include <led.h> |
157 | 26 #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
|
27 #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
|
28 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 // 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
|
30 #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
|
31 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 |
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 // ----- Defines ----- |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 // 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
|
37 #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
|
38 #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
|
39 //(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
|
40 #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
|
41 #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
|
42 |
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 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
|
44 |
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 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
|
46 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
47 // 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
|
48 #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
|
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 // 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
|
51 #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
|
52 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 // 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
|
54 #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
|
55 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 // 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
|
57 #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
|
58 #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
|
59 #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
|
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 // 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
|
62 #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
|
63 #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
|
64 #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
|
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 // 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
|
67 // 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
|
68 #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
|
69 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 // 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
|
71 #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
|
72 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
73 // 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
|
74 // 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
|
75 // 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
|
76 #define KEY_IDLE_SCANS 30000 |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
77 |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
78 // 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
|
79 #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
|
80 #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
|
81 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
82 // 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
|
83 #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
|
84 #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
|
85 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
86 #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
|
87 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
88 #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
|
89 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
90 #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
|
91 #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
|
92 #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
|
93 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 #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
|
95 #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
|
96 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
97 // 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
|
98 #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
|
99 |
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 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
|
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 // 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
|
103 // 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
|
104 // 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
|
105 // 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
|
106 #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
|
107 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
108 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
110 // ----- Macros ----- |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
111 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
112 // 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
|
113 #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
|
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 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
117 // ----- Function Declarations ----- |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
118 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
119 // CLI Functions |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
120 void cliFunc_avgDebug ( char* args ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
121 void cliFunc_echo ( char* args ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
122 void cliFunc_keyDebug ( char* args ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
123 void cliFunc_pressDebug ( char* args ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
124 void cliFunc_problemKeys( char* args ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
125 void cliFunc_senseDebug ( char* args ); |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
126 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
127 // Debug Functions |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
128 void dumpSenseTable(); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
129 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
130 // High-level Capsense Functions |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
131 void setup_ADC(); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
132 void capsense_scan(); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
133 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
134 // Capsense Sense Functions |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
135 void testColumn ( uint8_t strobe ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
136 void sampleColumn( uint8_t column ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
137 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
138 // Low-level Capsense Functions |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
139 void strobe_w( uint8_t strobe_num ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
140 void recovery( uint8_t on ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
141 |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
142 |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
143 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
144 // ----- Variables ----- |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
145 |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
146 // Scan Module command dictionary |
239
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
147 CLIDict_Entry( echo, "Example command, echos the arguments." ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 CLIDict_Entry( problemKeys, "Display current list of problem keys," ); |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
152 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
|
153 |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
154 CLIDict_Def( scanCLIDict, "DPH Module Commands" ) = { |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
155 CLIDict_Item( echo ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
156 CLIDict_Item( avgDebug ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
157 CLIDict_Item( keyDebug ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
158 CLIDict_Item( pressDebug ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
159 CLIDict_Item( problemKeys ), |
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
160 CLIDict_Item( senseDebug ), |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
161 { 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
|
162 }; |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
163 |
239
2a4c99da1276
HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents:
213
diff
changeset
|
164 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
165 // CLI Control Variables |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
166 uint8_t enableAvgDebug = 0; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
167 uint8_t enableKeyDebug = 0; |
213
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
168 uint8_t enablePressDebug = 0; |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
169 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
|
170 |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
171 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
172 // 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
|
173 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
|
174 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
|
175 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
|
176 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
177 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
|
178 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
|
179 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
180 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
181 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
|
182 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
|
183 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
188 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
|
189 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
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 // 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
|
196 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
|
197 |
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 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
|
199 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
|
200 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
201 |
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 // ----- Functions ----- |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
204 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
205 // 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
|
206 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
|
207 { |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
208 // Register Scan CLI dictionary |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
209 CLI_registerDictionary( scanCLIDict, scanCLIDictName ); |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
210 |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
211 // Scan for active strobes |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
212 // 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
|
213 // 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
|
214 // NOTE2: This will *NOT* detect floating strobes. |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
215 // 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
|
216 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
|
217 |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
218 DDRC = 0; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
219 PORTC = C_MASK; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
220 DDRD = 0; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
221 PORTD = D_MASK; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
222 DDRE = 0; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
223 PORTE = E_MASK; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
224 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
225 // Initially there are 0 strobes |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
226 total_strobes = 0; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
227 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
228 // Iterate over each the strobes |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
229 for ( uint8_t strobe = 0; strobe < MAX_STROBES; strobe++ ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
230 { |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
231 uint8_t detected = 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 // 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
|
234 switch ( strobe ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
235 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
236 |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
237 // Strobe Mappings |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
238 // Rev Rev |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
239 // 0.2 0.4 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
240 #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
|
241 case 0: // D0 0 n/c |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
242 case 1: // D1 1 n/c |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
243 #endif |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
244 case 2: // D2 2 15 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
245 case 3: // D3 3 14 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
246 case 4: // D4 4 13 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
247 case 5: // D5 5 12 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
248 case 6: // D6 6 11 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
249 case 7: // D7 7 10 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
250 detected = PIND & (1 << strobe); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
251 break; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
252 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
253 case 8: // E0 8 9 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
254 case 9: // E1 9 8 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
255 detected = PINE & (1 << (strobe - 8)); |
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 10: // C0 10 7 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
259 case 11: // C1 11 6 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
260 case 12: // C2 12 5 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
261 case 13: // C3 13 4 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
262 case 14: // C4 14 3 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
263 case 15: // C5 15 2 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
264 #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
|
265 case 16: // C6 16 1 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
266 case 17: // C7 17 0 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
267 #endif |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
268 detected = PINC & (1 << (strobe - 10)); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
269 break; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
270 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
271 default: |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
272 break; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
273 } |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
274 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
275 // Potential strobe line detected |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
276 if ( detected ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
277 { |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
278 strobe_map[total_strobes] = strobe; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
279 total_strobes++; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
280 } |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
281 } |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
282 |
155
7b4155f3b1b7
Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents:
154
diff
changeset
|
283 printInt8( total_strobes ); |
7b4155f3b1b7
Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents:
154
diff
changeset
|
284 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
|
285 |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
286 // 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
294 // Initialize ADC |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
295 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
|
296 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
297 // 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
|
298 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
|
299 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
300 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
|
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 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
303 // 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
|
304 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
|
305 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
306 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
|
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 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
309 |
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 // 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
|
312 // 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
|
313 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
|
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 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
|
316 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
317 // 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
|
318 // 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
|
319 // 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
|
320 // 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
|
321 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
|
322 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
323 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
324 |
213
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
325 // 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
|
326 // 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
|
327 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
|
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 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
330 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
331 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
332 |
213
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
333 // 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
|
334 // 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
|
335 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
|
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 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
338 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
339 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
340 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
341 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
|
342 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
343 // 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
|
344 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
|
345 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
|
346 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
347 // 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
|
348 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
|
349 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
|
350 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
351 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
|
352 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
353 // 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
|
354 key_activity = 0; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
355 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
356 // 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
|
357 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
|
358 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
359 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
|
360 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
361 // Sample the ADCs for the given column/strobe |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
362 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
|
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 // 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
|
365 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
|
366 { |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
367 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
|
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 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
370 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
|
371 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
|
372 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
373 // 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
|
374 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
|
375 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
|
376 } |
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 // 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
|
379 // 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
|
380 // 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
|
381 // 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
|
382 // 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
|
383 // 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
|
384 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
|
385 { |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
386 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
|
387 { |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
388 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
|
389 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
390 // 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
|
391 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
|
392 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
393 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
|
394 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
|
395 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
396 // 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
|
397 else |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
398 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
399 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
|
400 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
|
401 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
402 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
403 // 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
|
404 // 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
|
405 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
|
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 // 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
|
408 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
|
409 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
410 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
411 } // 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
|
412 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
413 // 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
|
414 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
|
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 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
|
417 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
|
418 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
|
419 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
420 // 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
|
421 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
|
422 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
423 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
|
424 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
|
425 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
426 } |
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 // 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
|
429 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
|
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 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
|
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 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
|
434 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
435 // 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
|
436 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
|
437 // 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
|
438 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
|
439 break; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
440 // 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 print("."); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
446 break; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
447 // 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
|
448 case WARMUP_STOP: |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
449 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
|
450 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
|
451 printInt16( WARMUP_LOOPS ); |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
452 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
|
453 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
454 // 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
|
455 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
|
456 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
|
457 print("): "); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
458 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
|
459 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
460 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
|
461 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
|
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( 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
|
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(" 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
|
466 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
|
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( low_avg ); |
155
7b4155f3b1b7
Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents:
154
diff
changeset
|
469 |
7b4155f3b1b7
Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents:
154
diff
changeset
|
470 print(" Rejection threshold: "); |
7b4155f3b1b7
Giving more breathing room for regular keys to be enable initially.
Jacob Alexander <haata@kiibohd.com>
parents:
154
diff
changeset
|
471 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
|
472 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
|
473 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
474 // 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
|
475 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
|
476 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
477 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
|
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 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
|
480 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
|
481 print(" ("); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
482 printHex( keys_problem[key] ); |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
483 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
|
484 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
485 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
486 |
158
0e3038f30819
Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents:
157
diff
changeset
|
487 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
|
488 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
|
489 break; |
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 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
492 else |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
493 { |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
494 // No keypress, accumulate averages |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
495 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
|
496 { |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
497 // 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
|
498 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
|
499 { |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
500 // Average Debugging |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
501 if ( enableAvgDebug ) |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
502 { |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
503 print("\033[1mAvg\033[0m: "); |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
504 } |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
505 |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
506 // aggregate |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
507 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
|
508 { |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
509 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
|
510 //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
|
511 uint32_t av = keys_averages[i]; |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
512 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
513 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
|
514 av >>= KEYS_AVERAGES_MIX_SHIFT; |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
515 |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
516 keys_averages[i] = av; |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
517 keys_averages_acc[i] = 0; |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
518 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
519 // Average Debugging |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
520 if ( enableAvgDebug && av > 0 ) |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
521 { |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
522 printHex( av ); |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
523 print(" "); |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
524 } |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
525 } |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
526 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
527 // Average Debugging |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
528 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
|
529 { |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
530 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
|
531 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
532 |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
533 // 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
|
534 key_release = 1; |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
535 } |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
536 // Otherwise decrement the idle counter |
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
537 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
|
538 { |
156
f663391a20f1
Fixed repeated press/release of a single key bug.
Jacob Alexander <haata@kiibohd.com>
parents:
155
diff
changeset
|
539 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
|
540 } |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
541 } |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
542 // Keypresses, reset accumulators |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
543 else if ( key_release ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
544 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
545 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
|
546 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
547 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
|
548 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
549 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
550 // If the debugging sense table is non-zero, display |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
551 if ( senseDebugCount > 0 ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
552 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
553 senseDebugCount--; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
554 print( NL ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
555 dumpSenseTable(); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
556 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
557 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
558 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
559 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
560 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
561 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
|
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 // 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
569 // 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
|
570 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
|
571 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
|
572 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
|
573 // 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
|
574 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
|
575 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
|
576 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
|
577 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
578 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
|
579 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
580 // 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
|
581 //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
|
582 //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
|
583 //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
|
584 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
|
585 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
586 // 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
|
587 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
|
588 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
|
589 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
590 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
|
591 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
|
592 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
593 |
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 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
|
596 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
601 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
|
602 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
603 // 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
|
604 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
|
605 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
|
606 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
|
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 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
|
609 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
|
610 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
|
611 |
308 | 612 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
|
613 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
|
614 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
|
615 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
|
616 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
617 else |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
618 { |
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_CONTROL); |
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 PORTB &= ~(1 << RECOVERY_SOURCE); // SOURCE low |
308 | 622 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
|
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 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
625 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
626 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 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
|
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 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
|
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 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
|
632 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
|
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 else |
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 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
|
637 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
|
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 } |
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 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
642 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
|
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 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
|
645 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
|
646 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
|
647 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 // 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
|
649 // 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
|
650 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
|
651 { |
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 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
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 |
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 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
|
663 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
|
664 |
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 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
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
674 default: |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
675 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 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
677 } |
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 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
680 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
|
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 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
|
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 //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
|
685 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
|
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 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
|
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 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
690 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
691 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
|
692 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
693 // 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
|
694 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
|
695 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
696 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
|
697 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
|
698 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
|
699 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
700 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
|
701 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
|
702 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
703 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
|
704 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
|
705 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
706 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
|
707 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
|
708 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
709 // 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
|
710 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
|
711 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
712 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
|
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 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
|
715 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
|
716 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
|
717 do { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
718 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
|
719 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
720 // retrieve current read. |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
721 uint16_t readVal = getADC(); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
722 samples[column][mux] = readVal; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
723 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
724 // Update max sense sample table |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
725 if ( readVal > sampleMax[column][mux] ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
726 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
727 sampleMax[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 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
730 mux++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
731 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
732 } 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
|
733 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
734 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
|
735 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
|
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 // 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
|
738 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
|
739 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
740 // 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
|
741 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
|
742 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
|
743 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
|
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 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
|
746 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
|
747 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
|
748 } |
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 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
751 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
|
752 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
753 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
|
754 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
|
755 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
|
756 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
757 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
|
758 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
|
759 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
760 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
|
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 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
|
763 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
764 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
|
765 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
766 // 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
|
767 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
|
768 { |
158
0e3038f30819
Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents:
157
diff
changeset
|
769 // 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
|
770 // re-enable the key |
158
0e3038f30819
Adding different algorithm to re-enable problem keys.
Jacob Alexander <haata@kiibohd.com>
parents:
157
diff
changeset
|
771 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
|
772 //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
|
773 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
774 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
|
775 printHex( key ); |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
776 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
|
777 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
778 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
|
779 } |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
780 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
781 // 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
|
782 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
|
783 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
784 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
785 // 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
|
786 // 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
|
787 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
|
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 column |= bit; |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
790 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
|
791 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
|
792 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
793 // 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
|
794 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
|
795 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
796 // 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
|
797 // 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
|
798 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
|
799 { |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
800 // Debug message, pressDebug CLI |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
801 if ( enablePressDebug ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
802 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
803 print("0x"); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
804 printHex_op( key, 2 ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
805 print(" "); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
806 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
807 |
176
d3ae6b409cfa
Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents:
159
diff
changeset
|
808 // Initial Keypress |
d3ae6b409cfa
Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents:
159
diff
changeset
|
809 Macro_keyState( key, 0x01 ); |
d3ae6b409cfa
Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents:
159
diff
changeset
|
810 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
811 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
812 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
|
813 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
814 } |
213
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
815 else if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD ) |
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
816 { |
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
817 // Held Key |
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
818 Macro_keyState( key, 0x02 ); |
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
819 } |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
820 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
821 // Long form key debugging |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
822 if ( enableKeyDebug ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
823 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
824 // Debug message |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
825 // <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
|
826 dbug_msg(""); |
159
84beeecd2c94
Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents:
158
diff
changeset
|
827 printHex_op( key, 1 ); |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
828 print(" ["); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
829 printInt8( strobe ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
830 print(":"); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
831 printInt8( mux ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
832 print("] : "); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
833 printHex( db_sample ); // Sense |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
834 print(" : "); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
835 printHex( db_threshold ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
836 print("+"); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
837 printHex( db_delta ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
838 print("="); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
839 printHex( db_threshold + db_delta ); // Sense compare |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
840 print(" : "); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
841 printHex( db_sample - ( db_threshold + db_delta ) ); // Margin |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
842 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
|
843 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
844 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
845 // 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
|
846 else |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
847 { |
176
d3ae6b409cfa
Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents:
159
diff
changeset
|
848 // Release Key |
213
2f6ec276a678
More fixes to the DPH scan module.
Jacob Alexander <haata@kiibohd.com>
parents:
200
diff
changeset
|
849 if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD ) |
159
84beeecd2c94
Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents:
158
diff
changeset
|
850 { |
176
d3ae6b409cfa
Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents:
159
diff
changeset
|
851 Macro_keyState( key, 0x03 ); |
159
84beeecd2c94
Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents:
158
diff
changeset
|
852 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
853 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
854 // 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
|
855 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
|
856 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
857 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
858 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
|
859 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
860 } |
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 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
863 void dumpSenseTable() |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
864 { |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
865 // Initial table alignment, with base threshold used for every key |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
866 print("\033[1m"); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
867 printHex( threshold ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
868 print("\033[0m "); |
141
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
869 |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
870 // Print out headers first |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
871 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
|
872 { |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
873 print(" Mux \033[1m"); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
874 printInt8( mux ); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
875 print("\033[0m "); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
876 } |
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( NL ); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
879 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
880 // 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
|
881 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
|
882 { |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
883 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
|
884 |
141
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
885 // Display the strobe |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
886 print("Strobe \033[1m"); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
887 printHex( strobe ); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
888 print("\033[0m "); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
889 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
890 // 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
|
891 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
|
892 { |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
893 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
|
894 uint8_t sample = samples[strobe][mux] >> 1; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
895 uint8_t max = sampleMax[strobe][mux] >> 1; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
896 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
897 // Indicate if the key is being pressed by displaying green |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
898 if ( sample > delta + threshold ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
899 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
900 print("\033[1;32m"); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
901 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
902 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
903 printHex_op( sample, 2 ); |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
904 print(":"); |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
905 printHex_op( max, 2 ); |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
906 print(":"); |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
907 printHex_op( delta, 2 ); |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
908 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
|
909 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
910 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
911 // New line for each strobe |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
912 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
|
913 } |
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 |
139
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
916 |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
917 // ----- CLI Command Functions ----- |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
918 |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
919 // 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
|
920 void cliFunc_echo( char* args ) |
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 char* curArgs; |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
923 char* arg1Ptr; |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
924 char* arg2Ptr = args; |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
925 |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
926 // Parse args until a \0 is found |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
927 while ( 1 ) |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
928 { |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
929 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
|
930 |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
931 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
|
932 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
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 // 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
|
935 if ( *arg1Ptr == '\0' ) |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
936 break; |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
937 |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
938 // Print out the arg |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
939 dPrint( arg1Ptr ); |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
940 } |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
941 } |
1ab045ef4266
Adding example CLI command to DPH module.
Jacob Alexander <haata@kiibohd.com>
parents:
138
diff
changeset
|
942 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
943 void cliFunc_avgDebug( char* args ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
944 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
945 print( NL ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
946 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
947 // Args ignored, just toggling |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
948 if ( enableAvgDebug ) |
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 info_print("Cap Sense averaging debug disabled."); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
951 enableAvgDebug = 0; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
952 } |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
953 else |
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 enabled."); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
956 enableAvgDebug = 1; |
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 } |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
959 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
960 void cliFunc_keyDebug( char* args ) |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
961 { |
141
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
962 print( NL ); |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
963 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
964 // Args ignored, just toggling |
141
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
965 if ( enableKeyDebug ) |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
966 { |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
967 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
|
968 enableKeyDebug = 0; |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
969 } |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
970 else |
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 enabled - pre debounce."); |
141
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
973 enableKeyDebug = 1; |
6e09a82d15ee
Added better formatting for debugging code.
Jacob Alexander <haata@kiibohd.com>
parents:
140
diff
changeset
|
974 } |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
975 } |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
976 |
153
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
977 void cliFunc_pressDebug( char* args ) |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
978 { |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
979 print( NL ); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
980 |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
981 // Args ignored, just toggling |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
982 if ( enablePressDebug ) |
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 info_print("Cap Sense key debug disabled - post debounce."); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
985 enablePressDebug = 0; |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
986 } |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
987 else |
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 enabled - post debounce."); |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
990 enablePressDebug = 1; |
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 } |
0f8218554421
Press/Release is working!
Jacob Alexander <haata@kiibohd.com>
parents:
141
diff
changeset
|
993 |
154
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
994 void cliFunc_problemKeys( char* args ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
995 { |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
996 print( NL ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
997 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
998 uint8_t count = 0; |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
999 |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1000 // Args ignored, just displaying |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1001 // Display problem keys, and the sense value at the time |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1002 for ( uint8_t key = 0; key < KEY_COUNT; key++ ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1003 { |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1004 if ( keys_problem[key] ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1005 { |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1006 if ( count++ == 0 ) |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1007 { |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1008 warn_msg("Problem keys: "); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1009 } |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1010 printHex( key ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1011 print(" ("); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1012 printHex( keys_problem[key] ); |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1013 print(") " ); |
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 } |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1016 } |
a2be5e8fc3d7
Adding strobe detection.
Jacob Alexander <haata@kiibohd.com>
parents:
153
diff
changeset
|
1017 |
140
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1018 void cliFunc_senseDebug( char* args ) |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1019 { |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1020 // Parse code from argument |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1021 // 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
|
1022 char* arg1Ptr; |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1023 char* arg2Ptr; |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1024 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1025 |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1026 // Default to a single print |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1027 senseDebugCount = 1; |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1028 |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1029 // 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
|
1030 if ( *arg1Ptr != '\0' ) |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1031 { |
195
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1032 senseDebugCount = numToInt( arg1Ptr ); |
140
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 } |
98e4f0bc2a5b
Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents:
139
diff
changeset
|
1035 |