Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -0,0 +1,163 @@
/*---------------------------------------------------------*\
| CrucialController.cpp |
| |
| Driver for Crucial Ballistix RAM |
| |
| Adam Honse (CalcProgrammer1) 19 Jan 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController.h"
#include "CrucialController.h"
CrucialController::CrucialController(i2c_smbus_interface* bus, crucial_dev_id dev)
{
this->bus = bus;
this->dev = dev;
for(int i = 0; i < 16; i++)
{
device_version[i] = CrucialRegisterRead(CRUCIAL_REG_DEVICE_VERSION + i);
}
}
CrucialController::~CrucialController()
{
}
std::string CrucialController::GetDeviceVersion()
{
return(device_version);
}
std::string CrucialController::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 CrucialController::SetMode(unsigned char mode)
{
SendEffectMode(mode, 0x10);
}
void CrucialController::SetAllColorsDirect(RGBColor* colors)
{
SendDirectColors(colors);
}
void CrucialController::SetAllColorsEffect(RGBColor* colors)
{
for(int led_idx = 0; led_idx < 8; led_idx++)
{
unsigned char red = RGBGetRValue(colors[led_idx]);
unsigned char grn = RGBGetGValue(colors[led_idx]);
unsigned char blu = RGBGetBValue(colors[led_idx]);
SendEffectColor(led_idx, red, grn, blu);
}
}
void CrucialController::SendBrightness(unsigned char brightness)
{
CrucialRegisterWrite(0x82EE, 0xFF);
CrucialRegisterWrite(0x82EF, brightness);
CrucialRegisterWrite(0x82F0, 0x83);
}
void CrucialController::SendEffectMode(unsigned char mode, unsigned char speed)
{
CrucialRegisterWrite(0x820F, mode);
CrucialRegisterWrite(0x82EE, 0x00);
CrucialRegisterWrite(0x82EF, speed);
CrucialRegisterWrite(0x82F0, 0x84);
}
void CrucialController::SendDirectColors(RGBColor* color_buf)
{
unsigned char color_blk[8];
for(unsigned int led = 0; led < 8; led++)
{
color_blk[led] = RGBGetRValue(color_buf[led]);
}
//Red Channels
CrucialRegisterWriteBlock(0x8300, color_blk, 8);
for(unsigned int led = 0; led < 8; led++)
{
color_blk[led] = RGBGetGValue(color_buf[led]);
}
//Green Channels
CrucialRegisterWriteBlock(0x8340, color_blk, 8);
for(unsigned int led = 0; led < 8; led++)
{
color_blk[led] = RGBGetBValue(color_buf[led]);
}
//Blue Channels
CrucialRegisterWriteBlock(0x8380, color_blk, 8);
}
unsigned char CrucialController::CrucialRegisterRead(crucial_register reg)
{
//Write Crucial register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Read Crucial value
return(bus->i2c_smbus_read_byte_data(dev, 0x81));
}
void CrucialController::CrucialRegisterWrite(crucial_register reg, unsigned char val)
{
//Write Crucial register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Crucial value
bus->i2c_smbus_write_byte_data(dev, 0x01, val);
}
void CrucialController::CrucialRegisterWriteBlock(crucial_register reg, unsigned char * data, unsigned char sz)
{
//Write Crucial register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Crucial block data
if(bus->i2c_smbus_write_block_data(dev, 0x03, sz, data) == -1)
{
//Fall back to individual byte operations if the block operation fails
for(unsigned int block_byte = 0; block_byte < sz; block_byte++)
{
bus->i2c_smbus_write_byte_data(dev, 0x01, data[block_byte]);
}
}
}
void CrucialController::SendEffectColor
(
unsigned int led_idx,
unsigned int red,
unsigned int green,
unsigned int blue
)
{
CrucialRegisterWrite(0x82E9, (1 << led_idx));
CrucialRegisterWrite(0x82EA, 0x00);
CrucialRegisterWrite(0x82EB, 0x00);
CrucialRegisterWrite(0x82EC, 0x00);
CrucialRegisterWrite(0x82ED, red);
CrucialRegisterWrite(0x82EE, green);
CrucialRegisterWrite(0x82EF, blue);
CrucialRegisterWrite(0x82F0, 0x01);
}
@@ -0,0 +1,77 @@
/*---------------------------------------------------------*\
| CrucialController.h |
| |
| Driver for Crucial Ballistix RAM |
| |
| Adam Honse (CalcProgrammer1) 19 Jan 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <string>
#include "RGBController.h"
#include "i2c_smbus.h"
typedef unsigned char crucial_dev_id;
typedef unsigned short crucial_register;
enum
{
CRUCIAL_REG_DEVICE_VERSION = 0x1000, /* Version (Date) String 16 bytes */
CRUCIAL_REG_MICRON_CHECK_1 = 0x1025, /* "Micron" string location 1 */
CRUCIAL_REG_MICRON_CHECK_2 = 0x1030 /* "Micron" string location 2 */
};
enum
{
CRUCIAL_MODE_UNKNOWN = 0x00, /* We don't know what the mode is */
CRUCIAL_MODE_SHIFT = 0x1F, /* Shift effect mode */
CRUCIAL_MODE_GRADIENT_SHIFT = 0x2F, /* Gradient shift mode */
CRUCIAL_MODE_FILL = 0x3F, /* Fill effect mode */
CRUCIAL_MODE_STACK = 0x4F, /* Stack effect mode */
CRUCIAL_MODE_DOUBLE_STACK = 0x5F, /* Double stack effect mode */
CRUCIAL_MODE_BREATHING = 0x6F, /* Breathing effect mode */
CRUCIAL_MODE_MOTION_POINT = 0x7F, /* Motion point effect mode */
CRUCIAL_MODE_INSIDE_OUT = 0x8F, /* Inside out effect mode */
CRUCIAL_MODE_COLOR_STEP = 0x9F, /* Color step effect mode */
CRUCIAL_MODE_WATER_WAVE = 0xAF, /* Water wave effect mode */
CRUCIAL_MODE_FLASHING = 0xBF, /* Flashing effect mode */
CRUCIAL_MODE_STATIC = 0xCF, /* Static effect mode */
};
class CrucialController
{
public:
CrucialController(i2c_smbus_interface* bus, crucial_dev_id dev);
~CrucialController();
std::string GetDeviceVersion();
std::string GetDeviceLocation();
void SetAllColorsDirect(RGBColor* colors);
void SetAllColorsEffect(RGBColor* colors);
void SetMode(unsigned char mode);
unsigned char CrucialRegisterRead(crucial_register reg);
void CrucialRegisterWrite(crucial_register reg, unsigned char val);
void CrucialRegisterWriteBlock(crucial_register reg, unsigned char * data, unsigned char sz);
private:
char device_version[16];
i2c_smbus_interface * bus;
crucial_dev_id dev;
void SendEffectColor
(
unsigned int led_idx,
unsigned int red,
unsigned int green,
unsigned int blue
);
void SendDirectColors(RGBColor* color_buf);
void SendBrightness(unsigned char brightness);
void SendEffectMode(unsigned char mode, unsigned char speed);
};
@@ -0,0 +1,230 @@
/*---------------------------------------------------------*\
| CrucialControllerDetect.cpp |
| |
| Detector for Crucial Ballistix RAM |
| |
| Adam Honse (CalcProgrammer1) 19 Jan 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <stdio.h>
#include <vector>
#include "Detector.h"
#include "CrucialController.h"
#include "LogManager.h"
#include "RGBController_Crucial.h"
#include "i2c_smbus.h"
#include "pci_ids.h"
using namespace std::chrono_literals;
/*----------------------------------------------------------------------*\
| This list contains the available SMBus addresses for Crucial RAM |
\*----------------------------------------------------------------------*/
#define CRUCIAL_ADDRESS_COUNT 8
static const unsigned char crucial_addresses[] =
{
0x39,
0x3A,
0x3B,
0x3C,
0x20,
0x21,
0x22,
0x23
};
#define CRUCIAL_CONTROLLER_NAME "Crucial DRAM"
std::string concatHexArray(const unsigned char array[], int count, const char split_char[])
{
std::string addresses = "";
for(int i = 0; i < count; i++)
{
char buffer[6];
snprintf(buffer, 6, "0x%02X%s", array[i], (i < count-1)? split_char: "");
addresses += buffer;
}
return addresses;
}
#define TESTING_ADDRESSES concatHexArray(crucial_addresses, CRUCIAL_ADDRESS_COUNT, "|").c_str()
/******************************************************************************************\
* *
* CrucialRegisterRead *
* *
* A standalone version of the AuraSMBusController::AuraRegisterRead function for *
* access to Aura devices without instancing the AuraSMBusController class or reading *
* the config table from the device. *
* *
\******************************************************************************************/
unsigned char CrucialRegisterRead(i2c_smbus_interface* bus, crucial_dev_id dev, crucial_register reg)
{
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Read Aura value
return(bus->i2c_smbus_read_byte_data(dev, 0x81));
}
/******************************************************************************************\
* *
* TestForCrucialController *
* *
* Tests the given address to see if an Crucial controller exists there. First does a*
* byte read to test for a response, and if so does a simple read at 0xA0 to test *
* for incrementing values 0...F which was observed at this location during data dump *
* *
\******************************************************************************************/
bool TestForCrucialController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_read_byte(address);
if(res >= 0)
{
pass = true;
LOG_DEBUG("[%s] Detected an I2C device at address %02X", CRUCIAL_CONTROLLER_NAME, address);
for(int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if(res != (i - 0xA0))
{
LOG_VERBOSE("[%s] Detection failed testing register %02X. Expected %02X, got %02X.", CRUCIAL_CONTROLLER_NAME, i, (i - 0xA0), res);
pass = false;
}
}
if(pass)
{
LOG_DEBUG("[%s] Checking for Micron string", CRUCIAL_CONTROLLER_NAME);
char buf[16];
for(int i = 0; i < 16; i++)
{
buf[i] = CrucialRegisterRead(bus, address, CRUCIAL_REG_MICRON_CHECK_1 + i);
}
if(strcmp(buf, "Micron") == 0)
{
LOG_DEBUG("[%s] Device %02X is a Micron device, continuing", CRUCIAL_CONTROLLER_NAME, address);
}
else
{
for(int i = 0; i < 16; i++)
{
buf[i] = CrucialRegisterRead(bus, address, CRUCIAL_REG_MICRON_CHECK_2 + i);
}
if(strcmp(buf, "Micron") == 0)
{
LOG_DEBUG("[%s] Device %02X is a Micron device, continuing", CRUCIAL_CONTROLLER_NAME, address);
}
else
{
LOG_DEBUG("[%s] Device %02X is not a Micron device, skipping", CRUCIAL_CONTROLLER_NAME, address);
pass = false;
}
}
}
}
return(pass);
} /* TestForCrucialController() */
void CrucialRegisterWrite(i2c_smbus_interface* bus, unsigned char dev, unsigned short reg, unsigned char val)
{
//Write Crucial register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Crucial value
bus->i2c_smbus_write_byte_data(dev, 0x01, val);
}
/******************************************************************************************\
* *
* DetectCrucialControllers *
* *
* Detect Crucial controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectCrucialControllers(std::vector<i2c_smbus_interface*> &busses)
{
for(unsigned int bus = 0; bus < busses.size(); bus++)
{
int address_list_idx = -1;
IF_DRAM_SMBUS(busses[bus]->pci_vendor, busses[bus]->pci_device)
{
for(unsigned int slot = 0; slot < 4; slot++)
{
int res = busses[bus]->i2c_smbus_read_byte(0x27);
if(res < 0)
{
break;
}
LOG_DEBUG("[%s] Remapping RAM module on 0x27", CRUCIAL_CONTROLLER_NAME);
do
{
address_list_idx++;
if(address_list_idx < CRUCIAL_ADDRESS_COUNT)
{
res = busses[bus]->i2c_smbus_read_byte(crucial_addresses[address_list_idx]);
}
else
{
break;
}
} while(res >= 0);
if(address_list_idx < CRUCIAL_ADDRESS_COUNT)
{
LOG_DEBUG("[%s] Remapping slot %d to address %02X", CRUCIAL_CONTROLLER_NAME, slot, crucial_addresses[address_list_idx]);
CrucialRegisterWrite(busses[bus], 0x27, 0x82EE, slot);
CrucialRegisterWrite(busses[bus], 0x27, 0x82EF, (crucial_addresses[address_list_idx] << 1));
CrucialRegisterWrite(busses[bus], 0x27, 0x82F0, 0xF0);
}
std::this_thread::sleep_for(1ms);
}
LOG_DEBUG("[%s] In bus: %02X:%02X looking for devices at [%s]", CRUCIAL_CONTROLLER_NAME, busses[bus]->pci_vendor, busses[bus]->pci_device, TESTING_ADDRESSES);
// Add Crucial controllers
for(unsigned int address_list_idx = 0; address_list_idx < CRUCIAL_ADDRESS_COUNT; address_list_idx++)
{
LOG_DEBUG("[%s] Testing address %02X to see if there is a device there", CRUCIAL_CONTROLLER_NAME, crucial_addresses[address_list_idx]);
if(TestForCrucialController(busses[bus], crucial_addresses[address_list_idx]))
{
CrucialController* controller = new CrucialController(busses[bus], crucial_addresses[address_list_idx]);
RGBController_Crucial* rgb_controller = new RGBController_Crucial(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
std::this_thread::sleep_for(1ms);
}
}
}
} /* DetectCrucialControllers() */
REGISTER_I2C_DETECTOR("Crucial Ballistix", DetectCrucialControllers);
@@ -0,0 +1,212 @@
/*---------------------------------------------------------*\
| RGBController_Crucial.cpp |
| |
| RGBController for Crucial Ballistix RAM |
| |
| Adam Honse (CalcProgrammer1) 19 Jan 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController_Crucial.h"
/**------------------------------------------------------------------*\
@name Crucial RAM
@category RAM
@type SMBus
@save :x:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectCrucialControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_Crucial::RGBController_Crucial(CrucialController* controller_ptr)
{
controller = controller_ptr;
name = "Crucial DRAM";
vendor = "Crucial";
type = DEVICE_TYPE_DRAM;
description = "Crucial DRAM Device";
version = controller->GetDeviceVersion();
location = controller->GetDeviceLocation();
mode Direct;
Direct.name = "Direct";
Direct.value = 0xFFFF;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Shift;
Shift.name = "Shift";
Shift.value = CRUCIAL_MODE_SHIFT;
Shift.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Shift.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Shift);
mode GradientShift;
GradientShift.name = "Gradient Shift";
GradientShift.value = CRUCIAL_MODE_GRADIENT_SHIFT;
GradientShift.flags = MODE_FLAG_HAS_PER_LED_COLOR;
GradientShift.color_mode = MODE_COLORS_PER_LED;
modes.push_back(GradientShift);
mode Fill;
Fill.name = "Fill";
Fill.value = CRUCIAL_MODE_FILL;
Fill.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Fill.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Fill);
mode Stack;
Stack.name = "Stack";
Stack.value = CRUCIAL_MODE_STACK;
Stack.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Stack.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Stack);
mode DoubleStack;
DoubleStack.name = "Double Stack";
DoubleStack.value = CRUCIAL_MODE_DOUBLE_STACK;
DoubleStack.flags = MODE_FLAG_HAS_PER_LED_COLOR;
DoubleStack.color_mode = MODE_COLORS_PER_LED;
modes.push_back(DoubleStack);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = CRUCIAL_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Breathing.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Breathing);
mode MotionPoint;
MotionPoint.name = "Motion Point";
MotionPoint.value = CRUCIAL_MODE_MOTION_POINT;
MotionPoint.flags = MODE_FLAG_HAS_PER_LED_COLOR;
MotionPoint.color_mode = MODE_COLORS_PER_LED;
modes.push_back(MotionPoint);
mode InsideOut;
InsideOut.name = "Inside Out";
InsideOut.value = CRUCIAL_MODE_INSIDE_OUT;
InsideOut.flags = MODE_FLAG_HAS_PER_LED_COLOR;
InsideOut.color_mode = MODE_COLORS_PER_LED;
modes.push_back(InsideOut);
mode ColorStep;
ColorStep.name = "Color Step";
ColorStep.value = CRUCIAL_MODE_COLOR_STEP;
ColorStep.flags = MODE_FLAG_HAS_PER_LED_COLOR;
ColorStep.color_mode = MODE_COLORS_PER_LED;
modes.push_back(ColorStep);
mode WaterWave;
WaterWave.name = "Water Wave (Color Blending)";
WaterWave.value = CRUCIAL_MODE_WATER_WAVE;
WaterWave.flags = MODE_FLAG_HAS_PER_LED_COLOR;
WaterWave.color_mode = MODE_COLORS_PER_LED;
modes.push_back(WaterWave);
mode Flashing;
Flashing.name = "Flashing";
Flashing.value = CRUCIAL_MODE_FLASHING;
Flashing.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Flashing.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Flashing);
mode Static;
Static.name = "Static";
Static.value = CRUCIAL_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Static.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Static);
SetupZones();
}
RGBController_Crucial::~RGBController_Crucial()
{
delete controller;
}
void RGBController_Crucial::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zone |
\*---------------------------------------------------------*/
zone new_zone;
new_zone.name = "DRAM";
new_zone.type = ZONE_TYPE_LINEAR;
new_zone.leds_min = 8;
new_zone.leds_max = 8;
new_zone.leds_count = 8;
new_zone.matrix_map = NULL;
zones.push_back(new_zone);
/*---------------------------------------------------------*\
| Set up LEDs |
\*---------------------------------------------------------*/
for(std::size_t led_idx = 0; led_idx < zones[0].leds_count; led_idx++)
{
led new_led;
new_led.name = "DRAM LED ";
new_led.name.append(std::to_string(led_idx));
leds.push_back(new_led);
}
SetupColors();
}
void RGBController_Crucial::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_Crucial::DeviceUpdateLEDs()
{
if(modes[active_mode].value == 0xFFFF)
{
controller->SetAllColorsDirect(&colors[0]);
}
else
{
controller->SetAllColorsEffect(&colors[0]);
if(modes[active_mode].value == CRUCIAL_MODE_STATIC)
{
controller->SetMode(modes[active_mode].value);
}
}
}
void RGBController_Crucial::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_Crucial::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_Crucial::DeviceUpdateMode()
{
if(modes[active_mode].value == 0xFFFF)
{
controller->SetMode(CRUCIAL_MODE_STATIC);
controller->SetAllColorsEffect(&colors[0]);
return;
}
if(modes[active_mode].color_mode == MODE_COLORS_PER_LED)
{
controller->SetAllColorsEffect(&colors[0]);
}
controller->SetMode(modes[active_mode].value);
}
@@ -0,0 +1,35 @@
/*---------------------------------------------------------*\
| RGBController_Crucial.h |
| |
| RGBController for Crucial Ballistix RAM |
| |
| Adam Honse (CalcProgrammer1) 19 Jan 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CrucialController.h"
class RGBController_Crucial : public RGBController
{
public:
RGBController_Crucial(CrucialController* controller_ptr);
~RGBController_Crucial();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
CrucialController* controller;
};