Impossible to build Adafruit GFX with PlatformIO

I can reproduce the same errors on the GFXCanvas and

[env:ATmega4809]
platform = atmelmegaavr
board = ATmega4809
framework = arduino
lib_ldf_mode = chain+
lib_deps =
     adafruit/Adafruit GFX Library @ ^1.10.7
     adafruit/Adafruit BusIO @ ^1.7.3
     SPI
     Wire

Fundamentally, when selecting ATmega4809 as board, it uses a different Arduino core (https://github.com/MCUdude/MegaCoreX) than when using nano_every (GitHub - arduino/ArduinoCore-megaavr: Arduino Core for the ATMEGA4809 CPU).

Every core can be implemented arbitrarily and thus are not necessarily compatible with each Arduino library.

When I use board = nano_every the sketch compiles no problems without modifications.

Processing ATmega4809 (platform: atmelmegaavr; board: nano_every; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/nano_every.html
PLATFORM: Atmel megaAVR (1.4.0) > Arduino Nano Every
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 47.50KB Flash
PACKAGES:
 - framework-arduino-megaavr 1.8.7
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain+, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit GFX Library> 1.10.7
|   |-- <Adafruit BusIO> 1.7.3
|   |   |-- <Wire> 1.0
|   |   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <Adafruit BusIO> 1.7.3
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <SPI> 1.0
|-- <Wire> 1.0
Building in release mode
Compiling .pio\build\ATmega4809\FrameworkArduinoVariant\variant.c.o
[..]
Building .pio\build\ATmega4809\firmware.hex
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.0% (used 187 bytes from 6144 bytes)
Flash: [===       ]  30.5% (used 14815 bytes from 48640 bytes)
==================== [SUCCESS] Took 2.92 seconds ====================

This is because for the Nano Every board, the Arduino core pulls in code from the ArduinoCore-API project which defines

and thus that type is declared and the include doesn’t trigger.

As for building with board = ATmega4809, the core does have the MSBFIRST and LSBFIRST macros…

but not the BitOrder type.

So in this in the header, the first block should light up.

However it doesn’t because ARDUINO_AVR_ATmega4809 is not defined for this board. Also

Is wrong because that is not seen globally when other .cpp files are compiled. The right way would be to do

build_flags = -DARDUINO_AVR_ATmega4809

which makes the sketch compile again.

The reason the flag is not defined is because it’s spelled differently in the PlatformIO definition…

thus this might a bug.