Browse Source

Add HAS_MULTI_SERIAL conditional

Scott Lahteine 4 years ago
parent
commit
6371782263

+ 1
- 1
Marlin/src/MarlinCore.cpp View File

@@ -862,7 +862,7 @@ void setup() {
862 862
     MYSERIAL0.begin(BAUDRATE);
863 863
     uint32_t serial_connect_timeout = millis() + 1000UL;
864 864
     while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
865
-    #if NUM_SERIAL > 1
865
+    #if HAS_MULTI_SERIAL
866 866
       MYSERIAL1.begin(BAUDRATE);
867 867
       serial_connect_timeout = millis() + 1000UL;
868 868
       while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }

+ 1
- 1
Marlin/src/core/serial.cpp View File

@@ -28,7 +28,7 @@ uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
28 28
 static PGMSTR(errormagic, "Error:");
29 29
 static PGMSTR(echomagic, "echo:");
30 30
 
31
-#if NUM_SERIAL > 1
31
+#if HAS_MULTI_SERIAL
32 32
   int8_t serial_port_index = 0;
33 33
 #endif
34 34
 

+ 1
- 1
Marlin/src/core/serial.h View File

@@ -47,7 +47,7 @@ extern uint8_t marlin_debug_flags;
47 47
 #define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
48 48
 
49 49
 #define SERIAL_BOTH 0x7F
50
-#if NUM_SERIAL > 1
50
+#if HAS_MULTI_SERIAL
51 51
   extern int8_t serial_port_index;
52 52
   #define _PORT_REDIRECT(n,p)   REMEMBER(n,serial_port_index,p)
53 53
   #define _PORT_RESTORE(n)      RESTORE(n)

+ 2
- 2
Marlin/src/feature/binary_protocol.h View File

@@ -32,7 +32,7 @@
32 32
 inline bool bs_serial_data_available(const uint8_t index) {
33 33
   switch (index) {
34 34
     case 0: return MYSERIAL0.available();
35
-    #if NUM_SERIAL > 1
35
+    #if HAS_MULTI_SERIAL
36 36
       case 1: return MYSERIAL1.available();
37 37
     #endif
38 38
   }
@@ -42,7 +42,7 @@ inline bool bs_serial_data_available(const uint8_t index) {
42 42
 inline int bs_read_serial(const uint8_t index) {
43 43
   switch (index) {
44 44
     case 0: return MYSERIAL0.read();
45
-    #if NUM_SERIAL > 1
45
+    #if HAS_MULTI_SERIAL
46 46
       case 1: return MYSERIAL1.read();
47 47
     #endif
48 48
   }

+ 3
- 3
Marlin/src/gcode/config/M575.cpp View File

@@ -42,7 +42,7 @@ void GcodeSuite::M575() {
42 42
       if (set0) {
43 43
         SERIAL_ECHO_START();
44 44
         SERIAL_ECHOLNPAIR(" Serial "
45
-          #if NUM_SERIAL > 1
45
+          #if HAS_MULTI_SERIAL
46 46
             , '0',
47 47
           #else
48 48
             "0"
@@ -50,7 +50,7 @@ void GcodeSuite::M575() {
50 50
           " baud rate set to ", baud
51 51
         );
52 52
       }
53
-      #if NUM_SERIAL > 1
53
+      #if HAS_MULTI_SERIAL
54 54
         const bool set1 = (port == -99 || port == 1);
55 55
         if (set1) {
56 56
           SERIAL_ECHO_START();
@@ -62,7 +62,7 @@ void GcodeSuite::M575() {
62 62
 
63 63
       if (set0) { MYSERIAL0.end(); MYSERIAL0.begin(baud); }
64 64
 
65
-      #if NUM_SERIAL > 1
65
+      #if HAS_MULTI_SERIAL
66 66
         if (set1) { MYSERIAL1.end(); MYSERIAL1.begin(baud); }
67 67
       #endif
68 68
 

+ 4
- 6
Marlin/src/gcode/host/M118.cpp View File

@@ -34,7 +34,7 @@
34 34
  */
35 35
 void GcodeSuite::M118() {
36 36
   bool hasE = false, hasA = false;
37
-  #if NUM_SERIAL > 1
37
+  #if HAS_MULTI_SERIAL
38 38
     int8_t port = -1; // Assume no redirect
39 39
   #endif
40 40
   char *p = parser.string_arg;
@@ -44,7 +44,7 @@ void GcodeSuite::M118() {
44 44
     switch (p[0]) {
45 45
       case 'A': hasA = true; break;
46 46
       case 'E': hasE = true; break;
47
-      #if NUM_SERIAL > 1
47
+      #if HAS_MULTI_SERIAL
48 48
         case 'P': port = p[1] - '0'; break;
49 49
       #endif
50 50
     }
@@ -52,7 +52,7 @@ void GcodeSuite::M118() {
52 52
     while (*p == ' ') ++p;
53 53
   }
54 54
 
55
-  #if NUM_SERIAL > 1
55
+  #if HAS_MULTI_SERIAL
56 56
     const int8_t old_serial = serial_port_index;
57 57
     if (WITHIN(port, 0, NUM_SERIAL))
58 58
       serial_port_index = (
@@ -69,7 +69,5 @@ void GcodeSuite::M118() {
69 69
   if (hasA) SERIAL_ECHOPGM("// ");
70 70
   SERIAL_ECHOLN(p);
71 71
 
72
-  #if NUM_SERIAL > 1
73
-    serial_port_index = old_serial;
74
-  #endif
72
+  TERN_(HAS_MULTI_SERIAL, serial_port_index = old_serial);
75 73
 }

+ 1
- 1
Marlin/src/gcode/parser.cpp View File

@@ -28,7 +28,7 @@
28 28
 
29 29
 #include "../MarlinCore.h"
30 30
 
31
-#if NUM_SERIAL > 1
31
+#if HAS_MULTI_SERIAL
32 32
   #include "queue.h"
33 33
 #endif
34 34
 

+ 11
- 19
Marlin/src/gcode/queue.cpp View File

@@ -72,7 +72,7 @@ char GCodeQueue::command_buffer[BUFSIZE][MAX_CMD_SIZE];
72 72
 /*
73 73
  * The port that the command was received on
74 74
  */
75
-#if NUM_SERIAL > 1
75
+#if HAS_MULTI_SERIAL
76 76
   int16_t GCodeQueue::port[BUFSIZE];
77 77
 #endif
78 78
 
@@ -119,14 +119,12 @@ void GCodeQueue::clear() {
119 119
  * Once a new command is in the ring buffer, call this to commit it
120 120
  */
121 121
 void GCodeQueue::_commit_command(bool say_ok
122
-  #if NUM_SERIAL > 1
122
+  #if HAS_MULTI_SERIAL
123 123
     , int16_t p/*=-1*/
124 124
   #endif
125 125
 ) {
126 126
   send_ok[index_w] = say_ok;
127
-  #if NUM_SERIAL > 1
128
-    port[index_w] = p;
129
-  #endif
127
+  TERN_(HAS_MULTI_SERIAL, port[index_w] = p);
130 128
   TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w));
131 129
   if (++index_w >= BUFSIZE) index_w = 0;
132 130
   length++;
@@ -138,14 +136,14 @@ void GCodeQueue::_commit_command(bool say_ok
138 136
  * Return false for a full buffer, or if the 'command' is a comment.
139 137
  */
140 138
 bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/
141
-  #if NUM_SERIAL > 1
139
+  #if HAS_MULTI_SERIAL
142 140
     , int16_t pn/*=-1*/
143 141
   #endif
144 142
 ) {
145 143
   if (*cmd == ';' || length >= BUFSIZE) return false;
146 144
   strcpy(command_buffer[index_w], cmd);
147 145
   _commit_command(say_ok
148
-    #if NUM_SERIAL > 1
146
+    #if HAS_MULTI_SERIAL
149 147
       , pn
150 148
     #endif
151 149
   );
@@ -276,7 +274,7 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
276 274
  *   B<int>  Block queue space remaining
277 275
  */
278 276
 void GCodeQueue::ok_to_send() {
279
-  #if NUM_SERIAL > 1
277
+  #if HAS_MULTI_SERIAL
280 278
     const int16_t pn = command_port();
281 279
     if (pn < 0) return;
282 280
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
@@ -303,30 +301,24 @@ void GCodeQueue::ok_to_send() {
303 301
  */
304 302
 void GCodeQueue::flush_and_request_resend() {
305 303
   const int16_t pn = command_port();
306
-  #if NUM_SERIAL > 1
304
+  #if HAS_MULTI_SERIAL
307 305
     if (pn < 0) return;
308 306
     PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
309 307
   #endif
310 308
   SERIAL_FLUSH();
311 309
   SERIAL_ECHOPGM(STR_RESEND);
312
-  
313
-  SERIAL_ECHOLN(last_N[pn] + 1);  
310
+  SERIAL_ECHOLN(last_N[pn] + 1);
314 311
   ok_to_send();
315 312
 }
316 313
 
317 314
 inline bool serial_data_available() {
318
-  return false
319
-    || MYSERIAL0.available()
320
-    #if NUM_SERIAL > 1
321
-      || MYSERIAL1.available()
322
-    #endif
323
-  ;
315
+  return MYSERIAL0.available() || TERN0(HAS_MULTI_SERIAL, MYSERIAL1.available());
324 316
 }
325 317
 
326 318
 inline int read_serial(const uint8_t index) {
327 319
   switch (index) {
328 320
     case 0: return MYSERIAL0.read();
329
-    #if NUM_SERIAL > 1
321
+    #if HAS_MULTI_SERIAL
330 322
       case 1: return MYSERIAL1.read();
331 323
     #endif
332 324
     default: return -1;
@@ -538,7 +530,7 @@ void GCodeQueue::get_serial_commands() {
538 530
 
539 531
         // Add the command to the queue
540 532
         _enqueue(serial_line_buffer[i], true
541
-          #if NUM_SERIAL > 1
533
+          #if HAS_MULTI_SERIAL
542 534
             , i
543 535
           #endif
544 536
         );

+ 4
- 8
Marlin/src/gcode/queue.h View File

@@ -55,16 +55,12 @@ public:
55 55
   /**
56 56
    * The port that the command was received on
57 57
    */
58
-  #if NUM_SERIAL > 1
58
+  #if HAS_MULTI_SERIAL
59 59
     static int16_t port[BUFSIZE];
60 60
   #endif
61 61
 
62 62
   static int16_t command_port() {
63
-    return (0
64
-      #if NUM_SERIAL > 1
65
-        + port[index_r]
66
-      #endif
67
-    );
63
+    return TERN0(HAS_MULTI_SERIAL, port[index_r]);
68 64
   }
69 65
 
70 66
   GCodeQueue();
@@ -162,13 +158,13 @@ private:
162 158
   #endif
163 159
 
164 160
   static void _commit_command(bool say_ok
165
-    #if NUM_SERIAL > 1
161
+    #if HAS_MULTI_SERIAL
166 162
       , int16_t p=-1
167 163
     #endif
168 164
   );
169 165
 
170 166
   static bool _enqueue(const char* cmd, bool say_ok=false
171
-    #if NUM_SERIAL > 1
167
+    #if HAS_MULTI_SERIAL
172 168
       , int16_t p=-1
173 169
     #endif
174 170
   );

+ 2
- 4
Marlin/src/gcode/sd/M28_M29.cpp View File

@@ -27,7 +27,7 @@
27 27
 #include "../gcode.h"
28 28
 #include "../../sd/cardreader.h"
29 29
 
30
-#if NUM_SERIAL > 1
30
+#if HAS_MULTI_SERIAL
31 31
   #include "../queue.h"
32 32
 #endif
33 33
 
@@ -49,9 +49,7 @@ void GcodeSuite::M28() {
49 49
     // Binary transfer mode
50 50
     if ((card.flag.binary_mode = binary_mode)) {
51 51
       SERIAL_ECHO_MSG("Switching to Binary Protocol");
52
-      #if NUM_SERIAL > 1
53
-        card.transfer_port_index = queue.port[queue.index_r];
54
-      #endif
52
+      TERN_(HAS_MULTI_SERIAL, card.transfer_port_index = queue.port[queue.index_r]);
55 53
     }
56 54
     else
57 55
       card.openFileWrite(p);

+ 2
- 0
Marlin/src/inc/Conditionals_post.h View File

@@ -2519,4 +2519,6 @@
2519 2519
 
2520 2520
 #if !NUM_SERIAL
2521 2521
   #undef BAUD_RATE_GCODE
2522
+#elif NUM_SERIAL > 1
2523
+  #define HAS_MULTI_SERIAL 1
2522 2524
 #endif

+ 2
- 2
Marlin/src/sd/cardreader.cpp View File

@@ -51,7 +51,7 @@ card_flags_t CardReader::flag;
51 51
 char CardReader::filename[FILENAME_LENGTH], CardReader::longFilename[LONG_FILENAME_LENGTH];
52 52
 int8_t CardReader::autostart_index;
53 53
 
54
-#if ENABLED(BINARY_FILE_TRANSFER) && NUM_SERIAL > 1
54
+#if BOTH(HAS_MULTI_SERIAL, BINARY_FILE_TRANSFER)
55 55
   int8_t CardReader::transfer_port_index;
56 56
 #endif
57 57
 
@@ -1095,7 +1095,7 @@ void CardReader::fileHasFinished() {
1095 1095
 #if ENABLED(AUTO_REPORT_SD_STATUS)
1096 1096
   uint8_t CardReader::auto_report_sd_interval = 0;
1097 1097
   millis_t CardReader::next_sd_report_ms;
1098
-  #if NUM_SERIAL > 1
1098
+  #if HAS_MULTI_SERIAL
1099 1099
     int8_t CardReader::auto_report_port;
1100 1100
   #endif
1101 1101
 

+ 3
- 5
Marlin/src/sd/cardreader.h View File

@@ -61,7 +61,7 @@ public:
61 61
 
62 62
   // Fast! binary file transfer
63 63
   #if ENABLED(BINARY_FILE_TRANSFER)
64
-    #if NUM_SERIAL > 1
64
+    #if HAS_MULTI_SERIAL
65 65
       static int8_t transfer_port_index;
66 66
     #else
67 67
       static constexpr int8_t transfer_port_index = 0;
@@ -164,9 +164,7 @@ public:
164 164
   #if ENABLED(AUTO_REPORT_SD_STATUS)
165 165
     static void auto_report_sd_status();
166 166
     static inline void set_auto_report_interval(uint8_t v) {
167
-      #if NUM_SERIAL > 1
168
-        auto_report_port = serial_port_index;
169
-      #endif
167
+      TERN_(HAS_MULTI_SERIAL, auto_report_port = serial_port_index);
170 168
       NOMORE(v, 60);
171 169
       auto_report_sd_interval = v;
172 170
       next_sd_report_ms = millis() + 1000UL * v;
@@ -258,7 +256,7 @@ private:
258 256
   #if ENABLED(AUTO_REPORT_SD_STATUS)
259 257
     static uint8_t auto_report_sd_interval;
260 258
     static millis_t next_sd_report_ms;
261
-    #if NUM_SERIAL > 1
259
+    #if HAS_MULTI_SERIAL
262 260
       static int8_t auto_report_port;
263 261
     #endif
264 262
   #endif

Loading…
Cancel
Save