Relatively-Universal-ROM-Programmer
Relatively-Universal-ROM-Programmer copied to clipboard
Support PlatformIO for Arduino project
This pull request adds PlatformIO support (https://platformio.org). It also gets rid of 2 compilation warnings. It also incorporates PR #5 by @BizarroBull ('cast result of Serial.read() so it doesn't get treated as signed when bit shifting').
Not a bad idea but it would break Arduino IDE compatibility (both the .ino and main.cpp would need to be kept in sync). Any good ways to automate that?
Any other for/against?
I haven't used the Arduino IDE in a (long) while. I'm not sure it still insists on .ino files, but the .cpp file should work otherwise; the only real change I made is I added #include <Arduino.h> for PlatformIO (other minor changes from the top of my head were: declare functions before use, incorporate #5, maybe some formatting).
I'm not sure if this PR would break Arduino IDE compat though? As long as you open only the ArduinoProgrammerFirmwarePrototype directory in Arduino IDE it should work, shouldn't it?
But I agree that having the .ino files and the PlatformIO files in separate directories means having to keep the files in sync. I'm not sure if having a sort-of 'common' directory with shared code that is included in a .ino and the Platformio projects is possible.
If I have time tomorrow I'll try and see what I can come up with (being a primarily .Net developer I'm not sure if what I come up with is the best approach...)
Changing main.cpp to only contain this:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "../../ArduinoProgrammerFirmwarePrototype/ArduinoProgrammerFirmwarePrototype.ino"
...and adding this to ArduinoProgrammerFirmwarePrototype.ino:
#include <Arduino.h>
... seems to work. But that seems a little bit (very) dirty to me...
Having a separate cpp file and directory for platformio isn't necessary. As long as the source directory and the ino file have the same name, which they already do in this case, then Platformio will automatically convert the ino file at compile time.
Adding #include <Arduino.h> to the ino file isn't necessary because platformio will do so during the conversion but doing so does help intellisense with code highlighting and completion if you open the project in vscode. The ino file will continue to compile without issue in the Arduino IDE with this change.
There is a decision regarding where to place the platformio.ini and .gitignore file. You can place them in the software/Arduino directory or the software/Arduino/ArduinoProgrammerFirmwarePrototype directory. If there is a chance additional software will ever be placed in the software/Arduino directory I recommend placing them in the ArduinoProgrammerFirmwarePrototype directory.
If placed in software/Arduino the platformio section of platformio.ini should be as follows:
[platformio]
default_envs = uno
src_dir = ArduinoProgrammerFirmwarePrototype
If placed in the ArduinoProgrammerFirmwarePrototype directory the following instead:
[platformio]
default_envs = uno
src_dir = .