Define tmc variables where needed (#13918)

This commit is contained in:
Ludy 2019-05-06 05:04:47 +02:00 committed by Scott Lahteine
parent f96eaad1ea
commit c837e9250c
2 changed files with 16 additions and 14 deletions

View File

@ -85,12 +85,15 @@
#endif
static TMC_driver_data get_driver_data(TMC2130Stepper &st) {
constexpr uint16_t SG_RESULT_bm = 0x3FF; // 0:9
constexpr uint8_t STEALTH_bp = 14, CS_ACTUAL_sb = 16;
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
constexpr uint8_t STALL_GUARD_bp = 24, OT_bp = 25, OTPW_bp = 26;
constexpr uint8_t OT_bp = 25, OTPW_bp = 26;
constexpr uint32_t S2G_bm = 0x18000000;
constexpr uint8_t STST_bp = 31;
#if ENABLED(TMC_DEBUG)
constexpr uint16_t SG_RESULT_bm = 0x3FF; // 0:9
constexpr uint8_t STEALTH_bp = 14;
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
constexpr uint8_t STALL_GUARD_bp = 24;
constexpr uint8_t STST_bp = 31;
#endif
TMC_driver_data data;
data.drv_status = st.DRV_STATUS();
#ifdef __AVR__
@ -112,13 +115,13 @@
data.is_standstill = !!(spart & _BV(STST_bp - 24));
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
#endif
UNUSED(CS_ACTUAL_sb);
#else // !__AVR__
data.is_ot = !!(data.drv_status & _BV(OT_bp));
data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
data.is_s2g = !!(data.drv_status & S2G_bm);
#if ENABLED(TMC_DEBUG)
constexpr uint8_t CS_ACTUAL_sb = 16;
data.sg_result = data.drv_status & SG_RESULT_bm;
data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
@ -143,15 +146,14 @@
static TMC_driver_data get_driver_data(TMC2208Stepper &st) {
constexpr uint8_t OTPW_bp = 0, OT_bp = 1;
constexpr uint8_t S2G_bm = 0b11110; // 2..5
constexpr uint8_t CS_ACTUAL_sb = 16;
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
constexpr uint8_t STEALTH_bp = 30, STST_bp = 31;
TMC_driver_data data;
data.drv_status = st.DRV_STATUS();
data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
data.is_ot = !!(data.drv_status & _BV(OT_bp));
data.is_s2g = !!(data.drv_status & S2G_bm);
#if ENABLED(TMC_DEBUG)
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
constexpr uint8_t STEALTH_bp = 30, STST_bp = 31;
#ifdef __AVR__
// 8-bit optimization saves up to 12 bytes of PROGMEM per axis
uint8_t spart = data.drv_status >> 16;
@ -159,8 +161,8 @@
spart = data.drv_status >> 24;
data.is_stealth = !!(spart & _BV(STEALTH_bp - 24));
data.is_standstill = !!(spart & _BV(STST_bp - 24));
UNUSED(CS_ACTUAL_sb);
#else
constexpr uint8_t CS_ACTUAL_sb = 16;
data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
data.is_standstill = !!(data.drv_status & _BV(STST_bp));
@ -181,11 +183,8 @@
#endif
static TMC_driver_data get_driver_data(TMC2660Stepper &st) {
constexpr uint8_t STALL_GUARD_bp = 0;
constexpr uint8_t OT_bp = 1, OTPW_bp = 2;
constexpr uint8_t S2G_bm = 0b11000;
constexpr uint8_t STST_bp = 7, SG_RESULT_sp = 10;
constexpr uint32_t SG_RESULT_bm = 0xFFC00; // 10:19
TMC_driver_data data;
data.drv_status = st.DRVSTATUS();
uint8_t spart = data.drv_status & 0xFF;
@ -193,6 +192,9 @@
data.is_ot = !!(spart & _BV(OT_bp));
data.is_s2g = !!(data.drv_status & S2G_bm);
#if ENABLED(TMC_DEBUG)
constexpr uint8_t STALL_GUARD_bp = 0;
constexpr uint8_t STST_bp = 7, SG_RESULT_sp = 10;
constexpr uint32_t SG_RESULT_bm = 0xFFC00; // 10:19
data.is_stall = !!(spart & _BV(STALL_GUARD_bp));
data.is_standstill = !!(spart & _BV(STST_bp));
data.sg_result = (data.drv_status & SG_RESULT_bm) >> SG_RESULT_sp;

View File

@ -47,7 +47,7 @@ opt_disable Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
opt_set X_DRIVER_TYPE TMC2130
opt_set Y_DRIVER_TYPE TMC2130
opt_set Z_DRIVER_TYPE TMC2130
opt_enable TMC_USE_SW_SPI MONITOR_DRIVER_STATUS STEALTHCHOP HYBRID_THRESHOLD TMC_DEBUG \
opt_enable TMC_USE_SW_SPI MONITOR_DRIVER_STATUS STEALTHCHOP_XY STEALTHCHOP_Z HYBRID_THRESHOLD TMC_DEBUG \
SENSORLESS_PROBING X_STALL_SENSITIVITY Y_STALL_SENSITIVITY Z_STALL_SENSITIVITY
exec_test $1 $2 "Delta Config (generic) + BOARD_COHESION3D_REMIX + UBL + EEPROM_SETTINGS + SENSORLESS_PROBING"