-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSerialDue.cpp
129 lines (113 loc) · 2.82 KB
/
SerialDue.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
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Modem Firmware
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2016,2017 Jonathan Naylor, G4KLX
* Copyright (C) 2018,2022 Bryan Biedenkapp, N2PLL
*
*/
#include "Globals.h"
#include "SerialPort.h"
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
#if (defined(__SAM3X8E__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)) && defined(ARDUINO_SAM_DUE)
/* Reads data from the modem flash parititon. */
void SerialPort::flashRead()
{
DEBUG1("SerialPort: flashRead(): unsupported on Arduino Due");
sendNAK(RSN_NO_INTERNAL_FLASH);
// unused on Arduino Due based dedicated modems
}
/* Writes data to the modem flash partition. */
uint8_t SerialPort::flashWrite(const uint8_t* data, uint8_t length)
{
DEBUG1("SerialPort: flashWrite(): unsupported on Arduino Due");
// unused on Arduino Due based dedicated modems
return RSN_NO_INTERNAL_FLASH;
}
/* */
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;
}
}
/* */
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;
}
}
/* */
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;
}
}
/* */
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;
}
}
/* */
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 // (defined(__SAM3X8E__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)) && defined(ARDUINO_SAM_DUE)