瀏覽代碼

Simplify serial port redirect (#13234)

Scott Lahteine 5 年之前
父節點
當前提交
e15354e387
No account linked to committer's email address

+ 8
- 2
Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp 查看文件

@@ -65,9 +65,12 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
65 65
     return CTRL_NO_PRESENT;
66 66
 
67 67
   #ifdef DEBUG_MMC
68
+  {
68 69
     char buffer[80];
69 70
     sprintf_P(buffer, PSTR("SDRD: %d @ 0x%08x\n"), nb_sector, addr);
70
-    SERIAL_ECHO_P(0, buffer);
71
+    PORT_REDIRECT(0);
72
+    SERIAL_ECHO(buffer);
73
+  }
71 74
   #endif
72 75
 
73 76
   // Start reading
@@ -99,9 +102,12 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
99 102
     return CTRL_NO_PRESENT;
100 103
 
101 104
   #ifdef DEBUG_MMC
105
+  {
102 106
     char buffer[80];
103 107
     sprintf_P(buffer, PSTR("SDWR: %d @ 0x%08x\n"), nb_sector, addr);
104
-    SERIAL_ECHO_P(0, buffer);
108
+    PORT_REDIRECT(0);
109
+    SERIAL_ECHO(buffer);
110
+  }
105 111
   #endif
106 112
 
107 113
   if (!card.getSd2Card().writeStart(addr, nb_sector))

+ 2
- 20
Marlin/src/core/serial.cpp 查看文件

@@ -29,30 +29,12 @@ static const char errormagic[] PROGMEM = "Error:";
29 29
 static const char echomagic[]  PROGMEM = "echo:";
30 30
 
31 31
 #if NUM_SERIAL > 1
32
-  void serialprintPGM_P(const int8_t p, const char * str) {
33
-    while (char ch = pgm_read_byte(str++)) SERIAL_CHAR_P(p, ch);
34
-  }
35
-
36
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, const char *v)   { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
37
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, char v)          { serialprintPGM_P(p, s_P); SERIAL_CHAR_P(p, v); }
38
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, int v)           { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
39
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, long v)          { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
40
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, float v)         { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
41
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, double v)        { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
42
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned int v)  { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
43
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned long v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
44
-
45
-  void serial_spaces_P(const int8_t p, uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR_P(p, ' '); }
46
-
47
-  void serial_echo_start_P(const int8_t p)  { serialprintPGM_P(p, echomagic); }
48
-  void serial_error_start_P(const int8_t p) { serialprintPGM_P(p, errormagic); }
49
-
32
+  int8_t serial_port_index = SERIAL_PORT;
50 33
 #endif
51 34
 
52 35
 void serialprintPGM(PGM_P str) {
53
-  while (char ch = pgm_read_byte(str++)) SERIAL_CHAR(ch);
36
+  while (const char c = pgm_read_byte(str++)) SERIAL_CHAR(c);
54 37
 }
55
-
56 38
 void serial_echo_start()  { serialprintPGM(echomagic); }
57 39
 void serial_error_start() { serialprintPGM(errormagic); }
58 40
 

+ 29
- 121
Marlin/src/core/serial.h 查看文件

@@ -43,131 +43,43 @@ extern uint8_t marlin_debug_flags;
43 43
 #define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
44 44
 
45 45
 #if TX_BUFFER_SIZE < 1
46
-  #define SERIAL_FLUSHTX_P(p)
47 46
   #define SERIAL_FLUSHTX()
48 47
 #endif
49 48
 
50 49
 #if NUM_SERIAL > 1
50
+  extern int8_t serial_port_index;
51
+  #define _PORT_REDIRECT(n,p)   REMEMBER(n,serial_port_index,p)
52
+  #define _PORT_RESTORE(n)      RESTORE(n)
53
+  #define SERIAL_BOTH 0x7F
54
+  #define SERIAL_OUT(WHAT, ...) do{ \
55
+    if (!serial_port_index || serial_port_index == SERIAL_BOTH) MYSERIAL0.WHAT(##__VA_ARGS__); \
56
+    if ( serial_port_index) MYSERIAL1.WHAT(##__VA_ARGS__); \
57
+  }while(0)
58
+#else
59
+  #define _PORT_REDIRECT(n,p)   NOOP
60
+  #define _PORT_RESTORE(n)      NOOP
61
+  #define SERIAL_OUT(WHAT, ...) MYSERIAL0.WHAT(__VA_ARGS__)
62
+#endif
51 63
 
52
-  //
53
-  // Serial out to all ports
54
-  //
55
-  #define SERIAL_CHAR(x)                    (MYSERIAL0.write(x), MYSERIAL1.write(x))
56
-  #define SERIAL_ECHO(x)                    (MYSERIAL0.print(x), MYSERIAL1.print(x))
57
-  #define SERIAL_ECHO_F(x,y)                (MYSERIAL0.print(x,y), MYSERIAL1.print(x,y))
58
-  #define SERIAL_ECHOLN(x)                  (MYSERIAL0.println(x), MYSERIAL1.println(x))
59
-  #define SERIAL_PRINT(x,b)                 (MYSERIAL0.print(x,b), MYSERIAL1.print(x,b))
60
-  #define SERIAL_PRINTLN(x,b)               (MYSERIAL0.println(x,b), MYSERIAL1.println(x,b))
61
-  #define SERIAL_PRINTF(args...)            (MYSERIAL0.printf(args), MYSERIAL1.printf(args))
62
-  #define SERIAL_FLUSH()                    (MYSERIAL0.flush(), MYSERIAL1.flush())
63
-  #if TX_BUFFER_SIZE > 0
64
-    #define SERIAL_FLUSHTX()                (MYSERIAL0.flushTX(), MYSERIAL1.flushTX())
65
-  #endif
66
-
67
-  //
68
-  // Serial out with port redirect
69
-  //
70
-  #define SERIAL_CHAR_P(p,x)                (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.write(x) : MYSERIAL1.write(x)) : SERIAL_CHAR(x))
71
-  #define SERIAL_ECHO_P(p,x)                (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x) : MYSERIAL1.print(x)) : SERIAL_ECHO(x))
72
-  #define SERIAL_ECHO_F_P(p,x,y)            (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x,y) : MYSERIAL1.print(x,y)) : SERIAL_ECHO_F(x,y))
73
-  #define SERIAL_ECHOLN_P(p,x)              (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x) : MYSERIAL1.println(x)) : SERIAL_ECHOLN(x))
74
-  #define SERIAL_PRINT_P(p,x,b)             (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x,b) : MYSERIAL1.print(x,b)) : SERIAL_PRINT(x,b))
75
-  #define SERIAL_PRINTLN_P(p,x,b)           (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x,b) : MYSERIAL1.println(x,b)) : SERIAL_PRINTLN(x,b))
76
-  #define SERIAL_PRINTF_P(p,args...)        (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.printf(args) : MYSERIAL1.printf(args)) : SERIAL_PRINTF(args))
77
-  #define SERIAL_FLUSH_P(p)                 (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flush() : MYSERIAL1.flush()) : SERIAL_FLUSH())
78
-  #if TX_BUFFER_SIZE > 0
79
-    #define SERIAL_FLUSHTX_P(p)             (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flushTX() : MYSERIAL1.flushTX()) : SERIAL_FLUSHTX())
80
-  #endif
81
-
82
-  #define SERIAL_ECHOPGM_P(p,x)             (serialprintPGM_P(p,PSTR(x)))
83
-  #define SERIAL_ECHOLNPGM_P(p,x)           (serialprintPGM_P(p,PSTR(x "\n")))
84
-  #define SERIAL_ECHOPAIR_P(p, pre, value)  (serial_echopair_PGM_P(p,PSTR(pre),(value)))
85
-
86
-  #define SERIAL_ECHO_START_P(p)            serial_echo_start_P(p)
87
-  #define SERIAL_ERROR_START_P(p)           serial_error_start_P(p)
88
-  #define SERIAL_EOL_P(p)                   SERIAL_CHAR_P(p,'\n')
89
-
90
-  #define SERIAL_ECHOPAIR_F_P(p, pre, value, y)   do{ SERIAL_ECHO_P(p, pre); SERIAL_ECHO_F_P(p, value, y); }while(0)
91
-  #define SERIAL_ECHOLNPAIR_F_P(p, pre, value, y) do{ SERIAL_ECHOPAIR_F_P(p, pre, value, y); SERIAL_EOL_P(p); }while(0)
92
-
93
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, const char *v);
94
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, char v);
95
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, int v);
96
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, long v);
97
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, float v);
98
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, double v);
99
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned int v);
100
-  void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned long v);
101
-  inline void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, uint8_t v) { serial_echopair_PGM_P(p, s_P, (int)v); }
102
-  inline void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, bool v)    { serial_echopair_PGM_P(p, s_P, (int)v); }
103
-  inline void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, void *v)   { serial_echopair_PGM_P(p, s_P, (unsigned long)v); }
104
-
105
-  void serial_spaces_P(const int8_t p, uint8_t count);
106
-  #define SERIAL_ECHO_SP_P(p,C)             serial_spaces_P(p,C)
107
-
108
-  void serialprintPGM_P(const int8_t p, PGM_P str);
109
-  void serial_echo_start_P(const int8_t p);
110
-  void serial_error_start_P(const int8_t p);
111
-
112
-#else // NUM_SERIAL <= 1
113
-
114
-  //
115
-  // Serial out to all ports
116
-  //
117
-  #define SERIAL_CHAR(x)                    MYSERIAL0.write(x)
118
-  #define SERIAL_ECHO(x)                    MYSERIAL0.print(x)
119
-  #define SERIAL_ECHO_F(x,y)                MYSERIAL0.print(x,y)
120
-  #define SERIAL_ECHOLN(x)                  MYSERIAL0.println(x)
121
-  #define SERIAL_PRINT(x,b)                 MYSERIAL0.print(x,b)
122
-  #define SERIAL_PRINTLN(x,b)               MYSERIAL0.println(x,b)
123
-  #define SERIAL_PRINTF(args...)            MYSERIAL0.printf(args)
124
-  #define SERIAL_FLUSH()                    MYSERIAL0.flush()
125
-  #if TX_BUFFER_SIZE > 0
126
-    #define SERIAL_FLUSHTX()                MYSERIAL0.flushTX()
127
-  #endif
128
-
129
-  //
130
-  // Serial out with port redirect
131
-  //
132
-  #define SERIAL_CHAR_P(p,x)                SERIAL_CHAR(x)
133
-  #define SERIAL_ECHO_P(p,x)                SERIAL_ECHO(x)
134
-  #define SERIAL_ECHO_F_P(p,x,y)            SERIAL_ECHO_F(x,y)
135
-  #define SERIAL_ECHOLN_P(p,x)              SERIAL_ECHOLN(x)
136
-  #define SERIAL_PRINT_P(p,x,b)             SERIAL_PRINT(x,b)
137
-  #define SERIAL_PRINTLN_P(p,x,b)           SERIAL_PRINTLN(x,b)
138
-  #define SERIAL_PRINTF_P(p,args...)        SERIAL_PRINTF(args)
139
-  #define SERIAL_FLUSH_P(p)                 SERIAL_FLUSH()
140
-  #if TX_BUFFER_SIZE > 0
141
-    #define SERIAL_FLUSHTX_P(p)             SERIAL_FLUSHTX()
142
-  #endif
143
-
144
-  #define SERIAL_ECHOPGM_P(p,x)             SERIAL_ECHOPGM(x)
145
-  #define SERIAL_ECHOLNPGM_P(p,x)           SERIAL_ECHOLNPGM(x)
146
-  #define SERIAL_ECHOPAIR_P(p, pre, value)  SERIAL_ECHOPAIR(pre, value)
147
-
148
-  #define SERIAL_ECHO_P(p,x)                SERIAL_ECHO(x)
149
-  #define SERIAL_ECHOLN_P(p,x)              SERIAL_ECHOLN(x)
150
-
151
-  #define SERIAL_ECHO_START_P(p)            SERIAL_ECHO_START()
152
-  #define SERIAL_ERROR_START_P(p)           SERIAL_ERROR_START()
153
-  #define SERIAL_EOL_P(p)                   SERIAL_EOL()
154
-
155
-  #define SERIAL_ECHOPAIR_F_P(p, pre, value, y)   SERIAL_ECHOPAIR_F(pre, value, y)
156
-  #define SERIAL_ECHOLNPAIR_F_P(p, pre, value, y) SERIAL_ECHOLNPAIR_F(pre, value, y)
157
-
158
-  #define serial_echopair_PGM_P(p,s_P,v)    serial_echopair_PGM(s_P, v)
159
-
160
-  #define serial_spaces_P(p,c)              serial_spaces(c)
161
-  #define SERIAL_ECHO_SP_P(p,C)             SERIAL_ECHO_SP(C)
162
-
163
-  #define serialprintPGM_P(p,s)             serialprintPGM(s)
164
-
165
-#endif // NUM_SERIAL < 2
64
+#define PORT_REDIRECT(p)        _PORT_REDIRECT(1,p)
65
+#define PORT_RESTORE()          _PORT_RESTORE(1)
66
+
67
+#define SERIAL_CHAR(x)          SERIAL_OUT(write, x)
68
+#define SERIAL_ECHO(x)          SERIAL_OUT(print, x)
69
+#define SERIAL_ECHO_F(x,y)      SERIAL_OUT(print, x, y)
70
+#define SERIAL_ECHOLN(x)        SERIAL_OUT(println, x)
71
+#define SERIAL_PRINT(x,b)       SERIAL_OUT(print, x, b)
72
+#define SERIAL_PRINTLN(x,b)     SERIAL_OUT(println, x, b)
73
+#define SERIAL_PRINTF(args...)  SERIAL_OUT(printf, args)
74
+#define SERIAL_FLUSH()          SERIAL_OUT(flush)
75
+#if TX_BUFFER_SIZE > 0
76
+  #define SERIAL_FLUSHTX()      SERIAL_OUT(flushTX)
77
+#endif
166 78
 
