Define HW serial ports needed for TMC UART (#21446)

This commit is contained in:
Scott Lahteine 2021-03-25 16:19:03 -05:00 committed by GitHub
parent 8bf6b190ff
commit 84b961cb20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 37 deletions

View file

@ -106,16 +106,16 @@ uint16_t HAL_adc_get_result() {
} }
// Forward the default serial ports // Forward the default serial ports
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
DefaultSerial1 MSerial0(false, Serial); DefaultSerial1 MSerial0(false, Serial);
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
DefaultSerial2 MSerial1(false, Serial1); DefaultSerial2 MSerial1(false, Serial1);
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
DefaultSerial3 MSerial2(false, Serial2); DefaultSerial3 MSerial2(false, Serial2);
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
DefaultSerial4 MSerial3(false, Serial3); DefaultSerial4 MSerial3(false, Serial3);
#endif #endif

View file

@ -140,7 +140,7 @@ struct MarlinSerialCfg {
static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED); static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED);
}; };
#if SERIAL_PORT >= 0 #if defined(SERIAL_PORT) && SERIAL_PORT >= 0
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT; typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
extern MSerialT customizedSerial1; extern MSerialT customizedSerial1;
#endif #endif

View file

@ -21,25 +21,26 @@
*/ */
#ifdef TARGET_LPC1768 #ifdef TARGET_LPC1768
#include "../../inc/MarlinConfigPre.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
#if ANY_SERIAL_IS(0) #include "../../inc/MarlinConfig.h"
#if USING_HW_SERIAL0
MarlinSerial _MSerial(LPC_UART0); MarlinSerial _MSerial(LPC_UART0);
MSerialT MSerial0(true, _MSerial); MSerialT MSerial0(true, _MSerial);
extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); } extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); }
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
MarlinSerial _MSerial1((LPC_UART_TypeDef *) LPC_UART1); MarlinSerial _MSerial1((LPC_UART_TypeDef *) LPC_UART1);
MSerialT MSerial1(true, _MSerial1); MSerialT MSerial1(true, _MSerial1);
extern "C" void UART1_IRQHandler() { _MSerial1.IRQHandler(); } extern "C" void UART1_IRQHandler() { _MSerial1.IRQHandler(); }
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
MarlinSerial _MSerial2(LPC_UART2); MarlinSerial _MSerial2(LPC_UART2);
MSerialT MSerial2(true, _MSerial2); MSerialT MSerial2(true, _MSerial2);
extern "C" void UART2_IRQHandler() { _MSerial2.IRQHandler(); } extern "C" void UART2_IRQHandler() { _MSerial2.IRQHandler(); }
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
MarlinSerial _MSerial3(LPC_UART3); MarlinSerial _MSerial3(LPC_UART3);
MSerialT MSerial3(true, _MSerial3); MSerialT MSerial3(true, _MSerial3);
extern "C" void UART3_IRQHandler() { _MSerial3.IRQHandler(); } extern "C" void UART3_IRQHandler() { _MSerial3.IRQHandler(); }
@ -50,16 +51,16 @@
bool MarlinSerial::recv_callback(const char c) { bool MarlinSerial::recv_callback(const char c) {
// Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro) // Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro)
if (false) {} if (false) {}
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
else if (this == &_MSerial) emergency_parser.update(MSerial0.emergency_state, c); else if (this == &_MSerial) emergency_parser.update(MSerial0.emergency_state, c);
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c); else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c);
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
else if (this == &_MSerial2) emergency_parser.update(MSerial2.emergency_state, c); else if (this == &_MSerial2) emergency_parser.update(MSerial2.emergency_state, c);
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
else if (this == &_MSerial3) emergency_parser.update(MSerial3.emergency_state, c); else if (this == &_MSerial3) emergency_parser.update(MSerial3.emergency_state, c);
#endif #endif
return true; return true;

View file

