Browse Source

Add HAS_MULTI_SERIAL conditional

Scott Lahteine 4 years ago
parent
commit
6371782263

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

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

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

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

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

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

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

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

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

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

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

34
  */
34
  */
35
 void GcodeSuite::M118() {
35
 void GcodeSuite::M118() {
36
   bool hasE = false, hasA = false;
36
   bool hasE = false, hasA = false;
37
-  #if NUM_SERIAL > 1
37
+  #if HAS_MULTI_SERIAL
38
     int8_t port = -1; // Assume no redirect
38
     int8_t port = -1; // Assume no redirect
39
   #endif
39
   #endif
40
   char *p = parser.string_arg;
40
   char *p = parser.string_arg;
44
     switch (p[0]) {
44
     switch (p[0]) {
45
       case 'A': hasA = true; break;
45
       case 'A': hasA = true; break;
46
       case 'E': hasE = true; break;
46
       case 'E': hasE = true; break;
47
-      #if NUM_SERIAL > 1
47
+      #if HAS_MULTI_SERIAL
48
         case 'P': port = p[1] - '0'; break;
48
         case 'P': port = p[1] - '0'; break;
49
       #endif
49
       #endif
50
     }
50
     }
52
     while (*p == ' ') ++p;
52
     while (*p == ' ') ++p;
53
   }
53
   }
54
 
54
 
55
-  #if NUM_SERIAL > 1
55
+  #if HAS_MULTI_SERIAL
56
     const int8_t old_serial = serial_port_index;
56
     const int8_t old_serial = serial_port_index;
57
     if (WITHIN(port, 0, NUM_SERIAL))
57
     if (WITHIN(port, 0, NUM_SERIAL))
58
       serial_port_index = (
58
       serial_port_index = (
69
   if (hasA) SERIAL_ECHOPGM("// ");
69
   if (hasA) SERIAL_ECHOPGM("// ");
70
   SERIAL_ECHOLN(p);
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
 
28
 
29
 #include "../MarlinCore.h"
29
 #include "../MarlinCore.h"
30
 
30
 
31
-#if NUM_SERIAL > 1
31
+#if HAS_MULTI_SERIAL
32
   #include "queue.h"
32
   #include "queue.h"
33
 #endif
33
 #endif
34
 
34
 

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

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

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

55
   /**
55
   /**
56
    * The port that the command was received on
56
    * The port that the command was received on
57
    */
57
    */
58
-  #if NUM_SERIAL > 1
58
+  #if HAS_MULTI_SERIAL
59
     static int16_t port[BUFSIZE];
59
     static int16_t port[BUFSIZE];
60
   #endif
60
   #endif
61
 
61
 
62
   static int16_t command_port() {
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
   GCodeQueue();
66
   GCodeQueue();
162
   #endif
158
   #endif
163
 
159
 
164
   static void _commit_command(bool say_ok
160
   static void _commit_command(bool say_ok
165
-    #if NUM_SERIAL > 1
161
+    #if HAS_MULTI_SERIAL
166
       , int16_t p=-1
162
       , int16_t p=-1
167
     #endif
163
     #endif
168
   );
164
   );
169
 
165
 
170
   static bool _enqueue(const char* cmd, bool say_ok=false
166
   static bool _enqueue(const char* cmd, bool say_ok=false
171
-    #if NUM_SERIAL > 1
167
+    #if HAS_MULTI_SERIAL
172
       , int16_t p=-1
168
       , int16_t p=-1
173
     #endif
169
     #endif
174
   );
170
   );

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

27
 #include "../gcode.h"
27
 #include "../gcode.h"
28
 #include "../../sd/cardreader.h"
28
 #include "../../sd/cardreader.h"
29
 
29
 
30
-#if NUM_SERIAL > 1
30
+#if HAS_MULTI_SERIAL
31
   #include "../queue.h"
31
   #include "../queue.h"
32
 #endif
32
 #endif
33
 
33
 
49
     // Binary transfer mode
49
     // Binary transfer mode
50
     if ((card.flag.binary_mode = binary_mode)) {
50
     if ((card.flag.binary_mode = binary_mode)) {
51
       SERIAL_ECHO_MSG("Switching to Binary Protocol");
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
     else
54
     else
57
       card.openFileWrite(p);
55
       card.openFileWrite(p);

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

2519
 
2519
 
2520
 #if !NUM_SERIAL
2520
 #if !NUM_SERIAL
2521
   #undef BAUD_RATE_GCODE
2521
   #undef BAUD_RATE_GCODE
2522
+#elif NUM_SERIAL > 1
2523
+  #define HAS_MULTI_SERIAL 1
2522
 #endif
2524
 #endif

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

51
 char CardReader::filename[FILENAME_LENGTH], CardReader::longFilename[LONG_FILENAME_LENGTH];
51
 char CardReader::filename[FILENAME_LENGTH], CardReader::longFilename[LONG_FILENAME_LENGTH];
52
 int8_t CardReader::autostart_index;
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
   int8_t CardReader::transfer_port_index;
55
   int8_t CardReader::transfer_port_index;
56
 #endif
56
 #endif
57
 
57
 
1095
 #if ENABLED(AUTO_REPORT_SD_STATUS)
1095
 #if ENABLED(AUTO_REPORT_SD_STATUS)
1096
   uint8_t CardReader::auto_report_sd_interval = 0;
1096
   uint8_t CardReader::auto_report_sd_interval = 0;
1097
   millis_t CardReader::next_sd_report_ms;
1097
   millis_t CardReader::next_sd_report_ms;
1098
-  #if NUM_SERIAL > 1
1098
+  #if HAS_MULTI_SERIAL
1099
     int8_t CardReader::auto_report_port;
1099
     int8_t CardReader::auto_report_port;
1100
   #endif
1100
   #endif
1101
 
1101
 

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

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

Loading…
Cancel
Save