Improved STMicro L64XX stepper driver support (#16452)

This commit is contained in:
Bob Kuhn
2020-01-13 18:47:30 -06:00
committed by Scott Lahteine
parent 53f1e5ff5b
commit 1ad53cee1f
315 changed files with 8582 additions and 5343 deletions

View File

@ -117,8 +117,10 @@ Stepper stepper; // Singleton
#include "../feature/runout.h"
#endif
#if HAS_DRIVER(L6470)
#include "../libs/L6470/L6470_Marlin.h"
#if HAS_L64XX
#include "../libs/L64XX/L64XX_Marlin.h"
uint8_t L6470_buf[MAX_L6470 + 1]; // chip command sequence - element 0 not used
bool L64XX_OK_to_power_up = false; // flag to keep L64xx steppers powered down after a reset or power up
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
@ -371,21 +373,17 @@ void Stepper::wake_up() {
*/
void Stepper::set_directions() {
#if HAS_DRIVER(L6470)
uint8_t L6470_buf[MAX_L6470 + 1]; // chip command sequence - element 0 not used
#endif
#if MINIMUM_STEPPER_PRE_DIR_DELAY > 0
DELAY_NS(MINIMUM_STEPPER_PRE_DIR_DELAY);
#endif
#define SET_STEP_DIR(A) \
if (motor_direction(_AXIS(A))) { \
A##_APPLY_DIR(INVERT_## A##_DIR, false); \
A##_APPLY_DIR(INVERT_##A##_DIR, false); \
count_direction[_AXIS(A)] = -1; \
} \
else { \
A##_APPLY_DIR(!INVERT_## A##_DIR, false); \
A##_APPLY_DIR(!INVERT_##A##_DIR, false); \
count_direction[_AXIS(A)] = 1; \
}
@ -425,25 +423,25 @@ void Stepper::set_directions() {
#endif
#endif // !LIN_ADVANCE
#if HAS_DRIVER(L6470)
#if HAS_L64XX
if (L64XX_OK_to_power_up) { // OK to send the direction commands (which powers up the L64XX steppers)
if (L64xxManager.spi_active) {
L64xxManager.spi_abort = true; // Interrupted SPI transfer needs to shut down gracefully
for (uint8_t j = 1; j <= L64XX::chain[0]; j++)
L6470_buf[j] = dSPIN_NOP; // Fill buffer with NOOPs
L64xxManager.transfer(L6470_buf, L64XX::chain[0]); // Send enough NOOPs to complete any command
L64xxManager.transfer(L6470_buf, L64XX::chain[0]);
L64xxManager.transfer(L6470_buf, L64XX::chain[0]);
}
if (L6470.spi_active) {
L6470.spi_abort = true; // interrupted a SPI transfer - need to shut it down gracefully
for (uint8_t j = 1; j <= L6470::chain[0]; j++)
L6470_buf[j] = dSPIN_NOP; // fill buffer with NOOP commands
L6470.transfer(L6470_buf, L6470::chain[0]); // send enough NOOPs to complete any command
L6470.transfer(L6470_buf, L6470::chain[0]);
L6470.transfer(L6470_buf, L6470::chain[0]);
// L64xxManager.dir_commands[] is an array that holds direction command for each stepper
// Scan command array, copy matches into L64xxManager.transfer
for (uint8_t j = 1; j <= L64XX::chain[0]; j++)
L6470_buf[j] = L64xxManager.dir_commands[L64XX::chain[j]];
L64xxManager.transfer(L6470_buf, L64XX::chain[0]); // send the command stream to the drivers
}
// The L6470.dir_commands[] array holds the direction command for each stepper
//scan command array and copy matches into L6470.transfer
for (uint8_t j = 1; j <= L6470::chain[0]; j++)
L6470_buf[j] = L6470.dir_commands[L6470::chain[j]];
L6470.transfer(L6470_buf, L6470::chain[0]); // send the command stream to the drivers
#endif
// A small delay may be needed after changing direction
@ -1846,8 +1844,8 @@ uint32_t Stepper::stepper_block_phase_isr() {
#endif
if (
#if HAS_DRIVER(L6470)
true // Always set direction for L6470 (This also enables the chips)
#if HAS_L64XX
true // Always set direction for L64xx (This also enables the chips)
#else
current_block->direction_bits != last_direction_bits
#if DISABLED(MIXING_EXTRUDER)
@ -1859,6 +1857,10 @@ uint32_t Stepper::stepper_block_phase_isr() {
#if EXTRUDERS > 1
last_moved_extruder = stepper_extruder;
#endif
#if HAS_L64XX
L64XX_OK_to_power_up = true;
#endif
set_directions();
}