Skip to content

Commit 10db3b4

Browse files
authored
Merge branch 'master' into bugfix/wificlient_connect_leak
2 parents 6b0602d + 42f824b commit 10db3b4

File tree

21 files changed

+288
-151
lines changed

21 files changed

+288
-151
lines changed

cores/esp8266/HardwareSerial.cpp

+2-83
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ void HardwareSerial::end()
5555
uart_set_debug(UART_NO);
5656
}
5757

58-
if (_uart) {
59-
uart_uninit(_uart);
60-
_uart = NULL;
61-
}
58+
uart_uninit(_uart);
59+
_uart = NULL;
6260
}
6361

6462
size_t HardwareSerial::setRxBufferSize(size_t size){
@@ -70,30 +68,6 @@ size_t HardwareSerial::setRxBufferSize(size_t size){
7068
return _rx_size;
7169
}
7270

73-
void HardwareSerial::swap(uint8_t tx_pin)
74-
{
75-
if(!_uart) {
76-
return;
77-
}
78-
uart_swap(_uart, tx_pin);
79-
}
80-
81-
void HardwareSerial::set_tx(uint8_t tx_pin)
82-
{
83-
if(!_uart) {
84-
return;
85-
}
86-
uart_set_tx(_uart, tx_pin);
87-
}
88-
89-
void HardwareSerial::pins(uint8_t tx, uint8_t rx)
90-
{
91-
if(!_uart) {
92-
return;
93-
}
94-
uart_set_pins(_uart, tx, rx);
95-
}
96-
9771
void HardwareSerial::setDebugOutput(bool en)
9872
{
9973
if(!_uart) {
@@ -113,16 +87,6 @@ void HardwareSerial::setDebugOutput(bool en)
11387
}
11488
}
11589

116-
bool HardwareSerial::isTxEnabled(void)
117-
{
118-
return _uart && uart_tx_enabled(_uart);
119-
}
120-
121-
bool HardwareSerial::isRxEnabled(void)
122-
{
123-
return _uart && uart_rx_enabled(_uart);
124-
}
125-
12690
int HardwareSerial::available(void)
12791
{
12892
int result = static_cast<int>(uart_rx_available(_uart));
@@ -132,27 +96,6 @@ int HardwareSerial::available(void)
13296
return result;
13397
}
13498

135-
int HardwareSerial::peek(void)
136-
{
137-
// this may return -1, but that's okay
138-
return uart_peek_char(_uart);
139-
}
140-
141-
int HardwareSerial::read(void)
142-
{
143-
// this may return -1, but that's okay
144-
return uart_read_char(_uart);
145-
}
146-
147-
int HardwareSerial::availableForWrite(void)
148-
{
149-
if(!_uart || !uart_tx_enabled(_uart)) {
150-
return 0;
151-
}
152-
153-
return static_cast<int>(uart_tx_free(_uart));
154-
}
155-
15699
void HardwareSerial::flush()
157100
{
158101
if(!_uart || !uart_tx_enabled(_uart)) {
@@ -165,33 +108,9 @@ void HardwareSerial::flush()
165108
delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
166109
}
167110

168-
size_t HardwareSerial::write(uint8_t c)
169-
{
170-
if(!_uart || !uart_tx_enabled(_uart)) {
171-
return 0;
172-
}
173-
174-
uart_write_char(_uart, c);
175-
return 1;
176-
}
177-
178-
int HardwareSerial::baudRate(void)
179-
{
180-
// Null pointer on _uart is checked by SDK
181-
return uart_get_baudrate(_uart);
182-
}
183-
184-
185-
HardwareSerial::operator bool() const
186-
{
187-
return _uart != 0;
188-
}
189-
190-
191111
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
192112
HardwareSerial Serial(UART0);
193113
#endif
194114
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
195115
HardwareSerial Serial1(UART1);
196116
#endif
197-

cores/esp8266/HardwareSerial.h

+56-13
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,50 @@ class HardwareSerial: public Stream
9393
{
9494
swap(1);
9595
}
96-
void swap(uint8_t tx_pin); //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX
96+
void swap(uint8_t tx_pin) //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX
97+
{
98+
uart_swap(_uart, tx_pin);
99+
}
97100

98101
/*
99102
* Toggle between use of GPIO1 and GPIO2 as TX on UART 0.
100103
* Note: UART 1 can't be used if GPIO2 is used with UART 0!
101104
*/
102-
void set_tx(uint8_t tx_pin);
105+
void set_tx(uint8_t tx_pin)
106+
{
107+
uart_set_tx(_uart, tx_pin);
108+
}
103109

104110
/*
105111
* UART 0 possible options are (1, 3), (2, 3) or (15, 13)
106112
* UART 1 allows only TX on 2 if UART 0 is not (2, 3)
107113
*/
108-
void pins(uint8_t tx, uint8_t rx);
114+
void pins(uint8_t tx, uint8_t rx)
115+
{
116+
uart_set_pins(_uart, tx, rx);
117+
}
109118

110119
int available(void) override;
111-
int peek(void) override;
112-
int read(void) override;
113-
int availableForWrite(void);
120+
121+
int peek(void) override
122+
{
123+
// this may return -1, but that's okay
124+
return uart_peek_char(_uart);
125+
}
126+
int read(void) override
127+
{
128+
// this may return -1, but that's okay
129+
return uart_read_char(_uart);
130+
}
131+
int availableForWrite(void)
132+
{
133+
return static_cast<int>(uart_tx_free(_uart));
134+
}
114135
void flush(void) override;
115-
size_t write(uint8_t) override;
136+
size_t write(uint8_t c) override
137+
{
138+
return uart_write_char(_uart, c);
139+
}
116140
inline size_t write(unsigned long n)
117141
{
118142
return write((uint8_t) n);
@@ -129,13 +153,32 @@ class HardwareSerial: public Stream
129153
{
130154
return write((uint8_t) n);
131155
}
132-
using Print::write; // pull in write(str) and write(buf, size) from Print
133-
operator bool() const;
134-
156+
size_t write(const uint8_t *buffer, size_t size)
157+
{
158+
return uart_write(_uart, (const char*)buffer, size);
159+
}
160+
operator bool() const
161+
{
162+
return _uart != 0;
163+
}
135164
void setDebugOutput(bool);
136-
bool isTxEnabled(void);
137-
bool isRxEnabled(void);
138-
int baudRate(void);
165+
bool isTxEnabled(void)
166+
{
167+
return uart_tx_enabled(_uart);
168+
}
169+
bool isRxEnabled(void)
170+
{
171+
return uart_rx_enabled(_uart);
172+
}
173+
int baudRate(void)
174+
{
175+
return uart_get_baudrate(_uart);
176+
}
177+
178+
bool hasOverrun(void)
179+
{
180+
return uart_has_overrun(_uart);
181+
}
139182

140183
protected:
141184
int _uart_nr;

cores/esp8266/Print.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333

3434
/* default implementation: may be overridden */
3535
size_t Print::write(const uint8_t *buffer, size_t size) {
36+
37+
#ifdef DEBUG_ESP_CORE
38+
static char not_the_best_way [] ICACHE_RODATA_ATTR STORE_ATTR = "Print::write(data,len) should be overridden for better efficiency\r\n";
39+
static bool once = false;
40+
if (!once) {
41+
once = true;
42+
os_printf_plus(not_the_best_way);
43+
}
44+
#endif
45+
3646
size_t n = 0;
3747
while (size--) {
3848
size_t ret = write(*buffer++);

cores/esp8266/core_esp8266_i2s.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static uint32_t *i2s_slc_buf_pntr[SLC_BUF_CNT]; //Pointer to the I2S DMA buffer
5656
static struct slc_queue_item i2s_slc_items[SLC_BUF_CNT]; //I2S DMA buffer descriptors
5757
static uint32_t *i2s_curr_slc_buf=NULL;//current buffer for writing
5858
static int i2s_curr_slc_buf_pos=0; //position in the current buffer
59+
static void (*i2s_callback) (void)=0; //Callback function should be defined as 'void ICACHE_FLASH_ATTR function_name()', placing the function in IRAM for faster execution. Avoid long computational tasks in this function, use it to set flags and process later.
5960

6061
bool ICACHE_FLASH_ATTR i2s_is_full(){
6162
return (i2s_curr_slc_buf_pos==SLC_BUF_LEN || i2s_curr_slc_buf==NULL) && (i2s_slc_queue_len == 0);
@@ -92,10 +93,15 @@ void ICACHE_FLASH_ATTR i2s_slc_isr(void) {
9293
i2s_slc_queue_next_item(); //free space for finished_item
9394
}
9495
i2s_slc_queue[i2s_slc_queue_len++] = finished_item->buf_ptr;
96+
if (i2s_callback) i2s_callback();
9597
ETS_SLC_INTR_ENABLE();
9698
}
9799
}
98100

101+
void i2s_set_callback(void (*callback) (void)){
102+
i2s_callback = callback;
103+
}
104+
99105
void ICACHE_FLASH_ATTR i2s_slc_begin(){
100106
i2s_slc_queue_len = 0;
101107
int x, y;
@@ -248,7 +254,6 @@ float ICACHE_FLASH_ATTR i2s_get_real_rate(){
248254
return (float)I2SBASEFREQ/32/((I2SC>>I2SBD) & I2SBDM)/((I2SC >> I2SCD) & I2SCDM);
249255
}
250256

251-
252257
void ICACHE_FLASH_ATTR i2s_begin(){
253258
_i2s_sample_rate = 0;
254259
i2s_slc_begin();

0 commit comments

Comments
 (0)