Looking for guide to set up open source project to run on multiple microcontller

I've created a device for measuring system latency, first using an arduino, then an itsy-bitsy, and now a custom PCB. I designed the Windows software/driver/whatever it's called that reads the USBs input, but an EE friend has helped me port it from each different config to the next.
Since this is the case, I'm not sure what my best options are for making the program portable.
One of the first lines in the program is a major culprit:

// LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) //Arduino pinout?
// LiquidCrystal lcd(4, 6, 8, 10, 11, 12, 13);   //adafruit itsybitsy prototype version
   LiquidCrystal lcd(8, 6, 4, 0, 1, 9, 5);      //syslat custom pcb version

Should I be using something like:

#IFDEF __ARDUINO__
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) //Arduino pinout?
#IFDEF __ITSYBITSY__
LiquidCrystal lcd(4, 6, 8, 10, 11, 12, 13);   //adafruit itsybitsy prototype version
#IFDEF __CUSTOMPCB__
LiquidCrystal lcd(8, 6, 4, 0, 1, 9, 5);      //syslat custom pcb version

Or something else?

Here's the full source (225 lines) if needed: GitHub - Skewjo/SysLat_Firmware: Arduino firmware for SysLat project

if all your microcontrollers are loading an arduino sketch then you need to look at what #define is indeed specific for a given target platform and have that into your library.

There are two standardized macros provided by the build system:

These can be used to switch architecture-specific code, as described here:
https://arduino.github.io/arduino-cli/latest/library-specification/#working-with-multiple-architectures
That's in the Arduino library documentation, but it applies just as well to sketches.

The individual toolchains may also provide their own macros, for example:
https://www.nongnu.org/avr-libc/user-manual/using_tools.html

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.