|
@ -68,8 +68,8 @@ FORCE_INLINE void store_char(unsigned char c) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if TX_BUFFER_SIZE > 0 |
|
|
#if TX_BUFFER_SIZE > 0 |
|
|
FORCE_INLINE void _tx_udr_empty_irq(void) |
|
|
|
|
|
{ |
|
|
FORCE_INLINE void _tx_udr_empty_irq(void) { |
|
|
// If interrupts are enabled, there must be more data in the output
|
|
|
// If interrupts are enabled, there must be more data in the output
|
|
|
// buffer. Send the next byte
|
|
|
// buffer. Send the next byte
|
|
|
uint8_t t = tx_buffer.tail; |
|
|
uint8_t t = tx_buffer.tail; |
|
@ -95,7 +95,7 @@ FORCE_INLINE void store_char(unsigned char c) { |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif // TX_BUFFER_SIZE
|
|
|
|
|
|
|
|
|
#if defined(M_USARTx_RX_vect) |
|
|
#if defined(M_USARTx_RX_vect) |
|
|
ISR(M_USARTx_RX_vect) { |
|
|
ISR(M_USARTx_RX_vect) { |
|
@ -160,15 +160,8 @@ void MarlinSerial::checkRx(void) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int MarlinSerial::peek(void) { |
|
|
int MarlinSerial::peek(void) { |
|
|
int v; |
|
|
|
|
|
CRITICAL_SECTION_START; |
|
|
CRITICAL_SECTION_START; |
|
|
uint8_t t = rx_buffer.tail; |
|
|
int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail]; |
|
|
if (rx_buffer.head == t) { |
|
|
|
|
|
v = -1; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
v = rx_buffer.buffer[t]; |
|
|
|
|
|
} |
|
|
|
|
|
CRITICAL_SECTION_END; |
|
|
CRITICAL_SECTION_END; |
|
|
return v; |
|
|
return v; |
|
|
} |
|
|
} |
|
@ -190,8 +183,8 @@ int MarlinSerial::read(void) { |
|
|
|
|
|
|
|
|
uint8_t MarlinSerial::available(void) { |
|
|
uint8_t MarlinSerial::available(void) { |
|
|
CRITICAL_SECTION_START; |
|
|
CRITICAL_SECTION_START; |
|
|
uint8_t h = rx_buffer.head; |
|
|
uint8_t h = rx_buffer.head, |
|
|
uint8_t t = rx_buffer.tail; |
|
|
t = rx_buffer.tail; |
|
|
CRITICAL_SECTION_END; |
|
|
CRITICAL_SECTION_END; |
|
|
return (uint8_t)(RX_BUFFER_SIZE + h - t) & (RX_BUFFER_SIZE - 1); |
|
|
return (uint8_t)(RX_BUFFER_SIZE + h - t) & (RX_BUFFER_SIZE - 1); |
|
|
} |
|
|
} |
|
@ -251,11 +244,10 @@ void MarlinSerial::flush(void) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
tx_buffer.buffer[tx_buffer.head] = c; |
|
|
tx_buffer.buffer[tx_buffer.head] = c; |
|
|
{ CRITICAL_SECTION_START; |
|
|
CRITICAL_SECTION_START; |
|
|
tx_buffer.head = i; |
|
|
tx_buffer.head = i; |
|
|
SBI(M_UCSRxB, M_UDRIEx); |
|
|
SBI(M_UCSRxB, M_UDRIEx); |
|
|
CRITICAL_SECTION_END; |
|
|
CRITICAL_SECTION_END; |
|
|
} |
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -386,23 +378,18 @@ void MarlinSerial::println(double n, int digits) { |
|
|
// Private Methods /////////////////////////////////////////////////////////////
|
|
|
// Private Methods /////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
void MarlinSerial::printNumber(unsigned long n, uint8_t base) { |
|
|
void MarlinSerial::printNumber(unsigned long n, uint8_t base) { |
|
|
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
|
|
|
if (n) { |
|
|
unsigned long i = 0; |
|
|
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
|
|
|
|
|
|
int8_t i = 0; |
|
|
if (n == 0) { |
|
|
while (n) { |
|
|
print('0'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (n > 0) { |
|
|
|
|
|
buf[i++] = n % base; |
|
|
buf[i++] = n % base; |
|
|
n /= base; |
|
|
n /= base; |
|
|
} |
|
|
} |
|
|
|
|
|
while (i--) |
|
|
for (; i > 0; i--) |
|
|
print((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10))); |
|
|
print((char)(buf[i - 1] < 10 ? |
|
|
} |
|
|
'0' + buf[i - 1] : |
|
|
else |
|
|
'A' + buf[i - 1] - 10)); |
|
|
print('0'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MarlinSerial::printFloat(double number, uint8_t digits) { |
|
|
void MarlinSerial::printFloat(double number, uint8_t digits) { |
|
@ -415,7 +402,7 @@ void MarlinSerial::printFloat(double number, uint8_t digits) { |
|
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
|
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
|
|
double rounding = 0.5; |
|
|
double rounding = 0.5; |
|
|
for (uint8_t i = 0; i < digits; ++i) |
|
|
for (uint8_t i = 0; i < digits; ++i) |
|
|
rounding /= 10.0; |
|
|
rounding *= 0.1; |
|
|
|
|
|
|
|
|
number += rounding; |
|
|
number += rounding; |
|
|
|
|
|
|
|
@ -425,15 +412,16 @@ void MarlinSerial::printFloat(double number, uint8_t digits) { |
|
|
print(int_part); |
|
|
print(int_part); |
|
|
|
|
|
|
|
|
// Print the decimal point, but only if there are digits beyond
|
|
|
// Print the decimal point, but only if there are digits beyond
|
|
|
if (digits > 0) print('.'); |
|
|
if (digits) { |
|
|
|
|
|
print('.'); |
|
|
// Extract digits from the remainder one at a time
|
|
|
// Extract digits from the remainder one at a time
|
|
|
while (digits-- > 0) { |
|
|
while (digits--) { |
|
|
remainder *= 10.0; |
|
|
remainder *= 10.0; |
|
|
int toPrint = int(remainder); |
|
|
int toPrint = int(remainder); |
|
|
print(toPrint); |
|
|
print(toPrint); |
|
|
remainder -= toPrint; |
|
|
remainder -= toPrint; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
// Preinstantiate Objects //////////////////////////////////////////////////////
|
|
|
// Preinstantiate Objects //////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
@ -534,4 +522,5 @@ MarlinSerial customizedSerial; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif |
|
|