Page 1 of 1

Using timerAttachInterrupt inside a library

Posted: Wed Mar 14, 2018 7:19 am
by dalvikvm
I moved most of my code to a library but one particular function call gives me an error when compiling.

This is the function needed for the timerAttachInterrupt():

Code: Select all

void IRAM_ATTR TriggerTimer::cdInterrupt(){
 //some codes
}
This is how I used the attachTimerInterrupt() function:

Code: Select all

void TriggerTimer::startTimer(){
  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &cdInterrupt, true);
  timerAlarmWrite(timer, 1000000, true);
  timerAlarmEnable(timer);
}
The compiler forbids me taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. It suggests me to use &TriggerTimer::cdInterrupt as a parameters which also gives me an error because the timerAttachInterrupt expects void(*)() and not void(TriggerTimer*)(). How do I solve this problem?

Re: Using timerAttachInterrupt inside a library

Posted: Fri Mar 16, 2018 3:13 am
by dalvikvm
I was able to fix it by making the function static in the header file.