Skip to content

Commit ac6bc77

Browse files
committed
Merged upstream Arduino master branch
2 parents 234c006 + d160a1b commit ac6bc77

File tree

6 files changed

+56
-18
lines changed

6 files changed

+56
-18
lines changed

hardware/arduino/avr/cores/arduino/Print.cpp

Lines changed: 3 additions & 0 deletions
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
{

hardware/arduino/avr/cores/arduino/Print.h

Lines changed: 4 additions & 1 deletion
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 *);

hardware/arduino/avr/cores/arduino/USBAPI.h

Lines changed: 1 addition & 0 deletions
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;

hardware/arduino/avr/cores/arduino/WInterrupts.c

Lines changed: 30 additions & 6 deletions
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) {

hardware/arduino/avr/cores/arduino/wiring_private.h

Lines changed: 2 additions & 0 deletions
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

hardware/arduino/avr/libraries/SPI/SPI.cpp

Lines changed: 16 additions & 11 deletions
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
}

0 commit comments

Comments
 (0)