From 26e4c76f03753f2d27bfc74e73cba0e4269d9c01 Mon Sep 17 00:00:00 2001 From: KundaPanda Date: Thu, 1 Apr 2021 17:59:27 +0200 Subject: [PATCH] Add V2 Gainward Controller for new NVidia GPUs Commits squashed and amended for code style by Adam Honse --- .../GainwardGPUControllerDetect.cpp | 74 +++++-- ...roller.cpp => GainwardGPUv1Controller.cpp} | 26 +-- ...Controller.h => GainwardGPUv1Controller.h} | 8 +- .../GainwardGPUv2Controller.cpp | 88 +++++++++ .../GainwardGPUv2Controller.h | 95 +++++++++ ...PU.cpp => RGBController_GainwardGPUv1.cpp} | 26 +-- ...ardGPU.h => RGBController_GainwardGPUv1.h} | 12 +- .../RGBController_GainwardGPUv2.cpp | 185 ++++++++++++++++++ .../RGBController_GainwardGPUv2.h | 33 ++++ OpenRGB.pro | 12 +- 10 files changed, 506 insertions(+), 53 deletions(-) rename Controllers/GainwardGPUController/{GainwardGPUController.cpp => GainwardGPUv1Controller.cpp} (57%) rename Controllers/GainwardGPUController/{GainwardGPUController.h => GainwardGPUv1Controller.h} (86%) create mode 100644 Controllers/GainwardGPUController/GainwardGPUv2Controller.cpp create mode 100644 Controllers/GainwardGPUController/GainwardGPUv2Controller.h rename Controllers/GainwardGPUController/{RGBController_GainwardGPU.cpp => RGBController_GainwardGPUv1.cpp} (78%) rename Controllers/GainwardGPUController/{RGBController_GainwardGPU.h => RGBController_GainwardGPUv1.h} (68%) create mode 100644 Controllers/GainwardGPUController/RGBController_GainwardGPUv2.cpp create mode 100644 Controllers/GainwardGPUController/RGBController_GainwardGPUv2.h diff --git a/Controllers/GainwardGPUController/GainwardGPUControllerDetect.cpp b/Controllers/GainwardGPUController/GainwardGPUControllerDetect.cpp index afcdf17f1..1cef15fb4 100644 --- a/Controllers/GainwardGPUController/GainwardGPUControllerDetect.cpp +++ b/Controllers/GainwardGPUController/GainwardGPUControllerDetect.cpp @@ -7,9 +7,11 @@ \*-----------------------------------------*/ #include "Detector.h" -#include "GainwardGPUController.h" +#include "GainwardGPUv1Controller.h" +#include "GainwardGPUv2Controller.h" #include "RGBController.h" -#include "RGBController_GainwardGPU.h" +#include "RGBController_GainwardGPUv1.h" +#include "RGBController_GainwardGPUv2.h" #include "i2c_smbus.h" #include "pci_ids.h" #include @@ -18,12 +20,19 @@ using namespace std::chrono_literals; +enum +{ + RGB_V1, + RGB_V2, +}; + typedef struct { int pci_vendor; int pci_device; int pci_subsystem_vendor; int pci_subsystem_device; + int gpu_rgb_version; const char * name; } gpu_pci_device; @@ -31,7 +40,8 @@ typedef struct static const gpu_pci_device device_list[] = { - { NVIDIA_VEN, NVIDIA_GTX1080_DEV, GAINWARD_SUB_VEN, GAINWARD_GTX_1080_PHOENIX, "Gainward GTX 1080 Phoenix" }, + { NVIDIA_VEN, NVIDIA_GTX1080_DEV, GAINWARD_SUB_VEN, GAINWARD_GTX_1080_PHOENIX, RGB_V1, "Gainward GTX 1080 Phoenix" }, + { NVIDIA_VEN, NVIDIA_RTX3070_DEV, GAINWARD_SUB_VEN, NVIDIA_RTX3070_DEV, RGB_V2, "Gainward RTX 3070 Phoenix" }, }; /******************************************************************************************\ @@ -42,11 +52,26 @@ static const gpu_pci_device device_list[] = * * \******************************************************************************************/ -bool TestForGainwardGPUController(i2c_smbus_interface* bus, unsigned char address) +bool TestForGainwardGPUController(i2c_smbus_interface* bus, int gpu_rgb_version) { bool pass = false; - pass = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE); + switch (gpu_rgb_version) + { + case RGB_V1: + pass = bus->i2c_smbus_write_quick(0x08, I2C_SMBUS_WRITE); + break; + + case RGB_V2: + /*-------------------------------------------------------------*\ + | This detection might need some modifications | + | Reading 0x6F*0x73 and comparing to 0x64 might be a possibility| + \*-------------------------------------------------------------*/ + s32 data = bus->i2c_smbus_read_byte_data(0x49, 0x0); + s32 mode_data = bus->i2c_smbus_read_byte_data(0x49, 0xe0); + pass = (data == 0x0) && (mode_data < 0x5); + break; + } return(pass); @@ -63,12 +88,12 @@ bool TestForGainwardGPUController(i2c_smbus_interface* bus, unsigned char addres void DetectGainwardGPUControllers(std::vector &busses) { - GainwardGPUController* new_GainwardGPU; - RGBController_GainwardGPU* new_controller; for (unsigned int bus = 0; bus < busses.size(); bus++) { - // Check for Gainward controller at 0x08 + /*-------------------------------------*\ + | Check for Gainward controller at 0x08 | + \*-------------------------------------*/ for(unsigned int dev_idx = 0; dev_idx < GPU_NUM_DEVICES; dev_idx++) { if(busses[bus]->pci_vendor == device_list[dev_idx].pci_vendor && @@ -76,12 +101,35 @@ void DetectGainwardGPUControllers(std::vector &busses) busses[bus]->pci_subsystem_vendor == device_list[dev_idx].pci_subsystem_vendor && busses[bus]->pci_subsystem_device == device_list[dev_idx].pci_subsystem_device) { - if (TestForGainwardGPUController(busses[bus], 0x08)) + + if (TestForGainwardGPUController(busses[bus], device_list[dev_idx].gpu_rgb_version)) { - new_GainwardGPU = new GainwardGPUController(busses[bus], 0x08); - new_controller = new RGBController_GainwardGPU(new_GainwardGPU); - new_controller->name = device_list[dev_idx].name; - ResourceManager::get()->RegisterRGBController(new_controller); + switch(device_list[dev_idx].gpu_rgb_version) + { + case RGB_V1: + { + GainwardGPUv1Controller* new_GainwardGPU; + RGBController_GainwardGPUv1* new_controller; + + new_GainwardGPU = new GainwardGPUv1Controller(busses[bus], 0x08); + new_controller = new RGBController_GainwardGPUv1(new_GainwardGPU); + new_controller->name = device_list[dev_idx].name; + ResourceManager::get()->RegisterRGBController(new_controller); + } + break; + + case RGB_V2: + { + GainwardGPUv2Controller* new_GainwardGPU; + RGBController_GainwardGPUv2* new_controller; + + new_GainwardGPU = new GainwardGPUv2Controller(busses[bus], 0x49); + new_controller = new RGBController_GainwardGPUv2(new_GainwardGPU); + new_controller->name = device_list[dev_idx].name; + ResourceManager::get()->RegisterRGBController(new_controller); + } + break; + } } } } diff --git a/Controllers/GainwardGPUController/GainwardGPUController.cpp b/Controllers/GainwardGPUController/GainwardGPUv1Controller.cpp similarity index 57% rename from Controllers/GainwardGPUController/GainwardGPUController.cpp rename to Controllers/GainwardGPUController/GainwardGPUv1Controller.cpp index 49919c66b..38c843fe2 100644 --- a/Controllers/GainwardGPUController/GainwardGPUController.cpp +++ b/Controllers/GainwardGPUController/GainwardGPUv1Controller.cpp @@ -1,26 +1,26 @@ /*-----------------------------------------*\ -| GainwardGPUController.cpp | +| GainwardGPUv1Controller.cpp | | | -| Driver for Gainward RGB on GPUs | +| Driver for Gainward RGB v1 on GPUs | | | | TheRogueZeta 11/05/2020 | \*-----------------------------------------*/ -#include "GainwardGPUController.h" +#include "GainwardGPUv1Controller.h" #include -GainwardGPUController::GainwardGPUController(i2c_smbus_interface* bus, gainward_gpu_dev_id dev) +GainwardGPUv1Controller::GainwardGPUv1Controller(i2c_smbus_interface* bus, gainward_gpu_dev_id dev) { this->bus = bus; this->dev = dev; } -GainwardGPUController::~GainwardGPUController() +GainwardGPUv1Controller::~GainwardGPUv1Controller() { } -std::string GainwardGPUController::GetDeviceLocation() +std::string GainwardGPUv1Controller::GetDeviceLocation() { std::string return_string(bus->device_name); char addr[5]; @@ -30,22 +30,22 @@ std::string GainwardGPUController::GetDeviceLocation() return("I2C: " + return_string); } -unsigned char GainwardGPUController::GetLEDRed() +unsigned char GainwardGPUv1Controller::GetLEDRed() { return(GainwardGPURegisterRead(GAINWARD_RED_REGISTER)); } -unsigned char GainwardGPUController::GetLEDGreen() +unsigned char GainwardGPUv1Controller::GetLEDGreen() { return(GainwardGPURegisterRead(GAINWARD_GREEN_REGISTER)); } -unsigned char GainwardGPUController::GetLEDBlue() +unsigned char GainwardGPUv1Controller::GetLEDBlue() { return(GainwardGPURegisterRead(GAINWARD_BLUE_REGISTER)); } -void GainwardGPUController::SetLEDColors(unsigned char red, unsigned char green, unsigned char blue) +void GainwardGPUv1Controller::SetLEDColors(unsigned char red, unsigned char green, unsigned char blue) { GainwardGPURegisterWrite(GAINWARD_RED_REGISTER, red); GainwardGPURegisterWrite(GAINWARD_GREEN_REGISTER, green); @@ -53,17 +53,17 @@ void GainwardGPUController::SetLEDColors(unsigned char red, unsigned char green, GainwardGPURegisterWrite(GAINWARD_06_REGISTER, 0xFF); } -void GainwardGPUController::SetMode() +void GainwardGPUv1Controller::SetMode() { } -unsigned char GainwardGPUController::GainwardGPURegisterRead(unsigned char reg) +unsigned char GainwardGPUv1Controller::GainwardGPURegisterRead(unsigned char reg) { return(bus->i2c_smbus_read_byte_data(dev, reg)); } -void GainwardGPUController::GainwardGPURegisterWrite(unsigned char reg, unsigned char val) +void GainwardGPUv1Controller::GainwardGPURegisterWrite(unsigned char reg, unsigned char val) { bus->i2c_smbus_write_byte_data(dev, reg, val); } diff --git a/Controllers/GainwardGPUController/GainwardGPUController.h b/Controllers/GainwardGPUController/GainwardGPUv1Controller.h similarity index 86% rename from Controllers/GainwardGPUController/GainwardGPUController.h rename to Controllers/GainwardGPUController/GainwardGPUv1Controller.h index feef05b5e..1d380ba1f 100644 --- a/Controllers/GainwardGPUController/GainwardGPUController.h +++ b/Controllers/GainwardGPUController/GainwardGPUv1Controller.h @@ -1,7 +1,7 @@ /*-----------------------------------------*\ | GainwardGPUController.h | | | -| Driver for Gainward RGB on GPUs | +| Driver for Gainward RGB v1 on GPUs | | | | TheRogueZeta 11/05/2020 | \*-----------------------------------------*/ @@ -22,11 +22,11 @@ enum GAINWARD_06_REGISTER = 0x06, /* Unknown (Brightness/Mode?) Register */ }; -class GainwardGPUController +class GainwardGPUv1Controller { public: - GainwardGPUController(i2c_smbus_interface* bus, gainward_gpu_dev_id); - ~GainwardGPUController(); + GainwardGPUv1Controller(i2c_smbus_interface* bus, gainward_gpu_dev_id); + ~GainwardGPUv1Controller(); std::string GetDeviceLocation(); unsigned char GetLEDRed(); diff --git a/Controllers/GainwardGPUController/GainwardGPUv2Controller.cpp b/Controllers/GainwardGPUController/GainwardGPUv2Controller.cpp new file mode 100644 index 000000000..8595a37f3 --- /dev/null +++ b/Controllers/GainwardGPUController/GainwardGPUv2Controller.cpp @@ -0,0 +1,88 @@ +/*-----------------------------------------*\ +| GainwardGPUv2Controller.cpp | +| | +| Driver for Gainward RGB v2 on GPUs | +| | +| KundaPanda 01/04/2021 | +\*-----------------------------------------*/ + +#include "GainwardGPUv2Controller.h" +#include + +GainwardGPUv2Controller::GainwardGPUv2Controller(i2c_smbus_interface* bus, gainward_gpu_dev_id dev) +{ + this->bus = bus; + this->dev = dev; +} + +GainwardGPUv2Controller::~GainwardGPUv2Controller() = default; + +std::string GainwardGPUv2Controller::GetDeviceLocation() +{ + std::string return_string(bus->device_name); + char addr[5]; + snprintf(addr, 5, "0x%02X", dev); + return_string.append(", address "); + return_string.append(addr); + return("I2C: " + return_string); +} + +unsigned char GainwardGPUv2Controller::GetLEDRed() +{ + return(bus->i2c_smbus_read_byte_data(dev, GAINWARD_V2_RED_REGISTER)); +} + +unsigned char GainwardGPUv2Controller::GetLEDGreen() +{ + return(bus->i2c_smbus_read_byte_data(dev, GAINWARD_V2_GREEN_REGISTER)); +} + +unsigned char GainwardGPUv2Controller::GetLEDBlue() +{ + return(bus->i2c_smbus_read_byte_data(dev, GAINWARD_V2_BLUE_REGISTER)); +} + +void GainwardGPUv2Controller::SetLEDColors(unsigned char red, unsigned char green, unsigned char blue, unsigned char color_register) +{ + switch (color_register) + { + default: + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_RED_REGISTER, red); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_GREEN_REGISTER, green); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BLUE_REGISTER, blue); + break; + case GAINWARD_V2_COLOR_REGISTER_SECONDARY: + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_RED_SECONDARY_REGISTER, red); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_GREEN_SECONDARY_REGISTER, green); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BLUE_SECONDARY_REGISTER, blue); + break; + case GAINWARD_V2_COLOR_REGISTER_TERTIARY: + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_RED_TERTIARY_REGISTER, red); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_GREEN_TERTIARY_REGISTER, green); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BLUE_TERTIARY_REGISTER, blue); + break; + } +} + +void GainwardGPUv2Controller::SetMode(unsigned char mode, unsigned char speed, unsigned char static_mode) +{ + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_MODE_REGISTER, mode); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_STATIC_CONTROL_REGISTER, static_mode); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_SPEED_REGISTER, speed); +} + +void GainwardGPUv2Controller::SetDirection(unsigned char direction) +{ + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_MODE_DIRECTION_REGISTER, direction); +} + +void GainwardGPUv2Controller::SetBreathingSpeed(unsigned int speed) +{ + unsigned char lower = speed & 0xFF; + unsigned char upper = (speed >> 2 * 4) & 0xFF; + + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BREATHE_SPEED_REGISTER_A, lower); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BREATHE_SPEED_SECONDARY_REGISTER_A, lower); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BREATHE_SPEED_REGISTER_B, upper); + bus->i2c_smbus_write_byte_data(dev, GAINWARD_V2_BREATHE_SPEED_SECONDARY_REGISTER_B, upper); +} diff --git a/Controllers/GainwardGPUController/GainwardGPUv2Controller.h b/Controllers/GainwardGPUController/GainwardGPUv2Controller.h new file mode 100644 index 000000000..405671127 --- /dev/null +++ b/Controllers/GainwardGPUController/GainwardGPUv2Controller.h @@ -0,0 +1,95 @@ +/*-----------------------------------------*\ +| GainwardGPUv2Controller.h | +| | +| Driver for Gainward RGB v2 on GPUs | +| | +| KundaPanda 01/04/2021 | +\*-----------------------------------------*/ + +#include +#include "i2c_smbus.h" + +#pragma once + +typedef unsigned char gainward_gpu_dev_id; + +/*---------------------------------------------------------------------------------*\ + | Newer Gainward models seem to use addresses very similar to those used by EVGA | + \*-------------------------------------------------------------------------------**/ + +enum +{ + /* RGB Registers */ + GAINWARD_V2_RED_REGISTER = 0x6C, /* Red Register */ + GAINWARD_V2_GREEN_REGISTER = 0x6D, /* Green Register */ + GAINWARD_V2_BLUE_REGISTER = 0x6E, /* Blue Register */ + GAINWARD_V2_RED_SECONDARY_REGISTER = 0x70, /* Red Register 2 */ + GAINWARD_V2_GREEN_SECONDARY_REGISTER = 0x71, /* Green Register 2 */ + GAINWARD_V2_BLUE_SECONDARY_REGISTER = 0x72, /* Blue Register 2 */ + GAINWARD_V2_RED_TERTIARY_REGISTER = 0xE4, /* Red Register 3 */ + GAINWARD_V2_GREEN_TERTIARY_REGISTER = 0xE5, /* Green Register 3 */ + GAINWARD_V2_BLUE_TERTIARY_REGISTER = 0xE6, /* Blue Register 3 */ + GAINWARD_V2_MODE_REGISTER = 0xE0, /* Mode Register */ + /* Direct mode switch register + * 0x1 Software control + * 0x22 Breathing */ + GAINWARD_V2_STATIC_CONTROL_REGISTER = 0x60, + GAINWARD_V2_BREATHE_SPEED_REGISTER_A = 0x62, /* Lower part of speed control for breathe effect */ + GAINWARD_V2_BREATHE_SPEED_REGISTER_B = 0x63, /* Upper part of speed control for breathe effect */ + GAINWARD_V2_BREATHE_SPEED_SECONDARY_REGISTER_A = 0x64, /* Lower part of speed control for breathe effect - prob. secondary color */ + GAINWARD_V2_BREATHE_SPEED_SECONDARY_REGISTER_B = 0x65, /* Upper part of speed control for breathe effect - prob. secondary color */ + /* Mode direction Register + * 0x0 + * 0x1 */ + GAINWARD_V2_MODE_DIRECTION_REGISTER = 0xE1, + /* Mode speed Register + * 0x0 MAX + * 0xF MIN */ + GAINWARD_V2_SPEED_REGISTER = 0xE2, +}; + +enum +{ + /* Manual color selection using primary registers */ + GAINWARD_V2_MODE_STATIC = 0x00, + /* Rainbow cycling with direction and speed controls */ + GAINWARD_V2_MODE_CYCLE = 0x01, + /* One strobing color running around the fan + * Color using primary registers, direction and speed control */ + GAINWARD_V2_MODE_STROBE = 0x02, +}; + +enum +{ + GAINWARD_V2_COLOR_REGISTER_PRIMARY, + GAINWARD_V2_COLOR_REGISTER_SECONDARY, + GAINWARD_V2_COLOR_REGISTER_TERTIARY, +}; + +enum +{ + /* Software controlled direct mode */ + GAINWARD_V2_STATIC_SOFTWARE = 0x01, + /* GPU controlled direct mode with breathing effect */ + GAINWARD_V2_STATIC_BREATHING = 0x22, +}; + +class GainwardGPUv2Controller +{ +public: + GainwardGPUv2Controller(i2c_smbus_interface* bus, gainward_gpu_dev_id); + ~GainwardGPUv2Controller(); + + std::string GetDeviceLocation(); + unsigned char GetLEDRed(); + unsigned char GetLEDGreen(); + unsigned char GetLEDBlue(); + void SetLEDColors(unsigned char red, unsigned char green, unsigned char blue, unsigned char color_register = GAINWARD_V2_COLOR_REGISTER_PRIMARY); + void SetMode(unsigned char mode, unsigned char speed, unsigned char direct_mode = GAINWARD_V2_STATIC_SOFTWARE); + void SetBreathingSpeed(unsigned int speed); + void SetDirection(unsigned char direction); + +private: + i2c_smbus_interface * bus; + gainward_gpu_dev_id dev; +}; diff --git a/Controllers/GainwardGPUController/RGBController_GainwardGPU.cpp b/Controllers/GainwardGPUController/RGBController_GainwardGPUv1.cpp similarity index 78% rename from Controllers/GainwardGPUController/RGBController_GainwardGPU.cpp rename to Controllers/GainwardGPUController/RGBController_GainwardGPUv1.cpp index 83365ca10..f0225c328 100644 --- a/Controllers/GainwardGPUController/RGBController_GainwardGPU.cpp +++ b/Controllers/GainwardGPUController/RGBController_GainwardGPUv1.cpp @@ -1,20 +1,20 @@ /*-----------------------------------------*\ -| RGBController_GainwardGPU.cpp | +| RGBController_GainwardGPUv1.cpp | | | -| Driver for Gainward RGB on GPUs | +| Driver for Gainward RGB v1 on GPUs | | | | TheRogueZeta 11/05/2020 | \*-----------------------------------------*/ -#include "RGBController_GainwardGPU.h" +#include "RGBController_GainwardGPUv1.h" -int RGBController_GainwardGPU::GetDeviceMode() +int RGBController_GainwardGPUv1::GetDeviceMode() { active_mode = 1; return(active_mode); } -RGBController_GainwardGPU::RGBController_GainwardGPU(GainwardGPUController * gainward_gpu_ptr) +RGBController_GainwardGPUv1::RGBController_GainwardGPUv1(GainwardGPUv1Controller * gainward_gpu_ptr) { gainward_gpu = gainward_gpu_ptr; @@ -35,12 +35,12 @@ RGBController_GainwardGPU::RGBController_GainwardGPU(GainwardGPUController * gai SetupZones(); } -RGBController_GainwardGPU::~RGBController_GainwardGPU() +RGBController_GainwardGPUv1::~RGBController_GainwardGPUv1() { delete gainward_gpu; } -void RGBController_GainwardGPU::SetupZones() +void RGBController_GainwardGPUv1::SetupZones() { /*---------------------------------------------------------*\ | Set up zone | @@ -73,14 +73,14 @@ void RGBController_GainwardGPU::SetupZones() colors[0] = ToRGBColor(red, grn, blu); } -void RGBController_GainwardGPU::ResizeZone(int /*zone*/, int /*new_size*/) +void RGBController_GainwardGPUv1::ResizeZone(int /*zone*/, int /*new_size*/) { /*---------------------------------------------------------*\ | This device does not support resizing zones | \*---------------------------------------------------------*/ } -void RGBController_GainwardGPU::DeviceUpdateLEDs() +void RGBController_GainwardGPUv1::DeviceUpdateLEDs() { for(std::size_t led = 0; led < colors.size(); led++) { @@ -92,22 +92,22 @@ void RGBController_GainwardGPU::DeviceUpdateLEDs() } } -void RGBController_GainwardGPU::UpdateZoneLEDs(int /*zone*/) +void RGBController_GainwardGPUv1::UpdateZoneLEDs(int /*zone*/) { DeviceUpdateLEDs(); } -void RGBController_GainwardGPU::UpdateSingleLED(int /*led*/) +void RGBController_GainwardGPUv1::UpdateSingleLED(int /*led*/) { DeviceUpdateLEDs(); } -void RGBController_GainwardGPU::SetCustomMode() +void RGBController_GainwardGPUv1::SetCustomMode() { active_mode = 0; } -void RGBController_GainwardGPU::DeviceUpdateMode() +void RGBController_GainwardGPUv1::DeviceUpdateMode() { } diff --git a/Controllers/GainwardGPUController/RGBController_GainwardGPU.h b/Controllers/GainwardGPUController/RGBController_GainwardGPUv1.h similarity index 68% rename from Controllers/GainwardGPUController/RGBController_GainwardGPU.h rename to Controllers/GainwardGPUController/RGBController_GainwardGPUv1.h index f1223105d..7aaac6727 100644 --- a/Controllers/GainwardGPUController/RGBController_GainwardGPU.h +++ b/Controllers/GainwardGPUController/RGBController_GainwardGPUv1.h @@ -1,7 +1,7 @@ /*-----------------------------------------*\ | RGBController_GainwardGPU.h | | | -| Driver for Gainward RGB on GPUs | +| Driver for Gainward RGB v1 on GPUs | | | | TheRogueZeta 11/05/2020 | \*-----------------------------------------*/ @@ -9,13 +9,13 @@ #pragma once #include "RGBController.h" -#include "GainwardGPUController.h" +#include "GainwardGPUv1Controller.h" -class RGBController_GainwardGPU : public RGBController +class RGBController_GainwardGPUv1 : public RGBController { public: - RGBController_GainwardGPU(GainwardGPUController* gainward_gpu_ptr); - ~RGBController_GainwardGPU(); + RGBController_GainwardGPUv1(GainwardGPUv1Controller* gainward_gpu_ptr); + ~RGBController_GainwardGPUv1(); void SetupZones(); @@ -29,7 +29,7 @@ public: void DeviceUpdateMode(); private: - GainwardGPUController* gainward_gpu; + GainwardGPUv1Controller* gainward_gpu; int GetDeviceMode(); }; diff --git a/Controllers/GainwardGPUController/RGBController_GainwardGPUv2.cpp b/Controllers/GainwardGPUController/RGBController_GainwardGPUv2.cpp new file mode 100644 index 000000000..61e03adab --- /dev/null +++ b/Controllers/GainwardGPUController/RGBController_GainwardGPUv2.cpp @@ -0,0 +1,185 @@ +/*-----------------------------------------*\ +| RGBController_GainwardGPUv2.cpp | +| | +| Driver for Gainward RGB v2 on GPUs | +| | +| KundaPanda 01/04/2021 | +\*-----------------------------------------*/ + +#include "RGBController_GainwardGPUv2.h" + +RGBController_GainwardGPUv2::RGBController_GainwardGPUv2(GainwardGPUv2Controller* gainward_gpu_ptr) +{ + gainward_gpu = gainward_gpu_ptr; + + name = "Gainward GPU"; + vendor = "Gainward"; + type = DEVICE_TYPE_GPU; + description = "Gainward RTX GPU"; + version = ""; + location = gainward_gpu->GetDeviceLocation(); + + mode Static; + Static.name = "Static"; + Static.value = GAINWARD_V2_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Static.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Static); + + mode Breathe; + Breathe.name = "Breathing"; + Breathe.value = GAINWARD_V2_MODE_STATIC; + Breathe.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; + Breathe.speed_max = 0x000a; + Breathe.speed_min = 0x1324; + Breathe.color_mode = MODE_COLORS_MODE_SPECIFIC; + Breathe.colors_min = 2; + Breathe.colors_max = 2; + Breathe.colors.resize(2); + modes.push_back(Breathe); + + mode RainbowWave; + RainbowWave.name = "Rainbow Wave"; + RainbowWave.value = GAINWARD_V2_MODE_CYCLE; + RainbowWave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR; + RainbowWave.speed_max = 0x0; + RainbowWave.speed_min = 0xF; + RainbowWave.color_mode = MODE_COLORS_NONE; + modes.push_back(RainbowWave); + + mode Strobe; + Strobe.name = "Strobe"; + Strobe.value = GAINWARD_V2_MODE_STROBE; + Strobe.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR; + Strobe.color_mode = MODE_COLORS_MODE_SPECIFIC; + Strobe.colors_min = 1; + Strobe.colors_max = 1; + Strobe.colors.resize(1); + Strobe.speed_max = 0x0; + Strobe.speed_min = 0xF; + modes.push_back(Strobe); + + SetupZones(); + + /*-------------------------*\ + | Initialize active mode | + \*-------------------------*/ + active_mode = 0; +} + +RGBController_GainwardGPUv2::~RGBController_GainwardGPUv2() +{ + delete gainward_gpu; +} + +void RGBController_GainwardGPUv2::SetupZones() +{ + /*---------------------------------------------------------*\ + | Set up zone | + \*---------------------------------------------------------*/ + zone gainward_gpu_zone; + gainward_gpu_zone.name = "GPU"; + gainward_gpu_zone.type = ZONE_TYPE_SINGLE; + gainward_gpu_zone.leds_min = 1; + gainward_gpu_zone.leds_max = 1; + gainward_gpu_zone.leds_count = 1; + gainward_gpu_zone.matrix_map = NULL; + zones.push_back(gainward_gpu_zone); + + /*---------------------------------------------------------*\ + | Set up LED | + \*---------------------------------------------------------*/ + led gainward_gpu_led; + gainward_gpu_led.name = "GPU"; + leds.push_back(gainward_gpu_led); + + SetupColors(); + + /*---------------------------------------------------------*\ + | Initialize color | + \*---------------------------------------------------------*/ + unsigned char red = gainward_gpu->GetLEDRed(); + unsigned char grn = gainward_gpu->GetLEDGreen(); + unsigned char blu = gainward_gpu->GetLEDBlue(); + + colors[0] = ToRGBColor(red, grn, blu); +} + +void RGBController_GainwardGPUv2::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_GainwardGPUv2::DeviceUpdateLEDs() +{ + for(unsigned int color : colors) + { + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + gainward_gpu->SetLEDColors(red, grn, blu); + gainward_gpu->SetMode(GAINWARD_V2_MODE_STATIC, 0x2); + } +} + +void RGBController_GainwardGPUv2::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_GainwardGPUv2::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_GainwardGPUv2::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_GainwardGPUv2::DeviceUpdateMode() +{ + mode current_mode = modes[(unsigned int)active_mode]; + switch (active_mode) + { + case 1: + { + gainward_gpu->SetBreathingSpeed(current_mode.speed); + + unsigned char r1 = RGBGetRValue(current_mode.colors[0]); + unsigned char g1 = RGBGetGValue(current_mode.colors[0]); + unsigned char b1 = RGBGetBValue(current_mode.colors[0]); + gainward_gpu->SetLEDColors(r1, g1, b1); + + unsigned char r2 = RGBGetRValue(current_mode.colors[1]); + unsigned char g2 = RGBGetGValue(current_mode.colors[1]); + unsigned char b2 = RGBGetBValue(current_mode.colors[1]); + gainward_gpu->SetLEDColors(r2, g2, b2, GAINWARD_V2_COLOR_REGISTER_SECONDARY); + gainward_gpu->SetMode(GAINWARD_V2_MODE_STATIC, 0x2, GAINWARD_V2_STATIC_BREATHING); + } + break; + + /*---------------------------------------------*\ + | Case 3 intentionally falls through to case 2 | + \*---------------------------------------------*/ + case 3: + { + unsigned char r = RGBGetRValue(current_mode.colors[0]); + unsigned char g = RGBGetGValue(current_mode.colors[0]); + unsigned char b = RGBGetBValue(current_mode.colors[0]); + gainward_gpu->SetLEDColors(r, g, b, GAINWARD_V2_COLOR_REGISTER_TERTIARY); + } + + case 2: + gainward_gpu->SetMode((unsigned char)(current_mode.value), (unsigned char)(current_mode.speed)); + gainward_gpu->SetDirection(current_mode.direction); + break; + + default: + gainward_gpu->SetMode((unsigned char)(current_mode.value), (unsigned char)(current_mode.speed)); + break; + } +} diff --git a/Controllers/GainwardGPUController/RGBController_GainwardGPUv2.h b/Controllers/GainwardGPUController/RGBController_GainwardGPUv2.h new file mode 100644 index 000000000..a7718a7b4 --- /dev/null +++ b/Controllers/GainwardGPUController/RGBController_GainwardGPUv2.h @@ -0,0 +1,33 @@ +/*-----------------------------------------*\ +| RGBController_GainwardGPUv2.h | +| | +| Driver for Gainward RGB v2 on GPUs | +| | +| KundaPanda 01/04/2021 | +\*-----------------------------------------*/ + +#pragma once + +#include "RGBController.h" +#include "GainwardGPUv2Controller.h" + +class RGBController_GainwardGPUv2 : public RGBController +{ +public: + RGBController_GainwardGPUv2(GainwardGPUv2Controller* gainward_gpu_ptr); + ~RGBController_GainwardGPUv2(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + GainwardGPUv2Controller* gainward_gpu; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index 28a1affd7..347fd153f 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -211,8 +211,10 @@ HEADERS += Controllers/FanBusController/FanBusController.h \ Controllers/FanBusController/FanBusInterface.h \ Controllers/FanBusController/RGBController_FanBus.h \ - Controllers/GainwardGPUController/GainwardGPUController.h \ - Controllers/GainwardGPUController/RGBController_GainwardGPU.h \ + Controllers/GainwardGPUController/GainwardGPUv1Controller.h \ + Controllers/GainwardGPUController/GainwardGPUv2Controller.h \ + Controllers/GainwardGPUController/RGBController_GainwardGPUv1.h \ + Controllers/GainwardGPUController/RGBController_GainwardGPUv2.h \ Controllers/GalaxGPUController/GalaxGPUController.h \ Controllers/GalaxGPUController/RGBController_GalaxGPU.h \ Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.h \ @@ -451,9 +453,11 @@ SOURCES += Controllers/FanBusController/FanBusControllerDetect.cpp \ Controllers/FanBusController/FanBusInterface.cpp \ Controllers/FanBusController/RGBController_FanBus.cpp \ - Controllers/GainwardGPUController/GainwardGPUController.cpp \ Controllers/GainwardGPUController/GainwardGPUControllerDetect.cpp \ - Controllers/GainwardGPUController/RGBController_GainwardGPU.cpp \ + Controllers/GainwardGPUController/GainwardGPUv1Controller.cpp \ + Controllers/GainwardGPUController/GainwardGPUv2Controller.cpp \ + Controllers/GainwardGPUController/RGBController_GainwardGPUv1.cpp \ + Controllers/GainwardGPUController/RGBController_GainwardGPUv2.cpp \ Controllers/GalaxGPUController/GalaxGPUController.cpp \ Controllers/GalaxGPUController/GalaxGPUControllerDetect.cpp \ Controllers/GalaxGPUController/RGBController_GalaxGPU.cpp \