Compiling code with PIO

I’m using some code on github which I want to get compiling under PIO. I am trying to make some changes to the code and thought it would be better to get it going with PIO.

https://github.com/terenceang/SDisk2/tree/master/firmware/src

First off, there is a makesdisk.sh file which if I manually run compiles the code without any errors for the atmega328.

If I try and build it using PIO I run into all sorts of compile errors.

Processing ATmega328 (platform: atmelavr; board: ATmega328; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328.html
PLATFORM: Atmel AVR (3.4.0) > ATmega328
HARDWARE: ATMEGA328 270MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr-minicore @ 2.1.3 
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/ATmega328/src/FAT32.c.o
Compiling .pio/build/ATmega328/src/SD_routines.c.o
Compiling .pio/build/ATmega328/src/SPI_routines.c.o
Compiling .pio/build/ATmega328/src/main.c.o
Compiling .pio/build/ATmega328/src/oled.c.o
In file included from src/main.h:60:0,
                 from src/main.c:37:
src/oled.h:78:26: error: unknown type name 'prog_char'
 void ssd1306_put_p(const prog_char *progmem_s);
                          ^~~~~~~~~
src/main.c:122:15: error: unknown type name 'prog_uchar'

Beginner c user here. If I google those errors it points to a depreciated command - is this why its working with bash script and not PIO?

The bash script is passing a lot of compiler parameters.

-Wall -Os -Wno-deprecated-declarations -Wno-strict-aliasing 
-D__PROG_TYPES_COMPAT__ -D_SDISK_OLED_  -fpack-struct -fshort-enums 
-std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p 
-DF_CPU=27000000UL -MMD -MP -c 

I’m taking a few stabs in the dark and guessing it might be related tno-deprecated-declarations flag?

I then tried the following flags in the platform.io file but this has not helped.

[env:ATmega328]

platform = atmelavr

board = ATmega328

framework = arduino

upload_protocol = usbtiny

board_build.f_cpu = 270000000L

build_flags = -Wall -Os -Wno-deprecated-declarations -Wno-strict-aliasing

Can anyone point me in the right direction before I go down another rabbit hole.

prog_char comes from avr/pgmspace per documentation, but only if

The typedef is only visible if the macro __PROG_TYPES_COMPAT__ has been defined before including <avr/pgmspace.h> (either by a #define directive, or by a -D compiler option.)

Sot the most critical thing is that you add -D__PROG_TYPES_COMPAT__ to the build_flags for that to work.

Thanks very much. That fixed the issue.