Kaleidoscope
Kaleidoscope-Hardware-Shortcut.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2  * Kaleidoscope-Hardware-Shortcut -- Shortcut hardware support for KaleidoscopeFirmware
3  * Copyright (C) 2017 Gergely Nagy
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <Arduino.h>
22 #include <AtmegaScanner.h>
23 
24 #define HARDWARE_IMPLEMENTATION Shortcut
25 
26 #define COLS 14
27 #define ROWS 4
28 
29 typedef struct {
30  uint8_t g;
31  uint8_t r;
32  uint8_t b;
33 } cRGB;
34 
35 #define CRGB(r, g, b) (cRGB){g, r, b}
36 
37 #define LED_COUNT 16
38 
39 class Shortcut {
40  public:
41  Shortcut(void);
42  void syncLeds(void);
43  void setCrgbAt(byte row, byte col, cRGB color);
44  void setCrgbAt(uint8_t i, cRGB crgb);
45  cRGB getCrgbAt(uint8_t i);
46  cRGB getKeyColor(byte row, byte col);
47 
48  void scanMatrix(void);
49  void readMatrix(void);
50  void actOnMatrixScan(void);
51  void setup();
52 
53  /* Key masking
54  * -----------
55  *
56  * There are situations when one wants to ignore key events for a while, and
57  * mask them out. These functions help do that. In isolation, they do nothing,
58  * plugins and the core firmware is expected to make use of these.
59  *
60  * See `handleKeyswitchEvent` in the Kaleidoscope sources for a use-case.
61  */
62  void maskKey(byte row, byte col);
63  void unMaskKey(byte row, byte col);
64  bool isKeyMasked(byte row, byte col);
65  void maskHeldKeys(void);
66 
68 
69  private:
70  cRGB leds[LED_COUNT];
71  static uint32_t leftHandMask;
72  static uint32_t rightHandMask;
73 };
74 
75 #define KEYMAP( \
76  r0c2 ,r0cb \
77  ,r0c1 ,r0c3 ,r0c4 ,r0c9 ,r0ca ,r0cc \
78  ,r0c0 ,r1c2 ,r1cb ,r0cd \
79  ,r2c0 ,r1c1 ,r1c3 ,r1c4 ,r1c9 ,r1ca ,r1cc ,r2cd \
80  ,r1c0 ,r2c2 ,r2cb ,r1cd \
81  ,r2c1 ,r2c3 ,r2ca ,r2cc \
82  \
83  ,r0c6 ,r0c7 \
84  ,r1c6 ,r3c6 ,r1c7 ,r3c7 \
85  ,r2c6 ,r2c7 \
86  \
87  ,r2c5 ,r2c8 \
88  ,r3c5 ,r1c5 ,r3c8 ,r1c8 \
89  ,r0c5 ,r0c8 \
90  ) \
91  { \
92  {r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c7, r0c8, r0c9, r0ca, r0cb, r0cc, r0cd}, \
93  {r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c7, r1c8, r1c9, r1ca, r1cb, r1cc, r1cd}, \
94  {r2c0, r2c1, r2c2, r2c3, XXX, r2c5, r2c6, r2c7, r2c8, XXX, r2ca, r2cb, r2cc, r2cd}, \
95  { XXX, XXX, XXX, XXX, XXX, r3c5, r3c6, r3c7, r3c8, XXX, XXX, XXX, XXX, XXX} \
96  }
97 
98 #define SCANBIT(row,col) ((uint32_t)1 << (row * (COLS / 2) + col))
99 
100 #define R0C0 SCANBIT(0, 0)
101 #define R0C1 SCANBIT(0, 1)
102 #define R0C2 SCANBIT(0, 2)
103 #define R0C3 SCANBIT(0, 3)
104 #define R0C4 SCANBIT(0, 4)
105 #define R0C5 SCANBIT(0, 5)
106 #define R0C6 SCANBIT(0, 6)
107 #define R1C0 SCANBIT(1, 0)
108 #define R1C1 SCANBIT(1, 1)
109 #define R1C2 SCANBIT(1, 2)
110 #define R1C3 SCANBIT(1, 3)
111 #define R1C4 SCANBIT(1, 4)
112 #define R1C5 SCANBIT(1, 5)
113 #define R1C6 SCANBIT(1, 6)
114 #define R2C0 SCANBIT(2, 0)
115 #define R2C1 SCANBIT(2, 1)
116 #define R2C2 SCANBIT(2, 2)
117 #define R2C3 SCANBIT(2, 3)
118 #define R2C4 SCANBIT(2, 4)
119 #define R2C5 SCANBIT(2, 5)
120 #define R2C6 SCANBIT(2, 6)
121 #define R3C0 SCANBIT(3, 0)
122 #define R3C1 SCANBIT(3, 1)
123 #define R3C2 SCANBIT(3, 2)
124 #define R3C3 SCANBIT(3, 3)
125 #define R3C4 SCANBIT(3, 4)
126 #define R3C5 SCANBIT(3, 5)
127 #define R3C6 SCANBIT(3, 6)
128 
129 #define R0C7 SCANBIT(0, 0)
130 #define R0C8 SCANBIT(0, 1)
131 #define R0C9 SCANBIT(0, 2)
132 #define R0C10 SCANBIT(0, 3)
133 #define R0C11 SCANBIT(0, 4)
134 #define R0C12 SCANBIT(0, 5)
135 #define R0C13 SCANBIT(0, 6)
136 #define R1C7 SCANBIT(1, 0)
137 #define R1C8 SCANBIT(1, 1)
138 #define R1C9 SCANBIT(1, 2)
139 #define R1C10 SCANBIT(1, 3)
140 #define R1C11 SCANBIT(1, 4)
141 #define R1C12 SCANBIT(1, 3)
142 #define R1C13 SCANBIT(1, 6)
143 #define R2C7 SCANBIT(2, 0)
144 #define R2C8 SCANBIT(2, 1)
145 #define R2C9 SCANBIT(2, 2)
146 #define R2C10 SCANBIT(2, 3)
147 #define R2C11 SCANBIT(2, 4)
148 #define R2C12 SCANBIT(2, 5)
149 #define R2C13 SCANBIT(2, 6)
150 #define R3C7 SCANBIT(3, 0)
151 #define R3C8 SCANBIT(3, 1)
152 #define R3C9 SCANBIT(3, 2)
153 #define R3C10 SCANBIT(3, 3)
154 #define R3C11 SCANBIT(3, 4)
155 #define R3C12 SCANBIT(3, 5)
156 #define R3C13 SCANBIT(3, 6)
cRGB getCrgbAt(uint8_t i)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:46
void actOnMatrixScan(void)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:58
void setup()
Definition: Kaleidoscope-Hardware-Shortcut.cpp:30
AtmegaScanner< COLS, ROWS > scanner
Definition: Kaleidoscope-Hardware-Shortcut.h:67
byte byte col
Definition: TapDance.cpp:229
uint8_t r
Definition: Kaleidoscope-Hardware-Shortcut.h:31
cRGB getKeyColor(byte row, byte col)
uint8_t g
Definition: Kaleidoscope-Hardware-Shortcut.h:30
Definition: Kaleidoscope-Hardware-Shortcut.h:39
bool isKeyMasked(byte row, byte col)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:101
void syncLeds(void)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:50
void unMaskKey(byte row, byte col)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:90
void scanMatrix(void)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:74
void setCrgbAt(byte row, byte col, cRGB color)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:43
#define LED_COUNT
Definition: Kaleidoscope-Hardware-Shortcut.h:37
Definition: Kaleidoscope-Hardware-Shortcut.h:29
uint8_t b
Definition: Kaleidoscope-Hardware-Shortcut.h:32
void maskKey(byte row, byte col)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:79
byte row
Definition: TapDance.cpp:229
Shortcut(void)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:27
void readMatrix(void)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:54
void maskHeldKeys(void)
Definition: Kaleidoscope-Hardware-Shortcut.cpp:112