🧑‍💻 General and Axis-based bitfield flags (#23989)

This commit is contained in:
Scott Lahteine
2022-04-03 16:14:02 -05:00
committed by Scott Lahteine
parent d5f472a6cf
commit d235bc9e1c
14 changed files with 106 additions and 51 deletions

View File

@ -178,11 +178,12 @@
#endif
#define _EN_ITEM(N) , E##N
#define _EN1_ITEM(N) , E##N:1
typedef struct { uint16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stepper_current_t;
typedef struct { uint32_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_hybrid_threshold_t;
typedef struct { int16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4; } tmc_sgt_t;
typedef struct { bool LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stealth_enabled_t;
typedef struct { uint16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint16_t;
typedef struct { uint32_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint32_t;
typedef struct { int16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4; } mot_stepper_int16_t;
typedef struct { bool LINEAR_AXIS_LIST(X:1, Y:1, Z:1, I:1, J:1, K:1), X2:1, Y2:1, Z2:1, Z3:1, Z4:1 REPEAT(E_STEPPERS, _EN1_ITEM); } per_stepper_bool_t;
#undef _EN_ITEM
@ -430,10 +431,10 @@ typedef struct SettingsDataStruct {
//
// HAS_TRINAMIC_CONFIG
//
tmc_stepper_current_t tmc_stepper_current; // M906 X Y Z...
tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z...
tmc_sgt_t tmc_sgt; // M914 X Y Z...
tmc_stealth_enabled_t tmc_stealth_enabled; // M569 X Y Z...
per_stepper_uint16_t tmc_stepper_current; // M906 X Y Z...
per_stepper_uint32_t tmc_hybrid_threshold; // M913 X Y Z...
mot_stepper_int16_t tmc_sgt; // M914 X Y Z...
per_stepper_bool_t tmc_stealth_enabled; // M569 X Y Z...
//
// LIN_ADVANCE
@ -1213,7 +1214,7 @@ void MarlinSettings::postprocess() {
{
_FIELD_TEST(tmc_stepper_current);
tmc_stepper_current_t tmc_stepper_current{0};
per_stepper_uint16_t tmc_stepper_current{0};
#if HAS_TRINAMIC_CONFIG
#if AXIS_IS_TMC(X)
@ -1284,7 +1285,7 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(tmc_hybrid_threshold);
#if ENABLED(HYBRID_THRESHOLD)
tmc_hybrid_threshold_t tmc_hybrid_threshold{0};
per_stepper_uint32_t tmc_hybrid_threshold{0};
TERN_(X_HAS_STEALTHCHOP, tmc_hybrid_threshold.X = stepperX.get_pwm_thrs());
TERN_(Y_HAS_STEALTHCHOP, tmc_hybrid_threshold.Y = stepperY.get_pwm_thrs());
TERN_(Z_HAS_STEALTHCHOP, tmc_hybrid_threshold.Z = stepperZ.get_pwm_thrs());
@ -1306,7 +1307,7 @@ void MarlinSettings::postprocess() {
TERN_(E7_HAS_STEALTHCHOP, tmc_hybrid_threshold.E7 = stepperE7.get_pwm_thrs());
#else
#define _EN_ITEM(N) , .E##N = 30
const tmc_hybrid_threshold_t tmc_hybrid_threshold = {
const per_stepper_uint32_t tmc_hybrid_threshold = {
LINEAR_AXIS_LIST(.X = 100, .Y = 100, .Z = 3, .I = 3, .J = 3, .K = 3),
.X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3, .Z4 = 3
REPEAT(E_STEPPERS, _EN_ITEM)
@ -1320,7 +1321,7 @@ void MarlinSettings::postprocess() {
// TMC StallGuard threshold
//
{
tmc_sgt_t tmc_sgt{0};
mot_stepper_int16_t tmc_sgt{0};
#if USE_SENSORLESS
LINEAR_AXIS_CODE(
TERN_(X_SENSORLESS, tmc_sgt.X = stepperX.homing_threshold()),
@ -1345,7 +1346,7 @@ void MarlinSettings::postprocess() {
{
_FIELD_TEST(tmc_stealth_enabled);
tmc_stealth_enabled_t tmc_stealth_enabled = { false };
per_stepper_bool_t tmc_stealth_enabled = { false };
TERN_(X_HAS_STEALTHCHOP, tmc_stealth_enabled.X = stepperX.get_stored_stealthChop());
TERN_(Y_HAS_STEALTHCHOP, tmc_stealth_enabled.Y = stepperY.get_stored_stealthChop());
TERN_(Z_HAS_STEALTHCHOP, tmc_stealth_enabled.Z = stepperZ.get_stored_stealthChop());
@ -2135,7 +2136,7 @@ void MarlinSettings::postprocess() {
{
_FIELD_TEST(tmc_stepper_current);
tmc_stepper_current_t currents;
per_stepper_uint16_t currents;
EEPROM_READ(currents);
#if HAS_TRINAMIC_CONFIG
@ -2205,7 +2206,7 @@ void MarlinSettings::postprocess() {
// TMC Hybrid Threshold
{
tmc_hybrid_threshold_t tmc_hybrid_threshold;
per_stepper_uint32_t tmc_hybrid_threshold;
_FIELD_TEST(tmc_hybrid_threshold);
EEPROM_READ(tmc_hybrid_threshold);
@ -2238,7 +2239,7 @@ void MarlinSettings::postprocess() {
// TMC StallGuard threshold.
//
{
tmc_sgt_t tmc_sgt;
mot_stepper_int16_t tmc_sgt;
_FIELD_TEST(tmc_sgt);
EEPROM_READ(tmc_sgt);
#if USE_SENSORLESS
@ -2264,7 +2265,7 @@ void MarlinSettings::postprocess() {
{
_FIELD_TEST(tmc_stealth_enabled);
tmc_stealth_enabled_t tmc_stealth_enabled;
per_stepper_bool_t tmc_stealth_enabled;
EEPROM_READ(tmc_stealth_enabled);
#if HAS_TRINAMIC_CONFIG

View File

@ -153,7 +153,7 @@ Stepper stepper; // Singleton
#endif
#endif
axis_flags_t Stepper::axis_enabled; // {0}
stepper_flags_t Stepper::axis_enabled; // {0}
// private:

View File

@ -252,7 +252,7 @@ typedef struct {
};
constexpr ena_mask_t linear_bits() { return _BV(LINEAR_AXES) - 1; }
constexpr ena_mask_t e_bits() { return (_BV(EXTRUDERS) - 1) << LINEAR_AXES; }
} axis_flags_t;
} stepper_flags_t;
// All the stepper enable pins
constexpr pin_t ena_pins[] = {
@ -587,7 +587,7 @@ class Stepper {
static void refresh_motor_power();
#endif
static axis_flags_t axis_enabled; // Axis stepper(s) ENABLED states
static stepper_flags_t axis_enabled; // Axis stepper(s) ENABLED states
static bool axis_is_enabled(const AxisEnum axis E_OPTARG(const uint8_t eindex=0)) {
return TEST(axis_enabled.bits, INDEX_OF_AXIS(axis, eindex));

View File

@ -1092,7 +1092,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
static hotend_pid_t work_pid[HOTENDS];
static float temp_iState[HOTENDS] = { 0 },
temp_dState[HOTENDS] = { 0 };
static bool pid_reset[HOTENDS] = { false };
static Flags<HOTENDS> pid_reset;
const float pid_error = temp_hotend[ee].target - temp_hotend[ee].celsius;
float pid_output;
@ -1102,17 +1102,17 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
|| TERN0(HEATER_IDLE_HANDLER, heater_idle[ee].timed_out)
) {
pid_output = 0;
pid_reset[ee] = true;
pid_reset.set(ee);
}
else if (pid_error > PID_FUNCTIONAL_RANGE) {
pid_output = BANG_MAX;
pid_reset[ee] = true;
pid_reset.set(ee);
}
else {
if (pid_reset[ee]) {
temp_iState[ee] = 0.0;
work_pid[ee].Kd = 0.0;
pid_reset[ee] = false;
pid_reset.clear(ee);
}
work_pid[ee].Kd = work_pid[ee].Kd + PID_K2 * (PID_PARAM(Kd, ee) * (temp_dState[ee] - temp_hotend[ee].celsius) - work_pid[ee].Kd);

View File

@ -46,7 +46,7 @@
#endif
#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
bool toolchange_extruder_ready[EXTRUDERS];
Flags<EXTRUDERS> toolchange_extruder_ready;
#endif
#if EITHER(MAGNETIC_PARKING_EXTRUDER, TOOL_SENSOR) \
@ -1047,7 +1047,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
if (new_tool == old_tool && !first_tool_is_primed && enable_first_prime) {
tool_change_prime();
first_tool_is_primed = true;
TERN_(TOOLCHANGE_FS_INIT_BEFORE_SWAP, toolchange_extruder_ready[old_tool] = true); // Primed and initialized
TERN_(TOOLCHANGE_FS_INIT_BEFORE_SWAP, toolchange_extruder_ready.set(old_tool)); // Primed and initialized
}
#endif
@ -1196,7 +1196,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
if (!toolchange_extruder_ready[new_tool]) {
toolchange_extruder_ready[new_tool] = true;
toolchange_extruder_ready.set(new_tool);
fr = toolchange_settings.prime_speed; // Next move is a prime
unscaled_e_move(0, MMM_TO_MMS(fr)); // Init planner with 0 length move
}
@ -1381,7 +1381,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
// Migrate the retracted state
#if ENABLED(FWRETRACT)
fwretract.retracted[migration_extruder] = fwretract.retracted[active_extruder];
fwretract.retracted.set(migration_extruder, fwretract.retracted[active_extruder]);
#endif
// Migrate the temperature to the new hotend

View File

@ -50,7 +50,7 @@
#endif
#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
extern bool toolchange_extruder_ready[EXTRUDERS];
extern Flags<EXTRUDERS> toolchange_extruder_ready;
#endif
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)