summaryrefslogtreecommitdiff
path: root/src/include/gpio.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gpio.h')
-rw-r--r--src/include/gpio.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/include/gpio.h b/src/include/gpio.h
index ea03a23231..4627e4412c 100644
--- a/src/include/gpio.h
+++ b/src/include/gpio.h
@@ -29,6 +29,7 @@ void gpio_input_pulldown(gpio_t gpio);
void gpio_input_pullup(gpio_t gpio);
void gpio_input(gpio_t gpio);
void gpio_output(gpio_t gpio, int value);
+int _gpio_base3_value(gpio_t gpio[], int num_gpio, int binary_first);
/*
* Read the value presented by the set of GPIOs, when each pin is interpreted
@@ -48,6 +49,39 @@ int gpio_base2_value(gpio_t gpio[], int num_gpio);
* gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
* num_gpio: number of pins to read.
*/
-int gpio_base3_value(gpio_t gpio[], int num_gpio);
+static inline int gpio_base3_value(gpio_t gpio[], int num_gpio)
+{
+ return _gpio_base3_value(gpio, num_gpio, 0);
+}
+
+/*
+ * Read the value presented by the set of GPIOs, when each pin is interpreted
+ * as a base-3 digit (LOW = 0, HIGH = 1, Z/floating = 2) in a non-standard
+ * ternary number system where the first 2^n natural numbers are represented
+ * as they would be in a binary system (without any Z digits), and the following
+ * 3^n-2^n numbers use the remaining ternary representations in the normal
+ * ternary system order (skipping the values that were already used up).
+ * This is useful for boards which initially used a binary board ID and later
+ * decided to switch to tri-state after some revisions have already been built.
+ * Example: For num_gpio = 2 we get the following representation:
+ *
+ * Number X1 X0
+ * 0 0 0
+ * 1 0 1
+ * 2 1 0
+ * 3 1 1 // Start counting ternaries back at 0 after this
+ * 4 0 2 // Skipping 00 and 01 which are already used up
+ * 5 1 2 // Skipping 10 and 11 which are already used up
+ * 6 2 0
+ * 7 2 1
+ * 8 2 2
+ *
+ * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
+ * num_gpio: number of pins to read.
+ */
+static inline int gpio_binary_first_base3_value(gpio_t gpio[], int num_gpio)
+{
+ return _gpio_base3_value(gpio, num_gpio, 1);
+}
#endif /* __SRC_INCLUDE_GPIO_H__ */