Skip to content

Commit 21b1132

Browse files
joschCalcProgrammer1
authored andcommitted
MNTKeyboardController: Add support for the MNT Reform and MNT Pocket Reform RGB keyboards
1 parent 6672b53 commit 21b1132

13 files changed

Lines changed: 618 additions & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*---------------------------------------------------------*\
2+
| MNTKeyboardController.cpp |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include "MNTKeyboardController.h"
13+
14+
MNTKeyboardController::~MNTKeyboardController()
15+
{
16+
hid_close(dev);
17+
}
18+
19+
void MNTKeyboardController::SendColorMatrix(unsigned char *color_map)
20+
{
21+
unsigned char row_size = kbd_cols * KBD_COLOR_SIZE;
22+
unsigned char cmdbuf_size = CMD_OFFSET + row_size;
23+
unsigned char usb_buf[cmdbuf_size];
24+
memcpy(usb_buf, CMD_PREFIX, CMD_PREFIX_LEN);
25+
for(unsigned int row_idx = 0; row_idx < KBD_ROWS; row_idx++)
26+
{
27+
usb_buf[CMD_PREFIX_LEN] = row_idx;
28+
memcpy(usb_buf + CMD_OFFSET, color_map + row_idx * row_size, row_size);
29+
hid_write(dev, usb_buf, cmdbuf_size);
30+
}
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------*\
2+
| MNTKeyboardController.h |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include <hidapi/hidapi.h>
15+
#include <cstring>
16+
#include <string>
17+
18+
#include "Detector.h"
19+
#include "LogManager.h"
20+
21+
#define KBD_ROWS 6
22+
#define KBD_COLOR_SIZE 3
23+
24+
#define CMD_PREFIX "xXRGB"
25+
#define CMD_OFFSET (sizeof("xXRGB"))
26+
#define CMD_PREFIX_LEN CMD_OFFSET - 1
27+
28+
#define KBD_VID 0x1209
29+
#define KBD_INTERFACE 0
30+
#define HID_USAGE_PAGE_DESKTOP 0x01
31+
#define HID_USAGE_DESKTOP_KEYBOARD 0x06
32+
33+
class MNTKeyboardController
34+
{
35+
public:
36+
~MNTKeyboardController();
37+
void SendColorMatrix(unsigned char *color_map);
38+
std::string location;
39+
unsigned char kbd_cols;
40+
41+
protected:
42+
hid_device *dev;
43+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*---------------------------------------------------------*\
2+
| MNTKeyboardControllerDetect.cpp |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include "Detector.h"
13+
#include "LogManager.h"
14+
#include <hidapi/hidapi.h>
15+
#include "MNTReformKeyboardController.h"
16+
#include "MNTPocketReformKeyboardController.h"
17+
#include "RGBController_MNTReformKeyboard.h"
18+
#include "RGBController_MNTPocketReformKeyboard.h"
19+
20+
#define PID_KBD_REFORM 0x6D02
21+
#define PID_KBD_POCKET_REFORM 0x6D06
22+
23+
void DetectMNTKeyboardControllers(hid_device_info *info, const std::string &name)
24+
{
25+
LOG_DEBUG("[%s] trying to detect … ", name.c_str());
26+
hid_device *dev = hid_open_path(info->path);
27+
if(dev)
28+
{
29+
LOG_DEBUG("[%s] found at %s", name.c_str(), info->path);
30+
if(info->product_id == PID_KBD_REFORM)
31+
{
32+
MNTReformKeyboardController *controller = new MNTReformKeyboardController(dev, info->path);
33+
RGBController_MNTReformKeyboard *rgb_controller = new RGBController_MNTReformKeyboard(controller);
34+
ResourceManager::get()->RegisterRGBController(rgb_controller);
35+
}
36+
else if(info->product_id == PID_KBD_POCKET_REFORM)
37+
{
38+
MNTPocketReformKeyboardController *controller = new MNTPocketReformKeyboardController(dev, info->path);
39+
RGBController_MNTPocketReformKeyboard *rgb_controller = new RGBController_MNTPocketReformKeyboard(controller);
40+
ResourceManager::get()->RegisterRGBController(rgb_controller);
41+
}
42+
else
43+
{
44+
return;
45+
}
46+
LOG_DEBUG("[%s] successfully registered", name.c_str());
47+
}
48+
}
49+
50+
REGISTER_HID_DETECTOR_IPU("MNT Reform Keyboard", DetectMNTKeyboardControllers, KBD_VID, PID_KBD_REFORM, KBD_INTERFACE, HID_USAGE_PAGE_DESKTOP, HID_USAGE_DESKTOP_KEYBOARD);
51+
REGISTER_HID_DETECTOR_IPU("MNT Pocket Reform Keyboard", DetectMNTKeyboardControllers, KBD_VID, PID_KBD_POCKET_REFORM, KBD_INTERFACE, HID_USAGE_PAGE_DESKTOP, HID_USAGE_DESKTOP_KEYBOARD);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*---------------------------------------------------------*\
2+
| MNTPocketReformKeyboardController.cpp |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include "MNTPocketReformKeyboardController.h"
13+
14+
MNTPocketReformKeyboardController::MNTPocketReformKeyboardController(hid_device *dev_handle, const char *path)
15+
{
16+
dev = dev_handle;
17+
location = path;
18+
kbd_cols = KBD_COLS_POCKET_REFORM;
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------*\
2+
| MNTPocketReformKeyboardController.cpp |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include "MNTKeyboardController.h"
15+
16+
#define KBD_COLS_POCKET_REFORM 12
17+
18+
class MNTPocketReformKeyboardController : public MNTKeyboardController
19+
{
20+
public:
21+
MNTPocketReformKeyboardController(hid_device *dev_handle, const char *path);
22+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*---------------------------------------------------------*\
2+
| MNTReformKeyboardController.cpp |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include "MNTReformKeyboardController.h"
13+
14+
MNTReformKeyboardController::MNTReformKeyboardController(hid_device *dev_handle, const char *path)
15+
{
16+
dev = dev_handle;
17+
location = path;
18+
kbd_cols = KBD_COLS_REFORM;
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------*\
2+
| MNTReformKeyboardController.h |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include "MNTKeyboardController.h"
15+
16+
#define KBD_COLS_REFORM 14
17+
18+
class MNTReformKeyboardController : public MNTKeyboardController
19+
{
20+
public:
21+
MNTReformKeyboardController(hid_device *dev_handle, const char *path);
22+
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*---------------------------------------------------------*\
2+
| RGBController_MNTKeyboard.cpp |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include "RGBController_MNTKeyboard.h"
13+
14+
void RGBController_MNTKeyboard::CommonInit()
15+
{
16+
vendor = "MNT Research";
17+
type = DEVICE_TYPE_KEYBOARD;
18+
location = controller->location;
19+
modes.resize(1);
20+
modes[0].name = "Direct";
21+
modes[0].flags = MODE_FLAG_HAS_PER_LED_COLOR;
22+
modes[0].color_mode = MODE_COLORS_PER_LED;
23+
SetupZones();
24+
SetAllLEDs(ToRGBColor(255, 255, 255));
25+
DeviceUpdateLEDs();
26+
}
27+
28+
RGBController_MNTKeyboard::~RGBController_MNTKeyboard()
29+
{
30+
delete zones[0].matrix_map;
31+
delete controller;
32+
}
33+
34+
void RGBController_MNTKeyboard::SetupZones()
35+
{
36+
zone new_zone;
37+
new_zone.type = ZONE_TYPE_MATRIX;
38+
new_zone.leds_count = KBD_ROWS * controller->kbd_cols;
39+
new_zone.matrix_map = new matrix_map_type;
40+
new_zone.matrix_map->height = KBD_ROWS;
41+
new_zone.matrix_map->width = controller->kbd_cols;
42+
new_zone.matrix_map->map = (unsigned int *)matrix_keys;
43+
zones.push_back(new_zone);
44+
for(unsigned int led_idx = 0; led_idx < zones[0].leds_count; led_idx++)
45+
{
46+
led new_led;
47+
new_led.name = led_names[led_idx];
48+
leds.push_back(new_led);
49+
}
50+
SetupColors();
51+
}
52+
53+
void RGBController_MNTKeyboard::DeviceUpdateLEDs()
54+
{
55+
unsigned char color_map[zones[0].leds_count * KBD_COLOR_SIZE];
56+
for(unsigned int led_idx = 0; led_idx < zones[0].leds_count; led_idx++)
57+
{
58+
RGBColor color = colors[led_idx];
59+
int offset = led_idx * KBD_COLOR_SIZE;
60+
color_map[offset + 2] = RGBGetRValue(color);
61+
color_map[offset + 1] = RGBGetGValue(color);
62+
color_map[offset + 0] = RGBGetBValue(color);
63+
}
64+
controller->SendColorMatrix(color_map);
65+
}
66+
67+
void RGBController_MNTKeyboard::ResizeZone(int, int)
68+
{
69+
}
70+
void RGBController_MNTKeyboard::UpdateZoneLEDs(int)
71+
{
72+
DeviceUpdateLEDs();
73+
}
74+
void RGBController_MNTKeyboard::UpdateSingleLED(int)
75+
{
76+
DeviceUpdateLEDs();
77+
}
78+
void RGBController_MNTKeyboard::DeviceUpdateMode()
79+
{
80+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*---------------------------------------------------------*\
2+
| RGBController_MNTKeyboard.h |
3+
| |
4+
| Driver for the MNT Reform keyboards |
5+
| |
6+
| Christian Heller <c.heller@plomlompom.de> 7 Aug 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include "RGBController.h"
15+
#include "RGBControllerKeyNames.h"
16+
#include "MNTKeyboardController.h"
17+
18+
#define NA 0xFFFFFFFF
19+
20+
class RGBController_MNTKeyboard : public RGBController
21+
{
22+
public:
23+
~RGBController_MNTKeyboard();
24+
void SetupZones();
25+
void DeviceUpdateLEDs();
26+
27+
void ResizeZone(int, int);
28+
void UpdateZoneLEDs(int);
29+
void UpdateSingleLED(int);
30+
void DeviceUpdateMode();
31+
32+
protected:
33+
const char **led_names;
34+
unsigned int *matrix_keys;
35+
void CommonInit();
36+
MNTKeyboardController *controller;
37+
};

0 commit comments

Comments
 (0)