Skip to content

Commit

Permalink
🔧 Auto-assign UART Rx based on Tx
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 27, 2024
1 parent 28c506d commit 85c8e2a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 109 deletions.
12 changes: 0 additions & 12 deletions Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,18 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN P0_01
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif

#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN P0_00
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif

#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN P2_13
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif

#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN P2_08
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif

// Reduce baud rate to improve software serial reliability
#ifndef TMC_BAUD_RATE
Expand Down
142 changes: 99 additions & 43 deletions Marlin/src/pins/pins_postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,74 +307,130 @@
#define E7_CS_PIN -1
#endif

#if HAS_TMC_UART
#if !defined(X_SERIAL_TX_PIN) && PIN_EXISTS(X_SERIAL_RX)
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif
#if !defined(X2_SERIAL_TX_PIN) && PIN_EXISTS(X2_SERIAL_RX)
#define X2_SERIAL_RX_PIN X2_SERIAL_TX_PIN
#endif
#if !defined(Y_SERIAL_TX_PIN) && PIN_EXISTS(Y_SERIAL_RX)
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif
#if !defined(Y2_SERIAL_TX_PIN) && PIN_EXISTS(Y2_SERIAL_RX)
#define Y2_SERIAL_RX_PIN Y2_SERIAL_TX_PIN
#endif
#if !defined(Z_SERIAL_TX_PIN) && PIN_EXISTS(Z_SERIAL_RX)
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#if !defined(Z2_SERIAL_TX_PIN) && PIN_EXISTS(Z2_SERIAL_RX)
#define Z2_SERIAL_RX_PIN Z2_SERIAL_TX_PIN
#endif
#if !defined(Z3_SERIAL_TX_PIN) && PIN_EXISTS(Z3_SERIAL_RX)
#define Z3_SERIAL_RX_PIN Z3_SERIAL_TX_PIN
#endif
#if !defined(Z4_SERIAL_TX_PIN) && PIN_EXISTS(Z4_SERIAL_RX)
#define Z4_SERIAL_RX_PIN Z4_SERIAL_TX_PIN
#endif
#if !defined(EX_SERIAL_TX_PIN) && PIN_EXISTS(EX_SERIAL_RX)
#define EX_SERIAL_RX_PIN EX_SERIAL_TX_PIN
#endif
#if !defined(E0_SERIAL_TX_PIN) && PIN_EXISTS(E0_SERIAL_RX)
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif
#if !defined(E1_SERIAL_TX_PIN) && PIN_EXISTS(E1_SERIAL_RX)
#define E1_SERIAL_RX_PIN E1_SERIAL_TX_PIN
#endif
#if !defined(E2_SERIAL_TX_PIN) && PIN_EXISTS(E2_SERIAL_RX)
#define E2_SERIAL_RX_PIN E2_SERIAL_TX_PIN
#endif
#if !defined(E3_SERIAL_TX_PIN) && PIN_EXISTS(E3_SERIAL_RX)
#define E3_SERIAL_RX_PIN E3_SERIAL_TX_PIN
#endif
#if !defined(E4_SERIAL_TX_PIN) && PIN_EXISTS(E4_SERIAL_RX)
#define E4_SERIAL_RX_PIN E4_SERIAL_TX_PIN
#endif
#if !defined(E5_SERIAL_TX_PIN) && PIN_EXISTS(E5_SERIAL_RX)
#define E5_SERIAL_RX_PIN E5_SERIAL_TX_PIN
#endif
#if !defined(E6_SERIAL_TX_PIN) && PIN_EXISTS(E6_SERIAL_RX)
#define E6_SERIAL_RX_PIN E6_SERIAL_TX_PIN
#endif
#if !defined(E7_SERIAL_TX_PIN) && PIN_EXISTS(E7_SERIAL_RX)
#define E7_SERIAL_RX_PIN E7_SERIAL_TX_PIN
#endif
#endif

