tuupola / hagl

Hardware Agnostic Graphics Library for embedded
https://www.appelsiini.net/tags/hagl/
MIT License
296 stars 47 forks source link

null hal / qemu hal #60

Open greenaddress opened 2 years ago

greenaddress commented 2 years ago

Hi,

I'm trying to build an esp32 based project with both the hagl_hal (hagl_esp_mipi) and a qemu_hal which currently does nothing but I would like to expose the screen via network for testing purposes. It works fine when I use the real hal but I have issues using the qemu hal as it conflicts with the other hal at build time even if I don't require it explicitly my project.

The README for this repo states that to build a hal you need to implement hagl_hal_put_pixel which I did - and I was planning to choose the hal at compile time by including the hal header from hagl_esp_mipi vs my basic hal function based on some sdkconfig.

I noticed that hagl.h includes hagl_hal.h and also that hagl CMakeFile requires hagl_hal

I also noticed that at the very minimum hagl_hal.h needs to provide not just the hagl_hal_put_pixel function but also the color_t definition.

Do you have suggestions on how to use one hal vs another in esp32?

tuupola commented 2 years ago

It is probably due my lack of understanding how CMake works but I haven't found out a good way to choose a HAL in compile time. Instead HAGL assumes it to be in the folder hagl_hal. This is not optimal but I have not had need for a fix myself so the problem has not been fixed.

Also slightly related I am pondering about enabling running several displays (even with different HALs) at the same time. This would require passing a display object to each function call. Something like:


hagl_display_t display;

hagl_init(display);
hagl_put_pixel(display, x0, y0, color);
greenaddress commented 2 years ago

Yeah I reckon for multiple displays it makes sense to pass in the display as a parameter.

In regards to having conditional builds, I manged to hack something which required no changes to the hagl repo but required some minimal changes to hagl_hal (hagl_esp_mipi)

I attach the patch here - if you like it I can do a PR against hagl_esp_mipi hagl_hal_external.txt but basically it involves adding a new kconfig that if set doesn't include any of the implementations of the hal, leaving the user of the libraries to provide the implementation. Let me know what you think please!

tuupola commented 2 years ago

Thanks I will check it!

greenaddress commented 2 years ago

Another option I found is that idf_component_register can be called conditionally - so for example in https://github.com/tuupola/hagl_esp_mipi/blob/master/CMakeLists.txt the register could be conditional on a config like CONFIG_HAGL_MIPI_ENABLE or whichever name you think is most appropriate of course.

Would you like me to do a PR for this instead? or provide a PoC?