From 441c462e59388ef984abdcb3640e48e92c236bce Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 22 Dec 2019 00:01:27 -0600 Subject: [PATCH] Add SMBus/I2C dumping tool to System Information page --- i2c_tools/i2c_tools.cpp | 42 +++++++++++++++++++++ i2c_tools/i2c_tools.h | 2 + qt/OpenRGBSystemInfoPage.cpp | 8 ++++ qt/OpenRGBSystemInfoPage.h | 2 + qt/OpenRGBSystemInfoPage.ui | 71 +++++++++++++++++++++++++++++++++--- 5 files changed, 120 insertions(+), 5 deletions(-) diff --git a/i2c_tools/i2c_tools.cpp b/i2c_tools/i2c_tools.cpp index 21f8f159..f89e296b 100644 --- a/i2c_tools/i2c_tools.cpp +++ b/i2c_tools/i2c_tools.cpp @@ -79,3 +79,45 @@ std::string i2c_detect(i2c_smbus_interface * bus, int mode) return text; } /* i2c_detect() */ + +/******************************************************************************************\ +* * +* i2c_dump * +* * +* Prints the values at each address of a given SMBus device * +* * +* bus - pointer to i2c_smbus_interface to scan * +* address - SMBus device address to scan * +* * +\******************************************************************************************/ + +std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address) +{ + int i, j; + + int start = 0x0000; + + char line[128]; + std::string text; + + sprintf(line, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n"); + text.append(line); + + for (i = 0; i < 0xFF; i += 16) + { + sprintf(line, "%04x: ", i + start); + text.append(line); + + for (j = 0; j < 16; j++) + { + sprintf(line, "%02x ", (unsigned char )bus->i2c_smbus_read_byte_data(address, start + i + j)); + text.append(line); + } + + sprintf(line, "\r\n"); + text.append(line); + } + + return text; + +} /* i2c_dump() */ diff --git a/i2c_tools/i2c_tools.h b/i2c_tools/i2c_tools.h index a992fa65..7353f6d0 100644 --- a/i2c_tools/i2c_tools.h +++ b/i2c_tools/i2c_tools.h @@ -7,3 +7,5 @@ #define MODE_FUNC 3 std::string i2c_detect(i2c_smbus_interface * bus, int mode); + +std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address); diff --git a/qt/OpenRGBSystemInfoPage.cpp b/qt/OpenRGBSystemInfoPage.cpp index e31b28a1..f136ea2a 100644 --- a/qt/OpenRGBSystemInfoPage.cpp +++ b/qt/OpenRGBSystemInfoPage.cpp @@ -41,3 +41,11 @@ void Ui::OpenRGBSystemInfoPage::on_DetectButton_clicked() ui->SMBusDataText->setPlainText(i2c_detect(bus, MODE_QUICK).c_str()); } + +void Ui::OpenRGBSystemInfoPage::on_DumpButton_clicked() +{ + i2c_smbus_interface* bus = busses[ui->SMBusAdaptersBox->currentIndex()]; + unsigned char address = ui->DumpAddressBox->value(); + + ui->SMBusDataText->setPlainText(i2c_dump(bus, address).c_str()); +} diff --git a/qt/OpenRGBSystemInfoPage.h b/qt/OpenRGBSystemInfoPage.h index d624861d..887897bc 100644 --- a/qt/OpenRGBSystemInfoPage.h +++ b/qt/OpenRGBSystemInfoPage.h @@ -20,6 +20,8 @@ public: private slots: void on_DetectButton_clicked(); + void on_DumpButton_clicked(); + private: Ui::OpenRGBSystemInfoPageUi *ui; std::vector& busses; diff --git a/qt/OpenRGBSystemInfoPage.ui b/qt/OpenRGBSystemInfoPage.ui index 80ce84ba..49a11fd7 100644 --- a/qt/OpenRGBSystemInfoPage.ui +++ b/qt/OpenRGBSystemInfoPage.ui @@ -7,7 +7,7 @@ 0 0 500 - 300 + 320 @@ -16,7 +16,7 @@ - 20 + 50 10 100 22 @@ -29,7 +29,7 @@ - 120 + 160 10 200 22 @@ -40,9 +40,9 @@ 50 - 60 + 80 400 - 200 + 210 @@ -59,6 +59,67 @@ Detect Devices + + + + 370 + 40 + 80 + 22 + + + + Dump Device + + + + + + 50 + 40 + 100 + 22 + + + + SMBus Dumper: + + + + + + 220 + 40 + 51 + 22 + + + + Address: + + + + + + 280 + 40 + 80 + 22 + + + + + + + 0x + + + 255 + + + 16 + +