From 3f429a9c61ae953d24f3d19ff1f6d9b332d29b9c Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 2 Jan 2012 12:38:23 -0500 Subject: [PATCH 01/10] Fixing static is not at beginning of declaration warnings (maniacbug). --- cores/arduino/WInterrupts.c | 2 +- variants/leonardo/pins_arduino.h | 36 ++++++++++++------------- variants/mega/pins_arduino.h | 46 ++++++++++++++++---------------- variants/standard/pins_arduino.h | 32 +++++++++++----------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index 1449cfb..4f035eb 100755 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -32,7 +32,7 @@ #include "wiring_private.h" -volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; +static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; // volatile static voidFuncPtr twiIntFunc; void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { diff --git a/variants/leonardo/pins_arduino.h b/variants/leonardo/pins_arduino.h index 15afb4e..5a15146 100644 --- a/variants/leonardo/pins_arduino.h +++ b/variants/leonardo/pins_arduino.h @@ -35,29 +35,29 @@ #define RXLED0 PORTB |= (1<<0) #define RXLED1 PORTB &= ~(1<<0) -const static uint8_t SDA = 2; -const static uint8_t SCL = 3; +static const uint8_t SDA = 2; +static const uint8_t SCL = 3; // Map SPI port to 'new' pins D14..D17 -const static uint8_t SS = 17; -const static uint8_t MOSI = 16; -const static uint8_t MISO = 14; -const static uint8_t SCK = 15; +static const uint8_t SS = 17; +static const uint8_t MOSI = 16; +static const uint8_t MISO = 14; +static const uint8_t SCK = 15; // Mapping of analog pins as digital I/O // A6-A11 share with digital pins -const static uint8_t A0 = 18; -const static uint8_t A1 = 19; -const static uint8_t A2 = 20; -const static uint8_t A3 = 21; -const static uint8_t A4 = 22; -const static uint8_t A5 = 23; -const static uint8_t A6 = 24; // D4 -const static uint8_t A7 = 25; // D6 -const static uint8_t A8 = 26; // D8 -const static uint8_t A9 = 27; // D9 -const static uint8_t A10 = 28; // D10 -const static uint8_t A11 = 29; // D12 +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 // __AVR_ATmega32U4__ has an unusual mapping of pins to channels extern const uint8_t PROGMEM analog_pin_to_channel_PGM[]; diff --git a/variants/mega/pins_arduino.h b/variants/mega/pins_arduino.h index 57ec97f..5a9b4cb 100644 --- a/variants/mega/pins_arduino.h +++ b/variants/mega/pins_arduino.h @@ -32,31 +32,31 @@ #define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1) #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46)) -const static uint8_t SS = 53; -const static uint8_t MOSI = 51; -const static uint8_t MISO = 50; -const static uint8_t SCK = 52; +static const uint8_t SS = 53; +static const uint8_t MOSI = 51; +static const uint8_t MISO = 50; +static const uint8_t SCK = 52; -const static uint8_t SDA = 20; -const static uint8_t SCL = 21; -const static uint8_t LED_BUILTIN = 13; +static const uint8_t SDA = 20; +static const uint8_t SCL = 21; +static const uint8_t LED_BUILTIN = 13; -const static uint8_t A0 = 54; -const static uint8_t A1 = 55; -const static uint8_t A2 = 56; -const static uint8_t A3 = 57; -const static uint8_t A4 = 58; -const static uint8_t A5 = 59; -const static uint8_t A6 = 60; -const static uint8_t A7 = 61; -const static uint8_t A8 = 62; -const static uint8_t A9 = 63; -const static uint8_t A10 = 64; -const static uint8_t A11 = 65; -const static uint8_t A12 = 66; -const static uint8_t A13 = 67; -const static uint8_t A14 = 68; -const static uint8_t A15 = 69; +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; // 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/standard/pins_arduino.h b/variants/standard/pins_arduino.h index 6e774d4..30b4266 100644 --- a/variants/standard/pins_arduino.h +++ b/variants/standard/pins_arduino.h @@ -37,23 +37,23 @@ #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11) #endif -const static uint8_t SS = 10; -const static uint8_t MOSI = 11; -const static uint8_t MISO = 12; -const static uint8_t SCK = 13; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 12; +static const uint8_t SCK = 13; -const static uint8_t SDA = 18; -const static uint8_t SCL = 19; -const static uint8_t LED_BUILTIN = 13; +static const uint8_t SDA = 18; +static const uint8_t SCL = 19; +static const uint8_t LED_BUILTIN = 13; -const static uint8_t A0 = 14; -const static uint8_t A1 = 15; -const static uint8_t A2 = 16; -const static uint8_t A3 = 17; -const static uint8_t A4 = 18; -const static uint8_t A5 = 19; -const static uint8_t A6 = 20; -const static uint8_t A7 = 21; +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 digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0)) #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1)) @@ -215,4 +215,4 @@ const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { #endif -#endif \ No newline at end of file +#endif From 95b51c7728619fb9a718e15d13d99cb371905ad9 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 2 Jan 2012 12:57:23 -0500 Subject: [PATCH 02/10] Fixing warnings (unsigned comparisons to 0). (maniacbug) --- cores/arduino/WString.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 3e81331..c6839fc 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -500,7 +500,7 @@ int String::lastIndexOf( char theChar ) const int String::lastIndexOf(char ch, unsigned int fromIndex) const { - if (fromIndex >= len || fromIndex < 0) return -1; + if (fromIndex >= len) return -1; char tempchar = buffer[fromIndex + 1]; buffer[fromIndex + 1] = '\0'; char* temp = strrchr( buffer, ch ); @@ -516,7 +516,7 @@ int String::lastIndexOf(const String &s2) const int String::lastIndexOf(const String &s2, unsigned int fromIndex) const { - if (s2.len == 0 || len == 0 || s2.len > len || fromIndex < 0) return -1; + if (s2.len == 0 || len == 0 || s2.len > len) return -1; if (fromIndex >= len) fromIndex = len - 1; int found = -1; for (char *p = buffer; p <= buffer + fromIndex; p++) { From 3b962be2730265dd27220b801fc9bceb92220977 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 2 Jan 2012 13:49:59 -0500 Subject: [PATCH 03/10] Fixing findUntil() problem with repeated initial characters. (Jeffery.zksun) http://code.google.com/p/arduino/issues/detail?id=768 --- cores/arduino/Stream.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cores/arduino/Stream.cpp b/cores/arduino/Stream.cpp index 5fad8dd..3d5b905 100644 --- a/cores/arduino/Stream.cpp +++ b/cores/arduino/Stream.cpp @@ -99,25 +99,27 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t size_t index = 0; // maximum target string length is 64k bytes! size_t termIndex = 0; int c; - + if( *target == 0) - return true; // return true if target is a null string + return true; // return true if target is a null string while( (c = timedRead()) > 0){ + + if(c != target[index]) + index = 0; // reset index if any char does not match + if( c == target[index]){ - //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); if(++index >= targetLen){ // return true if all chars in the target match return true; } } - else{ - index = 0; // reset index if any char does not match - } + if(termLen > 0 && c == terminator[termIndex]){ - if(++termIndex >= termLen) - return false; // return false if terminate string found before target string + if(++termIndex >= termLen) + return false; // return false if terminate string found before target string } else - termIndex = 0; + termIndex = 0; } return false; } From 6c00397e22021762851511a0a9b6f914db81deca Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 2 Jan 2012 14:20:28 -0500 Subject: [PATCH 04/10] Adding INPUT_PULLUP option pinMode(). (Paul Stoffregen). This also changes pinMode(pin, INPUT); to explicitly disable the pull-up resistor, even if it was previously set. http://code.google.com/p/arduino/issues/detail?id=246 --- cores/arduino/Arduino.h | 1 + cores/arduino/wiring_digital.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index bfec943..830c995 100755 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -20,6 +20,7 @@ extern "C"{ #define INPUT 0x0 #define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 #define true 0x1 #define false 0x0 diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 97ef134..584a28a 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -32,17 +32,25 @@ void pinMode(uint8_t pin, uint8_t mode) { uint8_t bit = digitalPinToBitMask(pin); uint8_t port = digitalPinToPort(pin); - volatile uint8_t *reg; + volatile uint8_t *reg, *out; if (port == NOT_A_PIN) return; // JWS: can I let the optimizer do this? reg = portModeRegister(port); + out = portOutputRegister(port); if (mode == INPUT) { uint8_t oldSREG = SREG; cli(); *reg &= ~bit; + *out &= ~bit; + SREG = oldSREG; + } else if (mode == INPUT_PULLUP) { + uint8_t oldSREG = SREG; + cli(); + *reg &= ~bit; + *out |= bit; SREG = oldSREG; } else { uint8_t oldSREG = SREG; From dd5bae59df6f1ba63083361ba284f364bc62b401 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 4 Jan 2012 16:01:52 -0500 Subject: [PATCH 05/10] Adding links to documentation of boards.txt and programmers.txt files. --- boards.txt | 2 ++ programmers.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/boards.txt b/boards.txt index 018a7fa..7b719de 100644 --- a/boards.txt +++ b/boards.txt @@ -1,3 +1,5 @@ +# See: http://code.google.com/p/arduino/wiki/Platforms + ############################################################## uno.name=Arduino Uno diff --git a/programmers.txt b/programmers.txt index 02457d9..43e8d95 100644 --- a/programmers.txt +++ b/programmers.txt @@ -1,3 +1,5 @@ +# See: http://code.google.com/p/arduino/wiki/Platforms + avrisp.name=AVR ISP avrisp.communication=serial avrisp.protocol=stk500v1 From e1438efb3a6d538ae3fd0e2037ec2b112aa1c563 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 3 Feb 2012 17:24:29 -0500 Subject: [PATCH 06/10] Making head and tail unsigned to avoid division in serial ISR. http://code.google.com/p/arduino/issues/detail?id=776 --- cores/arduino/HardwareSerial.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 1b1fa71..9985b78 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -46,8 +46,8 @@ struct ring_buffer { unsigned char buffer[SERIAL_BUFFER_SIZE]; - volatile int head; - volatile int tail; + volatile unsigned int head; + volatile unsigned int tail; }; #if defined(USBCON) From a7afdf40baf0598a97dbfeaf7d9bfcce93df74fd Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 12 Feb 2012 19:52:03 -0500 Subject: [PATCH 07/10] prog_char -> char PROGMEM in Print.cpp http://code.google.com/p/arduino/issues/detail?id=795 --- cores/arduino/Print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index ff9b154..e541a6c 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -41,7 +41,7 @@ size_t Print::write(const uint8_t *buffer, size_t size) size_t Print::print(const __FlashStringHelper *ifsh) { - const prog_char *p = (const prog_char *)ifsh; + const char PROGMEM *p = (const char PROGMEM *)ifsh; size_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); From 0c00db7809760aae21678615b153d4a09709d018 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 29 Feb 2012 17:25:46 -0500 Subject: [PATCH 08/10] Switching Mini w/ ATmega328 upload protocol from stk500 to arduino. --- boards.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards.txt b/boards.txt index 7b719de..8ce7cc9 100644 --- a/boards.txt +++ b/boards.txt @@ -184,7 +184,7 @@ mega.build.variant=mega mini328.name=Arduino Mini w/ ATmega328 -mini328.upload.protocol=stk500 +mini328.upload.protocol=arduino mini328.upload.maximum_size=28672 mini328.upload.speed=115200 From 4fade7007fbe2049f4f7a3867c9f9a76f8c06db1 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 2 Mar 2012 18:58:53 -0500 Subject: [PATCH 09/10] Small changes for the ATmega1284. http://code.google.com/p/arduino/issues/detail?id=736 --- cores/arduino/WInterrupts.c | 2 -- cores/arduino/wiring_analog.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index 4f035eb..3b9fe08 100755 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -121,8 +121,6 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { #elif defined(MCUCR) && defined(ISC20) && defined(GIMSK) && defined(GIMSK) MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); GIMSK |= (1 << INT2); - #else - #warning attachInterrupt may need some more work for this cpu (case 1) #endif break; #endif diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 902b153..a8bc817 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -45,6 +45,8 @@ int analogRead(uint8_t pin) if (pin >= 54) pin -= 54; // allow for channel or pin numbers #elif defined(__AVR_ATmega32U4__) if (pin >= 18) pin -= 18; // allow for channel or pin numbers +#elif defined(__AVR_ATmega1284__) + if (pin >= 24) pin -= 24; // allow for channel or pin numbers #else if (pin >= 14) pin -= 14; // allow for channel or pin numbers #endif From 9a8976ce56bcdb70815dd58c1764d9e5c3b6fe95 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 15 Mar 2012 19:00:24 -0400 Subject: [PATCH 10/10] Putting ArduinoISP back to 19200 baud. From 9600. And lowering the delay in the heartbeat from 40 to 20, which seems to fix things again. --- programmers.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programmers.txt b/programmers.txt index 43e8d95..c34b88c 100644 --- a/programmers.txt +++ b/programmers.txt @@ -23,4 +23,4 @@ parallel.force=true arduinoisp.name=Arduino as ISP arduinoisp.communication=serial arduinoisp.protocol=stk500v1 -arduinoisp.speed=9600 +arduinoisp.speed=19200