Skip to content

Commit 79e1233

Browse files
Chr1sNoCalcProgrammer1
authored andcommitted
Adding Wooting Two keyboards support
+ Add full matrix map + Amend WootingKeyboardController::SendDirect to support extra keys + Adjust WootingKeyboardController::wooting_usb_send_buffer to support extra buffer
1 parent ad6d605 commit 79e1233

File tree

4 files changed

+120
-47
lines changed

4 files changed

+120
-47
lines changed

Controllers/WootingKeyboardController/RGBController_WootingKeyboard.cpp

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,41 @@
1313
#define NA 0xFFFFFFFF
1414
#define RGB_RAW_BUFFER_SIZE 96
1515

16-
static unsigned int matrix_map[6][17] =
16+
static unsigned int matrix_map_tkl[6][17] =
1717
{
18-
{0, NA, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96},
19-
{1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97},
20-
{2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98},
21-
{3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, NA, NA, NA},
22-
{4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, NA, 82, NA, 94, NA},
23-
{5, 11, 17, NA, NA, NA, 41, NA, NA, NA, 65, 71, 77, 83, 89, 95, 101}
18+
{ 0, NA, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96},
19+
{ 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97},
20+
{ 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98},
21+
{ 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, NA, NA, NA},
22+
{ 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, NA, 82, NA, 94, NA},
23+
{ 5, 11, 17, NA, NA, NA, 41, NA, NA, NA, 65, 71, 77, 83, 89, 95, 101}
2424
};
2525

26-
static const char *zone_names[] =
26+
static unsigned int matrix_map_full[6][21] =
27+
{
28+
{ 0, NA, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 91, 90, 103, 109, 115, 96},
29+
{ 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 92, 98, 104, 110, 116, 122},
30+
{ 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 93, 99, 105, 111, 117, 123},
31+
{ 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, NA, NA, NA, 106, 112, 118, NA},
32+
{ 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, NA, 82, NA, 94, NA, 107, 113, 119, 125},
33+
{ 5, 11, 17, NA, NA, NA, 41, NA, NA, NA, 65, 71, 77, 83, 89, 95, 102, NA, 108, 120, NA}
34+
};
35+
36+
37+
/*static const char *zone_names[] =
2738
{
2839
"Keyboard"
2940
};
3041
3142
static zone_type zone_types[] =
3243
{
3344
ZONE_TYPE_MATRIX,
34-
};
45+
};*/
3546

3647
static const unsigned int zone_sizes[] =
3748
{
38-
102
49+
102,
50+
126
3951
};
4052

