From 6b2700e2b1a03b7e0191f3dd9b34f8c51eea3c84 Mon Sep 17 00:00:00 2001 From: Aditya Gaddam Date: Fri, 31 Aug 2012 14:19:57 -0400 Subject: "Added ability to set callbacks for interrupts that get an argument. This argument can be the instance that needs to handle the interrupt, or just a random argument you might find useful later. Suggestions from mbolivar and iperry from pull53 on libmaple were taken into account. Signed-off-by: Aditya Gaddam " --- wirish/ext_interrupts.cpp | 28 ++++++++++++++++++++++++++++ wirish/include/wirish/ext_interrupts.h | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'wirish') 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 @@ -59,6 +59,34 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { outMode); } +/** + * @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. diff --git a/wirish/include/wirish/ext_interrupts.h b/wirish/include/wirish/ext_interrupts.h index 933be04..1bd7956 100644 --- a/wirish/include/wirish/ext_interrupts.h +++ b/wirish/include/wirish/ext_interrupts.h @@ -68,6 +68,27 @@ 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, voidFuncPtr handler, void *arg, ExtIntTriggerMode mode); + /** * @brief Disable any registered external interrupt. * @param pin Maple pin number -- cgit v1.2.3 From 53b224544424f037c29617f066294058aa6572f5 Mon Sep 17 00:00:00 2001 From: Aditya Gaddam Date: Sun, 2 Sep 2012 11:04:01 -0400 Subject: "Callback versions of functions now take voidArgumentFuncPtr. We can probably use voidFuncPtr instead, but this way people can see that the function expects something different. Existing functions haven't changed in signature. Signed-off-by: Aditya Gaddam " --- libmaple/exti.c | 6 +++--- libmaple/include/libmaple/exti.h | 2 +- wirish/ext_interrupts.cpp | 2 +- wirish/include/wirish/ext_interrupts.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'wirish') diff --git a/libmaple/exti.c b/libmaple/exti.c index b620c77..abd618d 100644 --- a/libmaple/exti.c +++ b/libmaple/exti.c @@ -92,7 +92,7 @@ void exti_attach_interrupt(exti_num num, exti_trigger_mode mode) { // Call callback version with arg being null - exti_attach_callback(num, port, handler, NULL, mode); + exti_attach_callback(num, port, (voidArgumentFuncPtr)handler, NULL, mode); } /** @@ -114,14 +114,14 @@ void exti_attach_interrupt(exti_num num, */ void exti_attach_callback(exti_num num, exti_cfg port, - voidFuncPtr handler, + voidArgumentFuncPtr handler, void *arg, exti_trigger_mode mode) { ASSERT(handler); /* Register the handler */ - exti_channels[num].handler = (voidArgumentFuncPtr)handler; + exti_channels[num].handler = handler; exti_channels[num].arg = arg; /* Set trigger mode */ diff --git a/libmaple/include/libmaple/exti.h b/libmaple/include/libmaple/exti.h index 530b442..1d201ac 100644 --- a/libmaple/include/libmaple/exti.h +++ b/libmaple/include/libmaple/exti.h @@ -117,7 +117,7 @@ void exti_attach_interrupt(exti_num num, exti_trigger_mode mode); void exti_attach_callback(exti_num num, exti_cfg port, - voidFuncPtr handler, + voidArgumentFuncPtr handler, void *arg, exti_trigger_mode mode); void exti_detach_interrupt(exti_num num); diff --git a/wirish/ext_interrupts.cpp b/wirish/ext_interrupts.cpp index f72efbf..7271eb3 100644 --- a/wirish/ext_interrupts.cpp +++ b/wirish/ext_interrupts.cpp @@ -73,7 +73,7 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { * @sideeffect Registers a handler * @see detachInterrupt() */ -void attachInterrupt(uint8 pin, voidFuncPtr handler, void *arg, ExtIntTriggerMode mode) { +void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, ExtIntTriggerMode mode) { if (pin >= BOARD_NR_GPIO_PINS || !handler) { return; } diff --git a/wirish/include/wirish/ext_interrupts.h b/wirish/include/wirish/ext_interrupts.h index 1bd7956..7f2bd6a 100644 --- a/wirish/include/wirish/ext_interrupts.h +++ b/wirish/include/wirish/ext_interrupts.h @@ -87,7 +87,7 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode); * @sideeffect Registers a handler * @see detachInterrupt() */ -void attachInterrupt(uint8 pin, voidFuncPtr handler, void *arg, ExtIntTriggerMode mode); +void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, ExtIntTriggerMode mode); /** * @brief Disable any registered external interrupt. -- cgit v1.2.3 From 877a91bc649e7ef616d6366a8b39affeb650f63d Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 3 Sep 2012 18:27:18 -0400 Subject: Whitespace fixups to EXTI files. Signed-off-by: Marti Bolivar --- libmaple/exti.c | 2 -- wirish/include/wirish/ext_interrupts.h | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'wirish') diff --git a/libmaple/exti.c b/libmaple/exti.c index abd618d..91d8551 100644 --- a/libmaple/exti.c +++ b/libmaple/exti.c @@ -90,7 +90,6 @@ void exti_attach_interrupt(exti_num num, exti_cfg port, voidFuncPtr handler, exti_trigger_mode mode) { - // Call callback version with arg being null exti_attach_callback(num, port, (voidArgumentFuncPtr)handler, NULL, mode); } @@ -117,7 +116,6 @@ void exti_attach_callback(exti_num num, voidArgumentFuncPtr handler, void *arg, exti_trigger_mode mode) { - ASSERT(handler); /* Register the handler */ diff --git a/wirish/include/wirish/ext_interrupts.h b/wirish/include/wirish/ext_interrupts.h index 7f2bd6a..ce1ca03 100644 --- a/wirish/include/wirish/ext_interrupts.h +++ b/wirish/include/wirish/ext_interrupts.h @@ -77,17 +77,18 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode); * currently registered for the pin, if any. * * @param pin Pin number - * @param handler Static class member function to run upon external interrupt + * @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 + * 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); +void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, + ExtIntTriggerMode mode); /** * @brief Disable any registered external interrupt. -- cgit v1.2.3 From cb9f3547eb0fdb516391cc8b50eac14b89dcb612 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 3 Sep 2012 18:27:51 -0400 Subject: ext_interrupts.cpp: Doxygen fixups. Keep the Doxygen in the header as per Wirish conventions. Signed-off-by: Marti Bolivar --- wirish/ext_interrupts.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'wirish') diff --git a/wirish/ext_interrupts.cpp b/wirish/ext_interrupts.cpp index 7271eb3..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,21 +52,8 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { outMode); } -/** - * @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, voidArgumentFuncPtr handler, void *arg, ExtIntTriggerMode mode) { +void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, + ExtIntTriggerMode mode) { if (pin >= BOARD_NR_GPIO_PINS || !handler) { return; } @@ -87,10 +67,6 @@ void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, ExtIntTr outMode); } -/** - * @brief Disable any external interrupt attached to a pin. - * @param pin Pin number to detach any interrupt from. - */ void detachInterrupt(uint8 pin) { if (pin >= BOARD_NR_GPIO_PINS) { return; -- cgit v1.2.3