5 #include "Configuration_var.h"
8 extern uint8_t tmc2130_mode;
10 extern uint8_t tmc2130_mres[4];
13 extern uint8_t tmc2130_sg_thr[4];
15 extern bool tmc2130_sg_stop_on_crash;
16 extern uint8_t tmc2130_sg_crash;
18 extern uint8_t tmc2130_sg_homing_axes_mask;
20 extern const char eMotorCurrentScalingEnabled[];
22 #define TMC2130_MODE_NORMAL 0
23 #define TMC2130_MODE_SILENT 1
25 #define TMC2130_WAVE_FAC1000_MIN 30
26 #define TMC2130_WAVE_FAC1000_MAX 200
27 #define TMC2130_WAVE_FAC1000_STP 1
29 #define TMC2130_MINIMUM_PULSE 0
30 #define TMC2130_SET_DIR_DELAY 20
31 #define TMC2130_SET_PWR_DELAY 0
33 #ifdef TMC2130_DEDGE_STEPPING
34 #define TMC2130_MINIMUM_DELAY
35 #elif TMC2130_MINIMUM_PULSE == 0
36 #define TMC2130_MINIMUM_DELAY asm("nop")
38 #define TMC2130_MINIMUM_DELAY delayMicroseconds(TMC2130_MINIMUM_PULSE)
41 extern uint8_t tmc2130_home_enabled;
42 extern uint8_t tmc2130_home_origin[2];
43 extern uint8_t tmc2130_home_bsteps[2];
44 extern uint8_t tmc2130_home_fsteps[2];
46 extern uint8_t tmc2130_wave_fac[4];
68 void refreshCurrentScaling() {
73 const bool newvSense = (iRun < 32);
74 if (vSense != newvSense) {
101 constexpr
inline __attribute__((always_inline))
MotorCurrents(uint8_t ir, uint8_t ih)
102 : vSense((ir < 32) ? 1 : 0)
103 , iRun((ir < 32) ? ir : (ir >> 1))
104 , iHold((ir < 32) ? ih : (ih >> 1)) {}
106 inline uint8_t getiRun()
const {
return iRun; }
107 inline uint8_t getiHold()
const {
return min(iHold, iRun); }
108 inline uint8_t getOriginaliRun()
const {
return vSense ? iRun : iRun << 1; }
109 inline uint8_t getOriginaliHold()
const {
return min(vSense ? iHold : iHold << 1, getOriginaliRun()); }
110 inline bool iHoldIsClamped()
const {
return iHold > iRun; }
111 inline uint8_t getvSense()
const {
return vSense; }
113 void __attribute__((noinline)) setiRun(uint8_t ir) {
118 refreshCurrentScaling();
121 void __attribute__((noinline)) setiHold(uint8_t ih) {
122 iHold = vSense ? ih : ih >> 1;
140 uint8_t bSuppressFlag : 1;
141 uint8_t enableECool : 1;
143 inline explicit TMCInitParams(
bool bSuppressFlag,
bool enableECool):bSuppressFlag(bSuppressFlag), enableECool(enableECool) { }
152 , enableECool(enableECool) { }
156 extern void tmc2130_st_isr();
158 extern bool tmc2130_update_sg();
160 extern void tmc2130_check_overtemp();
162 extern void tmc2130_home_enter(uint8_t axes_mask);
164 extern void tmc2130_home_exit();
167 extern void tmc2130_sg_measure_start(uint8_t axis);
169 extern uint16_t tmc2130_sg_measure_stop();
172 void crashdet_use_eeprom_setting();
174 extern void tmc2130_setup_chopper(uint8_t axis, uint8_t mres,
const MotorCurrents *curr =
nullptr);
177 extern void tmc2130_print_currents();
180 extern void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl);
182 extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
185 extern uint16_t tmc2130_rd_MSCNT(uint8_t axis);
186 extern uint32_t tmc2130_rd_MSCURACT(uint8_t axis);
188 extern uint8_t tmc2130_usteps2mres(uint16_t usteps);
189 #define tmc2130_mres2usteps(mres) ((uint16_t)256 >> mres)
191 extern bool tmc2130_wait_standstill_xy(
int timeout);
193 extern uint16_t tmc2130_get_res(uint8_t axis);
194 extern void tmc2130_set_res(uint8_t axis, uint16_t res);
195 extern uint8_t tmc2130_get_pwr(uint8_t axis);
197 extern uint8_t tmc2130_get_inv(uint8_t axis);
198 extern uint8_t tmc2130_get_dir(uint8_t axis);
199 extern void tmc2130_set_dir(uint8_t axis, uint8_t dir);
200 extern void tmc2130_do_step(uint8_t axis);
201 extern void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us);
202 extern void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution);
203 extern void tmc2130_get_wave(uint8_t axis, uint8_t* data);
204 extern void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000);
206 extern bool tmc2130_home_calibrate(uint8_t axis);
209 extern float tmc2130_val2cur(uint8_t val);
Definition: tmc2130.h:139
uint8_t tmc2130_cur2val(float cur)
Translate current to tmc2130 vsense and IHOLD or IRUN.
Definition: tmc2130.cpp:1113
void tmc2130_set_pwr(uint8_t axis, uint8_t pwr)
Definition: tmc2130.cpp:759