tmc2130.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef TMC2130_H
  2. #define TMC2130_H
  3. extern uint8_t tmc2130_cs[4];
  4. //mode
  5. extern uint8_t tmc2130_mode;
  6. //holding and running currents
  7. extern uint8_t tmc2130_current_h[4];
  8. extern uint8_t tmc2130_current_r[4];
  9. //flags for axis stall detection
  10. extern uint8_t tmc2130_axis_stalled[4];
  11. extern uint8_t tmc2130_sg_thr[4];
  12. extern bool tmc2130_sg_stop_on_crash;
  13. extern bool tmc2130_sg_crash;
  14. extern uint8_t tmc2130_sg_meassure;
  15. extern uint16_t tmc2130_sg_meassure_cnt;
  16. extern uint32_t tmc2130_sg_meassure_val;
  17. #define TMC2130_MODE_NORMAL 0
  18. #define TMC2130_MODE_SILENT 1
  19. //initialize tmc2130
  20. extern void tmc2130_init();
  21. //check diag pins (called from stepper isr)
  22. extern void tmc2130_st_isr(uint8_t last_step_mask);
  23. //update stall guard (called from st_synchronize inside the loop)
  24. extern bool tmc2130_update_sg();
  25. //temperature watching (called from )
  26. extern void tmc2130_check_overtemp();
  27. //enter homing (called from homeaxis before homing starts)
  28. extern void tmc2130_home_enter(uint8_t axes_mask);
  29. //exit homing (called from homeaxis after homing ends)
  30. extern void tmc2130_home_exit();
  31. //restart homing (called from homeaxis befor move)
  32. extern void tmc2130_home_restart(uint8_t axis);
  33. //start stallguard meassuring for single axis
  34. extern void tmc2130_sg_meassure_start(uint8_t axis);
  35. //stop current stallguard meassuring and report result
  36. extern uint16_t tmc2130_sg_meassure_stop();
  37. //set holding current for any axis (M911)
  38. extern void tmc2130_set_current_h(uint8_t axis, uint8_t current);
  39. //set running current for any axis (M912)
  40. extern void tmc2130_set_current_r(uint8_t axis, uint8_t current);
  41. //print currents (M913)
  42. extern void tmc2130_print_currents();
  43. //set PWM_AMPL for any axis (M917)
  44. extern void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl);
  45. //set PWM_GRAD for any axis (M918)
  46. extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
  47. extern uint16_t tmc2130_rd_MSCNT(uint8_t cs);
  48. extern void tmc2130_home_pause(uint8_t axis);
  49. extern void tmc2130_home_resume(uint8_t axis);
  50. extern bool tmc2130_wait_standstill_xy(int timeout);
  51. extern void tmc2130_eeprom_load_config();
  52. extern void tmc2130_eeprom_save_config();
  53. #pragma pack(push)
  54. #pragma pack(1)
  55. struct
  56. {
  57. uint8_t mres:5; // mres - byte 0, bit 0..4 microstep resolution
  58. uint8_t reserved_0_0:2; // reserved - byte 0, bit 5..6
  59. uint8_t intpol:1; // intpol - byte 0, bit 7 linear interpolation to 255 usteps
  60. uint8_t pwm_ampl:8; // pwm_ampl - byte 1, bit 0..7 pwm amplitude for silent mode
  61. uint8_t pwm_grad:4; // pwm_grad - byte 2, bit 0..3 pwm gradient for silent mode
  62. uint8_t pwm_freq:2; // pwm_freq - byte 2, bit 4..5 pwm frequency for silent mode
  63. uint8_t reserved_2_0:2; // reserved - byte 2, bit 6..7
  64. uint16_t tcoolthrs:16; // tcoolthrs - byte 3..4 coolstep threshold / middle sensitivity
  65. int8_t sg_thrs:8; // sg_thrs - byte 5, bit 0..7 stallguard sensitivity in high power / middle sensitivity
  66. int8_t current_h:6; // current_h - byte 6, bit 0..5 holding current for high power mode
  67. uint8_t reserved_6_0:2; // reserved - byte 6, bit 6..7
  68. int8_t current_r:6; // current_r - byte 7, bit 0..5 running current for high power mode
  69. uint8_t reserved_7_0:2; // reserved - byte 7, bit 6..7
  70. int8_t home_sg_thrs:8; // sg_thrs - byte 8, bit 0..7 stallguard sensitivity for homing
  71. int8_t home_current:6; // current_r - byte 9, bit 0..5 running current for homing
  72. uint8_t reserved_9_0:2; // reserved - byte 9, bit 6..7
  73. int8_t home_dtcoolthrs:8; // dtcoolthrs - byte 10, bit 0..7 delta tcoolthrs for homing
  74. int8_t dtcoolthrs_low:8; // dtcoolthrs - byte 11, bit 0..7 delta tcoolthrs for low sensitivity (based on value for middle sensitivity)
  75. int8_t dtcoolthrs_high:8; // dtcoolthrs - byte 12, bit 0..7 delta tcoolthrs for high sensitivity (based on value for middle sensitivity)
  76. int8_t sg_thrs_low:8; // sg_thrs - byte 13, bit 0..7 stallguard sensitivity in high power / low sensitivity
  77. int8_t sg_thrs_high:8; // sg_thrs - byte 14, bit 0..7 stallguard sensitivity in high power / high sensitivity
  78. } tmc2130_axis_config;
  79. #pragma pack(pop)
  80. #endif //TMC2130_H