For a lot of libraries, especially most of Adafruit's, it's best to just let the AVR code compile for Teensy3. Something like this:
- Code: Select all
#if defined(__AVR__) || defined(TEENSYDUINO)
Obviously this doesn't work if you get too specific on AVR stuff, but it does work for nearly everything Adafruit publishes. Teensyduino automatically translates commonly used AVR registers like PORTD, DDRD, TWBR, SPSR, SPDR, SREG into equivalent native code. This particular library is a perfect example, where it only depends on the Wire library and TWBR. Your AVR specific code "just works" on Teensy 3.1 and set the I2C to 400 kHz, just by writing to TWBR.
But for more specific code, "#if defined(__MK20DX128__) || defined(__MK20DX256__)" would be technically correct. Generally that's only needed in much lower level libraries, like NeoPixel.
The situation with the robot libraries is really annoying. In fact, I'm about to put a patch in the java code to specifically not check those 2 libraries if a Teensy board is selected. Yup, resorting to such a dirty hack makes me feel a bit icky, but I'm getting really tired of people hitting this problem over and over again.