HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Working libraries, libraries being ported and related hardware
Post Reply
jmcSciences
Posts: 4
Joined: Mon May 18, 2020 11:42 am

HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Post by jmcSciences »

Hello,
As of the new 1.9.0 release, attachInterrupt callback's API of the HardwareTimer class is now std::function(void). HardwareTimer *htim is no longer passed as argument. As the callback must be a C function pointer, it must be a static function or a static member. So "this" operateur isn't usable.

So now, how to handle the HardwareTimer instance caller in the timer interrupt callback ?

User avatar
fpiSTM
Posts: 478
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 15
Location: Le Mans
Contact:

Re: HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Post by fpiSTM »

Answer from @ABOSTM ;)
With the new implementation done in the 1.9.0, it is always possible to give an argument to the callback at execution time. Thanks to the magical C++ binding and templates.

But the parameter is no longer restricted to the HardwareTimer object, it can be anything.
It is therefore always possible to pass the object ... but more if necessary.
An example is available here:
https://github.com/stm32duino/STM32Exam ... _parameter

jmcSciences
Posts: 4
Joined: Mon May 18, 2020 11:42 am

Re: HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Post by jmcSciences »

that's clear now, thank you for all ! ;)

mrburnette
Posts: 134
Joined: Thu Dec 19, 2019 1:23 am

Re: HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Post by mrburnette »

Code: Select all

  // Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup() function is finished.
+1 Nice


Ray

Post Reply

Return to “Libraries & Hardware”