Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Other code patches
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 10, 2024
1 parent 108f0b0 commit af6dac3
Show file tree
Hide file tree
Showing 123 changed files with 2,872 additions and 2,091 deletions.
11 changes: 4 additions & 7 deletions Marlin/src/core/drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
#define HAS_TMC220x 1
#endif

#if HAS_DRIVER(TMC26X)
#define HAS_TMC26X 1
#endif

#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC2660) \
Expand Down Expand Up @@ -184,10 +188,3 @@
#if ANY_AXIS_HAS(SPI)
#define HAS_TMC_SPI 1
#endif

//
// TMC26XX Stepper Drivers
//
#if HAS_DRIVER(TMC26X)
#define HAS_TMC26X 1
#endif
10 changes: 6 additions & 4 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,12 @@
//
// Endstop Names used by Endstops::report_states
//
#define STR_X_MIN "x_min"
#define STR_X_MAX "x_max"
#define STR_X2_MIN "x2_min"
#define STR_X2_MAX "x2_max"
#if HAS_X_AXIS
#define STR_X_MIN "x_min"
#define STR_X_MAX "x_max"
#define STR_X2_MIN "x2_min"
#define STR_X2_MAX "x2_max"
#endif

#if HAS_Y_AXIS
#define STR_Y_MIN "y_min"
Expand Down
58 changes: 55 additions & 3 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,12 @@
// Compiler flags -fno-signed-zeros -ffinite-math-only also cover 'f * 1.0', 'f - f', etc.
#define PLUS_TERN0(O,A) _TERN(_ENA_1(O),,+ (A)) // OPTION ? '+ (A)' : '<nul>'
#define MINUS_TERN0(O,A) _TERN(_ENA_1(O),,- (A)) // OPTION ? '- (A)' : '<nul>'
#define MUL_TERN1(O,A) _TERN(_ENA_1(O),,* (A)) // OPTION ? '* (A)' : '<nul>'
#define DIV_TERN1(O,A) _TERN(_ENA_1(O),,/ (A)) // OPTION ? '/ (A)' : '<nul>'
#define SUM_TERN(O,B,A) ((B) PLUS_TERN0(O,A)) // ((B) (OPTION ? '+ (A)' : '<nul>'))
#define DIFF_TERN(O,B,A) ((B) MINUS_TERN0(O,A)) // ((B) (OPTION ? '- (A)' : '<nul>'))
#define MUL_TERN(O,B,A) ((B) MUL_TERN1(O,A)) // ((B) (OPTION ? '* (A)' : '<nul>'))
#define DIV_TERN(O,B,A) ((B) DIV_TERN1(O,A)) // ((B) (OPTION ? '/ (A)' : '<nul>'))

#define IF_ENABLED TERN_
#define IF_DISABLED(O,A) TERN(O,,A)
Expand Down Expand Up @@ -434,6 +438,8 @@
extern "C++" {

// C++11 solution that is standards compliant. Return type is deduced automatically
template <class N> static constexpr N _MIN(const N val) { return val; }
template <class N> static constexpr N _MAX(const N val) { return val; }
template <class L, class R> static constexpr auto _MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
return lhs < rhs ? lhs : rhs;
}
Expand All @@ -453,9 +459,9 @@
FORCE_INLINE constexpr T operator|(T x, T y) { return static_cast<T>(static_cast<int>(x) | static_cast<int>(y)); } \
FORCE_INLINE constexpr T operator^(T x, T y) { return static_cast<T>(static_cast<int>(x) ^ static_cast<int>(y)); } \
FORCE_INLINE constexpr T operator~(T x) { return static_cast<T>(~static_cast<int>(x)); } \
FORCE_INLINE T & operator&=(T &x, T y) { return x &= y; } \
FORCE_INLINE T & operator|=(T &x, T y) { return x |= y; } \
FORCE_INLINE T & operator^=(T &x, T y) { return x ^= y; }
FORCE_INLINE T & operator&=(T &x, T y) { x = x & y; return x; } \
FORCE_INLINE T & operator|=(T &x, T y) { x = x | y; return x; } \
FORCE_INLINE T & operator^=(T &x, T y) { x = x ^ y; return x; }

