8000 adds some IDF error return conditions · SuGlider/arduino-esp32@d37a199 · GitHub
[go: up one dir, main page]

Skip to content

Commit d37a199

Browse files
authored
adds some IDF error return conditions
1 parent 6ef09b6 commit d37a199

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cores/esp32/esp32-hal-uart.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ size_t uartReadBytes(uart_t* uart, uint8_t *buffer, size_t size, uint32_t timeou
354354
return bytes_read;
355355
}
356356

357-
357+
// DEPRICATED but the original code will be kepts here as future reference when a final solution
358+
// to the UART driver is defined in the use case of reading byte by byte from UART.
358359
uint8_t uartRead(uart_t* uart)
359360
{
360361
if(uart == NULL) {
@@ -370,14 +371,15 @@ uint8_t uartRead(uart_t* uart)
370371
} else {
371372

372373
int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_RATE_MS);
373-
if (len == 0) {
374+
if (len <= 0) { // includes negative return from IDF in case of error
374375
c = 0;
375376
}
376377
}
377378
UART_MUTEX_UNLOCK();
378379
return c;
379380
}
380381

382+
381383
uint8_t uartPeek(uart_t* uart)
382384
{
383385
if(uart == NULL) {
@@ -391,7 +393,7 @@ uint8_t uartPeek(uart_t* uart)
391393
c = uart->peek_byte;
392394
} else {
393395
int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_RATE_MS);
394-
if (len == 0) {
396+
if (len <= 0) { // includes negative return from IDF in case of error
395397
c = 0;
396398
} else {
397399
uart->has_peek = true;

0 commit comments

Comments
 (0)
0