tmc2130.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef TMC2130_H
  2. #define TMC2130_H
  3. //mode
  4. extern uint8_t tmc2130_mode;
  5. //holding and running currents
  6. extern uint8_t tmc2130_current_h[4];
  7. extern uint8_t tmc2130_current_r[4];
  8. //microstep resolution (0 means 256usteps, 8 means 1ustep
  9. extern uint8_t tmc2130_mres[4];
  10. //flags for axis stall detection
  11. extern uint8_t tmc2130_sg_thr[4];
  12. extern bool tmc2130_sg_stop_on_crash;
  13. extern uint8_t tmc2130_sg_crash; //crash mask
  14. extern uint8_t tmc2130_sg_meassure;
  15. extern uint32_t tmc2130_sg_meassure_cnt;
  16. extern uint32_t tmc2130_sg_meassure_val;
  17. extern uint8_t tmc2130_sg_homing_axes_mask;
  18. #define TMC2130_MODE_NORMAL 0
  19. #define TMC2130_MODE_SILENT 1
  20. #define TMC2130_WAVE_FAC1000_MIN 30
  21. #define TMC2130_WAVE_FAC1000_MAX 200
  22. #define TMC2130_WAVE_FAC1000_STP 1
  23. extern uint8_t tmc2130_home_enabled;
  24. extern uint8_t tmc2130_home_origin[2];
  25. extern uint8_t tmc2130_home_bsteps[2];
  26. extern uint8_t tmc2130_home_fsteps[2];
  27. extern uint8_t tmc2130_wave_fac[4];
  28. #pragma pack(push)
  29. #pragma pack(1)
  30. typedef struct
  31. {
  32. uint8_t toff:4;
  33. uint8_t hstr:3;
  34. uint8_t hend:4;
  35. uint8_t tbl:2;
  36. uint8_t res:3;
  37. } tmc2130_chopper_config_t;
  38. #pragma pack(pop)
  39. extern tmc2130_chopper_config_t tmc2130_chopper_config[4];
  40. //initialize tmc2130
  41. #ifdef PSU_Delta
  42. extern void tmc2130_init(bool bSupressFlag=false);
  43. #else
  44. extern void tmc2130_init();
  45. #endif
  46. //check diag pins (called from stepper isr)
  47. extern void tmc2130_st_isr();
  48. //update stall guard (called from st_synchronize inside the loop)
  49. extern bool tmc2130_update_sg();
  50. //temperature watching (called from )
  51. extern void tmc2130_check_overtemp();
  52. //enter homing (called from homeaxis before homing starts)
  53. extern void tmc2130_home_enter(uint8_t axes_mask);
  54. //exit homing (called from homeaxis after homing ends)
  55. extern void tmc2130_home_exit();
  56. //start stallguard meassuring for single axis
  57. extern void tmc2130_sg_meassure_start(uint8_t axis);
  58. //stop current stallguard meassuring and report result
  59. extern uint16_t tmc2130_sg_meassure_stop();
  60. extern void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r);
  61. //set holding current for any axis (M911)
  62. extern void tmc2130_set_current_h(uint8_t axis, uint8_t current);
  63. //set running current for any axis (M912)
  64. extern void tmc2130_set_current_r(uint8_t axis, uint8_t current);
  65. //print currents (M913)
  66. extern void tmc2130_print_currents();
  67. //set PWM_AMPL for any axis (M917)
  68. extern void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl);
  69. //set PWM_GRAD for any axis (M918)
  70. extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
  71. extern uint16_t tmc2130_rd_MSCNT(uint8_t axis);
  72. extern uint32_t tmc2130_rd_MSCURACT(uint8_t axis);
  73. extern uint8_t tmc2130_usteps2mres(uint16_t usteps);
  74. #define tmc2130_mres2usteps(mres) ((uint16_t)256 >> mres)
  75. extern bool tmc2130_wait_standstill_xy(int timeout);
  76. extern uint16_t tmc2130_get_res(uint8_t axis);
  77. extern void tmc2130_set_res(uint8_t axis, uint16_t res);
  78. extern uint8_t tmc2130_get_pwr(uint8_t axis);
  79. extern void tmc2130_set_pwr(uint8_t axis, uint8_t pwr);
  80. extern uint8_t tmc2130_get_inv(uint8_t axis);
  81. extern uint8_t tmc2130_get_dir(uint8_t axis);
  82. extern void tmc2130_set_dir(uint8_t axis, uint8_t dir);
  83. extern void tmc2130_do_step(uint8_t axis);
  84. extern void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us);
  85. extern void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution);
  86. extern void tmc2130_get_wave(uint8_t axis, uint8_t* data, FILE* stream);
  87. extern void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000);
  88. extern bool tmc2130_home_calibrate(uint8_t axis);
  89. extern uint8_t tmc2130_cur2val(float cur);
  90. extern float tmc2130_val2cur(uint8_t val);
  91. #endif //TMC2130_H