Browse Source

🐛 Fix some Simulator on Windows issues (#22516)

Jason Smith 2 years ago
parent
commit
331cc5fd6a
No account linked to committer's email address

+ 6
- 4
Marlin/src/HAL/NATIVE_SIM/pinsDebug.h View File

@@ -21,6 +21,8 @@
21 21
  * Support routines for X86_64
22 22
  */
23 23
 
24
+#pragma once
25
+
24 26
 /**
25 27
  * Translation of routines & variables used by pinsDebug.h
26 28
  */
@@ -37,16 +39,16 @@
37 39
 #define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
38 40
 
39 41
 // active ADC function/mode/code values for PINSEL registers
40
-constexpr int8_t ADC_pin_mode(pin_t pin) {
42
+inline constexpr int8_t ADC_pin_mode(pin_t pin) {
41 43
   return (-1);
42 44
 }
43 45
 
44
-int8_t get_pin_mode(pin_t pin) {
46
+inline int8_t get_pin_mode(pin_t pin) {
45 47
   if (!VALID_PIN(pin)) return -1;
46 48
   return 0;
47 49
 }
48 50
 
49
-bool GET_PINMODE(pin_t pin) {
51
+inline bool GET_PINMODE(pin_t pin) {
50 52
   int8_t pin_mode = get_pin_mode(pin);
51 53
   if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
52 54
     return false;
@@ -54,6 +56,6 @@ bool GET_PINMODE(pin_t pin) {
54 56
   return (Gpio::getMode(pin) != 0); //input/output state
55 57
 }
56 58
 
57
-bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
59
+inline bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
58 60
   return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
59 61
 }

+ 1
- 1
Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_st7920_sw_spi.cpp View File

@@ -59,7 +59,7 @@
59 59
 
60 60
 #if ENABLED(U8GLIB_ST7920)
61 61
 
62
-#include <U8glib.h>
62
+#include <U8glib-HAL.h>
63 63
 #include "../../shared/Delay.h"
64 64
 
65 65
 #undef SPI_SPEED

+ 2
- 2
Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_sw_spi.cpp View File

@@ -63,7 +63,7 @@
63 63
 #define SPI_SPEED 2  // About 2 MHz
64 64
 
65 65
 #include <Arduino.h>
66
-#include <U8glib.h>
66
+#include <U8glib-HAL.h>
67 67
 
68 68
 #ifdef __cplusplus
69 69
   extern "C" {
@@ -209,7 +209,7 @@ uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_pt
209 209
 #endif
210 210
 
211 211
 #elif !ANY(TFT_COLOR_UI, TFT_CLASSIC_UI, TFT_LVGL_UI, HAS_MARLINUI_HD44780) && HAS_MARLINUI_U8GLIB
212
-  #include <U8glib.h>
212
+  #include <U8glib-HAL.h>
213 213
   uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {return 0;}
214 214
 #endif // HAS_MARLINUI_U8GLIB && !U8GLIB_ST7920
215 215
 #endif // __PLAT_NATIVE_SIM__

+ 2
- 2
Marlin/src/HAL/shared/cpu_exception/exception_arm.cpp View File

@@ -322,7 +322,7 @@ void hook_cpu_exceptions() {
322 322
 
323 323
     unsigned long *vecAddr = (unsigned long*)get_vtor();
324 324
     SERIAL_ECHOPGM("Vector table addr: ");
325
-    SERIAL_PRINTLN(get_vtor(), HEX);
325
+    SERIAL_PRINTLN(get_vtor(), PrintBase::Hex);
326 326
 
327 327
     #ifdef VECTOR_TABLE_SIZE
328 328
       uint32_t vec_size = VECTOR_TABLE_SIZE;
@@ -349,7 +349,7 @@ void hook_cpu_exceptions() {
349 349
       alignas(128) static unsigned long vectable[VECTOR_TABLE_SENTINEL];
350 350
 
351 351
       SERIAL_ECHOPGM("Detected vector table size: ");
352
-      SERIAL_PRINTLN(vec_size, HEX);
352
+      SERIAL_PRINTLN(vec_size, PrintBase::Hex);
353 353
     #endif
354 354
 
355 355
     uint32_t defaultFaultHandler = vecAddr[(unsigned)7];

+ 0
- 11
Marlin/src/core/serial.cpp View File

@@ -76,17 +76,6 @@ void serialprintPGM(PGM_P str) {
76 76
 void serial_echo_start()  { static PGMSTR(echomagic, "echo:"); serialprintPGM(echomagic); }
77 77
 void serial_error_start() { static PGMSTR(errormagic, "Error:"); serialprintPGM(errormagic); }
78 78
 
79
-void serial_echopair_PGM(PGM_P const s_P, serial_char_t v) { serialprintPGM(s_P); SERIAL_CHAR(v.c); }
80
-void serial_echopair_PGM(PGM_P const s_P, const char *v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
81
-void serial_echopair_PGM(PGM_P const s_P, char v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
82
-void serial_echopair_PGM(PGM_P const s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
83
-void serial_echopair_PGM(PGM_P const s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
84
-void serial_echopair_PGM(PGM_P const s_P, float v)         { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
85
-void serial_echopair_PGM(PGM_P const s_P, double v)        { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
86
-void serial_echopair_PGM(PGM_P const s_P, unsigned char v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
87
-void serial_echopair_PGM(PGM_P const s_P, unsigned int v)  { serialprintPGM(s_P); SERIAL_ECHO(v); }
88
-void serial_echopair_PGM(PGM_P const s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
89
-
90 79
 void serial_spaces(uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR(' '); }
91 80
 
92 81
 void serial_ternary(const bool onoff, PGM_P const pre, PGM_P const on, PGM_P const off, PGM_P const post/*=nullptr*/) {

+ 12
- 15
Marlin/src/core/serial.h View File

@@ -177,8 +177,8 @@ void SERIAL_ECHOLN(T x) { SERIAL_IMPL.println(x); }
177 177
 template <typename T, typename U>
178 178
 void SERIAL_PRINT(T x, U y) { SERIAL_IMPL.print(x, y); }
179 179
 
180
-template <typename T, typename U>
181
-void SERIAL_PRINTLN(T x, U y) { SERIAL_IMPL.println(x, y); }
180
+template <typename T>
181
+void SERIAL_PRINTLN(T x, PrintBase y) { SERIAL_IMPL.println(x, y); }
182 182
 
183 183
 // Flush the serial port
184 184
 inline void SERIAL_FLUSH()    { SERIAL_IMPL.flush(); }
@@ -293,21 +293,18 @@ void serialprintPGM(PGM_P str);
293 293
 //
294 294
 // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
295 295
 //
296
-void serial_echopair_PGM(PGM_P const s_P, serial_char_t v);
297
-void serial_echopair_PGM(PGM_P const s_P, const char *v);
298
-void serial_echopair_PGM(PGM_P const s_P, char v);
299
-void serial_echopair_PGM(PGM_P const s_P, int v);
300
-void serial_echopair_PGM(PGM_P const s_P, long v);
301
-void serial_echopair_PGM(PGM_P const s_P, float v);
302
-void serial_echopair_PGM(PGM_P const s_P, double v);
303
-void serial_echopair_PGM(PGM_P const s_P, unsigned char v);
304
-void serial_echopair_PGM(PGM_P const s_P, unsigned int v);
305
-void serial_echopair_PGM(PGM_P const s_P, unsigned long v);
296
+inline void serial_echopair_PGM(PGM_P const s_P, serial_char_t v) { serialprintPGM(s_P); SERIAL_CHAR(v.c); }
297
+
298
+inline void serial_echopair_PGM(PGM_P const s_P, float v)         { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
299
+inline void serial_echopair_PGM(PGM_P const s_P, double v)        { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
300
+inline void serial_echopair_PGM(PGM_P const s_P, const char *v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
301
+
302
+// Default implementation for types without a specialization. Handles integers.
303
+template <typename T>
304
+void serial_echopair_PGM(PGM_P const s_P, T v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
305
+
306 306
 inline void serial_echopair_PGM(PGM_P const s_P, bool v)    { serial_echopair_PGM(s_P, (int)v); }
307 307
 inline void serial_echopair_PGM(PGM_P const s_P, void *v)   { serial_echopair_PGM(s_P, (uintptr_t)v); }
308
-#if __INTPTR_WIDTH__ != __SIZE_WIDTH__
309
-  inline void serial_echopair_PGM(PGM_P const s_P, size_t v)   { serial_echopair_PGM(s_P, (long int)v); }
310
-#endif
311 308
 
312 309
 void serial_echo_start();
313 310
 void serial_error_start();

+ 67
- 47
Marlin/src/core/serial_base.h View File

@@ -74,12 +74,12 @@ CALL_IF_EXISTS_IMPL(SerialFeature, features, SerialFeature::None);
74 74
 // for any type other than double/float. For double/float, a conversion exists so the call will be invisible.
75 75
 struct EnsureDouble {
76 76
   double a;
77
-  FORCE_INLINE operator double() { return a; }
77
+  operator double() { return a; }
78 78
   // If the compiler breaks on ambiguity here, it's likely because print(X, base) is called with X not a double/float, and
79 79
   // a base that's not a PrintBase value. This code is made to detect the error. You MUST set a base explicitly like this:
80 80
   // SERIAL_PRINT(v, PrintBase::Hex)
81
-  FORCE_INLINE EnsureDouble(double a) : a(a) {}
82
-  FORCE_INLINE EnsureDouble(float a) : a(a) {}
81
+  EnsureDouble(double a) : a(a) {}
82
+  EnsureDouble(float a) : a(a) {}
83 83
 };
84 84
 
85 85
 // Using Curiously-Recurring Template Pattern here to avoid virtual table cost when compiling.
@@ -136,70 +136,90 @@ struct SerialBase {
136 136
   void flushTX()                    { CALL_IF_EXISTS(void, SerialChild, flushTX); }
137 137
 
138 138
   // Glue code here
139
-  FORCE_INLINE void write(const char *str)                    { while (*str) write(*str++); }
140
-  FORCE_INLINE void write(const uint8_t *buffer, size_t size) { while (size--) write(*buffer++); }
141
-  FORCE_INLINE void print(const char *str)                    { write(str); }
139
+  void write(const char *str)                    { while (*str) write(*str++); }
140
+  void write(const uint8_t *buffer, size_t size) { while (size--) write(*buffer++); }
141
+  void print(char *str)                          { write(str); }
142
+  void print(const char *str)                    { write(str); }
142 143
   // No default argument to avoid ambiguity
143
-  NO_INLINE void print(char c, PrintBase base)                { printNumber((signed long)c, (uint8_t)base); }
144
-  NO_INLINE void print(unsigned char c, PrintBase base)       { printNumber((unsigned long)c, (uint8_t)base); }
145
-  NO_INLINE void print(int c, PrintBase base)                 { printNumber((signed long)c, (uint8_t)base); }
146
-  NO_INLINE void print(unsigned int c, PrintBase base)        { printNumber((unsigned long)c, (uint8_t)base); }
147
-  void print(unsigned long c, PrintBase base)                 { printNumber((unsigned long)c, (uint8_t)base); }
148
-  void print(long c, PrintBase base)                          { printNumber((signed long)c, (uint8_t)base); }
149
-  void print(EnsureDouble c, int digits)                      { printFloat(c, digits); }
144
+
145
+  // Define print for every fundamental integer type, to ensure that all redirect properly
146
+  // to the correct underlying implementation.
147
+
148
+  // Prints are performed with a single size, to avoid needing multiple print functions.
149
+  // The fixed integer size used for prints will be the larger of long or a pointer.
150
+  #if __LONG_WIDTH__ >= __INTPTR_WIDTH__
151
+    typedef long int_fixed_print_t;
152
+    typedef unsigned long uint_fixed_print_t;
153
+  #else
154
+    typedef intptr_t int_fixed_print_t;
155
+    typedef uintptr_t uint_fixed_print_t;
156
+
157
+    FORCE_INLINE void print(intptr_t c, PrintBase base)         { printNumber_signed(c, base); }
158
+    FORCE_INLINE void print(uintptr_t c, PrintBase base)        { printNumber_unsigned(c, base); }
159
+  #endif
160
+
161
+  FORCE_INLINE void print(char c, PrintBase base)               { printNumber_signed(c, base); }
162
+  FORCE_INLINE void print(short c, PrintBase base)              { printNumber_signed(c, base); }
163
+  FORCE_INLINE void print(int c, PrintBase base)                { printNumber_signed(c, base); }
164
+  FORCE_INLINE void print(long c, PrintBase base)               { printNumber_signed(c, base); }
165
+  FORCE_INLINE void print(unsigned char c, PrintBase base)      { printNumber_unsigned(c, base); }
166
+  FORCE_INLINE void print(unsigned short c, PrintBase base)     { printNumber_unsigned(c, base); }
167
+  FORCE_INLINE void print(unsigned int c, PrintBase base)       { printNumber_unsigned(c, base); }
168
+  FORCE_INLINE void print(unsigned long c, PrintBase base)      { printNumber_unsigned(c, base); }
169
+
170
+
171
+  void print(EnsureDouble c, int digits)           { printFloat(c, digits); }
150 172
 
151 173
   // Forward the call to the former's method
152
-  FORCE_INLINE void print(char c)                { print(c, PrintBase::Dec); }
153
-  FORCE_INLINE void print(unsigned char c)       { print(c, PrintBase::Dec); }
154
-  FORCE_INLINE void print(int c)                 { print(c, PrintBase::Dec); }
155
-  FORCE_INLINE void print(unsigned int c)        { print(c, PrintBase::Dec); }
156
-  FORCE_INLINE void print(unsigned long c)       { print(c, PrintBase::Dec); }
157
-  FORCE_INLINE void print(long c)                { print(c, PrintBase::Dec); }
158
-  FORCE_INLINE void print(double c)              { print(c, 2); }
159
-
160
-  FORCE_INLINE void println(const char s[])                  { print(s); println(); }
161
-  FORCE_INLINE void println(char c, PrintBase base)          { print(c, base); println(); }
162
-  FORCE_INLINE void println(unsigned char c, PrintBase base) { print(c, base); println(); }
163
-  FORCE_INLINE void println(int c, PrintBase base)           { print(c, base); println(); }
164
-  FORCE_INLINE void println(unsigned int c, PrintBase base)  { print(c, base); println(); }
165
-  FORCE_INLINE void println(long c, PrintBase base)          { print(c, base); println(); }
166
-  FORCE_INLINE void println(unsigned long c, PrintBase base) { print(c, base); println(); }
167
-  FORCE_INLINE void println(double c, int digits)            { print(c, digits); println(); }
168
-  FORCE_INLINE void println()                                { write('\r'); write('\n'); }
174
+
175
+  // Default implementation for anything without a specialization
176
+  // This handles integers since they are the most common
177
+  template <typename T>
178
+  void print(T c)    { print(c, PrintBase::Dec); }
179
+
180
+  void print(float c)    { print(c, 2); }
181
+  void print(double c)    { print(c, 2); }
182
+
183
+  void println(char *s)               { print(s); println(); }
184
+  void println(const char *s)         { print(s); println(); }
185
+  void println(float c, int digits)   { print(c, digits); println(); }
186
+  void println(double c, int digits)  { print(c, digits); println(); }
187
+  void println()                      { write('\r'); write('\n'); }
188
+
189
+  // Default implementations for types without a specialization. Handles integers.
190
+  template <typename T>
191
+  void println(T c, PrintBase base)   { print(c, base); println(); }
192
+
193
+  template <typename T>
194
+  void println(T c)                   { println(c, PrintBase::Dec); }
169 195
 
170 196
   // Forward the call to the former's method
171
-  FORCE_INLINE void println(char c)                { println(c, PrintBase::Dec); }
172
-  FORCE_INLINE void println(unsigned char c)       { println(c, PrintBase::Dec); }
173
-  FORCE_INLINE void println(int c)                 { println(c, PrintBase::Dec); }
174
-  FORCE_INLINE void println(unsigned int c)        { println(c, PrintBase::Dec); }
175
-  FORCE_INLINE void println(unsigned long c)       { println(c, PrintBase::Dec); }
176
-  FORCE_INLINE void println(long c)                { println(c, PrintBase::Dec); }
177
-  FORCE_INLINE void println(double c)              { println(c, 2); }
197
+  void println(float c)               { println(c, 2); }
198
+  void println(double c)              { println(c, 2); }
178 199
 
179 200
   // Print a number with the given base
180
-  NO_INLINE void printNumber(unsigned long n, const uint8_t base) {
181
-    if (!base) return; // Hopefully, this should raise visible bug immediately
182
-
201
+  NO_INLINE void printNumber_unsigned(uint_fixed_print_t n, PrintBase base) {
183 202
     if (n) {
184 203
       unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
185 204
       int8_t i = 0;
186 205
       while (n) {
187
-        buf[i++] = n % base;
188
-        n /= base;
206
+        buf[i++] = n % (uint_fixed_print_t)base;
207
+        n /= (uint_fixed_print_t)base;
189 208
       }
190 209
       while (i--) write((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10)));
191 210
     }
192 211
     else write('0');
193 212
   }
194
-  void printNumber(signed long n, const uint8_t base) {
195
-    if (base == 10 && n < 0) {
213
+
214
+  NO_INLINE void printNumber_signed(int_fixed_print_t n, PrintBase base) {
215
+    if (base == PrintBase::Dec && n < 0) {
196 216
       n = -n; // This works because all platforms Marlin's builds on are using 2-complement encoding for negative number
197 217
               // On such CPU, changing the sign of a number is done by inverting the bits and adding one, so if n = 0x80000000 = -2147483648 then
198 218
               // -n = 0x7FFFFFFF + 1 => 0x80000000 = 2147483648 (if interpreted as unsigned) or -2147483648 if interpreted as signed.
199 219
               // On non 2-complement CPU, there would be no possible representation for 2147483648.
200 220
       write('-');
201 221
     }
202
-    printNumber((unsigned long)n , base);
222
+    printNumber_unsigned((uint_fixed_print_t)n , base);
203 223
   }
204 224
 
205 225
   // Print a decimal number
@@ -218,7 +238,7 @@ struct SerialBase {
218 238
     // Extract the integer part of the number and print it
219 239
     unsigned long int_part = (unsigned long)number;
220 240
     double remainder = number - (double)int_part;
221
-    printNumber(int_part, 10);
241
+    printNumber_unsigned(int_part, PrintBase::Dec);
222 242
 
223 243
     // Print the decimal point, but only if there are digits beyond
224 244
     if (digits) {
@@ -227,7 +247,7 @@ struct SerialBase {
227 247
       while (digits--) {
228 248
         remainder *= 10.0;
229 249
         unsigned long toPrint = (unsigned long)remainder;
230
-        printNumber(toPrint, 10);
250
+        printNumber_unsigned(toPrint, PrintBase::Dec);
231 251
         remainder -= toPrint;
232 252
       }
233 253
     }

+ 1
- 1
Marlin/src/feature/tmc_util.cpp View File

@@ -208,7 +208,7 @@
208 208
   #if ENABLED(STOP_ON_ERROR)
209 209
     void report_driver_error(const TMC_driver_data &data) {
210 210
       SERIAL_ECHOPGM(" driver error detected: 0x");
211
-      SERIAL_PRINTLN(data.drv_status, HEX);
211
+      SERIAL_PRINTLN(data.drv_status, PrintBase::Hex);
212 212
       if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature");
213 213
       if (data.is_s2g) SERIAL_ECHOLNPGM("coil short circuit");
214 214
       TERN_(TMC_DEBUG, tmc_report_all());

+ 1
- 1
Marlin/src/feature/tmc_util.h View File

@@ -330,7 +330,7 @@ void tmc_print_current(TMC &st) {
330 330
   void tmc_print_sgt(TMC &st) {
331 331
     st.printLabel();
332 332
     SERIAL_ECHOPGM(" homing sensitivity: ");
333
-    SERIAL_PRINTLN(st.homing_threshold(), DEC);
333
+    SERIAL_PRINTLN(st.homing_threshold(), PrintBase::Dec);
334 334
   }
335 335
 #endif
336 336
 

+ 2
- 2
ini/native.ini View File

@@ -120,11 +120,11 @@ build_unflags   = ${simulator_macos.build_unflags}
120 120
 # Simulator for Windows 10
121 121
 #
122 122
 #  MSYS2 mingw-w64-x86_64 with these packages:
123
-#  pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-glm mingw64/mingw-w64-x86_64-SDL2 mingw64/mingw-w64-x86_64-SDL2_net
123
+#  pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-glm mingw64/mingw-w64-x86_64-SDL2 mingw64/mingw-w64-x86_64-SDL2_net mingw-w64-x86_64-dlfcn
124 124
 #
125 125
 [env:simulator_windows]
126 126
 platform    = ${simulator_common.platform}
127 127
 extends     = simulator_common
128 128
 src_build_flags = ${simulator_common.src_build_flags} -fpermissive
129
-build_flags = ${simulator_common.build_flags} ${simulator_common.debug_build_flags} -fno-stack-protector -Wl,-subsystem,windows -ldl -lmingw32 -lSDL2main -lSDL2 -lSDL2_net -lopengl32 -lssp
129
+build_flags = ${simulator_common.build_flags} ${simulator_common.debug_build_flags} -IC:\\msys64\\mingw64\\include\\SDL2 -fno-stack-protector -Wl,-subsystem,windows -ldl -lmingw32 -lSDL2main -lSDL2 -lSDL2_net -lopengl32 -lssp
130 130
 build_type = debug

Loading…
Cancel
Save