diff --git a/Boards.h b/Boards.h index 365f5f66..41af1f37 100644 --- a/Boards.h +++ b/Boards.h @@ -9,7 +9,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated November 5th, 2015 + Last updated December 19th, 2015 */ #ifndef Firmata_Boards_h @@ -265,6 +265,26 @@ writePort(port, value, bitmask): Write an 8 bit port. #define PIN_TO_SERVO(p) (p) // deprecated since v2.4 +// Arduino 101 +#elif defined(_VARIANT_ARDUINO_101_X_) +#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS +#define TOTAL_PINS NUM_DIGITAL_PINS // 15 digital (including ATN pin) + 6 analog +#define VERSION_BLINK_PIN LED_BUILTIN +#define PIN_SERIAL1_RX 0 +#define PIN_SERIAL1_TX 1 +#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 20) +#define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS) +#define IS_PIN_PWM(p) digitalPinHasPWM(p) // 3, 5, 6, 9 +#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4 +#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL) // SDA = 18, SCL = 19 +#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK) +#define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1) +#define PIN_TO_DIGITAL(p) (p) +#define PIN_TO_ANALOG(p) ((p) - 14) +#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p) +#define PIN_TO_SERVO(p) (p) // deprecated since v2.4 + + // Teensy 1.0 #elif defined(__AVR_AT90USB162__) #define TOTAL_ANALOG_PINS 0 diff --git a/Firmata.h b/Firmata.h index e89e3ec4..7fe6d63f 100644 --- a/Firmata.h +++ b/Firmata.h @@ -25,6 +25,11 @@ #define MAX_DATA_BYTES 64 // max number of data bytes in incoming messages +// Arduino 101 also defines SET_PIN_MODE as a macro in scss_registers.h +#ifdef SET_PIN_MODE +#undef SET_PIN_MODE +#endif + // message command bytes (128-255/0x80-0xFF) #define DIGITAL_MESSAGE 0x90 // send data for a digital port (collection of 8 pins) #define ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM) diff --git a/examples/StandardFirmata/StandardFirmata.ino b/examples/StandardFirmata/StandardFirmata.ino index 6f94829c..206196de 100755 --- a/examples/StandardFirmata/StandardFirmata.ino +++ b/examples/StandardFirmata/StandardFirmata.ino @@ -743,7 +743,7 @@ void setup() Firmata.begin(57600); while (!Serial) { - ; // wait for serial port to connect. Only needed for ATmega32u4-based boards (Leonardo, etc). + ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101 } systemResetCallback(); // reset to default config } diff --git a/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino b/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino index a296f74a..913a499f 100644 --- a/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino +++ b/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino @@ -20,7 +20,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: December 9th, 2015 + Last updated by Jeff Hoefs: December 19th, 2015 */ /* @@ -59,10 +59,10 @@ #include #include -// SoftwareSerial is only supported for AVR-based boards -// The second condition checks if the IDE is in the 1.0.x series, if so, include SoftwareSerial +// SoftwareSerial is currently only supported for AVR-based boards and the Arduino 101 +// The third condition checks if the IDE is in the 1.0.x series, if so, include SoftwareSerial // since it should be available to all boards in that IDE. -#if defined(ARDUINO_ARCH_AVR) || (ARDUINO >= 100 && ARDUINO < 10500) +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ARC32) || (ARDUINO >= 100 && ARDUINO < 10500) #include #endif #include "utility/serialUtils.h" @@ -859,12 +859,12 @@ void sysexCallback(byte command, byte argc, byte *argv) case SERIAL_CONFIG: { long baud = (long)argv[1] | ((long)argv[2] << 7) | ((long)argv[3] << 14); - byte txPin, rxPin; + byte swTxPin, swRxPin; serial_pins pins; if (portId > 7 && argc > 4) { - rxPin = argv[4]; - txPin = argv[5]; + swRxPin = argv[4]; + swTxPin = argv[5]; } if (portId < 8) { @@ -885,29 +885,29 @@ void sysexCallback(byte command, byte argc, byte *argv) switch (portId) { case SW_SERIAL0: if (swSerial0 == NULL) { - swSerial0 = new SoftwareSerial(rxPin, txPin); + swSerial0 = new SoftwareSerial(swRxPin, swTxPin); } break; case SW_SERIAL1: if (swSerial1 == NULL) { - swSerial1 = new SoftwareSerial(rxPin, txPin); + swSerial1 = new SoftwareSerial(swRxPin, swTxPin); } break; case SW_SERIAL2: if (swSerial2 == NULL) { - swSerial2 = new SoftwareSerial(rxPin, txPin); + swSerial2 = new SoftwareSerial(swRxPin, swTxPin); } break; case SW_SERIAL3: if (swSerial3 == NULL) { - swSerial3 = new SoftwareSerial(rxPin, txPin); + swSerial3 = new SoftwareSerial(swRxPin, swTxPin); } break; } serialPort = getPortFromId(portId); if (serialPort != NULL) { - setPinModeCallback(rxPin, PIN_MODE_SERIAL); - setPinModeCallback(txPin, PIN_MODE_SERIAL); + setPinModeCallback(swRxPin, PIN_MODE_SERIAL); + setPinModeCallback(swTxPin, PIN_MODE_SERIAL); ((SoftwareSerial*)serialPort)->begin(baud); } #endif diff --git a/examples/StandardFirmataPlus/StandardFirmataPlus.ino b/examples/StandardFirmataPlus/StandardFirmataPlus.ino index fddf93fa..167679a8 100644 --- a/examples/StandardFirmataPlus/StandardFirmataPlus.ino +++ b/examples/StandardFirmataPlus/StandardFirmataPlus.ino @@ -20,7 +20,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: December 9th, 2015 + Last updated by Jeff Hoefs: December 19th, 2015 */ /* @@ -45,10 +45,10 @@ #include #include -// SoftwareSerial is only supported for AVR-based boards -// The second condition checks if the IDE is in the 1.0.x series, if so, include SoftwareSerial +// SoftwareSerial is currently only supported for AVR-based boards and the Arduino 101 +// The third condition checks if the IDE is in the 1.0.x series, if so, include SoftwareSerial // since it should be available to all boards in that IDE. -#if defined(ARDUINO_ARCH_AVR) || (ARDUINO >= 100 && ARDUINO < 10500) +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ARC32) || (ARDUINO >= 100 && ARDUINO < 10500) #include #endif #include "utility/serialUtils.h" @@ -795,12 +795,12 @@ void sysexCallback(byte command, byte argc, byte *argv) case SERIAL_CONFIG: { long baud = (long)argv[1] | ((long)argv[2] << 7) | ((long)argv[3] << 14); - byte txPin, rxPin; + byte swTxPin, swRxPin; serial_pins pins; if (portId > 7 && argc > 4) { - rxPin = argv[4]; - txPin = argv[5]; + swRxPin = argv[4]; + swTxPin = argv[5]; } if (portId < 8) { @@ -821,29 +821,29 @@ void sysexCallback(byte command, byte argc, byte *argv) switch (portId) { case SW_SERIAL0: if (swSerial0 == NULL) { - swSerial0 = new SoftwareSerial(rxPin, txPin); + swSerial0 = new SoftwareSerial(swRxPin, swTxPin); } break; case SW_SERIAL1: if (swSerial1 == NULL) { - swSerial1 = new SoftwareSerial(rxPin, txPin); + swSerial1 = new SoftwareSerial(swRxPin, swTxPin); } break; case SW_SERIAL2: if (swSerial2 == NULL) { - swSerial2 = new SoftwareSerial(rxPin, txPin); + swSerial2 = new SoftwareSerial(swRxPin, swTxPin); } break; case SW_SERIAL3: if (swSerial3 == NULL) { - swSerial3 = new SoftwareSerial(rxPin, txPin); + swSerial3 = new SoftwareSerial(swRxPin, swTxPin); } break; } serialPort = getPortFromId(portId); if (serialPort != NULL) { - setPinModeCallback(rxPin, PIN_MODE_SERIAL); - setPinModeCallback(txPin, PIN_MODE_SERIAL); + setPinModeCallback(swRxPin, PIN_MODE_SERIAL); + setPinModeCallback(swTxPin, PIN_MODE_SERIAL); ((SoftwareSerial*)serialPort)->begin(baud); } #endif @@ -1051,7 +1051,7 @@ void setup() Firmata.begin(57600); while (!Serial) { - ; // wait for serial port to connect. Only needed for ATmega32u4-based boards (Leonardo, etc). + ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101 } systemResetCallback(); // reset to default config }