user86306: I would like to share interrupt routine between class. I followed this tutorial.
But I need to call a member function in callback function, I have the issue :

This is my code :
Timer.h
static void (*__handleISR)(void);

class Timer
{
    public:
        Timer();
        ~Timer();
        static void init();
        static void handleISR(void (*function)(void));
};

Timer.cpp
Timer::Timer()
{
}

Timer::~Timer()
{}

void Timer::init()
{    
    TCCR2A = 0; //default 
    TIMSK2 = 0b00000001; // TOIE2
}

ISR (TIMER2_OVF_vect) 
{
    // 256-6=250 --> (250 x 16uS = 4mS)
    // Recharge le timer pour que la prochaine interruption se declenche dans 4mS
    TCNT2 = 6;

    __handleISR();
}

Device.h
class Device
{
    public:
        Device();

    private:
        void isr();
};

Device.cpp
Device::Device()
{
    Timer::init();
    Timer::handleISR(isr);
}

void Device::isr()
{
    // Do my stuff
}

If I set function isr() static, it works. But I need to call member from Device in isr().
How I can call non static member function ? Or another solution ?

user60431: This is not an Arduino specific question but a C++ question, and as such you might get more or better answers on StackOverflow. Anyway, I'll suggest a possible solution.
A member method always receives a pointer to its object as a hidden first argument that we know as this. Only via this argument such a method is able to access member attributes or member methods.
A class method does not have this parameter.
The function type you define is compatible only to functions or class methods.
So you need to provide a pointer (or reference) to the Device object.
I reduced your example and replaced the interrupt macro with something a standard C++ compiler accepts, as this is not part of the issue.
Timer.h
#ifndef TIMER_H
#define TIMER_H

#include "Device.h"

class Timer
{
    public:
        static void setCallback(void (*function)(Device*), Device*);
};

#endif

Timer.cpp
#include "Timer.h"

#define ISR(f) void f()

static void (*_function)(Device*);
static Device* _device;

void Timer::setCallback(void (*function)(Device*), Device* device)
{
    _function = function;
    _device = device;
}

ISR(TIMER2_OVF_vect) 
{
    _function(_device);
}

Device.h
#ifndef DEVICE_H
#define DEVICE_H

class Device
{
    public:
        Device();

    private:
        static void isr(Device* device);
        void isr();
};

#endif

Device.cpp
#include "Device.h"
#include "Timer.h"

Device::Device()
{
    Timer::setCallback(isr, this);
}

void Device::isr(Device* device)
{
    device->isr();
}

void Device::isr()
{
    // Do my stuff
}

If you don't need the Device object, you don't need a member method. Then go with a class method, as you already found out.

86306: <p>I would like to share interrupt routine between class. I followed this <a href="https://atadiat.com/en/e-arduino-trick-share-interrupt-service-routines-between-libraries-application/" rel="nofollow noreferrer">tutorial</a>.</p>
<p>But I need to call a member function in callback function, I have the issue :
<a href="https://i.stack.imgur.com/GApwK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GApwK.png" alt="enter image description here" /></a></p>
<p>This is my code :</p>
<p>Timer.h</p>
<pre><code>static void (*__handleISR)(void);

class Timer
{
    public:
        Timer();
        ~Timer();
        static void init();
        static void handleISR(void (*function)(void));
};
</code></pre>
<p>Timer.cpp</p>
<pre><code>Timer::Timer()
{
}

Timer::~Timer()
{}

void Timer::init()
{    
    TCCR2A = 0; //default 
    TIMSK2 = 0b00000001; // TOIE2
}

ISR (TIMER2_OVF_vect) 
{
    // 256-6=250 --&gt; (250 x 16uS = 4mS)
    // Recharge le timer pour que la prochaine interruption se declenche dans 4mS
    TCNT2 = 6;

    __handleISR();
}
</code></pre>
<p>Device.h</p>
<pre><code>class Device
{
    public:
        Device();

    private:
        void isr();
};
</code></pre>
<p>Device.cpp</p>
<pre><code>Device::Device()
{
    Timer::init();
    Timer::handleISR(isr);
}

void Device::isr()
{
    // Do my stuff
}
</code></pre>
<p>If I set function isr() static, it works. But I need to call member from Device in isr().</p>
<p>How I can call non static member function ? Or another solution ?</p>
 60431: <p>This is not an Arduino specific question but a C++ question, and as such you might get more or better answers on <a href="https://stackoverflow.com/">StackOverflow</a>. Anyway, I'll suggest a possible solution.</p>
<p>A member method always receives a pointer to its object as a hidden first argument that we know as <code>this</code>. Only via this argument such a method is able to access member attributes or member methods.</p>
<p>A class method does not have this parameter.</p>
<p>The function type you define is compatible only to functions or class methods.</p>
<p>So you need to provide a pointer (or reference) to the <code>Device</code> object.</p>
<p>I reduced your example and replaced the interrupt macro with something a standard C++ compiler accepts, as this is not part of the issue.</p>
<p>Timer.h</p>
<pre class="lang-cpp prettyprint-override"><code>#ifndef TIMER_H
#define TIMER_H

#include &quot;Device.h&quot;

class Timer
{
    public:
        static void setCallback(void (*function)(Device*), Device*);
};

#endif
</code></pre>
<p>Timer.cpp</p>
<pre class="lang-cpp prettyprint-override"><code>#include &quot;Timer.h&quot;

#define ISR(f) void f()

static void (*_function)(Device*);
static Device* _device;

void Timer::setCallback(void (*function)(Device*), Device* device)
{
    _function = function;
    _device = device;
}

ISR(TIMER2_OVF_vect) 
{
    _function(_device);
}
</code></pre>
<p>Device.h</p>
<pre class="lang-cpp prettyprint-override"><code>#ifndef DEVICE_H
#define DEVICE_H

class Device
{
    public:
        Device();

    private:
        static void isr(Device* device);
        void isr();
};

#endif
</code></pre>
<p>Device.cpp</p>
<pre class="lang-cpp prettyprint-override"><code>#include &quot;Device.h&quot;
#include &quot;Timer.h&quot;

Device::Device()
{
    Timer::setCallback(isr, this);
}

void Device::isr(Device* device)
{
    device-&gt;isr();
}

void Device::isr()
{
    // Do my stuff
}
</code></pre>
<p><strong>If</strong> you don't need the <code>Device</code> object, you don't need a member method. Then go with a class method, as you already found out.</p>
