From 8a9caf76c65da123fac59411d1169a598ca37855 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 24 Nov 2024 09:16:45 +0000 Subject: [PATCH 1/5] remove unused function uart2_rx_str_P --- Firmware/uart2.c | 28 ---------------------------- Firmware/uart2.h | 3 --- 2 files changed, 31 deletions(-) diff --git a/Firmware/uart2.c b/Firmware/uart2.c index 5d90889d50..2f6095c278 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.c @@ -45,34 +45,6 @@ void uart2_init(uint32_t baudRate) fdev_setup_stream(uart2io, uart2_putchar, uart2_getchar, _FDEV_SETUP_WRITE | _FDEV_SETUP_READ); //setup uart2 i/o stream } -//returns 1 if chars in input buffer match to str -//returns -1 if chars does not match and 0 for empty buffer -int8_t uart2_rx_str_P(const char* str) -{ - uint8_t r = rbuf_r(uart2_ibuf); //get read index - uint8_t w = rbuf_w(uart2_ibuf); //get write index -// printf_P(PSTR("uart2_rx_str_P r=%d w=%d\n"), r, w); - uint8_t e = rbuf_l(uart2_ibuf) - 1; //get end index - uint8_t len = strlen_P(str); //get string length - str += len; //last char will be compared first -// printf_P(PSTR(" len=%d\n"), len); - while (len--) //loop over all chars - { - if (w == r) return 0; //empty buffer - return 0 - if ((--w) == 255) w = e; //decrement index - char c0 = pgm_read_byte(--str); //read char from str - char c1 = uart2_ibuf[4 + w]; //read char from input buffer -// printf_P(PSTR(" uart2_rx_str_P w=%d l=%d c0=%02x c1=%02x\n"), w, len, c0, c1); - if (c0 == c1) continue; //if match, continue with next char - if ((c0 == '\r') && (c1 == '\n')) //match cr as lf - continue; - if ((c0 == '\n') && (c1 == '\r')) //match lf as cr - continue; - return -1; //no match - return -1 - } - return 1; //all characters match - return 1 -} - ISR(USART2_RX_vect) { //printf_P(PSTR("USART2_RX_vect \n") ); diff --git a/Firmware/uart2.h b/Firmware/uart2.h index 4c72daa831..fdb444aa2b 100644 --- a/Firmware/uart2.h +++ b/Firmware/uart2.h @@ -17,9 +17,6 @@ extern FILE _uart2io; extern void uart2_init(uint32_t baudRate); -extern int8_t uart2_rx_str_P(const char* str); - - #if defined(__cplusplus) } #endif //defined(__cplusplus) From 5d8b7b45da51b1d73d6f403dcef635b748877ae8 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 24 Nov 2024 09:19:10 +0000 Subject: [PATCH 2/5] Remove unhelpful comments and constants --- Firmware/uart2.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Firmware/uart2.c b/Firmware/uart2.c index 2f6095c278..7e05d7430d 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.c @@ -6,10 +6,7 @@ #include "rbuf.h" #include "macros.h" -#define UART2_BAUD 115200 #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*8.0)-1.0+0.5) -#define uart2_rxcomplete (UCSR2A & (1 << RXC2)) -#define uart2_txcomplete (UCSR2A & (1 << TXC2)) #define uart2_txready (UCSR2A & (1 << UDRE2)) uint8_t uart2_ibuf[20] = {0, 0}; @@ -20,9 +17,9 @@ FILE _uart2io = {0}; int uart2_putchar(char c, _UNUSED FILE *stream) { while (!uart2_txready); + UDR2 = c; // transmit byte -// while (!uart2_txcomplete); // wait until byte sent -// UCSR2A |= (1 << TXC2); // delete TXCflag + return 0; } @@ -47,10 +44,8 @@ void uart2_init(uint32_t baudRate) ISR(USART2_RX_vect) { - //printf_P(PSTR("USART2_RX_vect \n") ); if (rbuf_put(uart2_ibuf, UDR2) < 0) // put received byte to buffer { //rx buffer full - //uart2_rx_clr(); //for sure, clear input buffer puts_P(PSTR("USART2 rx Full!!!")); } } From 631bf805260a05d6c9a78600df577d6d4abdf77b Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 24 Nov 2024 09:21:52 +0000 Subject: [PATCH 3/5] Mark uart2_putchar and uart2_getchar as static --- Firmware/uart2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/uart2.c b/Firmware/uart2.c index 7e05d7430d..af75acf49f 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.c @@ -14,7 +14,7 @@ uint8_t uart2_ibuf[20] = {0, 0}; FILE _uart2io = {0}; -int uart2_putchar(char c, _UNUSED FILE *stream) +static int uart2_putchar(char c, _UNUSED FILE *stream) { while (!uart2_txready); @@ -23,7 +23,7 @@ int uart2_putchar(char c, _UNUSED FILE *stream) return 0; } -int uart2_getchar(_UNUSED FILE *stream) +static int uart2_getchar(_UNUSED FILE *stream) { if (rbuf_empty(uart2_ibuf)) return -1; return rbuf_get(uart2_ibuf); From d067f99a03201ca59f0447b0eb887d4b54f23178 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 24 Nov 2024 09:25:11 +0000 Subject: [PATCH 4/5] Trim empty lines --- Firmware/uart2.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Firmware/uart2.c b/Firmware/uart2.c index af75acf49f..994d11d813 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.c @@ -10,10 +10,8 @@ #define uart2_txready (UCSR2A & (1 << UDRE2)) uint8_t uart2_ibuf[20] = {0, 0}; - FILE _uart2io = {0}; - static int uart2_putchar(char c, _UNUSED FILE *stream) { while (!uart2_txready); From 78d999a30057bda8dc16afac871c198061e1a092 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 24 Nov 2024 09:28:26 +0000 Subject: [PATCH 5/5] Convert uart2.c to a C++ file --- CMakeLists.txt | 2 +- Firmware/{uart2.c => uart2.cpp} | 2 +- Firmware/uart2.h | 12 +----------- 3 files changed, 3 insertions(+), 13 deletions(-) rename Firmware/{uart2.c => uart2.cpp} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 609c575e81..581939c6a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,7 +268,7 @@ set(FW_SOURCES tmc2130.cpp tone04.c twi.cpp - uart2.c + uart2.cpp ultralcd.cpp util.cpp xflash.c diff --git a/Firmware/uart2.c b/Firmware/uart2.cpp similarity index 98% rename from Firmware/uart2.c rename to Firmware/uart2.cpp index 994d11d813..bdc5b11927 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.cpp @@ -10,7 +10,7 @@ #define uart2_txready (UCSR2A & (1 << UDRE2)) uint8_t uart2_ibuf[20] = {0, 0}; -FILE _uart2io = {0}; +FILE _uart2io; static int uart2_putchar(char c, _UNUSED FILE *stream) { diff --git a/Firmware/uart2.h b/Firmware/uart2.h index fdb444aa2b..f023268921 100644 --- a/Firmware/uart2.h +++ b/Firmware/uart2.h @@ -5,19 +5,9 @@ #include #include - -#if defined(__cplusplus) -extern "C" { -#endif //defined(__cplusplus) - - extern FILE _uart2io; #define uart2io (&_uart2io) +void uart2_init(uint32_t baudRate); -extern void uart2_init(uint32_t baudRate); - -#if defined(__cplusplus) -} -#endif //defined(__cplusplus) #endif //_UART2_H