PaulStoffregen / Encoder

Quadrature Encoder Library for Arduino
http://www.pjrc.com/teensy/td_libs_Encoder.html
540 stars 239 forks source link

attachInterrupt redefinition with optimized interrupts #8

Closed romainreignier closed 8 years ago

romainreignier commented 8 years ago

Hello, When using the ENCODER_OPTIMIZE_INTERRUPTS statement, the file utility/interrupt_config.h is used. In this file, the following macro l.6 is used to redefine the attachInterrupt method:

#define attachInterrupt(num, func, mode) enableInterrupt(num)

The issue is that it interferes with other uses of this method name like with the TimerOne & TimerThree libraries. In these libraries, the attachInterrupt method only takes one argument but as the previous macro is not scoped, it is used as well in the Timer libraries. So the compiler throws that kind of errors:

Arduino/libraries/TimerThree/TimerThree.h:141:39: error: macro "attachInterrupt" requires 3 arguments, but only 1 given
     void attachInterrupt(void (*isr)()) __attribute__((always_inline)) {
                                       ^

A simple workaround would be to replace the attachInterrupt method in the Timer libraries by something like attachInterruptHandler or attachInterruptFunction but it will break the API and Arduino users are already used to that name.

But the issue is caused by the Encoder library so it would be better to fix that in this library.

Sincerely,

Romain

romainreignier commented 8 years ago

Oh, I am so sorry, I missed the warming on the library page. I close the issue.

PaulStoffregen commented 8 years ago

I'm looking at this now....

romainreignier commented 8 years ago

Thanks :+1: