Add i2c tool for reading multiple bytes from an SMBus device register
This commit is contained in:
parent
4e95bc55d8
commit
c386a6c571
5 changed files with 163 additions and 39 deletions
|
|
@ -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() */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ private slots:
|
|||
|
||||
void on_DumpButton_clicked();
|
||||
|
||||
void on_ReadButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBSystemInfoPageUi *ui;
|
||||
std::vector<i2c_smbus_interface *>& busses;
|
||||
|
|
|
|||
|
|
@ -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,44 +61,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="DumpButton">
|
||||
<property name="text">
|
||||
<string>Dump Device</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="2" column="0">
|
||||
<widget class="QLabel" name="SMBusDumpLabel">
|
||||
<property name="text">
|
||||
<string>SMBus Dumper:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="SMBusAdaptersLabel">
|
||||
<property name="text">
|
||||
<string>SMBus Adapters:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="DetectButton">
|
||||
<property name="text">
|
||||
<string>Detect Devices</string>
|
||||
</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">
|
||||
<property name="text">
|
||||
|
|
@ -78,6 +68,9 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="SMBusAdaptersBox"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="SMBusDetectModeLabel">
|
||||
<property name="text">
|
||||
|
|
@ -88,6 +81,81 @@
|
|||
<item row="1" column="2">
|
||||
<widget class="QComboBox" name="SMBusDetectionModeBox"/>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="DetectButton">
|
||||
<property name="text">
|
||||
<string>Detect Devices</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="DumpButton">
|
||||
<property name="text">
|
||||
<string>Dump Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="SMBusReaderLabel">
|
||||
<property name="text">
|
||||
<string>SMBus Reader:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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>
|
||||
<tabstops>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue