22 #ifndef MarlinSerial_h
23 #define MarlinSerial_h
26 #if !defined(SERIAL_PORT)
31 #if ((SERIAL_PORT == 0 && (defined(UBRRH) || defined(UBRR0H))) || \
32 (SERIAL_PORT == 1 && defined(UBRR1H)) || \
33 (SERIAL_PORT == 2 && defined(UBRR2H)) || \
34 (SERIAL_PORT == 3 && defined(UBRR3H)))
40 #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0))
41 #define SERIAL_REGNAME(registerbase,number,suffix) _REGNAME_SHORT(registerbase, suffix)
43 #define SERIAL_REGNAME(registerbase,number,suffix) _REGNAME(registerbase, number, suffix)
48 #define M_UCSRxA SERIAL_REGNAME(UCSR,SERIAL_PORT,A)
49 #define M_UCSRxB SERIAL_REGNAME(UCSR,SERIAL_PORT,B)
50 #define M_RXENx SERIAL_REGNAME(RXEN,SERIAL_PORT,)
51 #define M_TXENx SERIAL_REGNAME(TXEN,SERIAL_PORT,)
52 #define M_RXCIEx SERIAL_REGNAME(RXCIE,SERIAL_PORT,)
53 #define M_UDREx SERIAL_REGNAME(UDRE,SERIAL_PORT,)
54 #define M_UDRx SERIAL_REGNAME(UDR,SERIAL_PORT,)
55 #define M_UBRRxH SERIAL_REGNAME(UBRR,SERIAL_PORT,H)
56 #define M_UBRRxL SERIAL_REGNAME(UBRR,SERIAL_PORT,L)
57 #define M_RXCx SERIAL_REGNAME(RXC,SERIAL_PORT,)
58 #define M_FEx SERIAL_REGNAME(FE,SERIAL_PORT,)
59 #define M_USARTx_RX_vect SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)
60 #define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,)
76 #define RX_BUFFER_SIZE 128
78 extern uint8_t selectedSerialPort;
82 unsigned char buffer[RX_BUFFER_SIZE];
95 static void begin(
long);
97 static int peek(
void);
98 static int read(
void);
99 static void flush(
void);
101 static int available(
void)
103 return (
unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
114 static void write(uint8_t c)
116 if (selectedSerialPort == 0)
118 while (!((M_UCSRxA) & (1 << M_UDREx)));
121 else if (selectedSerialPort == 1)
123 while (!((UCSR1A) & (1 << UDRE1)));
128 static void checkRx(
void)
130 if (selectedSerialPort == 0) {
131 if((M_UCSRxA & (1<<M_RXCx)) != 0) {
133 if (M_UCSRxA & (1<<M_FEx)) {
136 (void)(*(
char *)M_UDRx);
138 unsigned char c = M_UDRx;
139 int i = (
unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
144 if (i != rx_buffer.tail) {
145 rx_buffer.buffer[rx_buffer.head] = c;
149 #ifdef DEBUG_DUMP_TO_2ND_SERIAL
155 if((UCSR1A & (1<<RXC1)) != 0) {
157 if (UCSR1A & (1<<FE1)) {
160 (void)(*(
char *)UDR1);
162 unsigned char c = UDR1;
163 int i = (
unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
168 if (i != rx_buffer.tail) {
169 rx_buffer.buffer[rx_buffer.head] = c;
173 #ifdef DEBUG_DUMP_TO_2ND_SERIAL
183 static void printNumber(
unsigned long, uint8_t);
184 static void printFloat(
double, uint8_t);
189 static void write(
const char *str)
196 static void write(
const uint8_t *buffer,
size_t size)
209 static FORCE_INLINE
void print(
const char *str)
213 static void print(
char,
int = BYTE);
214 static void print(
unsigned char,
int = BYTE);
215 static void print(
int,
int = DEC);
216 static void print(
unsigned int,
int = DEC);
217 static void print(
long,
int = DEC);
218 static void print(
unsigned long,
int = DEC);
219 static void print(
double,
int = 2);
222 static void println(
const char[]);
223 static void println(
char,
int = BYTE);
224 static void println(
unsigned char,
int = BYTE);
225 static void println(
int,
int = DEC);
226 static void println(
unsigned int,
int = DEC);
227 static void println(
long,
int = DEC);
228 static void println(
unsigned long,
int = DEC);
229 static void println(
double,
int = 2);
230 static void println(
void);
237 #if defined(AT90USB) && defined (BTENABLED)
238 extern HardwareSerial bt;
Definition: MarlinSerial.h:92
Definition: MarlinSerial.h:81