Skip to content

attachInterruptToPin() and detachInterruptToPin() #1604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/shared/lib/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ analogRead KEYWORD2 AnalogRead
analogWrite KEYWORD2 AnalogWrite
attachInterrupt KEYWORD2 AttachInterrupt
detachInterrupt KEYWORD2 DetachInterrupt
attachInterruptToPin KEYWORD2 AttachInterruptToPin
detachInterruptFromPin KEYWORD2 DetachInterruptFromPin
delay KEYWORD2 Delay
delayMicroseconds KEYWORD2 DelayMicroseconds
digitalWrite KEYWORD2 DigitalWrite
Expand Down
3 changes: 3 additions & 0 deletions build/shared/revisions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

* Added attachInterruptToPin command (Rob Tillaart)

ARDUINO 1.5.7 BETA

[core]
Expand Down
18 changes: 18 additions & 0 deletions hardware/arduino/avr/cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,22 @@ long map(long, long, long, long, long);

#include "pins_arduino.h"

static inline boolean attachInterruptToPin(uint8_t pin, void (*userFunc)(void), int mode)
{
int irq = digitalPinToInterrupt(pin);
if (irq == NOT_AN_INTERRUPT)
return false;
attachInterrupt(irq, userFunc, mode);
return true;
}

static inline boolean detachInterruptFromPin(uint8_t pin)
{
int irq = digitalPinToInterrupt(pin);
if (irq == NOT_AN_INTERRUPT)
return false;
detachInterrupt(irq);
return true;
}

#endif
18 changes: 18 additions & 0 deletions hardware/arduino/sam/cores/arduino/WInterrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ void detachInterrupt(uint32_t pin)
pio->PIO_IDR = mask;
}

boolean attachInterruptToPin(uint8_t pin, void (*userFunc)(void), int mode)
{
int irq = digitalPinToInterrupt(pin);
if (irq == NOT_AN_INTERRUPT)
return false;
attachInterrupt(irq, userFunc, mode);
return true;
}

boolean detachInterruptFromPin(uint8_t pin)
{
int irq = digitalPinToInterrupt(pin);
if (irq == NOT_AN_INTERRUPT)
return false;
detachInterrupt(irq);
return true;
}

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
4 changes: 4 additions & 0 deletions hardware/arduino/sam/cores/arduino/WInterrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);

void detachInterrupt(uint32_t pin);

boolean attachInterruptToPin(uint8_t pin, void (*userFunc)(void), int mode);

boolean detachInterruptFromPin(uint8_t pin);

#ifdef __cplusplus
}
#endif
Expand Down