QUESTION: Folder structure for MCU specific implementations

Hello all,

I’m trying to organise my codebase to support separating abstract virtual interfaces from MCU specific implementations.

I want the following arrangement:

|--lib
|  |
|  |--Interfaces
|  |  |-iLed.h
|  | 
|  |--MCU
|  |  |--Feather32u4
|  |  |  |--src
|  |  |  |  |-Led.h
|  |  |  |  |-Led.cpp
|  |  |--Nodemcuv2
|  |  |  |--src
|  |  |  |  |-Led.h
|  |  |  |  |-Led.cpp
|--src
|  |- main.cpp

In e.g. Feather32u4\src\Led.h

 #include <iLed.h>
 class LED : public iLED {}

In main.cpp

#include <MCU/Feather32u4/src/Led.h>

Attempts:

[1] This (and combinations of it):

#include </MCU/Feather32u4/src/Led.h>

doesn’t work. It produces:

src/main.cpp:1:38: fatal error: /MCU/Feather32u4/src/Led.h: No such file or directory

[2] Although this fails to specify which Led.h to include:

#include <Led.h>

it apparently finds lib/MCU/Feather32u4/src/Led.h, but produces:

lib/MCU/Feather32u4/src/Led.h:2:18: fatal error: iLed.h: No such file or directory

Question: What spells do I have to cast through platformio.ini and various library.json files to get the compiler to find the header files? Is there some other way of achieving this outcome?

Many thanks.

Starting a include path with / seems wrong, might be interepreted as ‘root’. Also since MCU is the library (which contains two sub-folders), you’d more want to a #include <Feather32u4/src/Led.h>.

Then again it’s weird to have a source file in the src folder if you wanted to make that distinction in the first place. An inc would be clearer. Also think about moving the iLed.h directly in the library folder as the interface and implementation seem to make one logic block.

The library dependency finder might not have found the dependency of MCU to Interface. Try #include <iLed.h> in your main source code file or lib_deps = Interface in the platformio.ini. Or a proper dependencies declaration in library.json files.

Anyways, the documentation shows an example of a HAL based library which uses a library.json and advanced scripting to modifies the src_filter (docs) during the compilation process just right so that all files except the ones for the target MCU are ignored.

Max - many thanks for taking the time to reply and the useful thoughts on code structure. lib_deps = Interface solved it!

Best wishes - Richard