Close

Having config and low level drivers in a separate library

A project log for using uGFX in Arduino

uGFX was written for use with makefiles. Using it in arduino is possible with minimal effort, though. Here's how.

christophChristoph 11/23/2015 at 20:310 Comments

In the previous log I've described how uGFX can be simply put into arduino's library folder (that was trivial). The next step I tried was to create a wrapper library that simply points at the bare ugfx clone, but has only one header in its folder:

libraries/ugfx-arduino/
+- ugfx-arduino.h (includes gfx.h and all other ugfx headers)
+- ugfx-arduino.c (includes src/gfx_mk.c)
That way, when using the library menu to include the ugfx-arduino library, only one header will be added to the sketch. Fine, and now I'll try to create a config and low-level driver library:

libraries/myproject-ugfx/
+- board_ssd1331.cpp
+- board_ssd1331.h
+- driver_ssd1331.c
+- gdisp_lld_config.h
+- gfxconf.h
+- myproject-ugfx.h (includes ugfx-arduino.h)
This fails when including myproject-ugfx.h in a sketch:

In file included from ~/Arduino/libraries/ugfx/src/gdisp/gdisp.h:212:0,
                 from ~/Arduino/libraries/ugfx/gfx.h:198,
                 from ~/Arduino/libraries/ugfx-arduino/ugfx-arduino.h:5,
                 from ~/Arduino/libraries/myproject-ugfx/myproject-ugfx.h:2,
                 from ~/Arduino/ugfx-ArduinoTinyScreen/ugfx-ArduinoTinyScreen.ino:1:
~/Arduino/libraries/ugfx/src/gdisp/gdisp_colors.h:394:3: error: #error "GDISP: Unsupported color system"
  #error "GDISP: Unsupported color system"
I can't do much more than guess why, but I'll try: Probably because ugfx is compiled as a library before the config and low level drivers are compiled (ugfx is one of their depencies, so that would make sense), so no driver color system is known at that time: iirc ugfx uses some header trickery to get low-level driver information. If that's true, it's bad for us.

It seems the only way to circumvent this is to change the order of compilation or to add the whole ugfx source to the project-specific ugfx library. Some pros and cons of the second option:

+ The ugfx version used in the project is fixed, and updating some central ugfx clone won't affect it. Instead it can be updated when the project needs it.

- The ugfx source as cloned from the repo is quite large (about 16 MB!?), and having multiple copies will add up quickly. It might be possible to get around this with a file system link, though.

Discussions