// C++11 solution that is standard compliant. <type_traits> is not available on all platform
namespace Private {
Expand All @@ -467,6 +473,39 @@

template <typename T, typename ... Args> struct first_type_of { typedef T type; };
template <typename T> struct first_type_of<T> { typedef T type; };

// remove const/volatile type qualifiers
template<typename T> struct remove_const { typedef T type; };
template<typename T> struct remove_const<T const> { typedef T type; };

template<typename T> struct remove_volatile { typedef T type; };
template<typename T> struct remove_volatile<T volatile> { typedef T type; };

template<typename T> struct remove_cv { typedef typename remove_const<typename remove_volatile<T>::type>::type type; };

// test if type is integral
template<typename> struct _is_integral { enum { value = false }; };
template<> struct _is_integral<unsigned char> { enum { value = true }; };
template<> struct _is_integral<unsigned short> { enum { value = true }; };
template<> struct _is_integral<unsigned int> { enum { value = true }; };
template<> struct _is_integral<unsigned long> { enum { value = true }; };
template<> struct _is_integral<unsigned long long> { enum { value = true }; };
template<> struct _is_integral<char> { enum { value = true }; };
template<> struct _is_integral<short> { enum { value = true }; };
template<> struct _is_integral<int> { enum { value = true }; };
template<> struct _is_integral<long> { enum { value = true }; };
template<> struct _is_integral<long long> { enum { value = true }; };
template<typename T> struct is_integral : public _is_integral<typename remove_cv<T>::type> {};
}

// enum type check and regression to its underlying integral.
namespace Private {
template<typename T> struct is_enum { enum { value = __is_enum(T) }; };

template<typename T, bool = is_enum<T>::value> struct _underlying_type { using type = __underlying_type(T); };
template<typename T> struct _underlying_type<T, false> { };

template<typename T> struct underlying_type : public _underlying_type<T> { };
}

// C++11 solution using SFINAE to detect the existence of a member in a class at compile time.
Expand Down Expand Up @@ -726,6 +765,19 @@
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)

// Emit a list of N OP(I) items with ascending counter.
#define _REPLIST(_RPT_I,_RPT_N,_RPT_OP) \
_RPT_OP(_RPT_I) \
IF_ELSE(SUB1(_RPT_N)) \
( , DEFER2(__REPLIST)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP) ) \
( /* Do nothing */ )
#define __REPLIST() _REPLIST

// Repeat a macro, comma-separated, passing S...N-1.
#define REPLIST_S(S,N,OP) EVAL(_REPLIST(S,SUB##S(N),OP))
#define REPLIST(N,OP) REPLIST_S(0,N,OP)
#define REPLIST_1(N,OP) REPLIST_S(1,INCREMENT(N),OP)

// Call OP(A) with each item as an argument
#define _MAP(_MAP_OP,A,V...) \
_MAP_OP(A) \
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/core/multi_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ typedef const char Language_Str[];

#if NUM_LANGUAGES > 1
#define HAS_MULTI_LANGUAGE 1
#if HAS_MARLINUI_MENU
#define HAS_MENU_MULTI_LANGUAGE 1
#endif
#define GET_TEXT(MSG) ( \
ui.language == 4 ? GET_LANG(LCD_LANGUAGE_5)::MSG : \
ui.language == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/core/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#include "../feature/ethernet.h"
#endif

uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
// Echo commands to the terminal by default in dev mode
uint8_t marlin_debug_flags = TERN(MARLIN_DEV_MODE, MARLIN_DEBUG_ECHO, MARLIN_DEBUG_NONE);

// Commonly-used strings in serial output
PGMSTR(SP_A_STR, " A"); PGMSTR(SP_B_STR, " B"); PGMSTR(SP_C_STR, " C");
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_IMPL SERIAL_LEAF_1
#endif

#define SERIAL_OUT(WHAT, V...) (void)SERIAL_IMPL.WHAT(V)

#define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
#define PORT_RESTORE() _PORT_RESTORE(1)
#define SERIAL_PORTMASK(P) SerialMask::from(P)
Expand All @@ -149,10 +147,8 @@ template <typename T>
void SERIAL_ECHO(T x) { SERIAL_IMPL.print(x); }

// Wrapper for ECHO commands to interpret a char
typedef struct SerialChar { char c; SerialChar(char n) : c(n) { } } serial_char_t;
inline void SERIAL_ECHO(serial_char_t x) { SERIAL_IMPL.write(x.c); }
#define AS_CHAR(C) serial_char_t(C)
#define AS_DIGIT(C) AS_CHAR('0' + (C))
#define AS_DIGIT(n) C('0' + (n))

template <typename T>
void SERIAL_ECHOLN(T x) { SERIAL_IMPL.println(x); }
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/core/serial_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "../inc/MarlinConfigPre.h"

#include <stddef.h> // for size_t

#if ENABLED(EMERGENCY_PARSER)
#include "../feature/e_parser.h"
#endif
Expand Down
Loading

0 comments on commit af6dac3

Please sign in to comment.