浏览代码

Distinguish serial index from mask (#21287)

X-Ryl669 3 年前
父节点
当前提交
55c31fbe9a
没有帐户链接到提交者的电子邮件

+ 15
- 16
Marlin/src/core/serial.h 查看文件

@@ -62,37 +62,36 @@ extern uint8_t marlin_debug_flags;
62 62
 //
63 63
 // Serial redirection
64 64
 //
65
-#define SERIAL_ALL 0xFF
66 65
 #if HAS_MULTI_SERIAL
67
-  #define _PORT_REDIRECT(n,p)   REMEMBER(n,multiSerial.portMask,p)
68
-  #define _PORT_RESTORE(n,p)    RESTORE(n)
69
-  #define SERIAL_ASSERT(P)      if(multiSerial.portMask!=(P)){ debugger(); }
66
+  #define _PORT_REDIRECT(n,p) REMEMBER(n,multiSerial.portMask,p)
67
+  #define _PORT_RESTORE(n,p)  RESTORE(n)
68
+  #define SERIAL_ASSERT(P)    if(multiSerial.portMask!=(P)){ debugger(); }
70 69
   #ifdef SERIAL_CATCHALL
71 70
     typedef MultiSerial<decltype(MYSERIAL), decltype(SERIAL_CATCHALL), 0> SerialOutputT;
72 71
   #else
73
-    typedef MultiSerial<decltype(MYSERIAL0), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL1)>, decltype(MYSERIAL1)), 0>      SerialOutputT;
72
+    typedef MultiSerial<decltype(MYSERIAL0), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL1)>, decltype(MYSERIAL1)), 0> SerialOutputT;
74 73
   #endif
75
-  extern SerialOutputT          multiSerial;
76
-  #define _SERIAL_IMPL          multiSerial
74
+  extern SerialOutputT        multiSerial;
75
+  #define _SERIAL_IMPL        multiSerial
77 76
 #else
78
-  #define _PORT_REDIRECT(n,p)   NOOP
79
-  #define _PORT_RESTORE(n)      NOOP
80
-  #define SERIAL_ASSERT(P)      NOOP
81
-  #define _SERIAL_IMPL          MYSERIAL0
77
+  #define _PORT_REDIRECT(n,p) NOOP
78
+  #define _PORT_RESTORE(n)    NOOP
79
+  #define SERIAL_ASSERT(P)    NOOP
80
+  #define _SERIAL_IMPL        MYSERIAL0
82 81
 #endif
83 82
 
84 83
 #if ENABLED(MEATPACK)
85 84
   extern MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial;
86
-  #define SERIAL_IMPL          mpSerial
85
+  #define SERIAL_IMPL mpSerial
87 86
 #else
88
-  #define SERIAL_IMPL          _SERIAL_IMPL
87
+  #define SERIAL_IMPL _SERIAL_IMPL
89 88
 #endif
90 89
 
91 90
 #define SERIAL_OUT(WHAT, V...)  (void)SERIAL_IMPL.WHAT(V)
92 91
 
93
-#define PORT_REDIRECT(p)        _PORT_REDIRECT(1,p)
94
-#define PORT_RESTORE()          _PORT_RESTORE(1)
95
-#define SERIAL_PORTMASK(P)      _BV(P)
92
+#define PORT_REDIRECT(p)   _PORT_REDIRECT(1,p)
93
+#define PORT_RESTORE()     _PORT_RESTORE(1)
94
+#define SERIAL_PORTMASK(P) SerialMask::from(P)
96 95
 
97 96
 //
98 97
 // SERIAL_CHAR - Print one or more individual chars

+ 20
- 3
Marlin/src/core/serial_base.h 查看文件

@@ -22,12 +22,29 @@
22 22
 #pragma once
23 23
 
24 24
 #include "../inc/MarlinConfigPre.h"
25
-#include "macros.h"
26 25
 
27 26
 #if ENABLED(EMERGENCY_PARSER)
28 27
   #include "../feature/e_parser.h"
29 28
 #endif
30 29
 
