Add more sleeps to prevent mode corruption and add a function for reading the LED configuration register

This commit is contained in:
Adam Honse 2020-08-30 01:43:14 -05:00
parent 877469cd2d
commit f577e5ef3c
3 changed files with 49 additions and 14 deletions

View file

@ -30,18 +30,20 @@ PolychromeController::PolychromeController(i2c_smbus_interface* bus, polychrome_
if((major_version < 0x03) && (major_version > 0x00))
{
device_name = "ASRock ASR LED";
led_count = 1;
asr_led = true;
memset(zone_led_count, 0, sizeof(zone_led_count));
}
else if(major_version == 0x03)
{
device_name = "ASRock Polychrome";
led_count = 1;
asr_led = false;
ReadLEDConfiguration();
}
else
{
led_count = 0;
memset(zone_led_count, 0, sizeof(zone_led_count));
}
}
@ -84,9 +86,29 @@ unsigned short PolychromeController::ReadFirmwareVersion()
}
}
unsigned int PolychromeController::GetLEDCount()
void PolychromeController::ReadLEDConfiguration()
{
return(led_count);
// The LED configuration register holds 6 bytes, so the first read should return 6
// If not, set all zone sizes to zero
if (bus->i2c_smbus_read_byte_data(dev, POLYCHROME_REG_LED_CONFIG) == 0x06)
{
std::this_thread::sleep_for(1ms);
zone_led_count[POLYCHROME_ZONE_RGB_FAN_HDR] = bus->i2c_smbus_read_byte(dev);
std::this_thread::sleep_for(1ms);
zone_led_count[POLYCHROME_ZONE_RGB_LED_HDR] = bus->i2c_smbus_read_byte(dev);
std::this_thread::sleep_for(1ms);
zone_led_count[POLYCHROME_ZONE_AUDIO] = bus->i2c_smbus_read_byte(dev);
std::this_thread::sleep_for(1ms);
zone_led_count[POLYCHROME_ZONE_PCH] = bus->i2c_smbus_read_byte(dev);
std::this_thread::sleep_for(1ms);
zone_led_count[POLYCHROME_ZONE_IO_COVER] = bus->i2c_smbus_read_byte(dev);
std::this_thread::sleep_for(1ms);
zone_led_count[POLYCHROME_ZONE_ADDRESSABLE] = bus->i2c_smbus_read_byte(dev);
}
else
{
memset(zone_led_count, 0, sizeof(zone_led_count));
}
}
unsigned int PolychromeController::GetMode()
@ -149,6 +171,8 @@ void PolychromeController::SetColorsAndSpeed(unsigned char led, unsigned char re
\*-----------------------------------------------------*/
bus->i2c_smbus_write_block_data(dev, POLYCHROME_REG_LED_SELECT, 1, select_led_pkt);
std::this_thread::sleep_for(1ms);
/*-----------------------------------------------------*\
| Polychrome firmware always writes color to fixed reg |
\*-----------------------------------------------------*/

View file

@ -48,6 +48,7 @@ enum
POLYCHROME_REG_MODE = 0x30, /* Mode selection register */
POLYCHROME_REG_LED_SELECT = 0x31, /* LED selection register */
POLYCHROME_REG_LED_COUNT = 0x32, /* Additional LED count register */
POLYCHROME_REG_LED_CONFIG = 0x33, /* LED configuration register */
POLYCHROME_REG_COLOR = 0x34, /* Color register: Red, Green, Blue */
};
@ -78,6 +79,16 @@ enum
POLYCHROME_SPEED_MAX = 0x00, /* Fastest speed */
};
enum
{
POLYCHROME_ZONE_RGB_FAN_HDR = 0x00, /* RGB Fan Header */
POLYCHROME_ZONE_RGB_LED_HDR = 0x01, /* RGB LED Header */
POLYCHROME_ZONE_AUDIO = 0x02, /* Audio Zone LEDs */
POLYCHROME_ZONE_PCH = 0x03, /* PCH Zone LEDs */
POLYCHROME_ZONE_IO_COVER = 0x04, /* IO Cover Zone LEDs */
POLYCHROME_ZONE_ADDRESSABLE = 0x05, /* Addressable LED header */
};
class PolychromeController
{
public:
@ -86,7 +97,6 @@ public:
std::string GetDeviceName();
std::string GetFirmwareVersion();
unsigned int GetLEDCount();
unsigned int GetMode();
bool IsAsrLed();
void SetColorsAndSpeed(unsigned char led, unsigned char red, unsigned char green, unsigned char blue);
@ -95,11 +105,12 @@ public:
private:
bool asr_led;
std::string device_name;
unsigned int led_count;
unsigned int zone_led_count[6];
unsigned char active_mode;
unsigned char active_speed;
i2c_smbus_interface* bus;
polychrome_dev_id dev;
unsigned short ReadFirmwareVersion();
void ReadLEDConfiguration();
};

View file

@ -55,15 +55,15 @@ void DetectPolychromeControllers(std::vector<i2c_smbus_interface*>& busses, std:
{
new_polychrome = new PolychromeController(busses[bus], 0x6A);
if(new_polychrome->GetLEDCount() != 0)
{
// if(new_polychrome->GetLEDCount() != 0)
// {
new_controller = new RGBController_Polychrome(new_polychrome);
rgb_controllers.push_back(new_controller);
}
else
{
delete new_polychrome;
}
// }
// else
// {
// delete new_polychrome;
// }
}
}