Skip to content

HardwareTimer custom parameter in interrupt callback #891

Closed
@ramboerik

Description

@ramboerik

Is your feature request/improvement related to a problem? Please describe.
I'm using the HardwareTimer class and would like to pass a custom parameters to the interrupt callback. Currently the only way of doing this is to use global variable(s).

Describe the solution you'd like
I guess the easiest fix without breaking any compatibility would be to add a pointer for every timer channel that can be accessed from within the interrupt:

Usage:

static inline void isr(HardwareTimer* timer) {
    if(timer == nullptr){
        return;
    }

    custom_class* param = (custom_class*)timer->getArg();
    if(param  == nullptr){
        return;
    }
    param ->work();
}
custom_class param;
HardwareTimer m_timer(TIM1);
m_timer.attachInterrupt(GptChannel::isr, (void*)&param);

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions