|
@@ -75,22 +75,9 @@ inline void store_char(unsigned char c)
|
75
|
75
|
|
76
|
76
|
// Constructors ////////////////////////////////////////////////////////////////
|
77
|
77
|
|
78
|
|
-MarlinSerial::MarlinSerial(
|
79
|
|
- volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
|
80
|
|
- volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
|
81
|
|
- volatile uint8_t *udr,
|
82
|
|
- uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
|
|
78
|
+MarlinSerial::MarlinSerial()
|
83
|
79
|
{
|
84
|
|
- _ubrrh = ubrrh;
|
85
|
|
- _ubrrl = ubrrl;
|
86
|
|
- _ucsra = ucsra;
|
87
|
|
- _ucsrb = ucsrb;
|
88
|
|
- _udr = udr;
|
89
|
|
- _rxen = rxen;
|
90
|
|
- _txen = txen;
|
91
|
|
- _rxcie = rxcie;
|
92
|
|
- _udre = udre;
|
93
|
|
- _u2x = u2x;
|
|
80
|
+
|
94
|
81
|
}
|
95
|
82
|
|
96
|
83
|
// Public Methods //////////////////////////////////////////////////////////////
|
|
@@ -98,39 +85,39 @@ MarlinSerial::MarlinSerial(
|
98
|
85
|
void MarlinSerial::begin(long baud)
|
99
|
86
|
{
|
100
|
87
|
uint16_t baud_setting;
|
101
|
|
- bool use_u2x = true;
|
|
88
|
+ bool useU2X0 = true;
|
102
|
89
|
|
103
|
90
|
#if F_CPU == 16000000UL
|
104
|
91
|
// hardcoded exception for compatibility with the bootloader shipped
|
105
|
92
|
// with the Duemilanove and previous boards and the firmware on the 8U2
|
106
|
93
|
// on the Uno and Mega 2560.
|
107
|
94
|
if (baud == 57600) {
|
108
|
|
- use_u2x = false;
|
|
95
|
+ useU2X0 = false;
|
109
|
96
|
}
|
110
|
97
|
#endif
|
111
|
98
|
|
112
|
|
- if (use_u2x) {
|
113
|
|
- *_ucsra = 1 << _u2x;
|
|
99
|
+ if (useU2X0) {
|
|
100
|
+ UCSR0A = 1 << U2X0;
|
114
|
101
|
baud_setting = (F_CPU / 4 / baud - 1) / 2;
|
115
|
102
|
} else {
|
116
|
|
- *_ucsra = 0;
|
|
103
|
+ UCSR0A = 0;
|
117
|
104
|
baud_setting = (F_CPU / 8 / baud - 1) / 2;
|
118
|
105
|
}
|
119
|
106
|
|
120
|
107
|
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
|
121
|
|
- *_ubrrh = baud_setting >> 8;
|
122
|
|
- *_ubrrl = baud_setting;
|
|
108
|
+ UBRR0H = baud_setting >> 8;
|
|
109
|
+ UBRR0L = baud_setting;
|
123
|
110
|
|
124
|
|
- sbi(*_ucsrb, _rxen);
|
125
|
|
- sbi(*_ucsrb, _txen);
|
126
|
|
- sbi(*_ucsrb, _rxcie);
|
|
111
|
+ sbi(UCSR0B, RXEN0);
|
|
112
|
+ sbi(UCSR0B, TXEN0);
|
|
113
|
+ sbi(UCSR0B, RXCIE0);
|
127
|
114
|
}
|
128
|
115
|
|
129
|
116
|
void MarlinSerial::end()
|
130
|
117
|
{
|
131
|
|
- cbi(*_ucsrb, _rxen);
|
132
|
|
- cbi(*_ucsrb, _txen);
|
133
|
|
- cbi(*_ucsrb, _rxcie);
|
|
118
|
+ cbi(UCSR0B, RXEN0);
|
|
119
|
+ cbi(UCSR0B, TXEN0);
|
|
120
|
+ cbi(UCSR0B, RXCIE0);
|
134
|
121
|
}
|
135
|
122
|
|
136
|
123
|
|
|
@@ -367,7 +354,7 @@ void MarlinSerial::printFloat(double number, uint8_t digits)
|
367
|
354
|
// Preinstantiate Objects //////////////////////////////////////////////////////
|
368
|
355
|
|
369
|
356
|
#if defined(UBRR0H) && defined(UBRR0L)
|
370
|
|
- MarlinSerial MSerial( &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
|
|
357
|
+ MarlinSerial MSerial;
|
371
|
358
|
#else
|
372
|
359
|
#error no serial port defined (port 0)
|
373
|
360
|
#endif
|