From 1e5d73579cd0781e8ea50aeb8bc11ec53ce23171 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 21 Jul 2020 14:43:43 -0500 Subject: [PATCH] Anycubic followup --- .../extui/lib/anycubic/anycubic_serial.cpp | 16 ++++------ .../lcd/extui/lib/anycubic/anycubic_serial.h | 32 ++++++++++--------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.cpp b/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.cpp index 3fad103bb4..fd5f2691bd 100644 --- a/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.cpp @@ -29,10 +29,10 @@ #if ENABLED(ANYCUBIC_TFT_MODEL) -#include "Arduino.h" +#include -// this next line disables the entire HardwareSerial.cpp, -// so I can support AtTiny series and other chips without a UART +// This next line disables the entire anycubic_serial.cpp, +// to support AtTiny series and other chips without a UART #ifdef UBRR3H #include "anycubic_serial.h" @@ -59,10 +59,8 @@ struct ring_buffer { volatile unsigned int tail; }; -#ifdef UBRR3H - ring_buffer rx_buffer_ajg = { { 0 }, 0, 0 }; - ring_buffer tx_buffer_ajg = { { 0 }, 0, 0 }; -#endif +ring_buffer rx_buffer_ajg = { { 0 }, 0, 0 }; +ring_buffer tx_buffer_ajg = { { 0 }, 0, 0 }; inline void store_char(unsigned char c, ring_buffer *buffer) { int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE; @@ -286,9 +284,7 @@ AnycubicSerialClass::operator bool() { // Preinstantiate Objects ////////////////////////////////////////////////////// -#ifdef UBRR3H - AnycubicSerialClass AnycubicSerial(&rx_buffer_ajg, &tx_buffer_ajg, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3); -#endif +AnycubicSerialClass AnycubicSerial(&rx_buffer_ajg, &tx_buffer_ajg, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3); #endif // UBRR3H #endif // ANYCUBIC_TFT_MODEL diff --git a/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.h b/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.h index a568a50c98..ed4c19b63e 100644 --- a/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.h +++ b/Marlin/src/lcd/extui/lib/anycubic/anycubic_serial.h @@ -103,15 +103,15 @@ class AnycubicSerialClass : public Stream { extern void serialEventRun(void) __attribute__((weak)); #define ANYCUBIC_SERIAL_PROTOCOL(x) (AnycubicSerial.print(x)) -#define ANYCUBIC_SERIAL_PROTOCOL_F(x,y) (AnycubicSerial.print(x,y)) +#define ANYCUBIC_SERIAL_PROTOCOL_F(x,y) (AnycubicSerial.print(x, y)) #define ANYCUBIC_SERIAL_PROTOCOLPGM(x) (AnycubicSerialprintPGM(PSTR(x))) -#define ANYCUBIC_SERIAL_(x) (AnycubicSerial.print(x),AnycubicSerial.write('\n')) -#define ANYCUBIC_SERIAL_PROTOCOLLN(x) (AnycubicSerial.print(x),AnycubicSerial.write('\r'),AnycubicSerial.write('\n')) -#define ANYCUBIC_SERIAL_PROTOCOLLNPGM(x) (AnycubicSerialprintPGM(PSTR(x)),AnycubicSerial.write('\r'),AnycubicSerial.write('\n')) +#define ANYCUBIC_SERIAL_(x) (AnycubicSerial.print(x), AnycubicSerial.write('\n')) +#define ANYCUBIC_SERIAL_PROTOCOLLN(x) (AnycubicSerial.print(x), AnycubicSerial.write('\r'), AnycubicSerial.write('\n')) +#define ANYCUBIC_SERIAL_PROTOCOLLNPGM(x) (AnycubicSerialprintPGM(PSTR(x)), AnycubicSerial.write('\r'), AnycubicSerial.write('\n')) -#define ANYCUBIC_SERIAL_START() (AnycubicSerial.write('\r'),AnycubicSerial.write('\n')) -#define ANYCUBIC_SERIAL_CMD_SEND(x) (AnycubicSerialprintPGM(PSTR(x)),AnycubicSerial.write('\r'),AnycubicSerial.write('\n')) -#define ANYCUBIC_SERIAL_ENTER() (AnycubicSerial.write('\r'),AnycubicSerial.write('\n')) +#define ANYCUBIC_SERIAL_START() (AnycubicSerial.write('\r'), AnycubicSerial.write('\n')) +#define ANYCUBIC_SERIAL_CMD_SEND(x) (AnycubicSerialprintPGM(PSTR(x)), AnycubicSerial.write('\r'), AnycubicSerial.write('\n')) +#define ANYCUBIC_SERIAL_ENTER() (AnycubicSerial.write('\r'), AnycubicSerial.write('\n')) #define ANYCUBIC_SERIAL_SPACE() (AnycubicSerial.write(' ')) const char newErr[] PROGMEM = "ERR "; @@ -130,14 +130,16 @@ const char newSucc[] PROGMEM = "OK"; #define ANYCUBIC_SERIAL_ECHOPGM(x) ANYCUBIC_SERIAL_PROTOCOLPGM(x) #define ANYCUBIC_SERIAL_ECHO(x) ANYCUBIC_SERIAL_PROTOCOL(x) -FORCE_INLINE void AnycubicSerialprintPGM(const char *str) { - char ch = pgm_read_byte(str); - while (ch) { - AnycubicSerialClass::write(ch); - ch = pgm_read_byte(++str); - } -} - #ifdef UBRR3H + extern AnycubicSerialClass AnycubicSerial; + + FORCE_INLINE void AnycubicSerialprintPGM(const char *str) { + char ch = pgm_read_byte(str); + while (ch) { + AnycubicSerial.write(ch); + ch = pgm_read_byte(++str); + } + } + #endif