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 " --- libmaple/exti.c | 110 ++++++++++++++++++++++------- libmaple/include/libmaple/exti.h | 5 ++ libmaple/include/libmaple/libmaple_types.h | 1 + wirish/ext_interrupts.cpp | 28 ++++++++ wirish/include/wirish/ext_interrupts.h | 21 ++++++ 5 files changed, 141 insertions(+), 24 deletions(-) diff --git a/libmaple/exti.c b/libmaple/exti.c index 9023782..b620c77 100644 --- a/libmaple/exti.c +++ b/libmaple/exti.c @@ -43,27 +43,27 @@ static inline void dispatch_extis(uint32 start, uint32 stop); */ typedef struct exti_channel { - void (*handler)(void); - uint32 irq_line; + void (*handler)(void *); + void *arg; } exti_channel; static exti_channel exti_channels[] = { - { .handler = NULL, .irq_line = NVIC_EXTI0 }, // EXTI0 - { .handler = NULL, .irq_line = NVIC_EXTI1 }, // EXTI1 - { .handler = NULL, .irq_line = NVIC_EXTI2 }, // EXTI2 - { .handler = NULL, .irq_line = NVIC_EXTI3 }, // EXTI3 - { .handler = NULL, .irq_line = NVIC_EXTI4 }, // EXTI4 - { .handler = NULL, .irq_line = NVIC_EXTI_9_5 }, // EXTI5 - { .handler = NULL, .irq_line = NVIC_EXTI_9_5 }, // EXTI6 - { .handler = NULL, .irq_line = NVIC_EXTI_9_5 }, // EXTI7 - { .handler = NULL, .irq_line = NVIC_EXTI_9_5 }, // EXTI8 - { .handler = NULL, .irq_line = NVIC_EXTI_9_5 }, // EXTI9 - { .handler = NULL, .irq_line = NVIC_EXTI_15_10 }, // EXTI10 - { .handler = NULL, .irq_line = NVIC_EXTI_15_10 }, // EXTI11 - { .handler = NULL, .irq_line = NVIC_EXTI_15_10 }, // EXTI12 - { .handler = NULL, .irq_line = NVIC_EXTI_15_10 }, // EXTI13 - { .handler = NULL, .irq_line = NVIC_EXTI_15_10 }, // EXTI14 - { .handler = NULL, .irq_line = NVIC_EXTI_15_10 }, // EXTI15 + { .handler = NULL, .arg = NULL }, // EXTI0 + { .handler = NULL, .arg = NULL }, // EXTI1 + { .handler = NULL, .arg = NULL }, // EXTI2 + { .handler = NULL, .arg = NULL }, // EXTI3 + { .handler = NULL, .arg = NULL }, // EXTI4 + { .handler = NULL, .arg = NULL }, // EXTI5 + { .handler = NULL, .arg = NULL }, // EXTI6 + { .handler = NULL, .arg = NULL }, // EXTI7 + { .handler = NULL, .arg = NULL }, // EXTI8 + { .handler = NULL, .arg = NULL }, // EXTI9 + { .handler = NULL, .arg = NULL }, // EXTI10 + { .handler = NULL, .arg = NULL }, // EXTI11 + { .handler = NULL, .arg = NULL }, // EXTI12 + { .handler = NULL, .arg = NULL }, // EXTI13 + { .handler = NULL, .arg = NULL }, // EXTI14 + { .handler = NULL, .arg = NULL }, // EXTI15 }; /* @@ -90,10 +90,39 @@ 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, handler, NULL, mode); +} + +/** + * @brief Register a handler with an argument to run upon external interrupt. + * + * This function assumes that the interrupt request corresponding to + * the given external interrupt is masked. + * + * @param num External interrupt line number. + * @param port Port to use as source input for external interrupt. + * @param handler Function handler to execute when interrupt is triggered. + * @param arg Argument to pass to the interrupt handler. + * @param mode Type of transition to trigger on, one of: + * EXTI_RISING, EXTI_FALLING, EXTI_RISING_FALLING. + * @see exti_num + * @see exti_cfg + * @see voidFuncPtr + * @see exti_trigger_mode + */ +void exti_attach_callback(exti_num num, + exti_cfg port, + voidFuncPtr handler, + void *arg, + exti_trigger_mode mode) { + ASSERT(handler); /* Register the handler */ - exti_channels[num].handler = handler; + exti_channels[num].handler = (voidArgumentFuncPtr)handler; + exti_channels[num].arg = arg; /* Set trigger mode */ switch (mode) { @@ -116,7 +145,39 @@ void exti_attach_interrupt(exti_num num, bb_peri_set_bit(&EXTI_BASE->IMR, num, 1); /* Enable the interrupt line */ - nvic_irq_enable(exti_channels[num].irq_line); + switch(num) + { + case 0: + nvic_irq_enable(NVIC_EXTI0); + break; + case 1: + nvic_irq_enable(NVIC_EXTI1); + break; + case 2: + nvic_irq_enable(NVIC_EXTI2); + break; + case 3: + nvic_irq_enable(NVIC_EXTI3); + break; + case 4: + nvic_irq_enable(NVIC_EXTI4); + break; + case 5: + case 6: + case 7: + case 8: + case 9: + nvic_irq_enable(NVIC_EXTI_9_5); + break; + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + nvic_irq_enable(NVIC_EXTI_15_10); + break; + } } /** @@ -134,6 +195,7 @@ void exti_detach_interrupt(exti_num num) { /* Finally, unregister the user's handler */ exti_channels[num].handler = NULL; + exti_channels[num].arg = NULL; } /* @@ -199,13 +261,13 @@ static __always_inline void clear_pending_msk(uint32 exti_msk) { /* This dispatch routine is for non-multiplexed EXTI lines only; i.e., * it doesn't check EXTI_PR. */ static __always_inline void dispatch_single_exti(uint32 exti) { - voidFuncPtr handler = exti_channels[exti].handler; + voidArgumentFuncPtr handler = exti_channels[exti].handler; if (!handler) { return; } - handler(); + handler(exti_channels[exti].arg); clear_pending_msk(1U << exti); } @@ -219,9 +281,9 @@ static __always_inline void dispatch_extis(uint32 start, uint32 stop) { for (exti = start; exti <= stop; exti++) { uint32 eb = (1U << exti); if (pr & eb) { - voidFuncPtr handler = exti_channels[exti].handler; + voidArgumentFuncPtr handler = exti_channels[exti].handler; if (handler) { - handler(); + handler(exti_channels[exti].arg); handled_msk |= eb; } } diff --git a/libmaple/include/libmaple/exti.h b/libmaple/include/libmaple/exti.h index 3800b4a..530b442 100644 --- a/libmaple/include/libmaple/exti.h +++ b/libmaple/include/libmaple/exti.h @@ -115,6 +115,11 @@ void exti_attach_interrupt(exti_num num, exti_cfg port, voidFuncPtr handler, exti_trigger_mode mode); +void exti_attach_callback(exti_num num, + exti_cfg port, + voidFuncPtr handler, + void *arg, + exti_trigger_mode mode); void exti_detach_interrupt(exti_num num); /** diff --git a/libmaple/include/libmaple/libmaple_types.h b/libmaple/include/libmaple/libmaple_types.h index 9e1fbb3..60dd2ff 100644 --- a/libmaple/include/libmaple/libmaple_types.h +++ b/libmaple/include/libmaple/libmaple_types.h @@ -48,6 +48,7 @@ typedef int int32; typedef long long int64; typedef void (*voidFuncPtr)(void); +typedef void (*voidArgumentFuncPtr)(void *); #define __io volatile #define __attr_flash __attribute__((section (".USER_FLASH"))) 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(-) 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 aec407773bbef80478941193f05fd67ce8ed49e0 Mon Sep 17 00:00:00 2001 From: Aditya Gaddam Date: Mon, 3 Sep 2012 17:58:04 -0400 Subject: "Added two examples for using attachInterrupt. One shows the use of a global function. While the second shows the use of a static class method as the event handler. Both work on Maple REVC Signed-off-by: Aditya Gaddam " --- examples/exti-interrupt-callback.cpp | 90 ++++++++++++++++++++++++++++++++++++ examples/exti-interrupt.cpp | 51 ++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 examples/exti-interrupt-callback.cpp create mode 100644 examples/exti-interrupt.cpp diff --git a/examples/exti-interrupt-callback.cpp b/examples/exti-interrupt-callback.cpp new file mode 100644 index 0000000..9f018cf --- /dev/null +++ b/examples/exti-interrupt-callback.cpp @@ -0,0 +1,90 @@ +// Toggles the built-in LED when the built in button +// on the Maple is pushed in. This uses the attachInterrupt function to +// setup the interrupt handler for the button being pressed. +// +// This is similar to the exti-interrupt example, but shows the use of a class +// method to handle interrupts. +// +// More about attachInterrupt: +// http://leaflabs.com/docs/lang/api/attachinterrupt.html +// + + +#include + +class MyAwesomeClass +{ +public: + // Setup the interrupt handler + void initialize() + { + // LED is off by default + this->isLEDOn = false; + + // Attach interrupt to class method handler + attachInterrupt(BOARD_BUTTON_PIN, buttonInterruptHandler, this, RISING); + } + +private: + + bool isLEDOn; + + // Static event handler takes a void * argument that was originally + // passed to the attachInterrupt call. If the argument in question is an + // instance of the class (MyAwesomeClass in this case), the static function + // get access to that instance's data (even private data). + // + // In other words, this setup allows the Maple to have class method + // interrupt handlers (albeit with a work around). + // + // However, as you might imagine, this argument can be anything (if you + // don't need instance data access). + // + static void buttonInterruptHandler(void *arg) + { + // Cast the "generic" void argument to the class instance. + MyAwesomeClass *instance = (MyAwesomeClass *)arg; + + // Accessing private instance data + instance->isLEDOn = !(instance->isLEDOn); + + // Set LED + digitalWrite(BOARD_LED_PIN, instance->isLEDOn); + + // Delay slightly for switch de-bouncing + delay(20); + } +}; + +MyAwesomeClass myClass; + +// Setup pin modes and the interrupt handler class +void setup() { + pinMode(BOARD_BUTTON_PIN, INPUT); + pinMode(BOARD_LED_PIN, OUTPUT); + + // The initialize method sets up the event handler to the private method + // in MyAwesomeClass. There is however, nothing stopping you from setting + // up event handlers which are public methods in classes. + myClass.initialize(); +} + +// Loop. Does nothing in this example. +void loop() { + +} + +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated objects that need libmaple may fail. +__attribute__((constructor)) void premain() { + init(); +} + +int main(void) { + setup(); + + while (true) { + loop(); + } + return 0; +} diff --git a/examples/exti-interrupt.cpp b/examples/exti-interrupt.cpp new file mode 100644 index 0000000..06d6b6f --- /dev/null +++ b/examples/exti-interrupt.cpp @@ -0,0 +1,51 @@ +// Toggles the built-in LED when the built in button +// on the Maple is pushed in. This uses the attachInterrupt function to +// setup the interrupt handler for the button being pressed. +// +// More about attachInterrupt: +// http://leaflabs.com/docs/lang/api/attachinterrupt.html +// + +#include + +// LED is off by default +bool isLEDOn = false; + +// Interrupt handler takes in nothing and returns nothing. +void interruptHandler() +{ + // Set LED + isLEDOn = !isLEDOn; + digitalWrite(BOARD_LED_PIN, isLEDOn); + + // Delay slightly for switch debouncing. + delay(20); +} + +// Setup pin modes and the interrupt handler +void setup() { + pinMode(BOARD_BUTTON_PIN, INPUT); + pinMode(BOARD_LED_PIN, OUTPUT); + + attachInterrupt(BOARD_BUTTON_PIN, interruptHandler, RISING); +} + +// Loop. Does nothing in this example. +void loop() { + +} + +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated objects that need libmaple may fail. +__attribute__((constructor)) void premain() { + init(); +} + +int main(void) { + setup(); + + while (true) { + loop(); + } + return 0; +} -- cgit v1.2.3 From 3c0af902520b67ba2a8eb50f96a392d8070e3614 Mon Sep 17 00:00:00 2001 From: Aditya Gaddam Date: Mon, 3 Sep 2012 18:05:57 -0400 Subject: "Changed tabs to spaces. Changed some braces placement to match existing examples Signed-off-by: Aditya Gaddam " --- examples/exti-interrupt-callback.cpp | 75 +++++++++++++++++------------------- examples/exti-interrupt.cpp | 17 ++++---- 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/examples/exti-interrupt-callback.cpp b/examples/exti-interrupt-callback.cpp index 9f018cf..1053ab2 100644 --- a/examples/exti-interrupt-callback.cpp +++ b/examples/exti-interrupt-callback.cpp @@ -12,55 +12,52 @@ #include -class MyAwesomeClass -{ +class MyAwesomeClass { public: - // Setup the interrupt handler - void initialize() - { - // LED is off by default - this->isLEDOn = false; - - // Attach interrupt to class method handler - attachInterrupt(BOARD_BUTTON_PIN, buttonInterruptHandler, this, RISING); - } - + // Setup the interrupt handler + void initialize() { + // LED is off by default + this->isLEDOn = false; + + // Attach interrupt to class method handler + attachInterrupt(BOARD_BUTTON_PIN, buttonInterruptHandler, this, RISING); + } + private: - bool isLEDOn; + bool isLEDOn; - // Static event handler takes a void * argument that was originally - // passed to the attachInterrupt call. If the argument in question is an - // instance of the class (MyAwesomeClass in this case), the static function - // get access to that instance's data (even private data). - // - // In other words, this setup allows the Maple to have class method - // interrupt handlers (albeit with a work around). - // - // However, as you might imagine, this argument can be anything (if you - // don't need instance data access). - // - static void buttonInterruptHandler(void *arg) - { - // Cast the "generic" void argument to the class instance. - MyAwesomeClass *instance = (MyAwesomeClass *)arg; - - // Accessing private instance data - instance->isLEDOn = !(instance->isLEDOn); - - // Set LED - digitalWrite(BOARD_LED_PIN, instance->isLEDOn); - - // Delay slightly for switch de-bouncing - delay(20); - } + // Static event handler takes a void * argument that was originally + // passed to the attachInterrupt call. If the argument in question is an + // instance of the class (MyAwesomeClass in this case), the static function + // get access to that instance's data (even private data). + // + // In other words, this setup allows the Maple to have class method + // interrupt handlers (albeit with a work around). + // + // However, as you might imagine, this argument can be anything (if you + // don't need instance data access). + // + static void buttonInterruptHandler(void *arg) { + // Cast the "generic" void argument to the class instance. + MyAwesomeClass *instance = (MyAwesomeClass *)arg; + + // Accessing private instance data + instance->isLEDOn = !(instance->isLEDOn); + + // Set LED + digitalWrite(BOARD_LED_PIN, instance->isLEDOn); + + // Delay slightly for switch de-bouncing + delay(20); + } }; MyAwesomeClass myClass; // Setup pin modes and the interrupt handler class void setup() { - pinMode(BOARD_BUTTON_PIN, INPUT); + pinMode(BOARD_BUTTON_PIN, INPUT); pinMode(BOARD_LED_PIN, OUTPUT); // The initialize method sets up the event handler to the private method diff --git a/examples/exti-interrupt.cpp b/examples/exti-interrupt.cpp index 06d6b6f..bc02f30 100644 --- a/examples/exti-interrupt.cpp +++ b/examples/exti-interrupt.cpp @@ -12,19 +12,18 @@ bool isLEDOn = false; // Interrupt handler takes in nothing and returns nothing. -void interruptHandler() -{ - // Set LED - isLEDOn = !isLEDOn; - digitalWrite(BOARD_LED_PIN, isLEDOn); - - // Delay slightly for switch debouncing. - delay(20); +void interruptHandler() { + // Set LED + isLEDOn = !isLEDOn; + digitalWrite(BOARD_LED_PIN, isLEDOn); + + // Delay slightly for switch debouncing. + delay(20); } // Setup pin modes and the interrupt handler void setup() { - pinMode(BOARD_BUTTON_PIN, INPUT); + pinMode(BOARD_BUTTON_PIN, INPUT); pinMode(BOARD_LED_PIN, OUTPUT); attachInterrupt(BOARD_BUTTON_PIN, interruptHandler, RISING); -- 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(-) 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(-) 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 From 9b8d7c508f9ff0633b5ab8acf9e64bee891604dc Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 3 Sep 2012 18:28:48 -0400 Subject: EXTI examples: whitespace fixups. Signed-off-by: Marti Bolivar --- examples/exti-interrupt-callback.cpp | 32 ++++++++++++++++---------------- examples/exti-interrupt.cpp | 12 ++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/exti-interrupt-callback.cpp b/examples/exti-interrupt-callback.cpp index 1053ab2..c87c064 100644 --- a/examples/exti-interrupt-callback.cpp +++ b/examples/exti-interrupt-callback.cpp @@ -4,10 +4,10 @@ // // This is similar to the exti-interrupt example, but shows the use of a class // method to handle interrupts. -// -// More about attachInterrupt: +// +// More about attachInterrupt: // http://leaflabs.com/docs/lang/api/attachinterrupt.html -// +// #include @@ -18,36 +18,36 @@ public: void initialize() { // LED is off by default this->isLEDOn = false; - + // Attach interrupt to class method handler attachInterrupt(BOARD_BUTTON_PIN, buttonInterruptHandler, this, RISING); } - + private: bool isLEDOn; - // Static event handler takes a void * argument that was originally - // passed to the attachInterrupt call. If the argument in question is an + // Static event handler takes a void * argument that was originally + // passed to the attachInterrupt call. If the argument in question is an // instance of the class (MyAwesomeClass in this case), the static function - // get access to that instance's data (even private data). + // get access to that instance's data (even private data). // - // In other words, this setup allows the Maple to have class method + // In other words, this setup allows the Maple to have class method // interrupt handlers (albeit with a work around). // - // However, as you might imagine, this argument can be anything (if you + // However, as you might imagine, this argument can be anything (if you // don't need instance data access). // static void buttonInterruptHandler(void *arg) { // Cast the "generic" void argument to the class instance. MyAwesomeClass *instance = (MyAwesomeClass *)arg; - + // Accessing private instance data instance->isLEDOn = !(instance->isLEDOn); - + // Set LED digitalWrite(BOARD_LED_PIN, instance->isLEDOn); - + // Delay slightly for switch de-bouncing delay(20); } @@ -59,16 +59,16 @@ MyAwesomeClass myClass; void setup() { pinMode(BOARD_BUTTON_PIN, INPUT); pinMode(BOARD_LED_PIN, OUTPUT); - + // The initialize method sets up the event handler to the private method - // in MyAwesomeClass. There is however, nothing stopping you from setting + // in MyAwesomeClass. There is however, nothing stopping you from setting // up event handlers which are public methods in classes. myClass.initialize(); } // Loop. Does nothing in this example. void loop() { - + } // Force init to be called *first*, i.e. before static object allocation. diff --git a/examples/exti-interrupt.cpp b/examples/exti-interrupt.cpp index bc02f30..89382d7 100644 --- a/examples/exti-interrupt.cpp +++ b/examples/exti-interrupt.cpp @@ -1,10 +1,10 @@ // Toggles the built-in LED when the built in button // on the Maple is pushed in. This uses the attachInterrupt function to // setup the interrupt handler for the button being pressed. -// -// More about attachInterrupt: +// +// More about attachInterrupt: // http://leaflabs.com/docs/lang/api/attachinterrupt.html -// +// #include @@ -16,7 +16,7 @@ void interruptHandler() { // Set LED isLEDOn = !isLEDOn; digitalWrite(BOARD_LED_PIN, isLEDOn); - + // Delay slightly for switch debouncing. delay(20); } @@ -25,13 +25,13 @@ void interruptHandler() { void setup() { pinMode(BOARD_BUTTON_PIN, INPUT); pinMode(BOARD_LED_PIN, OUTPUT); - + attachInterrupt(BOARD_BUTTON_PIN, interruptHandler, RISING); } // Loop. Does nothing in this example. void loop() { - + } // Force init to be called *first*, i.e. before static object allocation. -- cgit v1.2.3