Use of PlatformIO with Arduino/Adafruit Github repos

I needed to fork and create a pull request on some public library repos owned by Adafruit. The file structure of those repos does not match PlatformIO’s (e.g. source files are at the top level, not in “src”). I’ve searched around and can’t find an answer to what I imagine is a FAQ which is how can I do this in a painless fashion? Ie. Clone the repo to my machine, edit and build with PlatformIO/Atom, and then commit the change to Github so I can create a pull request. Thanks.

Do you mean library repositories? We support old Arduino format too where source files are located in the root of folder.

Here is a specific example RA8875. I could not find a way to get PlatformIO to work with this file structure.

This works out-of-the box for me.

platformio.ini

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = 
	Adafruit GFX Library
	https://github.com/adafruit/Adafruit_RA8875

src\main.cpp

#include <Arduino.h>

#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"


// Library only supports hardware SPI at this time
// Connect SCLK to UNO Digital #13 (Hardware SPI clock)
// Connect MISO to UNO Digital #12 (Hardware SPI MISO)
// Connect MOSI to UNO Digital #11 (Hardware SPI MOSI)
#define RA8875_INT 3
#define RA8875_CS 10
#define RA8875_RESET 9

Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty;

void setup()
{
  Serial.begin(9600);
  Serial.println("RA8875 start");

  /* Initialise the display using 'RA8875_480x272' or 'RA8875_800x480' */
  if (!tft.begin(RA8875_480x272)) {
    Serial.println("RA8875 Not Found!");
    while (1);
  }

  Serial.println("Found RA8875");

  tft.displayOn(true);
  tft.GPIOX(true);      // Enable TFT - display enable tied to GPIOX
  tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
  tft.PWM1out(255);

  // With hardware accelleration this is instant
  tft.fillScreen(RA8875_WHITE);

  // Play with PWM
  for (uint8_t i=255; i!=0; i-=5 )
  {
    tft.PWM1out(i);
    delay(10);
  }
  for (uint8_t i=0; i!=255; i+=5 )
  {
    tft.PWM1out(i);
    delay(10);
  }
  tft.PWM1out(255);

  tft.fillScreen(RA8875_RED);
  delay(500);
  tft.fillScreen(RA8875_YELLOW);
  delay(500);
  tft.fillScreen(RA8875_GREEN);
  delay(500);
  tft.fillScreen(RA8875_CYAN);
  delay(500);
  tft.fillScreen(RA8875_MAGENTA);
  delay(500);
  tft.fillScreen(RA8875_BLACK);

  // Try some GFX acceleration!
  tft.drawCircle(100, 100, 50, RA8875_BLACK);
  tft.fillCircle(100, 100, 49, RA8875_GREEN);

  tft.fillRect(11, 11, 398, 198, RA8875_BLUE);
  tft.drawRect(10, 10, 400, 200, RA8875_GREEN);
  tft.fillRoundRect(200, 10, 200, 100, 10, RA8875_RED);
  tft.drawPixel(10,10,RA8875_BLACK);
  tft.drawPixel(11,11,RA8875_BLACK);
  tft.drawLine(10, 10, 200, 100, RA8875_RED);
  tft.drawTriangle(200, 15, 250, 100, 150, 125, RA8875_BLACK);
  tft.fillTriangle(200, 16, 249, 99, 151, 124, RA8875_YELLOW);
  tft.drawEllipse(300, 100, 100, 40, RA8875_BLACK);
  tft.fillEllipse(300, 100, 98, 38, RA8875_GREEN);
  // Argument 5 (curvePart) is a 2-bit value to control each corner (select 0, 1, 2, or 3)
  tft.drawCurve(50, 100, 80, 40, 2, RA8875_BLACK);
  tft.fillCurve(50, 100, 78, 38, 2, RA8875_WHITE);

  pinMode(RA8875_INT, INPUT);
  digitalWrite(RA8875_INT, HIGH);

  tft.touchEnable(true);

  Serial.print("Status: "); Serial.println(tft.readStatus(), HEX);
  Serial.println("Waiting for touch events ...");
}

void loop()
{
  float xScale = 1024.0F/tft.width();
  float yScale = 1024.0F/tft.height();

  /* Wait around for touch events */
  if (! digitalRead(RA8875_INT))
  {
    if (tft.touched())
    {
      Serial.print("Touch: ");
      tft.touchRead(&tx, &ty);
      Serial.print(tx); Serial.print(", "); Serial.println(ty);
      /* Draw a circle */
      tft.fillCircle((uint16_t)(tx/xScale), (uint16_t)(ty/yScale), 4, RA8875_WHITE);
    }
  }
}
Dependency Graph
|-- <Adafruit GFX Library> 1.4.2 (C:\Users\Maxi\Documents\stackoverflow_testing\.piolibdeps\Adafruit GFX Library_ID13)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
|-- <Adafruit RA8875> 1.0.4 #ea49095 [git+https://github.com/adafruit/Adafruit_RA8875] (C:\Users\Maxi\Documents\stackoverflow_testing\.piolibdeps\Adafruit RA8875)
|   |-- <Adafruit GFX Library> 1.4.2 (C:\Users\Maxi\Documents\stackoverflow_testing\.piolibdeps\Adafruit GFX Library_ID13)
|   |   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
|-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SPI)
[..]

DATA:    [==        ]  18.0% (used 368 bytes from 2048 bytes)
PROGRAM: [====      ]  39.0% (used 12570 bytes from 32256 bytes)
 [SUCCESS] Took 5.55 seconds 

Also this library is properly registered already: PlatformIO Registry

Yes, I can use the library just fine. My question was how to clone the library so I can make fixes and then do a pull request to the library owner. PlatformIO seems to insist I move the files into it’s idea of a folder structure.

If you git clone the library into your project’s lib/ folder, compilation should work as normal and you can still commit your changes to the repo in order to make a PR. Does that solve the problem?

Thanks for the suggestion. I’ll give it a try.