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

This commit is contained in:
Scott Lahteine
2022-04-03 16:14:02 -05:00
committed by GitHub
parent 7ce4a7f641
commit c4873a64ec
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 NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stepper_current_t;
typedef struct { uint32_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_hybrid_threshold_t;
typedef struct { int16_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4; } tmc_sgt_t;
typedef struct { bool NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stealth_enabled_t;
typedef struct { uint16_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint16_t;
typedef struct { uint32_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint32_t;
typedef struct { int16_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4; } mot_stepper_int16_t;
typedef struct { bool NUM_AXIS_LIST(X:1, Y:1, Z:1, I:1, J:1, K:1, U:1, V:1, W: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 X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
tmc_sgt_t tmc_sgt; // M914 X Y Z X2 Y2 Z2 Z3 Z4
tmc_stealth_enabled_t tmc_stealth_enabled; // M569 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
per_stepper_uint16_t tmc_stepper_current; // M906 X Y Z I J K U V W X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
per_stepper_uint32_t tmc_hybrid_threshold; // M913 X Y Z I J K U V W X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
mot_stepper_int16_t tmc_sgt; // M914 X Y Z I J K U V W X2 Y2 Z2 Z3 Z4
per_stepper_bool_t tmc_stealth_enabled; // M569 X Y Z I J K U V W X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
//
// LIN_ADVANCE
@@ -1220,7 +1221,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)
@@ -1300,7 +1301,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());
@@ -1325,7 +1326,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 = {
NUM_AXIS_LIST(.X = 100, .Y = 100, .Z = 3, .I = 3, .J = 3, .K = 3, .U = 3, .V = 3, .W = 3),
.X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3, .Z4 = 3
REPEAT(E_STEPPERS, _EN_ITEM)
@@ -1339,7 +1340,7 @@ void MarlinSettings::postprocess() {
// TMC StallGuard threshold
//
{
tmc_sgt_t tmc_sgt{0};
mot_stepper_int16_t tmc_sgt{0};
#if USE_SENSORLESS
NUM_AXIS_CODE(
TERN_(X_SENSORLESS, tmc_sgt.X = stepperX.homing_threshold()),
@@ -1367,7 +1368,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());
@@ -2168,7 +2169,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
@@ -2247,7 +2248,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);
@@ -2283,7 +2284,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
@@ -2312,7 +2313,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