Kaleidoscope
Kaleidoscope-Hardware-Model01.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Arduino.h>
4 
5 #define HARDWARE_IMPLEMENTATION Model01
6 #include "KeyboardioScanner.h"
7 
8 #define COLS 16
9 #define ROWS 4
10 
11 #define CRGB(r,g,b) (cRGB){b, g, r}
12 
13 class Model01 {
14  public:
15  Model01(void);
16  void syncLeds(void);
17  void setCrgbAt(byte row, byte col, cRGB color);
18  void setCrgbAt(uint8_t i, cRGB crgb);
19  cRGB getCrgbAt(uint8_t i);
20  cRGB getKeyColor(byte row, byte col);
21  uint8_t getLedIndex(byte row, byte col);
22 
23  void scanMatrix(void);
24  void readMatrix(void);
25  void actOnMatrixScan(void);
26  void setup();
27  void enableHighPowerLeds(void);
28  void enableScannerPower(void);
29  void rebootBootloader();
30 
31  boolean ledPowerFault(void);
32 
33  /* Key masking
34  * -----------
35  *
36  * There are situations when one wants to ignore key events for a while, and
37  * mask them out. These functions help do that. In isolation, they do nothing,
38  * plugins and the core firmware is expected to make use of these.
39  *
40  * See `handleKeyswitchEvent` in the Kaleidoscope sources for a use-case.
41  */
42  void maskKey(byte row, byte col);
43  void unMaskKey(byte row, byte col);
44  bool isKeyMasked(byte row, byte col);
45  void maskHeldKeys(void);
46 
51 
52  private:
53  static bool isLEDChanged;
54  static KeyboardioScanner leftHand;
55  static KeyboardioScanner rightHand;
56 
57  static keydata_t leftHandMask;
58  static keydata_t rightHandMask;
59 };
60 
61 #define SCANBIT(row,col) ((uint32_t)1 << ((row) * 8 + (7 - (col))))
62 
63 #define R0C0 SCANBIT(0, 0)
64 #define R0C1 SCANBIT(0, 1)
65 #define R0C2 SCANBIT(0, 2)
66 #define R0C3 SCANBIT(0, 3)
67 #define R0C4 SCANBIT(0, 4)
68 #define R0C5 SCANBIT(0, 5)
69 #define R0C6 SCANBIT(0, 6)
70 #define R0C7 SCANBIT(0, 7)
71 #define R1C0 SCANBIT(1, 0)
72 #define R1C1 SCANBIT(1, 1)
73 #define R1C2 SCANBIT(1, 2)
74 #define R1C3 SCANBIT(1, 3)
75 #define R1C4 SCANBIT(1, 4)
76 #define R1C5 SCANBIT(1, 5)
77 #define R1C6 SCANBIT(1, 6)
78 #define R1C7 SCANBIT(1, 7)
79 #define R2C0 SCANBIT(2, 0)
80 #define R2C1 SCANBIT(2, 1)
81 #define R2C2 SCANBIT(2, 2)
82 #define R2C3 SCANBIT(2, 3)
83 #define R2C4 SCANBIT(2, 4)
84 #define R2C5 SCANBIT(2, 5)
85 #define R2C6 SCANBIT(2, 6)
86 #define R2C7 SCANBIT(2, 7)
87 #define R3C0 SCANBIT(3, 0)
88 #define R3C1 SCANBIT(3, 1)
89 #define R3C2 SCANBIT(3, 2)
90 #define R3C3 SCANBIT(3, 3)
91 #define R3C4 SCANBIT(3, 4)
92 #define R3C5 SCANBIT(3, 5)
93 #define R3C6 SCANBIT(3, 6)
94 #define R3C7 SCANBIT(3, 7)
95 
96 #define R0C8 SCANBIT(0, 0)
97 #define R0C9 SCANBIT(0, 1)
98 #define R0C10 SCANBIT(0, 2)
99 #define R0C11 SCANBIT(0, 3)
100 #define R0C12 SCANBIT(0, 4)
101 #define R0C13 SCANBIT(0, 5)
102 #define R0C14 SCANBIT(0, 6)
103 #define R0C15 SCANBIT(0, 7)
104 #define R1C8 SCANBIT(1, 0)
105 #define R1C9 SCANBIT(1, 1)
106 #define R1C10 SCANBIT(1, 2)
107 #define R1C11 SCANBIT(1, 3)
108 #define R1C12 SCANBIT(1, 4)
109 #define R1C13 SCANBIT(1, 5)
110 #define R1C14 SCANBIT(1, 6)
111 #define R1C15 SCANBIT(1, 7)
112 #define R2C8 SCANBIT(2, 0)
113 #define R2C9 SCANBIT(2, 1)
114 #define R2C10 SCANBIT(2, 2)
115 #define R2C11 SCANBIT(2, 3)
116 #define R2C12 SCANBIT(2, 4)
117 #define R2C13 SCANBIT(2, 5)
118 #define R2C14 SCANBIT(2, 6)
119 #define R2C15 SCANBIT(2, 7)
120 #define R3C8 SCANBIT(3, 0)
121 #define R3C9 SCANBIT(3, 1)
122 #define R3C10 SCANBIT(3, 2)
123 #define R3C11 SCANBIT(3, 3)
124 #define R3C12 SCANBIT(3, 4)
125 #define R3C13 SCANBIT(3, 5)
126 #define R3C14 SCANBIT(3, 6)
127 #define R3C15 SCANBIT(3, 7)
128 
129 
130 #define LED_COUNT 64
131 
132 
133 #define LED_PGDN 0
134 #define LED_PGUP 1
135 #define LED_BACKTICK 2
136 #define LED_PROG 3
137 #define LED_1 4
138 #define LED_Q 5
139 #define LED_A 6
140 #define LED_Z 7
141 #define LED_X 8
142 #define LED_S 9
143 #define LED_W 10
144 #define LED_2 11
145 #define LED_3 12
146 #define LED_E 13
147 #define LED_D 14
148 #define LED_C 15
149 #define LED_V 16
150 #define LED_F 17
151 #define LED_R 18
152 #define LED_4 19
153 #define LED_5 20
154 #define LED_T 21
155 #define LED_G 22
156 #define LED_B 23
157 #define LED_ESC 24
158 #define LED_TAB 25
159 #define LED_LED 26
160 #define LED_L_FN 27
161 #define LED_L_CTRL 28
162 #define LED_DEL 29
163 #define LED_CMD 30
164 #define LED_L_SHIFT 31
165 #define LED_R_SHIFT 32
166 #define LED_ALT 33
167 #define LED_SPACE 34
168 #define LED_CTRL 35
169 #define LED_R_FN 36
170 #define LED_ANY 37
171 #define LED_RETURN 38
172 #define LED_BUTTERFLY 39
173 #define LED_N 40
174 #define LED_H 41
175 #define LED_Y 42
176 #define LED_6 43
177 #define LED_7 44
178 #define LED_U 45
179 #define LED_J 46
180 #define LED_M 47
181 #define LED_COMMA 48
182 #define LED_K 49
183 #define LED_I 50
184 #define LED_8 51
185 #define LED_9 52
186 #define LED_O 53
187 #define LED_L 54
188 #define LED_PERIOD 55
189 #define LED_SLASH 56
190 #define LED_SEMICOLON 57
191 #define LED_P 58
192 #define LED_0 59
193 #define LED_NUM 60
194 #define LED_EQUALS 61
195 #define LED_APOSTROPHE 62
196 #define LED_MINUS 63
197 
198 #define KEYMAP_STACKED( \
199  r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \
200  r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \
201  r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, \
202  r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r2c6, \
203  r0c7, r1c7, r2c7, r3c7, \
204  r3c6, \
205  \
206  r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15, \
207  r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, \
208  r2c10, r2c11, r2c12, r2c13, r2c14, r2c15, \
209  r2c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15, \
210  r3c8, r2c8, r1c8, r0c8, \
211  r3c9) \
212  { \
213  {r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c7, r0c8, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15}, \
214  {r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c7, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15}, \
215  {r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c6, r2c7, r2c8, r2c9, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15}, \
216  {r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r3c6, r3c7, r3c8, r3c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15}, \
217  }
218 
219 #define KEYMAP( \
220  r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15, \
221  r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, \
222  r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15, \
223  r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r2c6, r2c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15, \
224  r0c7, r1c7, r2c7, r3c7, r3c8, r2c8, r1c8, r0c8, \
225  r3c6, r3c9) \
226  { \
227  {r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c7, r0c8, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15}, \
228  {r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c7, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15}, \
229  {r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c6, r2c7, r2c8, r2c9, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15}, \
230  {r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r3c6, r3c7, r3c8, r3c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15}, \
231  }
boolean ledPowerFault(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:121
keydata_t rightHandState
Definition: Kaleidoscope-Hardware-Model01.h:48
Definition: KeyboardioScanner.h:36
cRGB getCrgbAt(uint8_t i)
Definition: Kaleidoscope-Hardware-Model01.cpp:92
void setup()
Definition: Kaleidoscope-Hardware-Model01.cpp:50
void readMatrix(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:146
byte byte col
Definition: TapDance.cpp:229
void maskHeldKeys(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:240
void actOnMatrixScan(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:162
Definition: Kaleidoscope-Hardware-Model01.h:13
void enableHighPowerLeds(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:35
void scanMatrix(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:181
keydata_t previousRightHandState
Definition: Kaleidoscope-Hardware-Model01.h:50
Definition: Kaleidoscope-Hardware-Shortcut.h:29
void setCrgbAt(byte row, byte col, cRGB color)
Definition: Kaleidoscope-Hardware-Model01.cpp:84
Definition: KeyboardioScanner.h:44
keydata_t previousLeftHandState
Definition: Kaleidoscope-Hardware-Model01.h:49
void rebootBootloader()
Definition: Kaleidoscope-Hardware-Model01.cpp:186
byte row
Definition: TapDance.cpp:229
void unMaskKey(byte row, byte col)
Definition: Kaleidoscope-Hardware-Model01.cpp:218
Model01(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:18
void enableScannerPower(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:22
cRGB getKeyColor(byte row, byte col)
uint8_t getLedIndex(byte row, byte col)
Definition: Kaleidoscope-Hardware-Model01.cpp:88
bool isKeyMasked(byte row, byte col)
Definition: Kaleidoscope-Hardware-Model01.cpp:229
keydata_t leftHandState
Definition: Kaleidoscope-Hardware-Model01.h:47
void maskKey(byte row, byte col)
Definition: Kaleidoscope-Hardware-Model01.cpp:207
void syncLeds(void)
Definition: Kaleidoscope-Hardware-Model01.cpp:102