diff options
-rw-r--r-- | cores/arduino/CDC.cpp | 43 | ||||
-rw-r--r-- | cores/arduino/USBCore.cpp | 13 | ||||
-rw-r--r-- | cores/arduino/USBCore.h | 17 | ||||
-rw-r--r-- | cores/arduino/WString.cpp | 2 | ||||
-rw-r--r-- | cores/arduino/WString.h | 18 | ||||
-rw-r--r-- | libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino | 10 | ||||
-rw-r--r-- | libraries/SoftwareSerial/src/SoftwareSerial.cpp | 4 | ||||
-rw-r--r-- | libraries/SoftwareSerial/src/SoftwareSerial.h | 2 | ||||
-rw-r--r-- | libraries/Wire/src/utility/twi.c | 6 | ||||
-rw-r--r-- | platform.txt | 11 | ||||
-rw-r--r-- | variants/ethernet/pins_arduino.h | 46 | ||||
-rw-r--r-- | variants/gemma/pins_arduino.h | 13 | ||||
-rw-r--r-- | variants/leonardo/pins_arduino.h | 58 | ||||
-rw-r--r-- | variants/mega/pins_arduino.h | 70 | ||||
-rw-r--r-- | variants/robot_control/pins_arduino.h | 65 | ||||
-rw-r--r-- | variants/robot_motor/pins_arduino.h | 65 | ||||
-rw-r--r-- | variants/standard/pins_arduino.h | 46 |
17 files changed, 339 insertions, 150 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp index f19b44c..0a743e1 100644 --- a/cores/arduino/CDC.cpp +++ b/cores/arduino/CDC.cpp @@ -34,6 +34,8 @@ typedef struct static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 }; static volatile int32_t breakValue = -1; +bool _updatedLUFAbootloader = false; + #define WEAK __attribute__ ((weak)) extern const CDCDescriptor _cdcInterface PROGMEM; @@ -99,24 +101,32 @@ bool CDC_Setup(USBSetup& setup) // with a relatively long period so it can finish housekeeping tasks // like servicing endpoints before the sketch ends -#ifndef MAGIC_KEY -#define MAGIC_KEY 0x7777 -#endif -#ifndef MAGIC_KEY_POS -#define MAGIC_KEY_POS 0x0800 + uint16_t magic_key_pos = MAGIC_KEY_POS; + +// If we don't use the new RAMEND directly, check manually if we have a newer bootloader. +// This is used to keep compatible with the old leonardo bootloaders. +// You are still able to set the magic key position manually to RAMEND-1 to save a few bytes for this check. +#if MAGIC_KEY_POS != (RAMEND-1) + // For future boards save the key in the inproblematic RAMEND + // Which is reserved for the main() return value (which will never return) + if (_updatedLUFAbootloader) { + // horray, we got a new bootloader! + magic_key_pos = (RAMEND-1); + } #endif // We check DTR state to determine if host port is open (bit 0 of lineState). if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0) { #if MAGIC_KEY_POS != (RAMEND-1) - *(uint16_t *)(RAMEND-1) = *(uint16_t *)MAGIC_KEY_POS; - *(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY; -#else - // for future boards save the key in the inproblematic RAMEND - // which is reserved for the main() return value (which will never return) - *(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY; + // Backup ram value if its not a newer bootloader. + // This should avoid memory corruption at least a bit, not fully + if (magic_key_pos != (RAMEND-1)) { + *(uint16_t *)(RAMEND-1) = *(uint16_t *)magic_key_pos; + } #endif + // Store boot key + *(uint16_t *)magic_key_pos = MAGIC_KEY; wdt_enable(WDTO_120MS); } else @@ -129,10 +139,15 @@ bool CDC_Setup(USBSetup& setup) wdt_disable(); wdt_reset(); #if MAGIC_KEY_POS != (RAMEND-1) - *(uint16_t *)MAGIC_KEY_POS = *(uint16_t *)(RAMEND-1); -#else - *(uint16_t *)MAGIC_KEY_POS = 0x0000; + // Restore backed up (old bootloader) magic key data + if (magic_key_pos != (RAMEND-1)) { + *(uint16_t *)magic_key_pos = *(uint16_t *)(RAMEND-1); + } else #endif + { + // Clean up RAMEND key + *(uint16_t *)magic_key_pos = 0x0000; + } } } return true; diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 62b90ed..6c8ae63 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -35,6 +35,7 @@ extern const u8 STRING_PRODUCT[] PROGMEM; extern const u8 STRING_MANUFACTURER[] PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptorB PROGMEM; +extern bool _updatedLUFAbootloader; const u16 STRING_LANGUAGE[2] = { (3<<8) | (2+2), @@ -254,7 +255,9 @@ u8 USB_SendSpace(u8 ep) LockEP lock(ep); if (!ReadWriteAllowed()) return 0; - return USB_EP_SIZE - FifoByteCount(); + // subtract 1 from the EP size to never send a full packet, + // this avoids dealing with ZLP's in USB_Send + return USB_EP_SIZE - 1 - FifoByteCount(); } // Blocking Send of data to an endpoint @@ -730,7 +733,7 @@ static inline void USB_ClockEnable() ISR(USB_GEN_vect) { u8 udint = UDINT; - UDINT = UDINT &= ~((1<<EORSTI) | (1<<SOFI)); // clear the IRQ flags for the IRQs which are handled here, except WAKEUPI and SUSPI (see below) + UDINT &= ~((1<<EORSTI) | (1<<SOFI)); // clear the IRQ flags for the IRQs which are handled here, except WAKEUPI and SUSPI (see below) // End of Reset if (udint & (1<<EORSTI)) @@ -806,6 +809,12 @@ void USBDevice_::attach() UDIEN = (1<<EORSTE) | (1<<SOFE) | (1<<SUSPE); // Enable interrupts for EOR (End of Reset), SOF (start of frame) and SUSPEND TX_RX_LED_INIT; + +#if MAGIC_KEY_POS != (RAMEND-1) + if (pgm_read_word(FLASHEND - 1) == NEW_LUFA_SIGNATURE) { + _updatedLUFAbootloader = true; + } +#endif } void USBDevice_::detach() diff --git a/cores/arduino/USBCore.h b/cores/arduino/USBCore.h index 4e08d71..66f3b5b 100644 --- a/cores/arduino/USBCore.h +++ b/cores/arduino/USBCore.h @@ -277,5 +277,22 @@ typedef struct #define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 } #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } +// Bootloader related fields +// Old Caterina bootloader places the MAGIC key into unsafe RAM locations (it can be rewritten +// by the running sketch before to actual reboot). +// Newer bootloaders, recognizable by the LUFA "signature" at the end of the flash, can handle both +// the usafe and the safe location. Check once (in USBCore.cpp) if the bootloader in new, then set the global +// _updatedLUFAbootloader variable to true/false and place the magic key consequently +#ifndef MAGIC_KEY +#define MAGIC_KEY 0x7777 +#endif + +#ifndef MAGIC_KEY_POS +#define MAGIC_KEY_POS 0x0800 +#endif + +#ifndef NEW_LUFA_SIGNATURE +#define NEW_LUFA_SIGNATURE 0xDCFB +#endif #endif diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index cd3e0e8..9975303 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -193,7 +193,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) void String::move(String &rhs) { if (buffer) { - if (capacity >= rhs.len) { + if (rhs && capacity >= rhs.len) { strcpy(buffer, rhs.buffer); len = rhs.len; rhs.len = 0; diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index b047980..de5632c 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -81,7 +81,7 @@ public: inline unsigned int length(void) const {return len;} // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be + // invalid, or if the memory allocation fails, the string will be // marked as invalid ("if (s)" will be false). String & operator = (const String &rhs); String & operator = (const char *cstr); @@ -92,10 +92,10 @@ public: #endif // concatenate (works w/ built-in types) - + // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsucessful. + // is left unchanged). if the argument is null or invalid, the + // concatenation is considered unsucessful. unsigned char concat(const String &str); unsigned char concat(const char *cstr); unsigned char concat(char c); @@ -107,7 +107,7 @@ public: unsigned char concat(float num); unsigned char concat(double num); unsigned char concat(const __FlashStringHelper * str); - + // if there's not enough memory for the concatenated value, the string // will be left unchanged (but this isn't signalled in any way) String & operator += (const String &rhs) {concat(rhs); return (*this);} @@ -159,8 +159,12 @@ public: char& operator [] (unsigned int index); void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - {getBytes((unsigned char *)buf, bufsize, index);} - const char * c_str() const { return buffer; } + { getBytes((unsigned char *)buf, bufsize, index); } + const char* c_str() const { return buffer; } + char* begin() { return buffer; } + char* end() { return buffer + length(); } + const char* begin() const { return c_str(); } + const char* end() const { return c_str() + length(); } // search int indexOf( char ch ) const; diff --git a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index 26659d6..8d7f93e 100644 --- a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -13,8 +13,8 @@ The circuit: Two devices which communicate serially are needed. - * First serial device's TX attached to digital pin 2, RX to pin 3 - * Second serial device's TX attached to digital pin 4, RX to pin 5 + * First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX) + * Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX) Note: Not all pins on the Mega and Mega 2560 support change interrupts, @@ -26,7 +26,7 @@ 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). created 18 Apr. 2011 - modified 25 May 2012 + modified 19 March 2016 by Tom Igoe based on Mikal Hart's twoPortRXExample @@ -35,10 +35,10 @@ */ #include <SoftwareSerial.h> -// software serial #1: TX = digital pin 10, RX = digital pin 11 +// software serial #1: RX = digital pin 10, TX = digital pin 11 SoftwareSerial portOne(10, 11); -// software serial #2: TX = digital pin 8, RX = digital pin 9 +// software serial #2: RX = digital pin 8, TX = digital pin 9 // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega SoftwareSerial portTwo(8, 9); diff --git a/libraries/SoftwareSerial/src/SoftwareSerial.cpp b/libraries/SoftwareSerial/src/SoftwareSerial.cpp index 0a16ff7..474fe4a 100644 --- a/libraries/SoftwareSerial/src/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/src/SoftwareSerial.cpp @@ -48,7 +48,7 @@ http://arduiniana.org. // Statics
//
SoftwareSerial *SoftwareSerial::active_object = 0;
-char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
+uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0;
volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
@@ -270,7 +270,7 @@ void SoftwareSerial::setTX(uint8_t tx) {
// First write, then set output. If we do this the other way around,
// the pin would be output low for a short while before switching to
- // output hihg. Now, it is input with pullup for a short while, which
+ // output high. Now, it is input with pullup for a short while, which
// is fine. With inverse logic, either order is fine.
digitalWrite(tx, _inverse_logic ? LOW : HIGH);
pinMode(tx, OUTPUT);
diff --git a/libraries/SoftwareSerial/src/SoftwareSerial.h b/libraries/SoftwareSerial/src/SoftwareSerial.h index 622e2a5..26183ba 100644 --- a/libraries/SoftwareSerial/src/SoftwareSerial.h +++ b/libraries/SoftwareSerial/src/SoftwareSerial.h @@ -66,7 +66,7 @@ private: uint16_t _inverse_logic:1;
// static data
- static char _receive_buffer[_SS_MAX_RX_BUFF];
+ static uint8_t _receive_buffer[_SS_MAX_RX_BUFF];
static volatile uint8_t _receive_buffer_tail;
static volatile uint8_t _receive_buffer_head;
static SoftwareSerial *active_object;
diff --git a/libraries/Wire/src/utility/twi.c b/libraries/Wire/src/utility/twi.c index f5d7d5b..171af73 100644 --- a/libraries/Wire/src/utility/twi.c +++ b/libraries/Wire/src/utility/twi.c @@ -304,7 +304,7 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length) uint8_t i; // ensure data will fit into buffer - if(TWI_BUFFER_LENGTH < length){ + if(TWI_BUFFER_LENGTH < (twi_txBufferLength+length)){ return 1; } @@ -314,10 +314,10 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length) } // set length and copy data into tx buffer - twi_txBufferLength = length; for(i = 0; i < length; ++i){ - twi_txBuffer[i] = data[i]; + twi_txBuffer[twi_txBufferLength+i] = data[i]; } + twi_txBufferLength += length; return 0; } diff --git a/platform.txt b/platform.txt index 0e8bc54..50778f1 100644 --- a/platform.txt +++ b/platform.txt @@ -6,7 +6,7 @@ # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification name=Arduino AVR Boards -version=1.6.10 +version=1.6.11 # AVR compile variables # --------------------- @@ -60,6 +60,8 @@ recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -m recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Create archives +# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value +archive_file_path={build.path}/{archive_file} recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" ## Combine gc-sections, archives, and objects @@ -95,11 +97,13 @@ tools.avrdude.config.path={path}/etc/avrdude.conf tools.avrdude.upload.params.verbose=-v tools.avrdude.upload.params.quiet=-q -q -tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" +tools.avrdude.upload.params.noverify=-V +tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} {upload.verify} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" tools.avrdude.program.params.verbose=-v tools.avrdude.program.params.quiet=-q -q -tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" +tools.avrdude.program.params.noverify=-V +tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" tools.avrdude.erase.params.verbose=-v tools.avrdude.erase.params.quiet=-q -q @@ -109,6 +113,7 @@ tools.avrdude.bootloader.params.verbose=-v tools.avrdude.bootloader.params.quiet=-q -q tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m +tools.avrdude_remote.upload.pattern=/usr/bin/run-avrdude /tmp/sketch.hex {upload.verbose} -p{build.mcu} # USB Default Flags # Default blank usb manufacturer will be filled in at compile time diff --git a/variants/ethernet/pins_arduino.h b/variants/ethernet/pins_arduino.h index a11ecfc..77fcc40 100644 --- a/variants/ethernet/pins_arduino.h +++ b/variants/ethernet/pins_arduino.h @@ -35,23 +35,41 @@ #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11) #endif -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 12; -static const uint8_t SCK = 13; +#define PIN_SPI_SS (10) +#define PIN_SPI_MOSI (11) +#define PIN_SPI_MISO (12) +#define PIN_SPI_SCK (13) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +#define PIN_WIRE_SDA (18) +#define PIN_WIRE_SCL (19) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; -static const uint8_t SDA = 18; -static const uint8_t SCL = 19; #define LED_BUILTIN 9 -static const uint8_t A0 = 14; -static const uint8_t A1 = 15; -static const uint8_t A2 = 16; -static const uint8_t A3 = 17; -static const uint8_t A4 = 18; -static const uint8_t A5 = 19; -static const uint8_t A6 = 20; -static const uint8_t A7 = 21; +#define PIN_A0 (14) +#define PIN_A1 (15) +#define PIN_A2 (16) +#define PIN_A3 (17) +#define PIN_A4 (18) +#define PIN_A5 (19) +#define PIN_A6 (20) +#define PIN_A7 (21) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0)) #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1)) diff --git a/variants/gemma/pins_arduino.h b/variants/gemma/pins_arduino.h index b6aed39..e0ec217 100644 --- a/variants/gemma/pins_arduino.h +++ b/variants/gemma/pins_arduino.h @@ -46,10 +46,15 @@ #define NUM_ANALOG_INPUTS 1 #define LED_BUILTIN 1 -static const uint8_t A0 = 6; -static const uint8_t A1 = 7; -static const uint8_t A2 = 8; -static const uint8_t A3 = 9; +#define PIN_A0 (6) +#define PIN_A1 (7) +#define PIN_A2 (8) +#define PIN_A3 (9) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; #define digitalPinToPCICR(p) ( ((p) >= 0 && (p) <= 4) ? (&GIMSK) : ((uint8_t *)0) ) #define digitalPinToPCICRbit(p) ( PCIE ) diff --git a/variants/leonardo/pins_arduino.h b/variants/leonardo/pins_arduino.h index 6027223..8586dac 100644 --- a/variants/leonardo/pins_arduino.h +++ b/variants/leonardo/pins_arduino.h @@ -97,32 +97,54 @@ #define RXLED0 PORTB |= (1<<0) #define RXLED1 PORTB &= ~(1<<0) -static const uint8_t SDA = 2; -static const uint8_t SCL = 3; +#define PIN_WIRE_SDA (2) +#define PIN_WIRE_SCL (3) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + #define LED_BUILTIN 13 #define LED_BUILTIN_RX 17 #define LED_BUILTIN_TX 30 // Map SPI port to 'new' pins D14..D17 -static const uint8_t SS = 17; -static const uint8_t MOSI = 16; -static const uint8_t MISO = 14; -static const uint8_t SCK = 15; +#define PIN_SPI_SS (17) +#define PIN_SPI_MOSI (16) +#define PIN_SPI_MISO (14) +#define PIN_SPI_SCK (15) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; // Mapping of analog pins as digital I/O // A6-A11 share with digital pins -static const uint8_t A0 = 18; -static const uint8_t A1 = 19; -static const uint8_t A2 = 20; -static const uint8_t A3 = 21; -static const uint8_t A4 = 22; -static const uint8_t A5 = 23; -static const uint8_t A6 = 24; // D4 -static const uint8_t A7 = 25; // D6 -static const uint8_t A8 = 26; // D8 -static const uint8_t A9 = 27; // D9 -static const uint8_t A10 = 28; // D10 -static const uint8_t A11 = 29; // D12 +#define PIN_A0 (18) +#define PIN_A1 (19) +#define PIN_A2 (20) +#define PIN_A3 (21) +#define PIN_A4 (22) +#define PIN_A5 (23) +#define PIN_A6 (24) +#define PIN_A7 (25) +#define PIN_A8 (26) +#define PIN_A9 (27) +#define PIN_A10 (28) +#define PIN_A11 (29) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; // D4 +static const uint8_t A7 = PIN_A7; // D6 +static const uint8_t A8 = PIN_A8; // D8 +static const uint8_t A9 = PIN_A9; // D9 +static const uint8_t A10 = PIN_A10; // D10 +static const uint8_t A11 = PIN_A11; // D12 #define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0)) #define digitalPinToPCICRbit(p) 0 diff --git a/variants/mega/pins_arduino.h b/variants/mega/pins_arduino.h index 7d330fa..5115c04 100644 --- a/variants/mega/pins_arduino.h +++ b/variants/mega/pins_arduino.h @@ -30,31 +30,57 @@ #define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1) #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46)) -static const uint8_t SS = 53; -static const uint8_t MOSI = 51; -static const uint8_t MISO = 50; -static const uint8_t SCK = 52; +#define PIN_SPI_SS (53) +#define PIN_SPI_MOSI (51) +#define PIN_SPI_MISO (50) +#define PIN_SPI_SCK (52) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +#define PIN_WIRE_SDA (20) +#define PIN_WIRE_SCL (21) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; -static const uint8_t SDA = 20; -static const uint8_t SCL = 21; #define LED_BUILTIN 13 -static const uint8_t A0 = 54; -static const uint8_t A1 = 55; -static const uint8_t A2 = 56; -static const uint8_t A3 = 57; -static const uint8_t A4 = 58; -static const uint8_t A5 = 59; -static const uint8_t A6 = 60; -static const uint8_t A7 = 61; -static const uint8_t A8 = 62; -static const uint8_t A9 = 63; -static const uint8_t A10 = 64; -static const uint8_t A11 = 65; -static const uint8_t A12 = 66; -static const uint8_t A13 = 67; -static const uint8_t A14 = 68; -static const uint8_t A15 = 69; +#define PIN_A0 (54) +#define PIN_A1 (55) +#define PIN_A2 (56) +#define PIN_A3 (57) +#define PIN_A4 (58) +#define PIN_A5 (59) +#define PIN_A6 (60) +#define PIN_A7 (61) +#define PIN_A8 (62) +#define PIN_A9 (63) +#define PIN_A10 (64) +#define PIN_A11 (65) +#define PIN_A12 (66) +#define PIN_A13 (67) +#define PIN_A14 (68) +#define PIN_A15 (69) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; +static const uint8_t A8 = PIN_A8; +static const uint8_t A9 = PIN_A9; +static const uint8_t A10 = PIN_A10; +static const uint8_t A11 = PIN_A11; +static const uint8_t A12 = PIN_A12; +static const uint8_t A13 = PIN_A13; +static const uint8_t A14 = PIN_A14; +static const uint8_t A15 = PIN_A15; // A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins) // Only pins available for RECEIVE (TRANSMIT can be on any pin): diff --git a/variants/robot_control/pins_arduino.h b/variants/robot_control/pins_arduino.h index 41aedea..3e36103 100644 --- a/variants/robot_control/pins_arduino.h +++ b/variants/robot_control/pins_arduino.h @@ -41,31 +41,56 @@ #define D4 TKD4 #define D5 TKD5 -static const uint8_t RX = 0; -static const uint8_t TX = 1; -static const uint8_t SDA = 2; -static const uint8_t SCL = 3; +#define PIN_SERIAL_RX (0) +#define PIN_SERIAL_TX (1) + +static const uint8_t RX = PIN_SERIAL_RX; +static const uint8_t TX = PIN_SERIAL_TX; + +#define PIN_WIRE_SDA (2) +#define PIN_WIRE_SCL (3) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; // Map SPI port to 'new' pins D14..D17 -static const uint8_t SS = 17; -static const uint8_t MOSI = 16; -static const uint8_t MISO = 14; -static const uint8_t SCK = 15; +#define PIN_SPI_SS (17) +#define PIN_SPI_MOSI (16) +#define PIN_SPI_MISO (14) +#define PIN_SPI_SCK (15) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; // Mapping of analog pins as digital I/O // A6-A11 share with digital pins -static const uint8_t A0 = 18; -static const uint8_t A1 = 19; -static const uint8_t A2 = 20; -static const uint8_t A3 = 21; -static const uint8_t A4 = 22; -static const uint8_t A5 = 23; -static const uint8_t A6 = 24; // D4 -static const uint8_t A7 = 25; // D6 -static const uint8_t A8 = 26; // D8 -static const uint8_t A9 = 27; // D9 -static const uint8_t A10 = 28; // D10 -static const uint8_t A11 = 29; // D12 +#define PIN_A0 (18) +#define PIN_A1 (19) +#define PIN_A2 (20) +#define PIN_A3 (21) +#define PIN_A4 (22) +#define PIN_A5 (23) +#define PIN_A6 (24) +#define PIN_A7 (25) +#define PIN_A8 (26) +#define PIN_A9 (27) +#define PIN_A10 (28) +#define PIN_A11 (29) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; // D4 +static const uint8_t A7 = PIN_A7; // D6 +static const uint8_t A8 = PIN_A8; // D8 +static const uint8_t A9 = PIN_A9; // D9 +static const uint8_t A10 = PIN_A10; // D10 +static const uint8_t A11 = PIN_A11; // D12 // Specific Mapping for the Control Board static const uint8_t KEY = 18; // AD0 diff --git a/variants/robot_motor/pins_arduino.h b/variants/robot_motor/pins_arduino.h index 7a943d8..2686b69 100644 --- a/variants/robot_motor/pins_arduino.h +++ b/variants/robot_motor/pins_arduino.h @@ -39,31 +39,56 @@ #define D8 TK4 #define D7 TK3 -static const uint8_t RX = 0; -static const uint8_t TX = 1; -static const uint8_t SDA = 2; -static const uint8_t SCL = 3; +#define PIN_SERIAL_RX (0) +#define PIN_SERIAL_TX (1) + +static const uint8_t RX = PIN_SERIAL_RX; +static const uint8_t TX = PIN_SERIAL_TX; + +#define PIN_WIRE_SDA (2) +#define PIN_WIRE_SCL (3) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; // Map SPI port to 'new' pins D14..D17 -static const uint8_t SS = 17; -static const uint8_t MOSI = 16; -static const uint8_t MISO = 14; -static const uint8_t SCK = 15; +#define PIN_SPI_SS (17) +#define PIN_SPI_MOSI (16) +#define PIN_SPI_MISO (14) +#define PIN_SPI_SCK (15) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; // Mapping of analog pins as digital I/O // A6-A11 share with digital pins -static const uint8_t A0 = 18; -static const uint8_t A1 = 19; -static const uint8_t A2 = 20; -static const uint8_t A3 = 21; -static const uint8_t A4 = 22; -static const uint8_t A5 = 23; -static const uint8_t A6 = 24; // D4 -static const uint8_t A7 = 25; // D6 -static const uint8_t A8 = 26; // D8 -static const uint8_t A9 = 27; // D9 -static const uint8_t A10 = 28; // D10 -static const uint8_t A11 = 29; // D12 +#define PIN_A0 (18) +#define PIN_A1 (19) +#define PIN_A2 (20) +#define PIN_A3 (21) +#define PIN_A4 (22) +#define PIN_A5 (23) +#define PIN_A6 (24) +#define PIN_A7 (25) +#define PIN_A8 (26) +#define PIN_A9 (27) +#define PIN_A10 (28) +#define PIN_A11 (29) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; // D4 +static const uint8_t A7 = PIN_A7; // D6 +static const uint8_t A8 = PIN_A8; // D8 +static const uint8_t A9 = PIN_A9; // D9 +static const uint8_t A10 = PIN_A10; // D10 +static const uint8_t A11 = PIN_A11; // D12 // Specific Mapping for the Motor Board static const uint8_t MUX_IN = 20; // A2 diff --git a/variants/standard/pins_arduino.h b/variants/standard/pins_arduino.h index a3f349e..2ea0190 100644 --- a/variants/standard/pins_arduino.h +++ b/variants/standard/pins_arduino.h @@ -35,23 +35,41 @@ #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11) #endif -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 12; -static const uint8_t SCK = 13; +#define PIN_SPI_SS (10) +#define PIN_SPI_MOSI (11) +#define PIN_SPI_MISO (12) +#define PIN_SPI_SCK (13) + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +#define PIN_WIRE_SDA (18) +#define PIN_WIRE_SCL (19) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; -static const uint8_t SDA = 18; -static const uint8_t SCL = 19; #define LED_BUILTIN 13 -static const uint8_t A0 = 14; -static const uint8_t A1 = 15; -static const uint8_t A2 = 16; -static const uint8_t A3 = 17; -static const uint8_t A4 = 18; -static const uint8_t A5 = 19; -static const uint8_t A6 = 20; -static const uint8_t A7 = 21; +#define PIN_A0 (14) +#define PIN_A1 (15) +#define PIN_A2 (16) +#define PIN_A3 (17) +#define PIN_A4 (18) +#define PIN_A5 (19) +#define PIN_A6 (20) +#define PIN_A7 (21) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0)) #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1)) |