diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-09-03 18:29:45 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-09-03 18:29:45 -0400 |
commit | 5a5aee7906b5c11a38d2a71fc2e8849f2afae4bc (patch) | |
tree | dfbbf24f499ca6dee1ad40a4639a196d502805c4 /wirish | |
parent | 359117bc2009a9302884f61b0b359bb1723ee0bd (diff) | |
parent | 9b8d7c508f9ff0633b5ab8acf9e64bee891604dc (diff) | |
download | librambutan-5a5aee7906b5c11a38d2a71fc2e8849f2afae4bc.tar.gz librambutan-5a5aee7906b5c11a38d2a71fc2e8849f2afae4bc.zip |
Merge branch 'callback_interrupt_handlers'
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/ext_interrupts.cpp | 26 | ||||
-rw-r--r-- | wirish/include/wirish/ext_interrupts.h | 22 |
2 files changed, 37 insertions, 11 deletions
diff --git a/wirish/ext_interrupts.cpp b/wirish/ext_interrupts.cpp index a3e61fd..1195ea9 100644 --- a/wirish/ext_interrupts.cpp +++ b/wirish/ext_interrupts.cpp @@ -39,13 +39,6 @@ static inline exti_trigger_mode exti_out_mode(ExtIntTriggerMode mode); -/** - * @brief Attach an interrupt handler to a pin, triggering on the given mode. - * @param pin Pin to attach an interrupt handler onto. - * @param handler Function to call when the external interrupt is triggered. - * @param mode Trigger mode for the given interrupt. - * @see ExtIntTriggerMode - */ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { if (pin >= BOARD_NR_GPIO_PINS || !handler) { return; @@ -59,10 +52,21 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { outMode); } -/** - * @brief Disable any external interrupt attached to a pin. - * @param pin Pin number to detach any interrupt from. - */ +void attachInterrupt(uint8 pin, voidArgumentFuncPtr 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); +} + void detachInterrupt(uint8 pin) { if (pin >= BOARD_NR_GPIO_PINS) { return; diff --git a/wirish/include/wirish/ext_interrupts.h b/wirish/include/wirish/ext_interrupts.h index 933be04..ce1ca03 100644 --- a/wirish/include/wirish/ext_interrupts.h +++ b/wirish/include/wirish/ext_interrupts.h @@ -69,6 +69,28 @@ typedef enum ExtIntTriggerMode { void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode); /** + * @brief Registers an interrupt handler on a pin. + * + * The interrupt will be triggered on a given transition on the pin, + * as specified by the mode parameter. The handler runs in interrupt + * context. The new handler will replace whatever handler is + * currently registered for the pin, if any. + * + * @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, voidArgumentFuncPtr handler, void *arg, + ExtIntTriggerMode mode); + +/** * @brief Disable any registered external interrupt. * @param pin Maple pin number * @sideeffect unregisters external interrupt handler |