Skip to content

lambda function not in IRAM #14

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
paul303 opened this issue Aug 18, 2019 · 4 comments
Closed

lambda function not in IRAM #14

paul303 opened this issue Aug 18, 2019 · 4 comments

Comments

@paul303
Copy link

paul303 commented Aug 18, 2019

In the example "Esp32RotaryEncoderBasics.ino" the lambda function for calling the ISR is not put into IRAM.

rotaryEncoder.setup([]{rotaryEncoder.readEncoder_ISR();});

Having the complete ISR call in IRAM is something I have painfully learned. My solution is to wrap the call in a plain function like

void IRAM_ATTR readEncoderWrapper_ISR(){ rotaryEncoder.readEncoder_ISR(); }

and set the library up with

rotaryEncoder.setup(readEncoderWrapper_ISR);

This discussion helped me to understand.

I hope this helps.

p.s. thanks for your ai-esp32-rotary-encoder library!

@igorantolic
Copy link
Owner

Would you improve the code and then I can merge.
Obviously you know how so we can improve.

@ril3y
Copy link

ril3y commented Nov 15, 2019

@paul303 can you share your implementation?

@stevesch
Copy link

stevesch commented Apr 16, 2021

I encountered the same-- example still has this flaw. Just do not use the lambda. Use a separate function defined with IRAM_ATTR:

void IRAM_ATTR readEncoderISR()
{
  rotaryEncoder.readEncoder_ISR();
}

void setup()
{
  rotaryEncoder.setup(readEncoderISR);
}

@igorantolic
Copy link
Owner

All examples are updated to include the same solution. Additionally, button functions changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants