[New Device/Implements] CH551G open source keyboard (Rebase)

This commit is contained in:
Yanzgz 2022-08-22 03:26:17 +00:00 committed by Adam Honse
parent 389cdf340f
commit 68df4d4b00
6 changed files with 580 additions and 0 deletions

View file

@ -0,0 +1,117 @@
/*---------------------------------------------------------------*\
| GaiZhongGaiKeyboardController.cpp |
| |
| https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO |
| |
| An Yang 2022/6/12 |
\*---------------------------------------------------------------*/
#include <cstring>
#include "GaiZhongGaiKeyboardController.h"
GaiZhongGaiKeyboardController::GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info)
{
dev = dev_handle;
location = info->path;
usb_pid = info->product_id;
/*-----------------------------------------------------*\
| Obtaining the Firmware Version |
\*-----------------------------------------------------*/
char str[10];
sprintf(str, "Ver%04X", info->release_number);
version = str;
}
GaiZhongGaiKeyboardController::~GaiZhongGaiKeyboardController()
{
/*-----------------------------------------------------*\
| Restore built-in light effect |
\*-----------------------------------------------------*/
unsigned char usb_buf[65];
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[1] = 0xFF;
hid_write(dev, usb_buf, 65);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
hid_close(dev);
}
std::string GaiZhongGaiKeyboardController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string GaiZhongGaiKeyboardController::GetSerialString()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
std::wstring return_wstring = serial_string;
std::string return_string(return_wstring.begin(), return_wstring.end());
return(return_string);
}
std::string GaiZhongGaiKeyboardController::GetVersion()
{
return(version);
}
unsigned short GaiZhongGaiKeyboardController::GetUSBPID()
{
return(usb_pid);
}
void GaiZhongGaiKeyboardController::SendColors
(
unsigned char* color_data,
unsigned int color_data_size
)
{
unsigned char usb_buf[65];
memset(usb_buf, 0x00, sizeof(usb_buf));
switch(usb_pid)
{
case GAIZHONGGAI_17_TOUCH_PRO_PID: //17PAD+Touch
case GAIZHONGGAI_20_PRO_PID: //20PAD
usb_buf[1] = 0x10;
memcpy(usb_buf + 2, color_data + 68 * 3, 60);
hid_write(dev, usb_buf, 65);
break;
case GAIZHONGGAI_17_PRO_PID: //17PAD
usb_buf[1] = 0x10;
memcpy(usb_buf + 2, color_data + 68 * 3, 51);
hid_write(dev, usb_buf, 65);
break;
case GAIZHONGGAI_68_PRO_PID: //68%
usb_buf[1] = 0x10;
memcpy(usb_buf + 2, color_data + 0 * 3, 63);
hid_write(dev, usb_buf, 65);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
usb_buf[1] = 0x11;
memcpy(usb_buf + 2, color_data + 21 * 3, 63);
hid_write(dev, usb_buf, 65);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
usb_buf[1] = 0x12;
memcpy(usb_buf + 2, color_data + 42 * 3, 63);
hid_write(dev, usb_buf, 65);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[1] = 0x13;
memcpy(usb_buf + 2, color_data + 63 * 3, 15);
hid_write(dev, usb_buf, 65);
break;
}
}

View file

@ -0,0 +1,51 @@
/*---------------------------------------------------------------*\
| GaiZhongGaiKeyboardController.h |
| |
| https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO |
| |
| An Yang 2022/6/12 |
\*---------------------------------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
/*-----------------------------------------------------*\
| GaiZhongGai vendor ID |
\*-----------------------------------------------------*/
#define GAIZHONGGAI_VID 0x3061
/*-----------------------------------------------------*\
| Keyboard product IDs |
\*-----------------------------------------------------*/
#define GAIZHONGGAI_68_PRO_PID 0x4700
#define GAIZHONGGAI_17_TOUCH_PRO_PID 0x4770
#define GAIZHONGGAI_17_PRO_PID 0x4771
#define GAIZHONGGAI_20_PRO_PID 0x4772
class GaiZhongGaiKeyboardController
{
public:
GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info);
~GaiZhongGaiKeyboardController();
std::string GetDeviceLocation();
std::string GetSerialString();
std::string GetVersion();
unsigned short GetUSBPID();
void SendColors
(
unsigned char* color_data,
unsigned int color_data_size
);
private:
hid_device* dev;
std::string location;
std::string version;
unsigned short usb_pid;
};

