Skip to content

HardwareTimer custom parameter in interrupt callback #891

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
ramboerik opened this issue Jan 26, 2020 · 0 comments · Fixed by #892
Closed

HardwareTimer custom parameter in interrupt callback #891

ramboerik opened this issue Jan 26, 2020 · 0 comments · Fixed by #892
Assignees
Labels
enhancement New feature or request

Comments

@ramboerik
Copy link
Contributor

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants