How to use HAL_*_RegisterCallback to register an object method (C++)
Hi everyone,
I have written class that handles U(S)ART communication on top of HAL. In my application I have several objects of that class, e.g. one for USART2, another for LPUART1,...
Currently, I have my own way of registering callbacks: I have static method that stores, which UART handle (UART_HandleTypeDef) belongs to which of my object. The callback function then looks up what object is responsible for the handle passed to it. E.g.:
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
UartComm* uc = UartComm::get_object_by_UART_Handle(huart);
if (uc == nullptr) {
return;
}
uc->RxEventCallback_(Size);
}
If understand correctly, the HAL provides HAL_*_RegisterCallback, which would allow a similar registration directly. Having "ordinary" functions this should be straight forward but in my case I would need binding to an object method.
Is there a clean / preferred way of doing so? Or better stick with the current solution :\
I am using Keil MDK-ARM Plus Version: 5.39, C++11 / C11
Thanks for any help, suggestions,...