View file

@ -0,0 +1,38 @@
/*---------------------------------------------------------------*\
| GaiZhongGaiKeyboardControllerDetect.cpp |
| |
| https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO |
| |
| An Yang 2022/6/12 |
\*---------------------------------------------------------------*/
#include "Detector.h"
#include "GaiZhongGaiKeyboardController.h"
#include "RGBController.h"
#include "RGBController_GaiZhongGaiKeyboard.h"
#include <hidapi/hidapi.h>
/******************************************************************************************\
* *
* DetectGaiZhongGaiKeyboardControllers *
* *
* Tests the USB address to see if a GaiZhongGai RGB Keyboard controller exists there.*
* *
\******************************************************************************************/
void DetectGaiZhongGaiKeyboardControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if( dev )
{
GaiZhongGaiKeyboardController* controller = new GaiZhongGaiKeyboardController(dev, info);
RGBController_GaiZhongGaiKeyboard* rgb_controller = new RGBController_GaiZhongGaiKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
} /* DetectGaiZhongGaiKeyboardControllers() */
REGISTER_HID_DETECTOR_I("GaiZhongGai 68+4 PRO", DetectGaiZhongGaiKeyboardControllers, GAIZHONGGAI_VID, GAIZHONGGAI_68_PRO_PID, 3);
REGISTER_HID_DETECTOR_I("GaiZhongGai 17+4+Touch PRO", DetectGaiZhongGaiKeyboardControllers, GAIZHONGGAI_VID, GAIZHONGGAI_17_TOUCH_PRO_PID, 3);
REGISTER_HID_DETECTOR_I("GaiZhongGai 17 PRO", DetectGaiZhongGaiKeyboardControllers, GAIZHONGGAI_VID, GAIZHONGGAI_17_PRO_PID, 3);
REGISTER_HID_DETECTOR_I("GaiZhongGai 20 PRO", DetectGaiZhongGaiKeyboardControllers, GAIZHONGGAI_VID, GAIZHONGGAI_20_PRO_PID, 3);

View file

