28
28
#include " Arduino.h"
29
29
#include " wiring_private.h"
30
30
31
+ #include " HardwareSerial.h"
32
+
31
33
// this next line disables the entire HardwareSerial.cpp,
32
34
// this is so I can support Attiny series and any other chip without a uart
33
- #if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
34
-
35
- #include " HardwareSerial.h"
35
+ #if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
36
36
37
37
// Ensure that the various bit positions we use are available with a 0
38
38
// postfix, so we can always use the values for UART0 for all UARTs. The
84
84
#error "Not all bit positions for UART3 are the same as for UART0"
85
85
#endif
86
86
87
- #if !defined(USART0_RX_vect) && defined(USART1_RX_vect)
88
- // do nothing - on the 32u4 the first USART is USART1
89
- #else
90
- #if !defined(USART_RX_vect) && !defined(USART0_RX_vect) && \
91
- !defined(USART_RXC_vect)
92
- #error "Don't know what the Data Received vector is called for the first UART"
93
- #else
87
+ #if defined(HAVE_HWSERIAL0)
94
88
void serialEvent () __attribute__((weak));
95
89
void serialEvent () {}
96
- #define serialEvent_implemented
97
90
#if defined(USART_RX_vect)
98
91
ISR (USART_RX_vect)
99
92
#elif defined(USART0_RX_vect)
100
93
ISR (USART0_RX_vect)
101
94
#elif defined(USART_RXC_vect)
102
95
ISR (USART_RXC_vect) // ATmega8
96
+ #else
97
+ #error "Don't know what the Data Received vector is called for the first UART"
103
98
#endif
104
99
{
105
100
Serial._rx_complete_irq ();
106
101
}
107
102
#endif
108
- #endif
109
103
110
- #if defined(USART1_RX_vect )
104
+ #if defined(HAVE_HWSERIAL1 )
111
105
void serialEvent1 () __attribute__((weak));
112
106
void serialEvent1 () {}
113
- #define serialEvent1_implemented
114
107
ISR (USART1_RX_vect)
115
108
{
116
109
Serial1._rx_complete_irq ();
117
110
}
118
111
#endif
119
112
120
- #if defined(USART2_RX_vect) && defined(UDR2 )
113
+ #if defined(HAVE_HWSERIAL2 )
121
114
void serialEvent2 () __attribute__((weak));
122
115
void serialEvent2 () {}
123
- #define serialEvent2_implemented
124
116
ISR (USART2_RX_vect)
125
117
{
126
118
Serial2._rx_complete_irq ();
127
119
}
128
120
#endif
129
121
130
- #if defined(USART3_RX_vect) && defined(UDR3 )
122
+ #if defined(HAVE_HWSERIAL3 )
131
123
void serialEvent3 () __attribute__((weak));
132
124
void serialEvent3 () {}
133
- #define serialEvent3_implemented
134
125
ISR (USART3_RX_vect)
135
126
{
136
127
Serial3._rx_complete_irq ();
139
130
140
131
void serialEventRun (void )
141
132
{
142
- #ifdef serialEvent_implemented
133
+ #if defined(HAVE_HWSERIAL0)
143
134
if (Serial.available ()) serialEvent ();
144
135
#endif
145
- #ifdef serialEvent1_implemented
136
+ #if defined(HAVE_HWSERIAL1)
146
137
if (Serial1.available ()) serialEvent1 ();
147
138
#endif
148
- #ifdef serialEvent2_implemented
139
+ #if defined(HAVE_HWSERIAL2)
149
140
if (Serial2.available ()) serialEvent2 ();
150
141
#endif
151
- #ifdef serialEvent3_implemented
142
+ #if defined(HAVE_HWSERIAL3)
152
143
if (Serial3.available ()) serialEvent3 ();
153
144
#endif
154
145
}
155
146
156
147
157
- #if !defined(USART0_UDRE_vect) && defined(USART1_UDRE_vect)
158
- // do nothing - on the 32u4 the first USART is USART1
159
- #else
160
- #if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
161
- #error "Don't know what the Data Register Empty vector is called for the first UART"
162
- #else
148
+ #if defined(HAVE_HWSERIAL0)
163
149
#if defined(UART0_UDRE_vect)
164
150
ISR (UART0_UDRE_vect)
165
151
#elif defined(UART_UDRE_vect)
@@ -168,28 +154,29 @@ ISR(UART_UDRE_vect)
168
154
ISR (USART0_UDRE_vect)
169
155
#elif defined(USART_UDRE_vect)
170
156
ISR (USART_UDRE_vect)
157
+ #else
158
+ #error "Don't know what the Data Register Empty vector is called for the first UART"
171
159
#endif
172
160
{
173
161
Serial._tx_udr_empty_irq ();
174
162
}
175
163
#endif
176
- #endif
177
164
178
- #ifdef USART1_UDRE_vect
165
+ #if defined(HAVE_HWSERIAL1)
179
166
ISR (USART1_UDRE_vect)
180
167
{
181
168
Serial1._tx_udr_empty_irq ();
182
169
}
183
170
#endif
184
171
185
- #ifdef USART2_UDRE_vect
172
+ #if defined(HAVE_HWSERIAL2)
186
173
ISR (USART2_UDRE_vect)
187
174
{
188
175
Serial2._tx_udr_empty_irq ();
189
176
}
190
177
#endif
191
178
192
- #ifdef USART3_UDRE_vect
179
+ #if defined(HAVE_HWSERIAL3)
193
180
ISR (USART3_UDRE_vect)
194
181
{
195
182
Serial3._tx_udr_empty_irq ();
@@ -386,23 +373,21 @@ size_t HardwareSerial::write(uint8_t c)
386
373
387
374
// Preinstantiate Objects //////////////////////////////////////////////////////
388
375
376
+ #if defined(HAVE_HWSERIAL0)
389
377
#if defined(UBRRH) && defined(UBRRL)
390
378
HardwareSerial Serial (&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR);
391
- #elif defined(UBRR0H) && defined(UBRR0L)
392
- HardwareSerial Serial (&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0);
393
- #elif defined(USBCON)
394
- // do nothing - Serial object and buffers are initialized in CDC code
395
379
#else
396
- #error no serial port defined (port 0)
380
+ HardwareSerial Serial (&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0);
381
+ #endif
397
382
#endif
398
383
399
- #if defined(UBRR1H )
384
+ #if defined(HAVE_HWSERIAL1 )
400
385
HardwareSerial Serial1 (&UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1);
401
386
#endif
402
- #if defined(UBRR2H )
387
+ #if defined(HAVE_HWSERIAL2 )
403
388
HardwareSerial Serial2 (&UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2);
404
389
#endif
405
- #if defined(UBRR3H )
390
+ #if defined(HAVE_HWSERIAL3 )
406
391
HardwareSerial Serial3 (&UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3);
407
392
#endif
408
393
0 commit comments