tmc2130.h 4.0 KB

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