mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-27 21:54:30 +01:00
fixed attachInterrupt() on Leonardo
had to define a separate block for the 32U4 since it looks like a Mega-series board based on a simple register trick. Only two useable HW interrupts though, compared to the Megas' 8, and numbering differs.
This commit is contained in:
parent
fd28193336
commit
d874bc9832
38
hardware/arduino/cores/arduino/WInterrupts.c
Executable file → Normal file
38
hardware/arduino/cores/arduino/WInterrupts.c
Executable file → Normal file
@ -47,7 +47,19 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
|
|||||||
// Enable the interrupt.
|
// Enable the interrupt.
|
||||||
|
|
||||||
switch (interruptNum) {
|
switch (interruptNum) {
|
||||||
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
|
#if defined(__AVR_ATmega32U4__)
|
||||||
|
// I hate doing this, but the register assignment differs between the 1280/2560
|
||||||
|
// and the 32U4. Since avrlib defines registers PCMSK1 and PCMSK2 that aren't
|
||||||
|
// even present on the 32U4 this is the only way to distinguish between them.
|
||||||
|
case 0:
|
||||||
|
EICRA = (EICRA & ~((1<<ISC00) | (1<<ISC01))) | (mode << ISC00);
|
||||||
|
EIMSK |= (1<<INT0);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
|
||||||
|
EIMSK |= (1<<INT1);
|
||||||
|
break;
|
||||||
|
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
|
||||||
case 2:
|
case 2:
|
||||||
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
|
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
|
||||||
EIMSK |= (1 << INT0);
|
EIMSK |= (1 << INT0);
|
||||||
@ -80,7 +92,7 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
|
|||||||
EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
|
EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
|
||||||
EIMSK |= (1 << INT7);
|
EIMSK |= (1 << INT7);
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
case 0:
|
case 0:
|
||||||
#if defined(EICRA) && defined(ISC00) && defined(EIMSK)
|
#if defined(EICRA) && defined(ISC00) && defined(EIMSK)
|
||||||
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
|
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
|
||||||
@ -136,7 +148,14 @@ void detachInterrupt(uint8_t interruptNum) {
|
|||||||
// to the number of the EIMSK bit to clear, as this isn't true on the
|
// to the number of the EIMSK bit to clear, as this isn't true on the
|
||||||
// ATmega8. There, INT0 is 6 and INT1 is 7.)
|
// ATmega8. There, INT0 is 6 and INT1 is 7.)
|
||||||
switch (interruptNum) {
|
switch (interruptNum) {
|
||||||
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
|
#if defined(__AVR_ATmega32U4__)
|
||||||
|
case 0:
|
||||||
|
EIMSK &= ~(1<<INT0);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
EIMSK &= ~(1<<INT1);
|
||||||
|
break;
|
||||||
|
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
|
||||||
case 2:
|
case 2:
|
||||||
EIMSK &= ~(1 << INT0);
|
EIMSK &= ~(1 << INT0);
|
||||||
break;
|
break;
|
||||||
@ -198,7 +217,18 @@ void attachInterruptTwi(void (*userFunc)(void) ) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(EICRA) && defined(EICRB)
|
#if defined(__AVR_ATmega32U4__)
|
||||||
|
SIGNAL(INT0_vect) {
|
||||||
|
if(intFunc[EXTERNAL_INT_0])
|
||||||
|
intFunc[EXTERNAL_INT_0]();
|
||||||
|
}
|
||||||
|
|
||||||
|
SIGNAL(INT1_vect) {
|
||||||
|
if(intFunc[EXTERNAL_INT_1])
|
||||||
|
intFunc[EXTERNAL_INT_1]();
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(EICRA) && defined(EICRB)
|
||||||
|
|
||||||
SIGNAL(INT0_vect) {
|
SIGNAL(INT0_vect) {
|
||||||
if(intFunc[EXTERNAL_INT_2])
|
if(intFunc[EXTERNAL_INT_2])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user