1////////////////////////////////////////////////////////////////////////////////
2// //
3// This software is supplied under the terms of a license agreement or //
4// nondisclosure agreement with Mitov Software and may not be copied //
5// or disclosed except in accordance with the terms of that agreement. //
6// Copyright(c) 2002-2016 Mitov Software. All Rights Reserved. //
7// //
8////////////////////////////////////////////////////////////////////////////////
9
10#ifndef _MITOV_USART_SERIAL_h
11#define _MITOV_USART_SERIAL_h
12
13#include <Mitov.h>
14
15namespace Mitov
16{
17 const USARTClass::USARTModes CUSARTSerialInits[] =
18 {
19 SERIAL_5N1,
20 SERIAL_6N1,
21 SERIAL_7N1,
22 SERIAL_8N2,
23
24 SERIAL_5N2,
25 SERIAL_6N2,
26 SERIAL_7N2,
27 SERIAL_8N2,
28
29 SERIAL_5E1,
30 SERIAL_6E1,
31 SERIAL_7E1,
32 SERIAL_8E2,
33
34 SERIAL_5E2,
35 SERIAL_6E2,
36 SERIAL_7E2,
37 SERIAL_8E2,
38
39 SERIAL_5O1,
40 SERIAL_6O1,
41 SERIAL_7O1,
42 SERIAL_8O2,
43
44 SERIAL_5O2,
45 SERIAL_6O2,
46 SERIAL_7O2,
47 SERIAL_8O2,
48
49 SERIAL_5M1,
50 SERIAL_6M1,
51 SERIAL_7M1,
52 SERIAL_8M2,
53
54 SERIAL_5M2,
55 SERIAL_6M2,
56 SERIAL_7M2,
57 SERIAL_8M2,
58
59 SERIAL_5S1,
60 SERIAL_6S1,
61 SERIAL_7S1,
62 SERIAL_8S2,
63
64 SERIAL_5S2,
65 SERIAL_6S2,
66 SERIAL_7S2,
67 SERIAL_8S2
68 };
69//---------------------------------------------------------------------------
70 template<typename T_SERIAL_TYPE, T_SERIAL_TYPE *T_SERIAL> class USARTSerialPort : public Mitov::SpeedSerialPort<T_SERIAL_TYPE, T_SERIAL>
71 {
72 typedef Mitov::SpeedSerialPort<T_SERIAL_TYPE, T_SERIAL> inherited;
73
74 public:
75 TArduinoSerialParity Parity : 3;
76 unsigned int StopBits : 2;
77 unsigned int DataBits : 3;
78
79 public:
80 void SetParity( TArduinoSerialParity AValue )
81 {
82 if( Parity == AValue )
83 return;
84
85 Parity = AValue;
86 inherited::RestartPort();
87 }
88
89 void SetStopBits( unsigned int AValue )
90 {
91 if( StopBits == AValue )
92 return;
93
94 StopBits = AValue;
95 inherited::RestartPort();
96 }
97
98 void SetDataBits( unsigned int AValue )
99 {
100 if( DataBits == AValue )
101 return;
102
103 DataBits = AValue;
104 inherited::RestartPort();
105 }
106
107 protected:
108 virtual void StartPort() override
109 {
110 int AIndex = ((int)Parity) * 8 + ( StopBits - 1 ) * 4 + ( DataBits - 5);
111 T_SERIAL->begin( inherited::Speed, CUSARTSerialInits[ AIndex ] );
112 }
113
114 public:
115 USARTSerialPort() :
116 Parity( spNone ),
117 StopBits( 2 ),
118 DataBits( 8 )
119 {
120 }
121 };
122//---------------------------------------------------------------------------
123} // Mitov
124
125#endif
126