Close

Passing parameters to drivers during linking

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/26/2015 at 15:170 Comments

In my example sketch and config library I used a header in the config library to set pin numbers for the display's reset, chip select and command signals. Arduino looks for this header and includes it, which is a source of potential library-mix-up if several config libraries use the same name for this header. They have to use the same name because in that example case the driver source file looks for the pin definition header:

#include "ugfx-arduino-ssd1351-pins.h"
Things can be turned around by letting the linker do it, because pin numbers can also be passed with a struct:
typedef struct {
  const uint8_t pin_reset;
  const uint8_t pin_cs;
  const uint8_t pin_dc;
} ssd1351_pins_t;

const ssd1351_pins_t ssd1351_pins;
And then in the sketch or in some other source file at global scope:
ssd1351_pins_t ssd1351_pins = {1,2,3};
If done that way or similar (this is just an untested idea, after all), this information is not filled in by the preprocessor but during linking.

Discussions