From f7bcadd9ed5686dcf81f9a5968ed9335ff8d7016 Mon Sep 17 00:00:00 2001 From: edbgon Date: Thu, 4 Feb 2021 22:47:43 +0100 Subject: [PATCH] Add initial support for AMD Radeon 6000 series reference cards Commits from edbgon, bobris, and Dr_No squashed and code style changes by Adam Honse --- .../CMR6000Controller.cpp | 196 ++++++++++++++++++ .../CMR6000Controller.h | 82 ++++++++ .../CoolerMasterControllerDetect.cpp | 16 ++ .../RGBController_CMR6000Controller.cpp | 138 ++++++++++++ .../RGBController_CMR6000Controller.h | 32 +++ OpenRGB.pro | 4 + 6 files changed, 468 insertions(+) create mode 100644 Controllers/CoolerMasterController/CMR6000Controller.cpp create mode 100644 Controllers/CoolerMasterController/CMR6000Controller.h create mode 100644 Controllers/CoolerMasterController/RGBController_CMR6000Controller.cpp create mode 100644 Controllers/CoolerMasterController/RGBController_CMR6000Controller.h diff --git a/Controllers/CoolerMasterController/CMR6000Controller.cpp b/Controllers/CoolerMasterController/CMR6000Controller.cpp new file mode 100644 index 00000000..e2df8894 --- /dev/null +++ b/Controllers/CoolerMasterController/CMR6000Controller.cpp @@ -0,0 +1,196 @@ +/*-------------------------------------------------------------------*\ +| CMR6000Controller.cpp | +| | +| Driver for Coolermaster based AMD Radeon GPU (6000 series) | +| | +| Eric S (edbgon) 2nd Feb 2021 | +\*-------------------------------------------------------------------*/ + +#include "CMR6000Controller.h" +#include + +CMR6000Controller::CMR6000Controller(hid_device* dev_handle, char *_path) +{ + dev = dev_handle; + location = _path; + + const int szTemp = 256; + wchar_t tmpName[szTemp]; + + hid_get_manufacturer_string(dev, tmpName, szTemp); + std::wstring wName = std::wstring(tmpName); + device_name = std::string(wName.begin(), wName.end()); + + hid_get_product_string(dev, tmpName, szTemp); + wName = std::wstring(tmpName); + device_name.append(" ").append(std::string(wName.begin(), wName.end())); + + hid_get_serial_number_string(dev, tmpName, szTemp); + wName = std::wstring(tmpName); + serial = std::string(wName.begin(), wName.end()); + + GetStatus(); //When setting up device get current status +} + +CMR6000Controller::~CMR6000Controller() +{ + if(dev) + { + hid_close(dev); + } +} + +void CMR6000Controller::GetStatus() +{ + unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x52, 0xA0, 0x01, 0x00, 0x00, 0x03 }; + int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); + + // Request mode + hid_write(dev, buffer, buffer_size); + hid_read(dev, buffer, buffer_size); + + unsigned char cmdbuffer[CM_6K_PACKET_SIZE] = { 0x00, 0x52, 0x2C, 0x01, 0x00 }; + int cmdbuffer_size = (sizeof(cmdbuffer) / sizeof(cmdbuffer[0])); + + current_mode = buffer[0x0A]; + cmdbuffer[0x05] = current_mode; + hid_write(dev, cmdbuffer, cmdbuffer_size); + hid_read(dev, cmdbuffer, cmdbuffer_size); + + current_speed = cmdbuffer[0x05]; + current_brightness = cmdbuffer[0x09]; + current_red = cmdbuffer[0x0A]; + current_green = cmdbuffer[0x0B]; + current_blue = cmdbuffer[0x0C]; +} + +std::string CMR6000Controller::GetDeviceName() +{ + return device_name; +} + +std::string CMR6000Controller::GetSerial() +{ + return serial; +} + +std::string CMR6000Controller::GetLocation() +{ + return("HID: " + location); +} + +unsigned char CMR6000Controller::GetMode() +{ + return current_mode; +} + +unsigned char CMR6000Controller::GetLedRed() +{ + return current_red; +} + +unsigned char CMR6000Controller::GetLedGreen() +{ + return current_green; +} + +unsigned char CMR6000Controller::GetLedBlue() +{ + return current_blue; +} + +unsigned char CMR6000Controller::GetLedSpeed() +{ + return current_speed; +} + +bool CMR6000Controller::GetRandomColours() +{ + return current_random; +} + +void CMR6000Controller::SetMode(unsigned char mode, unsigned char speed, unsigned char red, unsigned char green, unsigned char blue, unsigned char random) +{ + current_mode = mode; + current_speed = speed; + current_red = red; + current_green = green; + current_blue = blue; + current_random = random; + current_brightness = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0x7F : 0xFF; //Color_Cycle brightness needs to be clamped to 0x7F to avoid wash out + + SendUpdate(); +} + +void CMR6000Controller::SendUpdate() +{ + if(current_mode == CM_MR6000_MODE_OFF) + { + unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x41, 0x43 }; + int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); + hid_write(dev, buffer, buffer_size); + } + else + { + SendEnableCommand(); + + unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00 }; + int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); + memset(buffer, 0xFF, buffer_size); + + buffer[0x00] = 0x00; + buffer[0x01] = 0x51; + buffer[0x02] = 0x2C; + buffer[0x03] = 0x01; + buffer[0x04] = 0x00; + buffer[0x05] = current_mode; + buffer[0x06] = (current_mode == CM_MR6000_MODE_STATIC) ? 0xFF: current_speed; + buffer[0x07] = (current_mode == CM_MR6000_MODE_BREATHE)? current_random : 0x00; //random (A0) + buffer[0x08] = (current_mode == CM_MR6000_MODE_BREATHE)? 0x03 : 0xFF; + //buffer[0x09] = 0xFF; + buffer[0x0A] = current_brightness; + buffer[0x0B] = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0xFF : current_red; + buffer[0x0C] = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0xFF : current_green; + buffer[0x0D] = (current_mode == CM_MR6000_MODE_COLOR_CYCLE) ? 0xFF : current_blue; + buffer[0x0E] = 0x00; + buffer[0x0F] = 0x00; + buffer[0x10] = 0x00; + + hid_write(dev, buffer, buffer_size); + + SendColourConfig(); + SendApplyCommand(); + } +} + +void CMR6000Controller::SendEnableCommand() +{ + unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x41, 0x80 }; + int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); + + hid_write(dev, buffer, buffer_size); + hid_read_timeout(dev, buffer, buffer_size, CM_6K_INTERRUPT_TIMEOUT); +} + +void CMR6000Controller::SendApplyCommand() +{ + unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x51, 0x28, 0x00, 0x00, 0xE0 }; + int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); + + hid_write(dev, buffer, buffer_size); + hid_read_timeout(dev, buffer, buffer_size, CM_6K_INTERRUPT_TIMEOUT); +} + +void CMR6000Controller::SendColourConfig() +{ + unsigned char buffer[CM_6K_PACKET_SIZE] = { 0x00, 0x51, 0xA0, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x06 }; + int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); + + for(int i = 0x0B; i < 0x1A; i++) + { + buffer[i] = current_mode; + } + + hid_write(dev, buffer, buffer_size); + hid_read_timeout(dev, buffer, buffer_size, CM_6K_INTERRUPT_TIMEOUT); +} diff --git a/Controllers/CoolerMasterController/CMR6000Controller.h b/Controllers/CoolerMasterController/CMR6000Controller.h new file mode 100644 index 00000000..dbdd6d65 --- /dev/null +++ b/Controllers/CoolerMasterController/CMR6000Controller.h @@ -0,0 +1,82 @@ +/*-------------------------------------------------------------------*\ +| CMR6000Controller.h | +| | +| Driver for Coolermaster based AMD Radeon GPU (6000 series) | +| | +| Eric S (edbgon) 2nd Feb 2021 | +\*-------------------------------------------------------------------*/ + +#include +#include +#include + +#pragma once + +#define CM_6K_PACKET_SIZE 65 //Includes extra first byte for non HID Report packets +#define CM_6K_INTERRUPT_TIMEOUT 250 +#define CM_6K_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ])) +#define CM_6K_SERIAL_SIZE (sizeof(serial) / sizeof(serial[ 0 ])) +#define HID_MAX_STR 255 + +enum +{ + CM_MR6000_MODE_STATIC = 0x00, //Static Mode + CM_MR6000_MODE_BREATHE = 0x01, //Breathe Mode + CM_MR6000_MODE_COLOR_CYCLE = 0x02, //Color cycle + CM_MR6000_MODE_OFF = 0xFF, //Off +}; + +enum +{ + MR6000_CYCLE_SPEED_SLOWEST = 0x96, /* Slowest speed */ + MR6000_CYCLE_SPEED_SLOW = 0x8C, /* Slow speed */ + MR6000_CYCLE_SPEED_NORMAL = 0x80, /* Normal speed */ + MR6000_CYCLE_SPEED_FAST = 0x6E, /* Fast speed */ + MR6000_CYCLE_SPEED_FASTEST = 0x68, /* Fastest speed */ + + MR6000_BREATHE_SPEED_SLOWEST = 0x3C, /* Slowest speed */ + MR6000_BREATHE_SPEED_SLOW = 0x37, /* Slow speed */ + MR6000_BREATHE_SPEED_NORMAL = 0x31, /* Normal speed */ + MR6000_BREATHE_SPEED_FAST = 0x2C, /* Fast speed */ + MR6000_BREATHE_SPEED_FASTEST = 0x26, /* Fastest speed */ +}; + +class CMR6000Controller +{ +public: + CMR6000Controller(hid_device* dev_handle, char *_path); + ~CMR6000Controller(); + + std::string GetDeviceName(); + std::string GetSerial(); + std::string GetLocation(); + + unsigned char GetMode(); + unsigned char GetLedRed(); + unsigned char GetLedGreen(); + unsigned char GetLedBlue(); + unsigned char GetLedSpeed(); + bool GetRandomColours(); + void SetMode(unsigned char mode, unsigned char speed, unsigned char red, unsigned char green, unsigned char blue, unsigned char random); + +private: + std::string device_name; + std::string serial; + std::string location; + hid_device* dev; + + unsigned char current_mode; + unsigned char current_speed; + unsigned char current_random; + + unsigned char current_red; + unsigned char current_green; + unsigned char current_blue; + unsigned char current_brightness; + + void GetStatus(); + void SendUpdate(); + void SendEnableCommand(); + void SendApplyCommand(); + void SendColourConfig(); +}; diff --git a/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp b/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp index c6394f6c..7bbb9ce8 100644 --- a/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp +++ b/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp @@ -1,9 +1,11 @@ #include "Detector.h" #include "CMMP750Controller.h" #include "CMARGBcontroller.h" +#include "CMR6000Controller.h" #include "RGBController.h" #include "RGBController_CMMP750Controller.h" #include "RGBController_CMARGBController.h" +#include "RGBController_CMR6000Controller.h" #include #define COOLERMASTER_VID 0x2516 @@ -11,6 +13,7 @@ #define COOLERMASTER_MP750_XL_PID 0x0109 #define COOLERMASTER_MP750_MEDIUM_PID 0x0105 #define COOLERMASTER_ARGB_PID 0x1011 +#define COOLERMASTER_RADEON_6000_PID 0x014D /******************************************************************************************\ * * @@ -47,6 +50,19 @@ void DetectCoolerMasterARGB(hid_device_info* info, const std::string&) } } +void DetectCoolerMasterGPU(hid_device_info* info, const std::string&) +{ + hid_device* dev = hid_open_path(info->path); + if(dev) + { + CMR6000Controller* controller = new CMR6000Controller(dev, info->path); + RGBController_CMR6000Controller* rgb_controller = new RGBController_CMR6000Controller(controller); + // Constructor sets the name + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + REGISTER_HID_DETECTOR_IPU("Cooler Master MP750 XL", DetectCoolerMasterMousemats, COOLERMASTER_VID, COOLERMASTER_MP750_XL_PID, 0, 0xFF00, 1); REGISTER_HID_DETECTOR_IPU("Cooler Master MP750 Medium", DetectCoolerMasterMousemats, COOLERMASTER_VID, COOLERMASTER_MP750_MEDIUM_PID, 0, 0xFF00, 1); REGISTER_HID_DETECTOR_IPU("Cooler Master ARGB", DetectCoolerMasterARGB, COOLERMASTER_VID, COOLERMASTER_ARGB_PID, 0, 0xFF00, 1); +REGISTER_HID_DETECTOR_I("Cooler Master Radeon 6000 GPU",DetectCoolerMasterGPU, COOLERMASTER_VID, COOLERMASTER_RADEON_6000_PID, 1); diff --git a/Controllers/CoolerMasterController/RGBController_CMR6000Controller.cpp b/Controllers/CoolerMasterController/RGBController_CMR6000Controller.cpp new file mode 100644 index 00000000..2304b42e --- /dev/null +++ b/Controllers/CoolerMasterController/RGBController_CMR6000Controller.cpp @@ -0,0 +1,138 @@ +/*-------------------------------------------------------------------*\ +| RGBController_CMR6000Controller.cpp | +| | +| Driver for Coolermaster based AMD Radeon GPU (6000 series) | +| | +| Eric S (edbgon) 2nd Feb 2021 | +\*-------------------------------------------------------------------*/ + +#include "RGBController_CMR6000Controller.h" + +RGBController_CMR6000Controller::RGBController_CMR6000Controller(CMR6000Controller* cmmp_ptr) +{ + cmr6000 = cmmp_ptr; + unsigned char speed = cmr6000->GetLedSpeed(); + + name = "AMD RX 6xxx GPU"; + vendor = "Cooler Master"; + type = DEVICE_TYPE_GPU; + description = cmr6000->GetDeviceName(); + version = "1.0"; + serial = cmr6000->GetSerial(); + location = cmr6000->GetLocation(); + + mode Off; + Off.name = "Off"; + Off.flags = 0; + Off.value = CM_MR6000_MODE_OFF; + Off.color_mode = MODE_COLORS_NONE; + modes.push_back(Off); + + mode Static; + Static.name = "Static"; + Static.value = CM_MR6000_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR; + Static.color_mode = MODE_COLORS_MODE_SPECIFIC; + Static.colors_min = 1; + Static.colors_max = 1; + Static.colors.resize(1); + modes.push_back(Static); + + mode ColorCycle; + ColorCycle.name = "Color Cycle"; + ColorCycle.value = CM_MR6000_MODE_COLOR_CYCLE; + ColorCycle.flags = MODE_FLAG_HAS_SPEED; + ColorCycle.speed_min = MR6000_CYCLE_SPEED_SLOWEST; + ColorCycle.speed = MR6000_CYCLE_SPEED_NORMAL; + ColorCycle.speed_max = MR6000_CYCLE_SPEED_FASTEST; + ColorCycle.color_mode = MODE_COLORS_NONE; + ColorCycle.speed = speed; + modes.push_back(ColorCycle); + + mode Breathing; + Breathing.name = "Breathing"; + Breathing.value = CM_MR6000_MODE_BREATHE; + Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; + Breathing.speed_min = MR6000_BREATHE_SPEED_SLOWEST; + Breathing.speed = MR6000_BREATHE_SPEED_NORMAL; + Breathing.speed_max = MR6000_BREATHE_SPEED_FASTEST; + Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; + Breathing.colors_min = 1; + Breathing.colors_max = 1; + Breathing.colors.resize(1); + Breathing.speed = speed; + modes.push_back(Breathing); + + SetupZones(); + active_mode = cmr6000->GetMode(); + if (modes[active_mode].flags && MODE_FLAG_HAS_MODE_SPECIFIC_COLOR) + { + modes[active_mode].colors[0] = ToRGBColor(cmr6000->GetLedRed(), cmr6000->GetLedGreen(), cmr6000->GetLedBlue()); + } + modes[active_mode].color_mode = (cmr6000->GetRandomColours()) ? MODE_COLORS_RANDOM : MODE_COLORS_MODE_SPECIFIC; + if (modes[active_mode].flags && MODE_FLAG_HAS_SPEED) + { + modes[active_mode].speed = cmr6000->GetLedSpeed(); + } +} + +RGBController_CMR6000Controller::~RGBController_CMR6000Controller() +{ + delete cmr6000; +} + +void RGBController_CMR6000Controller::SetupZones() +{ + zone GP_zone; + GP_zone.name = "GPU"; + GP_zone.type = ZONE_TYPE_SINGLE; + GP_zone.leds_min = 1; + GP_zone.leds_max = 1; + GP_zone.leds_count = 1; + GP_zone.matrix_map = NULL; + zones.push_back(GP_zone); + + led GP_led; + GP_led.name = "Logo"; + leds.push_back(GP_led); + + SetupColors(); + +} + +void RGBController_CMR6000Controller::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_CMR6000Controller::DeviceUpdateLEDs() +{ + unsigned char red = RGBGetRValue(colors[0]); + unsigned char grn = RGBGetGValue(colors[0]); + unsigned char blu = RGBGetBValue(colors[0]); + unsigned char rnd = (modes[active_mode].color_mode == MODE_COLORS_RANDOM) ? 0xA0 : 0x20; + + cmr6000->SetMode(modes[active_mode].value, modes[active_mode].speed, red, grn, blu, rnd); +} + +void RGBController_CMR6000Controller::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_CMR6000Controller::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_CMR6000Controller::SetCustomMode() +{ + +} + +void RGBController_CMR6000Controller::DeviceUpdateMode() +{ + DeviceUpdateLEDs(); +} diff --git a/Controllers/CoolerMasterController/RGBController_CMR6000Controller.h b/Controllers/CoolerMasterController/RGBController_CMR6000Controller.h new file mode 100644 index 00000000..5a75b727 --- /dev/null +++ b/Controllers/CoolerMasterController/RGBController_CMR6000Controller.h @@ -0,0 +1,32 @@ +/*-------------------------------------------------------------------*\ +| RGBController_CMR6000Controller.h | +| | +| Driver for Coolermaster based AMD Radeon GPU (6000 series) | +| | +| Eric S (edbgon) 2nd Feb 2021 | +\*-------------------------------------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "CMR6000Controller.h" + +class RGBController_CMR6000Controller : public RGBController +{ +public: + RGBController_CMR6000Controller(CMR6000Controller* cmmp_ptr); + ~RGBController_CMR6000Controller(); + + void SetupZones(); + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); +private: + CMR6000Controller* cmr6000; + + int GetDeviceMode(); +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index 3fdc9d2e..fb86e39d 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -162,8 +162,10 @@ HEADERS += Controllers/AsusAuraUSBController/RGBController_AsusAuraUSB.h \ Controllers/CoolerMasterController/CMARGBcontroller.h \ Controllers/CoolerMasterController/CMMP750Controller.h \ + Controllers/CoolerMasterController/CMR6000Controller.h \ Controllers/CoolerMasterController/RGBController_CMARGBController.h \ Controllers/CoolerMasterController/RGBController_CMMP750Controller.h \ + Controllers/CoolerMasterController/RGBController_CMR6000Controller.h \ Controllers/CorsairDominatorPlatinumController/CorsairDominatorPlatinumController.h \ Controllers/CorsairDominatorPlatinumController/RGBController_CorsairDominatorPlatinum.h \ Controllers/CorsairHydroController/CorsairHydroController.h \ @@ -360,9 +362,11 @@ SOURCES += Controllers/AsusAuraUSBController/RGBController_AsusAuraUSB.cpp \ Controllers/CoolerMasterController/CMARGBcontroller.cpp \ Controllers/CoolerMasterController/CMMP750Controller.cpp \ + Controllers/CoolerMasterController/CMR6000Controller.cpp \ Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp \ Controllers/CoolerMasterController/RGBController_CMARGBController.cpp \ Controllers/CoolerMasterController/RGBController_CMMP750Controller.cpp \ + Controllers/CoolerMasterController/RGBController_CMR6000Controller.cpp \ Controllers/CorsairDominatorPlatinumController/CorsairDominatorPlatinumController.cpp \ Controllers/CorsairDominatorPlatinumController/CorsairDominatorPlatinumControllerDetect.cpp \ Controllers/CorsairDominatorPlatinumController/RGBController_CorsairDominatorPlatinum.cpp \