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
This commit is contained in:
Chris 2021-06-28 13:23:08 +10:00 committed by Adam Honse
parent ad6d605c88
commit 79e1233635
4 changed files with 120 additions and 47 deletions

View file

@ -13,17 +13,28 @@
#define NA 0xFFFFFFFF
#define RGB_RAW_BUFFER_SIZE 96
static unsigned int matrix_map[6][17] =
static unsigned int matrix_map_tkl[6][17] =
{
{0, NA, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96},
{1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97},
{2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98},
{3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, NA, NA, NA},
{4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, NA, 82, NA, 94, NA},
{5, 11, 17, NA, NA, NA, 41, NA, NA, NA, 65, 71, 77, 83, 89, 95, 101}
{ 0, NA, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96},
{ 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97},
{ 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98},
{ 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, NA, NA, NA},
{ 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, NA, 82, NA, 94, NA},
{ 5, 11, 17, NA, NA, NA, 41, NA, NA, NA, 65, 71, 77, 83, 89, 95, 101}
};
static const char *zone_names[] =
static unsigned int matrix_map_full[6][21] =
{
{ 0, NA, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 91, 90, 103, 109, 115, 96},
{ 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 92, 98, 104, 110, 116, 122},
{ 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 93, 99, 105, 111, 117, 123},
{ 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, NA, NA, NA, 106, 112, 118, NA},
{ 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, NA, 82, NA, 94, NA, 107, 113, 119, 125},
{ 5, 11, 17, NA, NA, NA, 41, NA, NA, NA, 65, 71, 77, 83, 89, 95, 102, NA, 108, 120, NA}
};
/*static const char *zone_names[] =
{
"Keyboard"
};
@ -31,11 +42,12 @@ static const char *zone_names[] =
static zone_type zone_types[] =
{
ZONE_TYPE_MATRIX,
};
};*/
static const unsigned int zone_sizes[] =
{
102
102,
126
};
static const char *led_names[] =
@ -50,7 +62,7 @@ static const char *led_names[] =
"Key: 1",
"Key: Q",
"Key: A",
"Key: \\ (ISO)", //iso key - 10
"Key: \\ (ISO)", //iso key - 10
"Key: Left Windows",
"Key: F1",
"Key: 2",
@ -60,7 +72,7 @@ static const char *led_names[] =
"Key: Left Alt",
"Key: F2",
"Key: 3",
"Key: E", //20
"Key: E", //20
"Key: D",
"Key: X",
"Unused", //space
@ -70,7 +82,7 @@ static const char *led_names[] =
"Key: F",
"Key: C",
"Unused", //space
"Key: F4", //30
"Key: F4", //30
"Key: 5",
"Key: T",
"Key: G",
@ -80,7 +92,7 @@ static const char *led_names[] =
"Key: 6",
"Key: Y",
"Key: H",
"Key: B", //40
"Key: B", //40
"Key: Space",
"Key: F6",
"Key: 7",
@ -90,7 +102,7 @@ static const char *led_names[] =
"Unused", //space
"Key: F7",
"Key: 8",
"Key: I",
"Key: I", //50
"Key: K",
"Key: M",
"Unused", //space
@ -100,7 +112,7 @@ static const char *led_names[] =
"Key: L",
"Key: ,",
"Unused", //space
"Key: F9",
"Key: F9", //60
"Key: 0",
"Key: P",
"Key: ;",
@ -110,7 +122,7 @@ static const char *led_names[] =
"Key: -",
"Key: [",
"Key: '",
"Key: /",
"Key: /", //70
"Key: Right Windows",
"Key: F11",
"Key: =",
@ -120,7 +132,7 @@ static const char *led_names[] =
"Key: Right Fn",
"Key: F12",
"Key: Backspace",
"Key: \\ (ANSI)",
"Key: \\ (ANSI)", //80
"Key: Enter",
"Key: Right Shift",
"Key: Right Control",
@ -130,7 +142,7 @@ static const char *led_names[] =
"Unused",
"Unused",
"Key: Left Arrow",
"Key: Scroll Lock",
"Key: Scroll Lock", //90
"Key: Pause/Break",
"Key: Home",
"Key: End",
@ -140,9 +152,33 @@ static const char *led_names[] =
"Key: Mode",
"Key: Page Up",
"Key: Page Down",
"Unused", //100
"Unused",
"Key: Right Arrow",
"Key: A1",
"Key: Num Lock",
"Key: Number Pad 7",
"Key: Number Pad 4",
"Key: Number Pad 1",
"Key: Number Pad 0",
"Key: A2",
"Key: Number Pad /", //110
"Key: Number Pad 8",
"Key: Number Pad 5",
"Key: Number Pad 2",
"Unused",
"Key: Right Arrow"
"Key: A3",
"Key: Number Pad *",
"Key: Number Pad 9",
"Key: Number Pad 6",
"Key: Number Pad 3",
"Key: Number Pad .", //120
"Unused",
"Key: Number Pad -",
"Key: Number Pad +",
"Unused",
"Key: Number Pad Enter",
"Unused"
};
RGBController_WootingKeyboard::RGBController_WootingKeyboard(WootingKeyboardController *wooting_ptr)
@ -185,26 +221,27 @@ void RGBController_WootingKeyboard::SetupZones()
/*---------------------------------------------------------*\
| Set up zones |
\*---------------------------------------------------------*/
unsigned int total_led_count = 0;
uint8_t wooting_type = wooting->GetWootingType();
unsigned int total_led_count = zone_sizes[wooting_type];
for (unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
{
/*for (unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
{*/
zone new_zone;
new_zone.name = zone_names[zone_idx];
new_zone.type = zone_types[zone_idx];
new_zone.leds_min = zone_sizes[zone_idx];
new_zone.leds_max = zone_sizes[zone_idx];
new_zone.leds_count = zone_sizes[zone_idx];
new_zone.name = name.append(" zone");
new_zone.type = ZONE_TYPE_MATRIX;
new_zone.leds_min = total_led_count;
new_zone.leds_max = total_led_count;
new_zone.leds_count = total_led_count;
new_zone.matrix_map = new matrix_map_type;
new_zone.matrix_map->height = 6;
new_zone.matrix_map->width = 17;
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
new_zone.matrix_map->width = total_led_count / new_zone.matrix_map->height;
new_zone.matrix_map->map = (wooting_type == WOOTING_KB_TKL) ? (unsigned int *)&matrix_map_tkl : (unsigned int *)&matrix_map_full;
zones.push_back(new_zone);
total_led_count += zone_sizes[zone_idx];
}
//total_led_count += zone_sizes[zone_idx];
//}
for (unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)
{

View file

@ -21,17 +21,22 @@
#define WOOTING_TWO_KEY_CODE_LIMIT 116
#define RGB_RAW_BUFFER_SIZE 96
#define WOOTING_RGB_ROWS 6
#define WOOTING_RGB_COLUMNS 21
#define WOOTING_ONE_RGB_COLUMNS 17
#define WOOTING_TWO_RGB_COLUMNS 21
//0xFFFFFFFF indicates an unused entry in matrix
#define NA 0xFFFFFFFF
static const unsigned int rgb_led_index[6][17] =
static const unsigned int rgb_led_index[WOOTING_RGB_ROWS][WOOTING_RGB_COLUMNS] =
{
{0, NA, 11, 12, 23, 24, 36, 47, 85, 84, 49, 48, 59, 61, 73, 81, 80},
{2, 1, 14, 13, 26, 25, 35, 38, 37, 87, 86, 95, 51, 63, 75, 72, 74},
{3, 4, 15, 16, 27, 28, 39, 42, 40, 88, 89, 52, 53, 71, 76, 83, 77},
{5, 6, 17, 18, 29, 30, 41, 46, 44, 90, 93, 54, 57, 65, NA, NA, NA},
{9, 8, 19, 20, 31, 34, 32, 45, 43, 91, 92, 55, NA, 66, NA, 78, NA},
{10, 22, 21, NA, NA, NA, 33, NA, NA, NA, 94, 58, 67, 68, 70, 79, 82}
{ 0, NA, 11, 12, 23, 24, 36, 47, 85, 84, 49, 48, 59, 61, 73, 81, 80, 113, 114, 115, 116 },
{ 2, 1, 14, 13, 26, 25, 35, 38, 37, 87, 86, 95, 51, 63, 75, 72, 74, 96, 97, 98, 99 },
{ 3, 4, 15, 16, 27, 28, 39, 42, 40, 88, 89, 52, 53, 71, 76, 83, 77, 102, 103, 104, 100 },
{ 5, 6, 17, 18, 29, 30, 41, 46, 44, 90, 93, 54, 57, 65, NA, NA, NA, 105, 106, 107, NA },
{ 9, 8, 19, 20, 31, 34, 32, 45, 43, 91, 92, 55, NA, 66, NA, 78, NA, 108, 109, 110, 101 },
{ 10, 22, 21, NA, NA, NA, 33, NA, NA, NA, 94, 58, 67, 68, 70, 79, 82, NA, 111, 112, NA }
};
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)
return crc;
}
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, const char *path)
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, const char *path, uint8_t wooting_type)
{
const int szTemp = 256;
wchar_t tmpName[szTemp];
dev = dev_handle;
location = path;
key_code_limit = (wooting_type == WOOTING_KB_TKL) ? WOOTING_ONE_KEY_CODE_LIMIT : WOOTING_TWO_KEY_CODE_LIMIT;
hid_get_manufacturer_string(dev, tmpName, szTemp);
std::wstring wName = std::wstring(tmpName);
@ -83,7 +89,7 @@ WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, con
WootingKeyboardController::~WootingKeyboardController()
{
}
std::string WootingKeyboardController::GetName()
@ -111,6 +117,11 @@ std::string WootingKeyboardController::GetSerial()
return serial;
}
uint8_t WootingKeyboardController::GetWootingType()
{
return wooting_type;
}
void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_colors)
{
const uint8_t pwm_mem_map[48] =
@ -125,19 +136,24 @@ void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_co
unsigned char buffer1[RGB_RAW_BUFFER_SIZE] = {0};
unsigned char buffer2[RGB_RAW_BUFFER_SIZE] = {0};
unsigned char buffer3[RGB_RAW_BUFFER_SIZE] = {0};
unsigned char buffer4[RGB_RAW_BUFFER_SIZE] = {0};
for(std::size_t color_idx = 0; color_idx < num_colors; color_idx++)
{
unsigned char led_index = rgb_led_index[color_idx % 6][color_idx / 6];
if(led_index > 95)
if(led_index > key_code_limit)
{
continue;
}
unsigned char *buffer_pointer = buffer0;
if(led_index >= 72)
if(led_index >= 96)
{
buffer_pointer = buffer4;
}
else if(led_index >= 72)
{
buffer_pointer = buffer3;
}
@ -164,6 +180,10 @@ void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_co
wooting_usb_send_buffer(RGB_PARTS::PART1, buffer1);
wooting_usb_send_buffer(RGB_PARTS::PART2, buffer2);
wooting_usb_send_buffer(RGB_PARTS::PART3, buffer3);
if(key_code_limit > WOOTING_ONE_KEY_CODE_LIMIT)
{
wooting_usb_send_buffer(RGB_PARTS::PART4, buffer4);
}
}
void WootingKeyboardController::SendInitialize()
@ -179,8 +199,8 @@ bool WootingKeyboardController::wooting_usb_send_feature(uint8_t commandId, uint
| Prevent sending unnecessary data to the Wootings if the |
| index exceedes it's capabilities |
\*---------------------------------------------------------*/
if ((commandId == WOOTING_SINGLE_COLOR_COMMAND && parameter0 > WOOTING_ONE_KEY_CODE_LIMIT)
|| (commandId == WOOTING_SINGLE_RESET_COMMAND && parameter3 > WOOTING_ONE_KEY_CODE_LIMIT))
if ((commandId == WOOTING_SINGLE_COLOR_COMMAND && parameter0 > key_code_limit)
|| (commandId == WOOTING_SINGLE_RESET_COMMAND && parameter3 > key_code_limit))
{
/*-----------------------------------------------------*\
| 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
report_buffer[5] = RGB_RAW_BUFFER_SIZE; // Reg start address
break;
case PART4:
report_buffer[4] = 2; // Slave nr
report_buffer[5] = 0; // Reg start address
break;
default:
return false;
break;

View file

@ -14,6 +14,12 @@
#pragma once
enum WOOTING_DEVICE_TYPE
{
WOOTING_KB_TKL = 0,
WOOTING_KB_FULL = 1
};
enum RGB_PARTS
{
PART0,
@ -26,7 +32,7 @@ enum RGB_PARTS
class WootingKeyboardController
{
public:
WootingKeyboardController(hid_device* dev_handle, const char *path);
WootingKeyboardController(hid_device* dev_handle, const char *path, uint8_t wooting_type);
~WootingKeyboardController();
void SendDirect(RGBColor* colors, unsigned int num_colors);
@ -35,6 +41,7 @@ public:
std::string GetDescription();
std::string GetLocation();
std::string GetSerial();
uint8_t GetWootingType();
private:
hid_device* dev;
std::string name;
@ -42,6 +49,8 @@ private:
std::string description;
std::string location;
std::string serial;
uint8_t wooting_type;
uint8_t key_code_limit;
void SendInitialize();

View file

@ -28,7 +28,9 @@ void DetectWootingKeyboardControllers(hid_device_info* info, const std::string&
if(dev)
{
WootingKeyboardController* controller = new WootingKeyboardController(dev, info->path);
uint8_t wooting_type = (info->product_id == WOOTING_ONE_PID) ? WOOTING_KB_TKL : WOOTING_KB_FULL;
WootingKeyboardController* controller = new WootingKeyboardController(dev, info->path, wooting_type);
RGBController_WootingKeyboard* rgb_controller = new RGBController_WootingKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);