diff options
Diffstat (limited to 'wirish/ext_interrupts.cpp')
-rw-r--r-- | wirish/ext_interrupts.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/wirish/ext_interrupts.cpp b/wirish/ext_interrupts.cpp index a3e61fd..f72efbf 100644 --- a/wirish/ext_interrupts.cpp +++ b/wirish/ext_interrupts.cpp @@ -60,6 +60,34 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { } /** + * @brief Registers an interrupt handler on a pin. + * + * @param pin Pin number + * @param handler Static class member function to run upon external interrupt + * trigger. The handler should take 1 argument and return void + * @param arg Argument that the handler will be passed when it's called. One + * use of this is to pass the specific instance of the class that + * will handle the interrupt. + * @param mode Type of transition to trigger on, e.g. falling, rising, etc. + * + * @sideeffect Registers a handler + * @see detachInterrupt() + */ +void attachInterrupt(uint8 pin, voidFuncPtr handler, void *arg, ExtIntTriggerMode mode) { + if (pin >= BOARD_NR_GPIO_PINS || !handler) { + return; + } + + exti_trigger_mode outMode = exti_out_mode(mode); + + exti_attach_callback((exti_num)(PIN_MAP[pin].gpio_bit), + gpio_exti_port(PIN_MAP[pin].gpio_device), + handler, + arg, + outMode); +} + +/** * @brief Disable any external interrupt attached to a pin. * @param pin Pin number to detach any interrupt from. */ |