Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move L64XX index_to_axis to progmem #16697

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,36 +291,36 @@ void quickstop_stepper() {
}

void enable_e_steppers() {
#define _ENA_E(N) enable_E##N();
#define _ENA_E(N) ENABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _ENA_E)
}

void enable_all_steppers() {
#if ENABLED(AUTO_POWER_CONTROL)
powerManager.power_on();
#endif
enable_X();
enable_Y();
enable_Z();
ENABLE_AXIS_X();
ENABLE_AXIS_Y();
ENABLE_AXIS_Z();
enable_e_steppers();
}

void disable_e_steppers() {
#define _DIS_E(N) disable_E##N();
#define _DIS_E(N) DISABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _DIS_E)
}

void disable_e_stepper(const uint8_t e) {
#define _CASE_DIS_E(N) case N: disable_E##N(); break;
#define _CASE_DIS_E(N) case N: DISABLE_AXIS_E##N(); break;
switch (e) {
REPEAT(EXTRUDERS, _CASE_DIS_E)
}
}

void disable_all_steppers() {
disable_X();
disable_Y();
disable_Z();
DISABLE_AXIS_X();
DISABLE_AXIS_Y();
DISABLE_AXIS_Z();
disable_e_steppers();
}

Expand Down Expand Up @@ -461,13 +461,13 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
if (!already_shutdown_steppers) {
already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this
#if ENABLED(DISABLE_INACTIVE_X)
disable_X();
DISABLE_AXIS_X();
#endif
#if ENABLED(DISABLE_INACTIVE_Y)
disable_Y();
DISABLE_AXIS_Y();
#endif
#if ENABLED(DISABLE_INACTIVE_Z)
disable_Z();
DISABLE_AXIS_Z();
#endif
#if ENABLED(DISABLE_INACTIVE_E)
disable_e_steppers();
Expand Down Expand Up @@ -542,19 +542,19 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
#if ENABLED(SWITCHING_EXTRUDER)
bool oldstatus;
switch (active_extruder) {
default: oldstatus = E0_ENABLE_READ(); enable_E0(); break;
default: oldstatus = E0_ENABLE_READ(); ENABLE_AXIS_E0(); break;
#if E_STEPPERS > 1
case 2: case 3: oldstatus = E1_ENABLE_READ(); enable_E1(); break;
case 2: case 3: oldstatus = E1_ENABLE_READ(); ENABLE_AXIS_E1(); break;
#if E_STEPPERS > 2
case 4: case 5: oldstatus = E2_ENABLE_READ(); enable_E2(); break;
case 4: case 5: oldstatus = E2_ENABLE_READ(); ENABLE_AXIS_E2(); break;
#endif // E_STEPPERS > 2
#endif // E_STEPPERS > 1
}
#else // !SWITCHING_EXTRUDER
bool oldstatus;
switch (active_extruder) {
default:
#define _CASE_EN(N) case N: oldstatus = E##N##_ENABLE_READ(); enable_E##N(); break;
#define _CASE_EN(N) case N: oldstatus = E##N##_ENABLE_READ(); ENABLE_AXIS_E##N(); break;
REPEAT(E_STEPPERS, _CASE_EN);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/babystep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
#endif

#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
#define BSA_ENABLE(AXIS) do{ switch (AXIS) { case X_AXIS: enable_X(); break; case Y_AXIS: enable_Y(); break; case Z_AXIS: enable_Z(); break; default: break; } }while(0)
#define BSA_ENABLE(AXIS) do{ switch (AXIS) { case X_AXIS: ENABLE_AXIS_X(); break; case Y_AXIS: ENABLE_AXIS_Y(); break; case Z_AXIS: ENABLE_AXIS_Z(); break; default: break; } }while(0)
#else
#define BSA_ENABLE(AXIS) NOOP
#endif
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/feature/prusa_MMU2/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void MMU2::tool_change(uint8_t index) {

if (index != extruder) {

disable_E0();
DISABLE_AXIS_E0();
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));

command(MMU_CMD_T0 + index);
Expand All @@ -459,7 +459,7 @@ void MMU2::tool_change(uint8_t index) {
extruder = index; //filament change is finished
active_extruder = 0;

enable_E0();
ENABLE_AXIS_E0();

SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(extruder));
Expand Down Expand Up @@ -497,13 +497,13 @@ void MMU2::tool_change(const char* special) {
case 'x': {
planner.synchronize();
uint8_t index = mmu2_choose_filament();
disable_E0();
DISABLE_AXIS_E0();
command(MMU_CMD_T0 + index);
manage_response(true, true);
command(MMU_CMD_C0);
mmu_loop();

enable_E0();
ENABLE_AXIS_E0();
extruder = index;
active_extruder = 0;
} break;
Expand Down Expand Up @@ -697,7 +697,7 @@ void MMU2::filament_runout() {

LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);

enable_E0();
ENABLE_AXIS_E0();
current_position.e -= MMU2_FILAMENTCHANGE_EJECT_FEED;
line_to_current_position(2500 / 60);
planner.synchronize();
Expand Down Expand Up @@ -731,7 +731,7 @@ void MMU2::filament_runout() {

BUZZ(200, 404);

disable_E0();
DISABLE_AXIS_E0();

return true;
}
Expand Down Expand Up @@ -776,7 +776,7 @@ void MMU2::filament_runout() {
void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {

planner.synchronize();
enable_E0();
ENABLE_AXIS_E0();

const E_Step* step = sequence;

Expand All @@ -794,7 +794,7 @@ void MMU2::filament_runout() {
step++;
}

disable_E0();
DISABLE_AXIS_E0();
}

#endif // HAS_LCD_MENU && MMU2_MENUS
Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ void GcodeSuite::G33() {
_opposite_results = (_4p_calibration && !towers_set) || probe_points >= 3,
_endstop_results = probe_points != 1 && probe_points != -1 && probe_points != 0,
_angle_results = probe_points >= 3 && towers_set;
static const char save_message[] PROGMEM = "Save with M500 and/or copy to Configuration.h";
int8_t iterations = 0;
float test_precision,
zero_std_dev = (verbose_level ? 999.0f : 0.0f), // 0.0 in dry-run mode : forced end
Expand Down Expand Up @@ -625,8 +624,7 @@ void GcodeSuite::G33() {
sprintf_P(&mess[15], PSTR("%03i.x"), (int)LROUND(zero_std_dev_min));
ui.set_status(mess);
print_calibration_settings(_endstop_results, _angle_results);
serialprintPGM(save_message);
SERIAL_EOL();
SERIAL_ECHOLNPGM("Save with M500 and/or copy to Configuration.h");
}
else { // !end iterations
char mess[15];
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/gcode/control/M17_M18_M84.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
*/
void GcodeSuite::M17() {
if (parser.seen("XYZE")) {
if (parser.seen('X')) enable_X();
if (parser.seen('Y')) enable_Y();
if (parser.seen('Z')) enable_Z();
if (parser.seen('X')) ENABLE_AXIS_X();
if (parser.seen('Y')) ENABLE_AXIS_Y();
if (parser.seen('Z')) ENABLE_AXIS_Z();
#if HAS_E_STEPPER_ENABLE
if (parser.seen('E')) enable_e_steppers();
#endif
Expand All @@ -57,9 +57,9 @@ void GcodeSuite::M18_M84() {
else {
if (parser.seen("XYZE")) {
planner.synchronize();
if (parser.seen('X')) disable_X();
if (parser.seen('Y')) disable_Y();
if (parser.seen('Z')) disable_Z();
if (parser.seen('X')) DISABLE_AXIS_X();
if (parser.seen('Y')) DISABLE_AXIS_Y();
if (parser.seen('Z')) DISABLE_AXIS_Z();
#if HAS_E_STEPPER_ENABLE
if (parser.seen('E')) disable_e_steppers();
#endif
Expand Down
104 changes: 49 additions & 55 deletions Marlin/src/libs/L64XX/L64XX_Marlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,40 @@ L64XX_Marlin L64xxManager;

void echo_yes_no(const bool yes) { serialprintPGM(yes ? PSTR(" YES") : PSTR(" NO ")); }

char L64XX_Marlin::index_to_axis[MAX_L64XX][3] = { "X ", "Y ", "Z ", "X2", "Y2", "Z2", "Z3", "Z4", "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7" };
static const char str_X[] PROGMEM = "X ", str_Y[] PROGMEM = "Y ", str_Z[] PROGMEM = "Z ",
str_X2[] PROGMEM = "X2", str_Y2[] PROGMEM = "Y2",
str_Z2[] PROGMEM = "Z2", str_Z3[] PROGMEM = "Z3", str_Z4[] PROGMEM = "Z4",
str_E0[] PROGMEM = "E0", str_E1[] PROGMEM = "E1",
str_E2[] PROGMEM = "E2", str_E3[] PROGMEM = "E3",
str_E4[] PROGMEM = "E4", str_E5[] PROGMEM = "E5",
str_E6[] PROGMEM = "E6", str_E7[] PROGMEM = "E7"
;

PGM_P const L64XX_Marlin::index_to_axis[] PROGMEM = {
str_X, str_Y, str_Z, str_X2, str_Y2, str_Z2, str_Z3, str_Z4,
str_E0, str_E1, str_E2, str_E3, str_E4, str_E5, str_E6, str_E7
};

#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
#include "../../core/debug_out.h"

uint8_t L64XX_Marlin::dir_commands[MAX_L64XX]; // array to hold direction command for each driver

uint8_t L64XX_Marlin::index_to_dir[MAX_L64XX] = { (INVERT_X_DIR), // 0 X
(INVERT_Y_DIR), // 1 Y
(INVERT_Z_DIR), // 2 Z
#if ENABLED(X_DUAL_STEPPER_DRIVERS) // 3 X2
(INVERT_X_DIR) ^ (INVERT_X2_VS_X_DIR),
#else
(INVERT_X_DIR),
#endif
#if ENABLED(Y_DUAL_STEPPER_DRIVERS) // 4 Y2
(INVERT_Y_DIR) ^ (INVERT_Y2_VS_Y_DIR),
#else
(INVERT_Y_DIR),
#endif
(INVERT_Z_DIR), // 5 Z2
(INVERT_Z_DIR), // 6 Z3
(INVERT_Z_DIR), // 7 Z4

(INVERT_E0_DIR), // 8 E0
(INVERT_E1_DIR), // 9 E1
(INVERT_E2_DIR), // 10 E2
(INVERT_E3_DIR), // 11 E3
(INVERT_E4_DIR), // 12 E4
(INVERT_E5_DIR), // 13 E5
(INVERT_E6_DIR), // 14 E6
(INVERT_E7_DIR) // 15 E7
};
const uint8_t L64XX_Marlin::index_to_dir[MAX_L64XX] = {
INVERT_X_DIR, INVERT_Y_DIR, INVERT_Z_DIR
, (INVERT_X_DIR) // X2
#if ENABLED(X_DUAL_STEPPER_DRIVERS)
^ (INVERT_X2_VS_X_DIR)
#endif
, (INVERT_Y_DIR) // Y2
#if ENABLED(Y_DUAL_STEPPER_DRIVERS)
^ (INVERT_Y2_VS_Y_DIR)
#endif
, INVERT_Z_DIR, INVERT_Z_DIR, INVERT_Z_DIR // Z2,Z3,Z4

, INVERT_E0_DIR, INVERT_E1_DIR, INVERT_E2_DIR, INVERT_E3_DIR
, INVERT_E4_DIR, INVERT_E5_DIR, INVERT_E6_DIR, INVERT_E7_DIR
};

volatile uint8_t L64XX_Marlin::spi_abort = false;
uint8_t L64XX_Marlin::spi_active = false;
Expand Down Expand Up @@ -379,35 +380,27 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in
found_displacement = true;
displacement = _displacement;
uint8_t axis_offset = parser.byteval('J');
axis_mon[0][0] = axis_codes[i]; // axis ASCII value (target character)
axis_mon[0][0] = axis_codes[i]; // Axis first character, one of XYZE
const bool single_or_e = axis_offset >= 2 || axis_mon[0][0] == 'E',
one_or_more = !single_or_e && axis_offset == 0;
uint8_t driver_count_local = 0; // Can't use "driver_count" directly as a subscript because it's passed by reference
if (axis_offset >= 2 || axis_mon[0][0] == 'E') { // Single axis, E0, or E1
axis_mon[0][1] = axis_offset + '0';
for (j = 0; j < MAX_L64XX; j++) { // See how many drivers on this axis
const char * const str = index_to_axis[j];
if (axis_mon[0][0] == str[0]) {
char * const mon = axis_mon[driver_count_local];
mon[0] = str[0];
mon[1] = str[1];
mon[2] = str[2]; // append end of string
axis_index[driver_count_local] = (L64XX_axis_t)j; // set axis index
driver_count_local++;
}
}
}
else if (axis_offset == 0) { // One or more axes
for (j = 0; j < MAX_L64XX; j++) { // See how many drivers on this axis
const char * const str = index_to_axis[j];
if (axis_mon[0][0] == str[0]) {
char * const mon = axis_mon[driver_count_local];
mon[0] = str[0];
mon[1] = str[1];
mon[2] = str[2]; // append end of string
axis_index[driver_count_local] = (L64XX_axis_t)j; // set axis index
if (single_or_e) // Single axis, E0, or E1
axis_mon[0][1] = axis_offset + '0'; // Index given by 'J' parameter

if (single_or_e || one_or_more) {
for (j = 0; j < MAX_L64XX; j++) { // Count up the drivers on this axis
PGM_P str = (PGM_P)pgm_read_ptr(&index_to_axis[j]); // Get a PGM_P from progmem
const char c = pgm_read_byte(str); // Get a char from progmem
if (axis_mon[0][0] == c) { // For each stepper on this axis...
char *mon = axis_mon[driver_count_local];
*mon++ = c; // Copy the 3 letter axis name
*mon++ = pgm_read_byte(&str[1]); // to the axis_mon array
*mon = pgm_read_byte(&str[2]);
axis_index[driver_count_local] = (L64XX_axis_t)j; // And store the L64XX axis index
driver_count_local++;
}
}
driver_count = driver_count_local;
if (one_or_more) driver_count = driver_count_local;
}
break; // only take first axis found
}
Expand Down Expand Up @@ -494,8 +487,8 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in
for (uint8_t k = 0; k < driver_count; k++) {
uint8_t not_found = true;
for (j = 1; j <= L64XX::chain[0]; j++) {
const char * const ind_axis = index_to_axis[L64XX::chain[j]];
if (ind_axis[0] == axis_mon[k][0] && ind_axis[1] == axis_mon[k][1]) { // See if a L6470 driver
PGM_P const str = (PGM_P)pgm_read_ptr(&index_to_axis[L64XX::chain[j]]);
if (pgm_read_byte(&str[0]) == axis_mon[k][0] && pgm_read_byte(&str[1]) == axis_mon[k][1]) { // See if a L6470 driver
not_found = false;
break;
}
Expand Down Expand Up @@ -724,7 +717,8 @@ void L64XX_Marlin::say_axis(const L64XX_axis_t axis, const uint8_t label/*=true*
};

void L64XX_Marlin::append_stepper_err(char* &p, const uint8_t stepper_index, const char * const err/*=nullptr*/) {
p += sprintf_P(p, PSTR("Stepper %c%c "), index_to_axis[stepper_index][0], index_to_axis[stepper_index][1]);
PGM_P const str = (PGM_P)pgm_read_ptr(&index_to_axis[stepper_index]);
p += sprintf_P(p, PSTR("Stepper %c%c "), pgm_read_byte(&str[0]), pgm_read_byte(&str[1]));
if (err) p += sprintf_P(p, err);
}

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/libs/L64XX/L64XX_Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ enum L64XX_axis_t : uint8_t { X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E

class L64XX_Marlin : public L64XXHelper {
public:
static char index_to_axis[MAX_L64XX][3];
static PGM_P const index_to_axis[MAX_L64XX];

static const uint8_t index_to_dir[MAX_L64XX];

static uint8_t index_to_dir[MAX_L64XX];
static uint8_t dir_commands[MAX_L64XX];

// Flags to guarantee graceful switch if stepper interrupts L6470 SPI transfer
Expand Down Expand Up @@ -69,7 +70,6 @@ class L64XX_Marlin : public L64XXHelper {

static void transfer(uint8_t L6470_buf[], const uint8_t length);

//static char* index_to_axis(const uint8_t index);
static void say_axis(const L64XX_axis_t axis, const uint8_t label=true);
#if ENABLED(L6470_CHITCHAT)
static void error_status_decode(
Expand Down
Loading