@ -92,7 +92,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#define ANY_TX(N,V...) DO(IS_TX##N,||,V) #define ANY_TX(N,V...) DO(IS_TX##N,||,V)
#define ANY_RX(N,V...) DO(IS_RX##N,||,V) #define ANY_RX(N,V...) DO(IS_RX##N,||,V)
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
#define IS_TX0(P) (P == P0_02) #define IS_TX0(P) (P == P0_02)
#define IS_RX0(P) (P == P0_03) #define IS_RX0(P) (P == P0_03)
#if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI) #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
@ -106,7 +106,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef IS_RX0 #undef IS_RX0
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
#define IS_TX1(P) (P == P0_15) #define IS_TX1(P) (P == P0_15)
#define IS_RX1(P) (P == P0_16) #define IS_RX1(P) (P == P0_16)
#define _IS_TX1_1 IS_TX1 #define _IS_TX1_1 IS_TX1
@ -127,7 +127,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef _IS_RX1_1 #undef _IS_RX1_1
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
#define IS_TX2(P) (P == P0_10) #define IS_TX2(P) (P == P0_10)
#define IS_RX2(P) (P == P0_11) #define IS_RX2(P) (P == P0_11)
#define _IS_TX2_1 IS_TX2 #define _IS_TX2_1 IS_TX2
@ -161,7 +161,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef _IS_RX2_1 #undef _IS_RX2_1
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
#define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00) #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
#define PIN_IS_RX3(P) (P##_PIN == P0_01) #define PIN_IS_RX3(P) (P##_PIN == P0_01)
#if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)

View file

@ -25,19 +25,19 @@
#include <wiring_private.h> #include <wiring_private.h>
#ifdef ADAFRUIT_GRAND_CENTRAL_M4 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
#if ANY_SERIAL_IS(-1) #if USING_HW_SERIALUSB
DefaultSerial1 MSerial0(false, Serial); DefaultSerial1 MSerial0(false, Serial);
#endif #endif
#if ANY_SERIAL_IS(0) #if USING_HW_SERIAL0
DefaultSerial2 MSerial1(false, Serial1); DefaultSerial2 MSerial1(false, Serial1);
#endif #endif
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
DefaultSerial3 MSerial2(false, Serial2); DefaultSerial3 MSerial2(false, Serial2);
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
DefaultSerial4 MSerial3(false, Serial3); DefaultSerial4 MSerial3(false, Serial3);
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
DefaultSerial5 MSerial4(false, Serial4); DefaultSerial5 MSerial4(false, Serial4);
#endif #endif
#endif #endif

View file

