Skip to content

Commit e5f960a

Browse files
authored
Merge pull request #9 from dmadison/upstream-updates
Arduino Core 1.8.3
2 parents 924299c + 4187057 commit e5f960a

File tree

11 files changed

+207
-43
lines changed

11 files changed

+207
-43
lines changed

cores/arduino/HardwareSerial0.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "HardwareSerial.h"
2727
#include "HardwareSerial_private.h"
2828

29-
// Each HardwareSerial is defined in its own file, sine the linker pulls
29+
// Each HardwareSerial is defined in its own file, since the linker pulls
3030
// in the entire file when any element inside is used. --gc-sections can
3131
// additionally cause unused symbols to be dropped, but ISRs have the
3232
// "used" attribute so are never dropped and they keep the

cores/arduino/HardwareSerial1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "HardwareSerial.h"
2727
#include "HardwareSerial_private.h"
2828

29-
// Each HardwareSerial is defined in its own file, sine the linker pulls
29+
// Each HardwareSerial is defined in its own file, since the linker pulls
3030
// in the entire file when any element inside is used. --gc-sections can
3131
// additionally cause unused symbols to be dropped, but ISRs have the
3232
// "used" attribute so are never dropped and they keep the

cores/arduino/HardwareSerial2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "HardwareSerial.h"
2727
#include "HardwareSerial_private.h"
2828

29-
// Each HardwareSerial is defined in its own file, sine the linker pulls
29+
// Each HardwareSerial is defined in its own file, since the linker pulls
3030
// in the entire file when any element inside is used. --gc-sections can
3131
// additionally cause unused symbols to be dropped, but ISRs have the
3232
// "used" attribute so are never dropped and they keep the

cores/arduino/HardwareSerial3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "HardwareSerial.h"
2727
#include "HardwareSerial_private.h"
2828

29-
// Each HardwareSerial is defined in its own file, sine the linker pulls
29+
// Each HardwareSerial is defined in its own file, since the linker pulls
3030
// in the entire file when any element inside is used. --gc-sections can
3131
// additionally cause unused symbols to be dropped, but ISRs have the
3232
// "used" attribute so are never dropped and they keep the

cores/arduino/new

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
this header is for compatibility with standard c++ header names
3+
so that #include<new> works as expected
4+
*/
5+
#include "new.h"

cores/arduino/wiring_analog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void analogWrite(uint8_t pin, int val)
164164

165165
#if defined(TCCR1A) && defined(COM1C1)
166166
case TIMER1C:
167-
// connect pwm to pin on timer 1, channel B
167+
// connect pwm to pin on timer 1, channel C
168168
sbi(TCCR1A, COM1C1);
169169
OCR1C = val; // set pwm duty
170170
break;

libraries/Wire/src/Wire.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
Modified 2012 by Todd Krein ([email protected]) to implement repeated starts
2020
Modified 2017 by Chuck Todd ([email protected]) to correct Unconfigured Slave Mode reboot
21+
Modified 2020 by Greyson Christoforo ([email protected]) to implement timeouts
2122
*/
2223

2324
extern "C" {
@@ -86,6 +87,52 @@ void TwoWire::setClock(uint32_t clock)
8687
twi_setFrequency(clock);
8788
}
8889

90+
/***
91+
* Sets the TWI timeout.
92+
*
93+
* This limits the maximum time to wait for the TWI hardware. If more time passes, the bus is assumed
94+
* to have locked up (e.g. due to noise-induced glitches or faulty slaves) and the transaction is aborted.
95+
* Optionally, the TWI hardware is also reset, which can be required to allow subsequent transactions to
96+
* succeed in some cases (in particular when noise has made the TWI hardware think there is a second
97+
* master that has claimed the bus).
98+
*
99+
* When a timeout is triggered, a flag is set that can be queried with `getWireTimeoutFlag()` and is cleared
100+
* when `clearWireTimeoutFlag()` or `setWireTimeoutUs()` is called.
101+
*
102+
* Note that this timeout can also trigger while waiting for clock stretching or waiting for a second master
103+
* to complete its transaction. So make sure to adapt the timeout to accomodate for those cases if needed.
104+
* A typical timeout would be 25ms (which is the maximum clock stretching allowed by the SMBus protocol),
105+
* but (much) shorter values will usually also work.
106+
*
107+
* In the future, a timeout will be enabled by default, so if you require the timeout to be disabled, it is
108+
* recommended you disable it by default using `setWireTimeoutUs(0)`, even though that is currently
109+
* the default.
110+
*
111+
* @param timeout a timeout value in microseconds, if zero then timeout checking is disabled
112+
* @param reset_with_timeout if true then TWI interface will be automatically reset on timeout
113+
* if false then TWI interface will not be reset on timeout
114+
115+
*/
116+
void TwoWire::setWireTimeout(uint32_t timeout, bool reset_with_timeout){
117+
twi_setTimeoutInMicros(timeout, reset_with_timeout);
118+
}
119+
120+
/***
121+
* Returns the TWI timeout flag.
122+
*
123+
* @return true if timeout has occured since the flag was last cleared.
124+
*/
125+
bool TwoWire::getWireTimeoutFlag(void){
126+
return(twi_manageTimeoutFlag(false));
127+
}
128+
129+
/***
130+
* Clears the TWI timeout flag.
131+
*/
132+
void TwoWire::clearWireTimeoutFlag(void){
133+
twi_manageTimeoutFlag(true);
134+
}
135+
89136
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
90137
{
91138
if (isize > 0) {

libraries/Wire/src/Wire.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919
Modified 2012 by Todd Krein ([email protected]) to implement repeated starts
20+
Modified 2020 by Greyson Christoforo ([email protected]) to implement timeouts
2021
*/
2122

2223
#ifndef TwoWire_h
@@ -54,13 +55,16 @@ class TwoWire : public Stream
5455
void begin(int);
5556
void end();
5657
void setClock(uint32_t);
58+
void setWireTimeout(uint32_t timeout = 25000, bool reset_with_timeout = false);
59+
bool getWireTimeoutFlag(void);
60+
void clearWireTimeoutFlag(void);
5761
void beginTransmission(uint8_t);
5862
void beginTransmission(int);
5963
uint8_t endTransmission(void);
6064
uint8_t endTransmission(uint8_t);
6165
uint8_t requestFrom(uint8_t, uint8_t);
6266
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
63-
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
67+
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
6468
uint8_t requestFrom(int, int);
6569
uint8_t requestFrom(int, int, int);
6670
virtual size_t write(uint8_t);

0 commit comments

Comments
 (0)