regulators: Implements support for i2c_write_byte
Implements support for parsing the i2c_write_byte JSON elements in the
configuration file parser.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I131edcbda0d637f8d75b3f67bbe2d61407a184d6
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index cdf758e..791f3f7 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -108,9 +108,8 @@
}
else if (element.contains("i2c_write_byte"))
{
- // TODO: Not implemented yet
- // action = parseI2CWriteByte(element["i2c_write_byte"]);
- // ++propertyCount;
+ action = parseI2CWriteByte(element["i2c_write_byte"]);
+ ++propertyCount;
}
else if (element.contains("i2c_write_bytes"))
{
@@ -220,6 +219,36 @@
return std::make_unique<I2CWriteBitAction>(reg, position, value);
}
+std::unique_ptr<I2CWriteByteAction> parseI2CWriteByte(const json& element)
+{
+ verifyIsObject(element);
+ unsigned int propertyCount{0};
+
+ // Required register property
+ const json& regElement = getRequiredProperty(element, "register");
+ uint8_t reg = parseStringToUint8(regElement);
+ ++propertyCount;
+
+ // Required value property
+ const json& valueElement = getRequiredProperty(element, "value");
+ uint8_t value = parseStringToUint8(valueElement);
+ ++propertyCount;
+
+ // Optional mask property
+ uint8_t mask = 0xff;
+ auto maskIt = element.find("mask");
+ if (maskIt != element.end())
+ {
+ mask = parseStringToUint8(*maskIt);
+ ++propertyCount;
+ }
+
+ // Verify no invalid properties exist
+ verifyPropertyCount(element, propertyCount);
+
+ return std::make_unique<I2CWriteByteAction>(reg, value, mask);
+}
+
std::unique_ptr<PMBusWriteVoutCommandAction>
parsePMBusWriteVoutCommand(const json& element)
{
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index f96e6b4..abfa4f5 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -18,6 +18,7 @@
#include "action.hpp"
#include "chassis.hpp"
#include "i2c_write_bit_action.hpp"
+#include "i2c_write_byte_action.hpp"
#include "pmbus_write_vout_command_action.hpp"
#include "rule.hpp"
@@ -215,6 +216,19 @@
parseI2CWriteBit(const nlohmann::json& element);
/**
+ * Parses a JSON element containing an i2c_write_byte action.
+ *
+ * Returns the corresponding C++ I2CWriteByteAction object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return I2CWriteByteAction object
+ */
+std::unique_ptr<I2CWriteByteAction>
+ parseI2CWriteByte(const nlohmann::json& element);
+
+/**
* Parses a JSON element containing an 8-bit signed integer.
*
* Returns the corresponding C++ int8_t value.