From 7d2d6c6fdcb296e776c7143cc72f6ca2271aa11e Mon Sep 17 00:00:00 2001 From: Andre Sklenar Date: Tue, 15 Aug 2017 10:13:08 +0200 Subject: [PATCH] run a reasonable LCD message on boot asap, support the second serial port (enabled only in farm mode) --- Firmware/Marlin.h | 3 +- Firmware/MarlinSerial.cpp | 43 ++++++++++++++++++++++++++-- Firmware/MarlinSerial.h | 59 ++++++++++++++++++++++++++++----------- Firmware/Marlin_main.cpp | 52 +++++++++++++++++++++++++++++++++- 4 files changed, 136 insertions(+), 21 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index a5c7ffa2..d1532036 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -96,6 +96,7 @@ void serial_echopair_P(const char *s_P, float v); void serial_echopair_P(const char *s_P, double v); void serial_echopair_P(const char *s_P, unsigned long v); +extern int selectedSerialPort; //Things to write to serial from Program memory. Saves 400 to 2k of RAM. FORCE_INLINE void serialprintPGM(const char *str) @@ -348,4 +349,4 @@ float temp_comp_interpolation(float temperature); void temp_compensation_apply(); void temp_compensation_start(); void wait_for_heater(long codenum); -void serialecho_temperatures(); \ No newline at end of file +void serialecho_temperatures(); diff --git a/Firmware/MarlinSerial.cpp b/Firmware/MarlinSerial.cpp index fba87cc8..c07ec458 100644 --- a/Firmware/MarlinSerial.cpp +++ b/Firmware/MarlinSerial.cpp @@ -64,6 +64,23 @@ FORCE_INLINE void store_char(unsigned char c) store_char(c); } } + + SIGNAL(USART2_RX_vect) + { + if (selectedSerialPort == 1) { + // Test for a framing error. + if (UCSR2A & (1<> 8; + UBRR2L = baud_setting; + + sbi(UCSR2B, RXEN2); + sbi(UCSR2B, TXEN2); + sbi(UCSR2B, RXCIE2); } void MarlinSerial::end() { cbi(M_UCSRxB, M_RXENx); cbi(M_UCSRxB, M_TXENx); - cbi(M_UCSRxB, M_RXCIEx); + cbi(M_UCSRxB, M_RXCIEx); + + cbi(UCSR2B, RXEN2); + cbi(UCSR2B, TXEN2); + cbi(UCSR2B, RXCIE2); } diff --git a/Firmware/MarlinSerial.h b/Firmware/MarlinSerial.h index 6776b568..30f5b83d 100644 --- a/Firmware/MarlinSerial.h +++ b/Firmware/MarlinSerial.h @@ -73,6 +73,7 @@ // is the index of the location from which to read. #define RX_BUFFER_SIZE 128 +extern int selectedSerialPort; struct ring_buffer { @@ -110,24 +111,48 @@ class MarlinSerial //: public Stream } - FORCE_INLINE void checkRx(void) + void checkRx(void) { - if((M_UCSRxA & (1< 0) { + uint8_t serial_char = MSerial.read(); + selectedSerialPort = 1; + MSerial.write(serial_char); + numbersRead++; + selectedSerialPort = 0; + } + } + selectedSerialPort = 1; + MSerial.write('\n'); + /*for (int b = 0; b < 3; b++) { + tone(BEEPER, 110); + delay(50); + noTone(BEEPER); + delay(50); + }*/ + } else { + MYSERIAL.println("Not in farm mode."); + } } else if(code_seen("Fir")){ SERIAL_PROTOCOLLN(FW_version);