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)
{