//
// Destroy stepper driver RX and TX pins when set to -1
// Some RX depend on TX, so RX needs to be un-defined before TX
// or it breaks "PIN_EXISTS(NAMED_THING)".
//
#if !PIN_EXISTS(Z2_SERIAL_TX)
#undef Z2_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Z2_SERIAL_RX)
#undef Z2_SERIAL_RX_PIN
#if !PIN_EXISTS(W_SERIAL_RX)
#undef W_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Z3_SERIAL_TX)
#undef Z3_SERIAL_TX_PIN
#if !PIN_EXISTS(W_SERIAL_TX)
#undef W_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Z3_SERIAL_RX)
#undef Z3_SERIAL_RX_PIN
#if !PIN_EXISTS(V_SERIAL_RX)
#undef V_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Z4_SERIAL_TX)
#undef Z4_SERIAL_TX_PIN
#if !PIN_EXISTS(V_SERIAL_TX)
#undef V_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Z4_SERIAL_RX)
#undef Z4_SERIAL_RX_PIN
#if !PIN_EXISTS(U_SERIAL_RX)
#undef U_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(X2_SERIAL_TX)
#undef X2_SERIAL_TX_PIN
#if !PIN_EXISTS(U_SERIAL_TX)
#undef U_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(X2_SERIAL_RX)
#undef X2_SERIAL_RX_PIN
#if !PIN_EXISTS(K_SERIAL_RX)
#undef K_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Y2_SERIAL_TX)
#undef Y2_SERIAL_TX_PIN
#if !PIN_EXISTS(K_SERIAL_TX)
#undef K_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Y2_SERIAL_RX)
#undef Y2_SERIAL_RX_PIN
#if !PIN_EXISTS(J_SERIAL_RX)
#undef J_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(I_SERIAL_TX)
#undef I_SERIAL_TX_PIN
#if !PIN_EXISTS(J_SERIAL_TX)
#undef J_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(I_SERIAL_RX)
#undef I_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(J_SERIAL_TX)
#undef J_SERIAL_TX_PIN
#if !PIN_EXISTS(I_SERIAL_TX)
#undef I_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(J_SERIAL_RX)
#undef J_SERIAL_RX_PIN
#if !PIN_EXISTS(Z4_SERIAL_RX)
#undef Z4_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(K_SERIAL_TX)
#undef K_SERIAL_TX_PIN
#if !PIN_EXISTS(Z4_SERIAL_TX)
#undef Z4_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(K_SERIAL_RX)
#undef K_SERIAL_RX_PIN
#if !PIN_EXISTS(Z3_SERIAL_RX)
#undef Z3_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(U_SERIAL_TX)
#undef U_SERIAL_TX_PIN
#if !PIN_EXISTS(Z3_SERIAL_TX)
#undef Z3_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(U_SERIAL_RX)
#undef U_SERIAL_RX_PIN
#if !PIN_EXISTS(Z2_SERIAL_RX)
#undef Z2_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(V_SERIAL_TX)
#undef V_SERIAL_TX_PIN
#if !PIN_EXISTS(Z2_SERIAL_TX)
#undef Z2_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(V_SERIAL_RX)
#undef V_SERIAL_RX_PIN
#if !PIN_EXISTS(Y2_SERIAL_RX)
#undef Y2_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(W_SERIAL_TX)
#undef W_SERIAL_TX_PIN
#if !PIN_EXISTS(Y2_SERIAL_TX)
#undef Y2_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(W_SERIAL_RX)
#undef W_SERIAL_RX_PIN
#if !PIN_EXISTS(X2_SERIAL_RX)
#undef X2_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(X2_SERIAL_TX)
#undef X2_SERIAL_TX_PIN
#endif

#ifndef FAN0_PIN
Expand Down
24 changes: 0 additions & 24 deletions Marlin/src/pins/samd/pins_RAMPS_144.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,54 +210,30 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN 47
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif
#ifndef X2_SERIAL_TX_PIN
#define X2_SERIAL_TX_PIN -1
#endif
#ifndef X2_SERIAL_RX_PIN
#define X2_SERIAL_RX_PIN X2_SERIAL_TX_PIN
#endif

#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN 45
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif
#ifndef Y2_SERIAL_TX_PIN
#define Y2_SERIAL_TX_PIN -1
#endif
#ifndef Y2_SERIAL_RX_PIN
#define Y2_SERIAL_RX_PIN Y2_SERIAL_TX_PIN
#endif

#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN 32
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#ifndef Z2_SERIAL_TX_PIN
#define Z2_SERIAL_TX_PIN 22
#endif
#ifndef Z2_SERIAL_RX_PIN
#define Z2_SERIAL_RX_PIN Z2_SERIAL_TX_PIN
#endif

#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN 43
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif
#ifndef E1_SERIAL_TX_PIN
#define E1_SERIAL_TX_PIN -1
#endif
#ifndef E1_SERIAL_RX_PIN
#define E1_SERIAL_RX_PIN E1_SERIAL_TX_PIN
#endif
#endif

//
Expand Down
12 changes: 0 additions & 12 deletions Marlin/src/pins/stm32f4/pins_FYSETC_CHEETAH_V30.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,17 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN PB3
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif

#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN PB3
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif

#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN PB3
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN PB3
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif

// Default TMC slave addresses
#ifndef X_SLAVE_ADDRESS
Expand Down
18 changes: 0 additions & 18 deletions Marlin/src/pins/stm32f4/pins_LERDGE_K.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,40 +120,22 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN PB2
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif
#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN PE2
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif
#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN PE3
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN PE4
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif
#ifndef E1_SERIAL_TX_PIN
#define E1_SERIAL_TX_PIN PE1
#endif
#ifndef E1_SERIAL_RX_PIN
#define E1_SERIAL_RX_PIN E1_SERIAL_TX_PIN
#endif
// Ex-motor can be any... X2/Y2/Z2 or E2
#ifndef EX_SERIAL_TX_PIN
#define EX_SERIAL_TX_PIN PE0
#endif
#ifndef EX_SERIAL_RX_PIN
#define EX_SERIAL_RX_PIN EX_SERIAL_TX_PIN
#endif
//#define Z2_SERIAL_RX_PIN EX_SERIAL_RX_PIN
//#define Z2_SERIAL_TX_PIN EX_SERIAL_TX_PIN
//#define E2_SERIAL_RX_PIN EX_SERIAL_RX_PIN
Expand Down

0 comments on commit 85c8e2a

Please sign in to comment.