From c563e4fb4daebc289983ceb2f8c4e0d8f8e80e9a Mon Sep 17 00:00:00 2001 From: Noel Eck Date: Mon, 18 Jun 2018 14:41:31 -0700 Subject: [PATCH] gpio.c: Handle subplatform interrupts For all subplaform pins, save the subplatform index as dev->pin and the actual platform index as dev->phy_pin. Example: pin 515 (subplatform pin 3) dev->pin = 515 dev->phy_pin = 515 - 512 = 3 In this way, methods which get a mraa_gpio_context have a means to tell whether the pin is on a subplatform or not. Signed-off-by: Noel Eck --- src/gpio/gpio.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index 81d137f..2734609 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -172,8 +172,18 @@ mraa_gpio_init(int pin) return NULL; } - if (mraa_is_sub_platform_id(pin)) { - syslog(LOG_NOTICE, "gpio%i: init: Using sub platform", pin); + /* If this pin belongs to a subplatform, then the pin member will contain + * the mraa pin index and the phy_pin will contain the subplatform's + * pin index. + * example: pin 515, dev->pin = 515, dev->phy_pin = 3 + */ + if (mraa_is_sub_platform_id(pin) && (board->sub_platform != NULL)) { + syslog(LOG_NOTICE, "gpio%i: initialised on sub platform '%s' physical pin: %i", + pin, + board->sub_platform->platform_name != NULL ? + board->sub_platform->platform_name : "", + mraa_get_sub_platform_index(pin)); + board = board->sub_platform; if (board == NULL) { syslog(LOG_ERR, "gpio%i: init: Sub platform not initialised", pin); @@ -599,7 +609,10 @@ mraa_gpio_interrupt_handler(void* arg) return NULL; } - if (plat->chardev_capable) { + /* Is this pin on a subplatform? Do nothing... */ + if (mraa_is_sub_platform_id(dev->pin)) {} + /* Is the platform chardev_capable? */ + else if (plat->chardev_capable) { mraa_gpiod_group_t gpio_group; for_each_gpio_group(gpio_group, dev) { @@ -607,7 +620,9 @@ mraa_gpio_interrupt_handler(void* arg) fps[idx++] = gpio_group->event_handles[i]; } } - } else { + } + /* Else, attempt fs access */ + else { mraa_gpio_context it = dev; while (it) { @@ -901,7 +916,7 @@ mraa_gpio_isr_exit(mraa_gpio_context dev) dev->isr_thread_terminating = 1; // stop isr being useful - if (plat->chardev_capable) + if (plat && (plat->chardev_capable)) _mraa_close_gpio_event_handles(dev); else ret = mraa_gpio_edge_mode(dev, MRAA_GPIO_EDGE_NONE); @@ -1561,7 +1576,10 @@ mraa_gpio_close(mraa_gpio_context dev) free(dev->events); } - if (plat->chardev_capable) { + /* Free any ISRs */ + mraa_gpio_isr_exit(dev); + + if (plat && plat->chardev_capable) { _mraa_free_gpio_groups(dev); free(dev);