167 79
 #define SERIAL_ECHOPGM(x)                   (serialprintPGM(PSTR(x)))
168 80
 #define SERIAL_ECHOLNPGM(x)                 (serialprintPGM(PSTR(x "\n")))
169 81
 #define SERIAL_ECHOPAIR(pre, value)         (serial_echopair_PGM(PSTR(pre), value))
170
-#define SERIAL_ECHOLNPAIR(pre, value)       do { SERIAL_ECHOPAIR(pre, value); SERIAL_EOL(); } while(0)
82
+#define SERIAL_ECHOLNPAIR(pre, value)       do{ SERIAL_ECHOPAIR(pre, value); SERIAL_EOL(); }while(0)
171 83
 
172 84
 #define SERIAL_ECHOPAIR_F(pre, value, y)    do{ SERIAL_ECHO(pre); SERIAL_ECHO_F(value, y); }while(0)
173 85
 #define SERIAL_ECHOLNPAIR_F(pre, value, y)  do{ SERIAL_ECHOPAIR_F(pre, value, y); SERIAL_EOL(); }while(0)
@@ -177,13 +89,8 @@ extern uint8_t marlin_debug_flags;
177 89
 #define SERIAL_EOL()                        SERIAL_CHAR('\n')
178 90
 
179 91
 #define SERIAL_ECHO_MSG(STR)                do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(STR); }while(0)
180
-#define SERIAL_ECHO_MSG_P(p, STR)           do{ SERIAL_ECHO_START_P(p); SERIAL_ECHOLNPGM_P(p, STR); }while(0)
181 92
 #define SERIAL_ERROR_MSG(STR)               do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPGM(STR); }while(0)
182
-#define SERIAL_ERROR_MSG_P(p, STR)          do{ SERIAL_ERROR_START_P(p); SERIAL_ECHOLNPGM_P(p, STR); }while(0)
183
-
184
-#define SERIAL_ECHOLNPAIR_P(p, pre, value)  do{ SERIAL_ECHOPAIR_P(p, pre, value); SERIAL_EOL_P(p); }while(0)
185 93
 
186
-void serial_spaces(uint8_t count);
187 94
 #define SERIAL_ECHO_SP(C)                   serial_spaces(C)
188 95
 
189 96
 //
@@ -206,6 +113,7 @@ void serial_echo_start();
206 113
 void serial_error_start();
207 114
 void serialprint_onoff(const bool onoff);
208 115
 void serialprintln_onoff(const bool onoff);
116
+void serial_spaces(uint8_t count);
209 117
 
210 118
 #if ENABLED(DEBUG_LEVELING_FEATURE)
211 119
   void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z);

+ 2
- 2
Marlin/src/core/utility.h 查看文件

@@ -133,5 +133,5 @@ public:
133 133
   inline void restore() { ref_ = val_; }
134 134
 };
135 135
 
