Browse Source

Don't use the serial number when multimaterial

Andre Sklenar 7 years ago
parent
commit
a056d11af0
2 changed files with 39 additions and 4 deletions
  1. 8 4
      Firmware/MarlinSerial.cpp
  2. 31 0
      Firmware/MarlinSerial.h

+ 8 - 4
Firmware/MarlinSerial.cpp

@@ -64,7 +64,7 @@ FORCE_INLINE void store_char(unsigned char c)
           store_char(c);
       }
   }
-  
+#ifndef SNMM
   SIGNAL(USART2_RX_vect)
   {
       if (selectedSerialPort == 1) {
@@ -82,6 +82,7 @@ FORCE_INLINE void store_char(unsigned char c)
       }
   }
 #endif
+#endif
 
 // Constructors ////////////////////////////////////////////////////////////////
 
@@ -122,7 +123,7 @@ void MarlinSerial::begin(long baud)
   sbi(M_UCSRxB, M_TXENx);
   sbi(M_UCSRxB, M_RXCIEx);
   
-  
+#ifndef SNMM
 // set up the second serial port
   if (useU2X) {
         UCSR2A = 1 << U2X2;
@@ -139,6 +140,7 @@ void MarlinSerial::begin(long baud)
     sbi(UCSR2B, RXEN2);
     sbi(UCSR2B, TXEN2);
     sbi(UCSR2B, RXCIE2);
+#endif
 }
 
 void MarlinSerial::end()
@@ -146,10 +148,12 @@ void MarlinSerial::end()
   cbi(M_UCSRxB, M_RXENx);
   cbi(M_UCSRxB, M_TXENx);
   cbi(M_UCSRxB, M_RXCIEx);
-  
+
+#ifndef SNMM
   cbi(UCSR2B, RXEN2);
   cbi(UCSR2B, TXEN2);
-  cbi(UCSR2B, RXCIE2); 
+  cbi(UCSR2B, RXCIE2);
+#endif
 }
 
 

+ 31 - 0
Firmware/MarlinSerial.h

@@ -104,6 +104,12 @@ class MarlinSerial //: public Stream
 
 	void write(uint8_t c)
 	{
+#ifdef SNMM // don't do the second serial port when multimaterialing
+        while (!((M_UCSRxA) & (1 << M_UDREx)))
+				;
+
+        M_UDRx = c;
+#else
 		if (selectedSerialPort == 0) {
 			while (!((M_UCSRxA) & (1 << M_UDREx)))
 				;
@@ -116,11 +122,35 @@ class MarlinSerial //: public Stream
 
 			UDR2 = c;
 		}
+#endif
 	}
     
     
     void checkRx(void)
     {
+        
+#ifdef SNMM
+        if((M_UCSRxA & (1<<M_RXCx)) != 0) {
+                // Test for a framing error.
+                if (M_UCSRxA & (1<<M_FEx)) {
+                    // Characters received with the framing errors will be ignored.
+                    // The temporary variable "c" was made volatile, so the compiler does not optimize this out.
+                    volatile unsigned char c = M_UDRx;
+                } else {
+                    unsigned char c  =  M_UDRx;
+                    int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
+                    // if we should be storing the received character into the location
+                    // just before the tail (meaning that the head would advance to the
+                    // current location of the tail), we're about to overflow the buffer
+                    // and so we don't write the character or advance the head.
+                    if (i != rx_buffer.tail) {
+                        rx_buffer.buffer[rx_buffer.head] = c;
+                        rx_buffer.head = i;
+                    }
+                    selectedSerialPort = 0;
+                }
+            }
+#else
         if (selectedSerialPort == 0) {
             if((M_UCSRxA & (1<<M_RXCx)) != 0) {
                 // Test for a framing error.
@@ -164,6 +194,7 @@ class MarlinSerial //: public Stream
                 }
             }
         }
+#endif
     }