libflashprog: Allow to query bus types, voltage, and test status
This is mostly an export of the long stable internal structures. We do
some renames, though, and provide the voltage range as floating point
numbers. While we are at it, also rename:
* flashprog_test_status.wp => .block_protection,
* BUS_PROG => BUS_OPAQUE,
* BUS_NONSPI => BUS_PRESPI.
The last one is a pseudonym for the older, memory-mapped buses, and
doesn't include BUS_OPAQUE.
Also try to name the captured test state consistently, either `tested`
or `status`.
Change-Id: Ibefb923fa5f566daa804651aa1a9bfe5602ca364
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/482
diff --git a/libflashprog/chips.c b/libflashprog/chips.c
index ec4adbc..0b43e6f 100644
--- a/libflashprog/chips.c
+++ b/libflashprog/chips.c
@@ -165,4 +165,50 @@
return chip->total_size * KiB;
}
+/**
+ * @brief Get a bit mask of the supported bus types.
+ *
+ * @param chip reference to query.
+ * @return bit mask of supported bus types.
+ */
+enum flashprog_bus_type flashprog_chip_buses(const struct flashprog_chip *chip) {
+ return chip->bustype;
+}
+
+/**
+ * @brief Get a string that lists the supported bus types.
+ *
+ * The resulting string needs to be freed with free().
+ *
+ * @param chip reference to query.
+ * @return comma-separated string of supported bus types.
+ */
+char *flashprog_chip_bus_names(const struct flashprog_chip *chip) {
+ return flashbuses_to_text(chip->bustype);
+}
+
+/**
+ * @brief Get the supported operating voltage range.
+ *
+ * @param chip reference to query.
+ * @return supported operating voltage range.
+ */
+struct flashprog_voltage_range flashprog_chip_voltage_range(const struct flashprog_chip *chip)
+{
+ return (struct flashprog_voltage_range) {
+ .min = chip->voltage.min / 1000.f,
+ .max = chip->voltage.max / 1000.f,
+ };
+}
+
+/**
+ * @brief Get the test status of a chip's standard features.
+ *
+ * @param chip reference to query.
+ * @return struct with the test status of the chip's standard features.
+ */
+struct flashprog_test_status flashprog_chip_test_status(const struct flashprog_chip *chip) {
+ return chip->tested;
+}
+
/** @} */ /* end flashprog-chip */