Skip to content

Commit 79521e1

Browse files
committed
Merged upstream Arduino master branch
2 parents 386e059 + 2ef2f9d commit 79521e1

File tree

9 files changed

+119
-62
lines changed

9 files changed

+119
-62
lines changed

Diff for: cores/arduino/Print.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ size_t Print::printFloat(double number, uint8_t digits)
226226
{
227227
size_t n = 0;
228228

229+
if (isnan(number)) return print("nan");
230+
if (isinf(number)) return print("inf");
231+
229232
// Handle negative numbers
230233
if (number < 0.0)
231234
{

Diff for: cores/arduino/Print.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class Print
4646
void clearWriteError() { setWriteError(0); }
4747

4848
virtual size_t write(uint8_t) = 0;
49-
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
49+
size_t write(const char *str) {
50+
if (str == NULL) return 0;
51+
return write((const uint8_t *)str, strlen(str));
52+
}
5053
virtual size_t write(const uint8_t *buffer, size_t size);
5154

5255
size_t print(const __FlashStringHelper *);

Diff for: cores/arduino/USBAPI.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Serial_ : public Stream
3939
virtual int read(void);
4040
virtual void flush(void);
4141
virtual size_t write(uint8_t);
42+
using Print::write; // pull in write(str) and write(buf, size) from Print
4243
operator bool();
4344
};
4445
extern Serial_ Serial;

Diff for: cores/arduino/WInterrupts.c

+30-6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
5959
EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
6060
EIMSK |= (1<<INT1);
6161
break;
62+
case 2:
63+
EICRA = (EICRA & ~((1<<ISC20) | (1<<ISC21))) | (mode << ISC20);
64+
EIMSK |= (1<<INT2);
65+
break;
66+
case 3:
67+
EICRA = (EICRA & ~((1<<ISC30) | (1<<ISC31))) | (mode << ISC30);
68+
EIMSK |= (1<<INT3);
69+
break;
6270
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
6371
case 2:
6472
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
@@ -147,12 +155,18 @@ void detachInterrupt(uint8_t interruptNum) {
147155
// ATmega8. There, INT0 is 6 and INT1 is 7.)
148156
switch (interruptNum) {
149157
#if defined(__AVR_ATmega32U4__)
150-
case 0:
151-
EIMSK &= ~(1<<INT0);
152-
break;
153-
case 1:
154-
EIMSK &= ~(1<<INT1);
155-
break;
158+
case 0:
159+
EIMSK &= ~(1<<INT0);
160+
break;
161+
case 1:
162+
EIMSK &= ~(1<<INT1);
163+
break;
164+
case 2:
165+
EIMSK &= ~(1<<INT2);
166+
break;
167+
case 3:
168+
EIMSK &= ~(1<<INT3);
169+
break;
156170
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
157171
case 2:
158172
EIMSK &= ~(1 << INT0);
@@ -226,6 +240,16 @@ SIGNAL(INT1_vect) {
226240
intFunc[EXTERNAL_INT_1]();
227241
}
228242

243+
SIGNAL(INT2_vect) {
244+
if(intFunc[EXTERNAL_INT_2])
245+
intFunc[EXTERNAL_INT_2]();
246+
}
247+
248+
SIGNAL(INT3_vect) {
249+
if(intFunc[EXTERNAL_INT_3])
250+
intFunc[EXTERNAL_INT_3]();
251+
}
252+
229253
#elif defined(EICRA) && defined(EICRB)
230254

231255
SIGNAL(INT0_vect) {

Diff for: cores/arduino/wiring_private.h

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ extern "C"{
5656
#define EXTERNAL_NUM_INTERRUPTS 8
5757
#elif defined(__AVR_ATmega1284P__)
5858
#define EXTERNAL_NUM_INTERRUPTS 3
59+
#elif defined(__AVR_ATmega32U4__)
60+
#define EXTERNAL_NUM_INTERRUPTS 4
5961
#else
6062
#define EXTERNAL_NUM_INTERRUPTS 2
6163
#endif

Diff for: libraries/SD/utility/Sd2PinMap.h

+31-32
Original file line numberDiff line numberDiff line change
@@ -166,44 +166,43 @@ static const pin_map_t digitalPinMap[] = {
166166
};
167167
//------------------------------------------------------------------------------
168168
#elif defined(__AVR_ATmega32U4__)
169-
// Teensy 2.0
169+
// Leonardo
170170

171171
// Two Wire (aka I2C) ports
172-
uint8_t const SDA_PIN = 6;
173-
uint8_t const SCL_PIN = 5;
172+
uint8_t const SDA_PIN = 2;
173+
uint8_t const SCL_PIN = 3;
174174

175175
// SPI port
176-
uint8_t const SS_PIN = 0;
177-
uint8_t const MOSI_PIN = 2;
178-
uint8_t const MISO_PIN = 3;
179-
uint8_t const SCK_PIN = 1;
176+
uint8_t const SS_PIN = 17;
177+
uint8_t const MOSI_PIN = 16;
178+
uint8_t const MISO_PIN = 14;
179+
uint8_t const SCK_PIN = 15;
180180

181181
static const pin_map_t digitalPinMap[] = {
182-
{&DDRB, &PINB, &PORTB, 0}, // B0 0
183-
{&DDRB, &PINB, &PORTB, 1}, // B1 1
184-
{&DDRB, &PINB, &PORTB, 2}, // B2 2
185-
{&DDRB, &PINB, &PORTB, 3}, // B3 3
186-
{&DDRB, &PINB, &PORTB, 7}, // B7 4
187-
{&DDRD, &PIND, &PORTD, 0}, // D0 5
188-
{&DDRD, &PIND, &PORTD, 1}, // D1 6
189-
{&DDRD, &PIND, &PORTD, 2}, // D2 7
190-
{&DDRD, &PIND, &PORTD, 3}, // D3 8
191-
{&DDRC, &PINC, &PORTC, 6}, // C6 9
192-
{&DDRC, &PINC, &PORTC, 7}, // C7 10
193-
{&DDRD, &PIND, &PORTD, 6}, // D6 11
194-
{&DDRD, &PIND, &PORTD, 7}, // D7 12
195-
{&DDRB, &PINB, &PORTB, 4}, // B4 13
196-
{&DDRB, &PINB, &PORTB, 5}, // B5 14
197-
{&DDRB, &PINB, &PORTB, 6}, // B6 15
198-
{&DDRF, &PINF, &PORTF, 7}, // F7 16
199-
{&DDRF, &PINF, &PORTF, 6}, // F6 17
200-
{&DDRF, &PINF, &PORTF, 5}, // F5 18
201-
{&DDRF, &PINF, &PORTF, 4}, // F4 19
202-
{&DDRF, &PINF, &PORTF, 1}, // F1 20
203-
{&DDRF, &PINF, &PORTF, 0}, // F0 21
204-
{&DDRD, &PIND, &PORTD, 4}, // D4 22
205-
{&DDRD, &PIND, &PORTD, 5}, // D5 23
206-
{&DDRE, &PINE, &PORTE, 6} // E6 24
182+
{&DDRD, &PIND, &PORTD, 2}, // D2 0
183+
{&DDRD, &PIND, &PORTD, 3}, // D3 1
184+
{&DDRD, &PIND, &PORTD, 1}, // D1 2
185+
{&DDRD, &PIND, &PORTD, 0}, // D0 3
186+
{&DDRD, &PIND, &PORTD, 4}, // D4 4
187+
{&DDRC, &PINC, &PORTC, 6}, // C6 5
188+
{&DDRD, &PIND, &PORTD, 7}, // D7 6
189+
{&DDRE, &PINE, &PORTE, 6}, // E6 7
190+
{&DDRB, &PINB, &PORTB, 4}, // B4 8
191+
{&DDRB, &PINB, &PORTB, 5}, // B5 9
192+
{&DDRB, &PINB, &PORTB, 6}, // B6 10
193+
{&DDRB, &PINB, &PORTB, 7}, // B7 11
194+
{&DDRD, &PIND, &PORTD, 6}, // D6 12
195+
{&DDRC, &PINC, &PORTC, 7}, // C7 13
196+
{&DDRB, &PINB, &PORTB, 3}, // B3 14
197+
{&DDRB, &PINB, &PORTB, 1}, // B1 15
198+
{&DDRB, &PINB, &PORTB, 2}, // B2 16
199+
{&DDRB, &PINB, &PORTB, 0}, // B0 17
200+
{&DDRF, &PINF, &PORTF, 7}, // F7 18
201+
{&DDRF, &PINF, &PORTF, 6}, // F6 19
202+
{&DDRF, &PINF, &PORTF, 5}, // F5 20
203+
{&DDRF, &PINF, &PORTF, 4}, // F4 21
204+
{&DDRF, &PINF, &PORTF, 1}, // F1 22
205+
{&DDRF, &PINF, &PORTF, 0}, // F0 23
207206
};
208207
//------------------------------------------------------------------------------
209208
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)

Diff for: libraries/SPI/SPI.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,32 @@
1414
SPIClass SPI;
1515

1616
void SPIClass::begin() {
17-
// Set direction register for SCK and MOSI pin.
18-
// MISO pin automatically overrides to INPUT.
17+
18+
// Set SS to high so a connected chip will be "deselected" by default
19+
digitalWrite(SS, HIGH);
20+
1921
// When the SS pin is set as OUTPUT, it can be used as
2022
// a general purpose output port (it doesn't influence
2123
// SPI operations).
22-
23-
pinMode(SCK, OUTPUT);
24-
pinMode(MOSI, OUTPUT);
2524
pinMode(SS, OUTPUT);
26-
27-
digitalWrite(SCK, LOW);
28-
digitalWrite(MOSI, LOW);
29-
digitalWrite(SS, HIGH);
3025

31-
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
32-
// automatically switches to Slave, so the data direction of
26+
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
27+
// automatically switches to Slave, so the data direction of
3328
// the SS pin MUST be kept as OUTPUT.
3429
SPCR |= _BV(MSTR);
3530
SPCR |= _BV(SPE);
31+
32+
// Set direction register for SCK and MOSI pin.
33+
// MISO pin automatically overrides to INPUT.
34+
// By doing this AFTER enabling SPI, we avoid accidentally
35+
// clocking in a single bit since the lines go directly
36+
// from "input" to SPI control.
37+
// http://code.google.com/p/arduino/issues/detail?id=888
38+
pinMode(SCK, OUTPUT);
39+
pinMode(MOSI, OUTPUT);
3640
}
3741

42+
3843
void SPIClass::end() {
3944
SPCR &= ~_BV(SPE);
4045
}

Diff for: libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
Receives from software serial, sends to hardware serial.
66
77
The circuit:
8-
* RX is digital pin 2 (connect to TX of other device)
9-
* TX is digital pin 3 (connect to RX of other device)
8+
* RX is digital pin 10 (connect to TX of other device)
9+
* TX is digital pin 11 (connect to RX of other device)
10+
11+
Note:
12+
Not all pins on the Mega and Mega 2560 support change interrupts,
13+
so only the following can be used for RX:
14+
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
15+
16+
Not all pins on the Leonardo support change interrupts,
17+
so only the following can be used for RX:
18+
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
1019
1120
created back in the mists of time
12-
modified 9 Apr 2012
21+
modified 25 May 2012
1322
by Tom Igoe
1423
based on Mikal Hart's example
1524
@@ -18,17 +27,17 @@
1827
*/
1928
#include <SoftwareSerial.h>
2029

21-
SoftwareSerial mySerial(2, 3); // RX, TX
30+
SoftwareSerial mySerial(10, 11); // RX, TX
2231

2332
void setup()
2433
{
25-
// Open serial communications and wait for port to open:
34+
// Open serial communications and wait for port to open:
2635
Serial.begin(57600);
27-
while (!Serial) {
36+
while (!Serial) {
2837
; // wait for serial port to connect. Needed for Leonardo only
2938
}
3039

31-
40+
3241
Serial.println("Goodnight moon!");
3342

3443
// set the data rate for the SoftwareSerial port
@@ -43,3 +52,4 @@ void loop() // run over and over
4352
if (Serial.available())
4453
mySerial.write(Serial.read());
4554
}
55+

Diff for: libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino

+15-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616
* First serial device's TX attached to digital pin 2, RX to pin 3
1717
* Second serial device's TX attached to digital pin 4, RX to pin 5
1818
19+
Note:
20+
Not all pins on the Mega and Mega 2560 support change interrupts,
21+
so only the following can be used for RX:
22+
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
23+
24+
Not all pins on the Leonardo support change interrupts,
25+
so only the following can be used for RX:
26+
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
27+
1928
created 18 Apr. 2011
20-
modified 9 Apr 2012
29+
modified 25 May 2012
2130
by Tom Igoe
2231
based on Mikal Hart's twoPortRXExample
2332
@@ -26,11 +35,12 @@
2635
*/
2736

2837
#include <SoftwareSerial.h>
29-
// software serial #1: TX = digital pin 2, RX = digital pin 3
30-
SoftwareSerial portOne(2, 3);
38+
// software serial #1: TX = digital pin 10, RX = digital pin 11
39+
SoftwareSerial portOne(10,11);
3140

32-
// software serial #2: TX = digital pin 4, RX = digital pin 5
33-
SoftwareSerial portTwo(4, 5);
41+
// software serial #2: TX = digital pin 8, RX = digital pin 9
42+
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
43+
SoftwareSerial portTwo(8,9);
3444

3545
void setup()
3646
{

0 commit comments

Comments
 (0)