diff --git a/.travis.yml b/.travis.yml index 51c18e1..84192a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - pip install -U platformio - platformio update script: -- platformio run -e $PLATOFORMIO_ENVIRONMENT +- platformio run --verbose --environment $PLATOFORMIO_ENVIRONMENT - mv .pio/build/${PLATOFORMIO_ENVIRONMENT}/firmware.elf teensytoany-${PLATOFORMIO_ENVIRONMENT}.elf - mv .pio/build/${PLATOFORMIO_ENVIRONMENT}/firmware.hex teensytoany-${PLATOFORMIO_ENVIRONMENT}.hex - cp teensytoany-${PLATOFORMIO_ENVIRONMENT}.elf teensytoany-${PLATOFORMIO_ENVIRONMENT}-${TRAVIS_BRANCH}.elf diff --git a/src/i2c.cpp b/src/i2c.cpp index 76c2d71..5a5d4e9 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -1,7 +1,6 @@ #include "i2c.hpp" #include -// Teensy 3.0 -#if defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK) +#if TEENSY_TO_ANY_HAS_I2C #include int I2CMaster::init(int baudrate, int timeout_ms, int address_size, int address_msb_first) { diff --git a/src/i2c.hpp b/src/i2c.hpp index 15e50c8..9ea91aa 100644 --- a/src/i2c.hpp +++ b/src/i2c.hpp @@ -1,6 +1,17 @@ #pragma once -#if defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK) -#define HAS_I2C 1 +// only support teensies 3.1, 3.2, 3.5, and 3.6 +// See list of microcontroller units +// https://docs.platformio.org/en/latest/platforms/teensy.html +#if defined(TEENSYDUINO) && \ + (defined(__MK20DX256__) || defined(__MK64FX512__) || \ + defined(__MK66FX1M0__)) +#define TEENSY_TO_ANY_HAS_I2C 1 +#else +#define TEENSY_TO_ANY_HAS_I2C 0 +#warning I2C library not available for this build. +#endif + +#if TEENSY_TO_ANY_HAS_I2C #include class I2CMaster { @@ -22,6 +33,4 @@ class I2CMaster { bool is_initialized = false; bool slave_8bit_address = true; }; -#else -#define HAS_I2C 0 #endif diff --git a/src/main.cpp b/src/main.cpp index 7a73a4c..a9969f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,7 @@ inline SPISettings my_spi_settings() { return SPISettings(spi_baudrate, spi_bit_order, spi_data_mode); } -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C I2CMaster i2c; #endif @@ -71,7 +71,7 @@ int version_func(CommandRouter *cmd, int argc, const char **argv) { } int i2c_init(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C int baudrate = 100'000; int timeout_ms = 200'000; // 200ms int address_size = 2; @@ -96,7 +96,7 @@ int i2c_init(CommandRouter *cmd, int argc, const char **argv) { } int i2c_reset(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C return i2c.reset(); #else return -1; @@ -104,7 +104,7 @@ int i2c_reset(CommandRouter *cmd, int argc, const char **argv) { } int i2c_write_uint16(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C if (argc != 4) return EINVAL; @@ -118,7 +118,7 @@ int i2c_write_uint16(CommandRouter *cmd, int argc, const char **argv) { } int i2c_write_uint8(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C if (argc != 4) return EINVAL; @@ -133,7 +133,7 @@ int i2c_write_uint8(CommandRouter *cmd, int argc, const char **argv) { } int i2c_read_uint16(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C if (argc != 3) return EINVAL; @@ -153,7 +153,7 @@ int i2c_read_uint16(CommandRouter *cmd, int argc, const char **argv) { } int i2c_read_uint8(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C if (argc != 3) return EINVAL; @@ -173,7 +173,7 @@ int i2c_read_uint8(CommandRouter *cmd, int argc, const char **argv) { int i2c_read_no_register_uint8(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C if (argc != 2) return EINVAL; @@ -193,7 +193,7 @@ int i2c_read_no_register_uint8(CommandRouter *cmd, int argc, int i2c_write_no_register_uint8(CommandRouter *cmd, int argc, const char **argv) { -#if HAS_I2C +#if TEENSY_TO_ANY_HAS_I2C if (argc != 3) return EINVAL;