-
Notifications
You must be signed in to change notification settings - Fork 141
/
SerialArduino.cpp
122 lines (113 loc) · 3.41 KB
/
SerialArduino.cpp
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
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016,2017 by Andy Uribe CA6JAU
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Config.h"
#include "Globals.h"
#include "SerialPort.h"
#if defined(ARDUINO)
void CSerialPort::beginInt(uint8_t n, int speed)
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
Serial1.begin(speed);
#else
Serial.begin(speed);
#endif
break;
case 3U:
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
Serial2.begin(speed);
#elif defined(SERIAL_REPEATER_USART1) && defined(__STM32F1__)
Serial1.begin(speed);
#elif defined(SERIAL_REPEATER) && (defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
Serial1.begin(speed);
#endif
break;
default:
break;
}
}
int CSerialPort::availableInt(uint8_t n)
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
return Serial1.available();
#else
return Serial.available();
#endif
case 3U:
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
return Serial2.available();
#elif defined(SERIAL_REPEATER_USART1) && defined(__STM32F1__)
return Serial1.available();
#elif defined(SERIAL_REPEATER) && (defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
return Serial1.available();
#endif
default:
return 0;
}
}
uint8_t CSerialPort::readInt(uint8_t n)
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
return Serial1.read();
#else
return Serial.read();
#endif
case 3U:
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
return Serial2.read();
#elif defined(SERIAL_REPEATER_USART1) && defined(__STM32F1__)
return Serial1.read();
#elif defined(SERIAL_REPEATER) && (defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
return Serial1.read();
#endif
default:
return 0U;
}
}
void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush)
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
Serial1.write(data, length);
#else
Serial.write(data, length);
if (flush)
Serial.flush();
#endif
break;
case 3U:
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
Serial2.write(data, length);
#elif defined(SERIAL_REPEATER_USART1) && defined(__STM32F1__)
Serial1.write(data, length);
#elif defined(SERIAL_REPEATER) && (defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
Serial1.write(data, length);
#endif
break;
default:
break;
}
}
#endif