@ -27,7 +27,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ANY_SERIAL_IS(1) #if USING_HW_SERIAL1
UartT Serial2(false, &sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX); UartT Serial2(false, &sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
void SERCOM4_0_Handler() { Serial2.IrqHandler(); } void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
void SERCOM4_1_Handler() { Serial2.IrqHandler(); } void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
@ -35,7 +35,7 @@
void SERCOM4_3_Handler() { Serial2.IrqHandler(); } void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
#endif #endif
#if ANY_SERIAL_IS(2) #if USING_HW_SERIAL2
UartT Serial3(false, &sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX); UartT Serial3(false, &sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
void SERCOM1_0_Handler() { Serial3.IrqHandler(); } void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
void SERCOM1_1_Handler() { Serial3.IrqHandler(); } void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
@ -43,7 +43,7 @@
void SERCOM1_3_Handler() { Serial3.IrqHandler(); } void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
#endif #endif
#if ANY_SERIAL_IS(3) #if USING_HW_SERIAL3
UartT Serial4(false, &sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX); UartT Serial4(false, &sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
void SERCOM5_0_Handler() { Serial4.IrqHandler(); } void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
void SERCOM5_1_Handler() { Serial4.IrqHandler(); } void SERCOM5_1_Handler() { Serial4.IrqHandler(); }

View file

@ -28,7 +28,6 @@
#ifndef USART4 #ifndef USART4
#define USART4 UART4 #define USART4 UART4
#endif #endif
#ifndef USART5 #ifndef USART5
#define USART5 UART5 #define USART5 UART5
#endif #endif
@ -43,15 +42,12 @@
#if defined(SERIAL_PORT) && SERIAL_PORT >= 0 #if defined(SERIAL_PORT) && SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT) DECLARE_SERIAL_PORT_EXP(SERIAL_PORT)
#endif #endif
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 #if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
#endif #endif
#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0 #if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT) DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT)
#endif #endif
#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0 #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT) DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
#endif #endif

View file

@ -530,12 +530,6 @@
#define NEED_LSF 1 #define NEED_LSF 1
#endif #endif
// Flag the indexed serial ports that are in use
#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || \
(defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || \
(defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == (N)) || \
(defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
#if BOTH(HAS_TFT_LVGL_UI, CUSTOM_MENU_MAIN) #if BOTH(HAS_TFT_LVGL_UI, CUSTOM_MENU_MAIN)
#define _HAS_1(N) (defined(USER_DESC_##N) && defined(USER_GCODE_##N)) #define _HAS_1(N) (defined(USER_DESC_##N) && defined(USER_GCODE_##N))
#define HAS_USER_ITEM(V...) DO(HAS,||,V) #define HAS_USER_ITEM(V...) DO(HAS,||,V)

View file

@ -1838,6 +1838,112 @@
#define HAS_TMC_SW_SERIAL 1 #define HAS_TMC_SW_SERIAL 1
#endif #endif
//
// Set USING_HW_SERIALn flags for used Serial Ports
//
// ... HW_SerialX
#define _SERIAL_ID(P) _CAT(HW_,P)
// ... (HW_Serial1 == HW_SerialX || HW_Serial1 == HW_MSerialX)
#define _TMC_UART_IS(P,N) ( _SERIAL_ID(P##_HARDWARE_SERIAL) == _SERIAL_ID(Serial##N) || _SERIAL_ID(P) == _SERIAL_ID(MSerial##N) )
#define TMC_UART_IS(A,N) (defined(A##_HARDWARE_SERIAL) && _TMC_UART_IS(A, N))
// Flag the indexed hardware serial ports in use
#define CONF_SERIAL_IS(N) ( (defined(SERIAL_PORT) && SERIAL_PORT == N) \
|| (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == N) \
|| (defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == N) \
|| (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == N) )
// Flag the named hardware serial ports in use
#define ANY_SERIAL_IS(N) ( CONF_SERIAL_IS(N) \
|| TMC_UART_IS(X, N) || TMC_UART_IS(Y , N) || TMC_UART_IS(Z , N) \
|| TMC_UART_IS(X2, N) || TMC_UART_IS(Y2, N) || TMC_UART_IS(Z2, N) || TMC_UART_IS(Z3, N) || TMC_UART_IS(Z4, N) \
|| TMC_UART_IS(E0, N) || TMC_UART_IS(E1, N) || TMC_UART_IS(E2, N) || TMC_UART_IS(E3, N) || TMC_UART_IS(E4, N) )
#define HW_Serial 501
#define HW_Serial0 502
#define HW_Serial1 503
#define HW_Serial2 504
#define HW_Serial3 505
#define HW_Serial4 506
#define HW_Serial5 507
#define HW_Serial6 508
#define HW_MSerial0 509
#define HW_MSerial1 510
#define HW_MSerial2 511
#define HW_MSerial3 512
#define HW_MSerial4 513
#define HW_MSerial5 514
#define HW_MSerial6 515
#define HW_MSerial7 516
#define HW_MSerial8 517
#define HW_MSerial9 518
#define HW_MSerial10 519
#if CONF_SERIAL_IS(-1)
#define USING_HW_SERIALUSB 1
#endif
#if ANY_SERIAL_IS(0)
#define USING_HW_SERIAL0 1
#endif
#if ANY_SERIAL_IS(1)
#define USING_HW_SERIAL1 1
#endif
#if ANY_SERIAL_IS(2)
#define USING_HW_SERIAL2 1
#endif
#if ANY_SERIAL_IS(3)
#define USING_HW_SERIAL3 1
#endif
#if ANY_SERIAL_IS(4)
#define USING_HW_SERIAL4 1
#endif
#if ANY_SERIAL_IS(5)
#define USING_HW_SERIAL5 1
#endif
#if ANY_SERIAL_IS(6)
#define USING_HW_SERIAL6 1
#endif
#if ANY_SERIAL_IS(7)
#define USING_HW_SERIAL7 1
#endif
#if ANY_SERIAL_IS(8)
#define USING_HW_SERIAL8 1
#endif
#if ANY_SERIAL_IS(9)
#define USING_HW_SERIAL9 1
#endif
#if ANY_SERIAL_IS(10)
#define USING_HW_SERIAL10 1
#endif
#undef HW_Serial
#undef HW_Serial0
#undef HW_Serial1
#undef HW_Serial2
#undef HW_Serial3
#undef HW_Serial4
#undef HW_Serial5
#undef HW_Serial6
#undef HW_MSerial0
#undef HW_MSerial1
#undef HW_MSerial2
#undef HW_MSerial3
#undef HW_MSerial4
#undef HW_MSerial5
#undef HW_MSerial6
#undef HW_MSerial7
#undef HW_MSerial8
#undef HW_MSerial9
#undef HW_MSerial10
#undef _SERIAL_ID
#undef _TMC_UART_IS
#undef TMC_UART_IS
#undef CONF_SERIAL_IS
#undef ANY_SERIAL_IS
// //
// Endstops and bed probe // Endstops and bed probe
// //

View file

@ -1,6 +1,6 @@
/** /**
* Marlin 3D Printer Firmware * Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* *
* Based on Sprinter and grbl. * Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm