Browse Source

MMU2 as standard serial device (#20771)

Giuliano Zaro 3 years ago
parent
commit
1d5862a39b
No account linked to committer's email address

+ 0
- 3
Marlin/Configuration_adv.h View File

3601
   //#define E_MUX2_PIN 44  // Needed for 5 to 8 inputs
3601
   //#define E_MUX2_PIN 44  // Needed for 5 to 8 inputs
3602
 #elif HAS_PRUSA_MMU2
3602
 #elif HAS_PRUSA_MMU2
3603
   // Serial port used for communication with MMU2.
3603
   // Serial port used for communication with MMU2.
3604
-  // For AVR enable the UART port used for the MMU. (e.g., mmuSerial)
3605
-  // For 32-bit boards check your HAL for available serial ports. (e.g., Serial2)
3606
   #define MMU2_SERIAL_PORT 2
3604
   #define MMU2_SERIAL_PORT 2
3607
-  #define MMU2_SERIAL mmuSerial
3608
 
3605
 
3609
   // Use hardware reset for MMU if a pin is defined for it
3606
   // Use hardware reset for MMU if a pin is defined for it
3610
   //#define MMU2_RST_PIN 23
3607
   //#define MMU2_RST_PIN 23

+ 7
- 0
Marlin/src/HAL/AVR/HAL.h View File

97
   #endif
97
   #endif
98
 #endif
98
 #endif
99
 
99
 
100
+#ifdef MMU2_SERIAL_PORT
101
+  #if !WITHIN(MMU2_SERIAL_PORT, -1, 3)
102
+    #error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
103
+  #endif
104
+  #define MMU2_SERIAL mmuSerial
105
+#endif
106
+
100
 #ifdef LCD_SERIAL_PORT
107
 #ifdef LCD_SERIAL_PORT
101
   #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
108
   #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
102
     #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
109
     #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."

+ 8
- 0
Marlin/src/HAL/DUE/HAL.h View File

59
   #endif
59
   #endif
60
 #endif
60
 #endif
61
 
61
 
62
+#ifdef MMU2_SERIAL_PORT
63
+  #if WITHIN(MMU2_SERIAL_PORT, 0, 3)
64
+    #define MMU2_SERIAL MSERIAL(SERIAL_PORT)
65
+  #else
66
+    #error "MMU2_SERIAL_PORT must be from 0 to 3. Please update your configuration."
67
+  #endif
68
+#endif
69
+
62
 #ifdef LCD_SERIAL_PORT
70
 #ifdef LCD_SERIAL_PORT
63
   #if LCD_SERIAL_PORT == -1
71
   #if LCD_SERIAL_PORT == -1
64
     #define LCD_SERIAL lcdSerial
72
     #define LCD_SERIAL lcdSerial

+ 10
- 0
Marlin/src/HAL/LPC1768/HAL.h View File

82
   #endif
82
   #endif
83
 #endif
83
 #endif
84
 
84
 
85
+#ifdef MMU2_SERIAL_PORT
86
+  #if MMU2_SERIAL_PORT == -1
87
+    #define MMU2_SERIAL UsbSerial
88
+  #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
89
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
90
+  #else
91
+    #error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
92
+  #endif
93
+#endif
94
+
85
 #ifdef LCD_SERIAL_PORT
95
 #ifdef LCD_SERIAL_PORT
86
   #if LCD_SERIAL_PORT == -1
96
   #if LCD_SERIAL_PORT == -1
87
     #define LCD_SERIAL UsbSerial
97
     #define LCD_SERIAL UsbSerial

+ 10
- 0
Marlin/src/HAL/SAMD51/HAL.h View File

57
     #endif
57
     #endif
58
   #endif
58
   #endif
59
 
59
 
60
+  #ifdef MMU2_SERIAL_PORT
61
+    #if MMU2_SERIAL_PORT == -1
62
+      #define MMU2_SERIAL Serial
63
+    #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
64
+      #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
65
+    #else
66
+      #error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
67
+    #endif
68
+  #endif
69
+
60
   #ifdef LCD_SERIAL_PORT
70
   #ifdef LCD_SERIAL_PORT
61
     #if LCD_SERIAL_PORT == -1
71
     #if LCD_SERIAL_PORT == -1
62
       #define LCD_SERIAL Serial
72
       #define LCD_SERIAL Serial

+ 4
- 4
Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp View File

21
 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
21
 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
22
 
22
 
23
 /**
23
 /**
24
- * Framework doesn't define some serial to save sercom resources
24
+ * Framework doesn't define some serials to save sercom resources
25
  * hence if these are used I need to define them
25
  * hence if these are used I need to define them
26
  */
26
  */
27
 
27
 
28
 #include "../../inc/MarlinConfig.h"
28
 #include "../../inc/MarlinConfig.h"
29
 
29
 
30
-#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1
30
+#if USING_SERIAL_1
31
   Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
31
   Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
32
   void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
32
   void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
33
   void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
33
   void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
35
   void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
35
   void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
36
 #endif
36
 #endif
37
 
37
 
38
-#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2
38
+#if USING_SERIAL_2
39
   Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
39
   Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
40
   void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
40
   void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
41
   void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
41
   void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
43
   void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
43
   void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
44
 #endif
44
 #endif
45
 
45
 
46
-#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3
46
+#if USING_SERIAL_3
47
   Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
47
   Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
48
   void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
48
   void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
49
   void SERCOM5_1_Handler() { Serial4.IrqHandler(); }
49
   void SERCOM5_1_Handler() { Serial4.IrqHandler(); }

+ 10
- 0
Marlin/src/HAL/STM32/HAL.h View File

65
   #endif
65
   #endif
66
 #endif
66
 #endif
67
 
67
 
68
+#ifdef MMU2_SERIAL_PORT
69
+  #if MMU2_SERIAL_PORT == -1
70
+    #define MMU2_SERIAL SerialUSB
71
+  #elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
72
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
73
+  #else
74
+    #error "MMU2_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
75
+  #endif
76
+#endif
77
+
68
 #ifdef LCD_SERIAL_PORT
78
 #ifdef LCD_SERIAL_PORT
69
   #if LCD_SERIAL_PORT == -1
79
   #if LCD_SERIAL_PORT == -1
70
     #define LCD_SERIAL SerialUSB
80
     #define LCD_SERIAL SerialUSB

+ 4
- 0
Marlin/src/HAL/STM32/MarlinSerial.cpp View File

48
   DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
48
   DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
49
 #endif
49
 #endif
50
 
50
 
51
+#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0
52
+  DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT)
53
+#endif
54
+
51
 #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
55
 #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
52
   DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
56
   DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
53
 #endif
57
 #endif

+ 12
- 0
Marlin/src/HAL/STM32F1/HAL.h View File

99
   #endif
99
   #endif
100
 #endif
100
 #endif
101
 
101
 
102
+#ifdef MMU2_SERIAL_PORT
103
+  #if MMU2_SERIAL_PORT == -1
104
+    #define MMU2_SERIAL UsbSerial
105
+  #elif WITHIN(MMU2_SERIAL_PORT, 1, NUM_UARTS)
106
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
107
+  #elif NUM_UARTS == 5
108
+    #error "MMU2_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
109
+  #else
110
+    #error "MMU2_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
111
+  #endif
112
+#endif
113
+
102
 #ifdef LCD_SERIAL_PORT
114
 #ifdef LCD_SERIAL_PORT
103
   #if LCD_SERIAL_PORT == -1
115
   #if LCD_SERIAL_PORT == -1
104
     #define LCD_SERIAL UsbSerial
116
     #define LCD_SERIAL UsbSerial

+ 7
- 9
Marlin/src/feature/mmu/mmu2.cpp View File

91
 #define MMU2_NO_TOOL 99
91
 #define MMU2_NO_TOOL 99
92
 #define MMU_BAUD    115200
92
 #define MMU_BAUD    115200
93
 
93
 
94
-#define mmuSerial   MMU2_SERIAL
95
-
96
 bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
94
 bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
97
 #if HAS_PRUSA_MMU2S
95
 #if HAS_PRUSA_MMU2S
98
   bool MMU2::mmu2s_triggered;
96
   bool MMU2::mmu2s_triggered;
132
     SET_OUTPUT(MMU2_RST_PIN);
130
     SET_OUTPUT(MMU2_RST_PIN);
133
   #endif
131
   #endif
134
 
132
 
135
-  mmuSerial.begin(MMU_BAUD);
133
+  MMU2_SERIAL.begin(MMU_BAUD);
136
   extruder = MMU2_NO_TOOL;
134
   extruder = MMU2_NO_TOOL;
137
 
135
 
138
   safe_delay(10);
136
   safe_delay(10);
