IoAbstraction icon indicating copy to clipboard operation
IoAbstraction copied to clipboard

Add support for function objects in ioDeviceAttachInterrupt

Open pward123 opened this issue 2 years ago • 3 comments

Would it be possible to support non-static class methods as callbacks in ioDeviceAttachInterrupt?

I ran across this post where they came up with this to work around the limitation.

pward123 avatar Oct 25 '21 03:10 pward123

We'll need to take a look at this in terms of safety, if as it looks it's already supported on ESP, then it could certainly be conditional for ESP32 and ESP8266 boards.

davetcc avatar Oct 25 '21 09:10 davetcc

Wow, how time flies, it's been a really busy year, but I've taken a look at this now and it looks like it would work for at least ESP32 and STM32Duino.

davetcc avatar Sep 25 '22 11:09 davetcc

see https://github.com/davetcc/TaskManagerIO/issues/42

davetcc avatar Sep 25 '22 11:09 davetcc

will be added in the next release of taskmanager

davetcc avatar Oct 01 '22 16:10 davetcc

Unfortunately, ESP32 does not support this directly, STM32 does, but I'm not sure how safe it even is on STM32 as I don't know how safe std::function objects are in an interrupt context.

Memory visibility and safety in interrupts is my major concern, if anything goes wrong, it would be extremely difficult to debug.

At any rate, we no longer really recommend the original interrupt marshalling, instead we suggest that people use events to handle the raw interrupt and just trigger the event. I thought this would be an easy one supported by ESP32, but unfortunately it is not. I'd recommend you just use that class in your own code with a task manager BaseEvent.

davetcc avatar Oct 01 '22 16:10 davetcc