136
-#define REMEMBER(N,X, ...) restorer<typeof(X)> N##_restorer(X, ##__VA_ARGS__)
137
-#define RESTORE(N) N##_restorer.restore()
136
+#define REMEMBER(N,X, ...) restorer<typeof(X)> restorer_##N(X, ##__VA_ARGS__)
137
+#define RESTORE(N) restorer_##N.restore()

+ 14
- 30
Marlin/src/feature/bedlevel/ubl/ubl.cpp 查看文件

@@ -34,46 +34,30 @@
34 34
 
35 35
   #include "math.h"
36 36
 
37
-  void unified_bed_leveling::echo_name(
38
-    #if NUM_SERIAL > 1
39
-      const int8_t port/*= -1*/
40
-    #endif
41
-  ) {
42
-    SERIAL_ECHOPGM_P(port, "Unified Bed Leveling");
37
+  void unified_bed_leveling::echo_name() {
38
+    SERIAL_ECHOPGM("Unified Bed Leveling");
43 39
   }
44 40
 
45
-  void unified_bed_leveling::report_current_mesh(
46
-    #if NUM_SERIAL > 1
47
-      const int8_t port/*= -1*/
48
-    #endif
49
-  ) {
41
+  void unified_bed_leveling::report_current_mesh() {
50 42
     if (!leveling_is_valid()) return;
51
-    SERIAL_ECHO_MSG_P(port, "  G29 I99");
43
+    SERIAL_ECHO_MSG("  G29 I99");
52 44
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
53 45
       for (uint8_t y = 0;  y < GRID_MAX_POINTS_Y; y++)
54 46
         if (!isnan(z_values[x][y])) {
55
-          SERIAL_ECHO_START_P(port);
56
-          SERIAL_ECHOPAIR_P(port, "  M421 I", x);
57
-          SERIAL_ECHOPAIR_P(port, " J", y);
58
-          SERIAL_ECHOPAIR_F_P(port, " Z", z_values[x][y], 2);
59
-          SERIAL_EOL_P(port);
47
+          SERIAL_ECHO_START();
48
+          SERIAL_ECHOPAIR("  M421 I", x);
49
+          SERIAL_ECHOPAIR(" J", y);
50
+          SERIAL_ECHOPAIR_F(" Z", z_values[x][y], 2);
51
+          SERIAL_EOL();
60 52
           serial_delay(75); // Prevent Printrun from exploding
61 53
         }
62 54
   }
63 55
 
64
-  void unified_bed_leveling::report_state(
65
-    #if NUM_SERIAL > 1
66
-      const int8_t port/*= -1*/
67
-    #endif
68
-  ) {
69
-    echo_name(
70
-      #if NUM_SERIAL > 1
71
-        port
72
-      #endif
73
-    );
74
-    SERIAL_ECHOPGM_P(port, " System v" UBL_VERSION " ");
75
-    if (!planner.leveling_active) SERIAL_ECHOPGM_P(port, "in");
76
-    SERIAL_ECHOLNPGM_P(port, "active.");
56
+  void unified_bed_leveling::report_state() {
57
+    echo_name();
58
+    SERIAL_ECHOPGM(" System v" UBL_VERSION " ");
59
+    if (!planner.leveling_active) SERIAL_ECHOPGM("in");
60
+    SERIAL_ECHOLNPGM("active.");
77 61
     serial_delay(50);
78 62
   }
79 63
 

+ 3
- 15
Marlin/src/feature/bedlevel/ubl/ubl.h 查看文件

@@ -94,21 +94,9 @@ class unified_bed_leveling {
94 94
 
95 95
   public:
96 96
 
97
-    static void echo_name(
98
-      #if NUM_SERIAL > 1
99
-        const int8_t port = -1
100
-      #endif
101
-    );
102
-    static void report_current_mesh(
103
-      #if NUM_SERIAL > 1
104
-        const int8_t port = -1
105
-      #endif
106
-    );
107
-    static void report_state(
108
-      #if NUM_SERIAL > 1
109
-        const int8_t port = -1
110
-      #endif
111
-    );
97
+    static void echo_name();
98
+    static void report_current_mesh();
99
+    static void report_state();
112 100
     static void save_ubl_active_state_and_disable();
113 101
     static void restore_ubl_active_state_and_leave();
114 102
     static void display_map(const int) _O0;

+ 7
- 11
Marlin/src/gcode/config/M217.cpp 查看文件

@@ -33,19 +33,15 @@
33 33
 
34 34
 void M217_report(const bool eeprom=false) {
35 35
 
36
-  #if NUM_SERIAL > 1
37
-    const int16_t port = command_queue_port[cmd_queue_index_r];
38
-  #endif
39
-
40 36
   #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
41
-    serialprintPGM_P(port, eeprom ? PSTR("  M217") : PSTR("Singlenozzle:"));
42
-    SERIAL_ECHOPAIR_P(port, " S", LINEAR_UNIT(toolchange_settings.swap_length));
43
-    SERIAL_ECHOPAIR_P(port, " P", LINEAR_UNIT(toolchange_settings.prime_speed));
44
-    SERIAL_ECHOPAIR_P(port, " R", LINEAR_UNIT(toolchange_settings.retract_speed));
37
+    serialprintPGM(eeprom ? PSTR("  M217") : PSTR("Singlenozzle:"));
38
+    SERIAL_ECHOPAIR(" S", LINEAR_UNIT(toolchange_settings.swap_length));
39
+    SERIAL_ECHOPAIR(" P", LINEAR_UNIT(toolchange_settings.prime_speed));
40
+    SERIAL_ECHOPAIR(" R", LINEAR_UNIT(toolchange_settings.retract_speed));
45 41
 
46 42
     #if ENABLED(TOOLCHANGE_PARK)
47
-      SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(toolchange_settings.change_point.x));
48
-      SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(toolchange_settings.change_point.y));
43
+      SERIAL_ECHOPAIR(" X", LINEAR_UNIT(toolchange_settings.change_point.x));
44
+      SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(toolchange_settings.change_point.y));
49 45
     #endif
50 46
 
51 47
   #else
@@ -54,7 +50,7 @@ void M217_report(const bool eeprom=false) {
54 50
 
55 51
   #endif
56 52
 
57
-  SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(toolchange_settings.z_raise));
53
+  SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(toolchange_settings.z_raise));
58 54
   SERIAL_EOL();
59 55
 }
60 56
 

+ 11
- 21
Marlin/src/gcode/config/M92.cpp 查看文件

@@ -23,27 +23,22 @@
23 23
 #include "../gcode.h"
24 24
 #include "../../module/planner.h"
25 25
 
26
-void report_M92(
27
-  #if NUM_SERIAL > 1
28
-    const int8_t port,
29
-  #endif
30
-  const bool echo=true, const int8_t e=-1
31
-) {
32
-  if (echo) SERIAL_ECHO_START_P(port); else SERIAL_CHAR(' ');
33
-  SERIAL_ECHOPAIR_P(port, " M92 X", LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]));
34
-  SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]));
35
-  SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]));
26
+void report_M92(const bool echo=true, const int8_t e=-1) {
27
+  if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
28
+  SERIAL_ECHOPAIR(" M92 X", LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]));
29
+  SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]));
30
+  SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]));
36 31
   #if DISABLED(DISTINCT_E_FACTORS)
37
-    SERIAL_ECHOPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS]));
32
+    SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS]));
38 33
   #endif
39
-  SERIAL_EOL_P(port);
34
+  SERIAL_EOL();
40 35
 
41 36
   #if ENABLED(DISTINCT_E_FACTORS)
42 37
     for (uint8_t i = 0; i < E_STEPPERS; i++) {
43 38
       if (e >= 0 && i != e) continue;
44
-      if (echo) SERIAL_ECHO_START_P(port); else SERIAL_CHAR(' ');
45
-      SERIAL_ECHOPAIR_P(port, " M92 T", (int)i);
46
-      SERIAL_ECHOLNPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)]));
39
+      if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
40
+      SERIAL_ECHOPAIR(" M92 T", (int)i);
41
+      SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)]));
47 42
     }
48 43
   #endif
49 44
 }
@@ -71,12 +66,7 @@ void GcodeSuite::M92() {
71 66
     #if ENABLED(MAGIC_NUMBERS_GCODE)
72 67
       "HL"
73 68
     #endif
74
-  )) return report_M92(
75
-    #if NUM_SERIAL > 1
76
-      command_queue_port[cmd_queue_index_r],
77
-    #endif
78
-    true, target_extruder
79
-  );
69
+  )) return report_M92(true, target_extruder);
80 70
 