30
+// Used in multiple places
31
+// You can build it but not manipulate it.
32
+// There are only few places where it's required to access the underlying member: GCodeQueue, SerialMask and MultiSerial
33
+struct serial_index_t {
34
+  // A signed index, where -1 is a special case meaning no action (neither output or input)
35
+  int8_t  index;
36
+
37
+  // Check if the index is within the range [a ... b]
38
+  constexpr inline bool within(const int8_t a, const int8_t b) const { return WITHIN(index, a, b); }
39
+  constexpr inline bool valid() const { return WITHIN(index, 0, 7); } // At most, 8 bits
40
+
41
+  // Construction is either from an index
42
+  constexpr serial_index_t(const int8_t index) : index(index) {}
43
+
44
+  // Default to "no index"
45
+  constexpr serial_index_t() : index(-1) {}
46
+};
47
+
31 48
 // flushTX is not implemented in all HAL, so use SFINAE to call the method where it is.
32 49
 CALL_IF_EXISTS_IMPL(void, flushTX);
33 50
 CALL_IF_EXISTS_IMPL(bool, connected, true);
@@ -79,10 +96,10 @@ struct SerialBase {
79 96
   void end()                        { static_cast<Child*>(this)->end(); }
80 97
   /** Check for available data from the port
81 98
       @param index  The port index, usually 0 */
82
-  int available(uint8_t index = 0)  { return static_cast<Child*>(this)->available(index); }
99
+  int available(serial_index_t index = 0)  { return static_cast<Child*>(this)->available(index); }
83 100
   /** Read a value from the port
84 101
       @param index  The port index, usually 0 */
85
-  int  read(uint8_t index = 0)      { return static_cast<Child*>(this)->read(index); }
102
+  int  read(serial_index_t index = 0)      { return static_cast<Child*>(this)->read(index); }
86 103
   // Check if the serial port is connected (usually bypassed)
87 104
   bool connected()                  { return static_cast<Child*>(this)->connected(); }
88 105
   // Redirect flush

+ 62
- 44
Marlin/src/core/serial_hook.h 查看文件

@@ -21,11 +21,32 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-#include "macros.h"
25 24
 #include "serial_base.h"
26 25
 
27
-// Used in multiple places
28
-typedef int8_t serial_index_t;
26
+// A mask containing a bitmap of the serial port to act upon
27
+// This is written to ensure a serial index is never used as a serial mask
28
+class SerialMask {
29
+  uint8_t mask;
30
+
31
+  // This constructor is private to ensure you can't convert an index to a mask
32
+  // The compiler will stop here if you are mixing index and mask in your code.
33
+  // If you need to, you'll have to use the explicit static "from" method here
34
+  SerialMask(const serial_index_t);
35
+
36
+public:
37
+  inline constexpr bool enabled(const SerialMask PortMask) const    { return mask & PortMask.mask; }
38
+  inline constexpr SerialMask combine(const SerialMask other) const { return SerialMask(mask | other.mask); }
39
+  inline constexpr SerialMask operator<< (const int offset) const   { return SerialMask(mask << offset); }
40
+  static inline SerialMask from(const serial_index_t index) {
41
+    if (index.valid()) return SerialMask(_BV(index.index));
42
+    return SerialMask(0); // A invalid index mean no output
43
+  }
44
+
45
+  constexpr SerialMask(const uint8_t mask) : mask(mask) {}
46
+  constexpr SerialMask(const SerialMask & other) : mask(other.mask) {} // Can't use = default here since not all framework support this
47
+
48
+  static constexpr uint8_t All = 0xFF;
49
+};
29 50
 
30 51
 // The most basic serial class: it dispatch to the base serial class with no hook whatsoever. This will compile to nothing but the base serial class
31 52
 template <class SerialT>
@@ -39,10 +60,10 @@ struct BaseSerial : public SerialBase< BaseSerial<SerialT> >, public SerialT {
39 60
   void msgDone() {}
40 61
 
41 62
   // We don't care about indices here, since if one can call us, it's the right index anyway
42
-  int available(uint8_t)  { return (int)SerialT::available(); }
43
-  int read(uint8_t)       { return (int)SerialT::read(); }
44
-  bool connected()        { return CALL_IF_EXISTS(bool, static_cast<SerialT*>(this), connected);; }
45
-  void flushTX()          { CALL_IF_EXISTS(void, static_cast<SerialT*>(this), flushTX); }
63
+  int available(serial_index_t) { return (int)SerialT::available(); }
64
+  int read(serial_index_t)      { return (int)SerialT::read(); }
65
+  bool connected()              { return CALL_IF_EXISTS(bool, static_cast<SerialT*>(this), connected);; }
66
+  void flushTX()                { CALL_IF_EXISTS(void, static_cast<SerialT*>(this), flushTX); }
46 67
 
47 68
   // We have 2 implementation of the same method in both base class, let's say which one we want
48 69
   using SerialT::available;
@@ -77,11 +98,10 @@ struct ConditionalSerial : public SerialBase< ConditionalSerial<SerialT> > {
77 98
   bool connected()          { return CALL_IF_EXISTS(bool, &out, connected); }
78 99
   void flushTX()            { CALL_IF_EXISTS(void, &out, flushTX); }
79 100
 
80
-  int available(uint8_t )   { return (int)out.available(); }
81
-  int read(uint8_t )        { return (int)out.read(); }
82
-  int available()           { return (int)out.available(); }
83
-  int read()                { return (int)out.read(); }
84
-
101
+  int available(serial_index_t )  { return (int)out.available(); }
102
+  int read(serial_index_t )       { return (int)out.read(); }
103
+  int available()                 { return (int)out.available(); }
104
+  int read()                      { return (int)out.read(); }
85 105
 
86 106
   ConditionalSerial(bool & conditionVariable, SerialT & out, const bool e) : BaseClassT(e), condition(conditionVariable), out(out) {}
87 107
 };
@@ -102,8 +122,8 @@ struct ForwardSerial : public SerialBase< ForwardSerial<SerialT> > {
102 122
   bool connected()              { return Private::HasMember_connected<SerialT>::value ? CALL_IF_EXISTS(bool, &out, connected) : (bool)out; }
103 123
   void flushTX()                { CALL_IF_EXISTS(void, &out, flushTX); }
104 124
 
105
-  int available(uint8_t)        { return (int)out.available(); }
106
-  int read(uint8_t)             { return (int)out.read(); }
125
+  int available(serial_index_t) { return (int)out.available(); }
126
+  int read(serial_index_t)      { return (int)out.read(); }
107 127
   int available()               { return (int)out.available(); }
108 128
   int read()                    { return (int)out.read(); }
109 129
 
@@ -130,8 +150,8 @@ struct RuntimeSerial : public SerialBase< RuntimeSerial<SerialT> >, public Seria
130 150
     if (eofHook) eofHook(userPointer);
131 151
   }
132 152
 
133
-  int available(uint8_t)  { return (int)SerialT::available(); }
134
-  int read(uint8_t)       { return (int)SerialT::read(); }
153
+  int available(serial_index_t)  { return (int)SerialT::available(); }
154
+  int read(serial_index_t)       { return (int)SerialT::read(); }
135 155
   using SerialT::available;
136 156
   using SerialT::read;
137 157
   using SerialT::flush;
@@ -170,53 +190,51 @@ template <class Serial0T, class Serial1T, const uint8_t offset = 0, const uint8_
170 190
 struct MultiSerial : public SerialBase< MultiSerial<Serial0T, Serial1T, offset, step> > {
171 191
   typedef SerialBase< MultiSerial<Serial0T, Serial1T, offset, step> > BaseClassT;
172 192
 
173
-  uint8_t    portMask;
193
+  SerialMask portMask;
174 194
   Serial0T & serial0;
175 195
   Serial1T & serial1;
176 196
 
177
-  enum Masks {
178
-    UsageMask         =  ((1 << step) - 1), // A bit mask containing as many bits as step
179
-    FirstOutputMask   =  (UsageMask << offset),
180
-    SecondOutputMask  =  (UsageMask << (offset + step)),
181
-    AllMask           = FirstOutputMask | SecondOutputMask,
182
-  };
197
+  static constexpr uint8_t Usage         =  ((1 << step) - 1); // A bit mask containing as many bits as step
198
+  static constexpr uint8_t FirstOutput   = (Usage << offset);
199
+  static constexpr uint8_t SecondOutput  = (Usage << (offset + step));
200
+  static constexpr uint8_t Both          = FirstOutput | SecondOutput;
183 201
 
184 202
   NO_INLINE size_t write(uint8_t c) {
185 203
     size_t ret = 0;
186
-    if (portMask & FirstOutputMask)   ret = serial0.write(c);
187
-    if (portMask & SecondOutputMask)  ret = serial1.write(c) | ret;
204
+    if (portMask.enabled(FirstOutput))   ret = serial0.write(c);
205
+    if (portMask.enabled(SecondOutput))  ret = serial1.write(c) | ret;
188 206
     return ret;
189 207
   }
190 208
   NO_INLINE void msgDone() {
191
-    if (portMask & FirstOutputMask)   serial0.msgDone();
192
-    if (portMask & SecondOutputMask)  serial1.msgDone();
209
+    if (portMask.enabled(FirstOutput))   serial0.msgDone();
210
+    if (portMask.enabled(SecondOutput))  serial1.msgDone();
193 211
   }
194
-  int available(uint8_t index) {
195
-    if (index >= 0 + offset && index < step + offset)
212
+  int available(serial_index_t index) {
213
+    if (index.within(0 + offset, step + offset - 1))
196 214
       return serial0.available(index);
197
-    else if (index >= step + offset && index < 2 * step + offset)
215
+    else if (index.within(step + offset, 2 * step + offset - 1))
198 216
       return serial1.available(index);
199 217
     return false;
200 218
   }
201
-  int read(uint8_t index) {
202
-    if (index >= 0 + offset && index < step + offset)
219
+  int read(serial_index_t index) {
220
+    if (index.within(0 + offset, step + offset - 1))
203 221
       return serial0.read(index);
204
-    else if (index >= step + offset && index < 2 * step + offset)
222
+    else if (index.within(step + offset, 2 * step + offset - 1))
205 223
       return serial1.read(index);
206 224
     return -1;
207 225
   }
208 226
   void begin(const long br) {
209
-    if (portMask & FirstOutputMask)   serial0.begin(br);
210
-    if (portMask & SecondOutputMask)  serial1.begin(br);
227
+    if (portMask.enabled(FirstOutput))   serial0.begin(br);
228
+    if (portMask.enabled(SecondOutput))  serial1.begin(br);
211 229
   }
212 230
   void end() {
213
-    if (portMask & FirstOutputMask)   serial0.end();
214
-    if (portMask & SecondOutputMask)  serial1.end();
231
+    if (portMask.enabled(FirstOutput))   serial0.end();
232
+    if (portMask.enabled(SecondOutput))  serial1.end();
215 233
   }
216 234
   bool connected() {
217 235
     bool ret = true;
218
-    if (portMask & FirstOutputMask)   ret = CALL_IF_EXISTS(bool, &serial0, connected);
219
-    if (portMask & SecondOutputMask)  ret = ret && CALL_IF_EXISTS(bool, &serial1, connected);
236
+    if (portMask.enabled(FirstOutput))   ret = CALL_IF_EXISTS(bool, &serial0, connected);
237
+    if (portMask.enabled(SecondOutput))  ret = ret && CALL_IF_EXISTS(bool, &serial1, connected);
220 238
     return ret;
221 239
   }
222 240
 
@@ -225,15 +243,15 @@ struct MultiSerial : public SerialBase< MultiSerial<Serial0T, Serial1T, offset,
225 243
 
226 244
   // Redirect flush
227 245
   NO_INLINE void flush()      {
228
-    if (portMask & FirstOutputMask)   serial0.flush();
229
-    if (portMask & SecondOutputMask)  serial1.flush();
246
+    if (portMask.enabled(FirstOutput))   serial0.flush();
247
+    if (portMask.enabled(SecondOutput))  serial1.flush();
230 248
   }
231 249
   NO_INLINE void flushTX()    {
232
-    if (portMask & FirstOutputMask)   CALL_IF_EXISTS(void, &serial0, flushTX);
233
-    if (portMask & SecondOutputMask)  CALL_IF_EXISTS(void, &serial1, flushTX);
250
+    if (portMask.enabled(FirstOutput))   CALL_IF_EXISTS(void, &serial0, flushTX);
251
+    if (portMask.enabled(SecondOutput))  CALL_IF_EXISTS(void, &serial1, flushTX);
234 252
   }
235 253
 
236
-  MultiSerial(Serial0T & serial0, Serial1T & serial1, int8_t mask = AllMask, const bool e = false) :
254
+  MultiSerial(Serial0T & serial0, Serial1T & serial1, const SerialMask mask = Both, const bool e = false) :
237 255
     BaseClassT(e),
238 256
     portMask(mask), serial0(serial0), serial1(serial1) {}
239 257
 };

+ 5
- 5
Marlin/src/feature/host_actions.cpp 查看文件

@@ -38,7 +38,7 @@
38 38
 #endif
39 39
 
40 40
 void host_action(PGM_P const pstr, const bool eol) {
41
-  PORT_REDIRECT(SERIAL_ALL);
41
+  PORT_REDIRECT(SerialMask::All);
42 42
   SERIAL_ECHOPGM("//action:");
43 43
   SERIAL_ECHOPGM_P(pstr);
44 44
   if (eol) SERIAL_EOL();
@@ -78,19 +78,19 @@ void host_action(PGM_P const pstr, const bool eol) {
78 78
   PromptReason host_prompt_reason = PROMPT_NOT_DEFINED;
79 79
 
80 80
   void host_action_notify(const char * const message) {
81
-    PORT_REDIRECT(SERIAL_ALL);
81
+    PORT_REDIRECT(SerialMask::All);
82 82
     host_action(PSTR("notification "), false);
83 83
     SERIAL_ECHOLN(message);
84 84
   }
85 85
 
86 86
   void host_action_notify_P(PGM_P const message) {
87
-    PORT_REDIRECT(SERIAL_ALL);
87
+    PORT_REDIRECT(SerialMask::All);
88 88
     host_action(PSTR("notification "), false);
89 89
     SERIAL_ECHOLNPGM_P(message);
90 90
   }
91 91
 
92 92
   void host_action_prompt(PGM_P const ptype, const bool eol=true) {
93
-    PORT_REDIRECT(SERIAL_ALL);
93
+    PORT_REDIRECT(SerialMask::All);
94 94
     host_action(PSTR("prompt_"), false);
95 95
     SERIAL_ECHOPGM_P(ptype);
96 96
     if (eol) SERIAL_EOL();
@@ -98,7 +98,7 @@ void host_action(PGM_P const pstr, const bool eol) {
98 98
 
99 99
   void host_action_prompt_plus(PGM_P const ptype, PGM_P const pstr, const char extra_char='\0') {
100 100
     host_action_prompt(ptype, false);
101
-    PORT_REDIRECT(SERIAL_ALL);
101
+    PORT_REDIRECT(SerialMask::All);
102 102
     SERIAL_CHAR(' ');
103 103
     SERIAL_ECHOPGM_P(pstr);
104 104
     if (extra_char != '\0') SERIAL_CHAR(extra_char);

+ 12
- 12
Marlin/src/feature/meatpack.h 查看文件

@@ -132,17 +132,17 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
132 132
   uint8_t charCount;
133 133
   uint8_t readIndex;
134 134
 
135
-  NO_INLINE size_t write(uint8_t c) { return out.write(c); }
136
-  void flush()                      { out.flush();  }
137
-  void begin(long br)               { out.begin(br); readIndex = 0; }
138
-  void end()                        { out.end(); }
135
+  NO_INLINE size_t write(uint8_t c)   { return out.write(c); }
136
+  void flush()                        { out.flush();  }
137
+  void begin(long br)                 { out.begin(br); readIndex = 0; }
138
+  void end()                          { out.end(); }
139 139
 
140
-  void msgDone()                    { out.msgDone(); }
140
+  void msgDone()                      { out.msgDone(); }
141 141
   // Existing instances implement Arduino's operator bool, so use that if it's available
142
-  bool connected()                  { return Private::HasMember_connected<SerialT>::value ? CALL_IF_EXISTS(bool, &out, connected) : (bool)out; }
143
-  void flushTX()                    { CALL_IF_EXISTS(void, &out, flushTX); }
142
+  bool connected()                    { return Private::HasMember_connected<SerialT>::value ? CALL_IF_EXISTS(bool, &out, connected) : (bool)out; }
143
+  void flushTX()                      { CALL_IF_EXISTS(void, &out, flushTX); }
144 144
 
145
-  int available(uint8_t index) {
145
+  int available(serial_index_t index) {
146 146
     // There is a potential issue here with multiserial, since it'll return its decoded buffer whatever the serial index here.
147 147
     // So, instead of doing MeatpackSerial<MultiSerial<...>> we should do MultiSerial<MeatpackSerial<...>, MeatpackSerial<...>>
148 148
     // TODO, let's fix this later on
@@ -160,7 +160,7 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
160 160
     return charCount;
161 161
   }
162 162
 
163
-  int readImpl(const uint8_t index) {
163
+  int readImpl(const serial_index_t index) {
164 164
     // Not enough char to make progress?
165 165
     if (charCount == 0 && available(index) == 0) return -1;
166 166
 
@@ -168,9 +168,9 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
168 168
     return serialBuffer[readIndex++];
169 169
   }
170 170
 
171
-  int read(uint8_t index) { return readImpl(index); }
172
-  int available()         { return available(0); }
173
-  int read()              { return readImpl(0); }
171
+  int read(serial_index_t index)  { return readImpl(index); }
172
+  int available()                 { return available(0); }
173
+  int read()                      { return readImpl(0); }
174 174
 
175 175
   MeatpackSerial(const bool e, SerialT & out) : BaseClassT(e), out(out) {}
176 176
 };

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

@@ -1067,7 +1067,7 @@ void GcodeSuite::process_subcommands_now(char * gcode) {
1067 1067
     static millis_t next_busy_signal_ms = 0;
1068 1068
     if (!autoreport_paused && host_keepalive_interval && busy_state != NOT_BUSY) {
1069 1069
       if (PENDING(ms, next_busy_signal_ms)) return;
1070
-      PORT_REDIRECT(SERIAL_ALL);
1070
+      PORT_REDIRECT(SerialMask::All);
1071 1071
       switch (busy_state) {
1072 1072
         case IN_HANDLER:
1073 1073
         case IN_PROCESS:

+ 1
- 1
Marlin/src/gcode/host/M118.cpp 查看文件

@@ -52,7 +52,7 @@ void GcodeSuite::M118() {
52 52
     while (*p == ' ') ++p;
53 53
   }
54 54
 
55
-  PORT_REDIRECT(WITHIN(port, 0, NUM_SERIAL) ? (port ? SERIAL_PORTMASK(port - 1) : SERIAL_ALL) : multiSerial.portMask);
55
+  PORT_REDIRECT(WITHIN(port, 0, NUM_SERIAL) ? (port ? SERIAL_PORTMASK(port - 1) : SerialMask::All) : multiSerial.portMask);
56 56
 
57 57
   if (hasE) SERIAL_ECHO_START();
58 58
   if (hasA) SERIAL_ECHOPGM("//");

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

@@ -240,7 +240,7 @@ void GCodeQueue::RingBuffer::ok_to_send() {
240 240
   CommandLine &command = commands[index_r];
241 241
   #if HAS_MULTI_SERIAL
242 242
     const serial_index_t serial_ind = command.port;
243
-    if (serial_ind < 0) return;
243
+    if (!serial_ind.valid()) return;              // Optimization here, skip processing if it's not going anywhere
244 244
     PORT_REDIRECT(SERIAL_PORTMASK(serial_ind));   // Reply to the serial port that sent the command
245 245
   #endif
246 246
   if (command.skip_ok) return;
@@ -264,15 +264,15 @@ void GCodeQueue::RingBuffer::ok_to_send() {
264 264
  */
265 265
 void GCodeQueue::flush_and_request_resend(const serial_index_t serial_ind) {
266 266
   #if HAS_MULTI_SERIAL
267
-    if (serial_ind < 0) return;                   // Never mind. Command came from SD or Flash Drive
267
+    if (!serial_ind.valid()) return;              // Optimization here, skip if the command came from SD or Flash Drive
268 268
     PORT_REDIRECT(SERIAL_PORTMASK(serial_ind));   // Reply to the serial port that sent the command
269 269
   #endif
270 270
   SERIAL_FLUSH();
271 271
   SERIAL_ECHOPGM(STR_RESEND);
272
-  SERIAL_ECHOLN(serial_state[serial_ind].last_N + 1);
272
+  SERIAL_ECHOLN(serial_state[serial_ind.index].last_N + 1);
273 273
 }
274 274
 
275
-inline bool serial_data_available(uint8_t index) {
275
+inline bool serial_data_available(serial_index_t index) {
276 276
   const int a = SERIAL_IMPL.available(index);
277 277
   #if BOTH(RX_BUFFER_MONITOR, RX_BUFFER_SIZE)
278 278
     if (a > RX_BUFFER_SIZE - 2) {
@@ -290,15 +290,15 @@ inline bool any_serial_data_available() {
290 290
       return true;
291 291
 }
292 292
 
293
-inline int read_serial(const uint8_t index) { return SERIAL_IMPL.read(index); }
293
+inline int read_serial(const serial_index_t index) { return SERIAL_IMPL.read(index); }
294 294
 
295 295
 void GCodeQueue::gcode_line_error(PGM_P const err, const serial_index_t serial_ind) {
296 296
   PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command
297 297
   SERIAL_ERROR_START();
298
-  SERIAL_ECHOLNPAIR_P(err, serial_state[serial_ind].last_N);
298
+  SERIAL_ECHOLNPAIR_P(err, serial_state[serial_ind.index].last_N);
299 299
   while (read_serial(serial_ind) != -1) { /* nada */ } // Clear out the RX buffer. Why don't use flush here ?
300 300
   flush_and_request_resend(serial_ind);
301
-  serial_state[serial_ind].count = 0;
301
+  serial_state[serial_ind.index].count = 0;
302 302
 }
303 303
 
304 304
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc

+ 3
- 3
Marlin/src/gcode/queue.h 查看文件

@@ -79,13 +79,13 @@ public:
79 79
 
80 80
     void commit_command(bool skip_ok
81 81
       #if HAS_MULTI_SERIAL
82
-        , serial_index_t serial_ind=-1
82
+        , serial_index_t serial_ind = serial_index_t()
83 83
       #endif
84 84
     );
85 85
 
86 86
     bool enqueue(const char* cmd, bool skip_ok = true
87 87
       #if HAS_MULTI_SERIAL
88
-        , serial_index_t serial_ind=-1
88
+        , serial_index_t serial_ind = serial_index_t()
89 89
       #endif
90 90
     );
91 91
 
@@ -197,7 +197,7 @@ public:
197 197
   /**
198 198
    * (Re)Set the current line number for the last received command
199 199
    */
200
-  static inline void set_current_line_number(long n) { serial_state[ring_buffer.command_port()].last_N = n; }
200
+  static inline void set_current_line_number(long n) { serial_state[ring_buffer.command_port().index].last_N = n; }
201 201
 
202 202
 private:
203 203
 

+ 1
- 1
Marlin/src/gcode/sd/M1001.cpp 查看文件

@@ -82,7 +82,7 @@ void GcodeSuite::M1001() {
82 82
 
83 83
   // Announce SD file completion
84 84
   {
85
-    PORT_REDIRECT(SERIAL_ALL);
85
+    PORT_REDIRECT(SerialMask::All);
86 86
     SERIAL_ECHOLNPGM(STR_FILE_PRINTED);
87 87
   }
88 88
 

+ 3
- 3
Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp 查看文件

@@ -395,21 +395,21 @@ void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *va
395 395
     default: return;
396 396
     #if HOTENDS >= 1
397 397
       case VP_T_E0_Set:
398
-        NOMORE(newvalue, HEATER_0_MAXTEMP);
398
+        NOMORE(newvalue, (uint16_t)HEATER_0_MAXTEMP);
399 399
         thermalManager.setTargetHotend(newvalue, 0);
400 400
         acceptedvalue = thermalManager.degTargetHotend(0);
401 401
         break;
402 402
     #endif
403 403
     #if HOTENDS >= 2
404 404
       case VP_T_E1_Set:
405
-        NOMORE(newvalue, HEATER_1_MAXTEMP);
405
+        NOMORE(newvalue, (uint16_t)HEATER_1_MAXTEMP);
406 406
         thermalManager.setTargetHotend(newvalue, 1);
407 407
         acceptedvalue = thermalManager.degTargetHotend(1);
408 408
         break;
409 409
     #endif
410 410
     #if HAS_HEATED_BED
411 411
       case VP_T_Bed_Set:
412
-        NOMORE(newvalue, BED_MAXTEMP);
412
+        NOMORE(newvalue, (uint16_t)BED_MAXTEMP);
413 413
         thermalManager.setTargetBed(newvalue);
414 414
         acceptedvalue = thermalManager.degTargetBed();
415 415
         break;

+ 2
- 2
Marlin/src/libs/autoreport.h 查看文件

@@ -28,8 +28,8 @@ struct AutoReporter {
28 28
   millis_t next_report_ms;
29 29
   uint8_t report_interval;
30 30
   #if HAS_MULTI_SERIAL
31
-    serial_index_t report_port_mask;
32
-    AutoReporter() : report_port_mask(SERIAL_ALL) {}
31
+    SerialMask report_port_mask;
32
+    AutoReporter() : report_port_mask(SerialMask::All) {}
33 33
   #endif
34 34
 
35 35
   inline void set_interval(uint8_t seconds, const uint8_t limit=60) {

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

@@ -329,7 +329,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
329 329
      */
330 330
     void Temperature::report_fan_speed(const uint8_t target) {
331 331
       if (target >= FAN_COUNT) return;
332
-      PORT_REDIRECT(SERIAL_ALL);
332
+      PORT_REDIRECT(SerialMask::All);
333 333
       SERIAL_ECHOLNPAIR("M106 P", target, " S", fan_speed[target]);
334 334
     }
335 335
   #endif

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

@@ -549,7 +549,7 @@ void openFailed(const char * const fname) {
549 549
 
550 550
 void announceOpen(const uint8_t doing, const char * const path) {
551 551
   if (doing) {
552
-    PORT_REDIRECT(SERIAL_ALL);
552
+    PORT_REDIRECT(SerialMask::All);
553 553
     SERIAL_ECHO_START();
554 554
     SERIAL_ECHOPGM("Now ");
555 555
     SERIAL_ECHOPGM_P(doing == 1 ? PSTR("doing") : PSTR("fresh"));
@@ -615,7 +615,7 @@ void CardReader::openFileRead(char * const path, const uint8_t subcall_type/*=0*
615 615
     sdpos = 0;
616 616
 
617 617
     { // Don't remove this block, as the PORT_REDIRECT is a RAII
618
-      PORT_REDIRECT(SERIAL_ALL);
618
+      PORT_REDIRECT(SerialMask::All);
619 619
       SERIAL_ECHOLNPAIR(STR_SD_FILE_OPENED, fname, STR_SD_SIZE, filesize);
620 620
       SERIAL_ECHOLNPGM(STR_SD_FILE_SELECTED);
621 621
     }

正在加载...
取消
保存