Migrating to Visual Studio Code and PlatformIO From Arduino IDE

Started by MojaveTom, February 11, 2021, 03:08:36 PM

MojaveTom

Only a small part of my programming efforts are oriented to embedded devices, so I find the Visual Studio Code IDE (VS Code) suits my needs well.  With the PlatformIO extension, it works well for embedded devices too.

One of my frustrations has been porting Arduino sketches (.ino) files to C++ as required for VS Code.  Arduino IDE implicitly adds #import <Arduino.h> to the .ino source, and somehow relaxes the C++ requirement that functions be defined before they are referenced.  I have been manually editing .ino sources to add those features.  VS Code also sometimes fails if the Wire.h and/or SPI.h files have not been included in the main program.

To alleviate my frustration, I developed a bash script and supporting files to add those # include directives and function prototypes to the top of the file while copying the .ino to a .cpp file.  The script invokes Doxygen to scan the source and write  XML files.  Then xsltproc is used to pick out the function declarations.

The project can be found at:
https://github.com/MojaveTom/Arduino_ino_to_cpp