gpio: add a function to read GPIO array as base-2 value
This adds gpio_base2_value() which reads an array of 2-state GPIOs and returns a base-2 value, where gpio[0] represents the least significant bit. BUG=none BRANCH=none TEST=tested with follow-up patches for pinky Change-Id: Ia7ffc16eb60e93413c0812573b9cf0999b92828e Signed-off-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/228323 Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
1a142cd2c5
commit
27873b7a9e
2 changed files with 21 additions and 0 deletions
|
|
@ -34,6 +34,15 @@ void gpio_input_pullup(gpio_t gpio);
|
|||
void gpio_input(gpio_t gpio);
|
||||
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).
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue