adafruit / ArduinoCore-samd

115 stars 119 forks source link

how to detect adafruit boards at compile time? #305

Closed 2bndy5 closed 3 years ago

2bndy5 commented 3 years ago

I need a way to detect if the SAMD core being used is from this fork (not the arduino/ArduinoCore-samd repo). The reason for this demand is because our library makes use of the Serial.printf() in this fork, however it is not present in the arduino/ArduinoUnified-API repo (as used by the arduino/ArduinoCore-samd repo).

Initially by using

            #if defined (ARDUINO_ARCH_SAMD) && !defined (ARDUINO_API_VERSION)
                // likely using the adafruit/ArduinoCore-samd repo
                #define printf_P Serial.printf
            #endif // defined (ARDUINO_ARCH_SAMD)

I thought that I could single out any board supported by this fork, but I'm now getting a user report that would indicate that it also gets triggered for the Arduino MKR WIFI 1010 board (which doesn't have Serial.printf()). I know I could just do a defined (ADAFRUIT_FEATHER_M0) but I don't want to do this for the 30 or so boards this fork supports. Is there a better way?

hathach commented 3 years ago

yeah, there is no explicit way to detect if the board is using this fork vs arduino one. Maybe we could add macro ARDUINO_SAMD_ADAFRUIT to the compile flag similar to what we did with nrf52. @ladyada do you have any better name or suggestion.

ladyada commented 3 years ago

woops sorry didnt see that you want all adafruit boards @2bdny want to add a global #define to our boards.txt?

2bndy5 commented 3 years ago

Yes please. That would be most convenient and future proof.

ladyada commented 3 years ago

@2bndy5 ok please try it out and make a PR!