Skip to content

Commit

Permalink
Update Config API
Browse files Browse the repository at this point in the history
Add bbReset to configurable parameters
  • Loading branch information
LawrenceStanton committed Sep 19, 2023
1 parent 770c274 commit f207f62
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Inc/Private/SM72445_Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class SM72445_X::Config {
bool panelModeOverrideEnable; // Panel Mode Override Enable
bool panelModeOverride; // Panel Mode Override

bool bbReset;

bool clockOutputManualEnable; // Pin 5 Clock Output Enable

bool openLoopOperation;
Expand Down
13 changes: 10 additions & 3 deletions Inc/Private/SM72445_ConfigBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ struct SM72445_X::ConfigBuilder {
*/
ConfigBuilder &setPanelModeRegisterOverride(bool override);

// Config &setBbReset(bool reset); // Unsupported
// void setClockOutputManualEnable(bool enable); // Unsupported
// void setOpenLoopOperation(bool enable); // Unsupported
/**
* @brief Set the Bb Reset Bit
*
* @param reset Set bit to true or false.
* @return This ConfigBuilder.
*/
ConfigBuilder &setBbReset(bool reset);

// ConfigBuilder setClockOutputManualEnable(bool enable); // Unsupported
// ConfigBuilder setOpenLoopOperation(bool enable); // Unsupported

/**
* @brief "Build" the Configuration Register.
Expand Down
5 changes: 5 additions & 0 deletions Inc/SM72445.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ class SM72445 {
*/
optional<Reg5> getThresholdRegister(void) const;

/**
* @brief Get the I2C Device Address of this SM72445.
*
* @return DeviceAddress The I2C Device Address of this SM72445.
*/
DeviceAddress getDeviceAddress(void) const;
};

Expand Down
13 changes: 9 additions & 4 deletions Src/SM72445_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Config::Config(const SM72445_X &sm72445, const Reg3 &reg3)
tdOn(static_cast<DeadTime>(reg3.tdOn)), //
panelModeOverrideEnable(reg3.passThroughSelect), //
panelModeOverride(reg3.passThroughManual), //
bbReset(reg3.bbReset), //
clockOutputManualEnable(reg3.clkOeManual), //
openLoopOperation(reg3.openLoopOperation) {}

Expand Down Expand Up @@ -105,8 +106,8 @@ ConfigBuilder &ConfigBuilder::setMaxOutputCurrentOverride(float current) {
const uint16_t maxOutputCurrentAdcThreshold =
current * this->sm72445.iOutGain / this->sm72445.vDDA * 0x3FFull;

if (maxOutputCurrentAdcThreshold > 0x3FFu) {
// Invalid value, exceeds settable range. Default action set to zero.
if (current < 0.0f || maxOutputCurrentAdcThreshold > 0x3FFu) {
// Invalid value, outside settable range. Default action set to zero.
this->reg3.iOutMax = 0x0u;
return *this;
}
Expand All @@ -120,8 +121,8 @@ ConfigBuilder &ConfigBuilder::setMaxOutputVoltageOverride(float voltage) {
const uint16_t maxOutputVoltageAdcThreshold =
voltage * this->sm72445.vOutGain / this->sm72445.vDDA * 0x3FFull;

if (maxOutputVoltageAdcThreshold > 0x3FFu) {
// Invalid value, exceeds settable range. Default action set to zero.
if (voltage < 0.0f || maxOutputVoltageAdcThreshold > 0x3FFu) {
// Invalid value, outside settable range. Default action set to zero.
this->reg3.vOutMax = 0x0u;
return *this;
}
Expand Down Expand Up @@ -152,6 +153,10 @@ ConfigBuilder &ConfigBuilder::setPanelModeRegisterOverride(bool override) {
return *this;
}

ConfigBuilder &SM72445_X::ConfigBuilder::setBbReset(bool reset) {
this->reg3.bbReset = reset;
return *this;
}
SM72445::ConfigRegister ConfigBuilder::build(void) const {
return ConfigRegister(Register(this->reg3));
}

0 comments on commit f207f62

Please sign in to comment.