Initial driver for Sapphire GPU (tested on RX580 Nitro+ on Windows)

This commit is contained in:
Adam Honse 2020-07-15 00:22:46 -05:00
parent 77ecfc3b46
commit 505e2d2aa4
7 changed files with 278 additions and 0 deletions

View file

@ -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);
}

View file

@ -0,0 +1,41 @@
/*-----------------------------------------*\
| SapphireGPUController.h |
| |
| Definitions and types for Sapphire Nitro |
| Glow GPU RGB lighting controller |
| |
| Adam Honse (CalcProgrammer1) 7/15/2020 |
\*-----------------------------------------*/
#include <string>
#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;
};

View file

@ -0,0 +1,56 @@
#include "SapphireGPUController.h"
#include "RGBController.h"
#include "RGBController_SapphireGPU.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* 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<i2c_smbus_interface*>& busses, std::vector<RGBController*>& 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() */