Page 1 of 1

Using software timers with lambda's

Posted: Mon Aug 29, 2022 11:18 am
by Bascy65
In my project I'm creating a scheduler that can schedule "random" actions using xTimerCreate method to create a software timer. I'm using software timers as I don't need very high accuracy and using interrupts would make things more complex than needed.

The xTimerCreate method has a parameter for a callback function but I would like to specify a lambda to be executed when the timer fires.

Code: Select all

TimerHandle_t xTimerCreate( const char * const pcTimerName,
  const TickType_t xTimerPeriodInTicks,
  const UBaseType_t uxAutoReload,
  void * const pvTimerID,
  TimerCallbackFunction_t pxCallbackFunction 
 )
 
 with TimerCallbackFunction defined as void vCallbackFunction( TimerHandle_t xTimer )
  
The pvTimerID parameter is a untyped void pointer which can point to anything, so it might be possible to specify the lambda here and use the callback function to retrieve and execute that.

How would I do that?