how to check for attached boards by "board type names"?

hi,
for some sketches targeting Adafruit TFTs (e.g. the 3.5" touchscreen) Adafruit sketches are checking for attached boards:

#ifdef ESP8266
   #define STMPE_CS 16
   #define TFT_CS   0
   #define TFT_DC   15
   #define SD_CS    2
#endif
#ifdef ESP32
   #define STMPE_CS 32
   #define TFT_CS   15
   #define TFT_DC   33
   #define SD_CS    14
#endif
#ifdef TEENSYDUINO
   #define TFT_DC   10
   #define TFT_CS   4
   #define STMPE_CS 3
   #define SD_CS    8
#endif
#ifdef ARDUINO_STM32_FEATHER
   #define TFT_DC   PB4
   #define TFT_CS   PA15
   #define STMPE_CS PC7
   #define SD_CS    PC5
#endif
#ifdef ARDUINO_FEATHER52
   #define STMPE_CS 30
   #define TFT_CS   13
   #define TFT_DC   11
   #define SD_CS    27
#endif
#if defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
   #define TFT_DC   P5_4
   #define TFT_CS   P5_3
   #define STMPE_CS P3_3
   #define SD_CS    P3_2
#endif

// Anything else!
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__) || defined(ARDUINO_SAMD_ZERO) || defined(__SAMD51__) || defined(__SAM3X8E__)
   #define STMPE_CS 6
   #define TFT_CS   9
   #define TFT_DC   10
   #define SD_CS    5
#endif

Unfortunately, some of my boards cannot be detected, i.e. my Adafruit Itsybitsy M0 and Arduino Due programming port. For Feather Huzzah (esp8266) and Feather M4 it works well though.
How can I determine the board type name, in case also other ones still not being checked yet?

The Adafruit Itsybitsy M0 specific macro is ARDUINO_ITSYBITSY_M0.

The SAM3X8E macro already used in the last set of pin definitions will match for the Due.

As for how to to determine board-specific macros in general, here's the documentation:

The uno.build.board property is used to set a compile-time variable ARDUINO_{build.board} to allow use of conditional code between #ifdefs. The Arduino IDE automatically generates a build.board value if not defined. In this case the variable defined at compile time will be ARDUINO_AVR_UNO.

So the way I found the Adafruit Itsybitsy M0 macro was to look in the Adafruit SAMD Boards boards.txt file for the Adafruit ItsyBitsy M0 board definition:

adafruit_itsybitsy_m0.name=Adafruit ItsyBitsy M0
adafruit_itsybitsy_m0.vid.0=0x239A
adafruit_itsybitsy_m0.pid.0=0x800F
adafruit_itsybitsy_m0.vid.1=0x239A
adafruit_itsybitsy_m0.pid.1=0x000F
adafruit_itsybitsy_m0.vid.2=0x239A
adafruit_itsybitsy_m0.pid.2=0x8012
adafruit_itsybitsy_m0.upload.tool=bossac
adafruit_itsybitsy_m0.upload.protocol=sam-ba
adafruit_itsybitsy_m0.upload.maximum_size=262144
adafruit_itsybitsy_m0.upload.offset=0x2000
adafruit_itsybitsy_m0.upload.use_1200bps_touch=true
adafruit_itsybitsy_m0.upload.wait_for_upload_port=true
adafruit_itsybitsy_m0.upload.native_usb=true
adafruit_itsybitsy_m0.build.mcu=cortex-m0plus
adafruit_itsybitsy_m0.build.f_cpu=48000000L
adafruit_itsybitsy_m0.build.usb_product="ItsyBitsy M0 Express"
adafruit_itsybitsy_m0.build.usb_manufacturer="Adafruit"
adafruit_itsybitsy_m0.build.board=ITSYBITSY_M0
adafruit_itsybitsy_m0.build.core=arduino
adafruit_itsybitsy_m0.build.extra_flags=-DCRYSTALLESS -DADAFRUIT_ITSYBITSY_M0 -D__SAMD21G18A__ -DARM_MATH_CM0PLUS {build.usb_flags}
adafruit_itsybitsy_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
adafruit_itsybitsy_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
adafruit_itsybitsy_m0.build.variant=itsybitsy_m0
adafruit_itsybitsy_m0.build.variant_system_lib=
adafruit_itsybitsy_m0.build.vid=0x239A
adafruit_itsybitsy_m0.build.pid=0x800F
adafruit_itsybitsy_m0.bootloader.tool=openocd
adafruit_itsybitsy_m0.bootloader.file=itsybitsyM0/bootloader-itsybitsy_m0-v2.0.0-adafruit.5.bin

In this case the build.board property is:

adafruit_itsybitsy_m0.build.board=ITSYBITSY_M0

Then in the Adafruit SAMD Boards platform.txt file you can see where the macro is defined:

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"

## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"

## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"

The -DARDUINO_{build.board} compiler flag is turned into -DARDUINO_ITSYBITSY_M0 when compiling for the Adafruit ItsyBitsy M0.

You could also use the Due's board-specific macro ARDUINO_SAM_DUE. The SAM3X8E macro will match any board that uses the SAM3X8E microcontroller. Likely any SAM3X8E-based Arduino boards would use the Due's pin mapping so that should be no problem. Using the board-specific macros can be a little more problematic because there are always new boards coming out, each of which will have their own macro so it's hard to keep code up to date with all the possible board macros.

thank you, pert,
ARDUINO_ITSYBITSY_M0 is fine, it works!

Now also ARDUINO_SAM_DUE and SAM3X8E
are accepted, the Due boards cores were broken - after uninstall and reinstall M3 cores it's fine now again (AFAICS :wink: )

Thank you very much again!

hi,
now another problem:
which is the general name for M0 cores?
ARDUINO_SAM_ZERO
seems to be wrong

OTOH, ARDUINO_ITSYBITSY_M0 works fine

What exactly do you mean by "M0 cores"?

a type for all boards which are powered by an M0,

similar to
SAM3X8E for all boards which are powered by an M3

(I already tried SAMD21 but with no success)

dsyleixa:
SAM3X8E for all boards which are powered by an M3

But this is not correct. There are many Cortex M3 microcontrollers other than the SAM3X8E. It would be more accurate to say that AVR_ATmega328P matches all boards which are powered by an AVR.

If you're asking for the macro to match boards using the SAMD21G18A microcontroller then you can use SAMD21G18A. If you want any SAMD microcontroller, try SAMD_SERIES.

yes, thank you,
SAMD_SERIES
now finally works also for my Itsybitsy M0 too!