@@ -20,31 +20,22 @@ limitations under the License.
20
20
#include " tensorflow/lite/micro/debug_log.h"
21
21
22
22
#if defined(ARDUINO) && !defined(ARDUINO_ARDUINO_NANO33BLE)
23
- #define ARDUINO_EXCLUDE_CODE
23
+ // #define ARDUINO_EXCLUDE_CODE
24
24
#endif // defined(ARDUINO) && !defined(ARDUINO_ARDUINO_NANO33BLE)
25
25
26
26
#ifndef ARDUINO_EXCLUDE_CODE
27
27
28
28
#include " Arduino.h"
29
29
30
- // The Arduino DUE uses a different object for the default serial port shown in
31
- // the monitor than most other models, so make sure we pick the right one. See
32
- // https://github.com/arduino/Arduino/issues/3088#issuecomment-406655244
33
- #if defined(__SAM3X8E__)
34
- #define DEBUG_SERIAL_OBJECT (SerialUSB)
35
- #else
36
30
#define DEBUG_SERIAL_OBJECT (Serial)
37
- #endif
38
-
39
- extern " C" void DebugLog (const char * s) { DEBUG_SERIAL_OBJECT.print (s); }
40
31
41
32
namespace tflite {
42
33
43
- constexpr ulong kSerialMaxInitWait = 4000 ; // milliseconds
34
+ constexpr unsigned long kSerialMaxInitWait = 4000 ; // milliseconds
44
35
45
36
void InitializeTarget () {
46
- DEBUG_SERIAL_OBJECT.begin (9600 );
47
- ulong start_time = millis ();
37
+ DEBUG_SERIAL_OBJECT.begin ();
38
+ unsigned long start_time = millis ();
48
39
while (!DEBUG_SERIAL_OBJECT) {
49
40
// allow for Arduino IDE Serial Monitor synchronization
50
41
if (millis () - start_time > kSerialMaxInitWait ) {
@@ -55,84 +46,4 @@ void InitializeTarget() {
55
46
56
47
} // namespace tflite
57
48
58
- namespace test_over_serial {
59
-
60
- // Change baud rate on default serial port
61
- void SerialChangeBaudRate (const int baud) {
62
- DEBUG_SERIAL_OBJECT.begin (baud);
63
- ulong start_time = millis ();
64
- while (!DEBUG_SERIAL_OBJECT) {
65
- // allow for Arduino IDE Serial Monitor synchronization
66
- if (millis () - start_time > tflite::kSerialMaxInitWait ) {
67
- break ;
68
- }
69
- }
70
- }
71
-
72
- class _RingBuffer : public RingBufferN <kSerialMaxInputLength + 1 > {
73
- public:
74
- bool need_reset = false ;
75
- };
76
-
77
- static _RingBuffer _ring_buffer;
78
-
79
- // SerialReadLine
80
- // Read a set of ASCII characters from the default
81
- // serial port. Data is read up to the first newline ('\\n') character.
82
- // This function uses an internal buffer which is automatically reset.
83
- // The buffer will not contain the newline character.
84
- // The buffer will be zero ('\\0') terminated.
85
- // The <timeout> value is in milliseconds. Any negative value means that
86
- // the wait for data will be forever.
87
- // Returns std::pair<size_t, char*>.
88
- // The first pair element is the number of characters in buffer not including
89
- // the newline character or zero terminator.
90
- // Returns {0, NULL} if the timeout occurs.
91
- std::pair<size_t , char *> SerialReadLine (int timeout) {
92
- if (_ring_buffer.need_reset ) {
93
- _ring_buffer.need_reset = false ;
94
- _ring_buffer.clear ();
95
- }
96
-
97
- ulong start_time = millis ();
98
-
99
- while (true ) {
100
- int value = DEBUG_SERIAL_OBJECT.read ();
101
- if (value >= 0 ) {
102
- if (value == ' \n ' ) {
103
- // read a newline character
104
- _ring_buffer.store_char (' \0 ' );
105
- _ring_buffer.need_reset = true ;
106
- break ;
107
- } else {
108
- // read other character
109
- _ring_buffer.store_char (value);
110
- if (_ring_buffer.availableForStore () == 1 ) {
111
- // buffer is full
112
- _ring_buffer.store_char (' \0 ' );
113
- _ring_buffer.need_reset = true ;
114
- break ;
115
- }
116
- }
117
- }
118
- if (timeout < 0 ) {
119
- // wait forever
120
- continue ;
121
- } else if (millis () - start_time >= static_cast <ulong>(timeout)) {
122
- // timeout
123
- return std::make_pair (0UL , reinterpret_cast <char *>(NULL ));
124
- }
125
- }
126
-
127
- return std::make_pair (static_cast <size_t >(_ring_buffer.available () - 1 ),
128
- reinterpret_cast <char *>(_ring_buffer._aucBuffer ));
129
- }
130
-
131
- // SerialWrite
132
- // Write the ASCII characters in <buffer> to the default serial port.
133
- // The <buffer> must be zero terminated.
134
- void SerialWrite (const char * buffer) { DEBUG_SERIAL_OBJECT.print (buffer); }
135
-
136
- } // namespace test_over_serial
137
-
138
49
#endif // ARDUINO_EXCLUDE_CODE
0 commit comments