385
 bool MMU2::rx_str_P(const char* str) {
383
 bool MMU2::rx_str_P(const char* str) {
386
   uint8_t i = strlen(rx_buffer);
384
   uint8_t i = strlen(rx_buffer);
387
 
385
 
388
-  while (mmuSerial.available()) {
389
-    rx_buffer[i++] = mmuSerial.read();
386
+  while (MMU2_SERIAL.available()) {
387
+    rx_buffer[i++] = MMU2_SERIAL.read();
390
     rx_buffer[i] = '\0';
388
     rx_buffer[i] = '\0';
391
 
389
 
392
     if (i == sizeof(rx_buffer) - 1) {
390
     if (i == sizeof(rx_buffer) - 1) {
417
 void MMU2::tx_str_P(const char* str) {
415
 void MMU2::tx_str_P(const char* str) {
418
   clear_rx_buffer();
416
   clear_rx_buffer();
419
   uint8_t len = strlen_P(str);
417
   uint8_t len = strlen_P(str);
420
-  LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
418
+  LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
421
   rx_buffer[0] = '\0';
419
   rx_buffer[0] = '\0';
422
   prev_request = millis();
420
   prev_request = millis();
423
 }
421
 }
428
 void MMU2::tx_printf_P(const char* format, int argument = -1) {
426
 void MMU2::tx_printf_P(const char* format, int argument = -1) {
429
   clear_rx_buffer();
427
   clear_rx_buffer();
430
   uint8_t len = sprintf_P(tx_buffer, format, argument);
428
   uint8_t len = sprintf_P(tx_buffer, format, argument);
431
-  LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
429
+  LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
432
   rx_buffer[0] = '\0';
430
   rx_buffer[0] = '\0';
433
   prev_request = millis();
431
   prev_request = millis();
434
 }
432
 }
439
 void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
437
 void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
440
   clear_rx_buffer();
438
   clear_rx_buffer();
441
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
439
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
442
-  LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
440
+  LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
443
   rx_buffer[0] = '\0';
441
   rx_buffer[0] = '\0';
444
   prev_request = millis();
442
   prev_request = millis();
445
 }
443
 }
448
  * Empty the rx buffer
446
  * Empty the rx buffer
449
  */
447
  */
450
 void MMU2::clear_rx_buffer() {
448
 void MMU2::clear_rx_buffer() {
451
-  while (mmuSerial.available()) mmuSerial.read();
449
+  while (MMU2_SERIAL.available()) MMU2_SERIAL.read();
452
   rx_buffer[0] = '\0';
450
   rx_buffer[0] = '\0';
453
 }
451
 }
454
 
452
 

+ 4
- 1
Marlin/src/inc/Conditionals_adv.h View File

512
 #endif
512
 #endif
513
 
513
 
514
 // Flag the indexed serial ports that are in use
514
 // Flag the indexed serial ports that are in use
515
-#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
515
+#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || \
516
+                         (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || \
517
+                         (defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == (N)) || \
518
+                         (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
516
 #if ANY_SERIAL_IS(-1)
519
 #if ANY_SERIAL_IS(-1)
517
   #define USING_SERIAL_DEFAULT
520
   #define USING_SERIAL_DEFAULT
518
 #endif
521
 #endif

+ 15
- 4
Marlin/src/inc/SanityCheck.h View File

588
   #error "SERIAL_PORT must be defined."
588
   #error "SERIAL_PORT must be defined."
589
 #elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT
589
 #elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT
590
   #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT."
590
   #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT."
591
-#elif defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == SERIAL_PORT
592
-  #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT."
593
-#elif defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == SERIAL_PORT_2
594
-  #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2."
595
 #endif
591
 #endif
596
 #if !(defined(__AVR__) && defined(USBCON))
592
 #if !(defined(__AVR__) && defined(USBCON))
597
   #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
593
   #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
2389
     #error "SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set SERIAL_PORT to a valid value for your board."
2385
     #error "SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set SERIAL_PORT to a valid value for your board."
2390
   #elif SERIAL_PORT_2 == -1
2386
   #elif SERIAL_PORT_2 == -1
2391
     #error "SERIAL_PORT_2 is set to -1, but the MOTHERBOARD has no native USB support. Set SERIAL_PORT_2 to a valid value for your board."
2387
     #error "SERIAL_PORT_2 is set to -1, but the MOTHERBOARD has no native USB support. Set SERIAL_PORT_2 to a valid value for your board."
2388
+  #elif MMU2_SERIAL_PORT == -1
2389
+    #error "MMU2_SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set MMU2_SERIAL_PORT to a valid value for your board."
2392
   #elif LCD_SERIAL_PORT == -1
2390
   #elif LCD_SERIAL_PORT == -1
2393
     #error "LCD_SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set LCD_SERIAL_PORT to a valid value for your board."
2391
     #error "LCD_SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set LCD_SERIAL_PORT to a valid value for your board."
2394
   #endif
2392
   #endif
2395
 #endif
2393
 #endif
2396
 
2394
 
2397
 /**
2395
 /**
2396
+ * MMU2 require a dedicated serial port
2397
+ */
2398
+#ifdef MMU2_SERIAL_PORT
2399
+  #if MMU2_SERIAL_PORT == SERIAL_PORT
2400
+    #error "MMU2_SERIAL_PORT cannot be the same as SERIAL_PORT."
2401
+  #elif defined(SERIAL_PORT_2) && MMU2_SERIAL_PORT == SERIAL_PORT_2
2402
+    #error "MMU2_SERIAL_PORT cannot be the same as SERIAL_PORT_2."
2403
+  #elif defined(LCD_SERIAL_PORT) && MMU2_SERIAL_PORT == LCD_SERIAL_PORT
2404
+    #error "MMU2_SERIAL_PORT cannot be the same as LCD_SERIAL_PORT."
2405
+  #endif
2406
+#endif
2407
+
2408
+/**
2398
  * Serial displays require a dedicated serial port
2409
  * Serial displays require a dedicated serial port
2399
  */
2410
  */
2400
 #ifdef LCD_SERIAL_PORT
2411
 #ifdef LCD_SERIAL_PORT

Loading…
Cancel
Save