Browse Source

Add i2c tool for reading multiple bytes from an SMBus device register

polychrome_b450_steel_legend
Adam Honse 1 year ago
parent
commit
c386a6c571
  1. 32
      i2c_tools/i2c_tools.cpp
  2. 2
      i2c_tools/i2c_tools.h
  3. 20
      qt/OpenRGBSystemInfoPage.cpp
  4. 2
      qt/OpenRGBSystemInfoPage.h
  5. 128
      qt/OpenRGBSystemInfoPage.ui

32
i2c_tools/i2c_tools.cpp

@ -121,3 +121,35 @@ std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address)
return text;
} /* i2c_dump() */
/******************************************************************************************\
* *
* i2c_read *
* *
* Prints <size> values read from register address regaddr of a given SMBus device *
* *
* bus - pointer to i2c_smbus_interface to scan *
* address - SMBus device address to scan *
* regaddr - register address to read from *
* size - number of bytes to read *
* *
\******************************************************************************************/
std::string i2c_read(i2c_smbus_interface * bus, unsigned char address, unsigned char regaddr, unsigned char size)
{
int i;
bus->i2c_smbus_write_byte(address, regaddr);
char line[128];
std::string text;
for(i = 0; i < size; i++)
{
sprintf(line, "%02x ", (unsigned char)bus->i2c_smbus_read_byte(address));
text.append(line);
}
return text;
} /* i2c_read() */

2
i2c_tools/i2c_tools.h

@ -9,3 +9,5 @@
std::string i2c_detect(i2c_smbus_interface * bus, int mode);
std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address);
std::string i2c_read(i2c_smbus_interface * bus, unsigned char address, unsigned char regaddr, unsigned char size);

20
qt/OpenRGBSystemInfoPage.cpp

@ -88,3 +88,23 @@ void Ui::OpenRGBSystemInfoPage::on_DumpButton_clicked()
ui->SMBusDataText->setPlainText(i2c_dump(bus, address).c_str());
}
}
void Ui::OpenRGBSystemInfoPage::on_ReadButton_clicked()
{
int current_index = ui->SMBusAdaptersBox->currentIndex();
if(current_index < 0)
{
current_index = 0;
}
if(busses.size() > current_index)
{
i2c_smbus_interface* bus = busses[current_index];
unsigned char address = ui->ReadAddressBox->value();
unsigned char regaddr = ui->ReadRegisterBox->value();
unsigned char size = ui->ReadSizeBox->value();
ui->SMBusDataText->setPlainText(i2c_read(bus, address, regaddr, size).c_str());
}
}

2
qt/OpenRGBSystemInfoPage.h

@ -22,6 +22,8 @@ private slots:
void on_DumpButton_clicked();
void on_ReadButton_clicked();
private:
Ui::OpenRGBSystemInfoPageUi *ui;
std::vector<i2c_smbus_interface *>& busses;

128
qt/OpenRGBSystemInfoPage.ui

@ -14,9 +14,37 @@
<string>Frame</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="4">
<item row="0" column="0">
<widget class="QLabel" name="SMBusAdaptersLabel">
<property name="text">
<string>SMBus Adapters:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="DumpAddressLabel">
<property name="text">
<string>Address:</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="ReadButton">
<property name="text">
<string>Read Device</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="QPlainTextEdit" name="SMBusDataText"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="SMBusDumpLabel">
<property name="text">
<string>SMBus Dumper:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="DumpAddressBox">
<property name="suffix">
@ -33,33 +61,25 @@
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="DumpButton">
<item row="1" column="0">
<widget class="QLabel" name="SMBusDetectorLabel">
<property name="text">
<string>Dump Device</string>
<string>SMBus Detector:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="DumpAddressLabel">
<property name="text">
<string>Address:</string>
</property>
</widget>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="SMBusAdaptersBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="SMBusDumpLabel">
<item row="1" column="1">
<widget class="QLabel" name="SMBusDetectModeLabel">
<property name="text">
<string>SMBus Dumper:</string>
<string>Detection Mode:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="SMBusAdaptersLabel">
<property name="text">
<string>SMBus Adapters:</string>
</property>
</widget>
<item row="1" column="2">
<widget class="QComboBox" name="SMBusDetectionModeBox"/>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="DetectButton">
@ -68,25 +88,73 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="SMBusAdaptersBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="SMBusDetectorLabel">
<item row="2" column="3">
<widget class="QPushButton" name="DumpButton">
<property name="text">
<string>SMBus Detector:</string>
<string>Dump Device</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="SMBusDetectModeLabel">
<item row="3" column="0">
<widget class="QLabel" name="SMBusReaderLabel">
<property name="text">
<string>Detection Mode:</string>
<string>SMBus Reader:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="SMBusDetectionModeBox"/>
<item row="3" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="ReadAddressLabel">
<property name="text">
<string>Addr:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="ReadAddressBox">
<property name="prefix">
<string>0x</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ReadRegisterLabel">
<property name="text">
<string>Reg:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="ReadRegisterBox">
<property name="prefix">
<string>0x</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ReadSizeLabel">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="ReadSizeBox"/>
</item>
</layout>
</item>
</layout>
</widget>

Loading…
Cancel
Save