4153
static const char *led_names[] =
@@ -50,7 +62,7 @@ static const char *led_names[] =
5062
"Key: 1",
5163
"Key: Q",
5264
"Key: A",
53-
"Key: \\ (ISO)", //iso key - 10
65+
"Key: \\ (ISO)", //iso key - 10
5466
"Key: Left Windows",
5567
"Key: F1",
5668
"Key: 2",
@@ -60,7 +72,7 @@ static const char *led_names[] =
6072
"Key: Left Alt",
6173
"Key: F2",
6274
"Key: 3",
63-
"Key: E", //20
75+
"Key: E", //20
6476
"Key: D",
6577
"Key: X",
6678
"Unused", //space
@@ -70,7 +82,7 @@ static const char *led_names[] =
7082
"Key: F",
7183
"Key: C",
7284
"Unused", //space
73-
"Key: F4", //30
85+
"Key: F4", //30
7486
"Key: 5",
7587
"Key: T",
7688
"Key: G",
@@ -80,7 +92,7 @@ static const char *led_names[] =
8092
"Key: 6",
8193
"Key: Y",
8294
"Key: H",
83-
"Key: B", //40
95+
"Key: B", //40
8496
"Key: Space",
8597
"Key: F6",
8698
"Key: 7",
@@ -90,7 +102,7 @@ static const char *led_names[] =
90102
"Unused", //space
91103
"Key: F7",
92104
"Key: 8",
93-
"Key: I",
105+
"Key: I", //50
94106
"Key: K",
95107
"Key: M",
96108
"Unused", //space
@@ -100,7 +112,7 @@ static const char *led_names[] =
100112
"Key: L",
101113
"Key: ,",
102114
"Unused", //space
103-
"Key: F9",
115+
"Key: F9", //60
104116
"Key: 0",
105117
"Key: P",
106118
"Key: ;",
@@ -110,7 +122,7 @@ static const char *led_names[] =
110122
"Key: -",
111123
"Key: [",
112124
"Key: '",
113-
"Key: /",
125+
"Key: /", //70
114126
"Key: Right Windows",
115127
"Key: F11",
116128
"Key: =",
@@ -120,7 +132,7 @@ static const char *led_names[] =
120132
"Key: Right Fn",
121133
"Key: F12",
122134
"Key: Backspace",
123-
"Key: \\ (ANSI)",
135+
"Key: \\ (ANSI)", //80
124136
"Key: Enter",
125137
"Key: Right Shift",
126138
"Key: Right Control",
@@ -130,7 +142,7 @@ static const char *led_names[] =
130142
"Unused",
131143
"Unused",
132144
"Key: Left Arrow",
133-
"Key: Scroll Lock",
145+
"Key: Scroll Lock", //90
134146
"Key: Pause/Break",
135147
"Key: Home",
136148
"Key: End",
@@ -140,9 +152,33 @@ static const char *led_names[] =
140152
"Key: Mode",
141153
"Key: Page Up",
142154
"Key: Page Down",
155+
"Unused", //100
143156
"Unused",
157+
"Key: Right Arrow",
158+
"Key: A1",
159+
"Key: Num Lock",
160+
"Key: Number Pad 7",
161+
"Key: Number Pad 4",
162+
"Key: Number Pad 1",
163+
"Key: Number Pad 0",
164+
"Key: A2",
165+
"Key: Number Pad /", //110
166+
"Key: Number Pad 8",
167+
"Key: Number Pad 5",
168+
"Key: Number Pad 2",
144169
"Unused",
145-
"Key: Right Arrow"
170+
"Key: A3",
171+
"Key: Number Pad *",
172+
"Key: Number Pad 9",
173+
"Key: Number Pad 6",
174+
"Key: Number Pad 3",
175+
"Key: Number Pad .", //120
176+
"Unused",
177+
"Key: Number Pad -",
178+
"Key: Number Pad +",
179+
"Unused",
180+
"Key: Number Pad Enter",
181+
"Unused"
146182
};
147183

148184
RGBController_WootingKeyboard::RGBController_WootingKeyboard(WootingKeyboardController *wooting_ptr)
@@ -185,26 +221,27 @@ void RGBController_WootingKeyboard::SetupZones()
185221
/*---------------------------------------------------------*\
186222
| Set up zones |
187223
\*---------------------------------------------------------*/
188-
unsigned int total_led_count = 0;
224+
uint8_t wooting_type = wooting->GetWootingType();
225+
unsigned int total_led_count = zone_sizes[wooting_type];
189226