@ -0,0 +1,337 @@
/*---------------------------------------------------------------*\
| RGBController_GaiZhongGaiKeyboard.cpp |
| |
| https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO |
| |
| An Yang 2022/6/12 |
\*---------------------------------------------------------------*/
#include "RGBController_GaiZhongGaiKeyboard.h"
#include "RGBControllerKeyNames.h"
//0xFFFFFFFF indicates an unused entry in matrix
#define NA 0xFFFFFFFF
static unsigned int matrix_map_17PAD[5][4] =
{
{ 84, 83, 82, 81 },
{ 80, 79, 78, 77 },
{ 76, 75, 74, NA },
{ 73, 72, 71, 68 },
{ 70, NA, 69, NA }
};
static unsigned int matrix_map_20PAD[6][4] =
{
{ 86, 87, 85, NA },
{ 84, 83, 82, 81 },
{ 80, 79, 78, 77 },
{ 76, 75, 74, NA },
{ 73, 72, 71, 68 },
{ 70, NA, 69, NA }
};
static unsigned int matrix_map_PAD_Touch[5][5] =
{
{ 84, 83, 82, 81 , NA},
{ 80, 79, 78, 77 , 85},
{ 76, 75, 74, NA , 86},
{ 73, 72, 71, 68 , 87},
{ 70, NA, 69, NA , NA}
};
static unsigned int matrix_map_68[5][17] =
{
{ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, NA, 66, 67 },
{ 36, NA, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 },
{ 23, NA, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, NA, 35, NA, NA },
{ 10, NA, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, NA, 21, NA, 22, NA },
{ 0, 1, 2, NA, NA, NA, 3, NA, NA, NA, 4, 5, 6, NA, 7, 8, 9 }
};
static const char* zone_names[] =
{
"Keyboard"
};
static zone_type zone_types[] =
{
ZONE_TYPE_MATRIX,
};
static const unsigned int zone_sizes_68[] =
{
68
};
static const unsigned int zone_sizes_PAD[] =
{
85
};
static const uns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D_3,
KEY_EN_NUMPAD_2,
KEY_EN_NUMPAD_1,
KEY_EN_NUMPAD_6,
KEY_EN_NUMPAD_5,
KEY_EN_NUMPAD_4,
KEY_EN_NUMPAD_PLUS,
KEY_EN_NUMPAD_9,
KEY_EN_NUMPAD_8,
KEY_EN_NUMPAD_7,
KEY_EN_NUMPAD_MINUS,
KEY_EN_NUMPAD_TIMES,
KEY_EN_NUMPAD_DIVIDE,
KEY_EN_NUMPAD_LOCK,
"RGB Strip 1",
"RGB Strip 2",
"RGB Strip 3",
"RGB Strip 4",
"RGB Strip 5",
"RGB Strip 6"
};
/**------------------------------------------------------------------*\
@name GaiZhongGai Keyboard
@category Keyboard
@type USB
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectGaiZhongGaiKeyboardControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_GaiZhongGaiKeyboard::RGBController_GaiZhongGaiKeyboard(GaiZhongGaiKeyboardController* controller_ptr)
{
controller = controller_ptr;
name = "GaiZhongGai Keyboard Device";
vendor = "Yang";
version = controller->GetVersion();
type = DEVICE_TYPE_KEYBOARD;
description = "https://oshwlab.com/";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = 0xFFFF;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
}
RGBController_GaiZhongGaiKeyboard::~RGBController_GaiZhongGaiKeyboard()
{
/*---------------------------------------------------------*\
| Delete the matrix map |
\*---------------------------------------------------------*/
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
{
if(zones[zone_index].matrix_map != NULL)
{
delete zones[zone_index].matrix_map;
}
}
delete controller;
}
void RGBController_GaiZhongGaiKeyboard::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zones |
\*---------------------------------------------------------*/
unsigned int total_led_count = 0;
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
{
unsigned int zone_size = 0;
unsigned int matrix_width = 0;
unsigned int matrix_height = 0;
unsigned int* matrix_map_ptr = NULL;
switch(controller->GetUSBPID())
{
case GAIZHONGGAI_68_PRO_PID:
zone_size = zone_sizes_68[zone_idx];
matrix_width = 17;
matrix_height = 5;
matrix_map_ptr = (unsigned int *)&matrix_map_68;
break;
case GAIZHONGGAI_17_TOUCH_PRO_PID:
zone_size = zone_sizes_PAD_Touch[zone_idx];
matrix_width = 5;
matrix_height = 5;
matrix_map_ptr = (unsigned int *)&matrix_map_PAD_Touch;
break;
case GAIZHONGGAI_17_PRO_PID:
zone_size = zone_sizes_PAD[zone_idx];
matrix_width = 4;
matrix_height = 5;
matrix_map_ptr = (unsigned int *)&matrix_map_17PAD;
break;
case GAIZHONGGAI_20_PRO_PID:
zone_size = zone_sizes_PAD_Touch[zone_idx];
matrix_width = 4;
matrix_height = 6;
matrix_map_ptr = (unsigned int *)&matrix_map_20PAD;
break;
}
zone new_zone;
new_zone.name = zone_names[zone_idx];
new_zone.type = zone_types[zone_idx];
new_zone.leds_min = zone_size;
new_zone.leds_max = zone_size;
new_zone.leds_count = zone_size;
new_zone.matrix_map = new matrix_map_type;
new_zone.matrix_map->height = matrix_height;
new_zone.matrix_map->width = matrix_width;
new_zone.matrix_map->map = matrix_map_ptr;
zones.push_back(new_zone);
total_led_count += zone_size;
}
for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)
{
led new_led;
new_led.name = led_names[led_idx];
leds.push_back(new_led);
}
SetupColors();
}
void RGBController_GaiZhongGaiKeyboard::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_GaiZhongGaiKeyboard::DeviceUpdateLEDs()
{
unsigned char colordata[100 * 3];
for(std::size_t color_idx = 0; color_idx < colors.size(); color_idx++)
{
uint16_t offset = color_idx * 3;
colordata[offset + 0] = RGBGetGValue(colors[color_idx]);
colordata[offset + 1] = RGBGetRValue(colors[color_idx]);
colordata[offset + 2] = RGBGetBValue(colors[color_idx]);
}
controller->SendColors(colordata, sizeof(colordata));
}
void RGBController_GaiZhongGaiKeyboard::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_GaiZhongGaiKeyboard::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_GaiZhongGaiKeyboard::SetCustomMode()
{
active_mode = 0;
}
void RGBController_GaiZhongGaiKeyboard::DeviceUpdateMode()
{
}

