diff options
Diffstat (limited to 'src/gpio')
-rw-r--r-- | src/gpio/gpio.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index 4c48919..b585472 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -31,7 +31,7 @@ unsigned int rin_gpio_open(const unsigned int num, const enum rin_gpiotype type) init(); - if (type == rin_gpio_closed || !rin_gpio_pin_exists(num) || gpio[num].type != rin_gpio_closed) { + if (type == rin_gpio_closed || !rin_gpio_num_exists(num) || gpio[num].type != rin_gpio_closed) { return 1; } @@ -91,7 +91,7 @@ unsigned int rin_gpio_setval(const unsigned int num, const unsigned int val) char buf[8] = { 0 }; init(); - if (!rin_gpio_pin_exists(num) || gpio[num].type != rin_gpio_out) { + if (!rin_gpio_num_exists(num) || gpio[num].type != rin_gpio_out) { return 1; } sprintf(buf, "%u", val); @@ -104,7 +104,7 @@ unsigned int rin_gpio_readval(const unsigned int num, unsigned int * const val) { init(); - if (!rin_gpio_pin_exists(num) || gpio[num].type != rin_gpio_in) { + if (!rin_gpio_num_exists(num) || gpio[num].type != rin_gpio_in) { exit(EXIT_FAILURE); } @@ -172,9 +172,9 @@ unsigned int rin_gpio_pulse(const unsigned int num, const struct timespec * cons * right now is rpi V1 specific, should be rewritten when/if we support * other platforms. */ -unsigned int rin_gpio_pin_exists(const unsigned int pin) +unsigned int rin_gpio_num_exists(const unsigned int num) { - switch (pin) { + switch (num) { case 2: case 3: case 4: @@ -201,11 +201,50 @@ unsigned int rin_gpio_pin_exists(const unsigned int pin) * in case we ever support hardware other than the V1 Raspberry, * we need this to get the pin usable pin count */ -unsigned int rin_gpio_get_pincount(void) +unsigned int rin_gpio_get_numcount(void) { return 16; } +unsigned int rin_gpio_get_pincount(void) +{ + return 26; +} + +unsigned int rin_gpio_pin_to_num(const unsigned int pin) +{ + static const unsigned int pinmap[] = { 0, /* nonexistent zeroth index */ + 0, 0, 2, 0, + 3, 0, 4, 14, + 0, 15, 17, 18, + 27, 0, 22, 23, + 0, 24, 10, 0, + 9, 25, 11, 8, 7}; + + if (pin <= rin_gpio_get_pincount()) { + return pinmap[pin]; + } else { + return 0; + } +} + +unsigned int rin_gpio_num_to_pin(const unsigned int num) +{ + static const unsigned int nummap[] = { 0, /* zeroth */ + 0, 3, 5, 7, + 0, 0, 26, 24, + 21, 19, 23, 0, + 0, 8, 10, 0, + 11, 12, 0, 0, + 0, 15, 16, 18, 22}; + + if (num <= 26) { + return nummap[num]; + } else { + return 0; + } +} + static void init(void) { size_t i; |