190-
for (unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
191-
{
227+
/*for (unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
228+
{*/
192229
zone new_zone;
193230

194-
new_zone.name = zone_names[zone_idx];
195-
new_zone.type = zone_types[zone_idx];
196-
new_zone.leds_min = zone_sizes[zone_idx];
197-
new_zone.leds_max = zone_sizes[zone_idx];
198-
new_zone.leds_count = zone_sizes[zone_idx];
231+
new_zone.name = name.append(" zone");
232+
new_zone.type = ZONE_TYPE_MATRIX;
233+
new_zone.leds_min = total_led_count;
234+
new_zone.leds_max = total_led_count;
235+
new_zone.leds_count = total_led_count;
199236
new_zone.matrix_map = new matrix_map_type;
200237
new_zone.matrix_map->height = 6;
201-
new_zone.matrix_map->width = 17;
202-
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
238+
new_zone.matrix_map->width = total_led_count / new_zone.matrix_map->height;
239+
new_zone.matrix_map->map = (wooting_type == WOOTING_KB_TKL) ? (unsigned int *)&matrix_map_tkl : (unsigned int *)&matrix_map_full;
203240

204241
zones.push_back(new_zone);
205242

206-
total_led_count += zone_sizes[zone_idx];
207-
}
243+
//total_led_count += zone_sizes[zone_idx];
244+
//}
208245

209246
for (unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)
210247
{

Controllers/WootingKeyboardController/WootingKeyboardController.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@
2121
#define WOOTING_TWO_KEY_CODE_LIMIT 116
2222
#define RGB_RAW_BUFFER_SIZE 96
2323

24+
#define WOOTING_RGB_ROWS 6
25+
#define WOOTING_RGB_COLUMNS 21
26+
#define WOOTING_ONE_RGB_COLUMNS 17
27+
#define WOOTING_TWO_RGB_COLUMNS 21
28+
2429
//0xFFFFFFFF indicates an unused entry in matrix
2530
#define NA 0xFFFFFFFF
2631

27-
static const unsigned int rgb_led_index[6][17] =
32+
static const unsigned int rgb_led_index[WOOTING_RGB_ROWS][WOOTING_RGB_COLUMNS] =
2833
{
29-
{0, NA, 11, 12, 23, 24, 36, 47, 85, 84, 49, 48, 59, 61, 73, 81, 80},
30-
{2, 1, 14, 13, 26, 25, 35, 38, 37, 87, 86, 95, 51, 63, 75, 72, 74},
31-
{3, 4, 15, 16, 27, 28, 39, 42, 40, 88, 89, 52, 53, 71, 76, 83, 77},
32-
{5, 6, 17, 18, 29, 30, 41, 46, 44, 90, 93, 54, 57, 65, NA, NA, NA},
33-
{9, 8, 19, 20, 31, 34, 32, 45, 43, 91, 92, 55, NA, 66, NA, 78, NA},
34-
{10, 22, 21, NA, NA, NA, 33, NA, NA, NA, 94, 58, 67, 68, 70, 79, 82}
34+
{ 0, NA, 11, 12, 23, 24, 36, 47, 85, 84, 49, 48, 59, 61, 73, 81, 80, 113, 114, 115, 116 },
35+
{ 2, 1, 14, 13, 26, 25, 35, 38, 37, 87, 86, 95, 51, 63, 75, 72, 74, 96, 97, 98, 99 },
36+
{ 3, 4, 15, 16, 27, 28, 39, 42, 40, 88, 89, 52, 53, 71, 76, 83, 77, 102, 103, 104, 100 },
37+
{ 5, 6, 17, 18, 29, 30, 41, 46, 44, 90, 93, 54, 57, 65, NA, NA, NA, 105, 106, 107, NA },
38+
{ 9, 8, 19, 20, 31, 34, 32, 45, 43, 91, 92, 55, NA, 66, NA, 78, NA, 108, 109, 110, 101 },
39+
{ 10, 22, 21, NA, NA, NA, 33, NA, NA, NA, 94, 58, 67, 68, 70, 79, 82, NA, 111, 112, NA }
3540
};
3641

3742
static uint16_t getCrc16ccitt(const uint8_t* buffer, uint16_t size)
@@ -58,13 +63,14 @@ static uint16_t getCrc16ccitt(const uint8_t* buffer, uint16_t size)
5863
return crc;
5964
}
6065

61-
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, const char *path)
66+
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, const char *path, uint8_t wooting_type)
6267
{
6368
const int szTemp = 256;
6469
wchar_t tmpName[szTemp];
6570

6671
dev = dev_handle;
6772
location = path;
73+
key_code_limit = (wooting_type == WOOTING_KB_TKL) ? WOOTING_ONE_KEY_CODE_LIMIT : WOOTING_TWO_KEY_CODE_LIMIT;
6874

6975
hid_get_manufacturer_string(dev, tmpName, szTemp);
7076
std::wstring wName = std::wstring(tmpName);
@@ -83,7 +89,7 @@ WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, con
8389

8490
WootingKeyboardController::~WootingKeyboardController()
8591
{
86-
92+
8793
}
8894

8995
std::string WootingKeyboardController::GetName()
@@ -111,6 +117,11 @@ std::string WootingKeyboardController::GetSerial()
111117
return serial;
112118
}
113119

120+
uint8_t WootingKeyboardController::GetWootingType()
121+
{
122+
return wooting_type;
123+
}
124+
114125
void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_colors)
115126
{
116127
const uint8_t pwm_mem_map[48] =
@@ -125,19 +136,24 @@ void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_co
125136
unsigned char buffer1[RGB_RAW_BUFFER_SIZE] = {0};
126137
unsigned char buffer2[RGB_RAW_BUFFER_SIZE] = {0};
127138
unsigned char buffer3[RGB_RAW_BUFFER_SIZE] = {0};
139+
unsigned char buffer4[RGB_RAW_BUFFER_SIZE] = {0};
128140

129141
for(std::size_t color_idx = 0; color_idx < num_colors; color_idx++)
130142
{
131143
unsigned char led_index = rgb_led_index[color_idx % 6][color_idx / 6];
132144

133-
if(led_index > 95)
145+
if(led_index > key_code_limit)
134146
{
135147
continue;
136148
}
137149

138150
unsigned char *buffer_pointer = buffer0;
139151

140-
if(led_index >= 72)
152+
if(led_index >= 96)
153+
{
154+
buffer_pointer = buffer4;
155+
}
156+
else if(led_index >= 72)
141157
{
142158
buffer_pointer = buffer3;
143159
}
@@ -164,6 +180,10 @@ void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_co
164180
wooting_usb_send_buffer(RGB_PARTS::PART1, buffer1);
165181
wooting_usb_send_buffer(RGB_PARTS::PART2, buffer2);
166182
wooting_usb_send_buffer(RGB_PARTS::PART3, buffer3);
183+
if(key_code_limit > WOOTING_ONE_KEY_CODE_LIMIT)
184+
{
185+
wooting_usb_send_buffer(RGB_PARTS::PART4, buffer4);
186+
}
167187
}
168188

169189
void WootingKeyboardController::SendInitialize()
@@ -179,8 +199,8 @@ bool WootingKeyboardController::wooting_usb_send_feature(uint8_t commandId, uint
179199
| Prevent sending unnecessary data to the Wootings if the |
180200
| index exceedes it's capabilities |
181201
\*---------------------------------------------------------*/
182-
if ((commandId == WOOTING_SINGLE_COLOR_COMMAND && parameter0 > WOOTING_ONE_KEY_CODE_LIMIT)
183-
|| (commandId == WOOTING_SINGLE_RESET_COMMAND && parameter3 > WOOTING_ONE_KEY_CODE_LIMIT))
202+
if ((commandId == WOOTING_SINGLE_COLOR_COMMAND && parameter0 > key_code_limit)
203+
|| (commandId == WOOTING_SINGLE_RESET_COMMAND && parameter3 > key_code_limit))
184204
{
185205
/*-----------------------------------------------------*\
186206
| This is not a USB error so let's return true. |
@@ -246,6 +266,11 @@ bool WootingKeyboardController::wooting_usb_send_buffer(RGB_PARTS part_number, u
246266
report_buffer[5] = RGB_RAW_BUFFER_SIZE; // Reg start address
247267
break;
248268

269+
case PART4:
270+
report_buffer[4] = 2; // Slave nr
271+
report_buffer[5] = 0; // Reg start address
272+
break;
273+
249274
default:
250275
return false;
251276
break;

Controllers/WootingKeyboardController/WootingKeyboardController.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
#pragma once
1616

17+
enum WOOTING_DEVICE_TYPE
18+
{
19+
WOOTING_KB_TKL = 0,
20+
WOOTING_KB_FULL = 1
21+
};
22+
1723
enum RGB_PARTS
1824
{
1925
PART0,
@@ -26,7 +32,7 @@ enum RGB_PARTS
2632
class WootingKeyboardController
2733
{
2834
public:
29-
WootingKeyboardController(hid_device* dev_handle, const char *path);
35+
WootingKeyboardController(hid_device* dev_handle, const char *path, uint8_t wooting_type);
3036
~WootingKeyboardController();
3137

3238
void SendDirect(RGBColor* colors, unsigned int num_colors);
@@ -35,13 +41,16 @@ class WootingKeyboardController
3541
std::string GetDescription();
3642
std::string GetLocation();
3743
std::string GetSerial();
44+
uint8_t GetWootingType();
3845
private:
3946
hid_device* dev;
4047
std::string name;
4148
std::string vendor;
4249
std::string description;
4350
std::string location;
4451
std::string serial;
52+
uint8_t wooting_type;
53+
uint8_t key_code_limit;
4554

4655
void SendInitialize();
4756

Controllers/WootingKeyboardController/WootingKeyboardControllerDetect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ void DetectWootingKeyboardControllers(hid_device_info* info, const std::string&
2828

2929
if(dev)
3030
{
31-
WootingKeyboardController* controller = new WootingKeyboardController(dev, info->path);
31+
uint8_t wooting_type = (info->product_id == WOOTING_ONE_PID) ? WOOTING_KB_TKL : WOOTING_KB_FULL;
32+
33+
WootingKeyboardController* controller = new WootingKeyboardController(dev, info->path, wooting_type);
3234
RGBController_WootingKeyboard* rgb_controller = new RGBController_WootingKeyboard(controller);
3335
rgb_controller->name = name;
3436
ResourceManager::get()->RegisterRGBController(rgb_controller);

0 commit comments

Comments
 (0)