summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/gpio.h9
-rw-r--r--src/lib/gpio.c12
2 files changed, 21 insertions, 0 deletions
diff --git a/src/include/gpio.h b/src/include/gpio.h
index e54b156ce7..7b64ebfe80 100644
--- a/src/include/gpio.h
+++ b/src/include/gpio.h
@@ -36,6 +36,15 @@ void gpio_output(gpio_t gpio, int value);
/*
* Read the value presented by the set of GPIOs, when each pin is interpreted
+ * as a base-2 digit (LOW = 0, HIGH = 1).
+ *
+ * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
+ * num_gpio: number of pins to read.
+ */
+int gpio_base2_value(gpio_t gpio[], int num_gpio);
+
+/*
+ * 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).
* Example: X1 = Z, X2 = 1 -> gpio_base3_value({GPIO(X1), GPIO(X2)}) = 5
* BASE3() from <base3.h> can generate numbers to compare the result to.
diff --git a/src/lib/gpio.c b/src/lib/gpio.c
index 3a646e0d1d..0875538bae 100644
--- a/src/lib/gpio.c
+++ b/src/lib/gpio.c
@@ -22,6 +22,18 @@
#include <delay.h>
#include <gpio.h>
+int gpio_base2_value(gpio_t gpio[], int num_gpio)
+{
+ int i, result = 0;
+
+ for (i = 0; i < num_gpio; i++) {
+ gpio_input(gpio[i]);
+ result |= gpio_get(gpio[i]) << i;
+ }
+
+ return result;
+}
+
int gpio_base3_value(gpio_t gpio[], int num_gpio)
{
/*