-
Notifications
You must be signed in to change notification settings - Fork 36
/
usart.h
2546 lines (2120 loc) · 77.9 KB
/
usart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* \brief
*
* \author Jan Oleksiewicz <[email protected]>
* \license SPDX-License-Identifier: MIT
*/
#ifndef _USART_H_
#define _USART_H_
#include <avr/io.h> // for inline func
#include "usart_config.h"
#ifndef F_CPU
#warning F_CPU is undefined, USART may not work correctly without this
#endif
#define BAUD_CALC(x) ((F_CPU+(x)*8UL) / (16UL*(x))-1UL) // macro calculating precise UBRR value
#define BAUD_CALC_FAST(x) ((F_CPU)/((x)*16UL)-1) // for faster real time calculations ? // not recommended
#define DOUBLE_BAUD_CALC(x) ((F_CPU+(x)*4UL) / (8UL*(x))-1UL) // macro calculating UBRR value for double speed
#if !defined(__OPTIMIZE__)&&!defined(USART_NO_ABI_BREAKING_PREMATURES)
#warning Compiler optimizations disabled; functions from usart.h might not work as designed
#endif
#ifdef DEBUG
#define USART_NO_ABI_BREAKING_PREMATURES
#endif
#ifndef __AVR_ARCH__ // compiler fault ?
#define USART_NO_ABI_BREAKING_PREMATURES
#endif
#ifndef RX_BUFFER_SIZE
#define RX_BUFFER_SIZE 32 // Size of the ring buffers, must be power of 2
#endif
#ifndef TX_BUFFER_SIZE
#define TX_BUFFER_SIZE 32 // Size of the ring buffers, must be power of 2
#endif
#ifndef TX0_BUFFER_SIZE
#define TX0_BUFFER_SIZE TX_BUFFER_SIZE
#endif
#ifndef RX0_BUFFER_SIZE
#define RX0_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TX1_BUFFER_SIZE
#define TX1_BUFFER_SIZE TX_BUFFER_SIZE
#endif
#ifndef RX1_BUFFER_SIZE
#define RX1_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TX2_BUFFER_SIZE
#define TX2_BUFFER_SIZE TX_BUFFER_SIZE
#endif
#ifndef RX2_BUFFER_SIZE
#define RX2_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TX3_BUFFER_SIZE
#define TX3_BUFFER_SIZE TX_BUFFER_SIZE
#endif
#ifndef RX3_BUFFER_SIZE
#define RX3_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#define TX0_BUFFER_MASK (TX0_BUFFER_SIZE - 1)
#define RX0_BUFFER_MASK (RX0_BUFFER_SIZE - 1)
#define TX1_BUFFER_MASK (TX1_BUFFER_SIZE - 1)
#define RX1_BUFFER_MASK (RX1_BUFFER_SIZE - 1)
#define TX2_BUFFER_MASK (TX2_BUFFER_SIZE - 1)
#define RX2_BUFFER_MASK (RX2_BUFFER_SIZE - 1)
#define TX3_BUFFER_MASK (TX3_BUFFER_SIZE - 1)
#define RX3_BUFFER_MASK (RX3_BUFFER_SIZE - 1)
enum {COMPLETED = 1, BUFFER_EMPTY = 0, BUFFER_FULL = 0};
#if defined(URSEL)||defined(URSEL0)||defined(URSEL1)||defined(URSEL2)||defined(URSEL3)
#define USART_XCK_RISING_EDGE 0x80
#define USART_XCK_FALLING_EDGE 0x81
#define USART_5BIT_DATA 0x80
#define USART_6BIT_DATA 0x82
#define USART_7BIT_DATA 0x84
#define USART_8BIT_DATA 0x86
#define USART_1STOP_BIT 0x80
#define USART_2STOP_BITS 0x88
#define USART_NO_PARITY 0x80
#define USART_EVEN_PARITY 0xA0
#define USART_ODD_PARITY 0xB0
#define USART_ASYNC_MODE 0x80
#define USART_SYNC_MODE 0xC0
#else
#define USART_XCK_RISING_EDGE 0x00
#define USART_XCK_FALLING_EDGE 0x01
#define USART_5BIT_DATA 0x00
#define USART_6BIT_DATA 0x02
#define USART_7BIT_DATA 0x04
#define USART_8BIT_DATA 0x06
#define USART_1STOP_BIT 0x00
#define USART_2STOP_BITS 0x08
#define USART_NO_PARITY 0x00
#define USART_EVEN_PARITY 0x20
#define USART_ODD_PARITY 0x30
#define USART_ASYNC_MODE 0x00
#define USART_SYNC_MODE 0x40
#define USART_MSPI_MODE 0xC0
#endif
#define USART_8N1 (USART_8BIT_DATA|USART_NO_PARITY|USART_1STOP_BIT)
#define USART_8N2 (USART_8BIT_DATA|USART_NO_PARITY|USART_2STOP_BITS)
#define USART_8E1 (USART_8BIT_DATA|USART_EVEN_PARITY|USART_1STOP_BIT)
#define USART_8E2 (USART_8BIT_DATA|USART_EVEN_PARITY|USART_2STOP_BITS)
#define USART_8O1 (USART_8BIT_DATA|USART_ODD_PARITY|USART_1STOP_BIT)
#define USART_8O2 (USART_8BIT_DATA|USART_ODD_PARITY|USART_2STOP_BITS)
#define USART_7N1 (USART_7BIT_DATA|USART_NO_PARITY|USART_1STOP_BIT)
#define USART_7N2 (USART_7BIT_DATA|USART_NO_PARITY|USART_2STOP_BITS)
#define USART_7E1 (USART_7BIT_DATA|USART_EVEN_PARITY|USART_1STOP_BIT)
#define USART_7E2 (USART_7BIT_DATA|USART_EVEN_PARITY|USART_2STOP_BITS)
#define USART_7O1 (USART_7BIT_DATA|USART_ODD_PARITY|USART_1STOP_BIT)
#define USART_7O2 (USART_7BIT_DATA|USART_ODD_PARITY|USART_2STOP_BITS)
#ifdef NO_USART_RX // remove all RX interrupts
#define NO_RX0_INTERRUPT
#define NO_RX1_INTERRUPT
#define NO_RX2_INTERRUPT
#define NO_RX3_INTERRUPT
#endif
#ifdef NO_USART_TX // remove all TX interrupts
#define NO_TX0_INTERRUPT
#define NO_TX1_INTERRUPT
#define NO_TX2_INTERRUPT
#define NO_TX3_INTERRUPT
#endif
#ifdef USE_DOUBLE_SPEED
#define USART0_U2X_SPEED
#define USART1_U2X_SPEED
#define USART2_U2X_SPEED
#define USART3_U2X_SPEED
#endif
#ifdef RX_GETC_ECHO
#define RX0_GETC_ECHO
#define RX1_GETC_ECHO
#define RX2_GETC_ECHO
#define RX3_GETC_ECHO
#endif
#ifdef PUTC_CONVERT_LF_TO_CRLF
#define PUTC0_CONVERT_LF_TO_CRLF
#define PUTC1_CONVERT_LF_TO_CRLF
#define PUTC2_CONVERT_LF_TO_CRLF
#define PUTC3_CONVERT_LF_TO_CRLF
#endif
#ifdef USART_EXTEND_RX_BUFFER
#define USART0_EXTEND_RX_BUFFER
#define USART1_EXTEND_RX_BUFFER
#define USART2_EXTEND_RX_BUFFER
#define USART3_EXTEND_RX_BUFFER
#endif
#ifdef USART_PUTC_FAST_INSERTIONS
#define USART0_PUTC_FAST_INSERTIONS
#define USART1_PUTC_FAST_INSERTIONS
#define USART2_PUTC_FAST_INSERTIONS
#define USART3_PUTC_FAST_INSERTIONS
#endif
#ifdef USART_MPCM_MODE
#define USART0_MPCM_MODE
#define USART1_MPCM_MODE
#define USART2_MPCM_MODE
#define USART3_MPCM_MODE
#endif
#if defined(CTS0_DDR)&&defined(CTS0_PORT)&&defined(CTS0_PIN)&&defined(CTS0_IONUM)
#define USART0_USE_SOFT_CTS
#endif
#if defined(CTS1_DDR)&&defined(CTS1_PORT)&&defined(CTS1_PIN)&&defined(CTS1_IONUM)
#define USART1_USE_SOFT_CTS
#endif
#if defined(CTS2_DDR)&&defined(CTS2_PORT)&&defined(CTS2_PIN)&&defined(CTS2_IONUM)
#define USART2_USE_SOFT_CTS
#endif
#if defined(CTS3_DDR)&&defined(CTS3_PORT)&&defined(CTS3_PIN)&&defined(CTS3_IONUM)
#define USART3_USE_SOFT_CTS
#endif
#if defined(RTS0_DDR)&&defined(RTS0_PORT)&&defined(RTS0_PIN)&&defined(RTS0_IONUM)
#define USART0_USE_SOFT_RTS
#endif
#if defined(RTS1_DDR)&&defined(RTS1_PORT)&&defined(RTS1_PIN)&&defined(RTS1_IONUM)
#define USART1_USE_SOFT_RTS
#endif
#if defined(RTS2_DDR)&&defined(RTS2_PORT)&&defined(RTS2_PIN)&&defined(RTS2_IONUM)
#define USART2_USE_SOFT_RTS
#endif
#if defined(RTS3_DDR)&&defined(RTS3_PORT)&&defined(RTS3_PIN)&&defined(RTS3_IONUM)
#define USART3_USE_SOFT_RTS
#endif
#if defined(RS485_CONTROL0_DDR)&&defined(RS485_CONTROL0_PORT)&&defined(RS485_CONTROL0_PIN)&&defined(RS485_CONTROL0_IONUM)
#define USART0_RS485_MODE
#endif
#if defined(RS485_CONTROL1_DDR)&&defined(RS485_CONTROL1_PORT)&&defined(RS485_CONTROL1_PIN)&&defined(RS485_CONTROL1_IONUM)
#define USART1_RS485_MODE
#endif
#if defined(RS485_CONTROL2_DDR)&&defined(RS485_CONTROL2_PORT)&&defined(RS485_CONTROL2_PIN)&&defined(RS485_CONTROL2_IONUM)
#define USART2_RS485_MODE
#endif
#if defined(RS485_CONTROL3_DDR)&&defined(RS485_CONTROL3_PORT)&&defined(RS485_CONTROL3_PIN)&&defined(RS485_CONTROL3_IONUM)
#define USART3_RS485_MODE
#endif
#ifdef USART0_USE_SOFT_RTS
#ifndef USART0_EXTEND_RX_BUFFER
#define USART0_EXTEND_RX_BUFFER
#endif
#endif
#ifdef USART1_USE_SOFT_RTS
#ifndef USART1_EXTEND_RX_BUFFER
#define USART1_EXTEND_RX_BUFFER
#endif
#endif
#ifdef USART2_USE_SOFT_RTS
#ifndef USART2_EXTEND_RX_BUFFER
#define USART2_EXTEND_RX_BUFFER
#endif
#endif
#ifdef USART3_USE_SOFT_RTS
#ifndef USART3_EXTEND_RX_BUFFER
#define USART3_EXTEND_RX_BUFFER
#endif
#endif
#ifdef RX_NEWLINE_MODE
#if (RX_NEWLINE_MODE == 0)
#define RX_NEWLINE_MODE_R
#elif (RX_NEWLINE_MODE == 1)
#define RX_NEWLINE_MODE_N
#else // RX_NEWLINE_MODE == 2
#define RX_NEWLINE_MODE_RN
#endif
#else
#define RX_NEWLINE_MODE_RN // 2
#endif
#ifdef USART_USE_GLOBALLY_RESERVED_ISR_SREG_SAVE
register uint8_t USART_SREG_SAVE_REG_NAME asm(USART_SREG_SAVE_REG_NUM); // have to be defined separately in every compilation unit
#endif
#ifdef USART_USE_GLOBALLY_RESERVED_ISR_Z_SAVE
register uint16_t USART_Z_SAVE_REG_NAME asm(USART_Z_SAVE_REG_NUM); // have to be defined separately in every compilation unit
#endif
#if defined(USART_USE_GLOBALLY_RESERVED_ISR_SREG_SAVE)&&defined(USART_USE_GLOBALLY_RESERVED_ISR_Z_SAVE)
#define USART_REG_SAVE_LIST \
[sreg_save] "+r" (USART_SREG_SAVE_REG_NAME), \
[z_save] "+r" (USART_Z_SAVE_REG_NAME)
#elif defined(USART_USE_GLOBALLY_RESERVED_ISR_Z_SAVE)
#define USART_REG_SAVE_LIST \
[z_save] "+r" (USART_Z_SAVE_REG_NAME)
#elif defined(USART_USE_GLOBALLY_RESERVED_ISR_SREG_SAVE)
#define USART_REG_SAVE_LIST \
[sreg_save] "+r" (USART_SREG_SAVE_REG_NAME)
#else
#define USART_REG_SAVE_LIST
#endif
#if defined(__usbdrv_h_included__)&&!defined(USART_UNSAFE_RX_INTERRUPT)
#warning "usb may not work with uart's RX ISR"
#endif
#if defined(__usbdrv_h_included__)&&!defined(USART_UNSAFE_TX_INTERRUPT)
#warning "usb may not work with uart's TX ISR"
#endif
#if (defined(USART_USE_GLOBALLY_RESERVED_ISR_SREG_SAVE)||defined(USART_USE_GLOBALLY_RESERVED_ISR_Z_SAVE))&&(defined(USART_UNSAFE_TX_INTERRUPT)||defined(USART_UNSAFE_RX_INTERRUPT))
#warning "using globally reserved save registers with interruptable interrupts might create special conditions"
#endif
#if defined(__AVR_ATtiny102__)||defined(__AVR_ATtiny104__)||defined(__AVR_ATtiny2313__)||defined(__AVR_ATtiny2313A__)
#define USART_USE_TINY_MEMORY_MODEL
#endif
#if defined(__AVR_ATtiny102__)||defined(__AVR_ATtiny104__)
#if (TX0_BUFFER_SIZE > 8)||(RX0_BUFFER_SIZE > 8)
#warning "TX or RX buffer may be too large for this mcu"
#endif
#define USART0_IN_UPPER_IO_ADDRESS_SPACE
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RXC_vect
#define TXC0_INTERRUPT USART0_TXC_vect
#define UDRE0_INTERRUPT USART0_DRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#endif
#if defined(__AVR_ATtiny2313__)||defined(__AVR_ATtiny2313A__)||defined(__AVR_ATtiny4313)
#define USART0_IN_IO_ADDRESS_SPACE
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART_RX_vect
#define TXC0_INTERRUPT USART_TX_vect
#define UDRE0_INTERRUPT USART_UDRE_vect
#define UDR0_REGISTER UDR
#define UBRR0L_REGISTER UBRRL
#define UBRR0H_REGISTER UBRRH
#define UCSR0A_REGISTER UCSRA
#define UCSR0B_REGISTER UCSRB
#define UCSR0C_REGISTER UCSRC
#define TXCIE0_BIT TXCIE
#define UDRIE0_BIT UDRIE
#define RXCIE0_BIT RXCIE
#define TXEN0_BIT TXEN
#define RXEN0_BIT RXEN
#define UDRE0_BIT UDRE
#define RXC0_BIT RXC
#define U2X0_BIT U2X
#define MPCM0_BIT MPCM
#define UCSZ02_BIT UCSZ2
#define TXB80_BIT TXB8
#endif //NO_USART0
#endif
#if defined(__AVR_ATtiny1634__)
#define USART0_IN_UPPER_IO_ADDRESS_SPACE
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#ifndef NO_USART1
#define USE_USART1
#define RX1_INTERRUPT USART1_RX_vect
#define TXC1_INTERRUPT USART1_TX_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81
#endif //NO_USART1
#endif
#if defined(__AVR_ATtiny441__)||defined(__AVR_ATtiny841__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#ifndef NO_USART1
#define USE_USART1
#define RX1_INTERRUPT USART1_RX_vect
#define TXC1_INTERRUPT USART1_TX_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81
#endif //NO_USART1
#endif
#if defined(__AVR_ATmega48__)||defined(__AVR_ATmega48P__)||defined(__AVR_ATmega48PA__)||defined(__AVR_ATmega48PB__)\
||defined(__AVR_ATmega88__)||defined(__AVR_ATmega88P__)||defined(__AVR_ATmega88PA__)||defined(__AVR_ATmega88PB__)\
||defined(__AVR_ATmega168__)||defined(__AVR_ATmega168P__)||defined(__AVR_ATmega168PA__)||defined(__AVR_ATmega168PB__)\
||defined(__AVR_ATmega328__)||defined(__AVR_ATmega328P__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART_RX_vect
#define TXC0_INTERRUPT USART_TX_vect
#define UDRE0_INTERRUPT USART_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#endif
#if defined(__AVR_ATmega328PB__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#ifndef NO_USART1
#define USE_USART1
#define RX1_INTERRUPT USART1_RX_vect
#define TXC1_INTERRUPT USART1_TX_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81
#endif //NO_USART1
#endif
#if defined(__AVR_ATmega8__)||defined(__AVR_ATmega8P__)||defined(__AVR_ATmega16__)\
||defined(__AVR_ATmega16A__)||defined(__AVR_ATmega32__)||defined(__AVR_ATmega32A__)\
||defined(__AVR_ATmega8A__)||defined(__AVR_ATmega8L__)
#define USART0_IN_IO_ADDRESS_SPACE
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART_RXC_vect
#define TXC0_INTERRUPT USART_TXC_vect
#define UDRE0_INTERRUPT USART_UDRE_vect
#define UDR0_REGISTER UDR
#define UBRR0L_REGISTER UBRRL
#define UBRR0H_REGISTER UBRRH
#define UCSR0A_REGISTER UCSRA
#define UCSR0B_REGISTER UCSRB
#define UCSR0C_REGISTER UCSRC
#define TXCIE0_BIT TXCIE
#define UDRIE0_BIT UDRIE
#define RXCIE0_BIT RXCIE
#define TXEN0_BIT TXEN
#define RXEN0_BIT RXEN
#define UDRE0_BIT UDRE
#define RXC0_BIT RXC
#define U2X0_BIT U2X
#define MPCM0_BIT MPCM
#define UCSZ02_BIT UCSZ2
#define TXB80_BIT TXB8
#endif //NO_USART0
#endif
#if defined(__AVR_ATmega8515__)||defined(__AVR_ATmega8515L__)
#define USART0_IN_IO_ADDRESS_SPACE
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART_RX_vect
#define TXC0_INTERRUPT USART_TX_vect
#define UDRE0_INTERRUPT USART_UDRE_vect
#define UDR0_REGISTER UDR
#define UBRR0L_REGISTER UBRRL
#define UBRR0H_REGISTER UBRRH
#define UCSR0A_REGISTER UCSRA
#define UCSR0B_REGISTER UCSRB
#define UCSR0C_REGISTER UCSRC
#define TXCIE0_BIT TXCIE
#define UDRIE0_BIT UDRIE
#define RXCIE0_BIT RXCIE
#define TXEN0_BIT TXEN
#define RXEN0_BIT RXEN
#define UDRE0_BIT UDRE
#define RXC0_BIT RXC
#define U2X0_BIT U2X
#define MPCM0_BIT MPCM
#define UCSZ02_BIT UCSZ2
#define TXB80_BIT TXB8
#endif //NO_USART0
#endif
#if defined(__AVR_ATmega162__)
#define USART0_IN_IO_ADDRESS_SPACE
#define USART1_IN_IO_ADDRESS_SPACE
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RXC_vect
#define TXC0_INTERRUPT USART0_TXC_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#ifndef NO_USART1
#define USE_USART1
#define RX1_INTERRUPT USART1_RXC_vect
#define TXC1_INTERRUPT USART1_TXC_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81
#endif //NO_USART1
#endif
#if defined(__AVR_ATmega128__)||defined(__AVR_ATmega128A__)||defined(__AVR_ATmega64__)\
||defined(__AVR_ATmega64A__)
#define USART0_IN_IO_ADDRESS_SPACE
#endif
#if defined(__AVR_ATmega644__)||defined(__AVR_ATmega644P__)||defined(__AVR_ATmega644PA__)\
||defined(__AVR_ATmega1284__)||defined(__AVR_ATmega1284P__)||defined(__AVR_ATmega128__)\
||defined(__AVR_ATmega128A__)||defined(__AVR_ATmega64__)||defined(__AVR_ATmega64A__)\
||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)||defined(__AVR_ATmega640__)\
||defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__)||defined(__AVR_ATmega164P__)\
||defined(__AVR_ATmega324P__)||defined(__AVR_ATmega324A__)||defined(__AVR_ATmega324PA__)\
||defined(__AVR_ATmega324PB__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif
#if !defined(NO_USART1) && !defined(__AVR_ATmega644__)
#define USE_USART1
#define RX1_INTERRUPT USART1_RX_vect
#define TXC1_INTERRUPT USART1_TX_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81
#endif // NO_USART1 && 644
#endif
#if defined(__AVR_ATmega640__)||defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__)||defined(__AVR_ATmega324PB__)
#ifndef NO_USART2
#define USE_USART2
#define RX2_INTERRUPT USART2_RX_vect
#define TXC2_INTERRUPT USART2_TX_vect
#define UDRE2_INTERRUPT USART2_UDRE_vect
#define UDR2_REGISTER UDR2
#define UBRR2L_REGISTER UBRR2L
#define UBRR2H_REGISTER UBRR2H
#define UCSR2A_REGISTER UCSR2A
#define UCSR2B_REGISTER UCSR2B
#define UCSR2C_REGISTER UCSR2C
#define TXCIE2_BIT TXCIE2
#define UDRIE2_BIT UDRIE2
#define RXCIE2_BIT RXCIE2
#define TXEN2_BIT TXEN2
#define RXEN2_BIT RXEN2
#define UDRE2_BIT UDRE2
#define RXC2_BIT RXC2
#define U2X2_BIT U2X2
#define MPCM2_BIT MPCM2
#define UCSZ22_BIT UCSZ22
#define TXB82_BIT TXB82
#endif // NO_USART2
#if !defined(NO_USART3)&&!defined(__AVR_ATmega324PB__)
#define USE_USART3
#define RX3_INTERRUPT USART3_RX_vect
#define TXC3_INTERRUPT USART3_TX_vect
#define UDRE3_INTERRUPT USART3_UDRE_vect
#define UDR3_REGISTER UDR3
#define UBRR3L_REGISTER UBRR3L
#define UBRR3H_REGISTER UBRR3H
#define UCSR3A_REGISTER UCSR3A
#define UCSR3B_REGISTER UCSR3B
#define UCSR3C_REGISTER UCSR3C
#define TXCIE3_BIT TXCIE3
#define UDRIE3_BIT UDRIE3
#define RXCIE3_BIT RXCIE3
#define TXEN3_BIT TXEN3
#define RXEN3_BIT RXEN3
#define UDRE3_BIT UDRE3
#define RXC3_BIT RXC3
#define U2X3_BIT U2X3
#define MPCM3_BIT MPCM3
#define UCSZ32_BIT UCSZ32
#define TXB83_BIT TXB83
#endif // NO_USART3
#endif // 640/1280/2560 usart 2 & 3
#if defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega16U4__)\
||defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U6__)\
||defined(__AVR_AT90USB82__)||defined(__AVR_AT90USB162__)
#define USART1_HARDWARE_FLOW_CONTROL_AVAILABLE
#ifndef NO_USART1 // we will call the only usart, as an usart0
#define USE_USART1
#define RX1_INTERRUPT USART1_RX_vect
#define TXC1_INTERRUPT USART1_TX_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define UCSR1D_REGISTER UCSR1D
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81
#define CTSEN1_BIT CTSEN
#define RTSEN1_BIT RTSEN
#endif // NO_USART1
#endif
#if defined(__AVR_ATmega169A__)||defined(__AVR_ATmega169__)||defined(__AVR_ATmega169P__)||defined(__AVR_ATmega169PA__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR
#define UBRR0L_REGISTER UBRRL
#define UBRR0H_REGISTER UBRRH
#define UCSR0A_REGISTER UCSRA
#define UCSR0B_REGISTER UCSRB
#define UCSR0C_REGISTER UCSRC
#define TXCIE0_BIT TXCIE
#define UDRIE0_BIT UDRIE
#define RXCIE0_BIT RXCIE
#define TXEN0_BIT TXEN
#define RXEN0_BIT RXEN
#define UDRE0_BIT UDRE
#define RXC0_BIT RXC
#define U2X0_BIT U2X
#define MPCM0_BIT MPCM
#define UCSZ02_BIT UCSZ2
#define TXB80_BIT TXB8
#endif //NO_USART0
#endif
#if defined(__AVR_ATmega329__)||defined(__AVR_ATmega329P__)||defined(__AVR_ATmega329PA__)\
||defined(__AVR_ATmega329A__)||defined(__AVR_ATmega649__)||defined(__AVR_ATmega649A__)\
||defined(__AVR_ATmega649P__)||defined(__AVR_ATmega169P__)||defined(__AVR_ATmega169PA__)\
||defined(__AVR_ATmega325__)||defined(__AVR_ATmega325A__)||defined(__AVR_ATmega325P__)\
||defined(__AVR_ATmega325PA__)||defined(__AVR_ATmega645__)||defined(__AVR_ATmega645A__)\
||defined(__AVR_ATmega645P__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#endif
#if defined(__AVR_ATmega3290__)||defined(__AVR_ATmega6490__)||defined(__AVR_ATmega3290P__)\
||defined(__AVR_ATmega3290PA__)||defined(__AVR_ATmega3290A__)||defined(__AVR_ATmega6490A__)\
||defined(__AVR_ATmega6490P__)||defined(__AVR_ATmega3250__)||defined(__AVR_ATmega3250A__)\
||defined(__AVR_ATmega3250P__)||defined(__AVR_ATmega3250PA__)||defined(__AVR_ATmega6450__)\
||defined(__AVR_ATmega6450A__)||defined(__AVR_ATmega6450P__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART_RX_vect // wtf
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif //NO_USART0
#endif
#if defined(__AVR_AT90CAN32__)||defined(__AVR_AT90CAN64__)||defined(__AVR_AT90CAN128__)\
||defined(__AVR_ATmega64RFR2__)||defined(__AVR_ATmega128RFR2__)||defined(__AVR_ATmega256RFR2__)\
||defined(__AVR_ATmega644RFR2__)||defined(__AVR_ATmega1284RFR2__)||defined(__AVR_ATmega2564RFR2__)\
||defined(__AVR_ATmega128RFA1__)
#ifndef NO_USART0
#define USE_USART0
#define RX0_INTERRUPT USART0_RX_vect
#define TXC0_INTERRUPT USART0_TX_vect
#define UDRE0_INTERRUPT USART0_UDRE_vect
#define UDR0_REGISTER UDR0
#define UBRR0L_REGISTER UBRR0L
#define UBRR0H_REGISTER UBRR0H
#define UCSR0A_REGISTER UCSR0A
#define UCSR0B_REGISTER UCSR0B
#define UCSR0C_REGISTER UCSR0C
#define TXCIE0_BIT TXCIE0
#define UDRIE0_BIT UDRIE0
#define RXCIE0_BIT RXCIE0
#define TXEN0_BIT TXEN0
#define RXEN0_BIT RXEN0
#define UDRE0_BIT UDRE0
#define RXC0_BIT RXC0
#define U2X0_BIT U2X0
#define MPCM0_BIT MPCM0
#define UCSZ02_BIT UCSZ02
#define TXB80_BIT TXB80
#endif // NO_USART0
#ifndef NO_USART1
#define USE_USART1
#define RX1_INTERRUPT USART1_RX_vect
#define TXC1_INTERRUPT USART1_TX_vect
#define UDRE1_INTERRUPT USART1_UDRE_vect
#define UDR1_REGISTER UDR1
#define UBRR1L_REGISTER UBRR1L
#define UBRR1H_REGISTER UBRR1H
#define UCSR1A_REGISTER UCSR1A
#define UCSR1B_REGISTER UCSR1B
#define UCSR1C_REGISTER UCSR1C
#define TXCIE1_BIT TXCIE1
#define UDRIE1_BIT UDRIE1
#define RXCIE1_BIT RXCIE1
#define TXEN1_BIT TXEN1
#define RXEN1_BIT RXEN1
#define UDRE1_BIT UDRE1
#define RXC1_BIT RXC1
#define U2X1_BIT U2X1
#define MPCM1_BIT MPCM1
#define UCSZ12_BIT UCSZ12
#define TXB81_BIT TXB81