81 71
   LOOP_XYZE(i) {
82 72
     if (parser.seenval(axis_codes[i])) {

+ 6
- 21
Marlin/src/gcode/eeprom/M500-M504.cpp 查看文件

@@ -33,17 +33,11 @@
33 33
   #include "../../gcode/queue.h"
34 34
 #endif
35 35
 
36
-#if ADD_PORT_ARG
37
-  #define CHAT_PORT command_queue_port[cmd_queue_index_r]
38
-#else
39
-  #define CHAT_PORT
40
-#endif
41
-
42 36
 /**
43 37
  * M500: Store settings in EEPROM
44 38
  */
45 39
 void GcodeSuite::M500() {
46
-  (void)settings.save(CHAT_PORT);
40
+  (void)settings.save();
47 41
   #if ENABLED(EXTENSIBLE_UI)
48 42
     ExtUI::onStoreSettings();
49 43
   #endif
@@ -53,11 +47,7 @@ void GcodeSuite::M500() {
53 47
  * M501: Read settings from EEPROM
54 48
  */
55 49
 void GcodeSuite::M501() {
56
-  (void)settings.load(
57
-    #if ENABLED(EEPROM_SETTINGS)
58
-      CHAT_PORT
59
-    #endif
60
-  );
50
+  (void)settings.load();
61 51
   #if ENABLED(EXTENSIBLE_UI)
62 52
     ExtUI::onLoadSettings();
63 53
   #endif
@@ -67,7 +57,7 @@ void GcodeSuite::M501() {
67 57
  * M502: Revert to default settings
68 58
  */
69 59
 void GcodeSuite::M502() {
70
-  (void)settings.reset(CHAT_PORT);
60
+  (void)settings.reset();
71 61
   #if ENABLED(EXTENSIBLE_UI)
72 62
     ExtUI::onFactoryReset();
73 63
   #endif
@@ -79,12 +69,7 @@ void GcodeSuite::M502() {
79 69
    * M503: print settings currently in memory
80 70
    */
81 71
   void GcodeSuite::M503() {
82
-    (void)settings.report(
83
-      parser.seen('S') && !parser.value_bool()
84
-      #if NUM_SERIAL > 1
85
-        , command_queue_port[cmd_queue_index_r]
86
-      #endif
87
-    );
72
+    (void)settings.report(parser.boolval('S', true));
88 73
   }
89 74
 
90 75
 #endif // !DISABLE_M503
@@ -94,7 +79,7 @@ void GcodeSuite::M502() {
94 79
    * M504: Validate EEPROM Contents
95 80
    */
96 81
   void GcodeSuite::M504() {
97
-    if (settings.validate(CHAT_PORT))
98
-      SERIAL_ECHO_MSG_P(command_queue_port[cmd_queue_index_r], "EEPROM OK");
82
+    if (settings.validate())
83
+      SERIAL_ECHO_MSG("EEPROM OK");
99 84
   }
100 85
 #endif

+ 2
- 0
Marlin/src/gcode/gcode.cpp 查看文件

@@ -754,6 +754,8 @@ void GcodeSuite::process_parsed_command(
754 754
 void GcodeSuite::process_next_command() {
755 755
   char * const current_command = command_queue[cmd_queue_index_r];
756 756
 
757
+  PORT_REDIRECT(command_queue_port[cmd_queue_index_r]);
758
+
757 759
   if (DEBUGGING(ECHO)) {
758 760
     SERIAL_ECHO_START();
759 761
     SERIAL_ECHOLN(current_command);

+ 2
- 8
Marlin/src/gcode/host/M115.cpp 查看文件

@@ -40,14 +40,8 @@
40 40
  * M115: Capabilities string
41 41
  */
42 42
 void GcodeSuite::M115() {
43
-  #if NUM_SERIAL > 1
44
-    const int8_t port = command_queue_port[cmd_queue_index_r];
45
-    #define CAPLINE(STR,...) cap_line(PSTR(STR), port, __VA_ARGS__)
46
-  #else
47
-    #define CAPLINE(STR,...) cap_line(PSTR(STR), __VA_ARGS__)
48
-  #endif
49
-
50
-  SERIAL_ECHOLNPGM_P(port, MSG_M115_REPORT);
43
+
44
+  SERIAL_ECHOLNPGM(MSG_M115_REPORT);
51 45
 
52 46
   #if ENABLED(EXTENDED_CAPABILITIES_REPORT)
53 47
 

+ 4
- 7
Marlin/src/gcode/parser.cpp 查看文件

@@ -328,13 +328,10 @@ void GCodeParser::parse(char *p) {
328 328
 #endif // CNC_COORDINATE_SYSTEMS
329 329
 
330 330
 void GCodeParser::unknown_command_error() {
331
-  #if NUM_SERIAL > 1
332
-    const int16_t port = command_queue_port[cmd_queue_index_r];
333
-  #endif
334
-  SERIAL_ECHO_START_P(port);
335
-  SERIAL_ECHOPAIR_P(port, MSG_UNKNOWN_COMMAND, command_ptr);
336
-  SERIAL_CHAR_P(port, '"');
337
-  SERIAL_EOL_P(port);
331
+  SERIAL_ECHO_START();
332
+  SERIAL_ECHOPAIR(MSG_UNKNOWN_COMMAND, command_ptr);
333
+  SERIAL_CHAR('"');
334
+  SERIAL_EOL();
338 335
 }
339 336
 
340 337
 #if ENABLED(DEBUG_GCODE_PARSER)

+ 52
- 50
Marlin/src/gcode/queue.cpp 查看文件

@@ -219,21 +219,22 @@ void ok_to_send() {
219 219
   #if NUM_SERIAL > 1
220 220
     const int16_t port = command_queue_port[cmd_queue_index_r];
221 221
     if (port < 0) return;
222
+    PORT_REDIRECT(port);
222 223
   #endif
223 224
   if (!send_ok[cmd_queue_index_r]) return;
224
-  SERIAL_ECHOPGM_P(port, MSG_OK);
225
+  SERIAL_ECHOPGM(MSG_OK);
225 226
   #if ENABLED(ADVANCED_OK)
226 227
     char* p = command_queue[cmd_queue_index_r];
227 228
     if (*p == 'N') {
228
-      SERIAL_ECHO_P(port, ' ');
229
-      SERIAL_ECHO_P(port, *p++);
229
+      SERIAL_ECHO(' ');
230
+      SERIAL_ECHO(*p++);
230 231
       while (NUMERIC_SIGNED(*p))
231
-        SERIAL_ECHO_P(port, *p++);
232
+        SERIAL_ECHO(*p++);
232 233
     }
233
-    SERIAL_ECHOPGM_P(port, " P"); SERIAL_ECHO_P(port, int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
234
-    SERIAL_ECHOPGM_P(port, " B"); SERIAL_ECHO_P(port, BUFSIZE - commands_in_queue);
234
+    SERIAL_ECHOPGM(" P"); SERIAL_ECHO(int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
235
+    SERIAL_ECHOPGM(" B"); SERIAL_ECHO(BUFSIZE - commands_in_queue);
235 236
   #endif
236
-  SERIAL_EOL_P(port);
237
+  SERIAL_EOL();
237 238
 }
238 239
 
239 240
 /**
@@ -244,10 +245,11 @@ void flush_and_request_resend() {
244 245
   #if NUM_SERIAL > 1
245 246
     const int16_t port = command_queue_port[cmd_queue_index_r];
246 247
     if (port < 0) return;
248
+    PORT_REDIRECT(port);
247 249
   #endif
248
-  SERIAL_FLUSH_P(port);
249
-  SERIAL_ECHOPGM_P(port, MSG_RESEND);
250
-  SERIAL_ECHOLN_P(port, gcode_LastN + 1);
250
+  SERIAL_FLUSH();
251
+  SERIAL_ECHOPGM(MSG_RESEND);
252
+  SERIAL_ECHOLN(gcode_LastN + 1);
251 253
   ok_to_send();
252 254
 }
253 255
 
@@ -270,10 +272,11 @@ inline int read_serial(const uint8_t index) {
270 272
   }
271 273
 }
272 274
 
273
-void gcode_line_error(PGM_P err, uint8_t port) {
274
-  SERIAL_ERROR_START_P(port);
275
-  serialprintPGM_P(port, err);
276
-  SERIAL_ECHOLN_P(port, gcode_LastN);
275
+void gcode_line_error(PGM_P const err, const int8_t port) {
276
+  PORT_REDIRECT(port);
277
+  SERIAL_ERROR_START();
278
+  serialprintPGM(err);
279
+  SERIAL_ECHOLN(gcode_LastN);
277 280
   while (read_serial(port) != -1);           // clear out the RX buffer
278 281
   flush_and_request_resend();
279 282
   serial_count[port] = 0;
@@ -281,12 +284,6 @@ void gcode_line_error(PGM_P err, uint8_t port) {
281 284
 
282 285
 #if ENABLED(FAST_FILE_TRANSFER)
283 286
 
284
-  #if ENABLED(SDSUPPORT)
285
-    #define CARD_CHAR_P(C)   SERIAL_CHAR_P(card.transfer_port, C)
286
-    #define CARD_ECHO_P(V)   SERIAL_ECHO_P(card.transfer_port, V)
287
-    #define CARD_ECHOLN_P(V) SERIAL_ECHOLN_P(card.transfer_port, V)
288
-  #endif
289
-
290 287
   inline bool serial_data_available(const uint8_t index) {
291 288
     switch (index) {
292 289
       case 0: return MYSERIAL0.available();
@@ -380,6 +377,11 @@ void gcode_line_error(PGM_P err, uint8_t port) {
380 377
     void receive(char (&buffer)[buffer_size]) {
381 378
       uint8_t data = 0;
382 379
       millis_t transfer_timeout = millis() + RX_TIMESLICE;
380
+
381
+      #if ENABLED(SDSUPPORT)
382
+        PORT_REDIRECT(card.transfer_port);
383
+      #endif
384
+
383 385
       while (PENDING(millis(), transfer_timeout)) {
384 386
         switch (stream_state) {
385 387
           case StreamState::STREAM_RESET:
@@ -388,24 +390,24 @@ void gcode_line_error(PGM_P err, uint8_t port) {
388 390
             packet_reset();
389 391
             stream_state = StreamState::PACKET_HEADER;
390 392
             break;
391
-          case StreamState::STREAM_HEADER: // we could also transfer the filename in this packet, rather than handling it in the gcode
392
-            for (size_t i = 0; i < sizeof(stream_header); ++i) {
393
+          case StreamState::STREAM_HEADER: // The filename could also be in this packet, rather than handling it in the gcode
394
+            for (size_t i = 0; i < sizeof(stream_header); ++i)
393 395
               stream_header_bytes[i] = buffer[i];
394
-            }
396
+
395 397
             if (stream_header.token == 0x1234) {
396 398
               stream_state = StreamState::PACKET_RESET;
397 399
               bytes_received = 0;
398 400
               time_stream_start = millis();
399
-              CARD_ECHO_P("echo: Datastream initialized (");
400
-              CARD_ECHO_P(stream_header.filesize);
401
-              CARD_ECHOLN_P("Bytes expected)");
402
-              CARD_ECHO_P("so"); // confirm active stream and the maximum block size supported
403
-              CARD_CHAR_P(static_cast<uint8_t>(buffer_size & 0xFF));
404
-              CARD_CHAR_P(static_cast<uint8_t>((buffer_size >> 8) & 0xFF));
405
-              CARD_CHAR_P('\n');
401
+              SERIAL_ECHO("echo: Datastream initialized (");
402
+              SERIAL_ECHO(stream_header.filesize);
403
+              SERIAL_ECHOLN("Bytes expected)");
404
+              SERIAL_ECHO("so"); // confirm active stream and the maximum block size supported
405
+              SERIAL_CHAR(static_cast<uint8_t>(buffer_size & 0xFF));
406
+              SERIAL_CHAR(static_cast<uint8_t>((buffer_size >> 8) & 0xFF));
407
+              SERIAL_CHAR('\n');
406 408
             }
407 409
             else {
408
-              CARD_ECHOLN_P("echo: Datastream initialization error (invalid token)");
410
+              SERIAL_ECHOLN("echo: Datastream initialization error (invalid token)");
409 411
               stream_state = StreamState::STREAM_FAILED;
410 412
             }
411 413
             buffer_next_index = 0;
@@ -421,7 +423,7 @@ void gcode_line_error(PGM_P err, uint8_t port) {
421 423
                 stream_state = StreamState::PACKET_DATA;
422 424
               }
423 425
               else {
424
-                CARD_ECHO_P("echo: Datastream packet out of order");
426
+                SERIAL_ECHO("echo: Datastream packet out of order");
425 427
                 stream_state = StreamState::PACKET_FLUSHRX;
426 428
               }
427 429
             }
@@ -433,7 +435,7 @@ void gcode_line_error(PGM_P err, uint8_t port) {
433 435
               buffer[buffer_next_index] = data;
434 436
             }
435 437
             else {
436
-              CARD_ECHO_P("echo: Datastream packet data buffer overrun");
438
+              SERIAL_ECHO("echo: Datastream packet data buffer overrun");
437 439
               stream_state = StreamState::STREAM_FAILED;
438 440
               break;
439 441
             }
@@ -458,22 +460,22 @@ void gcode_line_error(PGM_P err, uint8_t port) {
458 460
               else {
459 461
                 if (bytes_received < stream_header.filesize) {
460 462
                   stream_state = StreamState::PACKET_RESET;    // reset and receive next packet
461
-                  CARD_ECHOLN_P("ok");   // transmit confirm packet received and valid token
463
+                  SERIAL_ECHOLN("ok");   // transmit confirm packet received and valid token
462 464
                 }
463 465
                 else  {
464 466
                   stream_state = StreamState::STREAM_COMPLETE; // no more data required
465 467
                 }
466 468
                 if (card.write(buffer, buffer_next_index) < 0) {
467 469
                   stream_state = StreamState::STREAM_FAILED;
468
-                  CARD_ECHO_P("echo: IO ERROR");
470
+                  SERIAL_ECHO("echo: IO ERROR");
469 471
                   break;
470 472
                 };
471 473
               }
472 474
             }
473 475
             else {
474
-              CARD_ECHO_P("echo: Block(");
475
-              CARD_ECHO_P(packet.header.id);
476
-              CARD_ECHOLN_P(") Corrupt");
476
+              SERIAL_ECHO("echo: Block(");
477
+              SERIAL_ECHO(packet.header.id);
478
+              SERIAL_ECHOLN(") Corrupt");
477 479
               stream_state = StreamState::PACKET_FLUSHRX;
478 480
             }
479 481
             break;
@@ -481,9 +483,9 @@ void gcode_line_error(PGM_P err, uint8_t port) {
481 483
             if (packet_retries < MAX_RETRIES) {
482 484
               packet_retries ++;
483 485
               stream_state = StreamState::PACKET_RESET;
484
-              CARD_ECHO_P("echo: Resend request ");
485
-              CARD_ECHOLN_P(packet_retries);
486
-              CARD_ECHOLN_P("rs"); // transmit resend packet token
486
+              SERIAL_ECHO("echo: Resend request ");
487
+              SERIAL_ECHOLN(packet_retries);
488
+              SERIAL_ECHOLN("rs"); // transmit resend packet token
487 489
             }
488 490
             else {
489 491
               stream_state = StreamState::STREAM_FAILED;
@@ -499,27 +501,27 @@ void gcode_line_error(PGM_P err, uint8_t port) {
499 501
             packet.timeout = millis() + STREAM_MAX_WAIT;
500 502
             break;
501 503
           case StreamState::PACKET_TIMEOUT:
502
-            CARD_ECHOLN_P("echo: Datastream timeout");
504
+            SERIAL_ECHOLN("echo: Datastream timeout");
503 505
             stream_state = StreamState::PACKET_RESEND;
504 506
             break;
505 507
           case StreamState::STREAM_COMPLETE:
506 508
             stream_state = StreamState::STREAM_RESET;
507 509
             card.flag.binary_mode = false;
508 510
             card.closefile();
509
-            CARD_ECHO_P("echo: ");
510
-            CARD_ECHO_P(card.filename);
511
-            CARD_ECHO_P(" transfer completed @ ");
512
-            CARD_ECHO_P(((bytes_received / (millis() - time_stream_start) * 1000) / 1024 ));
513
-            CARD_ECHOLN_P("KiB/s");
514
-            CARD_ECHOLN_P("sc"); // transmit stream complete token
511
+            SERIAL_ECHO("echo: ");
512
+            SERIAL_ECHO(card.filename);
513
+            SERIAL_ECHO(" transfer completed @ ");
514
+            SERIAL_ECHO(((bytes_received / (millis() - time_stream_start) * 1000) / 1024 ));
515
+            SERIAL_ECHOLN("KiB/s");
516
+            SERIAL_ECHOLN("sc"); // transmit stream complete token
515 517
             return;
516 518
           case StreamState::STREAM_FAILED:
517 519
             stream_state = StreamState::STREAM_RESET;
518 520
             card.flag.binary_mode = false;
519 521
             card.closefile();
520 522
             card.removeFile(card.filename);
521
-            CARD_ECHOLN_P("echo: File transfer failed");
522
-            CARD_ECHOLN_P("sf"); // transmit stream failed token
523
+            SERIAL_ECHOLN("echo: File transfer failed");
524
+            SERIAL_ECHOLN("sf"); // transmit stream failed token
523 525
             return;
524 526
         }
525 527
       }

+ 9
- 17
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp 查看文件

@@ -50,17 +50,13 @@
50 50
  * M20: List SD card to serial output
51 51
  */
52 52
 void GcodeSuite::M20() {
53
-  #if NUM_SERIAL > 1
54
-    const int16_t port = command_queue_port[cmd_queue_index_r];
55
-  #endif
56
-
57
-  SERIAL_ECHOLNPGM_P(port, MSG_BEGIN_FILE_LIST);
53
+  SERIAL_ECHOLNPGM(MSG_BEGIN_FILE_LIST);
58 54
   card.ls(
59 55
     #if NUM_SERIAL > 1
60
-      port
56
+      command_queue_port[cmd_queue_index_r]
61 57
     #endif
62 58
   );
63
-  SERIAL_ECHOLNPGM_P(port, MSG_END_FILE_LIST);
59
+  SERIAL_ECHOLNPGM(MSG_END_FILE_LIST);
64 60
 }
65 61
 
66 62
 /**
@@ -165,11 +161,11 @@ void GcodeSuite::M26() {
165 161
  */
166 162
 void GcodeSuite::M27() {
167 163
   #if NUM_SERIAL > 1
168
-    const int16_t port = command_queue_port[cmd_queue_index_r];
164
+    const int16_t port = serial_port_index;
169 165
   #endif
170 166
 
171 167
   if (parser.seen('C')) {
172
-    SERIAL_ECHOPGM_P(port, "Current file: ");
168
+    SERIAL_ECHOPGM("Current file: ");
173 169
     card.printFilename();
174 170
   }
175 171
 
@@ -197,10 +193,6 @@ void GcodeSuite::M28() {
197 193
 
198 194
   #if ENABLED(FAST_FILE_TRANSFER)
199 195
 
200
-    #if NUM_SERIAL > 1
201
-      const int16_t port = command_queue_port[cmd_queue_index_r];
202
-    #endif
203
-
204 196
     bool binary_mode = false;
205 197
     char *p = parser.string_arg;
206 198
     if (p[0] == 'B' && NUMERIC(p[1])) {
@@ -211,12 +203,12 @@ void GcodeSuite::M28() {
211 203
 
212 204
     // Binary transfer mode
213 205
     if ((card.flag.binary_mode = binary_mode)) {
214
-      SERIAL_ECHO_START_P(port);
215
-      SERIAL_ECHO_P(port, " preparing to receive: ");
216
-      SERIAL_ECHOLN_P(port, p);
206
+      SERIAL_ECHO_START();
207
+      SERIAL_ECHO(" preparing to receive: ");
208
+      SERIAL_ECHOLN(p);
217 209
       card.openFile(p, false);
218 210
       #if NUM_SERIAL > 1
219
-        card.transfer_port = port;
211
+        card.transfer_port = command_queue_port[cmd_queue_index_r];
220 212
       #endif
221 213
     }
222 214
     else

+ 2
- 2
Marlin/src/gcode/stats/M31.cpp 查看文件

@@ -42,6 +42,6 @@ void GcodeSuite::M31() {
42 42
   elapsed.toString(buffer);
43 43
   ui.set_status(buffer);
44 44
 
45
-  SERIAL_ECHO_START_P(port);
46
-  SERIAL_ECHOLNPAIR_P(port, "Print time: ", buffer);
45
+  SERIAL_ECHO_START();
46
+  SERIAL_ECHOLNPAIR("Print time: ", buffer);
47 47
 }

+ 3
- 3
Marlin/src/gcode/temperature/M105.cpp 查看文件

@@ -40,15 +40,15 @@ void GcodeSuite::M105() {
40 40
   #endif
41 41
 
42 42
   #if HAS_TEMP_SENSOR
43
-    SERIAL_ECHOPGM_P(port, MSG_OK);
43
+    SERIAL_ECHOPGM(MSG_OK);
44 44
     thermalManager.print_heater_states(target_extruder
45 45
       #if NUM_SERIAL > 1
46 46
         , port
47 47
       #endif
48 48
     );
49 49
   #else // !HAS_TEMP_SENSOR
50
-    SERIAL_ERROR_MSG_P(port, MSG_ERR_NO_THERMISTORS);
50
+    SERIAL_ERROR_MSG(MSG_ERR_NO_THERMISTORS);
51 51
   #endif
52 52
 
53
-  SERIAL_EOL_P(port);
53
+  SERIAL_EOL();
54 54
 }

+ 347
- 385
Marlin/src/module/configuration_store.cpp
文件差異過大導致無法顯示
查看文件


+ 7
- 24
Marlin/src/module/configuration_store.h 查看文件

@@ -27,24 +27,14 @@
27 27
   #include "../HAL/shared/persistent_store_api.h"
28 28
 #endif
29 29
 
30
-#define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
31
-
32
-#if ADD_PORT_ARG
33
-  #define PORTINIT_SOLO    const int8_t port=-1
34
-  #define PORTINIT_AFTER  ,const int8_t port=-1
35
-#else
36
-  #define PORTINIT_SOLO
37
-  #define PORTINIT_AFTER
38
-#endif
39
-
40 30
 class MarlinSettings {
41 31
   public:
42 32
     MarlinSettings() { }
43 33
 
44 34
     static uint16_t datasize();
45 35
 
46
-    static void reset(PORTINIT_SOLO);
47
-    static bool save(PORTINIT_SOLO);    // Return 'true' if data was saved
36
+    static void reset();
37
+    static bool save();    // Return 'true' if data was saved
48 38
 
49 39
     FORCE_INLINE static bool init_eeprom() {
50 40
       reset();
@@ -65,8 +55,8 @@ class MarlinSettings {
65 55
     #endif
66 56
 
67 57
     #if ENABLED(EEPROM_SETTINGS)
68
-      static bool load(PORTINIT_SOLO);      // Return 'true' if data was loaded ok
69
-      static bool validate(PORTINIT_SOLO);  // Return 'true' if EEPROM data is ok
58
+      static bool load();      // Return 'true' if data was loaded ok
59
+      static bool validate();  // Return 'true' if EEPROM data is ok
70 60
 
71 61
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
72 62
                                          // That can store is enabled
@@ -86,11 +76,7 @@ class MarlinSettings {
86 76
     #endif
87 77
 
88 78
     #if DISABLED(DISABLE_M503)
89
-      static void report(const bool forReplay=false
90
-        #if NUM_SERIAL > 1
91
-          , const int8_t port=-1
92
-        #endif
93
-      );
79
+      static void report(const bool forReplay=false);
94 80
     #else
95 81
       FORCE_INLINE
96 82
       static void report(const bool forReplay=false) { UNUSED(forReplay); }
@@ -109,12 +95,9 @@ class MarlinSettings {
109 95
                                           // live at the very end of the eeprom
110 96
       #endif
111 97
 
112
-      static bool _load(PORTINIT_SOLO);
113
-      static bool size_error(const uint16_t size PORTINIT_AFTER);
98
+      static bool _load();
99
+      static bool size_error(const uint16_t size);
114 100
     #endif
115 101
 };
116 102
 
117 103
 extern MarlinSettings settings;
118
-
119
-#undef PORTINIT_SOLO
120
-#undef PORTINIT_AFTER

+ 16
- 23
Marlin/src/module/temperature.cpp 查看文件

@@ -2500,17 +2500,14 @@ void Temperature::isr() {
2500 2500
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
2501 2501
       , const float r
2502 2502
     #endif
2503
-    #if NUM_SERIAL > 1
2504
-      , const int8_t port=-1
2505
-    #endif
2506 2503
     , const int8_t e=-3
2507 2504
   ) {
2508 2505
     #if !(HAS_HEATED_BED && HAS_TEMP_HOTEND && HAS_TEMP_CHAMBER) && HOTENDS <= 1
2509 2506
       UNUSED(e);
2510 2507
     #endif
2511 2508
 
2512
-    SERIAL_CHAR_P(port, ' ');
2513
-    SERIAL_CHAR_P(port,
2509
+    SERIAL_CHAR(' ');
2510
+    SERIAL_CHAR(
2514 2511
       #if HAS_TEMP_CHAMBER && HAS_HEATED_BED && HAS_TEMP_HOTEND
2515 2512
         e == -2 ? 'C' : e == -1 ? 'B' : 'T'
2516 2513
       #elif HAS_HEATED_BED && HAS_TEMP_HOTEND
@@ -2522,23 +2519,19 @@ void Temperature::isr() {
2522 2519
       #endif
2523 2520
     );
2524 2521
     #if HOTENDS > 1
2525
-      if (e >= 0) SERIAL_CHAR_P(port, '0' + e);
2522
+      if (e >= 0) SERIAL_CHAR('0' + e);
2526 2523
     #endif
2527
-    SERIAL_CHAR_P(port, ':');
2528
-    SERIAL_ECHO_P(port, c);
2529
-    SERIAL_ECHOPAIR_P(port, " /" , t);
2524
+    SERIAL_CHAR(':');
2525
+    SERIAL_ECHO(c);
2526
+    SERIAL_ECHOPAIR(" /" , t);
2530 2527
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
2531
-      SERIAL_ECHOPAIR_P(port, " (", r / OVERSAMPLENR);
2532
-      SERIAL_CHAR_P(port, ')');
2528
+      SERIAL_ECHOPAIR(" (", r / OVERSAMPLENR);
2529
+      SERIAL_CHAR(')');
2533 2530
     #endif
2534 2531
     delay(2);
2535 2532
   }
2536 2533
 
2537
-  void Temperature::print_heater_states(const uint8_t target_extruder
2538
-    #if NUM_SERIAL > 1
2539
-      , const int8_t port
2540
-    #endif
2541
-  ) {
2534
+  void Temperature::print_heater_states(const uint8_t target_extruder) {
2542 2535
     #if HAS_TEMP_HOTEND
2543 2536
       print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder)
2544 2537
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
@@ -2579,17 +2572,17 @@ void Temperature::isr() {
2579 2572
         , e
2580 2573
       );
2581 2574
     #endif
2582
-    SERIAL_ECHOPGM_P(port, " @:");
2583
-    SERIAL_ECHO_P(port, getHeaterPower(target_extruder));
2575
+    SERIAL_ECHOPGM(" @:");
2576
+    SERIAL_ECHO(getHeaterPower(target_extruder));
2584 2577
     #if HAS_HEATED_BED
2585
-      SERIAL_ECHOPGM_P(port, " B@:");
2586
-      SERIAL_ECHO_P(port, getHeaterPower(-1));
2578
+      SERIAL_ECHOPGM(" B@:");
2579
+      SERIAL_ECHO(getHeaterPower(-1));
2587 2580
     #endif
2588 2581
     #if HOTENDS > 1
2589 2582
       HOTEND_LOOP() {
2590
-        SERIAL_ECHOPAIR_P(port, " @", e);
2591
-        SERIAL_CHAR_P(port, ':');
2592
-        SERIAL_ECHO_P(port, getHeaterPower(e));
2583
+        SERIAL_ECHOPAIR(" @", e);
2584
+        SERIAL_CHAR(':');
2585
+        SERIAL_ECHO(getHeaterPower(e));
2593 2586
       }
2594 2587
     #endif
2595 2588
   }

+ 1
- 5
Marlin/src/module/temperature.h 查看文件

@@ -672,11 +672,7 @@ class Temperature {
672 672
     #endif // HEATER_IDLE_HANDLER
673 673
 
674 674
     #if HAS_TEMP_SENSOR
675
-      static void print_heater_states(const uint8_t target_extruder
676
-        #if NUM_SERIAL > 1
677
-          , const int8_t port = -1
678
-        #endif
679
-      );
675
+      static void print_heater_states(const uint8_t target_extruder);
680 676
       #if ENABLED(AUTO_REPORT_TEMPERATURES)
681 677
         static uint8_t auto_report_temp_interval;
682 678
         static millis_t next_temp_report_ms;

+ 40
- 77
Marlin/src/sd/cardreader.cpp 查看文件

@@ -51,10 +51,8 @@ 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(FAST_FILE_TRANSFER)
55
-  #if NUM_SERIAL > 1
56
-    uint8_t CardReader::transfer_port;
57
-  #endif
54
+#if ENABLED(FAST_FILE_TRANSFER) && NUM_SERIAL > 1
55
+  int8_t CardReader::transfer_port;
58 56
 #endif
59 57
 
60 58
 // private:
@@ -160,11 +158,7 @@ char *createFilename(char *buffer, const dir_t &p) {
160 158
 
161 159
 uint16_t nrFile_index;
162 160
 
163
-void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/
164
-  #if NUM_SERIAL > 1
165
-    , const int8_t port/*= -1*/
166
-  #endif
167
-) {
161
+void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
168 162
   dir_t p;
169 163
   uint8_t cnt = 0;
170 164
 
@@ -197,16 +191,12 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
197 191
       SdFile dir;
198 192
       if (!dir.open(&parent, dosFilename, O_READ)) {
199 193
         if (lsAction == LS_SerialPrint) {
200
-          SERIAL_ECHO_START_P(port);
201
-          SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR);
202
-          SERIAL_ECHOLN_P(port, dosFilename);
194
+          SERIAL_ECHO_START();
195
+          SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
196
+          SERIAL_ECHOLN(dosFilename);
203 197
         }
204 198
       }
205
-      lsDive(path, dir
206
-        #if NUM_SERIAL > 1
207
-          , NULL, port
208
-        #endif
209
-      );
199
+      lsDive(path, dir);
210 200
       // close() is done automatically by destructor of SdFile
211 201
     }
212 202
     else {
@@ -228,10 +218,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
228 218
 
229 219
         case LS_SerialPrint:
230 220
           createFilename(filename, p);
231
-          if (prepend) SERIAL_ECHO_P(port, prepend);
232
-          SERIAL_ECHO_P(port, filename);
233
-          SERIAL_CHAR_P(port, ' ');
234
-          SERIAL_ECHOLN_P(port, p.fileSize);
221
+          if (prepend) SERIAL_ECHO(prepend);
222
+          SERIAL_ECHO(filename);
223
+          SERIAL_CHAR(' ');
224
+          SERIAL_ECHOLN(p.fileSize);
235 225
           break;
236 226
 
237 227
         case LS_GetFilename:
@@ -248,18 +238,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
248 238
   } // while readDir
249 239
 }
250 240
 
251
-void CardReader::ls(
252
-  #if NUM_SERIAL > 1
253
-    const int8_t port
254
-  #endif
255
-) {
241
+void CardReader::ls() {
256 242
   lsAction = LS_SerialPrint;
257 243
   root.rewind();
258
-  lsDive(NULL, root
259
-    #if NUM_SERIAL > 1
260
-      , NULL, port
261
-    #endif
262
-  );
244
+  lsDive(NULL, root);
263 245
 }
264 246
 
265 247
 #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
@@ -267,16 +249,12 @@ void CardReader::ls(
267 249
   /**
268 250
    * Get a long pretty path based on a DOS 8.3 path
269 251
    */
270
-  void CardReader::printLongPath(char *path
271
-    #if NUM_SERIAL > 1
272
-      , const int8_t port/*= -1*/
273
-    #endif
274
-  ) {
252
+  void CardReader::printLongPath(char *path) {
275 253
     lsAction = LS_GetFilename;
276 254
 
277 255
     int i, pathLen = strlen(path);
278 256
 
279
-    // SERIAL_ECHOPGM_P(port, "Full Path: "); SERIAL_ECHOLN_P(port, path);
257
+    // SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);
280 258
 
281 259
     // Zero out slashes to make segments
282 260
     for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
@@ -294,32 +272,28 @@ void CardReader::ls(
294 272
       // Go to the next segment
295 273
       while (path[++i]) { }
296 274
 
297
-      // SERIAL_ECHOPGM_P(port, "Looking for segment: "); SERIAL_ECHOLN_P(port, segment);
275
+      // SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);
298 276
 
299 277
       // Find the item, setting the long filename
300 278
       diveDir.rewind();
301
-      lsDive(NULL, diveDir, segment
302
-        #if NUM_SERIAL > 1
303
-          , port
304
-        #endif
305
-      );
279
+      lsDive(NULL, diveDir, segment);
306 280
 
307 281
       // Print /LongNamePart to serial output
308
-      SERIAL_CHAR_P(port, '/');
309
-      SERIAL_ECHO_P(port, longFilename[0] ? longFilename : "???");
282
+      SERIAL_CHAR('/');
283
+      SERIAL_ECHO(longFilename[0] ? longFilename : "???");
310 284
 
311 285
       // If the filename was printed then that's it
312 286
       if (!flag.filenameIsDir) break;
313 287
 
314
-      // SERIAL_ECHOPGM_P(port, "Opening dir: "); SERIAL_ECHOLN_P(port, segment);
288
+      // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
315 289
 
316 290
       // Open the sub-item as the new dive parent
317 291
       SdFile dir;
318 292
       if (!dir.open(&diveDir, segment, O_READ)) {
319
-        SERIAL_EOL_P(port);
320
-        SERIAL_ECHO_START_P(port);
321
-        SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR);
322
-        SERIAL_ECHO_P(port, segment);
293
+        SERIAL_EOL();
294
+        SERIAL_ECHO_START();
295
+        SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
296
+        SERIAL_ECHO(segment);
323 297
         break;
324 298
       }
325 299
 
@@ -328,7 +302,7 @@ void CardReader::ls(
328 302
 
329 303
     } // while i<pathLen
330 304
 
331
-    SERIAL_EOL_P(port);
305
+    SERIAL_EOL();
332 306
   }
333 307
 
334 308
 #endif // LONG_FILENAME_HOST_SUPPORT
@@ -336,27 +310,23 @@ void CardReader::ls(
336 310
 /**
337 311
  * Echo the DOS 8.3 filename (and long filename, if any)
338 312
  */
339
-void CardReader::printFilename(
340
-  #if NUM_SERIAL > 1
341
-    const int8_t port/*= -1*/
342
-  #endif
343
-) {
313
+void CardReader::printFilename() {
344 314
   if (file.isOpen()) {
345 315
     char dosFilename[FILENAME_LENGTH];
346 316
     file.getFilename(dosFilename);
347
-    SERIAL_ECHO_P(port, dosFilename);
317
+    SERIAL_ECHO(dosFilename);
348 318
     #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
349 319
       getfilename(0, dosFilename);
350 320
       if (longFilename[0]) {
351
-        SERIAL_ECHO_P(port, ' ');
352
-        SERIAL_ECHO_P(port, longFilename);
321
+        SERIAL_ECHO(' ');
322
+        SERIAL_ECHO(longFilename);
353 323
       }
354 324
     #endif
355 325
   }
356 326
   else
357
-    SERIAL_ECHOPGM_P(port, "(no file)");
327
+    SERIAL_ECHOPGM("(no file)");
358 328
 
359
-  SERIAL_EOL_P(port);
329
+  SERIAL_EOL();
360 330
 }
361 331
 
362 332
 void CardReader::initsd() {
@@ -556,19 +526,15 @@ void CardReader::removeFile(const char * const name) {
556 526
   }
557 527
 }
558 528
 
559
-void CardReader::report_status(
560
-  #if NUM_SERIAL > 1
561
-    const int8_t port/*= -1*/
562
-  #endif
563
-) {
529
+void CardReader::report_status() {
564 530
   if (isPrinting()) {
565
-    SERIAL_ECHOPGM_P(port, MSG_SD_PRINTING_BYTE);
566
-    SERIAL_ECHO_P(port, sdpos);
567
-    SERIAL_CHAR_P(port, '/');
568
-    SERIAL_ECHOLN_P(port, filesize);
531
+    SERIAL_ECHOPGM(MSG_SD_PRINTING_BYTE);
532
+    SERIAL_ECHO(sdpos);
533
+    SERIAL_CHAR('/');
534
+    SERIAL_ECHOLN(filesize);
569 535
   }
570 536
   else
571
-    SERIAL_ECHOLNPGM_P(port, MSG_SD_NOT_PRINTING);
537
+    SERIAL_ECHOLNPGM(MSG_SD_NOT_PRINTING);
572 538
 }
573 539
 
574 540
 void CardReader::write_command(char *buf) {
@@ -1038,18 +1004,15 @@ void CardReader::printingHasFinished() {
1038 1004
   uint8_t CardReader::auto_report_sd_interval = 0;
1039 1005
   millis_t CardReader::next_sd_report_ms;
1040 1006
   #if NUM_SERIAL > 1
1041
-    int8_t CardReader::serialport;
1007
+    int8_t CardReader::auto_report_port;
1042 1008
   #endif
1043 1009
 
1044 1010
   void CardReader::auto_report_sd_status() {
1045 1011
     millis_t current_ms = millis();
1046 1012
     if (auto_report_sd_interval && ELAPSED(current_ms, next_sd_report_ms)) {
1047 1013
       next_sd_report_ms = current_ms + 1000UL * auto_report_sd_interval;
1048
-      report_status(
1049
-        #if NUM_SERIAL > 1
1050
-          serialport
1051
-        #endif
1052
-      );
1014
+      PORT_REDIRECT(auto_report_port);
1015
+      report_status();
1053 1016
     }
1054 1017
   }
1055 1018
 #endif // AUTO_REPORT_SD_STATUS

+ 10
- 34
Marlin/src/sd/cardreader.h 查看文件

@@ -70,24 +70,12 @@ public:
70 70
       const bool re_sort=false
71 71
     #endif
72 72
   );
73
-  static void report_status(
74
-    #if NUM_SERIAL > 1
75
-      const int8_t port = -1
76
-    #endif
77
-  );
73
+  static void report_status();
78 74
   static void printingHasFinished();
79
-  static void printFilename(
80
-    #if NUM_SERIAL > 1
81
-      const int8_t port = -1
82
-    #endif
83
-  );
75
+  static void printFilename();
84 76
 
85 77
   #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
86
-    static void printLongPath(char *path
87
-      #if NUM_SERIAL > 1
88
-        , const int8_t port = -1
89
-      #endif
90
-    );
78
+    static void printLongPath(char *path);
91 79
   #endif
92 80
 
93 81
   static void getfilename(uint16_t nr, const char* const match=NULL);
@@ -95,11 +83,7 @@ public:
95 83
 
96 84
   static void getAbsFilename(char *t);
97 85
 
98
-  static void ls(
99
-    #if NUM_SERIAL > 1
100
-      const int8_t port = -1
101
-    #endif
102
-  );
86
+  static void ls();
103 87
   static void chdir(const char *relpath);
104 88
   static int8_t updir();
105 89
   static void setroot();
@@ -144,13 +128,9 @@ public:
144 128
 
145 129
   #if ENABLED(AUTO_REPORT_SD_STATUS)
146 130
     static void auto_report_sd_status(void);
147
-    static inline void set_auto_report_interval(uint8_t v
148
-      #if NUM_SERIAL > 1
149
-        , int8_t port
150
-      #endif
151
-    ) {
131
+    static inline void set_auto_report_interval(const uint8_t v) {
152 132
       #if NUM_SERIAL > 1
153
-        serialport = port;
133
+        auto_report_port = serial_port_index;
154 134
       #endif
155 135
       NOMORE(v, 60);
156 136
       auto_report_sd_interval = v;
@@ -167,9 +147,9 @@ public:
167 147
 
168 148
   #if ENABLED(FAST_FILE_TRANSFER)
169 149
     #if NUM_SERIAL > 1
170
-      static uint8_t transfer_port;
150
+      static int8_t transfer_port;
171 151
     #else
172
-      static constexpr uint8_t transfer_port = 0;
152
+      static constexpr int8_t transfer_port = SERIAL_PORT;
173 153
     #endif
174 154
   #endif
175 155
 
@@ -244,11 +224,7 @@ private:
244 224
   static LsAction lsAction; //stored for recursion.
245 225
   static uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
246 226
   static char *diveDirName;
247
-  static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL
248
-    #if NUM_SERIAL > 1
249
-      , const int8_t port = -1
250
-    #endif
251
-  );
227
+  static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
252 228
 
253 229
   #if ENABLED(SDCARD_SORT_ALPHA)
254 230
     static void flush_presort();
@@ -258,7 +234,7 @@ private:
258 234
     static uint8_t auto_report_sd_interval;
259 235
     static millis_t next_sd_report_ms;
260 236
     #if NUM_SERIAL > 1
261
-      static int8_t serialport;
237
+      static int8_t auto_report_port;
262 238
     #endif
263 239
   #endif
264 240
 };

Loading…
取消
儲存