Best way for preprocessing conditionnal based on arch

User avatar
citoyx
Posts: 13
Joined: Sat Sep 28, 2019 10:14 am

Best way for preprocessing conditionnal based on arch

Postby citoyx » Tue Jun 01, 2021 9:09 pm

Im looking to use lora components with esp32-C3 mcu.
Sadly it doesn't compile out of the box because vspi_host doesn't seem to exist on this chipset.

So i would like to adapt the library to use a specific spi host depending of the architecture.

which general variable is accessible from preprocessor to distinguish between arch.
Does idf.py set-target esp32/esp32c3 manipulate such existing variables i can rely on ?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Best way for preprocessing conditionnal based on arch

Postby ESP_Angus » Tue Jun 01, 2021 11:30 pm

Hi citoyx,

To have conditional compilation based on the target chip you can include sdkconfig.h and then use CONFIG_IDF_TARGET_ESP32C3, CONFIG_IDF_TARGET_ESP32, etc.

However to future proof your code I'd suggest #ifdef VSPI_HOST as this filters on the property you care about (is there a SPI peripheral called VSPI_HOST?)

For some similar macros please take a look at the soc_caps.h header as well:
https://github.com/espressif/esp-idf/bl ... soc_caps.h
https://github.com/espressif/esp-idf/bl ... soc_caps.h

SOC_SPI_PERIPH_NUM in this header could also be used to distinguish the two (VSPI_HOST is macro-defined to SPI3_HOST in the IDF HAL layer).

Who is online

Users browsing this forum: No registered users and 431 guests