From 7912a42b05957f30058ecce3410de3c04d738a86 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Wed, 10 Dec 2025 13:16:06 +0900 Subject: [PATCH 1/5] Update lpGBT.h --- include/pflib/lpGBT.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/pflib/lpGBT.h b/include/pflib/lpGBT.h index ec969789b..e6709233b 100644 --- a/include/pflib/lpGBT.h +++ b/include/pflib/lpGBT.h @@ -190,6 +190,13 @@ class lpGBT { bool strong_scl = true, bool strong_sda = true, bool pull_up_scl = false, bool pull_up_sda = false); + /** Setup i2c bus speed + \param ibus Which I2C bus (0-2) + \param speed_khz I2C speed (appropriate values are 100, 200, 400, 1000) + Note that this really just stores the information on what speed to use in a temporary variable + */ + void setup_i2c_speed(int ibus, int speed_khz); + /** Start an I2C read */ void start_i2c_read(int ibus, uint8_t i2c_addr, int len = 1); From a05c57028aac607b4ece547fb4e8e61a77800d55 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Wed, 10 Dec 2025 13:42:10 +0900 Subject: [PATCH 2/5] Update I2C.cxx --- src/pflib/lpgbt/I2C.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pflib/lpgbt/I2C.cxx b/src/pflib/lpgbt/I2C.cxx index 2aa7169a2..3590165c7 100644 --- a/src/pflib/lpgbt/I2C.cxx +++ b/src/pflib/lpgbt/I2C.cxx @@ -5,7 +5,7 @@ namespace lpgbt { void I2C::set_bus_speed(int speed) { ispeed_ = speed; - lpgbt_.setup_i2c(ibus_, speed); + lpgbt_.setup_i2c_speed(ibus_, speed); } int I2C::get_bus_speed() { return ispeed_; } From 93539fcf55d25b359a5f7f968828e0ef029f872d Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Wed, 10 Dec 2025 13:44:26 +0900 Subject: [PATCH 3/5] Update lpGBT.cxx --- src/pflib/lpGBT.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pflib/lpGBT.cxx b/src/pflib/lpGBT.cxx index 7f401f0af..4065d24fb 100644 --- a/src/pflib/lpGBT.cxx +++ b/src/pflib/lpGBT.cxx @@ -594,6 +594,15 @@ void lpGBT::setup_i2c(int ibus, int speed_khz, bool scl_drive, bool strong_scl, if (speed_khz > 500 && speed_khz < 2000) i2c_[ibus].ctl_reg |= 0x03; } +void lpGBT::setup_i2c_speed(int ibus, int speed_khz) { + if (ibus < 0 || ibus > 2) return; + + i2c_[ibus].ctl_reg &= 0x80; // keep the scl_drive + if (speed_khz > 125 && speed_khz < 300) i2c_[ibus].ctl_reg |= 0x01; + if (speed_khz > 300 && speed_khz < 500) i2c_[ibus].ctl_reg |= 0x02; + if (speed_khz > 500 && speed_khz < 2000) i2c_[ibus].ctl_reg |= 0x03; +} + static constexpr uint8_t CMD_I2C_WRITE_CR = 0; static constexpr uint8_t CMD_I2C_1BYTE_WRITE = 2; static constexpr uint8_t CMD_I2C_1BYTE_READ = 3; From df2790a963bd9cfc605a0c5a462a9ad795687274 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Wed, 10 Dec 2025 13:46:28 +0900 Subject: [PATCH 4/5] Update Bias.cxx --- src/pflib/Bias.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pflib/Bias.cxx b/src/pflib/Bias.cxx index 45248a573..69d0346ee 100644 --- a/src/pflib/Bias.cxx +++ b/src/pflib/Bias.cxx @@ -25,6 +25,7 @@ MAX5825::MAX5825(std::shared_ptr i2c, uint8_t addr) std::vector MAX5825::get(uint8_t channel) { uint8_t cmd = (uint8_t)(MAX5825::CODEn | (channel & 0x07)); + i2c_->set_bus_speed(100); std::vector retval = i2c_->general_write_read(our_addr_, {cmd}, 2); return retval; @@ -33,6 +34,7 @@ std::vector MAX5825::get(uint8_t channel) { void MAX5825::set(uint8_t channel, uint16_t code) { uint8_t cmd = (uint8_t)(0xB0 | (channel & 0x07)); + i2c_->set_bus_speed(100); std::vector retval = i2c_->general_write_read(our_addr_, {cmd, static_cast((code << 4) >> 8), @@ -58,18 +60,21 @@ Bias::Bias(std::shared_ptr i2c_bias, std::shared_ptr i2c_board) { void Bias::initialize() { // Reset all DAC:s + i2c_bias_->set_bus_speed(100); i2c_bias_->general_write_read(0x10, {0x35, 0x96, 0x30}, 0); i2c_bias_->general_write_read(0x12, {0x35, 0x96, 0x30}, 0); i2c_bias_->general_write_read(0x14, {0x35, 0x96, 0x30}, 0); i2c_bias_->general_write_read(0x18, {0x35, 0x96, 0x30}, 0); // Set internal ref on DAC to 4.096 V + i2c_bias_->set_bus_speed(100); i2c_bias_->general_write_read(0x10, {0x27, 0x00, 0x00}, 0); i2c_bias_->general_write_read(0x12, {0x27, 0x00, 0x00}, 0); i2c_bias_->general_write_read(0x14, {0x27, 0x00, 0x00}, 0); i2c_bias_->general_write_read(0x18, {0x27, 0x00, 0x00}, 0); // Set up the GPIO device MCP23008 + i2c_board_->set_bus_speed(100); i2c_board_->general_write_read(0x20, {0x00, 0x70}, 0); // Turn on the status LED @@ -88,6 +93,7 @@ void Bias::initialize() { } double Bias::readTemp() { + i2c_board_->set_bus_speed(100); i2c_board_->general_write_read(0x4A, {0x00}, 0); usleep(250); // Response is a bit slow std::vector ret = i2c_board_->general_write_read(0x4A, {}, 2); From ebdfe17ddaffc334766fb858942561c70b7a9850 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 10 Dec 2025 04:49:16 +0000 Subject: [PATCH 5/5] Apply clang-format --style=Google --- include/pflib/lpGBT.h | 3 ++- src/pflib/lpGBT.cxx | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/pflib/lpGBT.h b/include/pflib/lpGBT.h index e6709233b..b4f378ce4 100644 --- a/include/pflib/lpGBT.h +++ b/include/pflib/lpGBT.h @@ -193,7 +193,8 @@ class lpGBT { /** Setup i2c bus speed \param ibus Which I2C bus (0-2) \param speed_khz I2C speed (appropriate values are 100, 200, 400, 1000) - Note that this really just stores the information on what speed to use in a temporary variable + Note that this really just stores the information on what speed to use in + a temporary variable */ void setup_i2c_speed(int ibus, int speed_khz); diff --git a/src/pflib/lpGBT.cxx b/src/pflib/lpGBT.cxx index 4065d24fb..fe0806048 100644 --- a/src/pflib/lpGBT.cxx +++ b/src/pflib/lpGBT.cxx @@ -596,8 +596,8 @@ void lpGBT::setup_i2c(int ibus, int speed_khz, bool scl_drive, bool strong_scl, void lpGBT::setup_i2c_speed(int ibus, int speed_khz) { if (ibus < 0 || ibus > 2) return; - - i2c_[ibus].ctl_reg &= 0x80; // keep the scl_drive + + i2c_[ibus].ctl_reg &= 0x80; // keep the scl_drive if (speed_khz > 125 && speed_khz < 300) i2c_[ibus].ctl_reg |= 0x01; if (speed_khz > 300 && speed_khz < 500) i2c_[ibus].ctl_reg |= 0x02; if (speed_khz > 500 && speed_khz < 2000) i2c_[ibus].ctl_reg |= 0x03;