forked from DVMProject/dvmfirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialDue.cpp
More file actions
168 lines (161 loc) · 4.02 KB
/
Copy pathSerialDue.cpp
File metadata and controls
168 lines (161 loc) · 4.02 KB
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
/**
* Digital Voice Modem - DSP Firmware
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / DSP Firmware
*
*/
//
// Based on code from the MMDVM project. (https://github.com/g4klx/MMDVM)
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0)
//
/*
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2018,2022 Bryan Biedenkapp N2PLL
*
* 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 "Globals.h"
#include "SerialPort.h"
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
#if (defined(__SAM3X8E__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)) && defined(ARDUINO_SAM_DUE)
/// <summary>
///
/// </summary>
void SerialPort::flashRead()
{
DEBUG1("SerialPort: flashRead(): unsupported on Arduino Due");
sendNAK(RSN_NO_INTERNAL_FLASH);
// unused on Arduino Due based dedicated modems
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <param name="length"></param>
uint8_t SerialPort::flashWrite(const uint8_t* data, uint8_t length)
{
DEBUG1("SerialPort: flashRead(): unsupported on Arduino Due");
// unused on Arduino Due based dedicated modems
return RSN_NO_INTERNAL_FLASH;
}
/// <summary>
///
/// </summary>
/// <param name="n"></param>
/// <param name="speed"></param>
void SerialPort::beginInt(uint8_t n, int speed)
{
switch (n) {
case 1U:
Serial.begin(speed);
break;
case 2U:
Serial2.begin(speed);
break;
case 3U:
Serial3.begin(speed);
break;
default:
break;
}
}
/// <summary>
///
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
int SerialPort::availableInt(uint8_t n)
{
switch (n) {
case 1U:
return Serial.available();
case 2U:
return Serial2.available();
case 3U:
return Serial3.available();
default:
return false;
}
}
/// <summary>
///
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
int SerialPort::availableForWriteInt(uint8_t n)
{
switch (n) {
case 1U:
return Serial.availableForWrite();
case 2U:
return Serial2.availableForWrite();
case 3U:
return Serial3.availableForWrite();
default:
return false;
}
}
/// <summary>
///
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
uint8_t SerialPort::readInt(uint8_t n)
{
switch (n) {
case 1U:
return Serial.read();
case 2U:
return Serial2.read();
case 3U:
return Serial3.read();
default:
return 0U;
}
}
/// <summary>
///
/// </summary>
/// <param name="n"></param>
/// <param name="data"></param>
/// <param name="length"></param>
/// <param name="flush"></param>
void SerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush)
{
switch (n) {
case 1U:
Serial.write(data, length);
if (flush)
Serial.flush();
break;
case 2U:
Serial2.write(data, length);
if (flush)
Serial2.flush();
break;
case 3U:
Serial3.write(data, length);
if (flush)
Serial3.flush();
break;
default:
break;
}
}
#endif