|
| 1 | +/*---------------------------------------------------------*\ |
| 2 | +| ManliGPUController.cpp | |
| 3 | +| | |
| 4 | +| Driver for Manli GPU RGB controllers | |
| 5 | +| | |
| 6 | +| Based on ZotacV2GPUController | |
| 7 | +| Adapted for Manli RTX 4090 Gallardo | |
| 8 | +| | |
| 9 | +| This file is part of the OpenRGB project | |
| 10 | +| SPDX-License-Identifier: GPL-2.0-or-later | |
| 11 | +\*---------------------------------------------------------*/ |
| 12 | + |
| 13 | +#include "ManliGPUController.h" |
| 14 | + |
| 15 | +ManliGPUController::ManliGPUController(i2c_smbus_interface* bus, u8 dev, std::string dev_name) |
| 16 | +{ |
| 17 | + this->bus = bus; |
| 18 | + this->dev = dev; |
| 19 | + this->name = dev_name; |
| 20 | + |
| 21 | + if(dev) |
| 22 | + { |
| 23 | + ReadVersion(); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +ManliGPUController::~ManliGPUController() |
| 28 | +{ |
| 29 | +} |
| 30 | + |
| 31 | +std::string ManliGPUController::GetDeviceLocation() |
| 32 | +{ |
| 33 | + std::string return_string(bus->device_name); |
| 34 | + char addr[5]; |
| 35 | + snprintf(addr, 5, "0x%02X", dev); |
| 36 | + return_string.append(", address "); |
| 37 | + return_string.append(addr); |
| 38 | + return ("I2C: " + return_string); |
| 39 | +} |
| 40 | + |
| 41 | +std::string ManliGPUController::GetName() |
| 42 | +{ |
| 43 | + return(name); |
| 44 | +} |
| 45 | + |
| 46 | +std::string ManliGPUController::GetVersion() |
| 47 | +{ |
| 48 | + return(version); |
| 49 | +} |
| 50 | + |
| 51 | +bool ManliGPUController::ReadVersion() |
| 52 | +{ |
| 53 | + u8 data_pkt[] = { MANLI_GPU_REG_RGB, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 54 | + if(bus->i2c_write_block(dev, sizeof(data_pkt), data_pkt) < 0) |
| 55 | + { |
| 56 | + return false; |
| 57 | + } |
| 58 | + |
| 59 | + u8 rdata_pkt[I2C_SMBUS_BLOCK_MAX] = { 0x00 }; |
| 60 | + int rdata_len = sizeof(rdata_pkt); |
| 61 | + if(bus->i2c_read_block(dev, &rdata_len, rdata_pkt) < 0) |
| 62 | + { |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + version = std::string((char*)rdata_pkt); |
| 67 | + return true; |
| 68 | +} |
| 69 | + |
| 70 | +bool ManliGPUController::TurnOnOff(bool on) |
| 71 | +{ |
| 72 | + ManliGPUZone zoneConfig; |
| 73 | + return SendCommand(on, zoneConfig); |
| 74 | +} |
| 75 | + |
| 76 | +bool ManliGPUController::SetMode(ManliGPUZone zoneConfig) |
| 77 | +{ |
| 78 | + return SendCommand(true, zoneConfig); |
| 79 | +} |
| 80 | + |
| 81 | +bool ManliGPUController::SendCommand(bool on, ManliGPUZone zoneConfig) |
| 82 | +{ |
| 83 | + /*---------------------------------------------------------*\ |
| 84 | + | Color Cycle: Uses breathing mode (0x01) with flag 0x07 | |
| 85 | + | This cycles through colors with brightness and speed | |
| 86 | + \*---------------------------------------------------------*/ |
| 87 | + if(zoneConfig.mode == MANLI_GPU_MODE_COLOR_CYCLE) |
| 88 | + { |
| 89 | + u8 data_pkt[30] = { 0x00 }; |
| 90 | + data_pkt[0] = on ? (u8)0x01 : (u8)0x00; |
| 91 | + data_pkt[6] = 0x01; // mode = breathing |
| 92 | + data_pkt[7] = 0x00; // R |
| 93 | + data_pkt[8] = 0x00; // G |
| 94 | + data_pkt[9] = 0x00; // B |
| 95 | + data_pkt[10] = (u8)zoneConfig.speed; |
| 96 | + data_pkt[11] = (u8)zoneConfig.brightness; |
| 97 | + data_pkt[13] = 0x07; // color cycle flag |
| 98 | + |
| 99 | + if(bus->i2c_smbus_write_i2c_block_data(dev, MANLI_GPU_REG_RGB, sizeof(data_pkt), data_pkt) < 0) |
| 100 | + { |
| 101 | + return false; |
| 102 | + } |
| 103 | + return true; |
| 104 | + } |
| 105 | + /*---------------------------------------------------------*\ |
| 106 | + | Standard modes (Static, Breathing, Wave, Strobing, Rainbow)| |
| 107 | + \*---------------------------------------------------------*/ |
| 108 | + else |
| 109 | + { |
| 110 | + u8 data_pkt[30] = { 0x00 }; |
| 111 | + data_pkt[0] = on ? (u8)0x01 : (u8)0x00; |
| 112 | + data_pkt[6] = (u8)zoneConfig.mode; |
| 113 | + data_pkt[7] = (u8)RGBGetRValue(zoneConfig.color1); |
| 114 | + data_pkt[8] = (u8)RGBGetGValue(zoneConfig.color1); |
| 115 | + data_pkt[9] = (u8)RGBGetBValue(zoneConfig.color1); |
| 116 | + data_pkt[10] = (u8)zoneConfig.speed; |
| 117 | + data_pkt[11] = (u8)zoneConfig.brightness; |
| 118 | + |
| 119 | + if(bus->i2c_smbus_write_i2c_block_data(dev, MANLI_GPU_REG_RGB, sizeof(data_pkt), data_pkt) < 0) |
| 120 | + { |
| 121 | + return false; |
| 122 | + } |
| 123 | + return true; |
| 124 | + } |
| 125 | +} |
0 commit comments