From 07aa7a3803171192852353774a8115932c0980a3 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 7 Dec 2017 19:14:17 +0100 Subject: [PATCH] support two serial lines at the same time --- Firmware/MarlinSerial.cpp | 28 ++++++++++++++-------------- Firmware/MarlinSerial.h | 25 +++++++++++++++++++------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Firmware/MarlinSerial.cpp b/Firmware/MarlinSerial.cpp index c0f61d82..b01ef459 100644 --- a/Firmware/MarlinSerial.cpp +++ b/Firmware/MarlinSerial.cpp @@ -67,17 +67,17 @@ FORCE_INLINE void store_char(unsigned char c) } } #ifndef SNMM - SIGNAL(USART2_RX_vect) + SIGNAL(USART1_RX_vect) { if (selectedSerialPort == 1) { // Test for a framing error. - if (UCSR2A & (1<> 8; - UBRR2L = baud_setting; + UBRR1H = baud_setting >> 8; + UBRR1L = baud_setting; - sbi(UCSR2B, RXEN2); - sbi(UCSR2B, TXEN2); - sbi(UCSR2B, RXCIE2); + sbi(UCSR1B, RXEN1); + sbi(UCSR1B, TXEN1); + sbi(UCSR1B, RXCIE1); } #endif } @@ -154,9 +154,9 @@ void MarlinSerial::end() cbi(M_UCSRxB, M_RXCIEx); #ifndef SNMM - cbi(UCSR2B, RXEN2); - cbi(UCSR2B, TXEN2); - cbi(UCSR2B, RXCIE2); + cbi(UCSR1B, RXEN1); + cbi(UCSR1B, TXEN1); + cbi(UCSR1B, RXCIE1); #endif } diff --git a/Firmware/MarlinSerial.h b/Firmware/MarlinSerial.h index a4f799aa..24e9f79f 100644 --- a/Firmware/MarlinSerial.h +++ b/Firmware/MarlinSerial.h @@ -101,7 +101,7 @@ class MarlinSerial //: public Stream { return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE; } - + /* FORCE_INLINE void write(uint8_t c) { while (!((M_UCSRxA) & (1 << M_UDREx))) @@ -109,7 +109,20 @@ class MarlinSerial //: public Stream M_UDRx = c; } - + */ + void write(uint8_t c) + { + if (selectedSerialPort == 0) { + while (!((M_UCSRxA) & (1 << M_UDREx))) + ; + M_UDRx = c; + } + else if (selectedSerialPort == 1) { + while (!((UCSR1A) & (1 << UDRE1))) + ; + UDR1 = c; + } + } void checkRx(void) { @@ -135,14 +148,14 @@ class MarlinSerial //: public Stream } } } else if(selectedSerialPort == 1) { - if((UCSR2A & (1<