From 505e2d2aa41ca6f524c92ae4c9ec8f01a2cefdb1 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 15 Jul 2020 00:22:46 -0500 Subject: [PATCH] Initial driver for Sapphire GPU (tested on RX580 Nitro+ on Windows) --- .../SapphireGPUController.cpp | 43 ++++++++ .../SapphireGPUController.h | 41 ++++++++ .../SapphireGPUControllerDetect.cpp | 56 +++++++++++ OpenRGB.cpp | 2 + OpenRGB.pro | 6 ++ RGBController/RGBController_SapphireGPU.cpp | 97 +++++++++++++++++++ RGBController/RGBController_SapphireGPU.h | 33 +++++++ 7 files changed, 278 insertions(+) create mode 100644 Controllers/SapphireGPUController/SapphireGPUController.cpp create mode 100644 Controllers/SapphireGPUController/SapphireGPUController.h create mode 100644 Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp create mode 100644 RGBController/RGBController_SapphireGPU.cpp create mode 100644 RGBController/RGBController_SapphireGPU.h diff --git a/Controllers/SapphireGPUController/SapphireGPUController.cpp b/Controllers/SapphireGPUController/SapphireGPUController.cpp new file mode 100644 index 00000000..1e28bb03 --- /dev/null +++ b/Controllers/SapphireGPUController/SapphireGPUController.cpp @@ -0,0 +1,43 @@ +/*-----------------------------------------*\ +| SapphireGPUController.cpp | +| | +| Driver for Sapphire Nitro Glow GPU RGB | +| lighting controller | +| | +| Adam Honse (CalcProgrammer1) 7/15/2020 | +\*-----------------------------------------*/ + +#include "SapphireGPUController.h" + +SapphireGPUController::SapphireGPUController(i2c_smbus_interface* bus, sapphire_dev_id dev) +{ + this->bus = bus; + this->dev = dev; +} + +SapphireGPUController::~SapphireGPUController() +{ + +} + +std::string SapphireGPUController::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(return_string); +} + +void SapphireGPUController::SetColor(unsigned char red, unsigned char green, unsigned char blue) +{ + bus->i2c_smbus_write_byte_data(dev, SAPPHIRE_GPU_REG_RED, red); + bus->i2c_smbus_write_byte_data(dev, SAPPHIRE_GPU_REG_GREEN, green); + bus->i2c_smbus_write_byte_data(dev, SAPPHIRE_GPU_REG_BLUE, blue); +} + +void SapphireGPUController::SetMode(unsigned char mode, unsigned char speed) +{ + bus->i2c_smbus_write_byte_data(dev, SAPPHIRE_GPU_REG_MODE, 0x04); +} diff --git a/Controllers/SapphireGPUController/SapphireGPUController.h b/Controllers/SapphireGPUController/SapphireGPUController.h new file mode 100644 index 00000000..492148a5 --- /dev/null +++ b/Controllers/SapphireGPUController/SapphireGPUController.h @@ -0,0 +1,41 @@ +/*-----------------------------------------*\ +| SapphireGPUController.h | +| | +| Definitions and types for Sapphire Nitro | +| Glow GPU RGB lighting controller | +| | +| Adam Honse (CalcProgrammer1) 7/15/2020 | +\*-----------------------------------------*/ + +#include +#include "i2c_smbus.h" + +#pragma once + +typedef unsigned char sapphire_dev_id; + +enum +{ + SAPPHIRE_GPU_REG_MODE = 0x00, + SAPPHIRE_GPU_REG_BRIGHTNESS = 0x01, + SAPPHIRE_GPU_REG_RED = 0x03, + SAPPHIRE_GPU_REG_GREEN = 0x04, + SAPPHIRE_GPU_REG_BLUE = 0x05, +}; + +class SapphireGPUController +{ +public: + SapphireGPUController(i2c_smbus_interface* bus, sapphire_dev_id dev); + ~SapphireGPUController(); + + std::string GetDeviceLocation(); + + void SetColor(unsigned char red, unsigned char green, unsigned char blue); + void SetMode(unsigned char mode, unsigned char speed); + +private: + i2c_smbus_interface* bus; + sapphire_dev_id dev; + +}; diff --git a/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp b/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp new file mode 100644 index 00000000..626faceb --- /dev/null +++ b/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp @@ -0,0 +1,56 @@ +#include "SapphireGPUController.h" +#include "RGBController.h" +#include "RGBController_SapphireGPU.h" +#include "i2c_smbus.h" +#include +#include +#include + +/******************************************************************************************\ +* * +* TestForSapphireGPUController * +* * +* Tests the given address to see if a Sapphire GPU controller exists there. First * +* does a quick write to test for a response * +* * +\******************************************************************************************/ + +bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address) +{ + bool pass = false; + int res; + + //TODO - detection + + return(false); + +} /* TestForSapphireGPUController() */ + +/******************************************************************************************\ +* * +* DetectSapphireGPUControllers * +* * +* Detect Sapphire GPU controllers on the enumerated I2C busses at address 0x55. * +* * +* bus - pointer to i2c_smbus_interface where Sapphire GPU device is connected * +* dev - I2C address of Sapphire GPU device * +* * +\******************************************************************************************/ + +void DetectSapphireGPUControllers(std::vector& busses, std::vector& rgb_controllers) +{ + SapphireGPUController* new_sapphire; + RGBController_SapphireGPU* new_controller; + + for (unsigned int bus = 0; bus < busses.size(); bus++) + { + // Check for Sapphire GPU controller at 0x55 + if (TestForSapphireGPUController(busses[bus], 0x55)) + { + new_sapphire = new SapphireGPUController(busses[bus], 0x55); + new_controller = new RGBController_SapphireGPU(new_sapphire); + rgb_controllers.push_back(new_controller); + } + } + +} /* DetectSapphireGPUControllers() */ diff --git a/OpenRGB.cpp b/OpenRGB.cpp index defb2974..5cbcc2aa 100644 --- a/OpenRGB.cpp +++ b/OpenRGB.cpp @@ -424,6 +424,7 @@ void DetectRGBFusionGPUControllers(std::vector& busses, st void DetectRGBFusion2SMBusControllers(std::vector& busses, std::vector& rgb_controllers); void DetectRGBFusion2DRAMControllers(std::vector& busses, std::vector& rgb_controllers); void DetectMSIGPUControllers(std::vector& busses, std::vector& rgb_controllers); +void DetectSapphireGPUControllers(std::vector& busses, std::vector& rgb_controllers); void DetectMSIMysticLightControllers(std::vector &rgb_controllers); void DetectMSIRGBControllers(std::vector &rgb_controllers); void DetectAuraUSBControllers(std::vector &rgb_controllers); @@ -472,6 +473,7 @@ void DetectRGBControllers(void) DetectPolychromeControllers(busses, rgb_controllers); DetectRGBFusionGPUControllers(busses, rgb_controllers); DetectMSIGPUControllers(busses, rgb_controllers); + DetectSapphireGPUControllers(busses, rgb_controllers); //TODO: Implement better detection before enabling these controllers //DetectRGBFusion2SMBusControllers(busses, rgb_controllers); diff --git a/OpenRGB.pro b/OpenRGB.pro index 76a90aba..61ef2528 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -80,6 +80,7 @@ INCLUDEPATH += \ Controllers/RGBFusion2SMBusController/ \ Controllers/RGBFusion2USBController/ \ Controllers/RGBFusionGPUController/ \ + Controllers/SapphireGPUController/ \ Controllers/SteelSeriesController/ \ Controllers/ThermaltakeRiingController/ \ RGBController/ \ @@ -146,6 +147,7 @@ HEADERS += \ Controllers/RGBFusionGPUController/RGBFusionGPUController.h \ Controllers/RedragonController/RedragonK556Controller.h \ Controllers/RedragonController/RedragonM711Controller.h \ + Controllers/SapphireGPUController/SapphireGPUController.h \ Controllers/SteelSeriesController/SteelSeriesRivalController.h \ Controllers/SteelSeriesController/SteelSeriesSiberiaController.h \ Controllers/SteelSeriesController/SteelSeriesApexController.h \ @@ -192,6 +194,7 @@ HEADERS += \ RGBController/RGBController_RGBFusion2SMBus.h \ RGBController/RGBController_RGBFusion2USB.h \ RGBController/RGBController_RGBFusionGPU.h \ + RGBController/RGBController_SapphireGPU.h \ RGBController/RGBController_SteelSeriesRival.h \ RGBController/RGBController_SteelSeriesSiberia.h \ RGBController/RGBController_SteelSeriesApex.h \ @@ -295,6 +298,8 @@ SOURCES += \ Controllers/RedragonController/RedragonK556Controller.cpp \ Controllers/RedragonController/RedragonM711Controller.cpp \ Controllers/RedragonController/RedragonControllerDetect.cpp \ + Controllers/SapphireGPUController/SapphireGPUController.cpp \ + Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp \ Controllers/SteelSeriesController/SteelSeriesRivalController.cpp \ Controllers/SteelSeriesController/SteelSeriesSiberiaController.cpp \ Controllers/SteelSeriesController/SteelSeriesApexController.cpp \ @@ -343,6 +348,7 @@ SOURCES += \ RGBController/RGBController_RGBFusion2SMBus.cpp \ RGBController/RGBController_RGBFusion2USB.cpp \ RGBController/RGBController_RGBFusionGPU.cpp \ + RGBController/RGBController_SapphireGPU.cpp \ RGBController/RGBController_SteelSeriesRival.cpp \ RGBController/RGBController_SteelSeriesSiberia.cpp \ RGBController/RGBController_SteelSeriesApex.cpp \ diff --git a/RGBController/RGBController_SapphireGPU.cpp b/RGBController/RGBController_SapphireGPU.cpp new file mode 100644 index 00000000..93bda624 --- /dev/null +++ b/RGBController/RGBController_SapphireGPU.cpp @@ -0,0 +1,97 @@ +/*-----------------------------------------*\ +| RGBController_RGBFusionGPU.cpp | +| | +| Generic RGB Interface for OpenRGB | +| Gigabyte RGB Fusion GPU Driver | +| | +| Adam Honse (CalcProgrammer1) 2/23/2020 | +\*-----------------------------------------*/ + +#include "RGBController_SapphireGPU.h" + +RGBController_SapphireGPU::RGBController_SapphireGPU(SapphireGPUController* sapphire_ptr) +{ + sapphire = sapphire_ptr; + + name = "Sapphire GPU"; + description = "Sapphire GPU"; + location = sapphire->GetDeviceLocation(); + + type = DEVICE_TYPE_GPU; + + mode Static; + Static.name = "Static"; + Static.value = 0; + Static.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Static.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Static); + + SetupZones(); + + // Initialize active mode + active_mode = 0; +} + +void RGBController_SapphireGPU::SetupZones() +{ + /*---------------------------------------------------------*\ + | This device only has one LED, so create a single zone and | + | LED for it | + \*---------------------------------------------------------*/ + zone* new_zone = new zone(); + led* new_led = new led(); + + new_zone->name = "GPU Zone"; + new_zone->type = ZONE_TYPE_SINGLE; + new_zone->leds_min = 1; + new_zone->leds_max = 1; + new_zone->leds_count = 1; + new_zone->matrix_map = NULL; + + new_led->name = "GPU LED"; + + /*---------------------------------------------------------*\ + | Push the zone and LED on to device vectors | + \*---------------------------------------------------------*/ + leds.push_back(*new_led); + zones.push_back(*new_zone); + + SetupColors(); +} + +void RGBController_SapphireGPU::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_SapphireGPU::DeviceUpdateLEDs() +{ + RGBColor color = colors[0]; + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + sapphire->SetColor(red, grn, blu); +} + +void RGBController_SapphireGPU::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_SapphireGPU::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_SapphireGPU::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_SapphireGPU::UpdateMode() +{ + sapphire->SetMode((unsigned char)modes[(unsigned int)active_mode].value, (unsigned char)modes[(unsigned int)active_mode].speed); +} diff --git a/RGBController/RGBController_SapphireGPU.h b/RGBController/RGBController_SapphireGPU.h new file mode 100644 index 00000000..09909109 --- /dev/null +++ b/RGBController/RGBController_SapphireGPU.h @@ -0,0 +1,33 @@ +/*-----------------------------------------*\ +| RGBController_SapphireGPU.h | +| | +| Generic RGB Interface for OpenRGB | +| Sapphire GPU RGB Driver | +| | +| Adam Honse (CalcProgrammer1) 7/15/2020 | +\*-----------------------------------------*/ + +#pragma once + +#include "RGBController.h" +#include "SapphireGPUController.h" + +class RGBController_SapphireGPU : public RGBController +{ +public: + RGBController_SapphireGPU(SapphireGPUController* sapphire_ptr); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void UpdateMode(); + +private: + SapphireGPUController* sapphire; +};