How to set HAL JPEG register callbacks

Hello @jeromecoutant

For our project, we need to use the HAL confg USE_HAL_JPEG_REGISTER_CALLBACKS available here:

It is set to 0 and I don’t know how we can set it to one without modifying mbed-os’ files.

Do you have any idea? I can make a PR with a solution similar to this one:

Let me know :slight_smile:

– Ladislas

To be honest I have never used CALLBACKS…
About your issue, I think your proposition is valid.
We should even make a script that updates all the USE_HAL_xxx_REGISTER_CALLBACKS…

You never got the chance? Or you have a different solution?

It turns out that interfacing the HAL code with C++ is not easy… And I’m not talking about unit testing all that…

We ended up using a global object but that’s okay in our case. Funny enough we can now pass lambdas to the function which is quite nice :slight_smile:

	HAL_JPEG_RegisterInfoReadyCallback(corejpeg.getJpegHandle(), [](JPEG_HandleTypeDef *hjpeg, JPEG_ConfTypeDef *info) {
		corejpeg.onInfoReadyCallback(hjpeg, info);

	HAL_JPEG_RegisterGetDataCallback(corejpeg.getJpegHandle(), [](JPEG_HandleTypeDef *hjpeg, uint32_t size) {
		corejpeg.onDataAvailableCallback(hjpeg, size);

									   [](JPEG_HandleTypeDef *hjpeg, uint8_t *pDataOut, uint32_t size) {
										   corejpeg.onDataReadyCallback(hjpeg, pDataOut, size);

	HAL_JPEG_RegisterCallback(corejpeg.getJpegHandle(), HAL_JPEG_DECODE_CPLT_CB_ID,
							  [](JPEG_HandleTypeDef *hjpeg) { corejpeg.onDecodeCompleteCallback(hjpeg); });

	HAL_JPEG_RegisterCallback(corejpeg.getJpegHandle(), HAL_JPEG_ERROR_CB_ID,
							  [](JPEG_HandleTypeDef *hjpeg) { corejpeg.onErrorCallback(hjpeg); });

Woah, that works? I didn’t realize you could do that. It must be only for non-capturing lambdas though right?

Sadly yes, but that’s better than nothing!

I’ve made a PR : STM32F7 - Add if defined check for USE_HAL_XXX_REGISTER_CALLBACKS by ladislas · Pull Request #14351 · ARMmbed/mbed-os · GitHub