1+ /* ---------------------------------------------------------*\
2+ | PowerColorRedDevilV2Controller.cpp |
3+ | |
4+ | Driver for PowerColor Red Devil GPU |
5+ | |
6+ | Nexrem 15 Aug 2025 |
7+ | |
8+ | This file is part of the OpenRGB project |
9+ | SPDX-License-Identifier: GPL-2.0-only |
10+ \*---------------------------------------------------------*/
11+
12+ #include < string>
13+ #include " PowerColorRedDevilV2Controller.h"
14+
15+
16+ PowerColorRedDevilV2Controller::PowerColorRedDevilV2Controller (i2c_smbus_interface* bus, red_devil_v2_dev_id dev, std::string dev_name)
17+ {
18+ this ->bus = bus;
19+ this ->dev = dev;
20+ this ->name = dev_name;
21+ }
22+
23+ PowerColorRedDevilV2Controller::~PowerColorRedDevilV2Controller ()
24+ {
25+
26+ }
27+
28+ std::string PowerColorRedDevilV2Controller::GetDeviceLocation ()
29+ {
30+ std::string return_string (bus->device_name );
31+ char addr[5 ];
32+ snprintf (addr, 5 , " 0x%02X" , dev);
33+ return_string.append (" , address " );
34+ return_string.append (addr);
35+ return (" I2C:" + return_string);
36+ }
37+
38+ std::string PowerColorRedDevilV2Controller::GetDeviceName ()
39+ {
40+ return (name);
41+ }
42+
43+ bool PowerColorRedDevilV2Controller::GetSync ()
44+ {
45+ unsigned char data[3 ];
46+ RegisterRead (RED_DEVIL_V2_READ_REG_SYNC, data);
47+
48+ return data[0 ] && data[1 ] && data[2 ];
49+ }
50+
51+ void PowerColorRedDevilV2Controller::SetSync (bool sync)
52+ {
53+ if (sync)
54+ {
55+ unsigned char data[3 ] = {0x01 , 0x01 , 0x01 };
56+ RegisterWrite (RED_DEVIL_V2_WRITE_REG_SYNC, data);
57+ }
58+ else
59+ {
60+ unsigned char data[3 ] = {0x00 , 0x00 , 0x00 };
61+ RegisterWrite (RED_DEVIL_V2_WRITE_REG_SYNC, data);
62+ }
63+ }
64+
65+ /* ------------------------------------------------------------------*\
66+ | Mode returns MMBBSS |
67+ \*------------------------------------------------------------------*/
68+ red_devil_v2_mode PowerColorRedDevilV2Controller::GetMode ()
69+ {
70+ unsigned char data[3 ];
71+ red_devil_v2_mode mode;
72+
73+ RegisterRead (RED_DEVIL_V2_READ_REG_MODE, data);
74+
75+ mode.mode = data[0 ];
76+ mode.brightness = data[1 ];
77+ mode.speed = data[2 ];
78+
79+ return mode;
80+ }
81+
82+ void PowerColorRedDevilV2Controller::SetMode (red_devil_v2_mode mode)
83+ {
84+ if (mode.mode == RED_DEVIL_V2_MODE_SYNC)
85+ {
86+ SetSync (true );
87+ return ;
88+ }
89+
90+ SetSync (false );
91+
92+ unsigned char data[3 ] =
93+ {
94+ mode.mode ,
95+ mode.brightness ,
96+ mode.speed
97+ };
98+
99+ RegisterWrite (RED_DEVIL_V2_WRITE_REG_MODE, data);
100+ }
101+
102+ RGBColor PowerColorRedDevilV2Controller::GetLedColor (int led)
103+ {
104+ /* ------------------------------------------------------------------*\
105+ | On overflow read the first LED |
106+ \*------------------------------------------------------------------*/
107+ if (led >= RED_DEVIL_V2_NUM_LEDS)
108+ {
109+ led = 0 ;
110+ }
111+
112+ unsigned char data[3 ];
113+ RegisterRead (RED_DEVIL_V2_READ_REG_RGBX + led, data);
114+
115+ return ToRGBColor (data[0 ], data[1 ], data[2 ]);
116+ }
117+
118+ void PowerColorRedDevilV2Controller::SetLedColor (int led, RGBColor color)
119+ {
120+ /* ------------------------------------------------------------------*\
121+ | Skip writing to invalid LEDs |
122+ \*------------------------------------------------------------------*/
123+ if (led >= RED_DEVIL_V2_NUM_LEDS)
124+ {
125+ return ;
126+ }
127+
128+ unsigned char data[3 ] =
129+ {
130+ (unsigned char ) RGBGetRValue (color),
131+ (unsigned char ) RGBGetGValue (color),
132+ (unsigned char ) RGBGetBValue (color)
133+ };
134+
135+ RegisterWrite (RED_DEVIL_V2_WRITE_REG_RGBX+led, data);
136+ }
137+
138+ void PowerColorRedDevilV2Controller::SetLedColorAll (RGBColor color)
139+ {
140+ unsigned char data[3 ] =
141+ {
142+ (unsigned char ) RGBGetRValue (color),
143+ (unsigned char ) RGBGetGValue (color),
144+ (unsigned char ) RGBGetBValue (color)
145+ };
146+
147+ /* ------------------------------------------------------------------*\
148+ | Factory firmware writes both, but we only need 1 of them. |
149+ | Write both anyways just in case... |
150+ \*------------------------------------------------------------------*/
151+ RegisterWrite (RED_DEVIL_V2_WRITE_REG_RGB1, data);
152+ RegisterWrite (RED_DEVIL_V2_WRITE_REG_RGB2, data);
153+ }
154+
155+ int PowerColorRedDevilV2Controller::RegisterRead (unsigned char reg, unsigned char *data)
156+ {
157+ int ret = bus->i2c_smbus_read_i2c_block_data (dev, reg, 3 , data);
158+ std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
159+ return ret;
160+ }
161+
162+ int PowerColorRedDevilV2Controller::RegisterWrite (unsigned char reg, unsigned char *data)
163+ {
164+ int ret = bus->i2c_smbus_write_i2c_block_data (dev, reg, 3 , data);
165+ std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
166+ return ret;
167+ }
0 commit comments