Add Palit 1080 controller

This commit is contained in:
Manatsawin Hanmongkolchai 2023-04-12 17:50:15 +00:00 committed by Adam Honse
parent d012173ebe
commit f2132d79c5
6 changed files with 273 additions and 0 deletions

View file

@ -0,0 +1,38 @@
/*-----------------------------------------*\
| PalitGPUController.cpp |
| |
| Driver for Palit GPU RGB |
| lighting controller |
| |
| Manatsawin Hanmongkolchai 04/11/2023 |
\*-----------------------------------------*/
#include "PalitGPUController.h"
PalitGPUController::PalitGPUController(i2c_smbus_interface* bus, palit_dev_id dev)
{
this->bus = bus;
this->dev = dev;
}
PalitGPUController::~PalitGPUController()
{
}
std::string PalitGPUController::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);
}
void PalitGPUController::SetDirect(unsigned char red, unsigned char green, unsigned char blue)
{
// NvAPI_I2CWriteEx: Dev: 0x08 RegSize: 0x01 Reg: 0x03 Size: 0x04 Data: 0xFF 0x00 0x00 0xFF
uint8_t values[] = {red, green, blue, 0xFF};
bus->i2c_smbus_write_i2c_block_data(dev, PALIT_GPU_REG_LED, sizeof(values), values);
}

View file

@ -0,0 +1,41 @@
/*-----------------------------------------*\
| PalitGPUController.h |
| |
| Definitions and types for Palit GPU RGB |
| lighting controller |
| |
| Manatsawin Hanmongkolchai 04/11/2023 |
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
typedef unsigned char palit_dev_id;
enum
{
PALIT_GPU_MODE_DIRECT = 0x00,
};
enum
{
PALIT_GPU_REG_LED = 0x03,
};
class PalitGPUController
{
public:
PalitGPUController(i2c_smbus_interface* bus, palit_dev_id dev);
~PalitGPUController();
std::string GetDeviceLocation();
void SetDirect(unsigned char red, unsigned char green, unsigned char blue);
private:
i2c_smbus_interface* bus;
palit_dev_id dev;
};

View file

@ -0,0 +1,48 @@
#include "Detector.h"
#include "LogManager.h"
#include "PalitGPUController.h"
#include "RGBController.h"
#include "RGBController_PalitGPU.h"
#include "i2c_smbus.h"
#include "pci_ids.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* DetectPalitGPUControllers *
* *
* Detect Palit GPU controllers on the enumerated I2C busses at address 0x49. *
* *
* bus - pointer to i2c_smbus_interface where Palit GPU device is connected *
* dev - I2C address of Palit GPU device *
* *
\******************************************************************************************/
void DetectPalitGPUControllers(i2c_smbus_interface* bus, uint8_t i2c_addr, const std::string& name)
{
if(bus->port_id != 1)
{
return;
}
const uint8_t palit[] = {'P', 'A', 'L', 'I', 'T'};
for (int i = 0; i < sizeof(palit); i++)
{
int32_t letter = bus->i2c_smbus_read_byte_data(i2c_addr, 0x07 + i);
if (palit[i] != letter)
{
return;
}
}
PalitGPUController* controller = new PalitGPUController(bus, i2c_addr);
RGBController_PalitGPU* rgb_controller = new RGBController_PalitGPU(controller);
rgb_controller->name = name;
rgb_controller->vendor = name.substr(0, name.find(' '));
ResourceManager::get()->RegisterRGBController(rgb_controller);
} /* DetectPalitGPUControllers() */
REGISTER_I2C_PCI_DETECTOR("Palit 1080", DetectPalitGPUControllers, NVIDIA_VEN, NVIDIA_GTX1080_DEV, NVIDIA_SUB_VEN, NVIDIA_GTX1080_DEV, 0x08);

View file

@ -0,0 +1,110 @@
/*-----------------------------------------*\
| RGBController_PalitGPU.cpp |
| |
| Generic RGB Interface for OpenRGB |
| Palit GPU RGB Driver |
| |
| Manatsawin Hanmongkolchai 04/11/2023 |
\*-----------------------------------------*/
#include "RGBController_PalitGPU.h"
/**------------------------------------------------------------------*\
@name Palit GPU
@category GPU
@type I2C
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectPalitGPUControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_PalitGPU::RGBController_PalitGPU(PalitGPUController* controller_ptr)
{
controller = controller_ptr;
name = "Palit GPU";
vendor = "Palit";
description = "Legacy Palit RGB GPU Device";
location = controller->GetDeviceLocation();
type = DEVICE_TYPE_GPU;
mode Direct;
Direct.name = "Direct";
Direct.value = PALIT_GPU_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
// Initialize active mode
active_mode = 0;
}
void RGBController_PalitGPU::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_PalitGPU::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_PalitGPU::DeviceUpdateLEDs()
{
DeviceUpdateMode();
}
void RGBController_PalitGPU::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_PalitGPU::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_PalitGPU::DeviceUpdateMode()
{
RGBColor color = colors[0];
unsigned char r = RGBGetRValue(color);
unsigned char g = RGBGetGValue(color);
unsigned char b = RGBGetBValue(color);
unsigned char speed, brightness;
switch(modes[active_mode].value)
{
case PALIT_GPU_MODE_DIRECT:
controller->SetDirect(r, g, b);
break;
default:
break;
}
}

View file

@ -0,0 +1,31 @@
/*-----------------------------------------*\
| RGBController_PalitGPU.h |
| |
| Generic RGB Interface for OpenRGB |
| Palit GPU RGB Driver |
| |
| Manatsawin Hanmongkolchai 04/11/2023 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "PalitGPUController.h"
class RGBController_PalitGPU : public RGBController
{
public:
RGBController_PalitGPU(PalitGPUController* controller_ptr);
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
PalitGPUController* controller;
};