From d3cafe115bdde62957bd3b95fd000e6dae1b1c49 Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Mon, 7 Mar 2016 14:22:09 -0800 Subject: Add a helper to acknowledge a GPIO interrupt. When an interrupt triggers on a GPIO, we must lseek and read the value in order to be able to poll again. As we don't guarantee that the file descriptor we use to poll will be the value file, add a convenience function to reset the file descriptor's state. To illustrate how to use it, we provide an example that will watch a GPIO for interrupt and print a message when the GPIO's value changes. This is implemented with both select and poll. Bug: 26778811 Change-Id: Ib25338599a8e08d7734839171da6204bb64a2ded --- include/peripheralmanager/gpio.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/peripheralmanager/gpio.h b/include/peripheralmanager/gpio.h index 28989ea..de5bfdd 100644 --- a/include/peripheralmanager/gpio.h +++ b/include/peripheralmanager/gpio.h @@ -91,6 +91,13 @@ int BGpio_getValue(const BGpio* gpio, int* value); /// @return Error code (one of peripheral_error_t). int BGpio_getPollingFd(const BGpio* gpio, int* fd); +/// Acknowledges the interrupt and resets the file descriptor. +/// This must be called after each event triggers in order to be able to +/// poll/select for another event. +/// @param fd Polling file descriptor to reset. +/// @return 0 on success, errno on error. +int BGpio_ackInterruptEvent(int fd); + /// Destroys a BGpio struct. /// @param gpio Pointer to the BGpio struct. void BGpio_delete(BGpio* gpio); -- cgit v1.2.3