Using the method of the object as ISR without external code in "user space"

I want to suggest how to do it.

  1. Add new type to wiring_private.h
typedef void (*voidFuncPtr)(void);
typedef void (*voidFuncPtrEx)(void *);
  1. Add some code to WInterrupts.c (see attached file).

  2. Add description to Arduino.h

void attachInterruptEx(uint8_t, void (*userFunc)(void *), int, void * );

How to use:

class MyClass
	static void MyISRHelper( void * data )
		MyClass * self = reinterpret_cast< MyClass * >( data );
    void MyISR()
        // ...
	MyClass() {}
	~MyClass() {}

MyClass class1;

void setup() 
    attachInterruptEx( 2, MyClass::MyISRHelper, RISING, ( void * ) & class1 );	

void loop() {}

attachInterrupt() still works.

WInterrupts.c (10.6 KB)

So, if you have a class, Dog, with a Bark() method, and 12 instances of the class, Spot, Fido, DownDammit, etc., when the external interrupt happens, you want all 12 dogs to start barking?

No, attachInterruptEx() function takes as a parameter a pointer to the instance that is then used. When the method is called it will called with a pointer to an instance of an object as a parameter.

Looks a lot like this:

oqibidipo: Looks a lot like this:

Yes, this is similar that I do.