Don't use the serial number when multimaterial

This commit is contained in:
Andre Sklenar 2017-09-05 11:10:08 +02:00
parent 57638c5643
commit a056d11af0
2 changed files with 39 additions and 4 deletions

View File

@ -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
}

View File

@ -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
}