My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

L64XX_Marlin.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../inc/MarlinConfig.h"
  24. #include <L6470.h>
  25. #if !(L6470_LIBRARY_VERSION >= 0x000800)
  26. #error 'L6470_LIBRARY_VERSION 0x000800 or later required'
  27. #endif
  28. #define L6470_GETPARAM(P,Q) stepper##Q.GetParam(P)
  29. #define dSPIN_STEP_CLOCK 0x58
  30. #define dSPIN_STEP_CLOCK_FWD dSPIN_STEP_CLOCK
  31. #define dSPIN_STEP_CLOCK_REV dSPIN_STEP_CLOCK+1
  32. #define HAS_L64XX_EXTRUDER (AXIS_IS_L64XX(E0) || AXIS_IS_L64XX(E1) || AXIS_IS_L64XX(E2) || AXIS_IS_L64XX(E3) || AXIS_IS_L64XX(E4) || AXIS_IS_L64XX(E5))
  33. enum L64XX_axis_t : uint8_t { X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7, MAX_L64XX };
  34. class L64XX_Marlin : public L64XXHelper {
  35. public:
  36. static char index_to_axis[MAX_L64XX][3];
  37. static uint8_t index_to_dir[MAX_L64XX];
  38. static uint8_t dir_commands[MAX_L64XX];
  39. // Flags to guarantee graceful switch if stepper interrupts L6470 SPI transfer
  40. static volatile uint8_t spi_abort;
  41. static uint8_t spi_active;
  42. L64XX_Marlin() {}
  43. static void init();
  44. static void init_to_defaults();
  45. static uint16_t get_stepper_status(L64XX &st);
  46. static uint16_t get_status(const L64XX_axis_t axis);
  47. static uint32_t get_param(const L64XX_axis_t axis, const uint8_t param);
  48. static void set_param(const L64XX_axis_t axis, const uint8_t param, const uint32_t value);
  49. //static void send_command(const L64XX_axis_t axis, uint8_t command);
  50. static uint8_t get_user_input(uint8_t &driver_count, L64XX_axis_t axis_index[3], char axis_mon[3][3],
  51. float &position_max, float &position_min, float &final_feedrate, uint8_t &kval_hold,
  52. uint8_t over_current_flag, uint8_t &OCD_TH_val, uint8_t &STALL_TH_val, uint16_t &over_current_threshold);
  53. static void transfer(uint8_t L6470_buf[], const uint8_t length);
  54. //static char* index_to_axis(const uint8_t index);
  55. static void say_axis(const L64XX_axis_t axis, const uint8_t label=true);
  56. #if ENABLED(L6470_CHITCHAT)
  57. static void error_status_decode(
  58. const uint16_t status, const L64XX_axis_t axis,
  59. const uint16_t _status_axis_th_sd, const uint16_t _status_axis_th_wrn,
  60. const uint16_t _status_axis_step_loss_a, const uint16_t _status_axis_step_loss_b,
  61. const uint16_t _status_axis_ocd, const uint8_t _status_axis_layout
  62. );
  63. #else
  64. FORCE_INLINE static void error_status_decode(
  65. const uint16_t, const L64XX_axis_t,
  66. const uint16_t, const uint16_t,
  67. const uint16_t, const uint16_t,
  68. const uint16_t, const uint8_t
  69. ){}
  70. #endif
  71. // ~40 bytes SRAM to simplify status decode routines
  72. typedef struct {
  73. uint8_t STATUS_AXIS_LAYOUT; // Copy of L6470_status_layout
  74. uint8_t AXIS_OCD_TH_MAX; // Size of OCD_TH field
  75. uint8_t AXIS_STALL_TH_MAX; // Size of STALL_TH field
  76. float AXIS_OCD_CURRENT_CONSTANT_INV; // mA per count
  77. float AXIS_STALL_CURRENT_CONSTANT_INV; // mA per count
  78. uint8_t L6470_AXIS_CONFIG, // Address of the CONFIG register
  79. L6470_AXIS_STATUS; // Address of the STATUS register
  80. uint16_t L6470_ERROR_MASK, // STATUS_UVLO | STATUS_TH_WRN | STATUS_TH_SD | STATUS_OCD | STATUS_STEP_LOSS_A | STATUS_STEP_LOSS_B
  81. L6474_ERROR_MASK, // STATUS_UVLO | STATUS_TH_WRN | STATUS_TH_SD | STATUS_OCD
  82. STATUS_AXIS_RAW, // Copy of status register contents
  83. STATUS_AXIS, // Copy of status register contents but with all error bits active low
  84. STATUS_AXIS_OCD, // Overcurrent detected bit position
  85. STATUS_AXIS_SCK_MOD, // Step clock mode is active bit position
  86. STATUS_AXIS_STEP_LOSS_A, // Stall detected on A bridge bit position
  87. STATUS_AXIS_STEP_LOSS_B, // Stall detected on B bridge bit position
  88. STATUS_AXIS_TH_SD, // Thermal shutdown bit position
  89. STATUS_AXIS_TH_WRN, // Thermal warning bit position
  90. STATUS_AXIS_UVLO, // Undervoltage lockout is active bit position
  91. STATUS_AXIS_WRONG_CMD, // Last command not valid bit position
  92. STATUS_AXIS_CMD_ERR, // Command error bit position
  93. STATUS_AXIS_NOTPERF_CMD; // Last command not performed bit position
  94. } L64XX_shadow_t;
  95. static L64XX_shadow_t shadow;
  96. #if ENABLED(MONITOR_L6470_DRIVER_STATUS)
  97. static bool monitor_paused;
  98. static inline void pause_monitor(const bool p) { monitor_paused = p; }
  99. static void monitor_update(L64XX_axis_t stepper_index);
  100. static void monitor_driver();
  101. #else
  102. static inline void pause_monitor(const bool) {}
  103. #endif
  104. //protected:
  105. // L64XXHelper methods
  106. static void spi_init();
  107. static uint8_t transfer_single(uint8_t data, int16_t ss_pin);
  108. static uint8_t transfer_chain(uint8_t data, int16_t ss_pin, uint8_t chain_position);
  109. private:
  110. static void append_stepper_err(char* &p, const uint8_t stepper_index, const char * const err=nullptr);
  111. };
  112. void echo_yes_no(const bool yes);
  113. extern L64XX_Marlin L64xxManager;