Compare commits

..
Author SHA1 Message Date
Adam Honse eac739fdb4 Get libusb-1.0 building on Windows, pull in libusb-1.0.22 dependency. You need Zadig to set up individual devices for use 2019-12-25 02:26:18 -06:00
Adam Honse 5ae3de993d Add capability to set ring color 2019-12-25 01:21:18 -06:00
Adam Honse e79c97c4d0 RGBController interface for Wraith Prism now can change static colors for logo and fan 2019-12-25 01:08:28 -06:00
Adam Honse 45c7bc8008 Add an RGBController interface for AMD Wraith Prism 2019-12-25 00:54:45 -06:00
Adam Honse 7de0b2549b Add function to retrieve firmware version string on Wraith Prism 2019-12-24 19:26:40 -06:00
Adam Honse 39b52326b6 Add function to set all ring LEDs to a given effect channel 2019-12-24 15:04:30 -06:00
Adam Honse b35c900fae Add function to get effect string for a channel 2019-12-24 14:56:49 -06:00
Adam Honse 7cea74e466 AMD Wraith Prism controller file with some statically coded packets 2019-12-24 01:13:25 -06:00
Adam Honse 5f3e43e7b8 Only build Aorus GPU files on Windows 2019-12-23 17:37:31 -06:00
Adam Honse a84407b609 Bring PolychromeController into the build 2019-12-23 17:12:18 -06:00
Adam Honse 000511deff Update Aorus GPU files 2019-12-23 17:08:44 -06:00
Adam Honse fe37c261a2 Move Set Color buttons up for better alignment 2019-12-23 16:51:10 -06:00
Adam Honse cbdbb71d79 Add Set All Devices button 2019-12-23 16:17:00 -06:00
Adam Honse 5f786e649a Fix Hue+ initialization on Windows 2019-12-23 15:37:15 -06:00
Adam Honse f76bf34d8d HyperX zones per slot, set Hue Plus zones as linear type 2019-12-23 12:35:42 -06:00
Adam Honse e799574730 Add additional information to OpenRazer, set SPD to page 1 for proper HyperX detection 2019-12-23 02:52:09 -06:00
Adam Honse 1a5b12c7a0 OAdd strip autodetection to NZXT Hue+ interface, group zones into channels 2019-12-23 02:21:20 -06:00
Adam Honse d2acc75ba8 Report correct device types on OpenRazer interface 2019-12-22 23:11:11 -06:00
Adam Honse 74bcfbd940 Make Sleep function static on linux to avoid compile errors 2019-12-22 22:44:28 -06:00
Adam Honse 1db45f2cf2 Update slot addresses for HyperX Predator RGB and set brightness on effect modes 2019-12-22 21:27:27 -06:00
Adam Honse 6e467fe8cd Initial work on direct mode for HyperX Predator RGB 2019-12-22 02:18:20 -06:00
Adam Honse 441c462e59 Add SMBus/I2C dumping tool to System Information page 2019-12-22 00:02:08 -06:00
Adam Honse 89b4716012 Fix Aura DRAM detection and move firmware name to Version field 2019-12-20 14:28:42 -06:00
Adam Honse e51e9a71a0 Add name and serial number information fields to UI 2019-12-20 14:03:37 -06:00
Adam Honse 02273a3601 Exclude SMBus addresses from detection matching upstream i2c-tools code 2019-12-20 13:07:21 -06:00
Adam Honse e0018b23aa Use monospace font in system information box 2019-12-20 12:45:29 -06:00
Adam Honse b06f384350 System information page with i2c detect 2019-12-20 12:22:14 -06:00
Adam Honse 7dddb9d111 Start work on Information page and add information fields to RGBController API 2019-12-20 00:54:37 -06:00
Adam Honse 0d38154134 Fix DRAM type detection for some Aura based RAM Modules 2019-12-18 23:08:48 -06:00
Adam Honse 7dd84c7ac8 First round of user interface rework changes 2019-12-18 20:33:55 -06:00
Adam Honse ffd0088378 Rename dialog components from OpenAuraSDK to OpenRGB 2019-12-17 20:23:36 -06:00
Adam Honse f0c486c30d Rename OpenAuraSDK to OpenRGB for kernel patch and project file 2019-12-17 20:11:43 -06:00
Adam Honse 010ab1182d Move OpenAuraSDK_Win.pro to OpenAuraSDK.pro to unify the two project files for good 2019-12-17 19:57:06 -06:00
Adam Honse 7e64ca1f83 Merge QT project files in OpenAuraSDK_Win.pro 2019-12-17 19:51:34 -06:00
Adam Honse 2fcff92523 Add icon to Windows Qt project 2019-12-17 19:00:07 -06:00
Adam Honse 8beeb5f7b2 Get Qt project building on Windows, remove Visual Studio files 2019-12-17 18:57:53 -06:00
Adam Honse 7d2b5f285f More work on ASR LED/Polychrome support 2019-12-15 02:12:12 -06:00
Adam Honse b8eb4e9bcb Initial work on ASRock Polychrome/ASR LED interface. Does not function yet. 2019-12-14 11:15:55 -06:00
Adam Honse 733b904ec4 Undo commenting out of custom mode set function 2019-12-11 21:43:51 -06:00
Adam Honse 59a3b41480 Initial support for Gigabyte Aorus RGB Fusion motherboards 2019-12-11 20:19:21 -06:00
Adam Honse 28b41451f8 Fix typo in Aura header 2019-12-11 19:38:28 -06:00
Adam Honse 126c9295ac Add OpenRGB icon 2019-10-26 22:47:21 -05:00
Steven Franzen 0e4a162667 Change search path for i2c devices on linux
Looking for devices by bus instead of class should fix issues where the
class is named differently, e.g. i2c-dev instead of i2c-adapter.
2019-10-26 21:46:10 -05:00
Adam Honse 15fd537fa8 Add support for RGB E1.31 Streaming ACN multicast devices using libe131. Linux only for now. 2019-10-26 21:34:25 -05:00
Adam Honse 557c9df9a0 Rewrite OpenRazer support to use static constant device mapping table instead of big switch/case. Add support for some extra Razer devices. Use "ledstrip.txt" for LED strip settings 2019-10-26 18:21:02 -05:00
Adam Honse 68b0dc9e2e Fix LED Strips on Windows 2019-09-03 20:29:32 -05:00
Adam Honse c8a1363b35 Use generic interfaces for Razer Chroma SDK, get mouse and Chroma HDK working 2019-09-03 20:13:54 -05:00
Adam Honse 0a61e38ee1 Start writing an RGBController interface for the Razer Chroma SDK on Windows 2019-09-03 00:38:56 -05:00
Adam Honse b5f687c402 Get project building on Windows again 2019-09-02 17:48:34 -05:00
Adam Honse 50875fc698 Add 2D matrix support to OpenRazer RGB interface, add support for Chroma HDK 2019-09-02 17:16:49 -05:00
Adam Honse 802d444d9d Add net port files 2019-09-01 15:43:42 -05:00
Adam Honse a8c83e5688 Add interface for NZXT Hue+ based on KeyboardVisualizer code and add support for UDP LED strips. Clean up LEDStrip code. 2019-08-28 12:25:49 -05:00
Adam Honse 63bf13faac Add color buffer vector to all RGBController drivers, so that color patterns may be filled in by the application and updated all at once via an UpdateLEDs function 2019-08-23 01:31:39 -05:00
Adam Honse 5bc80cce96 Get reorganized code building on Windows 2019-08-22 21:07:13 -05:00
Adam Honse 3c34a659a0 Rename nct6793d to nct6775 to align with nct6775 naming convention from hwmon-based Linux driver 2019-08-22 19:03:59 -05:00
Adam Honse efed3faaf4 Add kernel patch for SMBus driver fixes to repository 2019-08-22 18:50:36 -05:00
Adam Honse 155ad165b1 Reorganization! Move all controllers into their own folders, move all RGBController wrappers into one folder, move i2c_smbus and serial_port dependencies into folders, and move main application/UI stuff into folders. Should help lead into creating a proper library 2019-08-22 18:43:17 -05:00
Adam Honse ef79de6c7c Fix LED strip length in RGBController_LEDStrip 2019-08-22 18:19:10 -05:00
Adam Honse 854d7d0ec5 Fix colors on LED strip 2019-08-22 18:13:41 -05:00
Adam Honse 727516e712 Initial LED strip settings.txt configuration (similar to KeyboardVisualizer) 2019-08-22 18:02:48 -05:00
Adam Honse 9126ded32e Move detection functions into their own files 2019-08-18 01:24:11 -05:00
Adam Honse d5a32eb743 Add more OpenRazer devices 2019-08-18 00:47:09 -05:00
Adam Honse 1bfeb59d6a Get OpenRazer autodetection working, add support for more devices 2019-08-18 00:24:44 -05:00
Adam Honse fd7d956913 Update detection for Corsair Vengeance Pro RGB 2019-08-16 18:46:12 -05:00
Adam Honse 50942d11b1 Update README 2019-08-16 18:30:25 -05:00
Network Silence aebffd9e48 Fixed readme for the project 2019-08-16 18:30:21 -05:00
Adam Honse ae77e44f73 Update README.md 2019-08-16 18:30:17 -05:00
Adam Honse 675eb40b94 Rudimentary detection for different types of RGB RAM, based on apparently static data from i2cdump 2019-08-15 23:41:56 -05:00
Adam Honse 7f09b14f50 Fix -0104 controller zone detection 2019-08-15 12:02:25 -05:00
Adam Honse b17d87a15b Add compile flags around Windows-specific code 2019-08-14 20:23:50 -05:00
Adam Honse 9e963e5cc7 Update Linux project file 2019-08-14 19:42:57 -05:00
Adam Honse fa8f06f273 Initial Corsair Vengeance Pro RGB support 2019-08-13 16:03:25 -05:00
Adam Honse 9c1d0e1a79 Add support for AUMA0-E6K5-0104 2019-08-07 12:19:45 -05:00
Adam Honse 60b9fd08bb Initial work on interface for HyperX Predator RGB, color and mode setting works 2019-06-30 11:57:08 -05:00
Adam Honse 9c5f592618 Add LEDStrip interface from KeyboardVisualizer 2019-06-20 22:43:26 -05:00
Adam Honse 8f96f9535d Add quick colors to Linux GUI 2019-06-20 12:27:01 -05:00
Adam Honse d94d6eb569 Fix Linux build 2019-06-20 00:03:55 -05:00
Adam Honse 06f21865c6 Move main function to its own file, add checks to prevent UI updates if no devices were detected 2019-06-19 12:31:58 -05:00
Adam Honse 18bf0ce013 Update Linux GUI to match changes to Windows one 2019-06-19 00:07:23 -05:00
Adam Honse af0bfde610 Set all devices at once with Set All button, add common function to set device to custom mode 2019-06-18 12:26:06 -05:00
Adam Honse ab4a07244a Add quick and dirty RGBController interface for Gigabyte Aorus 1080Ti Xtreme using GvDisplay.dll hack 2019-06-17 20:52:37 -05:00
Adam Honse 08532dc56c Add Razer DeathStalker Chroma 2019-06-16 15:16:22 -05:00
Adam Honse c69d8c4680 Initial support for DeathAdder Chroma 2019-06-16 14:24:02 -05:00
Adam Honse e9cf421719 Start writing a generic RGB wrapper for OpenRazer 2019-06-15 23:28:20 -05:00
Adam Honse 4887e9a11e Fix set LED button on Windows, rearrange Windows GUI to match Linux GUI 2019-06-15 21:34:43 -05:00
Adam Honse f71f325a97 Update Linux UI for generic RGB interface branch 2019-06-15 17:59:35 -05:00
Adam Honse 7ba607be8a Minor fixes - populate Mode box correctly on initialization and reorder operations for setting Aura mode to improve reliability 2019-06-15 12:38:57 -05:00
Adam Honse 4714aec6dd Start work on configuration table parsing for Aura devices. Process all channels with same type into their own zones 2019-06-15 12:16:21 -05:00
Adam Honse 7554e366f4 Add functions for setting single LED and all LEDs in a zone to a color, add zone dropdown to GUI 2019-06-14 23:31:23 -05:00
Adam Honse d60936b2e5 Use 32-bit RGBColor type (COLORREF compatible) instead of discrete red, green, and blue channels in generic RGB interface 2019-06-14 12:24:07 -05:00
Adam Honse 90b57e1846 Split RGBController classes into their own files 2019-06-13 23:24:05 -05:00
Adam Honse 8c3acbe889 Mode selection and Set All Colors working using generic RGB interface for Aura and Corsair Vengeance RGB 2019-06-13 23:02:27 -05:00
Adam Honse f5d7f2e537 Generic RGB development 2019-06-13 20:23:22 -05:00
Stavros Avramidis 234b006bee Add time-out on query enumeration
Signed-off-by: Stavros Avramidis <[email protected]>
2019-06-02 12:35:31 -05:00
Adam Honse 9c4bbec686 Add 0x4F and 0x66 to detected Aura addresses 2019-05-29 12:23:58 -05:00
Adam Honse 25d85a1db0 Re-add Super IO ID mask 2019-05-27 14:58:51 -05:00
Adam Honse dde0292719 Add a few more Nuvoton Super IO chips to the supported list including NCT6796D, clean up the Nuvoton detection code 2019-05-27 11:44:51 -05:00
Adam Honse 9d1745c0d0 Get SMBus base address from NCT6793D configuration registers 2019-05-27 04:14:22 -05:00
Adam Honse 559f1e9bcc Add preliminary probe functionality for NCT6793D, remove SMBus block read from NCT6793D SMBus driver as I haven't written this functionality yet 2019-05-23 00:05:28 -05:00
Adam Honse 3c95f9fe21 Fix block writes on Nuvoton NCT6793D SMBus driver 2019-05-22 00:01:58 -05:00
Adam Honse c2e384ab39 Add README.md 2019-05-21 03:55:04 +00:00
Adam Honse fe7d7df29b Initial SMBus driver for Nuvoton NCT6793D Super IO chip used on Prime Z270-A (and other Intel boards) 2019-05-20 22:21:10 -05:00
Thomas Berger 73d91b9494 Add support for 970 PRO GAMING/AURA
the Aura controller is located on 0x40 of the SMBus for
this board.
2019-04-23 20:30:02 -05:00
Adam Honse a2cdfc5aec Add Dump Aura button to Linux Qt dialog 2019-03-13 22:08:23 -05:00
Adam Honse 484e4e9770 Move Qt project file up to root directory 2019-03-13 19:49:36 -05:00
Adam Honse c45001b810 Initial files for Corsair Vengeance RGB RAM support 2019-03-09 00:18:35 -06:00
Adam Honse e3dcb9e87d Add button to dump Aura device memory 2019-03-06 21:48:48 -06:00
Adam Honse 75cf8b6aa8 Add support for AUMA0-E6K5-0105 2019-03-06 13:52:21 -06:00
Adam Honse 35ec4f5e90 cstring not string, oops 2019-03-06 12:47:16 -06:00
Adam Honse ab03edb6ce Add AUMA0-E6K5-0106 to device list and use v2 registers 2019-03-06 12:30:56 -06:00
Adam Honse 022871c5c5 Allow alternative color register locations for newer Aura chips. Select registers based on device string 2019-03-05 22:07:13 -06:00
Adam Honse dc3009bcaf Add some sanity checking to Aura device detection. Aura devices appear to read incrementing values at 0xA0 if no register written 2019-02-25 22:10:38 -06:00
Adam Honse 0941f25a8d Check for "INTEL" manufacturer string, per issue comment 10#note_144867740 by @F-Lehmann 2019-02-25 21:19:33 -06:00
Adam Honse 20fa1f4b1a vector not used on Linux, move to Windows ifdef block 2019-02-20 23:16:22 -06:00
Adam Honse f1be1c9a8f Add Qt GUI, builds and runs on Linux 2019-02-20 20:19:08 -06:00
Adam Honse b782a63ed5 Set direct mode when setting colors for all devices 2019-02-19 23:03:50 -06:00
Adam Honse 31446d18b4 More GUI improvements, GUI is mostly functional now 2019-02-19 22:57:12 -06:00
Adam Honse 3a249382fb Start work on Visual Studio GUI 2019-02-18 20:45:55 -06:00
Adam Honse 1e650d8f85 Move Aura device detection to its own function 2019-02-17 22:52:46 -06:00
151 changed files with 18571 additions and 569 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "dependencies/libe131"]
path = dependencies/libe131
url = https://github.com/hhromic/libe131
@@ -0,0 +1,340 @@
/*-----------------------------------------*\
| AMDWraithPrismController.h |
| |
| Driver for AMD Wraith Prism RGB lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 12/6/2019 |
\*-----------------------------------------*/
#include "AMDWraithPrismController.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
AMDWraithPrismController::AMDWraithPrismController(libusb_device_handle* dev_handle)
{
dev = dev_handle;
strcpy(device_name, "AMD Wraith Prism");
SendEnableCommand();
SetRingEffectChannel(0x00);
}
AMDWraithPrismController::~AMDWraithPrismController()
{
}
char* AMDWraithPrismController::GetDeviceName()
{
return device_name;
}
std::string AMDWraithPrismController::GetEffectChannelString(unsigned char channel)
{
std::string ret_string = "";
unsigned char usb_buf[] =
{
0x40, 0x21, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
int actual;
usb_buf[0x02] = channel;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
ret_string.append((char *)&usb_buf[0x08]);
return(ret_string);
}
std::string AMDWraithPrismController::GetFirmwareVersionString()
{
std::string ret_string = "";
unsigned char usb_buf[] =
{
0x12, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
int actual;
unsigned char fw_buf[16] = {0x00};
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
for(int char_idx = 0; char_idx < 16; char_idx+=2)
{
if(usb_buf[char_idx + 0x08] != 0)
{
fw_buf[char_idx / 2] = usb_buf[char_idx + 0x08];
}
else
{
break;
}
}
ret_string.append((char *)fw_buf);
return(ret_string);
}
void AMDWraithPrismController::SetFanColor(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[] =
{
0x51, 0x2C, 0x01, 0x00,
0x06, 0xFF, 0x00, 0x01,
0xFF, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
int actual;
usb_buf[0x0A] = red;
usb_buf[0x0B] = green;
usb_buf[0x0C] = blue;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
void AMDWraithPrismController::SetLogoColor(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[] =
{
0x51, 0x2C, 0x01, 0x00,
0x05, 0xFF, 0x00, 0x01,
0xFF, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
int actual;
usb_buf[0x0A] = red;
usb_buf[0x0B] = green;
usb_buf[0x0C] = blue;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
void AMDWraithPrismController::SetRingColor(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[] =
{
0x51, 0x2C, 0x01, 0x00,
0x00, 0xFF, 0x00, 0xFF,
0xFF, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
int actual;
usb_buf[0x0A] = red;
usb_buf[0x0B] = green;
usb_buf[0x0C] = blue;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
void AMDWraithPrismController::SetRingEffectChannel(unsigned char channel)
{
unsigned char usb_buf[] =
{
0x51, 0xA0, 0x01, 0x00,
0x00, 0x03, 0x00, 0x00,
0x05, 0x06, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07,
0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
int actual;
for(int led = 0x0A; led <= 0x18; led++)
{
usb_buf[led] = channel;
}
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
void AMDWraithPrismController::SendEnableCommand()
{
unsigned char usb_buf[] =
{
0x41, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
int actual;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
void AMDWraithPrismController::SendRemapCommand()
{
unsigned char usb_buf[] =
{
0x51, 0xA0, 0x01, 0x00,
0x00, 0x03, 0x00, 0x00,
0x05, 0x06, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07,
0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
int actual;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
void AMDWraithPrismController::SendEffectCommand()
{
unsigned char usb_buf[] =
{
0x51, 0x2C, 0x01, 0x00,
0x05, 0xFF, 0x00, 0x01,
0xFF, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
int actual;
libusb_interrupt_transfer(dev, 0x04, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x83, usb_buf, 64, &actual, 0);
}
@@ -0,0 +1,39 @@
/*-----------------------------------------*\
| AMDWraithPrismController.h |
| |
| Definitions and types for AMD Wraith |
| Prism lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/6/2019 |
\*-----------------------------------------*/
#include <string>
#include <libusb-1.0/libusb.h>
#pragma once
class AMDWraithPrismController
{
public:
AMDWraithPrismController(libusb_device_handle* dev_handle);
~AMDWraithPrismController();
char* GetDeviceName();
std::string GetEffectChannelString(unsigned char channel);
std::string GetFirmwareVersionString();
void SetRingEffectChannel(unsigned char channel);
void SetFanColor(unsigned char red, unsigned char green, unsigned char blue);
void SetLogoColor(unsigned char red, unsigned char green, unsigned char blue);
void SetRingColor(unsigned char red, unsigned char green, unsigned char blue);
void SendEnableCommand();
void SendRemapCommand();
void SendEffectCommand();
private:
char device_name[32];
libusb_device_handle* dev;
};
@@ -0,0 +1,37 @@
#include "AMDWraithPrismController.h"
#include "RGBController.h"
#include "RGBController_AMDWraithPrism.h"
#include <vector>
#include <libusb-1.0/libusb.h>
#define AMD_WRAITH_PRISM_VID 0x2516
#define AMD_WRAITH_PRISM_PID 0x0051
/******************************************************************************************\
* *
* DetectAMDWraithPrismControllers *
* *
* Tests the USB address to see if an AMD Wraith Prism controller exists there. *
* *
\******************************************************************************************/
void DetectAMDWraithPrismControllers(std::vector<RGBController*>& rgb_controllers)
{
libusb_context * ctx;
libusb_init(&ctx);
//Look for AMD Wraith Prism
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, AMD_WRAITH_PRISM_VID, AMD_WRAITH_PRISM_PID);
if( dev )
{
libusb_detach_kernel_driver(dev, 1);
libusb_claim_interface(dev, 1);
AMDWraithPrismController* controller = new AMDWraithPrismController(dev);
RGBController_AMDWraithPrism* rgb_controller = new RGBController_AMDWraithPrism(controller);
rgb_controllers.push_back(rgb_controller);
}
}
@@ -0,0 +1,258 @@
/*-----------------------------------------*\
| AuraController.cpp |
| |
| Driver for ASUS Aura RGB lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 8/19/2018 |
\*-----------------------------------------*/
#include "AuraController.h"
#include <cstring>
AuraController::AuraController(i2c_smbus_interface* bus, aura_dev_id dev)
{
this->bus = bus;
this->dev = dev;
AuraUpdateDeviceName();
// Read the device configuration table
for (int i = 0; i < 64; i++)
{
config_table[i] = AuraRegisterRead(AURA_REG_CONFIG_TABLE + i);
}
// Read LED count from configuration table
led_count = config_table[AURA_CONFIG_LED_COUNT];
// LED-0116 - First generation motherboard controller
if (strcmp(device_name, "LED-0116") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT;
effect_reg = AURA_REG_COLORS_EFFECT;
channel_cfg = AURA_CONFIG_CHANNEL_V1;
}
// DIMM_LED-0102 - First generation DRAM controller (Trident Z RGB)
else if (strcmp(device_name, "DIMM_LED-0102") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT;
effect_reg = AURA_REG_COLORS_EFFECT;
channel_cfg = AURA_CONFIG_CHANNEL_V1;
}
// AUDA0-E6K5-0101 - Second generation DRAM controller (Geil Super Luce)
else if (strcmp(device_name, "AUDA0-E6K5-0101") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// AUMA0-E6K5-0106 - Second generation motherboard controller
else if (strcmp(device_name, "AUMA0-E6K5-0106") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// AUMA0-E6K5-0105 - Second generation motherboard controller
else if (strcmp(device_name, "AUMA0-E6K5-0105") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// AUMA0-E6K5-0104 - Second generation motherboard controller
else if (strcmp(device_name, "AUMA0-E6K5-0104") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// Assume first generation controller if string does not match
else
{
direct_reg = AURA_REG_COLORS_DIRECT;
effect_reg = AURA_REG_COLORS_EFFECT;
channel_cfg = AURA_CONFIG_CHANNEL_V1;
}
}
AuraController::~AuraController()
{
}
std::string AuraController::GetDeviceName()
{
return(device_name);
}
std::string AuraController::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);
}
unsigned char AuraController::GetChannel(unsigned int led)
{
return(config_table[channel_cfg + led]);
}
const char * AuraController::GetChannelName(unsigned int led)
{
switch (config_table[channel_cfg + led])
{
case (unsigned char)AURA_LED_CHANNEL_AUDIO:
return(aura_channels[0]);
break;
case (unsigned char)AURA_LED_CHANNEL_BACKPLATE:
return(aura_channels[1]);
break;
case (unsigned char)AURA_LED_CHANNEL_BACK_IO:
return(aura_channels[2]);
break;
case (unsigned char)AURA_LED_CHANNEL_CENTER:
return(aura_channels[3]);
break;
case (unsigned char)AURA_LED_CHANNEL_CENTER_START:
return(aura_channels[4]);
break;
case (unsigned char)AURA_LED_CHANNEL_DRAM:
return(aura_channels[5]);
break;
case (unsigned char)AURA_LED_CHANNEL_PCIE:
return(aura_channels[6]);
break;
case (unsigned char)AURA_LED_CHANNEL_RGB_HEADER:
return(aura_channels[7]);
break;
case (unsigned char)AURA_LED_CHANNEL_RGB_HEADER_2:
return(aura_channels[8]);
break;
case (unsigned char)AURA_LED_CHANNEL_RGB_HEADER_3:
return(aura_channels[9]);
break;
default:
return(aura_channels[10]);
break;
}
}
unsigned int AuraController::GetLEDCount()
{
return(led_count);
}
void AuraController::SetAllColorsDirect(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char* colors = new unsigned char[led_count * 3];
for (int i = 0; i < (led_count * 3); i += 3)
{
colors[i + 0] = red;
colors[i + 1] = blue;
colors[i + 2] = green;
}
AuraRegisterWriteBlock(direct_reg, colors, led_count * 3);
delete colors;
}
void AuraController::SetAllColorsEffect(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char* colors = new unsigned char[led_count * 3];
for (int i = 0; i < (led_count * 3); i += 3)
{
colors[i + 0] = red;
colors[i + 1] = blue;
colors[i + 2] = green;
}
AuraRegisterWriteBlock(effect_reg, colors, led_count * 3);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
delete colors;
}
void AuraController::SetDirect(unsigned char direct)
{
AuraRegisterWrite(AURA_REG_DIRECT, direct);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
void AuraController::SetLEDColorDirect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char colors[3] = { red, blue, green };
AuraRegisterWriteBlock(direct_reg + ( 3 * led ), colors, 3);
}
void AuraController::SetLEDColorEffect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char colors[3] = { red, blue, green };
AuraRegisterWriteBlock(effect_reg + (3 * led), colors, 3);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
void AuraController::SetMode(unsigned char mode)
{
AuraRegisterWrite(AURA_REG_MODE, mode);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
void AuraController::AuraUpdateDeviceName()
{
for (int i = 0; i < 16; i++)
{
device_name[i] = AuraRegisterRead(AURA_REG_DEVICE_NAME + i);
}
}
unsigned char AuraController::AuraRegisterRead(aura_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));
}
void AuraController::AuraRegisterWrite(aura_register reg, unsigned char val)
{
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura value
bus->i2c_smbus_write_byte_data(dev, 0x01, val);
}
void AuraController::AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz)
{
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura block data
bus->i2c_smbus_write_block_data(dev, 0x03, sz, data);
}
+125
View File
@@ -0,0 +1,125 @@
/*-----------------------------------------*\
| AuraController.h |
| |
| Definitions and types for ASUS Aura RGB |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 8/19/2018 |
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
typedef unsigned char aura_dev_id;
typedef unsigned short aura_register;
#define AURA_APPLY_VAL 0x01 /* Value for Apply Changes Register */
enum
{
AURA_REG_DEVICE_NAME = 0x1000, /* Device String 16 bytes */
AURA_REG_CONFIG_TABLE = 0x1C00, /* Start of LED configuration bytes */
AURA_REG_COLORS_DIRECT = 0x8000, /* Colors for Direct Mode 15 bytes */
AURA_REG_COLORS_EFFECT = 0x8010, /* Colors for Internal Effects 15 bytes */
AURA_REG_DIRECT = 0x8020, /* "Direct Access" Selection Register */
AURA_REG_MODE = 0x8021, /* AURA Mode Selection Register */
AURA_REG_APPLY = 0x80A0, /* AURA Apply Changes Register */
AURA_REG_SLOT_INDEX = 0x80F8, /* AURA Slot Index Register (RAM only) */
AURA_REG_I2C_ADDRESS = 0x80F9, /* AURA I2C Address Register (RAM only) */
AURA_REG_COLORS_DIRECT_V2 = 0x8100, /* Direct Colors (v2) 30 bytes */
AURA_REG_COLORS_EFFECT_V2 = 0x8160, /* Internal Colors (v2) 30 bytes */
};
enum
{
AURA_MODE_OFF = 0, /* OFF mode */
AURA_MODE_STATIC = 1, /* Static color mode */
AURA_MODE_BREATHING = 2, /* Breathing effect mode */
AURA_MODE_FLASHING = 3, /* Flashing effect mode */
AURA_MODE_SPECTRUM_CYCLE = 4, /* Spectrum Cycle mode */
AURA_MODE_RAINBOW = 5, /* Rainbow effect mode */
AURA_MODE_SPECTRUM_CYCLE_BREATHING = 6, /* Rainbow Breathing effect mode */
AURA_MODE_CHASE_FADE = 7, /* Chase with Fade effect mode */
AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE = 8, /* Chase with Fade, Rainbow effect mode */
AURA_MODE_CHASE = 9, /* Chase effect mode */
AURA_MODE_SPECTRUM_CYCLE_CHASE = 10, /* Chase with Rainbow effect mode */
AURA_MODE_SPECTRUM_CYCLE_WAVE = 11, /* Wave effect mode */
AURA_MODE_CHASE_RAINBOW_PULSE = 12, /* Chase with Rainbow Pulse effect mode*/
AURA_MODE_RANDOM_FLICKER = 13, /* Random flicker effect mode */
AURA_NUMBER_MODES /* Number of Aura modes */
};
enum
{
AURA_LED_CHANNEL_DRAM_2 = 0x05, /* DRAM LED channel */
AURA_LED_CHANNEL_CENTER_START = 0x82, /* Center zone first LED channel */
AURA_LED_CHANNEL_CENTER = 0x83, /* Center zone LED channel */
AURA_LED_CHANNEL_AUDIO = 0x84, /* Audio zone LED channel */
AURA_LED_CHANNEL_BACK_IO = 0x85, /* Back I/O zone LED channel */
AURA_LED_CHANNEL_RGB_HEADER = 0x86, /* RGB Header LED channel */
AURA_LED_CHANNEL_RGB_HEADER_2 = 0x87, /* RGB Header 2 LED channel */
AURA_LED_CHANNEL_BACKPLATE = 0x88, /* Backplate zone LED channel */
AURA_LED_CHANNEL_DRAM = 0x8A, /* DRAM LED channel */
AURA_LED_CHANNEL_PCIE = 0x8B, /* PCIe zone LED channel */
AURA_LED_CHANNEL_RGB_HEADER_3 = 0x91, /* RGB Header 3 LED channel */
};
static const char* aura_channels[] = /* Aura channel strings */
{
"Audio",
"Backplate",
"Back I/O",
"Center",
"Center",
"DRAM",
"PCIe",
"RGB Header",
"RGB Header 2",
"RGB Header",
"Unknown",
};
enum
{
AURA_CONFIG_LED_COUNT = 0x02, /* LED Count configuration offset */
AURA_CONFIG_CHANNEL_V1 = 0x13, /* LED Channel configuration offset */
AURA_CONFIG_CHANNEL_V2 = 0x1B, /* LED Channel V2 configuration offset */
};
class AuraController
{
public:
AuraController(i2c_smbus_interface* bus, aura_dev_id dev);
~AuraController();
std::string GetDeviceName();
std::string GetDeviceLocation();
unsigned char GetChannel(unsigned int led);
const char* GetChannelName(unsigned int led);
unsigned int GetLEDCount();
void SetAllColorsDirect(unsigned char red, unsigned char green, unsigned char blue);
void SetAllColorsEffect(unsigned char red, unsigned char green, unsigned char blue);
void SetDirect(unsigned char direct);
void SetLEDColorDirect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColorEffect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetMode(unsigned char mode);
void AuraUpdateDeviceName();
unsigned char AuraRegisterRead(aura_register reg);
void AuraRegisterWrite(aura_register reg, unsigned char val);
void AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz);
private:
char device_name[16];
unsigned char config_table[64];
unsigned int led_count;
aura_register direct_reg;
aura_register effect_reg;
unsigned char channel_cfg;
i2c_smbus_interface * bus;
aura_dev_id dev;
};
@@ -0,0 +1,125 @@
#include "AuraController.h"
#include "RGBController.h"
#include "RGBController_Aura.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForAuraController *
* *
* Tests the given address to see if an Aura controller exists there. First does a *
* quick write 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 TestForAuraController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
for (int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if (res != (i - 0xA0))
{
pass = false;
}
}
}
return(pass);
} /* TestForAuraController() */
/******************************************************************************************\
* *
* DetectAuraControllers *
* *
* Detect Aura controllers on the enumerated I2C busses. Searches for Aura-enabled *
* RAM at 0x77 and tries to initialize their slot addresses, then searches for them *
* at their correct initialized addresses. Also looks for motherboard controller at *
* address 0x4E. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
AuraController* new_aura;
RGBController_Aura* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Remap Aura-enabled RAM modules on 0x77
for (unsigned int slot = 0; slot < 8; slot++)
{
int res = busses[bus]->i2c_smbus_write_quick(0x77, I2C_SMBUS_WRITE);
if (res < 0)
{
break;
}
AuraController temp_controller(busses[bus], 0x77);
temp_controller.AuraRegisterWrite(AURA_REG_SLOT_INDEX, slot);
temp_controller.AuraRegisterWrite(AURA_REG_I2C_ADDRESS, 0xE0 + (slot << 1));
}
// Add Aura-enabled controllers at their remapped addresses
for (unsigned int slot = 0; slot < 8; slot++)
{
if (TestForAuraController(busses[bus], 0x70 + slot))
{
new_aura = new AuraController(busses[bus], 0x70 + slot);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
}
// Check for Aura controller at 0x40
if (TestForAuraController(busses[bus], 0x40))
{
new_aura = new AuraController(busses[bus], 0x40);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
// Check for Aura controller at 0x4E
if (TestForAuraController(busses[bus], 0x4E))
{
new_aura = new AuraController(busses[bus], 0x4E);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
// Check for Aura controller at 0x4F
if (TestForAuraController(busses[bus], 0x4F))
{
new_aura = new AuraController(busses[bus], 0x4F);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
// Check for Aura controller at 0x66
if (TestForAuraController(busses[bus], 0x66))
{
new_aura = new AuraController(busses[bus], 0x66);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectAuraControllers() */
@@ -0,0 +1,68 @@
/*-----------------------------------------*\
| CorsairController.h |
| |
| Driver for Corsair Vengeance RGB RAM |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 3/8/2019 |
\*-----------------------------------------*/
#include "CorsairController.h"
#include <cstring>
CorsairController::CorsairController(i2c_smbus_interface* bus, corsair_dev_id dev)
{
this->bus = bus;
this->dev = dev;
strcpy(device_name, "Corsair Vengeance RGB");
led_count = 1;
}
CorsairController::~CorsairController()
{
}
std::string CorsairController::GetDeviceName()
{
return(device_name);
}
std::string CorsairController::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);
}
unsigned int CorsairController::GetLEDCount()
{
return(led_count);
}
void CorsairController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_RED_VAL, red);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_GREEN_VAL, green);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_BLUE_VAL, blue);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
}
void CorsairController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_RED_VAL, red);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_GREEN_VAL, green);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_BLUE_VAL, blue);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
}
void CorsairController::SetMode(unsigned char mode)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
}
@@ -0,0 +1,55 @@
/*-----------------------------------------*\
| CorsairController.h |
| |
| Definitions and types for Corsair |
| Vengeance RGB RAM lighting controller |
| |
| Adam Honse (CalcProgrammer1) 3/8/2019 |
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
typedef unsigned char corsair_dev_id;
typedef unsigned char corsair_cmd;
enum
{
CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME = 0xA4, /* Fade Time, 0 for Static */
CORSAIR_VENGEANCE_RGB_CMD_HOLD_TIME = 0xA5, /* Hold Time */
CORSAIR_VENGEANCE_RGB_CMD_MODE = 0xA6, /* Mode Control Value */
CORSAIR_VENGEANCE_RGB_CMD_RED_VAL = 0xB0, /* Red Color Value */
CORSAIR_VENGEANCE_RGB_CMD_GREEN_VAL = 0xB1, /* Green Color Value */
CORSAIR_VENGEANCE_RGB_CMD_BLUE_VAL = 0xB2, /* Blue Color Value */
};
enum
{
CORSAIR_VENGEANCE_RGB_MODE_SINGLE = 0x00, /* Single Color Effect Mode */
CORSAIR_VENGEANCE_RGB_MODE_FADE = 0x01, /* Fade Through Colors */
CORSAIR_VENGEANCE_RGB_MODE_PULSE = 0x02, /* Pulse Through Colors */
CORSAIR_NUMBER_MODES /* Number of Corsair modes */
};
class CorsairController
{
public:
CorsairController(i2c_smbus_interface* bus, corsair_dev_id dev);
~CorsairController();
std::string GetDeviceName();
std::string GetDeviceLocation();
unsigned int GetLEDCount();
void SetMode(unsigned char mode);
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
private:
char device_name[32];
unsigned int led_count;
i2c_smbus_interface * bus;
corsair_dev_id dev;
};
@@ -0,0 +1,109 @@
#include "CorsairController.h"
#include "RGBController.h"
#include "RGBController_Corsair.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForCorsairController *
* *
* Tests the given address to see if a Corsair controller exists there. *
* *
\******************************************************************************************/
bool TestForCorsairController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
for (int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if (res != 0xBA)
{
pass = false;
}
}
}
return(pass);
} /* TestForCorsairController() */
/******************************************************************************************\
* *
* DetectCorsairControllers *
* *
* Detect Corsair controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectCorsairControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
CorsairController* new_corsair;
RGBController_Corsair* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for Corsair controller at 0x58
if (TestForCorsairController(busses[bus], 0x58))
{
new_corsair = new CorsairController(busses[bus], 0x58);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x59
if (TestForCorsairController(busses[bus], 0x59))
{
new_corsair = new CorsairController(busses[bus], 0x59);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5A
if (TestForCorsairController(busses[bus], 0x5A))
{
new_corsair = new CorsairController(busses[bus], 0x5A);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5B
if (TestForCorsairController(busses[bus], 0x5B))
{
new_corsair = new CorsairController(busses[bus], 0x5B);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5C
if (TestForCorsairController(busses[bus], 0x5C))
{
new_corsair = new CorsairController(busses[bus], 0x5C);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5D
if (TestForCorsairController(busses[bus], 0x5D))
{
new_corsair = new CorsairController(busses[bus], 0x5D);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectCorsairControllers() */
@@ -0,0 +1,147 @@
/*-----------------------------------------*\
| CorsairProController.cpp |
| |
| Definitions and types for Corsair |
| Vengeance Pro RGB RAM lighting controller|
| |
| Adam Honse (CalcProgrammer1) 6/30/2019 |
\*-----------------------------------------*/
#include "CorsairProController.h"
#include <cstring>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
CorsairProController::CorsairProController(i2c_smbus_interface* bus, corsair_dev_id dev)
{
this->bus = bus;
this->dev = dev;
strcpy(device_name, "Corsair Vengeance Pro RGB");
led_count = CORSAIR_PRO_LED_COUNT;
for (int i = 0; i < led_count; i++)
{
led_red[i] = 0;
led_green[i] = 0;
led_blue[i] = 0;
}
}
CorsairProController::~CorsairProController()
{
}
std::string CorsairProController::GetDeviceName()
{
return(device_name);
}
std::string CorsairProController::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);
}
unsigned int CorsairProController::GetLEDCount()
{
return(led_count);
}
void CorsairProController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
for (int i = 0; i < led_count; i++)
{
led_red[i] = red;
led_green[i] = green;
led_blue[i] = blue;
}
}
void CorsairProController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
led_red[led] = red;
led_green[led] = green;
led_blue[led] = blue;
}
void CorsairProController::ApplyColors()
{
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x02);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1);
for (int i = 0; i < 10; i++)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, led_red[i]);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, led_green[i]);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, led_blue[i]);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
}
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x02);
}
void CorsairProController::SetEffect(unsigned char mode)
{
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x01);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, mode); //Mode
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_SPEED_MEDIUM); //Speed
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_EFFECT_RANDOM_COLORS); //Custom color
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_DIRECTION_UP); //Direction
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x01);
WaitReady();
}
void CorsairProController::SetCustom()
{
SetEffect(CORSAIR_PRO_MODE_STATIC);
}
bool CorsairProController::WaitReady()
{
int i = 0;
while (bus->i2c_smbus_read_byte_data(dev, 0x41) != 0x00)
{
i++;
Sleep(1);
}
return false;
}
@@ -0,0 +1,90 @@
/*-----------------------------------------*\
| CorsairProController.h |
| |
| Definitions and types for Corsair |
| Vengeance Pro RGB RAM lighting controller|
| |
| Adam Honse (CalcProgrammer1) 6/30/2019 |
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
typedef unsigned char corsair_dev_id;
#define CORSAIR_PRO_LED_COUNT ( 10 )
enum
{
CORSAIR_PRO_REG_COMMAND = 0x20, /* Command write register */
};
enum
{
CORSAIR_PRO_MODE_COLOR_SHIFT = 0x00, /* Color Shift mode */
CORSAIR_PRO_MODE_COLOR_PULSE = 0x01, /* Color Pulse mode */
CORSAIR_PRO_MODE_RAINBOW_WAVE = 0x03, /* Rainbow Wave mode */
CORSAIR_PRO_MODE_COLOR_WAVE = 0x04, /* Color Wave mode */
CORSAIR_PRO_MODE_VISOR = 0x05, /* Visor mode */
CORSAIR_PRO_MODE_RAIN = 0x06, /* Rain mode */
CORSAIR_PRO_MODE_MARQUEE = 0x07, /* Marquee mode */
CORSAIR_PRO_MODE_RAINBOW = 0x08, /* Rainbow mode */
CORSAIR_PRO_MODE_SEQUENTIAL = 0x09, /* Sequential mode */
CORSAIR_PRO_MODE_STATIC = 0x10, /* Static mode */
CORSAIR_PRO_NUMBER_MODES = 10, /* Number of Corsair Pro modes */
};
enum
{
CORSAIR_PRO_SPEED_SLOW = 0x00, /* Slow speed */
CORSAIR_PRO_SPEED_MEDIUM = 0x01, /* Medium speed */
CORSAIR_PRO_SPEED_FAST = 0x02, /* Fast speed */
};
enum
{
CORSAIR_PRO_EFFECT_RANDOM_COLORS = 0x00, /* Random colors */
CORSAIR_PRO_EFFECT_CUSTOM_COLORS = 0x01, /* Custom colors */
};
enum
{
CORSAIR_PRO_DIRECTION_UP = 0x00, /* Up direction */
CORSAIR_PRO_DIRECTION_DOWN = 0x01, /* Down direction */
CORSAIR_PRO_DIRECTION_LEFT = 0x02, /* Left direction */
CORSAIR_PRO_DIRECTION_RIGHT = 0x03, /* Right direction */
CORSAIR_PRO_DIRECTION_VERTICAL = 0x01, /* Vertical direction */
CORSAIR_PRO_DIRECTION_HORIZONTAL = 0x03, /* Horizontal direction */
};
class CorsairProController
{
public:
CorsairProController(i2c_smbus_interface* bus, corsair_dev_id dev);
~CorsairProController();
std::string GetDeviceName();
std::string GetDeviceLocation();
unsigned int GetLEDCount();
void SetEffect(unsigned char mode);
void SetCustom();
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void ApplyColors();
bool WaitReady();
private:
char device_name[32];
unsigned int led_count;
unsigned char led_red[CORSAIR_PRO_LED_COUNT];
unsigned char led_green[CORSAIR_PRO_LED_COUNT];
unsigned char led_blue[CORSAIR_PRO_LED_COUNT];
i2c_smbus_interface* bus;
corsair_dev_id dev;
};
@@ -0,0 +1,127 @@
#include "CorsairProController.h"
#include "RGBController.h"
#include "RGBController_CorsairPro.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForCorsairProController *
* *
* Tests the given address to see if a Corsair Pro controller exists there. *
* *
\******************************************************************************************/
bool TestForCorsairProController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
res = bus->i2c_smbus_read_byte_data(address, 0x24);
if (res != 0x02)
{
pass = false;
}
res = bus->i2c_smbus_read_byte_data(address, 0x25);
if (res != 0x02)
{
pass = false;
}
res = bus->i2c_smbus_read_byte_data(address, 0x43);
if (res != 0x1C)
{
pass = false;
}
res = bus->i2c_smbus_read_byte_data(address, 0x44);
if (res != 0x03)
{
pass = false;
}
}
return(pass);
} /* TestForCorsairProController() */
/******************************************************************************************\
* *
* DetectCorsairProControllers *
* *
* Detect Corsair Pro controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectCorsairProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
CorsairProController* new_corsair_pro;
RGBController_CorsairPro* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for Corsair controller at 0x58
if (TestForCorsairProController(busses[bus], 0x58))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x58);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x59
if (TestForCorsairProController(busses[bus], 0x59))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x59);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5A
if (TestForCorsairProController(busses[bus], 0x5A))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5A);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5B
if (TestForCorsairProController(busses[bus], 0x5B))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5B);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5C
if (TestForCorsairProController(busses[bus], 0x5C))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5C);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5D
if (TestForCorsairProController(busses[bus], 0x5D))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5D);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectCorsairProControllers() */
@@ -0,0 +1,114 @@
/*---------------------------------------------------------*\
| Processing Code for NZXT Hue+ |
| |
| Adam Honse ([email protected]), 12/11/2016 |
\*---------------------------------------------------------*/
#include "HuePlusController.h"
#include <fstream>
#include <iostream>
#include <string>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
HuePlusController::HuePlusController()
{
}
HuePlusController::~HuePlusController()
{
}
void HuePlusController::Initialize(char* port_name)
{
strcpy(led_string, port_name);
serialport = new serial_port(port_name, HUE_PLUS_BAUD);
channel_leds[HUE_PLUS_CHANNEL_1_IDX] = GetStripsOnChannel(HUE_PLUS_CHANNEL_1) * 10;
channel_leds[HUE_PLUS_CHANNEL_2_IDX] = GetStripsOnChannel(HUE_PLUS_CHANNEL_2) * 10;
}
char* HuePlusController::GetLEDString()
{
return(led_string);
}
unsigned int HuePlusController::GetStripsOnChannel(unsigned int channel)
{
unsigned int ret_val = 0;
if (serialport != NULL)
{
unsigned char *serial_buf;
serial_buf = new unsigned char[5];
serial_buf[0] = 0x8D;
serial_buf[1] = channel;
serialport->serial_flush_rx();
serialport->serial_write((char *)serial_buf, 2);
serialport->serial_flush_tx();
Sleep(50);
int bytes_read = serialport->serial_read((char *)serial_buf, 5);
if(bytes_read == 5)
{
ret_val = serial_buf[4];
}
delete[] serial_buf;
}
return(ret_val);
}
void HuePlusController::SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors)
{
if (serialport != NULL)
{
unsigned char *serial_buf;
serial_buf = new unsigned char[HUE_PLUS_PACKET_SIZE];
serial_buf[0] = 0x4B;
serial_buf[1] = channel;
serial_buf[2] = HUE_PLUS_MODE_FIXED;
serial_buf[3] = 0x00;
serial_buf[4] = 0x00;
for (int i = 5; i < HUE_PLUS_PACKET_SIZE; i++)
{
serial_buf[i] = 0x00;
}
for (int idx = 0; idx < (colors.size() * 3); idx += 3)
{
int pixel_idx = idx / 3;
RGBColor color = colors[pixel_idx];
serial_buf[idx + 5] = RGBGetGValue(color);
serial_buf[idx + 6] = RGBGetRValue(color);
serial_buf[idx + 7] = RGBGetBValue(color);
}
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
serialport->serial_flush_tx();
delete[] serial_buf;
}
}
@@ -0,0 +1,69 @@
/*---------------------------------------------------------*\
| Definitions for NZXT Hue+ |
| |
| Adam Honse ([email protected]), 12/11/2016 |
\*---------------------------------------------------------*/
#ifndef LED_STRIP_H
#define LED_STRIP_H
#include "RGBController.h"
#include "serial_port.h"
#include <vector>
#ifndef TRUE
#define TRUE true
#define FALSE false
#endif
#ifndef WIN32
#define LPSTR char *
#define strtok_s strtok_r
#endif
#define HUE_PLUS_BAUD 256000
#define HUE_PLUS_PACKET_SIZE 125
enum
{
HUE_PLUS_CHANNEL_BOTH = 0x00, /* Both channels */
HUE_PLUS_CHANNEL_1 = 0x01, /* Channel 1 */
HUE_PLUS_CHANNEL_2 = 0x02, /* Channel 2 */
HUE_PLUS_NUM_CHANNELS = 0x02 /* Number of channels */
};
enum
{
HUE_PLUS_CHANNEL_1_IDX = 0x00, /* Channel 1 array index */
HUE_PLUS_CHANNEL_2_IDX = 0x01, /* Channel 2 array index */
};
enum
{
HUE_PLUS_MODE_FIXED = 0x00, /* Fixed colors mode */
HUE_PLUS_MODE_FADING = 0x01, /* Fading mode */
HUE_PLUS_MODE_SPECTRUM = 0x02, /* Spectrum cycle mode */
HUE_PLUS_NUM_MODES /* Number of Hue Plus modes */
};
class HuePlusController
{
public:
HuePlusController();
~HuePlusController();
void Initialize(char* port_name);
char* GetLEDString();
unsigned int GetStripsOnChannel(unsigned int channel);
void SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors);
unsigned int channel_leds[HUE_PLUS_NUM_CHANNELS];
private:
char led_string[1024];
char port_name[128];
serial_port *serialport;
};
#endif
@@ -0,0 +1,88 @@
#include "HuePlusController.h"
#include "RGBController.h"
#include "RGBController_HuePlus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <string>
#ifndef WIN32
#include <unistd.h>
#include <dirent.h>
#endif
/******************************************************************************************\
* *
* DetectHuePlusControllers *
* *
* Detect devices supported by the HuePlus driver *
* * *
\******************************************************************************************/
void DetectHuePlusControllers(std::vector<RGBController*> &rgb_controllers)
{
HuePlusController* new_hueplus;
RGBController_HuePlus* new_controller;
//Get file path in executable directory
std::ifstream infile;
char filename[2048];
char arg1[64];
#ifdef WIN32
GetModuleFileName(NULL, filename, 2048);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
#else
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
#endif
strcat(filename, "/settings.txt");
//Open settings file
infile.open(filename);
if (infile.good())
{
for (std::string line; std::getline(infile, line); )
{
if (line == "")
{
continue;
}
if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/'))
{
char * argument;
char * value;
value = (char *)line.c_str();
argument = strtok_s(value, "=", &value);
//Strip off new line characters if present
argument = strtok(argument, "\r\n");
value = strtok(value, "\r\n");
if(argument)
{
if (strcmp(argument, "hueplus") == 0)
{
new_hueplus = new HuePlusController();
new_hueplus->Initialize(value);
new_controller = new RGBController_HuePlus(new_hueplus);
rgb_controllers.push_back(new_controller);
}
}
}
}
}
} /* DetectHuePlusControllers() */
@@ -0,0 +1,244 @@
/*-----------------------------------------*\
| HyperXController.cpp |
| |
| Definitions and types for HyperX Predator|
| RGB RAM lighting controller |
| |
| Adam Honse (CalcProgrammer1) 6/29/2019 |
\*-----------------------------------------*/
#include "HyperXController.h"
#include <cstring>
HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots)
{
this->bus = bus;
this->dev = dev;
slots_valid = slots;
strcpy(device_name, "HyperX Predator RGB");
led_count = 0;
for(int i = 0; i < 8; i++)
{
if((slots_valid & (1 << i)) != 0)
{
led_count += 5;
}
}
mode = HYPERX_MODE_DIRECT;
}
HyperXController::~HyperXController()
{
}
std::string HyperXController::GetDeviceName()
{
return(device_name);
}
std::string HyperXController::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);
}
unsigned int HyperXController::GetLEDCount()
{
return(led_count);
}
unsigned int HyperXController::GetSlotCount()
{
unsigned int slot_count = 0;
for(int slot = 0; slot < 4; slot++)
{
if((slots_valid & (1 << slot)) != 0)
{
slot_count++;
}
}
return(slot_count);
}
unsigned int HyperXController::GetMode()
{
return(mode);
}
void HyperXController::SetEffectColor(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_RED, red );
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_GREEN, green);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_BLUE, blue );
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_BRIGHTNESS, 0x64 );
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
/*-----------------------------------------------------*\
| Loop through all slots and only set those which are |
| active. |
\*-----------------------------------------------------*/
for(int slot = 0; slot < 4; slot++)
{
if((slots_valid & (1 << slot)) != 0)
{
unsigned char base = slot_base[slot];
unsigned char red_base = base + 0x00;
unsigned char green_base = base + 0x01;
unsigned char blue_base = base + 0x02;
unsigned char bright_base = base + 0x10;
if(mode == HYPERX_MODE_DIRECT)
{
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE3, HYPERX_MODE3_DIRECT);
}
for(int led = 0; led < 5; led++)
{
bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red );
bus->i2c_smbus_write_byte_data(dev, green_base + (3 * led), green);
bus->i2c_smbus_write_byte_data(dev, blue_base + (3 * led), blue );
bus->i2c_smbus_write_byte_data(dev, bright_base + (3 * led), 0x64 );
}
}
}
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
/*-----------------------------------------------------*\
| led_slot - the unmapped slot ID for the given LED |
| led - the LED ID within that slot |
| slot_id - counts enabled slots |
| slot - the mapped slot ID for the given LED |
\*-----------------------------------------------------*/
int led_slot = led / 5;
int slot_id = -1;
int slot;
led -= (led_slot * 5);
/*-----------------------------------------------------*\
| Loop through all possible slots and only count those |
| which are active. |
\*-----------------------------------------------------*/
for(slot = 0; slot < 4; slot++)
{
if((slots_valid & ( 1 << slot)) != 0)
{
slot_id++;
}
if(slot_id == led_slot)
{
break;
}
}
unsigned char base = slot_base[slot];
unsigned char red_base = base + 0x00;
unsigned char green_base = base + 0x01;
unsigned char blue_base = base + 0x02;
unsigned char bright_base = base + 0x10;
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red );
bus->i2c_smbus_write_byte_data(dev, green_base + (3 * led), green);
bus->i2c_smbus_write_byte_data(dev, blue_base + (3 * led), blue );
bus->i2c_smbus_write_byte_data(dev, bright_base + (3 * led), 0x64 );
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
void HyperXController::SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char base = slot_base[slot];
unsigned char red_base = base + 0x00;
unsigned char green_base = base + 0x01;
unsigned char blue_base = base + 0x02;
unsigned char bright_base = base + 0x10;
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red );
bus->i2c_smbus_write_byte_data(dev, green_base + (3 * led), green);
bus->i2c_smbus_write_byte_data(dev, blue_base + (3 * led), blue );
bus->i2c_smbus_write_byte_data(dev, bright_base + (3 * led), 0x64 );
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
void HyperXController::SetMode(unsigned char new_mode)
{
mode = new_mode;
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
switch (mode)
{
case HYPERX_MODE_DIRECT:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE3, HYPERX_MODE3_DIRECT);
break;
case HYPERX_MODE_STATIC:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_STATIC);
break;
case HYPERX_MODE_RAINBOW:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE1, HYPERX_MODE1_RAINBOW);
break;
case HYPERX_MODE_COMET:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_COMET);
break;
case HYPERX_MODE_HEARTBEAT:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_HEARTBEAT);
break;
case HYPERX_MODE_CYCLE:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE1, HYPERX_MODE1_CYCLE);
break;
case HYPERX_MODE_BREATHING:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_BREATHING);
break;
case HYPERX_MODE_BOUNCE:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_BOUNCE);
break;
case HYPERX_MODE_BLINK:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_BLINK);
break;
}
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
@@ -0,0 +1,182 @@
/*-----------------------------------------*\
| HyperXController.h |
| |
| Definitions and types for HyperX Predator|
| RGB RAM lighting controller |
| |
| Adam Honse (CalcProgrammer1) 6/29/2019 |
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
typedef unsigned char hyperx_dev_id;
typedef unsigned short hyperx_register;
enum
{
HYPERX_REG_SLOT0_LED0_RED = 0x11, /* R color register for LED 0, Slot 0 */
HYPERX_REG_SLOT0_LED0_GREEN = 0x12, /* G color register for LED 0, Slot 0 */
HYPERX_REG_SLOT0_LED0_BLUE = 0x13, /* B color register for LED 0, Slot 0 */
HYPERX_REG_SLOT0_LED1_RED = 0x14, /* R color register for LED 1, Slot 0 */
HYPERX_REG_SLOT0_LED1_GREEN = 0x15, /* G color register for LED 1, Slot 0 */
HYPERX_REG_SLOT0_LED1_BLUE = 0x16, /* B color register for LED 1, Slot 0 */
HYPERX_REG_SLOT0_LED2_RED = 0x17, /* R color register for LED 2, Slot 0 */
HYPERX_REG_SLOT0_LED2_GREEN = 0x18, /* G color register for LED 2, Slot 0 */
HYPERX_REG_SLOT0_LED2_BLUE = 0x19, /* B color register for LED 2, Slot 0 */
HYPERX_REG_SLOT0_LED3_RED = 0x1A, /* R color register for LED 3, Slot 0 */
HYPERX_REG_SLOT0_LED3_GREEN = 0x1B, /* G color register for LED 3, Slot 0 */
HYPERX_REG_SLOT0_LED3_BLUE = 0x1C, /* B color register for LED 3, Slot 0 */
HYPERX_REG_SLOT0_LED4_RED = 0x1D, /* R color register for LED 4, Slot 0 */
HYPERX_REG_SLOT0_LED4_GREEN = 0x1E, /* G color register for LED 4, Slot 0 */
HYPERX_REG_SLOT0_LED4_BLUE = 0x1F, /* B color register for LED 4, Slot 0 */
HYPERX_REG_SLOT0_LED0_BRIGHTNESS = 0x21, /* Brightness for LED 0, Slot 0 (0-100) */
HYPERX_REG_SLOT0_LED1_BRIGHTNESS = 0x24, /* Brightness for LED 1, Slot 0 (0-100) */
HYPERX_REG_SLOT0_LED2_BRIGHTNESS = 0x27, /* Brightness for LED 2, Slot 0 (0-100) */
HYPERX_REG_SLOT0_LED3_BRIGHTNESS = 0x2A, /* Brightness for LED 3, Slot 0 (0-100) */
HYPERX_REG_SLOT0_LED4_BRIGHTNESS = 0x2D, /* Brightness for LED 4, Slot 0 (0-100) */
HYPERX_REG_SLOT1_LED0_RED = 0x41, /* R color register for LED 0, Slot 1 */
HYPERX_REG_SLOT1_LED0_GREEN = 0x42, /* G color register for LED 0, Slot 1 */
HYPERX_REG_SLOT1_LED0_BLUE = 0x43, /* B color register for LED 0, Slot 1 */
HYPERX_REG_SLOT1_LED1_RED = 0x44, /* R color register for LED 1, Slot 1 */
HYPERX_REG_SLOT1_LED1_GREEN = 0x45, /* G color register for LED 1, Slot 1 */
HYPERX_REG_SLOT1_LED1_BLUE = 0x46, /* B color register for LED 1, Slot 1 */
HYPERX_REG_SLOT1_LED2_RED = 0x47, /* R color register for LED 2, Slot 1 */
HYPERX_REG_SLOT1_LED2_GREEN = 0x48, /* G color register for LED 2, Slot 1 */
HYPERX_REG_SLOT1_LED2_BLUE = 0x49, /* B color register for LED 2, Slot 1 */
HYPERX_REG_SLOT1_LED3_RED = 0x4A, /* R color register for LED 3, Slot 1 */
HYPERX_REG_SLOT1_LED3_GREEN = 0x4B, /* G color register for LED 3, Slot 1 */
HYPERX_REG_SLOT1_LED3_BLUE = 0x4C, /* B color register for LED 3, Slot 1 */
HYPERX_REG_SLOT1_LED4_RED = 0x4D, /* R color register for LED 4, Slot 1 */
HYPERX_REG_SLOT1_LED4_GREEN = 0x4E, /* G color register for LED 4, Slot 1 */
HYPERX_REG_SLOT1_LED4_BLUE = 0x4F, /* B color register for LED 4, Slot 1 */
HYPERX_REG_SLOT1_LED0_BRIGHTNESS = 0x51, /* Brightness for LED 0, Slot 1 (0-100) */
HYPERX_REG_SLOT1_LED1_BRIGHTNESS = 0x54, /* Brightness for LED 1, Slot 1 (0-100) */
HYPERX_REG_SLOT1_LED2_BRIGHTNESS = 0x57, /* Brightness for LED 2, Slot 1 (0-100) */
HYPERX_REG_SLOT1_LED3_BRIGHTNESS = 0x5A, /* Brightness for LED 3, Slot 1 (0-100) */
HYPERX_REG_SLOT1_LED4_BRIGHTNESS = 0x5D, /* Brightness for LED 4, Slot 1 (0-100) */
HYPERX_REG_SLOT2_LED0_RED = 0x71, /* R color register for LED 0, Slot 2 */
HYPERX_REG_SLOT2_LED0_GREEN = 0x72, /* G color register for LED 0, Slot 2 */
HYPERX_REG_SLOT2_LED0_BLUE = 0x73, /* B color register for LED 0, Slot 2 */
HYPERX_REG_SLOT2_LED1_RED = 0x74, /* R color register for LED 1, Slot 2 */
HYPERX_REG_SLOT2_LED1_GREEN = 0x75, /* G color register for LED 1, Slot 2 */
HYPERX_REG_SLOT2_LED1_BLUE = 0x76, /* B color register for LED 1, Slot 2 */
HYPERX_REG_SLOT2_LED2_RED = 0x77, /* R color register for LED 2, Slot 2 */
HYPERX_REG_SLOT2_LED2_GREEN = 0x78, /* G color register for LED 2, Slot 2 */
HYPERX_REG_SLOT2_LED2_BLUE = 0x79, /* B color register for LED 2, Slot 2 */
HYPERX_REG_SLOT2_LED3_RED = 0x7A, /* R color register for LED 3, Slot 2 */
HYPERX_REG_SLOT2_LED3_GREEN = 0x7B, /* G color register for LED 3, Slot 2 */
HYPERX_REG_SLOT2_LED3_BLUE = 0x7C, /* B color register for LED 3, Slot 2 */
HYPERX_REG_SLOT2_LED4_RED = 0x7D, /* R color register for LED 4, Slot 2 */
HYPERX_REG_SLOT2_LED4_GREEN = 0x7E, /* G color register for LED 4, Slot 2 */
HYPERX_REG_SLOT2_LED4_BLUE = 0x7F, /* B color register for LED 4, Slot 2 */
HYPERX_REG_SLOT2_LED0_BRIGHTNESS = 0x81, /* Brightness for LED 0, Slot 2 (0-100) */
HYPERX_REG_SLOT2_LED1_BRIGHTNESS = 0x84, /* Brightness for LED 1, Slot 2 (0-100) */
HYPERX_REG_SLOT2_LED2_BRIGHTNESS = 0x87, /* Brightness for LED 2, Slot 2 (0-100) */
HYPERX_REG_SLOT2_LED3_BRIGHTNESS = 0x8A, /* Brightness for LED 3, Slot 2 (0-100) */
HYPERX_REG_SLOT2_LED4_BRIGHTNESS = 0x8D, /* Brightness for LED 4, Slot 2 (0-100) */
HYPERX_REG_SLOT3_LED0_RED = 0xA1, /* R color register for LED 0, Slot 3 */
HYPERX_REG_SLOT3_LED0_GREEN = 0xA2, /* G color register for LED 0, Slot 3 */
HYPERX_REG_SLOT3_LED0_BLUE = 0xA3, /* B color register for LED 0, Slot 3 */
HYPERX_REG_SLOT3_LED1_RED = 0xA4, /* R color register for LED 1, Slot 3 */
HYPERX_REG_SLOT3_LED1_GREEN = 0xA5, /* G color register for LED 1, Slot 3 */
HYPERX_REG_SLOT3_LED1_BLUE = 0xA6, /* B color register for LED 1, Slot 3 */
HYPERX_REG_SLOT3_LED2_RED = 0xA7, /* R color register for LED 2, Slot 3 */
HYPERX_REG_SLOT3_LED2_GREEN = 0xA8, /* G color register for LED 2, Slot 3 */
HYPERX_REG_SLOT3_LED2_BLUE = 0xA9, /* B color register for LED 2, Slot 3 */
HYPERX_REG_SLOT3_LED3_RED = 0xAA, /* R color register for LED 3, Slot 3 */
HYPERX_REG_SLOT3_LED3_GREEN = 0xAB, /* G color register for LED 3, Slot 3 */
HYPERX_REG_SLOT3_LED3_BLUE = 0xAC, /* B color register for LED 3, Slot 3 */
HYPERX_REG_SLOT3_LED4_RED = 0xAD, /* R color register for LED 4, Slot 3 */
HYPERX_REG_SLOT3_LED4_GREEN = 0xAE, /* G color register for LED 4, Slot 3 */
HYPERX_REG_SLOT3_LED4_BLUE = 0xAF, /* B color register for LED 4, Slot 3 */
HYPERX_REG_SLOT3_LED0_BRIGHTNESS = 0xB1, /* Brightness for LED 0, Slot 3 (0-100) */
HYPERX_REG_SLOT3_LED1_BRIGHTNESS = 0xB4, /* Brightness for LED 1, Slot 3 (0-100) */
HYPERX_REG_SLOT3_LED2_BRIGHTNESS = 0xB7, /* Brightness for LED 2, Slot 3 (0-100) */
HYPERX_REG_SLOT3_LED3_BRIGHTNESS = 0xBA, /* Brightness for LED 3, Slot 3 (0-100) */
HYPERX_REG_SLOT3_LED4_BRIGHTNESS = 0xBD, /* Brightness for LED 4, Slot 3 (0-100) */
HYPERX_REG_EFFECT_BRIGHTNESS = 0xDD, /* Brightness for effects (0-100) */
HYPERX_REG_APPLY = 0xE1, /* Apply changes register */
HYPERX_REG_MODE1 = 0xE3, /* Mode control register 1 */
HYPERX_REG_MODE2 = 0xE4, /* Mode control register 2 */
HYPERX_REG_MODE3 = 0xE5, /* Mode control register 3 */
HYPERX_REG_EFFECT_RED = 0xEC, /* Red color register for effects */
HYPERX_REG_EFFECT_GREEN = 0xED, /* Green color register for effects */
HYPERX_REG_EFFECT_BLUE = 0xEE, /* Blue color register for effects */
};
enum
{
HYPERX_MODE1_RAINBOW = 0x05, /* Mode 1 rainbow effect */
HYPERX_MODE1_CYCLE = 0x04, /* Mode 1 cycle effect */
};
enum
{
HYPERX_MODE2_BOUNCE = 0x02, /* Mode 2 bounce effect */
HYPERX_MODE2_BREATHING = 0x03, /* Mode 2 breathing effect */
HYPERX_MODE2_BLINK = 0x06, /* Mode 2 blink effect */
HYPERX_MODE2_HEARTBEAT = 0x07, /* Mode 2 heartbeat effect */
HYPERX_MODE2_COMET = 0x08, /* Mode 2 comet effect */
HYPERX_MODE2_STATIC = 0x09, /* Mode 2 static effect */
};
enum
{
HYPERX_MODE3_DIRECT = 0x21, /* Mode 3 direct control */
};
enum
{
HYPERX_MODE_DIRECT = 0, /* Direct control mode */
HYPERX_MODE_STATIC = 1, /* Static color mode */
HYPERX_MODE_RAINBOW = 2, /* Rainbow wave mode */
HYPERX_MODE_COMET = 3, /* Comet (chase) mode */
HYPERX_MODE_HEARTBEAT = 4, /* Heartbeat (pulsing) mode */
HYPERX_MODE_CYCLE = 5, /* Spectrum cycle mode */
HYPERX_MODE_BREATHING = 6, /* Breathing mode */
HYPERX_MODE_BOUNCE = 7, /* Bounce mode */
HYPERX_MODE_BLINK = 8, /* Blinking mode */
HYPERX_NUMBER_MODES /* Number of HyperX modes */
};
static const unsigned char slot_base[4] =
{
HYPERX_REG_SLOT0_LED0_RED, /* SPD 0x50 maps to slot 0 */
HYPERX_REG_SLOT1_LED0_RED, /* SPD 0x51 maps to slot 1 */
HYPERX_REG_SLOT2_LED0_RED, /* SPD 0x52 maps to slot 2 */
HYPERX_REG_SLOT3_LED0_RED /* SPD 0x53 maps to slot 3 */
};
class HyperXController
{
public:
HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots);
~HyperXController();
std::string GetDeviceName();
std::string GetDeviceLocation();
unsigned int GetLEDCount();
unsigned int GetSlotCount();
unsigned int GetMode();
void SetMode(unsigned char new_mode);
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetEffectColor(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
private:
char device_name[32];
unsigned int led_count;
unsigned char slots_valid;
i2c_smbus_interface* bus;
hyperx_dev_id dev;
unsigned int mode;
};
@@ -0,0 +1,106 @@
#include "HyperXController.h"
#include "RGBController.h"
#include "RGBController_HyperX.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
/******************************************************************************************\
* *
* TestForHyperXController *
* *
* Tests the given address to see if a HyperX controller exists there. *
* *
\******************************************************************************************/
bool TestForHyperXController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
for (int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if (res != i)
{
pass = false;
}
}
}
return(pass);
} /* TestForHyperXController() */
/******************************************************************************************\
* *
* DetectHyperXControllers *
* *
* Detect HyperX controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectHyperXControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
HyperXController* new_hyperx;
RGBController_HyperX* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
unsigned char slots_valid = 0x00;
// Check for HyperX controller at 0x27
if (TestForHyperXController(busses[bus], 0x27))
{
busses[bus]->i2c_smbus_write_byte_data(0x37, 0x00, 0xFF);
Sleep(1);
for(int slot_addr = 0x50; slot_addr <= 0x57; slot_addr++)
{
// Test for HyperX SPD at slot_addr
// This test was copied from NGENUITY software
// Tests SPD addresses in order: 0x40, 0x41, 0x68, and 0x67
if((busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x40) == 0x01)
&&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x41) == 0x98)
&&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x68) == 0x10)
&&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x67) == 0x00))
{
slots_valid |= (1 << (slot_addr - 0x50));
}
Sleep(1);
}
if(slots_valid != 0)
{
new_hyperx = new HyperXController(busses[bus], 0x27, slots_valid);
new_controller = new RGBController_HyperX(new_hyperx);
rgb_controllers.push_back(new_controller);
}
}
}
} /* DetectHyperXControllers() */
@@ -0,0 +1,147 @@
/*---------------------------------------------------------*\
| Processing Code for Generic LED Strip Interface |
| |
| Adam Honse ([email protected]), 12/11/2016 |
\*---------------------------------------------------------*/
#include "LEDStripController.h"
#include <fstream>
#include <iostream>
#include <string>
LEDStripController::LEDStripController()
{
}
LEDStripController::~LEDStripController()
{
}
void LEDStripController::Initialize(char* ledstring)
{
LPSTR numleds = NULL;
LPSTR source = NULL;
LPSTR udpport_baud = NULL;
LPSTR next = NULL;
//Assume serial device unless a different protocol is specified
bool serial = TRUE;
source = strtok_s(ledstring, ",", &next);
//Check if we are setting up a Keyboard Visualizer UDP protocol device
if (strncmp(source, "udp:", 4) == 0)
{
source = source + 4;
serial = FALSE;
}
//Check for either the UDP port or the serial baud rate
if (strlen(next))
{
udpport_baud = strtok_s(next, ",", &next);
}
//Check for the number of LEDs
if (strlen(next))
{
numleds = strtok_s(next, ",", &next);
}
if (serial)
{
if (udpport_baud == NULL)
{
//Initialize with default baud rate
InitializeSerial(source, 115200);
}
else
{
//Initialize with custom baud rate
InitializeSerial(source, atoi(udpport_baud));
}
}
else
{
if (udpport_baud == NULL)
{
//Do something
}
else
{
//Initialize UDP port
InitializeUDP(source, udpport_baud);
}
}
if (numleds != NULL && strlen(numleds))
{
num_leds = atoi(numleds);
}
}
void LEDStripController::InitializeSerial(char* portname, int baud)
{
portname = strtok(portname, "\r");
strcpy(port_name, portname);
baud_rate = baud;
serialport = new serial_port(port_name, baud_rate);
udpport = NULL;
}
void LEDStripController::InitializeUDP(char * clientname, char * port)
{
strcpy(client_name, clientname);
strcpy(port_name, port);
udpport = new net_port(client_name, port_name);
serialport = NULL;
}
char* LEDStripController::GetLEDString()
{
return(led_string);
}
void LEDStripController::SetLEDs(std::vector<RGBColor> colors)
{
unsigned char *serial_buf;
serial_buf = new unsigned char[(num_leds * 3) + 3];
serial_buf[0] = 0xAA;
for (int idx = 0; idx < (num_leds * 3); idx += 3)
{
int pixel_idx = idx / 3;
RGBColor color = colors[pixel_idx];
serial_buf[idx + 1] = RGBGetRValue(color);
serial_buf[idx + 2] = RGBGetGValue(color);
serial_buf[idx + 3] = RGBGetBValue(color);
}
unsigned short sum = 0;
for (int i = 0; i < (num_leds * 3) + 1; i++)
{
sum += serial_buf[i];
}
serial_buf[(num_leds * 3) + 1] = sum >> 8;
serial_buf[(num_leds * 3) + 2] = sum & 0x00FF;
if (serialport != NULL)
{
serialport->serial_write((char *)serial_buf, (num_leds * 3) + 3);
serialport->serial_flush_tx();
}
else if (udpport != NULL)
{
udpport->udp_write((char *)serial_buf, (num_leds * 3) + 3);
}
delete[] serial_buf;
}
@@ -0,0 +1,50 @@
/*---------------------------------------------------------*\
| Definitions for Generic LED Strip Interface |
| |
| Adam Honse ([email protected]), 12/11/2016 |
\*---------------------------------------------------------*/
#ifndef LED_STRIP_H
#define LED_STRIP_H
#include "RGBController.h"
#include "serial_port.h"
#include "net_port.h"
#include <vector>
#ifndef TRUE
#define TRUE true
#define FALSE false
#endif
#ifndef WIN32
#define LPSTR char *
#define strtok_s strtok_r
#endif
class LEDStripController
{
public:
LEDStripController();
~LEDStripController();
void Initialize(char* ledstring);
void InitializeSerial(char* portname, int baud);
void InitializeUDP(char* clientname, char* port);
char* GetLEDString();
void SetLEDs(std::vector<RGBColor> colors);
int num_leds;
private:
int baud_rate;
char led_string[1024];
char port_name[128];
char client_name[1024];
serial_port *serialport;
net_port *udpport;
};
#endif
@@ -0,0 +1,88 @@
#include "LEDStripController.h"
#include "RGBController.h"
#include "RGBController_LEDStrip.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <string>
#ifndef WIN32
#include <unistd.h>
#include <dirent.h>
#endif
/******************************************************************************************\
* *
* DetectLEDStripControllers *
* *
* Detect devices supported by the LEDStrip driver *
* * *
\******************************************************************************************/
void DetectLEDStripControllers(std::vector<RGBController*> &rgb_controllers)
{
LEDStripController* new_ledstrip;
RGBController_LEDStrip* new_controller;
//Get file path in executable directory
std::ifstream infile;
char filename[2048];
char arg1[64];
#ifdef WIN32
GetModuleFileName(NULL, filename, 2048);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "\\ledstrip.txt");
#else
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "/ledstrip.txt");
#endif
//Open settings file
infile.open(filename);
if (infile.good())
{
for (std::string line; std::getline(infile, line); )
{
if (line == "")
{
continue;
}
if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/'))
{
char * argument;
char * value;
value = (char *)line.c_str();
argument = strtok_s(value, "=", &value);
//Strip off new line characters if present
argument = strtok(argument, "\r\n");
value = strtok(value, "\r\n");
if(argument)
{
if (strcmp(argument, "ledstrip") == 0)
{
new_ledstrip = new LEDStripController();
new_ledstrip->Initialize(value);
new_controller = new RGBController_LEDStrip(new_ledstrip);
rgb_controllers.push_back(new_controller);
}
}
}
}
}
} /* DetectLEDStripControllers() */
@@ -0,0 +1,110 @@
/*-----------------------------------------*\
| PolychromeController.cpp |
| |
| Driver for for ASRock ASR LED and |
| Polychrome RGB lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/14/2019 |
\*-----------------------------------------*/
#include "PolychromeController.h"
#include <cstring>
PolychromeController::PolychromeController(i2c_smbus_interface* bus, polychrome_dev_id dev)
{
this->bus = bus;
this->dev = dev;
switch (GetFirmwareVersion())
{
case FIRMWARE_VER_1_PT_10:
led_count = 1;
asr_led = true;
strcpy(device_name, "ASRock ASR LED FW 1.10");
break;
case FIRMWARE_VER_2_PT_00:
led_count = 1;
asr_led = false;
strcpy(device_name, "ASRock Polychrome FW 2.00");
break;
case FIRMWARE_VER_3_PT_00:
led_count = 1;
asr_led = false;
strcpy(device_name, "ASRock Polychrome FW 3.00");
break;
}
}
PolychromeController::~PolychromeController()
{
}
char* PolychromeController::GetDeviceName()
{
return(device_name);
}
unsigned short PolychromeController::GetFirmwareVersion()
{
// The firmware register holds two bytes, so the first read should return 2
// If not, report invalid firmware revision FFFF
if (bus->i2c_smbus_read_byte_data(dev, POLYCHROME_REG_FIRMWARE_VER) == 0x02)
{
unsigned char major = bus->i2c_smbus_read_byte(dev);
unsigned char minor = bus->i2c_smbus_read_byte(dev);
return((major << 8) | minor);
}
else
{
return(0xFFFF);
}
}
unsigned int PolychromeController::GetLEDCount()
{
return(led_count);
}
void PolychromeController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
if (asr_led)
{
}
else
{
unsigned char colors[3] = { red, green, blue };
bus->i2c_smbus_write_block_data(dev, POLYCHROME_REG_COLOR, 3, colors);
}
}
void PolychromeController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
if (asr_led)
{
}
else
{
unsigned char colors[3] = { red, green, blue };
bus->i2c_smbus_write_block_data(dev, POLYCHROME_REG_COLOR, 3, colors);
}
}
void PolychromeController::SetMode(unsigned char mode)
{
if (asr_led)
{
}
else
{
bus->i2c_smbus_write_byte_data(dev, POLYCHROME_REG_MODE, mode);
}
}
@@ -0,0 +1,91 @@
/*-----------------------------------------*\
| PolychromeController.h |
| |
| Definitions and types for ASRock |
| ASR LED and Polychrome RGB lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 12/13/2019 |
\*-----------------------------------------*/
#include "i2c_smbus.h"
#pragma once
typedef unsigned char polychrome_dev_id;
enum
{
FIRMWARE_VER_1_PT_10 = 0x010A, /* Firmware nu51_1.10 */
FIRMWARE_VER_2_PT_00 = 0x0200, /* Firmware nu51_2.00 */
FIRMWARE_VER_3_PT_00 = 0x0300, /* Firmware nu51_3.00 */
};
enum
{
ASRLED_REG_FIRMWARE_VER = 0x00, /* Firmware version Major.Minor */
ASRLED_REG_MODE = 0x30, /* Mode selection register */
};
#define ASRLED_NUM_MODES 8 /* Number of ASR LED modes */
enum
{
ASRLED_MODE_OFF = 0x10, /* OFF mode */
ASRLED_MODE_STATIC = 0x11, /* Static color mode */
ASRLED_MODE_BREATHING = 0x12, /* Breathing effect mode */
ASRLED_MODE_FLASHING = 0x13, /* Flashing effect mode */
ASRLED_MODE_SPECTRUM_CYCLE = 0x14, /* Spectrum Cycle effect mode */
ASRLED_MODE_RANDOM = 0x15, /* Random effect mode */
ASRLED_MODE_MUSIC = 0x17, /* Music effect mode */
ASRLED_MODE_WAVE = 0x18, /* Wave effect mode */
};
enum
{
POLYCHROME_REG_FIRMWARE_VER = 0x00, /* Firmware version Major.Minor */
POLYCHROME_REG_MODE = 0x30, /* Mode selection register */
POLYCHROME_REG_COLOR = 0x34, /* Color register: Red, Green, Blue */
};
#define POLYCHROME_NUM_MODES 14 /* Number of Polychrome modes */
enum
{
POLYCHROME_MODE_OFF = 0x10, /* OFF mode */
POLYCHROME_MODE_STATIC = 0x11, /* Static color mode */
POLYCHROME_MODE_BREATHING = 0x12, /* Breating effect mode */
POLYCHROME_MODE_FLASHING = 0x13, /* Flashing effect mode */
POLYCHROME_MODE_SPECTRUM_CYCLE = 0x14, /* Spectrum Cycle effect mode */
POLYCHROME_MODE_RANDOM = 0x15, /* Random effect mode */
POLYCHROME_MODE_WAVE = 0x17, /* Wave effect mode */
POLYCHROME_MODE_SPRING = 0x18, /* Spring effect mode */
POLYCHROME_MODE_STACK = 0x19, /* Stack effect mode */
POLYCHROME_MODE_CRAM = 0x1A, /* Cram effect mode */
POLYCHROME_MODE_SCAN = 0x1B, /* Scan effect mode */
POLYCHROME_MODE_NEON = 0x1C, /* Neon effect mode */
POLYCHROME_MODE_WATER = 0x1D, /* Water effect mode */
POLYCHROME_MODE_RAINBOW = 0x1E, /* Rainbow effect mode */
};
class PolychromeController
{
public:
PolychromeController(i2c_smbus_interface* bus, polychrome_dev_id dev);
~PolychromeController();
char* GetDeviceName();
unsigned int GetLEDCount();
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetMode(unsigned char mode);
unsigned short GetFirmwareVersion();
private:
bool asr_led;
char device_name[32];
unsigned int led_count;
i2c_smbus_interface* bus;
polychrome_dev_id dev;
};
@@ -0,0 +1,171 @@
/*-----------------------------------------*\
| RGBFusionController.cpp |
| |
| Driver for Gigabyte Aorus RGB Fusion |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/10/2019 |
\*-----------------------------------------*/
#include "RGBFusionController.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
RGBFusionController::RGBFusionController(i2c_smbus_interface* bus, rgb_fusion_dev_id dev)
{
this->bus = bus;
this->dev = dev;
// Set Device name
strcpy(device_name, "Gigabyte Motherboard");
// Set LED count
led_count = 2;
}
RGBFusionController::~RGBFusionController()
{
}
std::string RGBFusionController::GetDeviceName()
{
return(device_name);
}
std::string RGBFusionController::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);
}
unsigned int RGBFusionController::GetLEDCount()
{
return(led_count);
}
unsigned char RGBFusionController::GetMode()
{
switch_bank(0);
return(get_mode_ch_0());
}
void RGBFusionController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char mode_ch_0;
unsigned char mode_ch_1;
switch_bank(1);
set_color_ch_0(red, green, blue);
set_color_ch_1(red, green, blue);
switch_bank(0);
mode_ch_0 = get_mode_ch_0();
mode_ch_1 = get_mode_ch_1();
set_mode_ch_0(mode_ch_0);
set_mode_ch_1(mode_ch_1);
}
void RGBFusionController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char mode;
switch (led)
{
case 0:
switch_bank(1);
set_color_ch_0(red, green, blue);
switch_bank(0);
mode = get_mode_ch_0();
set_mode_ch_0(mode);
break;
case 1:
switch_bank(1);
set_color_ch_1(red, green, blue);
switch_bank(0);
mode = get_mode_ch_1();
set_mode_ch_1(mode);
break;
}
}
void RGBFusionController::SetMode(unsigned char mode)
{
switch_bank(0);
set_mode_ch_0(mode);
set_mode_ch_1(mode);
}
void RGBFusionController::dump()
{
int i, j;
int start = 0x00;
FILE* file = freopen("rgb_fusion_dump.txt", "a", stdout);
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
for (i = 0; i < 0xFF; i += 16)
{
printf("%04x: ", i + start);
for (j = 0; j < 16; j++)
{
printf("%02x ", bus->i2c_smbus_read_byte_data(dev, (start + i + j)));
}
printf("\r\n");
}
fclose(file);
}
unsigned char RGBFusionController::get_mode_ch_0()
{
s32 temp = bus->i2c_smbus_read_byte_data(dev, RGB_FUSION_BANK_1_REG_CH_0_MODE);
return(temp);
}
unsigned char RGBFusionController::get_mode_ch_1()
{
return(bus->i2c_smbus_read_byte_data(dev, RGB_FUSION_BANK_1_REG_CH_1_MODE));
}
void RGBFusionController::set_color_ch_0(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_0_REG_CH_0_R, red);
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_0_REG_CH_0_G, green);
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_0_REG_CH_0_B, blue);
}
void RGBFusionController::set_color_ch_1(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_0_REG_CH_1_R, red);
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_0_REG_CH_1_G, green);
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_0_REG_CH_1_B, blue);
}
void RGBFusionController::set_mode_ch_0(unsigned char mode)
{
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_1_REG_CH_0_MODE, mode + RGB_FUSION_WRITE_MODE_OFST);
}
void RGBFusionController::set_mode_ch_1(unsigned char mode)
{
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_1_REG_CH_1_MODE, mode + RGB_FUSION_WRITE_MODE_OFST);
}
void RGBFusionController::switch_bank(unsigned char bank)
{
bus->i2c_smbus_write_byte_data(dev, RGB_FUSION_BANK_SWITCH_REG, bank);
}
@@ -0,0 +1,71 @@
/*-----------------------------------------*\
| RGBFusionController.h |
| |
| Definitions and types for Gigabyte Aorus |
| RGB Fusion lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/10/2019 |
\*-----------------------------------------*/
#include <string>
#include "i2c_smbus.h"
#pragma once
typedef unsigned char rgb_fusion_dev_id;
enum
{
RGB_FUSION_BANK_0_REG_CH_0_R = 0x00, /* Channel 0 Red Value */
RGB_FUSION_BANK_0_REG_CH_0_G = 0x01, /* Channel 0 Green Value */
RGB_FUSION_BANK_0_REG_CH_0_B = 0x02, /* Channel 0 Blue Value */
RGB_FUSION_BANK_0_REG_CH_1_R = 0x08, /* Channel 1 Red Value */
RGB_FUSION_BANK_0_REG_CH_1_G = 0x09, /* Channel 1 Green Value */
RGB_FUSION_BANK_0_REG_CH_1_B = 0x0A, /* Channel 1 Blue Value */
RGB_FUSION_BANK_1_REG_CH_0_MODE = 0x03, /* Channel 0 Mode Selection */
RGB_FUSION_BANK_1_REG_CH_1_MODE = 0x13, /* Channel 1 Mode Selection */
RGB_FUSION_BANK_SWITCH_REG = 0xF0, /* Bank Switch Register */
};
#define RGB_FUSION_NUMBER_MODES 3 /* Number of RGB Fusion modes */
#define RGB_FUSION_WRITE_MODE_OFST 0x10 /* offset to add when writing mode */
enum
{
RGB_FUSION_MODE_STATIC = 0x00, /* Static color mode */
RGB_FUSION_MODE_BREATHING = 0x01, /* Breathing effect mode */
RGB_FUSION_MODE_FLASHING = 0x02, /* Flashing effect mode */
};
class RGBFusionController
{
public:
RGBFusionController(i2c_smbus_interface* bus, rgb_fusion_dev_id dev);
~RGBFusionController();
std::string GetDeviceName();
std::string GetDeviceLocation();
unsigned int GetLEDCount();
unsigned char GetMode();
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetMode(unsigned char mode);
private:
void dump();
unsigned char get_mode_ch_0();
unsigned char get_mode_ch_1();
void set_color_ch_0(unsigned char red, unsigned char green, unsigned char blue);
void set_color_ch_1(unsigned char red, unsigned char green, unsigned char blue);
void set_mode_ch_0(unsigned char mode);
void set_mode_ch_1(unsigned char mode);
void switch_bank(unsigned char bank);
char device_name[32];
unsigned int led_count;
i2c_smbus_interface* bus;
rgb_fusion_dev_id dev;
};
@@ -0,0 +1,60 @@
#include "RGBFusionController.h"
#include "RGBController.h"
#include "RGBController_RGBFusion.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForRGBFusionController *
* *
* Tests the given address to see if an RGB Fusion controller exists there. First *
* does a quick write to test for a response *
* *
\******************************************************************************************/
bool TestForRGBFusionController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
}
return(pass);
} /* TestForRGBFusionController() */
/******************************************************************************************\
* *
* DetectRGBFusionControllers *
* *
* Detect RGB Fusion controllers on the enumerated I2C busses at address 0x28. *
* *
* bus - pointer to i2c_smbus_interface where RGB Fusion device is connected *
* dev - I2C address of RGB Fusion device *
* *
\******************************************************************************************/
void DetectRGBFusionControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers)
{
RGBFusionController* new_rgb_fusion;
RGBController_RGBFusion* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for RGB Fusion controller at 0x28
if (TestForRGBFusionController(busses[bus], 0x28))
{
new_rgb_fusion = new RGBFusionController(busses[bus], 0x28);
new_controller = new RGBController_RGBFusion(new_rgb_fusion);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectRGBFusionControllers() */
+176 -169
View File
@@ -7,6 +7,8 @@
\******************************************************************************************/
#include "AuraController.h"
#include "RGBController.h"
#include "RGBController_AorusGPU.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
@@ -14,24 +16,145 @@
#ifdef WIN32
#include <regex>
#include "i2c_smbus_piix4.h"
#include "i2c_smbus_i801.h"
#include "i2c_smbus_nct6775.h"
#include "wmi.h"
#include "inpout32.h"
#pragma comment(lib, "inpout32.lib")
#else /* WIN32 */
#include "i2c_smbus_linux.h"
#include <regex>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#endif /* WIN32 */
std::vector<AuraController *> controllers;
std::vector<i2c_smbus_interface *> busses;
std::vector<i2c_smbus_interface*> busses;
std::vector<RGBController*> rgb_controllers;
#ifdef WIN32
/******************************************************************************************\
* *
* Nuvoton Super IO constants *
* *
\******************************************************************************************/
#define SIO_NCT5577_ID 0xC330 /* Device ID for NCT5577D (C333) */
#define SIO_NCT6102_ID 0x1060 /* Device ID for NCT6102D/6106D (1061) */
#define SIO_NCT6793_ID 0xd120 /* Device ID for NCT6793D (D121) */
#define SIO_NCT6796_ID 0xd420 /* Device ID for NCT6796D (D421) */
#define SIO_REG_LOGDEV 0x07 /* Logical Device Register */
#define SIO_REG_DEVID 0x20 /* Device ID Register */
#define SIO_REG_SMBA 0x62 /* SMBus Base Address Register */
#define SIO_LOGDEV_SMBUS 0x0B /* Logical Device for SMBus */
#define SIO_ID_MASK 0xFFF8 /* Device ID mask */
/******************************************************************************************\
* *
* superio_enter *
* *
* Put the Super IO chip into Extended Function Mode *
* *
\******************************************************************************************/
void superio_enter(int ioreg)
{
Out32(ioreg, 0x87);
Out32(ioreg, 0x87);
}
/******************************************************************************************\
* *
* superio_outb *
* *
* Write a byte to the Super IO configuration register *
* *
\******************************************************************************************/
void superio_outb(int ioreg, int reg, int val)
{
Out32(ioreg, reg);
Out32(ioreg + 1, val);
}
/******************************************************************************************\
* *
* superio_inb *
* *
* Read a byte to the Super IO configuration register *
* *
\******************************************************************************************/
int superio_inb(int ioreg, int reg)
{
Out32(ioreg, reg);
return Inp32(ioreg + 1);
}
/******************************************************************************************\
* *
* DetectNuvotonI2CBusses (Windows) *
* *
* Detects available Nuvoton Super IO SMBUS adapters and enumerates *
* i2c_smbus_interface objects for them *
* *
\******************************************************************************************/
void DetectNuvotonI2CBusses()
{
i2c_smbus_interface* bus;
int sioaddr = 0x2E;
superio_enter(sioaddr);
int val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) | superio_inb(sioaddr, SIO_REG_DEVID + 1);
switch (val & SIO_ID_MASK)
{
case SIO_NCT5577_ID:
case SIO_NCT6102_ID:
case SIO_NCT6793_ID:
case SIO_NCT6796_ID:
bus = new i2c_smbus_nct6775();
// Set logical device register to get SMBus base address
superio_outb(sioaddr, SIO_REG_LOGDEV, SIO_LOGDEV_SMBUS);
// Get SMBus base address from configuration register
int smba = (superio_inb(sioaddr, SIO_REG_SMBA) << 8) | superio_inb(sioaddr, SIO_REG_SMBA + 1);
((i2c_smbus_nct6775*)bus)->nct6775_smba = smba;
// Set device name string
switch (val & SIO_ID_MASK)
{
case SIO_NCT5577_ID:
sprintf(bus->device_name, "Nuvoton NCT5577D SMBus at %X", smba);
break;
case SIO_NCT6102_ID:
sprintf(bus->device_name, "Nuvoton NCT6102D/NCT6106D SMBus at %X", smba);
break;
case SIO_NCT6793_ID:
sprintf(bus->device_name, "Nuvoton NCT6793D SMBus at %X", smba);
break;
case SIO_NCT6796_ID:
sprintf(bus->device_name, "Nuvoton NCT6796D SMBus at %X", smba);
break;
}
busses.push_back(bus);
}
} /* DetectNuvotonI2CBusses() */
/******************************************************************************************\
* *
* DetectI2CBusses (Windows) *
@@ -67,11 +190,15 @@ void DetectI2CBusses()
if (i["Manufacturer"].find("Advanced Micro Devices, Inc") != std::string::npos)
{
bus = new i2c_smbus_piix4();
strcpy(bus->device_name, i["Description"].c_str());
strcat(bus->device_name, " at 0x0B00");
((i2c_smbus_piix4 *)bus)->piix4_smba = 0x0B00;
busses.push_back(bus);
bus = new i2c_smbus_piix4();
((i2c_smbus_piix4 *)bus)->piix4_smba = 0x0B20;
strcpy(bus->device_name, i["Description"].c_str());
strcat(bus->device_name, " at 0x0B20");
busses.push_back(bus);
}
@@ -79,7 +206,8 @@ void DetectI2CBusses()
// Analysis of many Intel boards has shown that Intel SMBus adapter I/O space varies between boards
// We can query Win32_PnPAllocatedResource entries and look up the PCI device ID to find the allocated I/O space
// Intel SMBus adapters use the i801 driver
else if (i["Manufacturer"].find("Intel") != std::string::npos)
else if ((i["Manufacturer"].find("Intel") != std::string::npos)
|| (i["Manufacturer"].find("INTEL") != std::string::npos))
{
std::string rgx1 = ".+" + q_res_PnPSignedDriver[0]["DeviceID"].substr(4, 33) + ".+";
@@ -99,12 +227,16 @@ void DetectI2CBusses()
unsigned int IORangeStart = std::stoi(matches[1].str());
bus = new i2c_smbus_i801();
strcpy(bus->device_name, i["Description"].c_str());
((i2c_smbus_i801 *)bus)->i801_smba = IORangeStart;
busses.push_back(bus);
}
}
}
// Detect Nuvoton Super IO SMBus adapters
DetectNuvotonI2CBusses();
} /* DetectI2CBusses() */
#else /* WIN32 */
@@ -127,8 +259,8 @@ void DetectI2CBusses()
struct dirent * ent;
int test_fd;
// Start looking for I2C adapters in /sys/class/i2c-adapter/
strcpy(driver_path, "/sys/class/i2c-adapter/");
// Start looking for I2C adapters in /sys/bus/i2c/devices/
strcpy(driver_path, "/sys/bus/i2c/devices/");
dir = opendir(driver_path);
if(dir == NULL)
@@ -187,101 +319,6 @@ void DetectI2CBusses()
#endif /* WIN32 */
/******************************************************************************************\
* *
* CreateAuraDevice *
* *
* Enumerates an ASUS Aura compatibler I2C device with the given address on the given *
* bus *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
AuraController * CreateAuraDevice(i2c_smbus_interface * bus, aura_dev_id dev)
{
AuraController * aura;
aura = new AuraController();
aura->bus = bus;
aura->dev = dev;
return(aura);
} /* CreateAuraDevice() */
/******************************************************************************************\
* *
* DetectI2C *
* *
* Prints a list of all detected I2C addresses on the given bus *
* *
* bus - pointer to i2c_smbus_interface to scan *
* mode - one of AUTO, QUICK, READ, FUNC - method of access *
* *
* Code adapted from i2cdetect.c from i2c-tools Linux package *
* *
\******************************************************************************************/
#define MODE_AUTO 0
#define MODE_QUICK 1
#define MODE_READ 2
#define MODE_FUNC 3
void DetectI2C(i2c_smbus_interface * bus, int mode)
{
int i, j;
int res;
int slave_addr;
freopen("i2cdetect.txt", "a", stdout);
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
for (i = 0; i < 128; i += 16)
{
printf("%02x: ", i);
for (j = 0; j < 16; j++)
{
/* Set slave address */
slave_addr = i + j;
/* Probe this address */
switch (mode)
{
case MODE_QUICK:
res = bus->i2c_smbus_write_quick(slave_addr, I2C_SMBUS_WRITE);
break;
case MODE_READ:
res = bus->i2c_smbus_read_byte(slave_addr);
break;
default:
if ((i + j >= 0x30 && i + j <= 0x37)
|| (i + j >= 0x50 && i + j <= 0x5F))
res = bus->i2c_smbus_read_byte(slave_addr);
else
res = bus->i2c_smbus_write_quick(slave_addr, I2C_SMBUS_WRITE);
break;
}
if (res < 0)
{
printf("-- ");
}
else
{
printf("%02x ", i + j);
}
}
printf("\r\n");
}
} /* DetectI2C() */
/******************************************************************************************\
* *
* DumpAuraRegisters *
@@ -294,13 +331,13 @@ void DumpAuraRegisters(AuraController * controller)
{
int i, j;
int start = 0x8000;
int start = 0x0000;
freopen("auradump.txt", "a", stdout);
FILE* file = freopen("auradump.txt", "a", stdout);
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
for (i = 0; i < 512; i += 16)
for (i = 0; i < 0xFFFF; i += 16)
{
printf("%04x: ", i + start);
@@ -312,87 +349,57 @@ void DumpAuraRegisters(AuraController * controller)
printf("\r\n");
}
fclose(file);
} /* DumpAuraRegisters() */
void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
void DetectCorsairControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
void DetectCorsairProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
void DetectHyperXControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
void DetectRGBFusionControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers);
void DetectLEDStripControllers(std::vector<RGBController*> &rgb_controllers);
void DetectHuePlusControllers(std::vector<RGBController*> &rgb_controllers);
void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers);
void DetectRazerChromaSDKControllers(std::vector<RGBController*>& rgb_controllers);
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers);
void DetectAMDWraithPrismControllers(std::vector<RGBController*>& rgb_controllers);
/******************************************************************************************\
* *
* main/WinMain *
* DetectRGBConrollers *
* *
* Main function. Has no defined purpose yet, but is where you can call the other *
* functions in this project to test them out *
* *
* Currently, this program will enumerate all detected SMBus adapters and then detect *
* all attached devices, similar to i2cdetect on Linux *
* Detect and populate RGB Controllers vector *
* *
\******************************************************************************************/
#ifdef WIN32
INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow)
#else /* WIN32 */
int main()
#endif /* WIN32 */
void DetectRGBControllers(void)
{
// Colors Array R B G
unsigned char colors[15] = { 255, 0, 0,
0, 255, 0,
0, 0, 255,
255, 0, 255,
0, 255, 255 };
DetectI2CBusses();
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Remap Aura-enabled RAM modules on 0x77
for (unsigned int slot = 0; slot < 8; slot++)
{
int res = busses[bus]->i2c_smbus_write_quick(0x77, I2C_SMBUS_WRITE);
DetectAuraControllers(busses, rgb_controllers);
DetectCorsairControllers(busses, rgb_controllers);
DetectCorsairProControllers(busses, rgb_controllers);
DetectHyperXControllers(busses, rgb_controllers);
DetectRGBFusionControllers(busses, rgb_controllers);
if (res < 0)
{
break;
}
DetectLEDStripControllers(rgb_controllers);
DetectHuePlusControllers(rgb_controllers);
AuraController * temp_controller = CreateAuraDevice(busses[bus], 0x77);
DetectAMDWraithPrismControllers(rgb_controllers);
temp_controller->AuraRegisterWrite(AURA_REG_SLOT_INDEX, slot);
temp_controller->AuraRegisterWrite(AURA_REG_I2C_ADDRESS, 0xE0 + ( slot << 1 ) );
#ifdef WIN32
DetectRazerChromaSDKControllers(rgb_controllers);
#else
DetectE131Controllers(rgb_controllers);
DetectOpenRazerControllers(rgb_controllers);
#endif
delete temp_controller;
}
//This is for testing Aorus GPU
#if 0
RGBController_AorusGPU * aorus_rgb = new RGBController_AorusGPU();
// Add Aura-enabled controllers at their remapped addresses
for (unsigned int slot = 0; slot < 8; slot++)
{
int res = busses[bus]->i2c_smbus_write_quick(0x70 + slot, I2C_SMBUS_WRITE);
rgb_controllers.push_back(aorus_rgb);
#endif
if (res >= 0)
{
AuraController * new_controller = CreateAuraDevice(busses[bus], 0x70 + slot);
controllers.push_back(new_controller);
}
}
// Check for Aura controller at 0x4E
int res = busses[bus]->i2c_smbus_write_quick(0x4E, I2C_SMBUS_WRITE);
if (res >= 0)
{
AuraController * new_controller = CreateAuraDevice(busses[bus], 0x4E);
controllers.push_back(new_controller);
}
}
for (unsigned int i = 0; i < controllers.size(); i++)
{
controllers[i]->AuraRegisterWrite(AURA_REG_DIRECT, 1);
controllers[i]->AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
for (unsigned int i = 0; i < controllers.size(); i++)
{
controllers[i]->AuraRegisterWriteBlock(AURA_REG_COLORS_DIRECT, colors, 15);
}
return 1;
}
+12
View File
@@ -0,0 +1,12 @@
#include <string>
#include "AuraController.h"
#include "i2c_smbus.h"
#define MODE_AUTO 0
#define MODE_QUICK 1
#define MODE_READ 2
#define MODE_FUNC 3
std::string DetectI2C(i2c_smbus_interface * bus, int mode);
void DumpAuraRegisters(AuraController * controller);
void DetectRGBControllers();
-31
View File
@@ -1,31 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenAuraSDK", "OpenAuraSDK\OpenAuraSDK.vcxproj", "{6D22BFF3-C1DF-407A-8816-05D63919A991}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Debug|x64.ActiveCfg = Debug|x64
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Debug|x64.Build.0 = Debug|x64
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Debug|x86.ActiveCfg = Debug|Win32
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Debug|x86.Build.0 = Debug|Win32
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Release|x64.ActiveCfg = Release|x64
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Release|x64.Build.0 = Release|x64
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Release|x86.ActiveCfg = Release|Win32
{6D22BFF3-C1DF-407A-8816-05D63919A991}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A2BB3E13-D506-413D-900E-F2B1323B3BB3}
EndGlobalSection
EndGlobal
-40
View File
@@ -1,40 +0,0 @@
/*-----------------------------------------*\
| AuraController.h |
| |
| Driver for ASUS Aura RGB lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 8/19/2018 |
\*-----------------------------------------*/
#include "AuraController.h"
unsigned char AuraController::AuraRegisterRead(aura_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));
}
void AuraController::AuraRegisterWrite(aura_register reg, unsigned char val)
{
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura value
bus->i2c_smbus_write_byte_data(dev, 0x01, val);
}
void AuraController::AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz)
{
//Write Aura register (0x8000 for colors)
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura block data
bus->i2c_smbus_write_block_data(dev, 0x03, sz, data);
}
-60
View File
@@ -1,60 +0,0 @@
/*-----------------------------------------*\
| AuraController.h |
| |
| Definitions and types for ASUS Aura RGB |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 8/19/2018 |
\*-----------------------------------------*/
#include "i2c_smbus.h"
#pragma once
typedef unsigned char aura_dev_id;
typedef unsigned short aura_register;
#define AURA_APPLY_VAL 0x01 /* Value for Apply Changes Register */
enum
{
AURA_REG_COLORS_DIRECT = 0x8000, /* Colors for Direct Mode 15 bytes */
AURA_REG_COLORS_EFFECT = 0x8010, /* Colors for Internal Effects 15 bytes */
AURA_REG_DIRECT = 0x8020, /* "Direct Access" Selection Register */
AURA_REG_MODE = 0x8021, /* AURA Mode Selection Register */
AURA_REG_APPLY = 0x80A0, /* AURA Apply Changes Register */
AURA_REG_SLOT_INDEX = 0x80F8, /* AURA Slot Index Register (RAM only) */
AURA_REG_I2C_ADDRESS = 0x80F9, /* AURA I2C Address Register (RAM only) */
};
enum
{
AURA_MODE_OFF = 0, /* OFF mode */
AURA_MODE_STATIC = 1, /* Static color mode */
AURA_MODE_BREATHING = 2, /* Breathing effect mode */
AURA_MODE_FLASHING = 3, /* Flashing effect mode */
AURA_MODE_SPECTRUM_CYCLE = 4, /* Spectrum Cycle mode */
AURA_MODE_RAINBOW = 5, /* Rainbow effect mode */
AURA_MODE_SPECTRUM_CYCLE_BREATHING = 6, /* Rainbow Breathing effect mode */
AURA_MODE_CHASE_FADE = 7, /* Chase with Fade effect mode */
AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE = 8, /* Chase with Fade, Rainbow effect mode */
AURA_MODE_CHASE = 9, /* Chase effect mode */
AURA_MODE_SPECTRUM_CYCLE_CHASE = 10, /* Chase with Rainbow effect mode */
AURA_MODE_SPECTRUM_CYCLE_WAVE = 11, /* Wave effect mode */
AURA_MODE_CHASE_RAINBOW_PULSE = 12, /* Chase with Rainbow Pulse effect mode*/
AURA_MODE_RANDOM_FLICKER = 13, /* Random flicker effect mode */
};
class AuraController
{
public:
unsigned char AuraRegisterRead(aura_register reg);
void AuraRegisterWrite(aura_register reg, unsigned char val);
void AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz);
i2c_smbus_interface * bus;
aura_dev_id dev;
private:
};
-17
View File
@@ -1,17 +0,0 @@
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
i2c_smbus.cpp \
AuraController.cpp \
OpenAuraSDK.cpp \
i2c_smbus_linux.cpp
HEADERS += \
i2c_smbus.h \
i2c_smbus_linux.h \
AuraController.h
FORMS +=
-191
View File
@@ -1,191 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{6D22BFF3-C1DF-407A-8816-05D63919A991}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>OpenAuraSDK</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
<AdditionalIncludeDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
<AdditionalIncludeDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\dependencies\inpout32_1501\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AuraController.h" />
<ClInclude Include="i2c_smbus.h" />
<ClInclude Include="i2c_smbus_i801.h" />
<ClInclude Include="i2c_smbus_piix4.h" />
<ClInclude Include="wmi.h" />
<ClInclude Include="OpenAuraSDK.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AuraController.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="i2c_smbus.cpp" />
<ClCompile Include="i2c_smbus_i801.cpp" />
<ClCompile Include="i2c_smbus_piix4.cpp" />
<ClCompile Include="wmi.cpp" />
<ClCompile Include="OpenAuraSDK.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
-60
View File
@@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="i2c_smbus.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="i2c_smbus_piix4.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AuraController.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OpenAuraSDK.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="i2c_smbus_i801.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wmi.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="OpenAuraSDK.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="i2c_smbus_piix4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AuraController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="i2c_smbus_i801.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="i2c_smbus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wmi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Binary file not shown.
+685
View File
@@ -0,0 +1,685 @@
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 09367fc014c3..25c0e02b3344 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -216,6 +216,15 @@ config I2C_CHT_WC
combined with a FUSB302 Type-C port-controller as such it is advised
to also select CONFIG_TYPEC_FUSB302=m.
+config I2C_NCT6775
+ tristate "Nuvoton NCT6775 and compatible SMBus controller"
+ help
+ If you say yes to this option, support will be included for the
+ Nuvoton NCT6775 and compatible SMBus controllers.
+
+ This driver can also be built as a module. If so, the module
+ will be called i2c-nct6775.
+
config I2C_NFORCE2
tristate "Nvidia nForce2, nForce3 and nForce4"
depends on PCI
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 80c23895eaaf..57a2daf0b94e 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_I2C_CHT_WC) += i2c-cht-wc.o
obj-$(CONFIG_I2C_I801) += i2c-i801.o
obj-$(CONFIG_I2C_ISCH) += i2c-isch.o
obj-$(CONFIG_I2C_ISMT) += i2c-ismt.o
+obj-$(CONFIG_I2C_NCT6775) += i2c-nct6775.o
obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o
obj-$(CONFIG_I2C_NFORCE2_S4985) += i2c-nforce2-s4985.o
obj-$(CONFIG_I2C_NVIDIA_GPU) += i2c-nvidia-gpu.o
diff --git a/drivers/i2c/busses/i2c-nct6775.c b/drivers/i2c/busses/i2c-nct6775.c
new file mode 100644
index 000000000000..e2b491a4b9f6
--- /dev/null
+++ b/drivers/i2c/busses/i2c-nct6775.c
@@ -0,0 +1,617 @@
+/*
+ * i2c-nct6775 - Driver for the SMBus master functionality of
+ * Nuvoton NCT677x Super-I/O chips
+ *
+ * Copyright (C) 2019 Adam Honse <[email protected]>
+ *
+ * Derived from nct6775 hwmon driver
+ * Copyright (C) 2012 Guenter Roeck <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/hwmon-vid.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/ioport.h>
+#include <linux/i2c.h>
+#include <linux/acpi.h>
+#include <linux/bitops.h>
+#include <linux/dmi.h>
+#include <linux/io.h>
+#include <linux/nospec.h>
+
+#define DRVNAME "i2c-nct6775"
+
+/* Nuvoton SMBus address offsets */
+#define SMBHSTDAT (0 + nuvoton_nct6793d_smba)
+#define SMBBLKSZ (1 + nuvoton_nct6793d_smba)
+#define SMBHSTCMD (2 + nuvoton_nct6793d_smba)
+#define SMBHSTIDX (3 + nuvoton_nct6793d_smba) //Index field is the Command field on other controllers
+#define SMBHSTCTL (4 + nuvoton_nct6793d_smba)
+#define SMBHSTADD (5 + nuvoton_nct6793d_smba)
+#define SMBHSTERR (9 + nuvoton_nct6793d_smba)
+#define SMBHSTSTS (0xE + nuvoton_nct6793d_smba)
+
+/* Command register */
+#define NCT6793D_READ_BYTE 0
+#define NCT6793D_READ_WORD 1
+#define NCT6793D_READ_BLOCK 2
+#define NCT6793D_BLOCK_WRITE_READ_PROC_CALL 3
+#define NCT6793D_PROC_CALL 4
+#define NCT6793D_WRITE_BYTE 8
+#define NCT6793D_WRITE_WORD 9
+#define NCT6793D_WRITE_BLOCK 10
+
+/* Control register */
+#define NCT6793D_MANUAL_START 128
+#define NCT6793D_SOFT_RESET 64
+
+/* Error register */
+#define NCT6793D_NO_ACK 32
+
+/* Status register */
+#define NCT6793D_FIFO_EMPTY 1
+#define NCT6793D_FIFO_FULL 2
+#define NCT6793D_MANUAL_ACTIVE 4
+
+#define NCT6775_LD_SMBUS 0x0B
+
+enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791, nct6792, nct6793,
+ nct6795, nct6796, nct6798 };
+
+struct nct6775_sio_data {
+ int sioreg;
+ enum kinds kind;
+};
+
+/* used to set data->name = nct6775_device_names[data->sio_kind] */
+static const char * const nct6775_device_names[] = {
+ "nct6106",
+ "nct6775",
+ "nct6776",
+ "nct6779",
+ "nct6791",
+ "nct6792",
+ "nct6793",
+ "nct6795",
+ "nct6796",
+ "nct6798",
+};
+
+static const char * const nct6775_sio_names[] __initconst = {
+ "NCT6106D",
+ "NCT6775F",
+ "NCT6776D/F",
+ "NCT6779D",
+ "NCT6791D",
+ "NCT6792D",
+ "NCT6793D",
+ "NCT6795D",
+ "NCT6796D",
+ "NCT6798D",
+};
+
+#define SIO_REG_LDSEL 0x07 /* Logical device select */
+#define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
+#define SIO_REG_SMBA 0x62 /* SMBus base address register */
+
+#define SIO_NCT6106_ID 0xc450
+#define SIO_NCT6775_ID 0xb470
+#define SIO_NCT6776_ID 0xc330
+#define SIO_NCT6779_ID 0xc560
+#define SIO_NCT6791_ID 0xc800
+#define SIO_NCT6792_ID 0xc910
+#define SIO_NCT6793_ID 0xd120
+#define SIO_NCT6795_ID 0xd350
+#define SIO_NCT6796_ID 0xd420
+#define SIO_NCT6798_ID 0xd428
+#define SIO_ID_MASK 0xFFF0
+
+static inline void
+superio_outb(int ioreg, int reg, int val)
+{
+ outb(reg, ioreg);
+ outb(val, ioreg + 1);
+}
+
+static inline int
+superio_inb(int ioreg, int reg)
+{
+ outb(reg, ioreg);
+ return inb(ioreg + 1);
+}
+
+static inline void
+superio_select(int ioreg, int ld)
+{
+ outb(SIO_REG_LDSEL, ioreg);
+ outb(ld, ioreg + 1);
+}
+
+static inline int
+superio_enter(int ioreg)
+{
+ /*
+ * Try to reserve <ioreg> and <ioreg + 1> for exclusive access.
+ */
+ if (!request_muxed_region(ioreg, 2, DRVNAME))
+ return -EBUSY;
+
+ outb(0x87, ioreg);
+ outb(0x87, ioreg);
+
+ return 0;
+}
+
+static inline void
+superio_exit(int ioreg)
+{
+ outb(0xaa, ioreg);
+ outb(0x02, ioreg);
+ outb(0x02, ioreg + 1);
+ release_region(ioreg, 2);
+}
+
+/*
+ * ISA constants
+ */
+
+#define IOREGION_ALIGNMENT (~7)
+#define IOREGION_LENGTH 2
+#define ADDR_REG_OFFSET 0
+#define DATA_REG_OFFSET 1
+
+#define NCT6775_REG_BANK 0x4E
+#define NCT6775_REG_CONFIG 0x40
+
+static struct i2c_adapter *nct6775_adapter;
+
+struct i2c_nct6775_adapdata {
+ unsigned short smba;
+};
+
+/* Return negative errno on error. */
+static s32 nct6775_access(struct i2c_adapter * adap, u16 addr,
+ unsigned short flags, char read_write,
+ u8 command, int size, union i2c_smbus_data * data)
+{
+ struct i2c_nct6775_adapdata *adapdata = i2c_get_adapdata(adap);
+ unsigned short nuvoton_nct6793d_smba = adapdata->smba;
+ int i, len, cnt;
+
+ cnt = 0;
+ len = 0;
+
+ outb_p(NCT6793D_SOFT_RESET, SMBHSTCTL);
+
+ switch (size) {
+ case I2C_SMBUS_QUICK:
+ outb_p((addr << 1) | read_write,
+ SMBHSTADD);
+ break;
+ case I2C_SMBUS_BYTE:
+ case I2C_SMBUS_BYTE_DATA:
+ outb_p((addr << 1) | read_write,
+ SMBHSTADD);
+ outb_p(command, SMBHSTIDX);
+ if (read_write == I2C_SMBUS_WRITE) {
+ outb_p(data->byte, SMBHSTDAT);
+ outb_p(NCT6793D_WRITE_BYTE, SMBHSTCMD);
+ }
+ else {
+ outb_p(NCT6793D_READ_BYTE, SMBHSTCMD);
+ }
+ break;
+ case I2C_SMBUS_WORD_DATA:
+ outb_p((addr << 1) | read_write,
+ SMBHSTADD);
+ outb_p(command, SMBHSTIDX);
+ if (read_write == I2C_SMBUS_WRITE) {
+ outb_p(data->word & 0xff, SMBHSTDAT);
+ outb_p((data->word & 0xff00) >> 8, SMBHSTDAT);
+ outb_p(NCT6793D_WRITE_WORD, SMBHSTCMD);
+ }
+ else {
+ outb_p(NCT6793D_READ_WORD, SMBHSTCMD);
+ }
+ break;
+ case I2C_SMBUS_BLOCK_DATA:
+ outb_p((addr << 1) | read_write,
+ SMBHSTADD);
+ outb_p(command, SMBHSTIDX);
+ if (read_write == I2C_SMBUS_WRITE) {
+ len = data->block[0];
+ if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
+ return -EINVAL;
+ outb_p(len, SMBBLKSZ);
+
+ cnt = 1;
+ if (len >= 4) {
+ for (i = cnt; i <= 4; i++) {
+ outb_p(data->block[i], SMBHSTDAT);
+ }
+
+ len -= 4;
+ cnt += 4;
+ }
+ else {
+ for (i = cnt; i <= len; i++ ) {
+ outb_p(data->block[i], SMBHSTDAT);
+ }
+
+ len = 0;
+ }
+
+ outb_p(NCT6793D_WRITE_BLOCK, SMBHSTCMD);
+ }
+ else {
+ return -ENOTSUPP;
+ }
+ break;
+ default:
+ dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
+ return -EOPNOTSUPP;
+ }
+
+ outb_p(NCT6793D_MANUAL_START, SMBHSTCTL);
+
+ while ((size == I2C_SMBUS_BLOCK_DATA) && (len > 0)) {
+ if (read_write == I2C_SMBUS_WRITE) {
+ while ((inb_p(SMBHSTSTS) & NCT6793D_FIFO_EMPTY) == 0);
+
+ //Load more bytes into FIFO
+ if (len >= 4) {
+ for (i = cnt; i <= (cnt + 4); i++) {
+ outb_p(data->block[i], SMBHSTDAT);
+ }
+
+ len -= 4;
+ cnt += 4;
+ }
+ else {
+ for (i = cnt; i <= (cnt + len); i++) {
+ outb_p(data->block[i], SMBHSTDAT);
+ }
+
+ len = 0;
+ }
+ }
+ }
+
+ //wait for manual mode to complete
+ while ((inb_p(SMBHSTSTS) & NCT6793D_MANUAL_ACTIVE) != 0);
+
+ if ((inb_p(SMBHSTERR) & NCT6793D_NO_ACK) != 0) {
+ return -ENXIO;
+ }
+ else if ((read_write == I2C_SMBUS_WRITE) || (size == I2C_SMBUS_QUICK)) {
+ return 0;
+ }
+
+ switch (size) {
+ case I2C_SMBUS_QUICK:
+ case I2C_SMBUS_BYTE_DATA:
+ data->byte = inb_p(SMBHSTDAT);
+ break;
+ case I2C_SMBUS_WORD_DATA:
+ data->word = inb_p(SMBHSTDAT) + (inb_p(SMBHSTDAT) << 8);
+ break;
+ }
+ return 0;
+}
+
+static u32 nct6775_func(struct i2c_adapter *adapter)
+{
+ return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
+ I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
+ I2C_FUNC_SMBUS_BLOCK_DATA;
+}
+
+static const struct i2c_algorithm smbus_algorithm = {
+ .smbus_xfer = nct6775_access,
+ .functionality = nct6775_func,
+};
+
+static int nct6775_add_adapter(unsigned short smba, const char *name, struct i2c_adapter **padap)
+{
+ struct i2c_adapter *adap;
+ struct i2c_nct6775_adapdata *adapdata;
+ int retval;
+
+ adap = kzalloc(sizeof(*adap), GFP_KERNEL);
+ if (adap == NULL) {
+ return -ENOMEM;
+ }
+
+ adap->owner = THIS_MODULE;
+ adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
+ adap->algo = &smbus_algorithm;
+
+ adapdata = kzalloc(sizeof(*adapdata), GFP_KERNEL);
+ if (adapdata == NULL) {
+ kfree(adap);
+ return -ENOMEM;
+ }
+
+ adapdata->smba = smba;
+
+ snprintf(adap->name, sizeof(adap->name),
+ "SMBus NCT67xx adapter%s at %04x", name, smba);
+
+ i2c_set_adapdata(adap, adapdata);
+
+ retval = i2c_add_adapter(adap);
+ if (retval) {
+ kfree(adapdata);
+ kfree(adap);
+ return retval;
+ }
+
+ *padap = adap;
+ return 0;
+}
+
+static void nct6775_remove_adapter(struct i2c_adapter *adap)
+{
+ struct i2c_nct6775_adapdata *adapdata = i2c_get_adapdata(adap);
+
+ if (adapdata->smba) {
+ i2c_del_adapter(adap);
+ kfree(adapdata);
+ kfree(adap);
+ }
+}
+
+//static SIMPLE_DEV_PM_OPS(nct6775_dev_pm_ops, nct6775_suspend, nct6775_resume);
+
+/*
+ * when Super-I/O functions move to a separate file, the Super-I/O
+ * bus will manage the lifetime of the device and this module will only keep
+ * track of the nct6775 driver. But since we use platform_device_alloc(), we
+ * must keep track of the device
+ */
+static struct platform_device *pdev[2];
+
+static int nct6775_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct nct6775_sio_data *sio_data = dev_get_platdata(dev);
+ struct resource *res;
+
+ res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+ if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH,
+ DRVNAME))
+ return -EBUSY;
+
+ switch (sio_data->kind) {
+ case nct6791:
+ case nct6792:
+ case nct6793:
+ case nct6795:
+ case nct6796:
+ case nct6798:
+ nct6775_add_adapter(res->start, "", &nct6775_adapter);
+ break;
+ default:
+ return -ENODEV;
+ }
+
+ return 0;
+}
+/*
+static void nct6791_enable_io_mapping(int sioaddr)
+{
+ int val;
+
+ val = superio_inb(sioaddr, NCT6791_REG_HM_IO_SPACE_LOCK_ENABLE);
+ if (val & 0x10) {
+ pr_info("Enabling hardware monitor logical device mappings.\n");
+ superio_outb(sioaddr, NCT6791_REG_HM_IO_SPACE_LOCK_ENABLE,
+ val & ~0x10);
+ }
+}*/
+
+static struct platform_driver i2c_nct6775_driver = {
+ .driver = {
+ .name = DRVNAME,
+// .pm = &nct6775_dev_pm_ops,
+ },
+ .probe = nct6775_probe,
+};
+
+static void __exit i2c_nct6775_exit(void)
+{
+ int i;
+
+ if(nct6775_adapter)
+ nct6775_remove_adapter(nct6775_adapter);
+
+ for (i = 0; i < ARRAY_SIZE(pdev); i++) {
+ if (pdev[i])
+ platform_device_unregister(pdev[i]);
+ }
+ platform_driver_unregister(&i2c_nct6775_driver);
+}
+
+/* nct6775_find() looks for a '627 in the Super-I/O config space */
+static int __init nct6775_find(int sioaddr, struct nct6775_sio_data *sio_data)
+{
+ u16 val;
+ int err;
+ int addr;
+
+ err = superio_enter(sioaddr);
+ if (err)
+ return err;
+
+ val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) |
+ superio_inb(sioaddr, SIO_REG_DEVID + 1);
+
+ switch (val & SIO_ID_MASK) {
+ case SIO_NCT6106_ID:
+ sio_data->kind = nct6106;
+ break;
+ case SIO_NCT6775_ID:
+ sio_data->kind = nct6775;
+ break;
+ case SIO_NCT6776_ID:
+ sio_data->kind = nct6776;
+ break;
+ case SIO_NCT6779_ID:
+ sio_data->kind = nct6779;
+ break;
+ case SIO_NCT6791_ID:
+ sio_data->kind = nct6791;
+ break;
+ case SIO_NCT6792_ID:
+ sio_data->kind = nct6792;
+ break;
+ case SIO_NCT6793_ID:
+ sio_data->kind = nct6793;
+ break;
+ case SIO_NCT6795_ID:
+ sio_data->kind = nct6795;
+ break;
+ case SIO_NCT6796_ID:
+ sio_data->kind = nct6796;
+ break;
+ case SIO_NCT6798_ID:
+ sio_data->kind = nct6798;
+ break;
+ default:
+ if (val != 0xffff)
+ pr_debug("unsupported chip ID: 0x%04x\n", val);
+ superio_exit(sioaddr);
+ return -ENODEV;
+ }
+
+ /* We have a known chip, find the SMBus I/O address */
+ superio_select(sioaddr, NCT6775_LD_SMBUS);
+ val = (superio_inb(sioaddr, SIO_REG_SMBA) << 8)
+ | superio_inb(sioaddr, SIO_REG_SMBA + 1);
+ addr = val & IOREGION_ALIGNMENT;
+ if (addr == 0) {
+ pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n");
+ superio_exit(sioaddr);
+ return -ENODEV;
+ }
+
+ //if (sio_data->kind == nct6791 || sio_data->kind == nct6792 ||
+ // sio_data->kind == nct6793 || sio_data->kind == nct6795 ||
+ // sio_data->kind == nct6796)
+ // nct6791_enable_io_mapping(sioaddr);
+
+ superio_exit(sioaddr);
+ pr_info("Found %s or compatible chip at %#x:%#x\n",
+ nct6775_sio_names[sio_data->kind], sioaddr, addr);
+ sio_data->sioreg = sioaddr;
+
+ return addr;
+}
+
+static int __init i2c_nct6775_init(void)
+{
+ int i, err;
+ bool found = false;
+ int address;
+ struct resource res;
+ struct nct6775_sio_data sio_data;
+ int sioaddr[2] = { 0x2e, 0x4e };
+
+ err = platform_driver_register(&i2c_nct6775_driver);
+ if (err)
+ return err;
+
+ /*
+ * initialize sio_data->kind and sio_data->sioreg.
+ *
+ * when Super-I/O functions move to a separate file, the Super-I/O
+ * driver will probe 0x2e and 0x4e and auto-detect the presence of a
+ * nct6775 hardware monitor, and call probe()
+ */
+ for (i = 0; i < ARRAY_SIZE(pdev); i++) {
+ address = nct6775_find(sioaddr[i], &sio_data);
+ if (address <= 0)
+ continue;
+
+ found = true;
+
+ pdev[i] = platform_device_alloc(DRVNAME, address);
+ if (!pdev[i]) {
+ err = -ENOMEM;
+ goto exit_device_unregister;
+ }
+
+ err = platform_device_add_data(pdev[i], &sio_data,
+ sizeof(struct nct6775_sio_data));
+ if (err)
+ goto exit_device_put;
+
+ memset(&res, 0, sizeof(res));
+ res.name = DRVNAME;
+ res.start = address;
+ res.end = address + IOREGION_LENGTH - 1;
+ res.flags = IORESOURCE_IO;
+
+ err = acpi_check_resource_conflict(&res);
+ if (err) {
+ platform_device_put(pdev[i]);
+ pdev[i] = NULL;
+ continue;
+ }
+
+ err = platform_device_add_resources(pdev[i], &res, 1);
+ if (err)
+ goto exit_device_put;
+
+ /* platform_device_add calls probe() */
+ err = platform_device_add(pdev[i]);
+ if (err)
+ goto exit_device_put;
+ }
+ if (!found) {
+ err = -ENODEV;
+ goto exit_unregister;
+ }
+
+ return 0;
+
+exit_device_put:
+ platform_device_put(pdev[i]);
+exit_device_unregister:
+ while (--i >= 0) {
+ if (pdev[i])
+ platform_device_unregister(pdev[i]);
+ }
+exit_unregister:
+ platform_driver_unregister(&i2c_nct6775_driver);
+ return err;
+}
+
+MODULE_AUTHOR("Adam Honse <[email protected]>");
+MODULE_DESCRIPTION("SMBus driver for NCT6775F and compatible chips");
+MODULE_LICENSE("GPL");
+
+module_init(i2c_nct6775_init);
+module_exit(i2c_nct6775_exit);
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index c46c4bddc7ca..8565d08178a2 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -468,11 +468,11 @@ static int piix4_transaction(struct i2c_adapter *piix4_adapter)
if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
usleep_range(2000, 2100);
else
- usleep_range(250, 500);
+ usleep_range(25, 50);
while ((++timeout < MAX_TIMEOUT) &&
((temp = inb_p(SMBHSTSTS)) & 0x01))
- usleep_range(250, 500);
+ usleep_range(25, 50);
/* If the SMBus is still busy, we give up */
if (timeout == MAX_TIMEOUT) {
@@ -963,6 +963,11 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
retval = piix4_setup_sb800(dev, id, 1);
}
+ if (dev->vendor == PCI_VENDOR_ID_AMD &&
+ dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) {
+ retval = piix4_setup_sb800(dev, id, 1);
+ }
+
if (retval > 0) {
/* Try to add the aux adapter if it exists,
* piix4_add_adapter will clean up if this fails */
+163
View File
@@ -0,0 +1,163 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenRGB
TEMPLATE = app
INCLUDEPATH += \
i2c_smbus/ \
i2c_tools/ \
net_port/ \
serial_port/ \
Controllers/AMDWraithPrismController/ \
Controllers/AuraController/ \
Controllers/CorsairController/ \
Controllers/CorsairProController/ \
Controllers/HuePlusController/ \
Controllers/HyperXController/ \
Controllers/LEDStripController/ \
Controllers/PolychromeController/ \
Controllers/RGBFusionController/ \
RGBController/ \
qt/
SOURCES += \
main.cpp \
OpenAuraSDK.cpp \
qt/OpenRGBDeviceInfoPage.cpp \
qt/OpenRGBDevicePage.cpp \
qt/OpenRGBDialog.cpp \
i2c_smbus/i2c_smbus.cpp \
i2c_tools/i2c_tools.cpp \
net_port/net_port.cpp \
qt/OpenRGBDialog2.cpp \
qt/OpenRGBSystemInfoPage.cpp \
qt/hsv.cpp \
serial_port/serial_port.cpp \
Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp \
Controllers/AMDWraithPrismController/AMDWraithPrismControllerDetect.cpp \
Controllers/AuraController/AuraController.cpp \
Controllers/AuraController/AuraControllerDetect.cpp \
Controllers/CorsairController/CorsairController.cpp \
Controllers/CorsairController/CorsairControllerDetect.cpp \
Controllers/CorsairProController/CorsairProController.cpp \
Controllers/CorsairProController/CorsairProControllerDetect.cpp \
Controllers/HuePlusController/HuePlusController.cpp \
Controllers/HuePlusController/HuePlusControllerDetect.cpp \
Controllers/HyperXController/HyperXController.cpp \
Controllers/HyperXController/HyperXControllerDetect.cpp \
Controllers/LEDStripController/LEDStripController.cpp \
Controllers/LEDStripController/LEDStripControllerDetect.cpp \
Controllers/PolychromeController/PolychromeController.cpp \
Controllers/RGBFusionController/RGBFusionController.cpp \
Controllers/RGBFusionController/RGBFusionControllerDetect.cpp \
RGBController/RGBController_AMDWraithPrism.cpp \
RGBController/RGBController_Aura.cpp \
RGBController/RGBController_Corsair.cpp \
RGBController/RGBController_CorsairPro.cpp \
RGBController/RGBController_HuePlus.cpp \
RGBController/RGBController_HyperX.cpp \
RGBController/RGBController_LEDStrip.cpp \
RGBController/RGBController_RGBFusion.cpp
HEADERS += \
Controllers/RGBFusionController/RGBFusionController.h \
qt/OpenRGBDeviceInfoPage.h \
qt/OpenRGBDevicePage.h \
qt/OpenRGBDialog.h \
i2c_smbus/i2c_smbus.h \
i2c_tools/i2c_tools.h \
net_port/net_port.h \
qt/OpenRGBDialog2.h \
qt/OpenRGBSystemInfoPage.h \
serial_port/serial_port.h \
Controllers/AMDWraithPrismController/AMDWraithPrismController.h \
Controllers/AuraController/AuraController.h \
Controllers/CorsairController/CorsairController.h \
Controllers/CorsairProController/CorsairProController.h \
Controllers/HuePlusController/HuePlusController.h \
Controllers/HyperXController/HyperXController.h \
Controllers/LEDStripController/LEDStripController.h \
RGBController/RGBController.h \
RGBController/RGBController_AMDWraithPrism.h \
RGBController/RGBController_Aura.h \
RGBController/RGBController_Corsair.h \
RGBController/RGBController_CorsairPro.h \
RGBController/RGBController_HuePlus.h \
RGBController/RGBController_HyperX.h \
RGBController/RGBController_Polychrome.h \
RGBController/RGBController_RGBFusion.h
RESOURCES += \
qt/resources.qrc
FORMS += \
qt/OpenRGBDeviceInfoPage.ui \
qt/OpenRGBDevicePage.ui \
qt/OpenRGBDialog.ui \
qt/OpenRGBDialog2.ui \
qt/OpenRGBSystemInfoPage.ui
#-----------------------------------------------
# Windows specific project configuration
#-----------------------------------------------
win32:INCLUDEPATH += \
dependencies/inpout32_1501/Win32/ \
dependencies/razer-chroma-2.9.0/inc \
dependencies/libusb-1.0.22/include \
wmi/ \
win32:SOURCES += \
i2c_smbus/i2c_smbus_i801.cpp \
i2c_smbus/i2c_smbus_nct6775.cpp \
i2c_smbus/i2c_smbus_piix4.cpp \
wmi/wmi.cpp \
RGBController/RGBController_AorusGPU.cpp \
RGBController/RazerChromaSDKDetect.cpp \
RGBController/RGBController_RazerChromaSDK.cpp \
win32:HEADERS += \
dependencies/inpout32_1501/Win32/inpout32.h \
i2c_smbus/i2c_smbus_i801.h \
i2c_smbus/i2c_smbus_nct6775.h \
i2c_smbus/i2c_smbus_piix4.h \
wmi/wmi.h \
RGBController/RGBController_AorusGPU.h \
RGBController/RGBController_RazerChromaSDK.h \
win32:LIBS += \
-lws2_32 \
-L"$$PWD/dependencies/inpout32_1501/Win32/" -linpout32 \
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0
win32:DEFINES -= \
UNICODE
win32:DEFINES += \
_MBCS \
WIN32 \
_CRT_SECURE_NO_WARNINGS \
_WINSOCK_DEPRECATED_NO_WARNINGS \
WIN32_LEAN_AND_MEAN
#-----------------------------------------------
# Linux specific project configuration
#-----------------------------------------------
unix:INCLUDEPATH += \
dependencies/libe131/src/ \
unix:HEADERS += \
i2c_smbus/i2c_smbus_linux.h \
RGBController/RGBController_E131.h \
unix:LIBS += \
-lusb-1.0
unix:SOURCES += \
dependencies/libe131/src/e131.c \
i2c_smbus/i2c_smbus_linux.cpp \
RGBController/OpenRazerDetect.cpp \
RGBController/E131ControllerDetect.cpp \
RGBController/RGBController_E131.cpp \
RGBController/RGBController_OpenRazer.cpp \
+63
View File
@@ -0,0 +1,63 @@
# OpenRGB (formerly OpenAuraSDK)
The goal of this project is to create an easy-to-use open source software program and library for accessing and controlling RGB lights on various PC hardware including motherboards, RAM modules, graphics cards, cooling devices, and peripherals.
This project originally focused only on ASUS Aura. It was spun off of Keyboard Visualizer's AsusAuraWindows branch to learn more about the details behind the Aura protocol and to develop a more flexible, compatible, and reliable driver for Aura. Our Aura implementation is now quite solid and supports multiple generations of Aura controller across both Intel and AMD platforms. It also supports Aura-compatible controllers used across multiple manufacturers of RGB memory modules including G.Skill Trident Z RGB and others. It is still lacking a few capabilities, namely saving settings to persist across reboots, but the core functionality of setting colors and modes is there.
After getting a solid Aura implementation, the project branched out into other manufacturers and categories of RGB devices. A major focus was to develop a software API that could reliably represent as many RGB devices as possible, exposing their various modes and describing their LED layouts via zones, that was generic enough to write a user application without specifically targeting any one manufacturer. To this extent, the generic_rgb_interface_test branch was created which became the foundation of OpenRGB. The goal of OpenRGB is to both develop new drivers for unsupported devices and integrate existing open source drivers for devices that do have some sort of open support. The goal is to be the one-stop solution to open source RGB lighting control!
## Supported Devices
* Asus Aura (SMBus variants only)
* Gigabyte RGB Fusion 1.0
* Asus Aura RAM
* Corsair Vengeance RGB
* Corsair Vengeance Pro RGB
* HyperX Predator RGB
* NZXT Hue+
* KeyboardVisualizer Arduino LED Strips
* E1.31 (Linux only)
* OpenRazer (Linux only)
## Installation
#### Windows
1. Download the latest Visual Studio Community Edition and Qt Creator.
2. Open the OpenRGB_Win.pro project.
3. Build the project for `x86` Architecture. The InpOut32 library I use does not support x64.
4. Copy InpOut32.dll from dependencies to the same path as OpenAuraSDK.exe along with the Qt libraries.
**You must run the application as Administrator the first time to allow InpOut32 to set up. It can be run as a normal user afterwards**
#### Linux:
1. Either open the project using QT Creator or build it using qmake.
cd OpenAuraSDK
qmake OpenAuraSDK.pro
make
2. Allow access to SMBus:<br>
- This can be identified by your motherboard
##### Intel
- `modprobe i2c-dev i2c-i801`
- Asus used the SMBus controller on the Super IO chip for on-board Aura chips on Intel motherboards. I have a kernel patch to add a driver for this chip [here](https://gitlab.com/CalcProgrammer1/OpenAuraSDK/issues/22). After patching the kernel, enable the Nuvoton NCT67xx SMBus driver in your kernel configuration. The driver may be loaded with `modprobe i2c-nct6775`
##### AMD
- `modprobe i2c-dev i2c-piix4`
- The second SMBus isn't currently picked up by the kernel driver and that seems to be where Asus wired the Aura controllers so I have a kernel patch [here](https://gitlab.com/CalcProgrammer1/OpenAuraSDK/issues/9) that will allow the kernel to use the second bus (at `0x0b20`).
- You'll have to enable user access to your SMbus if you don't run as root.
- List all SMBus controllers: `sudo i2cdetect -l`
- Find out which control your Aura devices (PIIX4, I801, and NCT67xx)
- Give user access to those controllers, for instance: `sudo chmod 777 /dev/i2c-0`
+170
View File
@@ -0,0 +1,170 @@
#include "RGBController.h"
#include "RGBController_E131.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <string>
#ifndef WIN32
#include <unistd.h>
#include <dirent.h>
#endif
#ifndef WIN32
#define LPSTR char *
#define strtok_s strtok_r
#endif
/******************************************************************************************\
* *
* DetectE131Controllers *
* *
* Detect devices supported by the E131 driver *
* * *
\******************************************************************************************/
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
{
RGBController_E131* new_controller;
//Get file path in executable directory
std::ifstream infile;
char filename[2048];
char arg1[64];
#ifdef WIN32
GetModuleFileName(NULL, filename, 2048);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "\\e131.txt");
#else
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "/e131.txt");
#endif
E131Device dev;
std::vector<E131Device> devices;
bool new_device = false;
//Open settings file
infile.open(filename);
if (infile.good())
{
for (std::string line; std::getline(infile, line); )
{
if (new_device)
{
dev.name = line;
new_device = false;
}
if (line == "")
{
continue;
}
if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/'))
{
char * argument;
char * value;
value = (char *)line.c_str();
argument = strtok_s(value, "=", &value);
//Strip off new line characters if present
argument = strtok(argument, "\r\n");
value = strtok(value, "\r\n");
if(argument)
{
if (strcmp(argument, "e131_device_start") == 0)
{
new_device = true;
}
else if(strcmp(argument, "num_leds") == 0)
{
dev.num_leds = atoi(value);
}
else if(strcmp(argument, "start_universe") == 0)
{
dev.start_universe = atoi(value);
}
else if(strcmp(argument, "start_channel") == 0)
{
dev.start_channel = atoi(value);
}
else if(strcmp(argument, "rgb_order") == 0)
{
if(strcmp(value, "RGB") == 0)
{
dev.rgb_order = E131_RGB_ORDER_RGB;
}
else if(strcmp(value, "RBG") == 0)
{
dev.rgb_order = E131_RGB_ORDER_RBG;
}
else if(strcmp(value, "GRB") == 0)
{
dev.rgb_order = E131_RGB_ORDER_GRB;
}
else if(strcmp(value, "GBR") == 0)
{
dev.rgb_order = E131_RGB_ORDER_GBR;
}
else if(strcmp(value, "BRG") == 0)
{
dev.rgb_order = E131_RGB_ORDER_BRG;
}
else if(strcmp(value, "BGR") == 0)
{
dev.rgb_order = E131_RGB_ORDER_BGR;
}
else
{
dev.rgb_order = atoi(value);
}
}
else if(strcmp(argument, "type") == 0)
{
if(strcmp(value, "SINGLE") == 0)
{
dev.type = ZONE_TYPE_SINGLE;
}
else if(strcmp(value, "LINEAR") == 0)
{
dev.type = ZONE_TYPE_LINEAR;
}
else if(strcmp(value, "MATRIX") == 0)
{
dev.type = ZONE_TYPE_MATRIX;
}
else
{
dev.type = atoi(value);
}
}
else if(strcmp(argument, "e131_device_end") == 0)
{
devices.push_back(dev);
}
}
}
}
if(devices.size() > 0)
{
new_controller = new RGBController_E131(devices);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectLEDStripControllers() */
+127
View File
@@ -0,0 +1,127 @@
#include "RGBController.h"
#include "RGBController_OpenRazer.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
/******************************************************************************************\
* *
* DetectOpenRazerControllers *
* *
* Detect devices supported by the OpenRazer kernel drivers *
* * *
\******************************************************************************************/
void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers)
{
char driver_path[512];
DIR *dir;
struct dirent *ent;
int test_fd;
bool done = false;
int driver_to_read = 0;
while(driver_to_read < 8)
{
switch(driver_to_read)
{
case 0:
strcpy(driver_path, "/sys/bus/hid/drivers/razerkbd/");
break;
case 1:
strcpy(driver_path, "/sys/bus/hid/drivers/razermouse/");
break;
case 2:
strcpy(driver_path, "/sys/bus/hid/drivers/razerfirefly/");
break;
case 3:
strcpy(driver_path, "/sys/bus/hid/drivers/razermug/");
break;
case 4:
strcpy(driver_path, "/sys/bus/hid/drivers/razercore/");
break;
case 5:
strcpy(driver_path, "/sys/bus/hid/drivers/razerkraken/");
break;
case 6:
strcpy(driver_path, "/sys/bus/hid/drivers/razermousemat/");
break;
case 7:
strcpy(driver_path, "/sys/bus/hid/drivers/razerchromahdk/");
break;
}
done = false;
dir = opendir(driver_path);
if(dir == NULL)
{
closedir(dir);
driver_to_read++;
continue;
}
ent = readdir(dir);
while(ent != NULL)
{
if(ent->d_type == DT_DIR || ent->d_type == DT_LNK)
{
if(!strcmp(ent->d_name, "."))
{
if(done == false)
{
done = true;
}
else
{
break;
}
}
else if(!strcmp(ent->d_name, "..") || !strcmp(ent->d_name, "module"))
{
}
else
{
int device_type;
char device_string[1024];
strcpy(device_string, driver_path);
strcat(device_string, ent->d_name);
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(device_string);
if(razer_rgb->device != -1)
{
rgb_controllers.push_back(razer_rgb);
}
else
{
delete razer_rgb;
}
}
}
ent = readdir(dir);
}
closedir(dir);
driver_to_read++;
}
} /* DetectOpenRazerControllers() */
+87
View File
@@ -0,0 +1,87 @@
/*-----------------------------------------*\
| RGBController.h |
| |
| Definitions and types for generic RGB |
| lighting controller interface |
| |
| Adam Honse (CalcProgrammer1) 6/2/2019 |
\*-----------------------------------------*/
#pragma once
#include <vector>
#include <string>
typedef unsigned int RGBColor;
#define RGBGetRValue(rgb) (rgb & 0x000000FF)
#define RGBGetGValue(rgb) ((rgb >> 8) & 0x000000FF)
#define RGBGetBValue(rgb) ((rgb >> 16) & 0x000000FF)
#define ToRGBColor(r, g, b) ((b << 16) | (g << 8) | (r))
typedef struct
{
std::string name; /* LED name */
} led;
typedef struct
{
std::string name; /* Mode name */
} mode;
typedef int zone_type;
enum
{
ZONE_TYPE_SINGLE,
ZONE_TYPE_LINEAR,
ZONE_TYPE_MATRIX
};
typedef int device_type;
enum
{
DEVICE_TYPE_MOTHERBOARD,
DEVICE_TYPE_DRAM,
DEVICE_TYPE_GPU,
DEVICE_TYPE_COOLER,
DEVICE_TYPE_LEDSTRIP,
DEVICE_TYPE_KEYBOARD,
DEVICE_TYPE_MOUSE,
DEVICE_TYPE_MOUSEMAT,
DEVICE_TYPE_HEADSET,
DEVICE_TYPE_UNKNOWN
};
typedef struct
{
std::string name; /* Zone name */
zone_type type; /* Zone type */
std::vector<std::vector<int>>
map; /* LED index map */
} zone;
class RGBController
{
public:
std::string name; /* controller name */
std::string description; /* controller description */
std::string version; /* controller version */
std::string serial; /* controller serial number */
std::string location; /* controller location */
std::vector<led> leds; /* LEDs */
std::vector<zone> zones; /* Zones */
std::vector<mode> modes; /* Modes */
std::vector<RGBColor> colors; /* Color buffer */
device_type type; /* device type */
virtual int GetMode() = 0;
virtual void SetMode(int mode) = 0;
virtual void SetCustomMode() = 0;
virtual void SetAllLEDs(RGBColor color) = 0;
virtual void SetAllZoneLEDs(int zone, RGBColor color) = 0;
virtual void SetLED(int led, RGBColor color) = 0;
virtual void UpdateLEDs() = 0;
};
@@ -0,0 +1,135 @@
/*-----------------------------------------*\
| RGBController_AMDWraithPrism.cpp |
| |
| Generic RGB Interface for AMD Wraith |
| Prism |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController_AMDWraithPrism.h"
RGBController_AMDWraithPrism::RGBController_AMDWraithPrism(AMDWraithPrismController* wraith_ptr)
{
wraith = wraith_ptr;
name = "AMD Wraith Prism";
type = DEVICE_TYPE_COOLER;
version = wraith->GetFirmwareVersionString();
mode led_mode;
led_mode.name = "Custom";
modes.push_back(led_mode);
led logo_led;
logo_led.name = "Logo";
leds.push_back(logo_led);
zone logo_zone;
logo_zone.name = "Logo";
logo_zone.type = ZONE_TYPE_SINGLE;
std::vector<int> logo_zone_map;
logo_zone_map.push_back(0);
logo_zone.map.push_back(logo_zone_map);
zones.push_back(logo_zone);
led fan_led;
fan_led.name = "Fan";
leds.push_back(fan_led);
zone fan_zone;
fan_zone.name = "Fan";
fan_zone.type = ZONE_TYPE_SINGLE;
std::vector<int> fan_zone_map;
fan_zone_map.push_back(1);
fan_zone.map.push_back(fan_zone_map);
zones.push_back(fan_zone);
led ring_led;
ring_led.name = "Ring";
leds.push_back(ring_led);
zone ring_zone;
ring_zone.name = "Ring";
ring_zone.type = ZONE_TYPE_SINGLE;
std::vector<int> ring_zone_map;
ring_zone_map.push_back(2);
ring_zone.map.push_back(ring_zone_map);
zones.push_back(ring_zone);
}
RGBController_AMDWraithPrism::~RGBController_AMDWraithPrism()
{
}
int RGBController_AMDWraithPrism::GetMode()
{
return 0;
}
void RGBController_AMDWraithPrism::SetMode(int mode)
{
}
void RGBController_AMDWraithPrism::SetCustomMode()
{
}
void RGBController_AMDWraithPrism::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
wraith->SetFanColor(red, grn, blu);
wraith->SetLogoColor(red, grn, blu);
wraith->SetRingColor(red, grn, blu);
}
void RGBController_AMDWraithPrism::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if(zone == 0)
{
wraith->SetLogoColor(red, grn, blu);
}
else if(zone == 1)
{
wraith->SetFanColor(red, grn, blu);
}
else if(zone == 2)
{
wraith->SetRingColor(red, grn, blu);
}
}
void RGBController_AMDWraithPrism::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if(led == 0)
{
wraith->SetLogoColor(red, grn, blu);
}
else if(led == 1)
{
wraith->SetFanColor(red, grn, blu);
}
else if(led == 2)
{
wraith->SetRingColor(red, grn, blu);
}
}
void RGBController_AMDWraithPrism::UpdateLEDs()
{
}
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_AMDWraithPrism.h |
| |
| Generic RGB Interface for AMD Wraith |
| Prism |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "AMDWraithPrismController.h"
class RGBController_AMDWraithPrism : public RGBController
{
public:
RGBController_AMDWraithPrism(AMDWraithPrismController* wraith_ptr);
~RGBController_AMDWraithPrism();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
AMDWraithPrismController* wraith;
};
+98
View File
@@ -0,0 +1,98 @@
/*-----------------------------------------*\
| RGBController_AorusGPU.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| Aorus GPU |
| |
| Adam Honse (CalcProgrammer1) 6/17/2019 |
\*-----------------------------------------*/
#include "RGBController_AorusGPU.h"
#include <Windows.h>
static HMODULE handle;
static unsigned char data[] = { 0x8E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x64, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00 };
int RGBController_AorusGPU::GetMode()
{
return(0);
}
void RGBController_AorusGPU::SetMode(int mode)
{
}
void RGBController_AorusGPU::SetCustomMode()
{
}
void RGBController_AorusGPU::SetAllLEDs(RGBColor color)
{
data[9] = RGBGetRValue(color);
data[10] = RGBGetGValue(color);
data[11] = RGBGetBValue(color);
GvWriteI2C(0x00000000, data, 0x00000000);
}
void RGBController_AorusGPU::SetAllZoneLEDs(int zone, RGBColor color)
{
data[9] = RGBGetRValue(color);
data[10] = RGBGetGValue(color);
data[11] = RGBGetBValue(color);
GvWriteI2C(0x00000000, data, 0x00000000);
}
void RGBController_AorusGPU::SetLED(int led, RGBColor color)
{
data[9] = RGBGetRValue(color);
data[10] = RGBGetGValue(color);
data[11] = RGBGetBValue(color);
GvWriteI2C(0x00000000, data, 0x00000000);
}
void RGBController_AorusGPU::UpdateLEDs()
{
}
RGBController_AorusGPU::RGBController_AorusGPU()
{
name = "Aorus GPU";
type = DEVICE_TYPE_GPU;
handle = LoadLibrary("GvDisplay.dll");
GvWriteI2C = (_GvWriteI2C)GetProcAddress(handle, "GvWriteI2C");
GvFreeDispLib = (_GvFreeDispLib)GetProcAddress(handle, "GvFreeDispLib");
GvInitDispLib = (_GvInitDispLib)GetProcAddress(handle, "GvInitDispLib");
GvFreeDispLib();
GvInitDispLib();
mode aorus_mode;
aorus_mode.name = "Static";
modes.push_back(aorus_mode);
led aorus_led;
aorus_led.name = "GPU LED";
leds.push_back(aorus_led);
zone aorus_zone;
aorus_zone.name = "GPU LED";
std::vector<int> aorus_zone_map;
aorus_zone_map.push_back(0);
aorus_zone.map.push_back(aorus_zone_map);
zones.push_back(aorus_zone);
}
+34
View File
@@ -0,0 +1,34 @@
/*-----------------------------------------*\
| RGBController_AorusGPU.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| Aorus GPU |
| |
| Adam Honse (CalcProgrammer1) 6/17/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
typedef unsigned int uint32;
typedef uint32(*_GvWriteI2C)(uint32, void*, uint32);
typedef void (*_GvFreeDispLib)();
typedef void (*_GvInitDispLib)();
class RGBController_AorusGPU : public RGBController
{
public:
RGBController_AorusGPU();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
_GvWriteI2C GvWriteI2C;
_GvFreeDispLib GvFreeDispLib;
_GvInitDispLib GvInitDispLib;
};
+214
View File
@@ -0,0 +1,214 @@
/*-----------------------------------------*\
| RGBController_Aura.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| Asus Aura driver |
| |
| Adam Honse (CalcProgrammer1) 6/13/2019 |
\*-----------------------------------------*/
#include "RGBController_Aura.h"
int RGBController_Aura::GetMode()
{
if (aura->AuraRegisterRead(AURA_REG_DIRECT))
{
return(0);
}
else
{
return(aura->AuraRegisterRead(AURA_REG_MODE) + 1);
}
}
void RGBController_Aura::SetMode(int mode)
{
if (mode == 0)
{
aura->SetDirect(true);
}
else
{
aura->SetMode(mode - 1);
aura->SetDirect(false);
}
}
void RGBController_Aura::SetCustomMode()
{
aura->SetDirect(true);
}
void RGBController_Aura::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if (GetMode() == 0)
{
aura->SetAllColorsDirect(red, grn, blu);
}
else
{
aura->SetAllColorsEffect(red, grn, blu);
}
}
void RGBController_Aura::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
if (GetMode() == 0)
{
aura->SetLEDColorDirect(zones[zone].map[x][y], red, grn, blu);
}
else
{
aura->SetLEDColorEffect(zones[zone].map[x][y], red, grn, blu);
}
}
}
}
void RGBController_Aura::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if (GetMode() == 0)
{
aura->SetLEDColorDirect(led, red, grn, blu);
}
else
{
aura->SetLEDColorEffect(led, red, grn, blu);
}
}
void RGBController_Aura::UpdateLEDs()
{
for(int led = 0; led < colors.size(); led++)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
if (GetMode() == 0)
{
aura->SetLEDColorDirect(led, red, grn, blu);
}
else
{
aura->SetLEDColorEffect(led, red, grn, blu);
}
}
}
RGBController_Aura::RGBController_Aura(AuraController * aura_ptr)
{
std::vector<unsigned char> aura_channels;
aura = aura_ptr;
version = aura->GetDeviceName();
location = aura->GetDeviceLocation();
if((version.find("DIMM_LED") != std::string::npos) || (version.find("AUDA") != std::string::npos) )
{
type = DEVICE_TYPE_DRAM;
name = "ASUS Aura DRAM";
}
else
{
type = DEVICE_TYPE_MOTHERBOARD;
name = "ASUS Aura Motherboard";
}
mode aura_modes[AURA_NUMBER_MODES + 1];
aura_modes[0].name = "Direct";
aura_modes[1].name = "Off";
aura_modes[2].name = "Static";
aura_modes[3].name = "Breathing";
aura_modes[4].name = "Flashing";
aura_modes[5].name = "Spectrum Cycle";
aura_modes[6].name = "Rainbow";
aura_modes[7].name = "Spectrum Cycle Breathing";
aura_modes[8].name = "Chase Fade";
aura_modes[9].name = "Spectrum Cycle Chase Fade";
aura_modes[10].name = "Chase";
aura_modes[11].name = "Spectrum Cycle Chase";
aura_modes[12].name = "Spectrum Cycle Wave";
aura_modes[13].name = "Chase Rainbow Pulse";
aura_modes[14].name = "Random Flicker";
for (int i = 0; i < (AURA_NUMBER_MODES + 1); i++)
{
modes.push_back(aura_modes[i]);
}
for (int i = 0; i < aura->GetLEDCount(); i++)
{
aura_channels.push_back(aura->GetChannel(i));
led* new_led = new led();
new_led->name = aura->GetChannelName(i);
leds.push_back(*new_led);
colors.push_back(0x00000000);
}
std::vector<unsigned char> aura_zones;
// Search through all LEDs and create zones for each channel type
for (int i = 0; i < aura_channels.size(); i++)
{
bool matched = false;
// Search through existing zones to make sure we don't create a duplicate zone
for (int j = 0; j < aura_zones.size(); j++)
{
if (aura_channels[i] == aura_zones[j])
{
matched = true;
}
}
// If zone does not already exist, create it
if (matched == false)
{
zone* new_zone = new zone();
std::vector<int>* zone_row = new std::vector<int>();
// Set zone name to channel name
new_zone->name = aura->GetChannelName(i);
// Find all LEDs with this channel type and add them to zone
for (int j = 0; j < aura->GetLEDCount(); j++)
{
if (aura->GetChannel(j) == aura_channels[i])
{
zone_row->push_back(j);
}
}
// Aura devices can be either single or linear, never matrix
// That means only one row is needed
new_zone->map.push_back(*zone_row);
// Save channel to aura_zones so we know not to create another zone with this channel
aura_zones.push_back(aura_channels[i]);
// Push new zone to zones vector
zones.push_back(*new_zone);
}
}
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_Aura.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| Asus Aura driver |
| |
| Adam Honse (CalcProgrammer1) 6/13/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "AuraController.h"
class RGBController_Aura : public RGBController
{
public:
RGBController_Aura(AuraController* aura_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
AuraController* aura;
};
+110
View File
@@ -0,0 +1,110 @@
/*-----------------------------------------*\
| RGBController_Corsair.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| Corsair Vengeance RGB driver |
| |
| Adam Honse (CalcProgrammer1) 6/13/2019 |
\*-----------------------------------------*/
#include "RGBController_Corsair.h"
int RGBController_Corsair::GetMode()
{
return(CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
}
void RGBController_Corsair::SetMode(int mode)
{
corsair->SetMode(mode);
}
void RGBController_Corsair::SetCustomMode()
{
}
void RGBController_Corsair::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
corsair->SetAllColors(red, grn, blu);
}
void RGBController_Corsair::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
corsair->SetLEDColor(zones[zone].map[x][y], red, grn, blu);
}
}
}
void RGBController_Corsair::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
corsair->SetLEDColor(led, red, grn, blu);
}
void RGBController_Corsair::UpdateLEDs()
{
}
RGBController_Corsair::RGBController_Corsair(CorsairController* corsair_ptr)
{
corsair = corsair_ptr;
name = corsair->GetDeviceName();
location = corsair->GetDeviceLocation();
type = DEVICE_TYPE_DRAM;
mode corsair_modes[CORSAIR_NUMBER_MODES];
corsair_modes[0].name = "Static";
corsair_modes[1].name = "Fade";
corsair_modes[2].name = "Pulse";
for (int i = 0; i < CORSAIR_NUMBER_MODES; i++)
{
modes.push_back(corsair_modes[i]);
}
for (int i = 0; i < corsair->GetLEDCount(); i++)
{
led* new_led = new led();
new_led->name = "Corsair LED";
leds.push_back(*new_led);
colors.push_back(0x00000000);
}
zone new_zone;
new_zone.name = "Corsair Zone";
new_zone.type = ZONE_TYPE_SINGLE;
std::vector<int> zone_row;
for (int i = 0; i < corsair->GetLEDCount(); i++)
{
zone_row.push_back(i);
}
new_zone.map.push_back(zone_row);
zones.push_back(new_zone);
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_Corsair.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| Corsair Vengeance RGB driver |
| |
| Adam Honse (CalcProgrammer1) 6/13/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CorsairController.h"
class RGBController_Corsair : public RGBController
{
public:
RGBController_Corsair(CorsairController* corsair_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
CorsairController* corsair;
};
+153
View File
@@ -0,0 +1,153 @@
/*-----------------------------------------*\
| RGBController_CorsairPro.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| Corsair Vengeance Pro RGB driver |
| |
| Adam Honse (CalcProgrammer1) 6/30/2019 |
\*-----------------------------------------*/
#include "RGBController_CorsairPro.h"
int RGBController_CorsairPro::GetMode()
{
return(0);
}
void RGBController_CorsairPro::SetMode(int mode)
{
switch (mode)
{
case 0:
corsair->SetEffect(CORSAIR_PRO_MODE_COLOR_SHIFT);
break;
case 1:
corsair->SetEffect(CORSAIR_PRO_MODE_COLOR_PULSE);
break;
case 2:
corsair->SetEffect(CORSAIR_PRO_MODE_RAINBOW_WAVE);
break;
case 3:
corsair->SetEffect(CORSAIR_PRO_MODE_COLOR_WAVE);
break;
case 4:
corsair->SetEffect(CORSAIR_PRO_MODE_VISOR);
break;
case 5:
corsair->SetEffect(CORSAIR_PRO_MODE_RAIN);
break;
case 6:
corsair->SetEffect(CORSAIR_PRO_MODE_MARQUEE);
break;
case 7:
corsair->SetEffect(CORSAIR_PRO_MODE_RAINBOW);
break;
case 8:
corsair->SetEffect(CORSAIR_PRO_MODE_SEQUENTIAL);
break;
case 9:
corsair->SetEffect(CORSAIR_PRO_MODE_STATIC);
break;
}
}
void RGBController_CorsairPro::SetCustomMode()
{
corsair->SetCustom();
}
void RGBController_CorsairPro::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
corsair->SetAllColors(red, grn, blu);
corsair->ApplyColors();
}
void RGBController_CorsairPro::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
corsair->SetLEDColor(zones[zone].map[x][y], red, grn, blu);
}
}
corsair->ApplyColors();
}
void RGBController_CorsairPro::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
corsair->SetLEDColor(led, red, grn, blu);
corsair->ApplyColors();
}
void RGBController_CorsairPro::UpdateLEDs()
{
}
RGBController_CorsairPro::RGBController_CorsairPro(CorsairProController* corsair_ptr)
{
corsair = corsair_ptr;
name = corsair->GetDeviceName();
location = corsair->GetDeviceLocation();
type = DEVICE_TYPE_DRAM;
mode corsair_modes[CORSAIR_PRO_NUMBER_MODES];
corsair_modes[0].name = "Color Shift";
corsair_modes[1].name = "Color Pulse";
corsair_modes[2].name = "Rainbow Wave";
corsair_modes[3].name = "Color Wave";
corsair_modes[4].name = "Visor";
corsair_modes[5].name = "Rain";
corsair_modes[6].name = "Marquee";
corsair_modes[7].name = "Rainbow";
corsair_modes[8].name = "Sequential";
corsair_modes[9].name = "Static";
for (int i = 0; i < CORSAIR_PRO_NUMBER_MODES; i++)
{
modes.push_back(corsair_modes[i]);
}
for (int i = 0; i < corsair->GetLEDCount(); i++)
{
led* new_led = new led();
new_led->name = "Corsair Pro LED";
leds.push_back(*new_led);
colors.push_back(0x00000000);
}
zone new_zone;
new_zone.name = "Corsair Pro Zone";
new_zone.type = ZONE_TYPE_LINEAR;
std::vector<int> zone_row;
for (int i = 0; i < corsair->GetLEDCount(); i++)
{
zone_row.push_back(i);
}
new_zone.map.push_back(zone_row);
zones.push_back(new_zone);
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_CorsairPro.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| Corsair Vengeance Pro RGB driver |
| |
| Adam Honse (CalcProgrammer1) 6/30/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CorsairProController.h"
class RGBController_CorsairPro : public RGBController
{
public:
RGBController_CorsairPro(CorsairProController* corsair_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
CorsairProController* corsair;
};
+193
View File
@@ -0,0 +1,193 @@
/*-----------------------------------------*\
| RGBController_LEDStrip.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| E1.31 Streaming ACN interface |
| |
| Adam Honse (CalcProgrammer1) 10/18/2019 |
\*-----------------------------------------*/
#include "RGBController_E131.h"
#include <e131.h>
#include <math.h>
RGBController_E131::RGBController_E131(std::vector<E131Device> device_list)
{
name = "E1.31 Streaming ACN Device";
devices = device_list;
unsigned int led_zone_idx = 0;
mode led_mode;
led_mode.name = "Custom";
modes.push_back(led_mode);
sockfd = e131_socket();
for (int i = 0; i < devices.size(); i++)
{
/*-----------------------------------------*\
| Add LEDs |
\*-----------------------------------------*/
for (int led_idx = 0; led_idx < devices[i].num_leds; led_idx++)
{
colors.push_back(0x00000000);
led new_led;
new_led.name = devices[i].name + " LED";
leds.push_back(new_led);
}
/*-----------------------------------------*\
| Add Zones |
\*-----------------------------------------*/
zone led_zone;
led_zone.name = devices[i].name;
led_zone.type = devices[i].type;
std::vector<int> led_zone_map;
for (int led_idx = 0; led_idx < devices[i].num_leds; led_idx++)
{
led_zone_map.push_back(led_zone_idx);
led_zone_idx++;
}
led_zone.map.push_back(led_zone_map);
zones.push_back(led_zone);
/*-----------------------------------------*\
| Add Universes |
\*-----------------------------------------*/
unsigned int total_universes = ceil( ( ( devices[i].num_leds * 3 ) + devices[i].start_channel ) / 512.0f );
for (int univ_idx = 0; univ_idx < total_universes; univ_idx++)
{
unsigned int universe = devices[i].start_universe + univ_idx;
bool universe_exists = false;
for (int pkt_idx = 0; pkt_idx < packets.size(); pkt_idx++)
{
if(universes[pkt_idx] == universe)
{
universe_exists = true;
}
}
if(!universe_exists)
{
e131_packet_t packet;
e131_addr_t dest_addr;
e131_pkt_init(&packet, universe, 512);
e131_multicast_dest(&dest_addr, universe, E131_DEFAULT_PORT);
packets.push_back(packet);
universes.push_back(universe);
dest_addrs.push_back(dest_addr);
}
}
}
}
int RGBController_E131::GetMode()
{
return 0;
}
void RGBController_E131::SetMode(int mode)
{
}
void RGBController_E131::SetCustomMode()
{
}
void RGBController_E131::SetAllLEDs(RGBColor color)
{
for (int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
UpdateLEDs();
}
void RGBController_E131::SetAllZoneLEDs(int zone, RGBColor color)
{
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
colors[zones[zone].map[x][y]] = color;
}
}
UpdateLEDs();
}
void RGBController_E131::SetLED(int led, RGBColor color)
{
colors[led] = color;
UpdateLEDs();
}
void RGBController_E131::UpdateLEDs()
{
int color_idx = 0;
for(int device_idx = 0; device_idx < devices.size(); device_idx++)
{
unsigned int total_universes = ceil( ( ( devices[device_idx].num_leds * 3 ) + devices[device_idx].start_channel ) / 512.0f );
unsigned int channel_idx = devices[device_idx].start_channel;
unsigned int led_idx = 0;
unsigned int rgb_idx = 0;
bool done = false;
for (int univ_idx = 0; univ_idx < total_universes; univ_idx++)
{
unsigned int universe = devices[device_idx].start_universe + univ_idx;
for(int packet_idx = 0; packet_idx < packets.size(); packet_idx++)
{
if(!done && (universes[packet_idx] == universe))
{
while(!done && (channel_idx <= 512))
{
switch(rgb_idx)
{
case 0:
packets[packet_idx].dmp.prop_val[channel_idx] = RGBGetRValue( colors[color_idx] );
rgb_idx = 1;
break;
case 1:
packets[packet_idx].dmp.prop_val[channel_idx] = RGBGetGValue( colors[color_idx] );
rgb_idx = 2;
break;
case 2:
packets[packet_idx].dmp.prop_val[channel_idx] = RGBGetBValue( colors[color_idx] );
rgb_idx = 0;
led_idx++;
color_idx++;
break;
}
if(led_idx >= devices[device_idx].num_leds)
{
done = true;
}
channel_idx++;
}
}
}
channel_idx = 1;
}
}
for(int packet_idx = 0; packet_idx < packets.size(); packet_idx++)
{
e131_send(sockfd, &packets[packet_idx], &dest_addrs[packet_idx]);
packets[packet_idx].frame.seq_number++;
}
}
+54
View File
@@ -0,0 +1,54 @@
/*-----------------------------------------*\
| RGBController_E131.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| E1.31 Streaming ACN interface |
| |
| Adam Honse (CalcProgrammer1) 10/18/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include <e131.h>
typedef unsigned int e131_rgb_order;
enum
{
E131_RGB_ORDER_RGB,
E131_RGB_ORDER_RBG,
E131_RGB_ORDER_GRB,
E131_RGB_ORDER_GBR,
E131_RGB_ORDER_BRG,
E131_RGB_ORDER_BGR
};
struct E131Device
{
std::string name;
unsigned int num_leds;
unsigned int start_universe;
unsigned int start_channel;
e131_rgb_order rgb_order;
zone_type type;
};
class RGBController_E131 : public RGBController
{
public:
RGBController_E131(std::vector<E131Device> device_list);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
std::vector<E131Device> devices;
std::vector<e131_packet_t> packets;
std::vector<e131_addr_t> dest_addrs;
std::vector<unsigned int> universes;
int sockfd;
};
+140
View File
@@ -0,0 +1,140 @@
/*-----------------------------------------*\
| RGBController_HuePlus.cpp |
| |
| Generic RGB Interface for NZXT Hue+ |
| |
| Adam Honse (CalcProgrammer1) 6/20/2019 |
\*-----------------------------------------*/
#include "RGBController_HuePlus.h"
RGBController_HuePlus::RGBController_HuePlus(HuePlusController* hueplus_ptr)
{
hueplus = hueplus_ptr;
name = "NZXT Hue+";
type = DEVICE_TYPE_LEDSTRIP;
location = hueplus->GetLEDString();
mode led_mode;
led_mode.name = "Custom";
modes.push_back(led_mode);
unsigned int led_idx = 0;
for (int channel_idx = 0; channel_idx < HUE_PLUS_NUM_CHANNELS; channel_idx++)
{
if(hueplus->channel_leds[channel_idx] > 0)
{
zone* new_zone = new zone;
char ch_idx_string[2];
sprintf(ch_idx_string, "%d", channel_idx + 1);
new_zone->name = "Hue+ Channel ";
new_zone->name.append(ch_idx_string);
new_zone->type = ZONE_TYPE_LINEAR;
std::vector<int> *new_zone_map = new std::vector<int>();
for (int led_ch_idx = 0; led_ch_idx < hueplus->channel_leds[channel_idx]; led_ch_idx++)
{
colors.push_back(0x00000000);
char led_idx_string[3];
sprintf(led_idx_string, "%d", led_ch_idx + 1);
led new_led;
new_led.name = "Hue+ Channel ";
new_led.name.append(ch_idx_string);
new_led.name.append(", LED ");
new_led.name.append(led_idx_string);
leds.push_back(new_led);
leds_channel.push_back(channel_idx + 1);
new_zone_map->push_back(led_idx);
led_idx++;
}
new_zone->map.push_back(*new_zone_map);
zones.push_back(*new_zone);
zones_channel.push_back(channel_idx + 1);
}
}
}
int RGBController_HuePlus::GetMode()
{
return 0;
}
void RGBController_HuePlus::SetMode(int mode)
{
}
void RGBController_HuePlus::SetCustomMode()
{
}
void RGBController_HuePlus::SetAllLEDs(RGBColor color)
{
for (int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
hueplus->SetChannelLEDs(0, colors);
}
void RGBController_HuePlus::SetAllZoneLEDs(int zone, RGBColor color)
{
int channel = zones_channel[zone];
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
colors[zones[zone].map[x][y]] = color;
}
}
std::vector<RGBColor> channel_colors;
for(int color = 0; color < colors.size(); color++)
{
if(leds_channel[color] == channel)
{
channel_colors.push_back(colors[color]);
}
}
hueplus->SetChannelLEDs(channel, channel_colors);
}
void RGBController_HuePlus::SetLED(int led, RGBColor color)
{
int channel = leds_channel[led];
colors[led] = color;
std::vector<RGBColor> channel_colors;
for(int color = 0; color < colors.size(); color++)
{
if(leds_channel[color] == channel)
{
channel_colors.push_back(colors[color]);
}
}
hueplus->SetChannelLEDs(channel, channel_colors);
}
void RGBController_HuePlus::UpdateLEDs()
{
hueplus->SetChannelLEDs(0, colors);
}
+30
View File
@@ -0,0 +1,30 @@
/*-----------------------------------------*\
| RGBController_HuePlus.h |
| |
| Generic RGB Interface for NZXT Hue+ |
| |
| Adam Honse (CalcProgrammer1) 6/20/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "serial_port.h"
#include "HuePlusController.h"
class RGBController_HuePlus : public RGBController
{
public:
RGBController_HuePlus(HuePlusController* hueplus_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
HuePlusController* hueplus;
std::vector<unsigned int> leds_channel;
std::vector<unsigned int> zones_channel;
};
+150
View File
@@ -0,0 +1,150 @@
/*-----------------------------------------*\
| RGBController_HyperX.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| HyperX Predator RGB interface |
| |
| Adam Honse (CalcProgrammer1) 6/29/2019 |
\*-----------------------------------------*/
#include "RGBController_HyperX.h"
int RGBController_HyperX::GetMode()
{
return(0);
}
void RGBController_HyperX::SetMode(int mode)
{
hyperx->SetMode(mode);
}
void RGBController_HyperX::SetCustomMode()
{
hyperx->SetMode(HYPERX_MODE_DIRECT);
}
void RGBController_HyperX::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if(hyperx->GetMode() == HYPERX_MODE_DIRECT)
{
hyperx->SetAllColors(red, grn, blu);
}
else
{
hyperx->SetEffectColor(red, grn, blu);
}
}
void RGBController_HyperX::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if(hyperx->GetMode() == HYPERX_MODE_DIRECT)
{
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
hyperx->SetLEDColor(zones[zone].map[x][y], red, grn, blu);
}
}
}
else
{
hyperx->SetEffectColor(red, grn, blu);
}
}
void RGBController_HyperX::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if(hyperx->GetMode() == HYPERX_MODE_DIRECT)
{
hyperx->SetLEDColor(led, red, grn, blu);
}
else
{
hyperx->SetEffectColor(red, grn, blu);
}
}
void RGBController_HyperX::UpdateLEDs()
{
}
RGBController_HyperX::RGBController_HyperX(HyperXController* hyperx_ptr)
{
hyperx = hyperx_ptr;
name = hyperx->GetDeviceName();
location = hyperx->GetDeviceLocation();
type = DEVICE_TYPE_DRAM;
mode hyperx_modes[HYPERX_NUMBER_MODES];
hyperx_modes[0].name = "Direct";
hyperx_modes[1].name = "Static";
hyperx_modes[2].name = "Rainbow";
hyperx_modes[3].name = "Comet";
hyperx_modes[4].name = "Heartbeat";
hyperx_modes[5].name = "Spectrum Cycle";
hyperx_modes[6].name = "Breathing";
hyperx_modes[7].name = "Bounce";
hyperx_modes[8].name = "Blink";
for (int i = 0; i < HYPERX_NUMBER_MODES; i++)
{
modes.push_back(hyperx_modes[i]);
}
unsigned int led_idx = 0;
for(int slot = 0; slot < hyperx->GetSlotCount(); slot++)
{
zone* new_zone = new zone;
char slot_idx_str[3];
sprintf(slot_idx_str, "%d", slot);
new_zone->name = "HyperX Slot ";
new_zone->name.append(slot_idx_str);
new_zone->type = ZONE_TYPE_LINEAR;
std::vector<int> *new_zone_map = new std::vector<int>();
for(int led_slot_idx = 0; led_slot_idx < 5; led_slot_idx++)
{
colors.push_back(0x00000000);
led* new_led = new led();
char led_idx_str[3];
sprintf(led_idx_str, "%d", led_slot_idx);
new_led->name = "HyperX Slot ";
new_led->name.append(slot_idx_str);
new_led->name.append(", LED ");
new_led->name.append(led_idx_str);
leds.push_back(*new_led);
new_zone_map->push_back(led_idx);
led_idx++;
}
new_zone->map.push_back(*new_zone_map);
zones.push_back(*new_zone);
}
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_HyperX.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| HyperX Predator RGB interface |
| |
| Adam Honse (CalcProgrammer1) 6/29/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "HyperXController.h"
class RGBController_HyperX : public RGBController
{
public:
RGBController_HyperX(HyperXController* hyperx_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
HyperXController* hyperx;
};
+89
View File
@@ -0,0 +1,89 @@
/*-----------------------------------------*\
| RGBController_LEDStrip.cpp |
| |
| Generic RGB Interface for OpenAuraSDK |
| KeyboardVisualizer LED strip interface |
| |
| Adam Honse (CalcProgrammer1) 6/20/2019 |
\*-----------------------------------------*/
#include "RGBController_LEDStrip.h"
RGBController_LEDStrip::RGBController_LEDStrip(LEDStripController* ledstrip_ptr)
{
strip = ledstrip_ptr;
name = "LED Strip";
type = DEVICE_TYPE_LEDSTRIP;
mode led_mode;
led_mode.name = "Custom";
modes.push_back(led_mode);
for (int i = 0; i < strip->num_leds; i++)
{
colors.push_back(0x00000000);
led new_led;
new_led.name = "LED Strip";
leds.push_back(new_led);
}
zone led_zone;
led_zone.name = "LED Strip";
std::vector<int> led_zone_map;
for (int i = 0; i < strip->num_leds; i++)
{
led_zone_map.push_back(i);
}
led_zone.map.push_back(led_zone_map);
zones.push_back(led_zone);
}
int RGBController_LEDStrip::GetMode()
{
return 0;
}
void RGBController_LEDStrip::SetMode(int mode)
{
}
void RGBController_LEDStrip::SetCustomMode()
{
}
void RGBController_LEDStrip::SetAllLEDs(RGBColor color)
{
for (int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
strip->SetLEDs(colors);
}
void RGBController_LEDStrip::SetAllZoneLEDs(int zone, RGBColor color)
{
for (int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
strip->SetLEDs(colors);
}
void RGBController_LEDStrip::SetLED(int led, RGBColor color)
{
colors[led] = color;
strip->SetLEDs(colors);
}
void RGBController_LEDStrip::UpdateLEDs()
{
strip->SetLEDs(colors);
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_LEDStrip.h |
| |
| Generic RGB Interface for OpenAuraSDK |
| KeyboardVisualizer LED strip interface |
| |
| Adam Honse (CalcProgrammer1) 6/20/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "serial_port.h"
#include "LEDStripController.h"
class RGBController_LEDStrip : public RGBController
{
public:
RGBController_LEDStrip(LEDStripController* ledstrip_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
LEDStripController* strip;
};
+423
View File
@@ -0,0 +1,423 @@
/*-----------------------------------------*\
| RGBController_OpenRazer.cpp |
| |
| Generic RGB Interface for OpenRazer |
| kernel drivers for Chroma peripherals |
| |
| Adam Honse (CalcProgrammer1) 6/15/2019 |
\*-----------------------------------------*/
#include "RGBController_OpenRazer.h"
#include <fstream>
#include <unistd.h>
int RGBController_OpenRazer::GetMode()
{
return(0);
}
void RGBController_OpenRazer::SetMode(int mode)
{
char update_value = 1;
switch(matrix_type)
{
case RAZER_TYPE_MATRIX_FRAME:
case RAZER_TYPE_MATRIX_NOFRAME:
{
switch(mode)
{
case RAZER_MODE_CUSTOM:
matrix_effect_custom.write(&update_value, 1);
matrix_effect_custom.flush();
break;
case RAZER_MODE_OFF:
matrix_effect_none.write(&update_value, 1);
matrix_effect_none.flush();
break;
case RAZER_MODE_STATIC:
break;
case RAZER_MODE_BREATHING:
break;
case RAZER_MODE_SPECTRUM_CYCLE:
matrix_effect_spectrum.write(&update_value, 1);
matrix_effect_spectrum.flush();
break;
case RAZER_MODE_WAVE:
matrix_effect_wave.write(&update_value, 1);
matrix_effect_wave.flush();
break;
case RAZER_MODE_REACTIVE:
matrix_effect_reactive.write(&update_value, 1);
matrix_effect_reactive.flush();
break;
}
}
break;
case RAZER_TYPE_NOMATRIX:
{
switch(mode)
{
case RAZER_MODE_CUSTOM:
update_value = 0;
logo_led_effect.write(&update_value, 1);
scroll_led_effect.write(&update_value, 1);
logo_led_effect.flush();
scroll_led_effect.flush();
break;
case RAZER_MODE_SPECTRUM_CYCLE:
update_value = '4';
logo_led_effect.write(&update_value, 1);
scroll_led_effect.write(&update_value, 1);
logo_led_effect.flush();
scroll_led_effect.flush();
break;
}
}
}
}
void RGBController_OpenRazer::SetCustomMode()
{
SetMode(RAZER_MODE_CUSTOM);
}
void RGBController_OpenRazer::UpdateLEDs()
{
switch(matrix_type)
{
case RAZER_TYPE_MATRIX_FRAME:
case RAZER_TYPE_MATRIX_NOFRAME:
case RAZER_TYPE_MATRIX_STATIC:
{
char update_value = 1;
for (int row = 0; row < matrix_rows; row++)
{
unsigned int output_array_size;
unsigned int output_offset;
unsigned int row_offset = (row * matrix_cols);
if(matrix_type == RAZER_TYPE_MATRIX_FRAME)
{
output_array_size = 3 + (matrix_cols* 3);
output_offset = 3;
}
else
{
output_array_size = 3;
output_offset = 0;
}
char output_array[output_array_size];
if(matrix_type == RAZER_TYPE_MATRIX_FRAME)
{
output_array[0] = row;
output_array[1] = 0;
output_array[2] = matrix_cols - 1;
}
for(int col = 0; col < matrix_cols; col++)
{
unsigned int color_idx = col + row_offset;
output_array[(col * 3) + 0 + output_offset] = (char)RGBGetRValue(colors[color_idx]);
output_array[(col * 3) + 1 + output_offset] = (char)RGBGetGValue(colors[color_idx]);
output_array[(col * 3) + 2 + output_offset] = (char)RGBGetBValue(colors[color_idx]);
}
if(matrix_type == RAZER_TYPE_MATRIX_FRAME)
{
matrix_custom_frame.write(output_array, output_array_size);
matrix_custom_frame.flush();
}
else if(matrix_type == RAZER_TYPE_MATRIX_NOFRAME)
{
matrix_effect_custom.write(output_array, output_array_size);
matrix_effect_custom.flush();
}
else
{
matrix_effect_static.write(output_array, output_array_size);
matrix_effect_static.flush();
}
}
if(matrix_type == RAZER_TYPE_MATRIX_FRAME)
{
matrix_effect_custom.write(&update_value, 1);
matrix_effect_custom.flush();
}
}
break;
case RAZER_TYPE_NOMATRIX:
{
unsigned int output_array_size = 3;
char output_array[output_array_size];
char update_value = 0;
output_array[0] = (char)RGBGetRValue(colors[0]);
output_array[1] = (char)RGBGetGValue(colors[0]);
output_array[2] = (char)RGBGetBValue(colors[0]);
logo_led_rgb.write(output_array, output_array_size);
output_array[0] = (char)RGBGetRValue(colors[1]);
output_array[1] = (char)RGBGetGValue(colors[1]);
output_array[2] = (char)RGBGetBValue(colors[1]);
scroll_led_rgb.write(output_array, output_array_size);
logo_led_rgb.flush();
scroll_led_rgb.flush();
logo_led_effect.write(&update_value, 1);
scroll_led_effect.write(&update_value, 1);
logo_led_effect.flush();
scroll_led_effect.flush();
}
break;
}
}
void RGBController_OpenRazer::SetAllLEDs(RGBColor color)
{
for(int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
UpdateLEDs();
}
void RGBController_OpenRazer::SetAllZoneLEDs(int zone, RGBColor color)
{
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
colors[zones[zone].map[x][y]] = color;
}
}
UpdateLEDs();
}
void RGBController_OpenRazer::SetLED(int led, RGBColor color)
{
colors[led] = color;
UpdateLEDs();
}
static std::string GetDeviceTypeString(std::string dev_path)
{
// Read device_type for device name string
std::string dev_type_path = dev_path + "/device_type";
std::ifstream dev_type_file;
std::string ret_str;
dev_type_file.open(dev_type_path);
std::getline(dev_type_file, ret_str);
dev_type_file.close();
return(ret_str);
}
static std::string GetFirmwareVersionString(std::string dev_path)
{
// Read firmware_version for firmware version string
std::string firm_ver_path = dev_path + "/firmware_version";
std::ifstream firm_ver_file;
std::string ret_str;
firm_ver_file.open(firm_ver_path);
std::getline(firm_ver_file, ret_str);
firm_ver_file.close();
return(ret_str);
}
static std::string GetSerialNumberString(std::string dev_path)
{
// Read device_serial for serial number string
std::string ser_num_path = dev_path + "/device_serial";
std::ifstream ser_num_file;
std::string ret_str;
ser_num_file.open(ser_num_path);
std::getline(ser_num_file, ret_str);
ser_num_file.close();
return(ret_str);
}
void RGBController_OpenRazer::SetupMatrixDevice(std::string dev_path, unsigned int rows, unsigned int cols)
{
matrix_custom_frame.open(dev_path + "/matrix_custom_frame");
matrix_effect_custom.open(dev_path + "/matrix_effect_custom");
matrix_effect_breath.open(dev_path + "/matrix_effect_breath");
matrix_effect_none.open(dev_path + "/matrix_effect_none");
matrix_effect_reactive.open(dev_path + "/matrix_effect_reactive");
matrix_effect_spectrum.open(dev_path + "/matrix_effect_spectrum");
matrix_effect_static.open(dev_path + "/matrix_effect_static");
matrix_effect_wave.open(dev_path + "/matrix_effect_wave");
if(!matrix_custom_frame)
{
if(!matrix_effect_custom)
{
matrix_type = RAZER_TYPE_MATRIX_STATIC;
}
else
{
matrix_type = RAZER_TYPE_MATRIX_NOFRAME;
}
matrix_rows = 1;
matrix_cols = 1;
}
else
{
matrix_type = RAZER_TYPE_MATRIX_FRAME;
matrix_rows = rows;
matrix_cols = cols;
}
}
void RGBController_OpenRazer::SetupNonMatrixDevice(std::string dev_path)
{
logo_led_effect.open(dev_path + "/logo_led_effect");
logo_led_rgb.open(dev_path + "/logo_led_rgb");
scroll_led_effect.open(dev_path + "/scroll_led_effect");
scroll_led_rgb.open(dev_path + "/scroll_led_rgb");
matrix_type = RAZER_TYPE_NOMATRIX;
}
RGBController_OpenRazer::RGBController_OpenRazer(std::string dev_path)
{
unsigned int led_count = 0;
/*-----------------------------------------------------------------*\
| Start device at -1. This indicates the device was not detected |
\*-----------------------------------------------------------------*/
device = -1;
/*-----------------------------------------------------------------*\
| Get the device name from the OpenRazer driver |
\*-----------------------------------------------------------------*/
name = GetDeviceTypeString(dev_path);
/*-----------------------------------------------------------------*\
| Set the description to indicate this is an OpenRazer device |
\*-----------------------------------------------------------------*/
description = "OpenRazer Device";
/*-----------------------------------------------------------------*\
| Set the device path as the location |
\*-----------------------------------------------------------------*/
location = dev_path;
/*-----------------------------------------------------------------*\
| Get the serial number from the dev path |
\*-----------------------------------------------------------------*/
serial = GetSerialNumberString(dev_path);
/*-----------------------------------------------------------------*\
| Get the firmware version from the dev path |
\*-----------------------------------------------------------------*/
version = GetFirmwareVersionString(dev_path);
/*-----------------------------------------------------------------*\
| Loop through all known devices to look for a name match |
\*-----------------------------------------------------------------*/
for (int i = 0; i < RAZER_NUM_DEVICES; i++)
{
if (device_list[i]->name == name)
{
/*---------------------------------------------------------*\
| Set device ID |
\*---------------------------------------------------------*/
device = i;
/*---------------------------------------------------------*\
| Set device type |
\*---------------------------------------------------------*/
type = device_list[i]->type;
/*---------------------------------------------------------*\
| Initialize modes |
\*---------------------------------------------------------*/
mode razer_modes[RAZER_NUM_MODES];
razer_modes[0].name = "Custom";
razer_modes[1].name = "Off";
razer_modes[2].name = "Static";
razer_modes[3].name = "Breathing";
razer_modes[4].name = "Spectrum Cycle";
razer_modes[5].name = "Wave";
razer_modes[6].name = "Reactive";
for (int i = 0; i < RAZER_NUM_MODES; i++)
{
modes.push_back(razer_modes[i]);
}
/*---------------------------------------------------------*\
| Initialize file descriptors |
\*---------------------------------------------------------*/
if(device_list[i]->matrix_type == true)
{
SetupMatrixDevice(dev_path, device_list[i]->rows, device_list[i]->cols);
}
else
{
SetupNonMatrixDevice(dev_path);
}
/*---------------------------------------------------------*\
| Fill in zone information based on device table |
\*---------------------------------------------------------*/
for (int zone_id = 0; zone_id < RAZER_MAX_ZONES; zone_id++)
{
if (device_list[i]->zones[zone_id] != NULL)
{
zone new_zone;
new_zone.name = device_list[i]->zones[zone_id]->name;
new_zone.type = device_list[i]->zones[zone_id]->type;
for (int row_id = 0; row_id < device_list[i]->zones[zone_id]->rows; row_id++)
{
std::vector<int> new_zone_map;
for (int col_id = 0; col_id < device_list[i]->zones[zone_id]->cols; col_id++)
{
RGBColor new_color = 0x00000000;
colors.push_back(new_color);
led* new_led = new led();
new_led->name = device_list[i]->zones[zone_id]->name;
leds.push_back(*new_led);
new_zone_map.push_back(led_count);
led_count++;
}
new_zone.map.push_back(new_zone_map);
}
zones.push_back(new_zone);
}
}
}
}
}
+956
View File
@@ -0,0 +1,956 @@
/*-----------------------------------------*\
| RGBController_OpenRazer.h |
| |
| Generic RGB Interface for OpenRazer |
| kernel drivers for Chroma peripherals |
| |
| Adam Honse (CalcProgrammer1) 6/15/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include <fstream>
#define RAZER_MAX_ZONES 6
typedef struct
{
std::string name;
unsigned int type;
unsigned int rows;
unsigned int cols;
} razer_zone;
typedef struct
{
std::string name;
device_type type;
bool matrix_type;
unsigned int rows;
unsigned int cols;
const razer_zone* zones[RAZER_MAX_ZONES];
} razer_device;
/*-------------------------------------------------------------------------*\
| KEYBOARDS |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer BlackWidow Chroma |
| |
| Zone "Keyboard" |
| Matrix |
| 6 Rows, 22 Columns |
\*-------------------------------------------------------------*/
static const razer_zone blackwidow_chroma_zone =
{
"Keyboard",
ZONE_TYPE_MATRIX,
6,
22
};
static const razer_device blackwidow_chroma_device =
{
"Razer BlackWidow Chroma",
DEVICE_TYPE_KEYBOARD,
true,
6,
22,
{
&blackwidow_chroma_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer BlackWidow Chroma Tournament Edition |
| |
| Zone "Keyboard" |
| Matrix |
| 6 Rows, 22 Columns |
\*-------------------------------------------------------------*/
static const razer_zone blackwidow_chroma_te_zone =
{
"Keyboard",
ZONE_TYPE_MATRIX,
6,
22
};
static const razer_device blackwidow_chroma_te_device =
{
"Razer BlackWidow Chroma Tournament Edition",
DEVICE_TYPE_KEYBOARD,
true,
6,
22,
{
&blackwidow_chroma_te_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Ornata Chroma |
| |
| Zone "Keyboard" |
| Matrix |
| 6 Rows, 22 Columns |
\*-------------------------------------------------------------*/
static const razer_zone ornata_chroma_zone =
{
"Keyboard",
ZONE_TYPE_MATRIX,
6,
22
};
static const razer_device ornata_chroma_device =
{
"Razer Ornata Chroma",
DEVICE_TYPE_KEYBOARD,
true,
6,
22,
{
&ornata_chroma_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer DeathStalker Chroma |
| |
| Zone "Keyboard" |
| Linear |
| 12 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone deathstalker_chroma_zone =
{
"Keyboard",
ZONE_TYPE_LINEAR,
1,
12
};
static const razer_device deathstalker_chroma_device =
{
"Razer DeathStalker Chroma",
DEVICE_TYPE_KEYBOARD,
true,
1,
12,
{
&deathstalker_chroma_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| LAPTOPS |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer Blade Stealth |
| |
| Zone "Keyboard" |
| Matrix |
| 6 Rows, 16 Columns |
\*-------------------------------------------------------------*/
static const razer_zone blade_stealth_zone =
{
"Keyboard",
ZONE_TYPE_MATRIX,
6,
16
};
static const razer_device blade_stealth_device =
{
"Razer Blade Stealth",
DEVICE_TYPE_KEYBOARD,
true,
6,
16,
{
&blade_stealth_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Blade Pro (Late 2016) |
| |
| Zone "Keyboard" |
| Matrix |
| 6 Rows, 25 Columns |
\*-------------------------------------------------------------*/
static const razer_zone blade_pro_late_2016_zone =
{
"Keyboard",
ZONE_TYPE_MATRIX,
6,
25
};
static const razer_device blade_pro_late_2016_device =
{
"Razer Blade Pro (Late 2016)",
DEVICE_TYPE_KEYBOARD,
true,
6,
25,
{
&blade_pro_late_2016_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Blade Pro (2017) |
| |
| Zone "Keyboard" |
| Matrix |
| 6 Rows, 25 Columns |
\*-------------------------------------------------------------*/
static const razer_zone blade_pro_2017_zone =
{
"Keyboard",
ZONE_TYPE_MATRIX,
6,
25
};
static const razer_device blade_pro_2017_device =
{
"Razer Blade Pro (2017)",
DEVICE_TYPE_KEYBOARD,
true,
6,
25,
{
&blade_pro_2017_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| MICE |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer Mamba Tournament Edition |
| |
| Zone "Left" |
| Linear |
| 7 LEDs |
| |
| Zone "Right" |
| Linear |
| 7 LEDs |
| |
| Zone "Logo" |
| Single |
| 1 LED |
| |
| Zone "Scroll Wheel" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone mamba_te_left_zone =
{
"Left LED Strip",
ZONE_TYPE_LINEAR,
1,
7
};
static const razer_zone mamba_te_right_zone =
{
"Right LED Strip",
ZONE_TYPE_LINEAR,
1,
7
};
static const razer_zone mamba_te_logo_zone =
{
"Logo",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_zone mamba_te_scroll_wheel_zone =
{
"Scroll Wheel",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device mamba_te_device =
{
"Razer Mamba Tournament Edition",
DEVICE_TYPE_MOUSE,
true,
1,
16,
{
&mamba_te_left_zone,
&mamba_te_right_zone,
&mamba_te_logo_zone,
&mamba_te_scroll_wheel_zone,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Diamondback Chroma |
| |
| Zone "Right" |
| Linear |
| 7 LEDs |
| |
| Zone "Bottom" |
| Linear |
| 5 LEDs |
| |
| Zone "Left" |
| Linear |
| 7 LEDs |
| |
| Zone "Logo" |
| Single |
| 1 LED |
| |
| Zone "Scroll Wheel" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone diamondback_chroma_right_zone =
{
"Right LED Strip",
ZONE_TYPE_LINEAR,
1,
7
};
static const razer_zone diamondback_chroma_bottom_zone =
{
"Bottom LED Strip",
ZONE_TYPE_LINEAR,
1,
5
};
static const razer_zone diamondback_chroma_left_zone =
{
"Left LED Strip",
ZONE_TYPE_LINEAR,
1,
7
};
static const razer_zone diamondback_chroma_logo_zone =
{
"Logo",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_zone diamondback_chroma_scroll_wheel_zone =
{
"Scroll Wheel",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device diamondback_chroma_device =
{
"Razer Diamondback Chroma",
DEVICE_TYPE_MOUSE,
true,
1,
21,
{
&diamondback_chroma_right_zone,
&diamondback_chroma_bottom_zone,
&diamondback_chroma_left_zone,
&diamondback_chroma_logo_zone,
&diamondback_chroma_scroll_wheel_zone,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer DeathAdder Chroma |
| |
| Zone "Logo" |
| Single |
| 1 LED |
| |
| Zone "Scroll Wheel" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone deathadder_chroma_logo_zone =
{
"Logo",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_zone deathadder_chroma_scroll_wheel_zone =
{
"Scroll Wheel",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device deathadder_chroma_device =
{
"Razer DeathAdder Chroma",
DEVICE_TYPE_MOUSE,
false,
1,
2,
{
&deathadder_chroma_logo_zone,
&deathadder_chroma_scroll_wheel_zone,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Naga Chroma |
| |
| Zone "Logo" |
| Single |
| 1 LED |
| |
| Zone "Scroll Wheel" |
| Single |
| 1 LED |
| |
| Zone "Numpad" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone naga_chroma_logo_zone =
{
"Logo",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_zone naga_chroma_scroll_wheel_zone =
{
"Scroll Wheel",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_zone naga_chroma_numpad_zone =
{
"Numpad",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device naga_chroma_device =
{
"Razer Naga Chroma",
DEVICE_TYPE_MOUSE,
false,
1,
3,
{
&naga_chroma_logo_zone,
&naga_chroma_scroll_wheel_zone,
&naga_chroma_numpad_zone,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| KEYPADS |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer Orbweaver Chroma |
| |
| Zone "Keypad" |
| Matrix |
| 4 Rows, 5 Columns |
\*-------------------------------------------------------------*/
static const razer_zone orbweaver_chroma_zone =
{
"Keypad",
ZONE_TYPE_MATRIX,
4,
5
};
static const razer_device orbweaver_chroma_device =
{
"Razer Orbweaver Chroma",
DEVICE_TYPE_KEYBOARD,
true,
6,
25,
{
&orbweaver_chroma_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Tartarus Chroma |
| |
| Zone "Keypad" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone tartarus_chroma_zone =
{
"Keypad",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device tartarus_chroma_device =
{
"Razer Tartarus Chroma",
DEVICE_TYPE_KEYBOARD,
true,
1,
1,
{
&tartarus_chroma_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| MOUSEMATS |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer Firefly |
| |
| Zone "LED Strip" |
| Linear |
| 15 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone firefly_zone =
{
"LED Strip",
ZONE_TYPE_LINEAR,
1,
15
};
static const razer_device firefly_device =
{
"Razer Firefly",
DEVICE_TYPE_MOUSEMAT,
true,
1,
15,
{
&firefly_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Goliathus Extended |
| |
| Zone "LED Strip" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone goliathus_extended_zone =
{
"LED Strip",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device goliathus_extended_device =
{
"Razer Goliathus Extended",
DEVICE_TYPE_MOUSEMAT,
true,
1,
1,
{
&goliathus_extended_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| HEADSETS |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer Kraken 7.1 Chroma |
| |
| Zone "Headset" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone kraken_chroma_zone =
{
"Headset",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device kraken_chroma_device =
{
"Razer Kraken 7.1 Chroma",
DEVICE_TYPE_HEADSET,
true,
1,
1,
{
&kraken_chroma_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Kraken 7.1 V2 |
| |
| Zone "Headset" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone kraken_v2_zone =
{
"Headset",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_device kraken_v2_device =
{
"Razer Kraken 7.1 V2",
DEVICE_TYPE_HEADSET,
true,
1,
1,
{
&kraken_v2_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| OTHER |
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------*\
| Razer Core |
| |
| Zone "Side Window Lights" |
| Single |
| 1 LED |
| |
| Zone "LED Strip" |
| Linear |
| 8 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone core_side_zone =
{
"Side Window Lights",
ZONE_TYPE_SINGLE,
1,
1
};
static const razer_zone core_led_strip_zone =
{
"LED Strip",
ZONE_TYPE_LINEAR,
1,
8
};
static const razer_device core_device =
{
"Razer Core",
DEVICE_TYPE_UNKNOWN,
true,
1,
9,
{
&core_side_zone,
&core_led_strip_zone,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Chroma Mug Holder |
| |
| Zone "LED Strip" |
| Linear |
| 15 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone mug_holder_zone =
{
"LED Strip",
ZONE_TYPE_LINEAR,
1,
15
};
static const razer_device mug_holder_device =
{
"Razer Chroma Mug Holder",
DEVICE_TYPE_UNKNOWN,
true,
1,
15,
{
&mug_holder_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*-------------------------------------------------------------*\
| Razer Chroma HDK |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone chromahdk_zone =
{
"LED Strip",
ZONE_TYPE_LINEAR,
1,
16
};
static const razer_device chromahdk_device =
{
"Razer Chroma HDK",
DEVICE_TYPE_LEDSTRIP,
true,
4,
16,
{
&chromahdk_zone,
&chromahdk_zone,
&chromahdk_zone,
&chromahdk_zone,
NULL,
NULL
}
};
/*-------------------------------------------------------------------------*\
| DEVICE MASTER LIST |
\*-------------------------------------------------------------------------*/
#define RAZER_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
static const razer_device* device_list[] =
{
/*-----------------------------------------------------------------*\
| KEYBOARDS |
\*-----------------------------------------------------------------*/
&blackwidow_chroma_device,
&blackwidow_chroma_te_device,
&ornata_chroma_device,
&deathstalker_chroma_device,
/*-----------------------------------------------------------------*\
| LAPTOPS |
\*-----------------------------------------------------------------*/
&blade_stealth_device,
&blade_pro_late_2016_device,
&blade_pro_2017_device,
/*-----------------------------------------------------------------*\
| MICE |
\*-----------------------------------------------------------------*/
&mamba_te_device,
&diamondback_chroma_device,
&deathadder_chroma_device,
/*-----------------------------------------------------------------*\
| KEYPADS |
\*-----------------------------------------------------------------*/
&orbweaver_chroma_device,
&tartarus_chroma_device,
/*-----------------------------------------------------------------*\
| MOUSEMATS |
\*-----------------------------------------------------------------*/
&firefly_device,
&goliathus_extended_device,
/*-----------------------------------------------------------------*\
| HEADSETS |
\*-----------------------------------------------------------------*/
&kraken_chroma_device,
&kraken_v2_device,
/*-----------------------------------------------------------------*\
| OTHER |
\*-----------------------------------------------------------------*/
&core_device,
&mug_holder_device,
&chromahdk_device
};
class RGBController_OpenRazer : public RGBController
{
public:
enum
{
RAZER_MODE_CUSTOM,
RAZER_MODE_OFF,
RAZER_MODE_STATIC,
RAZER_MODE_BREATHING,
RAZER_MODE_SPECTRUM_CYCLE,
RAZER_MODE_WAVE,
RAZER_MODE_REACTIVE,
RAZER_NUM_MODES
};
enum
{
RAZER_TYPE_MATRIX_FRAME,
RAZER_TYPE_MATRIX_NOFRAME,
RAZER_TYPE_MATRIX_STATIC,
RAZER_TYPE_NOMATRIX,
RAZER_NUM_TYPES
};
public:
RGBController_OpenRazer(std::string dev_path);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
int device;
private:
void SetupMatrixDevice(std::string dev_path, unsigned int rows, unsigned int cols);
void SetupNonMatrixDevice(std::string dev_path);
unsigned int matrix_type;
unsigned int matrix_rows;
unsigned int matrix_cols;
//OpenRazer Sysfs Entries for Matrix Devices
std::ofstream matrix_custom_frame;
std::ofstream matrix_effect_custom;
std::ofstream matrix_effect_breath;
std::ofstream matrix_effect_none;
std::ofstream matrix_effect_reactive;
std::ofstream matrix_effect_spectrum;
std::ofstream matrix_effect_static;
std::ofstream matrix_effect_wave;
//OpenRazer Sysfs Entries for Non-Matrix Devices
std::ofstream logo_led_effect;
std::ofstream logo_led_rgb;
std::ofstream scroll_led_effect;
std::ofstream scroll_led_rgb;
};
+112
View File
@@ -0,0 +1,112 @@
/*-----------------------------------------*\
| RGBController_Polychrome.cpp |
| |
| Generic RGB Interface for OpenRGB |
| ASRock ASR LED and Polychrome RGB Driver |
| |
| Adam Honse (CalcProgrammer1) 12/15/2019 |
\*-----------------------------------------*/
#include "RGBController_Polychrome.h"
int RGBController_Polychrome::GetMode()
{
return(polychrome->GetMode());
}
void RGBController_Polychrome::SetMode(int mode)
{
polychrome->SetMode(mode);
}
void RGBController_Polychrome::SetCustomMode()
{
polychrome->SetMode(POLYCHROME_MODE_STATIC);
}
void RGBController_Polychrome::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
polychrome->SetAllColors(red, grn, blu);
}
void RGBController_Polychrome::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
polychrome->SetLEDColor(zone, red, grn, blu);
}
void RGBController_Polychrome::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
polychrome->SetLEDColor(led, red, grn, blu);
}
void RGBController_Polychrome::UpdateLEDs()
{
for (int led = 0; led < colors.size(); led++)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
polychrome->SetLEDColor(led, red, grn, blu);
}
}
static const char* polychrome_zone_names[] =
{
"Motherboard"
};
RGBController_Polychrome::RGBController_Polychrome(PolychromeController* polychrome_ptr)
{
polychrome = polychrome_ptr;
name = polychrome->GetDeviceName();
mode polychrome_modes[POLYCHROME_NUM_MODES];
polychrome_modes[0].name = "Static";
polychrome_modes[1].name = "Breathing";
polychrome_modes[2].name = "Flashing";
for (int i = 0; i < POLYCHROME_NUM_MODES; i++)
{
modes.push_back(polychrome_modes[i]);
}
// Search through all LEDs and create zones for each channel type
for (int i = 0; i < polychrome->GetLEDCount(); i++)
{
zone* new_zone = new zone();
led* new_led = new led();
std::vector<int>* zone_row = new std::vector<int>();
// Set zone name to channel name
new_zone->name = polychrome_zone_names[i];
new_led->name = polychrome_zone_names[i];
zone_row->push_back(i);
// Aura devices can be either single or linear, never matrix
// That means only one row is needed
new_zone->map.push_back(*zone_row);
// Push new LED to LEDs vector
leds.push_back(*new_led);
// Push new zone to zones vector
zones.push_back(*new_zone);
}
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_Polychrome.h |
| |
| Generic RGB Interface for OpenRGB |
| ASRock ASR LED and Polychrome RGB Driver |
| |
| Adam Honse (CalcProgrammer1) 12/15/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "PolychromeController.h"
class RGBController_Polychrome : public RGBController
{
public:
RGBController_Polychrome(PolychromeController* polychrome_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
PolychromeController* polychrome;
};
+117
View File
@@ -0,0 +1,117 @@
/*-----------------------------------------*\
| RGBController_RGBFusion.cpp |
| |
| Generic RGB Interface for OpenRGB |
| Gigabyte RGB Fusion Driver |
| |
| Adam Honse (CalcProgrammer1) 12/11/2019 |
\*-----------------------------------------*/
#include "RGBController_RGBFusion.h"
int RGBController_RGBFusion::GetMode()
{
return(rgb_fusion->GetMode());
}
void RGBController_RGBFusion::SetMode(int mode)
{
rgb_fusion->SetMode(mode);
}
void RGBController_RGBFusion::SetCustomMode()
{
rgb_fusion->SetMode(RGB_FUSION_MODE_STATIC);
}
void RGBController_RGBFusion::SetAllLEDs(RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
rgb_fusion->SetAllColors(red, grn, blu);
}
void RGBController_RGBFusion::SetAllZoneLEDs(int zone, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
rgb_fusion->SetLEDColor(zone, red, grn, blu);
}
void RGBController_RGBFusion::SetLED(int led, RGBColor color)
{
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
rgb_fusion->SetLEDColor(led, red, grn, blu);
}
void RGBController_RGBFusion::UpdateLEDs()
{
for (int led = 0; led < colors.size(); led++)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
rgb_fusion->SetLEDColor(led, red, grn, blu);
}
}
static const char* rgb_fusion_zone_names[] =
{
"Motherboard",
"RGB Header"
};
RGBController_RGBFusion::RGBController_RGBFusion(RGBFusionController* rgb_fusion_ptr)
{
rgb_fusion = rgb_fusion_ptr;
name = rgb_fusion->GetDeviceName();
description = "RGB Fusion 1.0";
location = rgb_fusion->GetDeviceLocation();
type = DEVICE_TYPE_MOTHERBOARD;
mode rgb_fusion_modes[RGB_FUSION_NUMBER_MODES];
rgb_fusion_modes[0].name = "Static";
rgb_fusion_modes[1].name = "Breathing";
rgb_fusion_modes[2].name = "Flashing";
for (int i = 0; i < RGB_FUSION_NUMBER_MODES; i++)
{
modes.push_back(rgb_fusion_modes[i]);
}
// Search through all LEDs and create zones for each channel type
for (int i = 0; i < rgb_fusion->GetLEDCount(); i++)
{
zone* new_zone = new zone();
led* new_led = new led();
std::vector<int>* zone_row = new std::vector<int>();
// Set zone name to channel name
new_zone->name = rgb_fusion_zone_names[i];
new_led->name = rgb_fusion_zone_names[i];
zone_row->push_back(i);
// Aura devices can be either single or linear, never matrix
// That means only one row is needed
new_zone->map.push_back(*zone_row);
// Push new LED to LEDs vector
leds.push_back(*new_led);
// Push new zone to zones vector
zones.push_back(*new_zone);
}
}
+29
View File
@@ -0,0 +1,29 @@
/*-----------------------------------------*\
| RGBController_RGBFusion.h |
| |
| Generic RGB Interface for OpenRGB |
| Gigabyte RGB Fusion Driver |
| |
| Adam Honse (CalcProgrammer1) 12/11/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "RGBFusionController.h"
class RGBController_RGBFusion : public RGBController
{
public:
RGBController_RGBFusion(RGBFusionController* rgb_fusion_ptr);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
RGBFusionController* rgb_fusion;
};
@@ -0,0 +1,191 @@
/*-----------------------------------------*\
| RGBController_RazerChromaSDK.h |
| |
| Generic RGB Interface for official Razer |
| Chroma SDK |
| |
| Adam Honse (CalcProgrammer1) 9/2/2019 |
\*-----------------------------------------*/
#include "RGBController_RazerChromaSDK.h"
CREATEEFFECT RGBController_RazerChromaSDK::CreateEffect = NULL;
CREATEKEYBOARDEFFECT RGBController_RazerChromaSDK::CreateKeyboardEffect = NULL;
CREATEMOUSEEFFECT RGBController_RazerChromaSDK::CreateMouseEffect = NULL;
CREATEMOUSEPADEFFECT RGBController_RazerChromaSDK::CreateMousepadEffect = NULL;
CREATEHEADSETEFFECT RGBController_RazerChromaSDK::CreateHeadsetEffect = NULL;
CREATECHROMALINKEFFECT RGBController_RazerChromaSDK::CreateChromaLinkEffect = NULL;
RGBController_RazerChromaSDK::RGBController_RazerChromaSDK(unsigned int device_type, HMODULE* hModule)
{
unsigned int led_count = 0;
for (int i = 0; i < RAZER_NUM_DEVICES; i++)
{
if (device_list[i]->razer_type == device_type)
{
name = device_list[i]->name;
type = device_list[i]->type;
location = "Razer Chroma SDK";
for (int zone_id = 0; zone_id < RAZER_MAX_ZONES; zone_id++)
{
if (device_list[i]->zones[zone_id] != NULL)
{
device = device_list[i];
zone* new_zone = new zone();
new_zone->name = device_list[i]->zones[zone_id]->name;
new_zone->type = device_list[i]->zones[zone_id]->type;
std::vector<int> new_zone_map;
for (int led_id = 0; led_id < device_list[i]->zones[zone_id]->leds; led_id++)
{
RGBColor new_color = 0x00000000;
colors.push_back(new_color);
led* new_led = new led();
new_led->name = device_list[i]->zones[zone_id]->name;
leds.push_back(*new_led);
new_zone_map.push_back(led_count);
led_count++;
}
new_zone->map.push_back(new_zone_map);
zones.push_back(*new_zone);
}
}
}
}
if(CreateEffect == NULL) CreateEffect = (CREATEEFFECT)GetProcAddress(*hModule, "CreateEffect");
if(CreateKeyboardEffect == NULL) CreateKeyboardEffect = (CREATEKEYBOARDEFFECT)GetProcAddress(*hModule, "CreateKeyboardEffect");
if(CreateMouseEffect == NULL) CreateMouseEffect = (CREATEMOUSEEFFECT)GetProcAddress(*hModule, "CreateMouseEffect");
if(CreateMousepadEffect == NULL) CreateMousepadEffect = (CREATEMOUSEPADEFFECT)GetProcAddress(*hModule, "CreateMousepadEffect");
if(CreateHeadsetEffect == NULL) CreateHeadsetEffect = (CREATEHEADSETEFFECT)GetProcAddress(*hModule, "CreateHeadsetEffect");
if(CreateChromaLinkEffect == NULL) CreateChromaLinkEffect = (CREATECHROMALINKEFFECT)GetProcAddress(*hModule, "CreateChromaLinkEffect");
}
int RGBController_RazerChromaSDK::GetMode()
{
return 0;
}
void RGBController_RazerChromaSDK::SetMode(int mode)
{
}
void RGBController_RazerChromaSDK::SetCustomMode()
{
}
void RGBController_RazerChromaSDK::SetAllLEDs(RGBColor color)
{
for (int i = 0; i < colors.size(); i++)
{
colors[i] = color;
}
UpdateLEDs();
}
void RGBController_RazerChromaSDK::SetAllZoneLEDs(int zone, RGBColor color)
{
for (int x = 0; x < zones[zone].map.size(); x++)
{
for (int y = 0; y < zones[zone].map[x].size(); y++)
{
colors[zones[zone].map[x][y]] = color;
}
}
UpdateLEDs();
}
void RGBController_RazerChromaSDK::SetLED(int led, RGBColor color)
{
colors[led] = color;
UpdateLEDs();
}
void RGBController_RazerChromaSDK::UpdateLEDs()
{
switch (device->razer_type)
{
case RAZER_GENERIC_MOUSE:
{
ChromaSDK::Mouse::CUSTOM_EFFECT_TYPE2 MouseEffect = {};
std::vector<int> left_zone_map = zones[0].map[0];
for (int left = 1; left < 8; left++)
{
MouseEffect.Color[left][0] = colors[left_zone_map[left - 1]];
}
std::vector<int> right_zone_map = zones[1].map[0];
for (int right = 1; right < 8; right++)
{
MouseEffect.Color[right][6] = colors[right_zone_map[right - 1]];
}
std::vector<int> bottom_zone_map = zones[2].map[0];
for (int bottom = 1; bottom < 6; bottom++)
{
MouseEffect.Color[8][bottom] = colors[bottom_zone_map[bottom - 1]];
}
std::vector<int> scroll_wheel_zone_map = zones[3].map[0];
MouseEffect.Color[2][3] = colors[scroll_wheel_zone_map[0]];
std::vector<int> logo_zone_map = zones[4].map[0];
MouseEffect.Color[7][3] = colors[logo_zone_map[0]];
std::vector<int> numpad_backlight_zone_map = zones[5].map[0];
MouseEffect.Color[4][3] = colors[numpad_backlight_zone_map[0]];
CreateMouseEffect(ChromaSDK::Mouse::CHROMA_CUSTOM2, &MouseEffect, NULL);
}
break;
case RAZER_GENERIC_MOUSEPAD:
{
ChromaSDK::Mousepad::CUSTOM_EFFECT_TYPE MousepadEffect = {};
for (int x = 0; x < 15; x++)
{
MousepadEffect.Color[x] = colors[x];
}
CreateMousepadEffect(ChromaSDK::Mousepad::CHROMA_CUSTOM, &MousepadEffect, NULL);
}
break;
case RAZER_CHROMA_HDK:
{
ChromaSDK::CUSTOM_EFFECT_TYPE ChromaBoxEffect = {};
for (int x = 0; x < 16; x++)
{
for (int y = 0; y < 4; y++)
{
ChromaBoxEffect.Color[y][x] = colors[(y*16) + x];
}
}
CreateEffect(ChromaSDK::CHROMABOX, ChromaSDK::CHROMA_CUSTOM, &ChromaBoxEffect, NULL);
}
break;
}
}
@@ -0,0 +1,249 @@
/*-----------------------------------------*\
| RGBController_RazerChromaSDK.h |
| |
| Generic RGB Interface for official Razer |
| Chroma SDK |
| |
| Adam Honse (CalcProgrammer1) 9/2/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include <Windows.h>
#include "RzChromaSDKDefines.h"
#include "RzChromaSDKTypes.h"
#include "RzErrors.h"
using namespace ChromaSDK::Keyboard;
typedef RZRESULT(*INIT)(void);
typedef RZRESULT(*UNINIT)(void);
typedef RZRESULT(*CREATEEFFECT)(RZDEVICEID DeviceId, ChromaSDK::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEKEYBOARDEFFECT)(ChromaSDK::Keyboard::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEMOUSEEFFECT)(ChromaSDK::Mouse::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEMOUSEPADEFFECT)(ChromaSDK::Mousepad::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEHEADSETEFFECT)(ChromaSDK::Headset::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATECHROMALINKEFFECT)(ChromaSDK::ChromaLink::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
#define RAZER_MAX_ZONES 6
#define RAZER_NUM_DEVICES 3
enum
{
RAZER_GENERIC_KEYBOARD,
RAZER_GENERIC_MOUSE,
RAZER_GENERIC_MOUSEPAD,
RAZER_CHROMA_HDK
};
enum
{
RAZER_MODE_CUSTOM,
RAZER_MODE_OFF,
RAZER_MODE_STATIC,
RAZER_MODE_BREATHING,
RAZER_MODE_SPECTRUM_CYCLE,
RAZER_MODE_WAVE,
RAZER_MODE_REACTIVE,
RAZER_NUM_MODES
};
typedef struct
{
std::string name;
unsigned int type;
unsigned int leds;
} razer_zone;
typedef struct
{
std::string name;
unsigned int razer_type;
unsigned int type;
const razer_zone* zones[RAZER_MAX_ZONES];
} razer_device;
/*------------------------------------------------------------ *\
| Razer Generic Mouse |
| |
| Zone "Left" |
| Linear |
| 7 LEDs |
| |
| Zone "Right" |
| Linear |
| 7 LEDs |
| |
| Zone "Bottom" |
| Linear |
| 5 LEDs |
| |
| Zone "Scroll Wheel" |
| Single |
| 1 LED |
| |
| Zone "Logo" |
| Single |
| 1 LED |
| |
| Zone "Numpad/Backlight" |
| Single |
| 1 LED |
\*-------------------------------------------------------------*/
static const razer_zone mouse_left_zone =
{
"Left LED Strip",
ZONE_TYPE_LINEAR,
7
};
static const razer_zone mouse_right_zone =
{
"Right LED Strip",
ZONE_TYPE_LINEAR,
7
};
static const razer_zone mouse_bottom_zone =
{
"Bottom LED Strip",
ZONE_TYPE_LINEAR,
5
};
static const razer_zone mouse_scroll_wheel_zone =
{
"Scroll Wheel",
ZONE_TYPE_SINGLE,
1
};
static const razer_zone mouse_logo_zone =
{
"Logo",
ZONE_TYPE_SINGLE,
1
};
static const razer_zone mouse_numpad_backlight_zone =
{
"Numpad/Backlight",
ZONE_TYPE_SINGLE,
1
};
static const razer_device mouse_device =
{
"Razer Generic Mouse",
RAZER_GENERIC_MOUSE,
DEVICE_TYPE_MOUSE,
{
&mouse_left_zone,
&mouse_right_zone,
&mouse_bottom_zone,
&mouse_scroll_wheel_zone,
&mouse_logo_zone,
&mouse_numpad_backlight_zone
}
};
/*------------------------------------------------------------ *\
| Razer Generic Mousepad (Firefly, Mug Holder) |
| |
| Zone "LED Strip" |
| Linear |
| 15 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone mousepad_zone =
{
"LED Strip",
ZONE_TYPE_LINEAR,
15
};
static const razer_device mousepad_device =
{
"Razer Generic Mousepad",
RAZER_GENERIC_MOUSEPAD,
DEVICE_TYPE_MOUSE,
{
&mousepad_zone,
NULL,
NULL,
NULL,
NULL,
NULL
}
};
/*------------------------------------------------------------ *\
| Razer Chroma HDK |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
| |
| Zone "LED Strip" |
| Linear |
| 16 LEDs |
\*-------------------------------------------------------------*/
static const razer_zone chromahdk_zone =
{
"LED Strip",
ZONE_TYPE_LINEAR,
16
};
static const razer_device chromahdk_device =
{
"Razer Chroma HDK",
RAZER_CHROMA_HDK,
DEVICE_TYPE_LEDSTRIP,
{
&chromahdk_zone,
&chromahdk_zone,
&chromahdk_zone,
&chromahdk_zone,
NULL,
NULL
}
};
static const razer_device* device_list[RAZER_NUM_DEVICES] =
{
&mouse_device,
&mousepad_device,
&chromahdk_device
};
class RGBController_RazerChromaSDK : public RGBController
{
public:
RGBController_RazerChromaSDK(unsigned int device_type, HMODULE* hModule);
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void SetAllLEDs(RGBColor color);
void SetAllZoneLEDs(int zone, RGBColor color);
void SetLED(int led, RGBColor color);
void UpdateLEDs();
private:
const razer_device* device;
static CREATEEFFECT CreateEffect;
static CREATEKEYBOARDEFFECT CreateKeyboardEffect;
static CREATEMOUSEEFFECT CreateMouseEffect;
static CREATEMOUSEPADEFFECT CreateMousepadEffect;
static CREATEHEADSETEFFECT CreateHeadsetEffect;
static CREATECHROMALINKEFFECT CreateChromaLinkEffect;
};
+70
View File
@@ -0,0 +1,70 @@
#include "RGBController.h"
#include "RGBController_RazerChromaSDK.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
static HMODULE hModule;
#include "RzChromaSDKDefines.h"
#include "RzChromaSDKTypes.h"
#include "RzErrors.h"
using namespace ChromaSDK::Keyboard;
typedef RZRESULT(*INIT)(void);
typedef RZRESULT(*UNINIT)(void);
typedef RZRESULT(*CREATEEFFECT)(RZDEVICEID DeviceId, ChromaSDK::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEKEYBOARDEFFECT)(ChromaSDK::Keyboard::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEMOUSEEFFECT)(ChromaSDK::Mouse::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEMOUSEPADEFFECT)(ChromaSDK::Mousepad::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATEHEADSETEFFECT)(ChromaSDK::Headset::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
typedef RZRESULT(*CREATECHROMALINKEFFECT)(ChromaSDK::ChromaLink::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID* pEffectId);
#ifdef _WIN64
#define CHROMASDKDLL ("RzChromaSDK64.dll")
#else
#define CHROMASDKDLL ("RzChromaSDK.dll")
#endif
/******************************************************************************************\
* *
* DetectRazerChromaSDKControllers *
* *
* Detect devices supported by the Razer Chroma SDK *
* * *
\******************************************************************************************/
void DetectRazerChromaSDKControllers(std::vector<RGBController*>& rgb_controllers)
{
RGBController_RazerChromaSDK* razer_rgb;
// Dynamically loads the Chroma SDK library.
hModule = LoadLibrary(CHROMASDKDLL);
if (hModule)
{
INIT Init = (INIT)GetProcAddress(hModule, "Init");
if (Init)
{
//Initialize the SDK
Init();
}
}
razer_rgb = new RGBController_RazerChromaSDK(RAZER_GENERIC_MOUSE, &hModule);
rgb_controllers.push_back(razer_rgb);
razer_rgb = new RGBController_RazerChromaSDK(RAZER_GENERIC_MOUSEPAD, &hModule);
rgb_controllers.push_back(razer_rgb);
razer_rgb = new RGBController_RazerChromaSDK(RAZER_CHROMA_HDK, &hModule);
rgb_controllers.push_back(razer_rgb);
} /* DetectRazerChromaSDKControllers() */
Vendored Submodule
+1
Submodule dependencies/libe131 added at 0fc009f1f6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+61
View File
@@ -0,0 +1,61 @@
libusb 1.0 Windows binary snapshot - README
*********************************************************************
* The latest version of this snapshot can always be downloaded at: *
* https://sourceforge.net/projects/libusb/files/ *
*********************************************************************
o Visual Studio:
- Open existing or create a new project for your application
- Copy libusb.h, from the include\libusb-1.0\ directory, into your project and
make sure that the location where the file reside appears in the 'Additional
Include Directories' section (Configuration Properties -> C/C++ -> General).
- Copy the relevant .lib file from MS32\ or MS64\ and add 'libusb-1.0.lib' to
your 'Additional Dependencies' (Configuration Properties -> Linker -> Input)
Also make sure that the directory where libusb-1.0.lib resides is added to
'Additional Library Directories' (Configuration Properties -> Linker
-> General)
- If you use the static version of the libusb library, make sure that
'Runtime Library' is set to 'Multi-threaded DLL (/MD)' (Configuration
Properties -> C/C++ -> Code Generation).
NB: If your application requires /MT (Multi-threaded/libCMT), you need to
recompile a static libusb 1.0 library from source.
- Compile and run your application. If you use the DLL version of libusb-1.0,
remember that you need to have a copy of the DLL either in the runtime
directory or in system32
o WDK/DDK:
- The following is an example of a sources files that you can use to compile
a libusb 1.0 based console application. In this sample ..\libusb\ is the
directory where you would have copied libusb.h as well as the relevant
libusb-1.0.lib
TARGETNAME=your_app
TARGETTYPE=PROGRAM
USE_MSVCRT=1
UMTYPE=console
INCLUDES=..\libusb;$(DDK_INC_PATH)
TARGETLIBS=..\libusb\libusb-1.0.lib
SOURCES=your_app.c
- Note that if you plan to use libCMT instead of MSVCRT (USE_LIBCMT=1 instead
of USE_MSVCRT=1), you will need to recompile libusb to use libCMT. This can
easily be achieved, in the DDK environment, by running 'ddk_build /MT'
o MinGW/cygwin
- Copy libusb.h, from include/libusb-1.0/ to your default include directory,
and copy the MinGW32/ or MinGW64/ .a files to your default library directory.
Or, if you don't want to use the default locations, make sure that you feed
the relevant -I and -L options to the compiler.
- Add the '-lusb-1.0' linker option when compiling.
o Additional information:
- The libusb 1.0 API documentation can be accessed at:
http://api.libusb.info
- For some libusb samples (including source), please have a look in examples/
- For additional information on the libusb 1.0 Windows backend please visit:
http://windows.libusb.info
- The MinGW and MS generated DLLs are fully interchangeable, provided that you
use the import libs provided or generate one from the .def also provided.
- If you find any issue, please visit http://libusb.info/ and check the
Support section
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+831
View File
@@ -0,0 +1,831 @@
/*
* Copyright © 2001 Stephen Williams ([email protected])
* Copyright © 2001-2002 David Brownell ([email protected])
* Copyright © 2008 Roger Williams ([email protected])
* Copyright © 2012 Pete Batard ([email protected])
* Copyright © 2013 Federico Manzan ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "libusb.h"
#include "ezusb.h"
extern void logerror(const char *format, ...)
__attribute__ ((format(printf, 1, 2)));
/*
* This file contains functions for uploading firmware into Cypress
* EZ-USB microcontrollers. These chips use control endpoint 0 and vendor
* specific commands to support writing into the on-chip SRAM. They also
* support writing into the CPUCS register, which is how we reset the
* processor after loading firmware (including the reset vector).
*
* These Cypress devices are 8-bit 8051 based microcontrollers with
* special support for USB I/O. They come in several packages, and
* some can be set up with external memory when device costs allow.
* Note that the design was originally by AnchorChips, so you may find
* references to that vendor (which was later merged into Cypress).
* The Cypress FX parts are largely compatible with the Anchorhip ones.
*/
int verbose = 1;
/*
* return true if [addr,addr+len] includes external RAM
* for Anchorchips EZ-USB or Cypress EZ-USB FX
*/
static bool fx_is_external(uint32_t addr, size_t len)
{
/* with 8KB RAM, 0x0000-0x1b3f can be written
* we can't tell if it's a 4KB device here
*/
if (addr <= 0x1b3f)
return ((addr + len) > 0x1b40);
/* there may be more RAM; unclear if we can write it.
* some bulk buffers may be unused, 0x1b3f-0x1f3f
* firmware can set ISODISAB for 2KB at 0x2000-0x27ff
*/
return true;
}
/*
* return true if [addr,addr+len] includes external RAM
* for Cypress EZ-USB FX2
*/
static bool fx2_is_external(uint32_t addr, size_t len)
{
/* 1st 8KB for data/code, 0x0000-0x1fff */
if (addr <= 0x1fff)
return ((addr + len) > 0x2000);
/* and 512 for data, 0xe000-0xe1ff */
else if (addr >= 0xe000 && addr <= 0xe1ff)
return ((addr + len) > 0xe200);
/* otherwise, it's certainly external */
else
return true;
}
/*
* return true if [addr,addr+len] includes external RAM
* for Cypress EZ-USB FX2LP
*/
static bool fx2lp_is_external(uint32_t addr, size_t len)
{
/* 1st 16KB for data/code, 0x0000-0x3fff */
if (addr <= 0x3fff)
return ((addr + len) > 0x4000);
/* and 512 for data, 0xe000-0xe1ff */
else if (addr >= 0xe000 && addr <= 0xe1ff)
return ((addr + len) > 0xe200);
/* otherwise, it's certainly external */
else
return true;
}
/*****************************************************************************/
/*
* These are the requests (bRequest) that the bootstrap loader is expected
* to recognize. The codes are reserved by Cypress, and these values match
* what EZ-USB hardware, or "Vend_Ax" firmware (2nd stage loader) uses.
* Cypress' "a3load" is nice because it supports both FX and FX2, although
* it doesn't have the EEPROM support (subset of "Vend_Ax").
*/
#define RW_INTERNAL 0xA0 /* hardware implements this one */
#define RW_MEMORY 0xA3
/*
* Issues the specified vendor-specific write request.
*/
static int ezusb_write(libusb_device_handle *device, const char *label,
uint8_t opcode, uint32_t addr, const unsigned char *data, size_t len)
{
int status;
if (verbose > 1)
logerror("%s, addr 0x%08x len %4u (0x%04x)\n", label, addr, (unsigned)len, (unsigned)len);
status = libusb_control_transfer(device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
opcode, addr & 0xFFFF, addr >> 16,
(unsigned char*)data, (uint16_t)len, 1000);
if (status != (signed)len) {
if (status < 0)
logerror("%s: %s\n", label, libusb_error_name(status));
else
logerror("%s ==> %d\n", label, status);
}
return (status < 0) ? -EIO : 0;
}
/*
* Issues the specified vendor-specific read request.
*/
static int ezusb_read(libusb_device_handle *device, const char *label,
uint8_t opcode, uint32_t addr, const unsigned char *data, size_t len)
{
int status;
if (verbose > 1)
logerror("%s, addr 0x%08x len %4u (0x%04x)\n", label, addr, (unsigned)len, (unsigned)len);
status = libusb_control_transfer(device,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
opcode, addr & 0xFFFF, addr >> 16,
(unsigned char*)data, (uint16_t)len, 1000);
if (status != (signed)len) {
if (status < 0)
logerror("%s: %s\n", label, libusb_error_name(status));
else
logerror("%s ==> %d\n", label, status);
}
return (status < 0) ? -EIO : 0;
}
/*
* Modifies the CPUCS register to stop or reset the CPU.
* Returns false on error.
*/
static bool ezusb_cpucs(libusb_device_handle *device, uint32_t addr, bool doRun)
{
int status;
uint8_t data = doRun ? 0x00 : 0x01;
if (verbose)
logerror("%s\n", data ? "stop CPU" : "reset CPU");
status = libusb_control_transfer(device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
RW_INTERNAL, addr & 0xFFFF, addr >> 16,
&data, 1, 1000);
if ((status != 1) &&
/* We may get an I/O error from libusb as the device disappears */
((!doRun) || (status != LIBUSB_ERROR_IO)))
{
const char *mesg = "can't modify CPUCS";
if (status < 0)
logerror("%s: %s\n", mesg, libusb_error_name(status));
else
logerror("%s\n", mesg);
return false;
} else
return true;
}
/*
* Send an FX3 jumpt to address command
* Returns false on error.
*/
static bool ezusb_fx3_jump(libusb_device_handle *device, uint32_t addr)
{
int status;
if (verbose)
logerror("transfer execution to Program Entry at 0x%08x\n", addr);
status = libusb_control_transfer(device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
RW_INTERNAL, addr & 0xFFFF, addr >> 16,
NULL, 0, 1000);
/* We may get an I/O error from libusb as the device disappears */
if ((status != 0) && (status != LIBUSB_ERROR_IO))
{
const char *mesg = "failed to send jump command";
if (status < 0)
logerror("%s: %s\n", mesg, libusb_error_name(status));
else
logerror("%s\n", mesg);
return false;
} else
return true;
}
/*****************************************************************************/
/*
* Parse an Intel HEX image file and invoke the poke() function on the
* various segments to implement policies such as writing to RAM (with
* a one or two stage loader setup, depending on the firmware) or to
* EEPROM (two stages required).
*
* image - the hex image file
* context - for use by poke()
* is_external - if non-null, used to check which segments go into
* external memory (writable only by software loader)
* poke - called with each memory segment; errors indicated
* by returning negative values.
*
* Caller is responsible for halting CPU as needed, such as when
* overwriting a second stage loader.
*/
static int parse_ihex(FILE *image, void *context,
bool (*is_external)(uint32_t addr, size_t len),
int (*poke) (void *context, uint32_t addr, bool external,
const unsigned char *data, size_t len))
{
unsigned char data[1023];
uint32_t data_addr = 0;
size_t data_len = 0;
int rc;
int first_line = 1;
bool external = false;
/* Read the input file as an IHEX file, and report the memory segments
* as we go. Each line holds a max of 16 bytes, but uploading is
* faster (and EEPROM space smaller) if we merge those lines into larger
* chunks. Most hex files keep memory segments together, which makes
* such merging all but free. (But it may still be worth sorting the
* hex files to make up for undesirable behavior from tools.)
*
* Note that EEPROM segments max out at 1023 bytes; the upload protocol
* allows segments of up to 64 KBytes (more than a loader could handle).
*/
for (;;) {
char buf[512], *cp;
char tmp, type;
size_t len;
unsigned idx, off;
cp = fgets(buf, sizeof(buf), image);
if (cp == NULL) {
logerror("EOF without EOF record!\n");
break;
}
/* EXTENSION: "# comment-till-end-of-line", for copyrights etc */
if (buf[0] == '#')
continue;
if (buf[0] != ':') {
logerror("not an ihex record: %s", buf);
return -2;
}
/* ignore any newline */
cp = strchr(buf, '\n');
if (cp)
*cp = 0;
if (verbose >= 3)
logerror("** LINE: %s\n", buf);
/* Read the length field (up to 16 bytes) */
tmp = buf[3];
buf[3] = 0;
len = strtoul(buf+1, NULL, 16);
buf[3] = tmp;
/* Read the target offset (address up to 64KB) */
tmp = buf[7];
buf[7] = 0;
off = (int)strtoul(buf+3, NULL, 16);
buf[7] = tmp;
/* Initialize data_addr */
if (first_line) {
data_addr = off;
first_line = 0;
}
/* Read the record type */
tmp = buf[9];
buf[9] = 0;
type = (char)strtoul(buf+7, NULL, 16);
buf[9] = tmp;
/* If this is an EOF record, then make it so. */
if (type == 1) {
if (verbose >= 2)
logerror("EOF on hexfile\n");
break;
}
if (type != 0) {
logerror("unsupported record type: %u\n", type);
return -3;
}
if ((len * 2) + 11 > strlen(buf)) {
logerror("record too short?\n");
return -4;
}
/* FIXME check for _physically_ contiguous not just virtually
* e.g. on FX2 0x1f00-0x2100 includes both on-chip and external
* memory so it's not really contiguous */
/* flush the saved data if it's not contiguous,
* or when we've buffered as much as we can.
*/
if (data_len != 0
&& (off != (data_addr + data_len)
/* || !merge */
|| (data_len + len) > sizeof(data))) {
if (is_external)
external = is_external(data_addr, data_len);
rc = poke(context, data_addr, external, data, data_len);
if (rc < 0)
return -1;
data_addr = off;
data_len = 0;
}
/* append to saved data, flush later */
for (idx = 0, cp = buf+9 ; idx < len ; idx += 1, cp += 2) {
tmp = cp[2];
cp[2] = 0;
data[data_len + idx] = (uint8_t)strtoul(cp, NULL, 16);
cp[2] = tmp;
}
data_len += len;
}
/* flush any data remaining */
if (data_len != 0) {
if (is_external)
external = is_external(data_addr, data_len);
rc = poke(context, data_addr, external, data, data_len);
if (rc < 0)
return -1;
}
return 0;
}
/*
* Parse a binary image file and write it as is to the target.
* Applies to Cypress BIX images for RAM or Cypress IIC images
* for EEPROM.
*
* image - the BIX image file
* context - for use by poke()
* is_external - if non-null, used to check which segments go into
* external memory (writable only by software loader)
* poke - called with each memory segment; errors indicated
* by returning negative values.
*
* Caller is responsible for halting CPU as needed, such as when
* overwriting a second stage loader.
*/
static int parse_bin(FILE *image, void *context,
bool (*is_external)(uint32_t addr, size_t len), int (*poke)(void *context,
uint32_t addr, bool external, const unsigned char *data, size_t len))
{
unsigned char data[4096];
uint32_t data_addr = 0;
size_t data_len = 0;
int rc;
bool external = false;
for (;;) {
data_len = fread(data, 1, 4096, image);
if (data_len == 0)
break;
if (is_external)
external = is_external(data_addr, data_len);
rc = poke(context, data_addr, external, data, data_len);
if (rc < 0)
return -1;
data_addr += (uint32_t)data_len;
}
return feof(image)?0:-1;
}
/*
* Parse a Cypress IIC image file and invoke the poke() function on the
* various segments for writing to RAM
*
* image - the IIC image file
* context - for use by poke()
* is_external - if non-null, used to check which segments go into
* external memory (writable only by software loader)
* poke - called with each memory segment; errors indicated
* by returning negative values.
*
* Caller is responsible for halting CPU as needed, such as when
* overwriting a second stage loader.
*/
static int parse_iic(FILE *image, void *context,
bool (*is_external)(uint32_t addr, size_t len),
int (*poke)(void *context, uint32_t addr, bool external, const unsigned char *data, size_t len))
{
unsigned char data[4096];
uint32_t data_addr = 0;
size_t data_len = 0, read_len;
uint8_t block_header[4];
int rc;
bool external = false;
long file_size, initial_pos;
initial_pos = ftell(image);
if (initial_pos < 0)
return -1;
if (fseek(image, 0L, SEEK_END) != 0)
return -1;
file_size = ftell(image);
if (fseek(image, initial_pos, SEEK_SET) != 0)
return -1;
for (;;) {
/* Ignore the trailing reset IIC data (5 bytes) */
if (ftell(image) >= (file_size - 5))
break;
if (fread(&block_header, 1, sizeof(block_header), image) != 4) {
logerror("unable to read IIC block header\n");
return -1;
}
data_len = (block_header[0] << 8) + block_header[1];
data_addr = (block_header[2] << 8) + block_header[3];
if (data_len > sizeof(data)) {
/* If this is ever reported as an error, switch to using malloc/realloc */
logerror("IIC data block too small - please report this error to libusb.info\n");
return -1;
}
read_len = fread(data, 1, data_len, image);
if (read_len != data_len) {
logerror("read error\n");
return -1;
}
if (is_external)
external = is_external(data_addr, data_len);
rc = poke(context, data_addr, external, data, data_len);
if (rc < 0)
return -1;
}
return 0;
}
/* the parse call will be selected according to the image type */
static int (*parse[IMG_TYPE_MAX])(FILE *image, void *context, bool (*is_external)(uint32_t addr, size_t len),
int (*poke)(void *context, uint32_t addr, bool external, const unsigned char *data, size_t len))
= { parse_ihex, parse_iic, parse_bin };
/*****************************************************************************/
/*
* For writing to RAM using a first (hardware) or second (software)
* stage loader and 0xA0 or 0xA3 vendor requests
*/
typedef enum {
_undef = 0,
internal_only, /* hardware first-stage loader */
skip_internal, /* first phase, second-stage loader */
skip_external /* second phase, second-stage loader */
} ram_mode;
struct ram_poke_context {
libusb_device_handle *device;
ram_mode mode;
size_t total, count;
};
#define RETRY_LIMIT 5
static int ram_poke(void *context, uint32_t addr, bool external,
const unsigned char *data, size_t len)
{
struct ram_poke_context *ctx = (struct ram_poke_context*)context;
int rc;
unsigned retry = 0;
switch (ctx->mode) {
case internal_only: /* CPU should be stopped */
if (external) {
logerror("can't write %u bytes external memory at 0x%08x\n",
(unsigned)len, addr);
return -EINVAL;
}
break;
case skip_internal: /* CPU must be running */
if (!external) {
if (verbose >= 2) {
logerror("SKIP on-chip RAM, %u bytes at 0x%08x\n",
(unsigned)len, addr);
}
return 0;
}
break;
case skip_external: /* CPU should be stopped */
if (external) {
if (verbose >= 2) {
logerror("SKIP external RAM, %u bytes at 0x%08x\n",
(unsigned)len, addr);
}
return 0;
}
break;
case _undef:
default:
logerror("bug\n");
return -EDOM;
}
ctx->total += len;
ctx->count++;
/* Retry this till we get a real error. Control messages are not
* NAKed (just dropped) so time out means is a real problem.
*/
while ((rc = ezusb_write(ctx->device,
external ? "write external" : "write on-chip",
external ? RW_MEMORY : RW_INTERNAL,
addr, data, len)) < 0
&& retry < RETRY_LIMIT) {
if (rc != LIBUSB_ERROR_TIMEOUT)
break;
retry += 1;
}
return rc;
}
/*
* Load a Cypress Image file into target RAM.
* See http://www.cypress.com/?docID=41351 (AN76405 PDF) for more info.
*/
static int fx3_load_ram(libusb_device_handle *device, const char *path)
{
uint32_t dCheckSum, dExpectedCheckSum, dAddress, i, dLen, dLength;
uint32_t* dImageBuf;
unsigned char *bBuf, hBuf[4], blBuf[4], rBuf[4096];
FILE *image;
int ret = 0;
image = fopen(path, "rb");
if (image == NULL) {
logerror("unable to open '%s' for input\n", path);
return -2;
} else if (verbose)
logerror("open firmware image %s for RAM upload\n", path);
// Read header
if (fread(hBuf, sizeof(char), sizeof(hBuf), image) != sizeof(hBuf)) {
logerror("could not read image header");
ret = -3;
goto exit;
}
// check "CY" signature byte and format
if ((hBuf[0] != 'C') || (hBuf[1] != 'Y')) {
logerror("image doesn't have a CYpress signature\n");
ret = -3;
goto exit;
}
// Check bImageType
switch(hBuf[3]) {
case 0xB0:
if (verbose)
logerror("normal FW binary %s image with checksum\n", (hBuf[2]&0x01)?"data":"executable");
break;
case 0xB1:
logerror("security binary image is not currently supported\n");
ret = -3;
goto exit;
case 0xB2:
logerror("VID:PID image is not currently supported\n");
ret = -3;
goto exit;
default:
logerror("invalid image type 0x%02X\n", hBuf[3]);
ret = -3;
goto exit;
}
// Read the bootloader version
if (verbose) {
if ((ezusb_read(device, "read bootloader version", RW_INTERNAL, 0xFFFF0020, blBuf, 4) < 0)) {
logerror("Could not read bootloader version\n");
ret = -8;
goto exit;
}
logerror("FX3 bootloader version: 0x%02X%02X%02X%02X\n", blBuf[3], blBuf[2], blBuf[1], blBuf[0]);
}
dCheckSum = 0;
if (verbose)
logerror("writing image...\n");
while (1) {
if ((fread(&dLength, sizeof(uint32_t), 1, image) != 1) || // read dLength
(fread(&dAddress, sizeof(uint32_t), 1, image) != 1)) { // read dAddress
logerror("could not read image");
ret = -3;
goto exit;
}
if (dLength == 0)
break; // done
// coverity[tainted_data]
dImageBuf = (uint32_t*)calloc(dLength, sizeof(uint32_t));
if (dImageBuf == NULL) {
logerror("could not allocate buffer for image chunk\n");
ret = -4;
goto exit;
}
// read sections
if (fread(dImageBuf, sizeof(uint32_t), dLength, image) != dLength) {
logerror("could not read image");
free(dImageBuf);
ret = -3;
goto exit;
}
for (i = 0; i < dLength; i++)
dCheckSum += dImageBuf[i];
dLength <<= 2; // convert to Byte length
bBuf = (unsigned char*) dImageBuf;
while (dLength > 0) {
dLen = 4096; // 4K max
if (dLen > dLength)
dLen = dLength;
if ((ezusb_write(device, "write firmware", RW_INTERNAL, dAddress, bBuf, dLen) < 0) ||
(ezusb_read(device, "read firmware", RW_INTERNAL, dAddress, rBuf, dLen) < 0)) {
logerror("R/W error\n");
free(dImageBuf);
ret = -5;
goto exit;
}
// Verify data: rBuf with bBuf
for (i = 0; i < dLen; i++) {
if (rBuf[i] != bBuf[i]) {
logerror("verify error");
free(dImageBuf);
ret = -6;
goto exit;
}
}
dLength -= dLen;
bBuf += dLen;
dAddress += dLen;
}
free(dImageBuf);
}
// read pre-computed checksum data
if ((fread(&dExpectedCheckSum, sizeof(uint32_t), 1, image) != 1) ||
(dCheckSum != dExpectedCheckSum)) {
logerror("checksum error\n");
ret = -7;
goto exit;
}
// transfer execution to Program Entry
if (!ezusb_fx3_jump(device, dAddress)) {
ret = -6;
}
exit:
fclose(image);
return ret;
}
/*
* Load a firmware file into target RAM. device is the open libusb
* device, and the path is the name of the source file. Open the file,
* parse the bytes, and write them in one or two phases.
*
* If stage == 0, this uses the first stage loader, built into EZ-USB
* hardware but limited to writing on-chip memory or CPUCS. Everything
* is written during one stage, unless there's an error such as the image
* holding data that needs to be written to external memory.
*
* Otherwise, things are written in two stages. First the external
* memory is written, expecting a second stage loader to have already
* been loaded. Then file is re-parsed and on-chip memory is written.
*/
int ezusb_load_ram(libusb_device_handle *device, const char *path, int fx_type, int img_type, int stage)
{
FILE *image;
uint32_t cpucs_addr;
bool (*is_external)(uint32_t off, size_t len);
struct ram_poke_context ctx;
int status;
uint8_t iic_header[8] = { 0 };
int ret = 0;
if (fx_type == FX_TYPE_FX3)
return fx3_load_ram(device, path);
image = fopen(path, "rb");
if (image == NULL) {
logerror("%s: unable to open for input.\n", path);
return -2;
} else if (verbose > 1)
logerror("open firmware image %s for RAM upload\n", path);
if (img_type == IMG_TYPE_IIC) {
if ( (fread(iic_header, 1, sizeof(iic_header), image) != sizeof(iic_header))
|| (((fx_type == FX_TYPE_FX2LP) || (fx_type == FX_TYPE_FX2)) && (iic_header[0] != 0xC2))
|| ((fx_type == FX_TYPE_AN21) && (iic_header[0] != 0xB2))
|| ((fx_type == FX_TYPE_FX1) && (iic_header[0] != 0xB6)) ) {
logerror("IIC image does not contain executable code - cannot load to RAM.\n");
ret = -1;
goto exit;
}
}
/* EZ-USB original/FX and FX2 devices differ, apart from the 8051 core */
switch(fx_type) {
case FX_TYPE_FX2LP:
cpucs_addr = 0xe600;
is_external = fx2lp_is_external;
break;
case FX_TYPE_FX2:
cpucs_addr = 0xe600;
is_external = fx2_is_external;
break;
default:
cpucs_addr = 0x7f92;
is_external = fx_is_external;
break;
}
/* use only first stage loader? */
if (stage == 0) {
ctx.mode = internal_only;
/* if required, halt the CPU while we overwrite its code/data */
if (cpucs_addr && !ezusb_cpucs(device, cpucs_addr, false))
{
ret = -1;
goto exit;
}
/* 2nd stage, first part? loader was already uploaded */
} else {
ctx.mode = skip_internal;
/* let CPU run; overwrite the 2nd stage loader later */
if (verbose)
logerror("2nd stage: write external memory\n");
}
/* scan the image, first (maybe only) time */
ctx.device = device;
ctx.total = ctx.count = 0;
status = parse[img_type](image, &ctx, is_external, ram_poke);
if (status < 0) {
logerror("unable to upload %s\n", path);
ret = status;
goto exit;
}
/* second part of 2nd stage: rescan */
// TODO: what should we do for non HEX images there?
if (stage) {
ctx.mode = skip_external;
/* if needed, halt the CPU while we overwrite the 1st stage loader */
if (cpucs_addr && !ezusb_cpucs(device, cpucs_addr, false))
{
ret = -1;
goto exit;
}
/* at least write the interrupt vectors (at 0x0000) for reset! */
rewind(image);
if (verbose)
logerror("2nd stage: write on-chip memory\n");
status = parse_ihex(image, &ctx, is_external, ram_poke);
if (status < 0) {
logerror("unable to completely upload %s\n", path);
ret = status;
goto exit;
}
}
if (verbose && (ctx.count != 0)) {
logerror("... WROTE: %d bytes, %d segments, avg %d\n",
(int)ctx.total, (int)ctx.count, (int)(ctx.total/ctx.count));
}
/* if required, reset the CPU so it runs what we just uploaded */
if (cpucs_addr && !ezusb_cpucs(device, cpucs_addr, true))
ret = -1;
exit:
fclose(image);
return ret;
}
+120
View File
@@ -0,0 +1,120 @@
#ifndef ezusb_H
#define ezusb_H
/*
* Copyright © 2001 Stephen Williams ([email protected])
* Copyright © 2002 David Brownell ([email protected])
* Copyright © 2013 Federico Manzan ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(_MSC_VER)
#include <stdbool.h>
#else
#define __attribute__(x)
#if !defined(bool)
#define bool int
#endif
#if !defined(true)
#define true (1 == 1)
#endif
#if !defined(false)
#define false (!true)
#endif
#if defined(_PREFAST_)
#pragma warning(disable:28193)
#endif
#endif
#define FX_TYPE_UNDEFINED -1
#define FX_TYPE_AN21 0 /* Original AnchorChips parts */
#define FX_TYPE_FX1 1 /* Updated Cypress versions */
#define FX_TYPE_FX2 2 /* USB 2.0 versions */
#define FX_TYPE_FX2LP 3 /* Updated FX2 */
#define FX_TYPE_FX3 4 /* USB 3.0 versions */
#define FX_TYPE_MAX 5
#define FX_TYPE_NAMES { "an21", "fx", "fx2", "fx2lp", "fx3" }
#define IMG_TYPE_UNDEFINED -1
#define IMG_TYPE_HEX 0 /* Intel HEX */
#define IMG_TYPE_IIC 1 /* Cypress 8051 IIC */
#define IMG_TYPE_BIX 2 /* Cypress 8051 BIX */
#define IMG_TYPE_IMG 3 /* Cypress IMG format */
#define IMG_TYPE_MAX 4
#define IMG_TYPE_NAMES { "Intel HEX", "Cypress 8051 IIC", "Cypress 8051 BIX", "Cypress IMG format" }
#ifdef __cplusplus
extern "C" {
#endif
/*
* Automatically identified devices (VID, PID, type, designation).
* TODO: Could use some validation. Also where's the FX2?
*/
typedef struct {
uint16_t vid;
uint16_t pid;
int type;
const char* designation;
} fx_known_device;
#define FX_KNOWN_DEVICES { \
{ 0x0547, 0x2122, FX_TYPE_AN21, "Cypress EZ-USB (2122S)" },\
{ 0x0547, 0x2125, FX_TYPE_AN21, "Cypress EZ-USB (2121S/2125S)" },\
{ 0x0547, 0x2126, FX_TYPE_AN21, "Cypress EZ-USB (2126S)" },\
{ 0x0547, 0x2131, FX_TYPE_AN21, "Cypress EZ-USB (2131Q/2131S/2135S)" },\
{ 0x0547, 0x2136, FX_TYPE_AN21, "Cypress EZ-USB (2136S)" },\
{ 0x0547, 0x2225, FX_TYPE_AN21, "Cypress EZ-USB (2225)" },\
{ 0x0547, 0x2226, FX_TYPE_AN21, "Cypress EZ-USB (2226)" },\
{ 0x0547, 0x2235, FX_TYPE_AN21, "Cypress EZ-USB (2235)" },\
{ 0x0547, 0x2236, FX_TYPE_AN21, "Cypress EZ-USB (2236)" },\
{ 0x04b4, 0x6473, FX_TYPE_FX1, "Cypress EZ-USB FX1" },\
{ 0x04b4, 0x8613, FX_TYPE_FX2LP, "Cypress EZ-USB FX2LP (68013A/68014A/68015A/68016A)" }, \
{ 0x04b4, 0x00f3, FX_TYPE_FX3, "Cypress FX3" },\
}
/*
* This function uploads the firmware from the given file into RAM.
* Stage == 0 means this is a single stage load (or the first of
* two stages). Otherwise it's the second of two stages; the
* caller having preloaded the second stage loader.
*
* The target processor is reset at the end of this upload.
*/
extern int ezusb_load_ram(libusb_device_handle *device,
const char *path, int fx_type, int img_type, int stage);
/*
* This function uploads the firmware from the given file into EEPROM.
* This uses the right CPUCS address to terminate the EEPROM load with
* a reset command where FX parts behave differently than FX2 ones.
* The configuration byte is as provided here (zero for an21xx parts)
* and the EEPROM type is set so that the microcontroller will boot
* from it.
*
* The caller must have preloaded a second stage loader that knows
* how to respond to the EEPROM write request.
*/
extern int ezusb_load_eeprom(libusb_device_handle *device,
const char *path, int fx_type, int img_type, int config);
/* Verbosity level (default 1). Can be increased or decreased with options v/q */
extern int verbose;
#ifdef __cplusplus
}
#endif
#endif
+309
View File
@@ -0,0 +1,309 @@
/*
* Copyright © 2001 Stephen Williams ([email protected])
* Copyright © 2001-2002 David Brownell ([email protected])
* Copyright © 2008 Roger Williams ([email protected])
* Copyright © 2012 Pete Batard ([email protected])
* Copyright © 2013 Federico Manzan ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/types.h>
#include <getopt.h>
#include "libusb.h"
#include "ezusb.h"
#if !defined(_WIN32) || defined(__CYGWIN__ )
#include <syslog.h>
static bool dosyslog = false;
#include <strings.h>
#define _stricmp strcasecmp
#endif
#ifndef FXLOAD_VERSION
#define FXLOAD_VERSION (__DATE__ " (libusb)")
#endif
#ifndef ARRAYSIZE
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
void logerror(const char *format, ...)
__attribute__ ((format (__printf__, 1, 2)));
void logerror(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#if !defined(_WIN32) || defined(__CYGWIN__ )
if (dosyslog)
vsyslog(LOG_ERR, format, ap);
else
#endif
vfprintf(stderr, format, ap);
va_end(ap);
}
static int print_usage(int error_code) {
fprintf(stderr, "\nUsage: fxload [-v] [-V] [-t type] [-d vid:pid] [-p bus,addr] [-s loader] -i firmware\n");
fprintf(stderr, " -i <path> -- Firmware to upload\n");
fprintf(stderr, " -s <path> -- Second stage loader\n");
fprintf(stderr, " -t <type> -- Target type: an21, fx, fx2, fx2lp, fx3\n");
fprintf(stderr, " -d <vid:pid> -- Target device, as an USB VID:PID\n");
fprintf(stderr, " -p <bus,addr> -- Target device, as a libusb bus number and device address path\n");
fprintf(stderr, " -v -- Increase verbosity\n");
fprintf(stderr, " -q -- Decrease verbosity (silent mode)\n");
fprintf(stderr, " -V -- Print program version\n");
return error_code;
}
#define FIRMWARE 0
#define LOADER 1
int main(int argc, char*argv[])
{
fx_known_device known_device[] = FX_KNOWN_DEVICES;
const char *path[] = { NULL, NULL };
const char *device_id = NULL;
const char *device_path = getenv("DEVICE");
const char *type = NULL;
const char *fx_name[FX_TYPE_MAX] = FX_TYPE_NAMES;
const char *ext, *img_name[] = IMG_TYPE_NAMES;
int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)];
int opt, status;
unsigned int i, j;
unsigned vid = 0, pid = 0;
unsigned busnum = 0, devaddr = 0, _busnum, _devaddr;
libusb_device *dev, **devs;
libusb_device_handle *device = NULL;
struct libusb_device_descriptor desc;
while ((opt = getopt(argc, argv, "qvV?hd:p:i:I:s:S:t:")) != EOF)
switch (opt) {
case 'd':
device_id = optarg;
if (sscanf(device_id, "%x:%x" , &vid, &pid) != 2 ) {
fputs ("please specify VID & PID as \"vid:pid\" in hexadecimal format\n", stderr);
return -1;
}
break;
case 'p':
device_path = optarg;
if (sscanf(device_path, "%u,%u", &busnum, &devaddr) != 2 ) {
fputs ("please specify bus number & device number as \"bus,dev\" in decimal format\n", stderr);
return -1;
}
break;
case 'i':
case 'I':
path[FIRMWARE] = optarg;
break;
case 's':
case 'S':
path[LOADER] = optarg;
break;
case 'V':
puts(FXLOAD_VERSION);
return 0;
case 't':
type = optarg;
break;
case 'v':
verbose++;
break;
case 'q':
verbose--;
break;
case '?':
case 'h':
default:
return print_usage(-1);
}
if (path[FIRMWARE] == NULL) {
logerror("no firmware specified!\n");
return print_usage(-1);
}
if ((device_id != NULL) && (device_path != NULL)) {
logerror("only one of -d or -p can be specified\n");
return print_usage(-1);
}
/* determine the target type */
if (type != NULL) {
for (i=0; i<FX_TYPE_MAX; i++) {
if (strcmp(type, fx_name[i]) == 0) {
fx_type = i;
break;
}
}
if (i >= FX_TYPE_MAX) {
logerror("illegal microcontroller type: %s\n", type);
return print_usage(-1);
}
}
/* open the device using libusb */
status = libusb_init(NULL);
if (status < 0) {
logerror("libusb_init() failed: %s\n", libusb_error_name(status));
return -1;
}
libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, verbose);
/* try to pick up missing parameters from known devices */
if ((type == NULL) || (device_id == NULL) || (device_path != NULL)) {
if (libusb_get_device_list(NULL, &devs) < 0) {
logerror("libusb_get_device_list() failed: %s\n", libusb_error_name(status));
goto err;
}
for (i=0; (dev=devs[i]) != NULL; i++) {
_busnum = libusb_get_bus_number(dev);
_devaddr = libusb_get_device_address(dev);
if ((type != NULL) && (device_path != NULL)) {
// if both a type and bus,addr were specified, we just need to find our match
if ((libusb_get_bus_number(dev) == busnum) && (libusb_get_device_address(dev) == devaddr))
break;
} else {
status = libusb_get_device_descriptor(dev, &desc);
if (status >= 0) {
if (verbose >= 3) {
logerror("examining %04x:%04x (%d,%d)\n",
desc.idVendor, desc.idProduct, _busnum, _devaddr);
}
for (j=0; j<ARRAYSIZE(known_device); j++) {
if ((desc.idVendor == known_device[j].vid)
&& (desc.idProduct == known_device[j].pid)) {
if (// nothing was specified
((type == NULL) && (device_id == NULL) && (device_path == NULL)) ||
// vid:pid was specified and we have a match
((type == NULL) && (device_id != NULL) && (vid == desc.idVendor) && (pid == desc.idProduct)) ||
// bus,addr was specified and we have a match
((type == NULL) && (device_path != NULL) && (busnum == _busnum) && (devaddr == _devaddr)) ||
// type was specified and we have a match
((type != NULL) && (device_id == NULL) && (device_path == NULL) && (fx_type == known_device[j].type)) ) {
fx_type = known_device[j].type;
vid = desc.idVendor;
pid = desc.idProduct;
busnum = _busnum;
devaddr = _devaddr;
break;
}
}
}
if (j < ARRAYSIZE(known_device)) {
if (verbose)
logerror("found device '%s' [%04x:%04x] (%d,%d)\n",
known_device[j].designation, vid, pid, busnum, devaddr);
break;
}
}
}
}
if (dev == NULL) {
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
logerror("could not find a known device - please specify type and/or vid:pid and/or bus,dev\n");
return print_usage(-1);
}
status = libusb_open(dev, &device);
libusb_free_device_list(devs, 1);
if (status < 0) {
logerror("libusb_open() failed: %s\n", libusb_error_name(status));
goto err;
}
} else if (device_id != NULL) {
device = libusb_open_device_with_vid_pid(NULL, (uint16_t)vid, (uint16_t)pid);
if (device == NULL) {
logerror("libusb_open() failed\n");
goto err;
}
}
/* We need to claim the first interface */
libusb_set_auto_detach_kernel_driver(device, 1);
status = libusb_claim_interface(device, 0);
if (status != LIBUSB_SUCCESS) {
libusb_close(device);
logerror("libusb_claim_interface failed: %s\n", libusb_error_name(status));
goto err;
}
if (verbose)
logerror("microcontroller type: %s\n", fx_name[fx_type]);
for (i=0; i<ARRAYSIZE(path); i++) {
if (path[i] != NULL) {
ext = path[i] + strlen(path[i]) - 4;
if ((_stricmp(ext, ".hex") == 0) || (strcmp(ext, ".ihx") == 0))
img_type[i] = IMG_TYPE_HEX;
else if (_stricmp(ext, ".iic") == 0)
img_type[i] = IMG_TYPE_IIC;
else if (_stricmp(ext, ".bix") == 0)
img_type[i] = IMG_TYPE_BIX;
else if (_stricmp(ext, ".img") == 0)
img_type[i] = IMG_TYPE_IMG;
else {
logerror("%s is not a recognized image type\n", path[i]);
goto err;
}
}
if (verbose && path[i] != NULL)
logerror("%s: type %s\n", path[i], img_name[img_type[i]]);
}
if (path[LOADER] == NULL) {
/* single stage, put into internal memory */
if (verbose > 1)
logerror("single stage: load on-chip memory\n");
status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 0);
} else {
/* two-stage, put loader into internal memory */
if (verbose > 1)
logerror("1st stage: load 2nd stage loader\n");
status = ezusb_load_ram(device, path[LOADER], fx_type, img_type[LOADER], 0);
if (status == 0) {
/* two-stage, put firmware into internal memory */
if (verbose > 1)
logerror("2nd state: load on-chip memory\n");
status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 1);
}
}
libusb_release_interface(device, 0);
libusb_close(device);
libusb_exit(NULL);
return status;
err:
libusb_exit(NULL);
return -1;
}
+71
View File
@@ -0,0 +1,71 @@
/*
* libusb example program to list devices on the bus
* Copyright © 2007 Daniel Drake <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include "libusb.h"
static void print_devs(libusb_device **devs)
{
libusb_device *dev;
int i = 0, j = 0;
uint8_t path[8];
while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
fprintf(stderr, "failed to get device descriptor");
return;
}
printf("%04x:%04x (bus %d, device %d)",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev), libusb_get_device_address(dev));
r = libusb_get_port_numbers(dev, path, sizeof(path));
if (r > 0) {
printf(" path: %d", path[0]);
for (j = 1; j < r; j++)
printf(".%d", path[j]);
}
printf("\n");
}
}
int main(void)
{
libusb_device **devs;
int r;
ssize_t cnt;
r = libusb_init(NULL);
if (r < 0)
return r;
cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0)
return (int) cnt;
print_devs(devs);
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
return 0;
}
+256
View File
@@ -0,0 +1,256 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file was originally part of the w64 mingw-runtime package.
*/
/* ISO C9x 7.18 Integer types <stdint.h>
* Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* Contributor: Danny Smith <[email protected]>
* Modified for libusb/MSVC: Pete Batard <[email protected]>
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Date: 2010-04-02
*/
#ifndef _MSC_VER
#error This header should only be used with Microsoft compilers
#endif
#ifndef _STDINT_H
#define _STDINT_H
#ifndef _INTPTR_T_DEFINED
#define _INTPTR_T_DEFINED
#ifndef __intptr_t_defined
#define __intptr_t_defined
#undef intptr_t
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef int intptr_t;
#endif /* _WIN64 */
#endif /* __intptr_t_defined */
#endif /* _INTPTR_T_DEFINED */
#ifndef _UINTPTR_T_DEFINED
#define _UINTPTR_T_DEFINED
#ifndef __uintptr_t_defined
#define __uintptr_t_defined
#undef uintptr_t
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef unsigned int uintptr_t;
#endif /* _WIN64 */
#endif /* __uintptr_t_defined */
#endif /* _UINTPTR_T_DEFINED */
#ifndef _PTRDIFF_T_DEFINED
#define _PTRDIFF_T_DEFINED
#ifndef _PTRDIFF_T_
#define _PTRDIFF_T_
#undef ptrdiff_t
#ifdef _WIN64
typedef __int64 ptrdiff_t;
#else
typedef int ptrdiff_t;
#endif /* _WIN64 */
#endif /* _PTRDIFF_T_ */
#endif /* _PTRDIFF_T_DEFINED */
#ifndef _WCHAR_T_DEFINED
#define _WCHAR_T_DEFINED
#ifndef __cplusplus
typedef unsigned short wchar_t;
#endif /* C++ */
#endif /* _WCHAR_T_DEFINED */
#ifndef _WCTYPE_T_DEFINED
#define _WCTYPE_T_DEFINED
#ifndef _WINT_T
#define _WINT_T
typedef unsigned short wint_t;
typedef unsigned short wctype_t;
#endif /* _WINT_T */
#endif /* _WCTYPE_T_DEFINED */
/* 7.18.1.1 Exact-width integer types */
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
/* 7.18.1.2 Minimum-width integer types */
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
typedef int int_least32_t;
typedef unsigned uint_least32_t;
typedef __int64 int_least64_t;
typedef unsigned __int64 uint_least64_t;
/* 7.18.1.3 Fastest minimum-width integer types
* Not actually guaranteed to be fastest for all purposes
* Here we use the exact-width types for 8 and 16-bit ints.
*/
typedef __int8 int_fast8_t;
typedef unsigned __int8 uint_fast8_t;
typedef __int16 int_fast16_t;
typedef unsigned __int16 uint_fast16_t;
typedef __int32 int_fast32_t;
typedef unsigned __int32 uint_fast32_t;
typedef __int64 int_fast64_t;
typedef unsigned __int64 uint_fast64_t;
/* 7.18.1.5 Greatest-width integer types */
typedef __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
/* 7.18.2 Limits of specified-width integer types */
/* 7.18.2.1 Limits of exact-width integer types */
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 255
#define UINT16_MAX 65535
#define UINT32_MAX 0xffffffffU /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
/* 7.18.2.2 Limits of minimum-width integer types */
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
/* 7.18.2.3 Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
/* 7.18.2.4 Limits of integer types capable of holding
object pointers */
#ifdef _WIN64
#define INTPTR_MIN INT64_MIN
#define INTPTR_MAX INT64_MAX
#define UINTPTR_MAX UINT64_MAX
#else
#define INTPTR_MIN INT32_MIN
#define INTPTR_MAX INT32_MAX
#define UINTPTR_MAX UINT32_MAX
#endif
/* 7.18.2.5 Limits of greatest-width integer types */
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
/* 7.18.3 Limits of other integer types */
#ifdef _WIN64
#define PTRDIFF_MIN INT64_MIN
#define PTRDIFF_MAX INT64_MAX
#else
#define PTRDIFF_MIN INT32_MIN
#define PTRDIFF_MAX INT32_MAX
#endif
#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX
#ifndef SIZE_MAX
#ifdef _WIN64
#define SIZE_MAX UINT64_MAX
#else
#define SIZE_MAX UINT32_MAX
#endif
#endif
#ifndef WCHAR_MIN /* also in wchar.h */
#define WCHAR_MIN 0U
#define WCHAR_MAX 0xffffU
#endif
/*
* wint_t is unsigned short for compatibility with MS runtime
*/
#define WINT_MIN 0U
#define WINT_MAX 0xffffU
/* 7.18.4 Macros for integer constants */
/* 7.18.4.1 Macros for minimum-width integer constants
Accoding to Douglas Gwyn <[email protected]>:
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
9899:1999 as initially published, the expansion was required
to be an integer constant of precisely matching type, which
is impossible to accomplish for the shorter types on most
platforms, because C99 provides no standard way to designate
an integer constant with width less than that of type int.
TC1 changed this to require just an integer constant
*expression* with *promoted* type."
The trick used here is from Clive D W Feather.
*/
#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
/* The 'trick' doesn't work in C89 for long long because, without
suffix, (val) will be evaluated as int, not intmax_t */
#define INT64_C(val) val##i64
#define UINT8_C(val) (val)
#define UINT16_C(val) (val)
#define UINT32_C(val) (val##i32)
#define UINT64_C(val) val##ui64
/* 7.18.4.2 Macros for greatest-width integer constants */
#define INTMAX_C(val) val##i64
#define UINTMAX_C(val) val##ui64
#endif
+277
View File
@@ -0,0 +1,277 @@
/*
* Test suite program based of libusb-0.1-compat testlibusb
* Copyright (c) 2013 Nathan Hjelm <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <string.h>
#include "libusb.h"
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
int verbose = 0;
static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
{
printf(" USB 3.0 Endpoint Companion:\n");
printf(" bMaxBurst: %d\n", ep_comp->bMaxBurst);
printf(" bmAttributes: 0x%02x\n", ep_comp->bmAttributes);
printf(" wBytesPerInterval: %d\n", ep_comp->wBytesPerInterval);
}
static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
{
int i, ret;
printf(" Endpoint:\n");
printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize);
printf(" bInterval: %d\n", endpoint->bInterval);
printf(" bRefresh: %d\n", endpoint->bRefresh);
printf(" bSynchAddress: %d\n", endpoint->bSynchAddress);
for (i = 0; i < endpoint->extra_length;) {
if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {
struct libusb_ss_endpoint_companion_descriptor *ep_comp;
ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);
if (LIBUSB_SUCCESS != ret) {
continue;
}
print_endpoint_comp(ep_comp);
libusb_free_ss_endpoint_companion_descriptor(ep_comp);
}
i += endpoint->extra[i];
}
}
static void print_altsetting(const struct libusb_interface_descriptor *interface)
{
uint8_t i;
printf(" Interface:\n");
printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber);
printf(" bAlternateSetting: %d\n", interface->bAlternateSetting);
printf(" bNumEndpoints: %d\n", interface->bNumEndpoints);
printf(" bInterfaceClass: %d\n", interface->bInterfaceClass);
printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass);
printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol);
printf(" iInterface: %d\n", interface->iInterface);
for (i = 0; i < interface->bNumEndpoints; i++)
print_endpoint(&interface->endpoint[i]);
}
static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
{
printf(" USB 2.0 Extension Capabilities:\n");
printf(" bDevCapabilityType: %d\n", usb_2_0_ext_cap->bDevCapabilityType);
printf(" bmAttributes: 0x%x\n", usb_2_0_ext_cap->bmAttributes);
}
static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
{
printf(" USB 3.0 Capabilities:\n");
printf(" bDevCapabilityType: %d\n", ss_usb_cap->bDevCapabilityType);
printf(" bmAttributes: 0x%x\n", ss_usb_cap->bmAttributes);
printf(" wSpeedSupported: 0x%x\n", ss_usb_cap->wSpeedSupported);
printf(" bFunctionalitySupport: %d\n", ss_usb_cap->bFunctionalitySupport);
printf(" bU1devExitLat: %d\n", ss_usb_cap->bU1DevExitLat);
printf(" bU2devExitLat: %d\n", ss_usb_cap->bU2DevExitLat);
}
static void print_bos(libusb_device_handle *handle)
{
struct libusb_bos_descriptor *bos;
int ret;
ret = libusb_get_bos_descriptor(handle, &bos);
if (0 > ret) {
return;
}
printf(" Binary Object Store (BOS):\n");
printf(" wTotalLength: %d\n", bos->wTotalLength);
printf(" bNumDeviceCaps: %d\n", bos->bNumDeviceCaps);
if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
ret = libusb_get_usb_2_0_extension_descriptor(NULL, bos->dev_capability[0],&usb_2_0_extension);
if (0 > ret) {
return;
}
print_2_0_ext_cap(usb_2_0_extension);
libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
}
if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
struct libusb_ss_usb_device_capability_descriptor *dev_cap;
ret = libusb_get_ss_usb_device_capability_descriptor(NULL, bos->dev_capability[0],&dev_cap);
if (0 > ret) {
return;
}
print_ss_usb_cap(dev_cap);
libusb_free_ss_usb_device_capability_descriptor(dev_cap);
}
libusb_free_bos_descriptor(bos);
}
static void print_interface(const struct libusb_interface *interface)
{
int i;
for (i = 0; i < interface->num_altsetting; i++)
print_altsetting(&interface->altsetting[i]);
}
static void print_configuration(struct libusb_config_descriptor *config)
{
uint8_t i;
printf(" Configuration:\n");
printf(" wTotalLength: %d\n", config->wTotalLength);
printf(" bNumInterfaces: %d\n", config->bNumInterfaces);
printf(" bConfigurationValue: %d\n", config->bConfigurationValue);
printf(" iConfiguration: %d\n", config->iConfiguration);
printf(" bmAttributes: %02xh\n", config->bmAttributes);
printf(" MaxPower: %d\n", config->MaxPower);
for (i = 0; i < config->bNumInterfaces; i++)
print_interface(&config->interface[i]);
}
static int print_device(libusb_device *dev, int level)
{
struct libusb_device_descriptor desc;
libusb_device_handle *handle = NULL;
char description[256];
char string[256];
int ret;
uint8_t i;
ret = libusb_get_device_descriptor(dev, &desc);
if (ret < 0) {
fprintf(stderr, "failed to get device descriptor");
return -1;
}
ret = libusb_open(dev, &handle);
if (LIBUSB_SUCCESS == ret) {
if (desc.iManufacturer) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
if (ret > 0)
snprintf(description, sizeof(description), "%s - ", string);
else
snprintf(description, sizeof(description), "%04X - ",
desc.idVendor);
}
else
snprintf(description, sizeof(description), "%04X - ",
desc.idVendor);
if (desc.iProduct) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
if (ret > 0)
snprintf(description + strlen(description), sizeof(description) -
strlen(description), "%s", string);
else
snprintf(description + strlen(description), sizeof(description) -
strlen(description), "%04X", desc.idProduct);
}
else
snprintf(description + strlen(description), sizeof(description) -
strlen(description), "%04X", desc.idProduct);
}
else {
snprintf(description, sizeof(description), "%04X - %04X",
desc.idVendor, desc.idProduct);
}
printf("%.*sDev (bus %d, device %d): %s\n", level * 2, " ",
libusb_get_bus_number(dev), libusb_get_device_address(dev), description);
if (handle && verbose) {
if (desc.iSerialNumber) {
ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
if (ret > 0)
printf("%.*s - Serial Number: %s\n", level * 2,
" ", string);
}
}
if (verbose) {
for (i = 0; i < desc.bNumConfigurations; i++) {
struct libusb_config_descriptor *config;
ret = libusb_get_config_descriptor(dev, i, &config);
if (LIBUSB_SUCCESS != ret) {
printf(" Couldn't retrieve descriptors\n");
continue;
}
print_configuration(config);
libusb_free_config_descriptor(config);
}
if (handle && desc.bcdUSB >= 0x0201) {
print_bos(handle);
}
}
if (handle)
libusb_close(handle);
return 0;
}
int main(int argc, char *argv[])
{
libusb_device **devs;
ssize_t cnt;
int r, i;
if (argc > 1 && !strcmp(argv[1], "-v"))
verbose = 1;
r = libusb_init(NULL);
if (r < 0)
return r;
cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0)
return (int)cnt;
for (i = 0; devs[i]; ++i) {
print_device(devs[i], 0);
}
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
return 0;
}
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More