View file

@ -0,0 +1,31 @@
/*---------------------------------------------------------------*\
| RGBController_GaiZhongGaiKeyboard.h |
| |
| https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO |
| |
| An Yang 2022/6/12 |
\*---------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "GaiZhongGaiKeyboardController.h"
class RGBController_GaiZhongGaiKeyboard : public RGBController
{
public:
RGBController_GaiZhongGaiKeyboard(GaiZhongGaiKeyboardController* controller_ptr);
~RGBController_GaiZhongGaiKeyboard();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
GaiZhongGaiKeyboardController* controller;
};

View file

@ -112,6 +112,7 @@ INCLUDEPATH +=
Controllers/EVisionKeyboardController/ \
Controllers/FanBusController/ \
Controllers/GainwardGPUController/ \
Controllers/GaiZongGaiKeyboardController/ \
Controllers/GalaxGPUController/ \
Controllers/GigabyteAorusCPUCoolerController/ \
Controllers/GigabyteRGBFusion2DRAMController/ \
@ -381,6 +382,8 @@ HEADERS +=
Controllers/GainwardGPUController/GainwardGPUv2Controller.h \
Controllers/GainwardGPUController/RGBController_GainwardGPUv1.h \
Controllers/GainwardGPUController/RGBController_GainwardGPUv2.h \
Controllers/GaiZongGaiKeyboardController/GaiZhongGaiKeyboardController.h \
Controllers/GaiZongGaiKeyboardController/RGBController_GaiZhongGaiKeyboard.h \
Controllers/GalaxGPUController/GalaxGPUController.h \
Controllers/GalaxGPUController/RGBController_GalaxGPU.h \
Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.h \
@ -892,6 +895,9 @@ SOURCES +=
Controllers/GainwardGPUController/GainwardGPUv2Controller.cpp \
Controllers/GainwardGPUController/RGBController_GainwardGPUv1.cpp \
Controllers/GainwardGPUController/RGBController_GainwardGPUv2.cpp \
Controllers/GaiZongGaiKeyboardController/GaiZhongGaiKeyboardController.cpp \
Controllers/GaiZongGaiKeyboardController/GaiZhongGaiKeyboardControllerDetect.cpp \
Controllers/GaiZongGaiKeyboardController/RGBController_GaiZhongGaiKeyboard.cpp \
Controllers/GalaxGPUController/GalaxGPUController.cpp \
Controllers/GalaxGPUController/GalaxGPUControllerDetect.cpp \
Controllers/GalaxGPUController/RGBController_GalaxGPU.cpp \