1 use std
::time
::Duration
;
3 use crate::{piix4_i2c
, rgb
::RGB
, timer
};
5 // use windows::{*, Win32::{System::LibraryLoader::*, Foundation::HCS_E_CONNECTION_CLOSED, Security::InitializeAcl}, Devices::I2c::*, core::HSTRING};
7 use crc
::{Algorithm
, Crc
};
9 const CRC8_ALG
: Algorithm
<u8> = Algorithm
{
21 const BUS_ADDRESS
: i32 = 0x0B00;
23 // Called "device location" in 'CorsairDominatorPlatinumController' class.
24 const ADDRESS_DDR_1
: i32 = 0x19;
25 const ADDRESS_DDR_2
: i32 = 0x1B;
27 const CORSAIR_LED_COUNT
: usize = 12;
29 pub struct Controller
{
35 pub fn new(ddr_address
: u8) -> Self {
37 bus
: piix4_i2c
::I2c
::new(0x0B00),
43 self.bus
.i2c_smbus_write_quick(self.ddr_address
, 0);
46 pub fn set_color(&self, color
: &RGB
) {
47 let mut data
= [0u8; CORSAIR_LED_COUNT
* 3 + 2];
50 for i
in 0..CORSAIR_LED_COUNT
{
51 let offset
= i
* 3 + 1;
52 data
[offset
] = color
.red
;
53 data
[offset
+ 1] = color
.green
;
54 data
[offset
+ 2] = color
.blue
;
57 let crc
= Crc
::<u8>::new(&CRC8_ALG
);
58 let mut digest
= crc
.digest();
59 digest
.update(&data
[0..data
.len() - 1]); // '-1' to not take the last byte.
60 data
[data
.len() - 1] = digest
.finalize();
62 let timer
= timer
::Sleep
::new();
65 .write_block_data(self.ddr_address
, 0x31, &data
[0..piix4_i2c
::I2C_BLOCK_MAX
]);
66 timer
.wait(Duration
::from_micros(800));
69 .write_block_data(self.ddr_address
, 0x32, &data
[piix4_i2c
::I2C_BLOCK_MAX
..]);
70 timer
.wait(Duration
::from_micros(200));
74 // TESTS WITH I2C from winapi:
76 // let connection_settings = I2cConnectionSettings::Create(ADDRESS_DDR_1).unwrap();
78 // // For A770: "DISPLAY\\INTC_I2C\\7&3255D98A&0&UID26040"
79 // // "PCI\\VEN_1022&DEV_790B&SUBSYS_88771043&REV_71\\3&11583659&0&A0"
81 // let selector = I2cDevice::GetDeviceSelector().unwrap();
82 // println!("{:?}", selector);
84 // let devices_async = Devices::Enumeration::DeviceInformation::FindAllAsync().unwrap(); // Devices::Enumeration::DeviceInformation::FindAllAsyncAqsFilter(&selector).unwrap();
85 // let devices = devices_async.get().unwrap();
87 // // println!("{:?}", devices.Size());
89 // for i in 0..devices.Size().unwrap() {
90 // let device = devices.GetAt(i).unwrap();
91 // println!("Device Name: {:?}", device.Name().unwrap());
92 // println!("Device Kind: {:?}", device.Kind().unwrap());
93 // println!("Device ID: {:?}", device.Id().unwrap());
94 // println!("-----------------")
97 // // let device_id = "PCI\\VEN_1022&DEV_790B";
99 // // let async_get_device = I2cDevice::FromIdAsync(&HSTRING::from(device_id), &connection_settings).unwrap();
100 // // let device = async_get_device.get();
102 // // println!("{:?}", device);