Digipots refactor / cleanup (#19690)

This commit is contained in:
Scott Lahteine
2020-10-11 14:58:35 -05:00
committed by GitHub
parent 349465b168
commit 492ba2a111
23 changed files with 240 additions and 187 deletions

View File

@ -36,7 +36,7 @@
*/
// Change EEPROM version if the structure changes
#define EEPROM_VERSION "V81"
#define EEPROM_VERSION "V82"
#define EEPROM_OFFSET 100
// Check the integrity of data offsets.
@ -365,7 +365,10 @@ typedef struct SettingsDataStruct {
//
// HAS_MOTOR_CURRENT_PWM
//
uint32_t motor_current_setting[3]; // M907 X Z E
#ifndef MOTOR_CURRENT_COUNT
#define MOTOR_CURRENT_COUNT 3
#endif
uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // M907 X Z E
//
// CNC_COORDINATE_SYSTEMS
@ -1277,10 +1280,10 @@ void MarlinSettings::postprocess() {
{
_FIELD_TEST(motor_current_setting);
#if HAS_MOTOR_CURRENT_PWM
#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
EEPROM_WRITE(stepper.motor_current_setting);
#else
const uint32_t no_current[3] = { 0 };
const uint32_t no_current[MOTOR_CURRENT_COUNT] = { 0 };
EEPROM_WRITE(no_current);
#endif
}
@ -2110,10 +2113,16 @@ void MarlinSettings::postprocess() {
// Motor Current PWM
//
{
uint32_t motor_current_setting[3];
_FIELD_TEST(motor_current_setting);
uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]
#if HAS_MOTOR_CURRENT_SPI
= DIGIPOT_MOTOR_CURRENT
#endif
;
DEBUG_ECHOLNPGM("DIGIPOTS Loading");
EEPROM_READ(motor_current_setting);
#if HAS_MOTOR_CURRENT_PWM
DEBUG_ECHOLNPGM("DIGIPOTS Loaded");
#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
if (!validating)
COPY(stepper.motor_current_setting, motor_current_setting);
#endif
@ -2791,9 +2800,20 @@ void MarlinSettings::reset() {
//
#if HAS_MOTOR_CURRENT_PWM
constexpr uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT;
LOOP_L_N(q, 3)
stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
constexpr uint32_t tmp_motor_current_setting[MOTOR_CURRENT_COUNT] = PWM_MOTOR_CURRENT;
LOOP_L_N(q, MOTOR_CURRENT_COUNT)
stepper.set_digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
#endif
//
// DIGIPOTS
//
#if HAS_MOTOR_CURRENT_SPI
static constexpr uint32_t tmp_motor_current_setting[] = DIGIPOT_MOTOR_CURRENT;
DEBUG_ECHOLNPGM("Writing Digipot");
LOOP_L_N(q, COUNT(tmp_motor_current_setting))
stepper.set_digipot_current(q, tmp_motor_current_setting[q]);
DEBUG_ECHOLNPGM("Digipot Written");
#endif
//
@ -3695,14 +3715,23 @@ void MarlinSettings::reset() {
#endif
#endif
#if HAS_MOTOR_CURRENT_PWM
#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
CONFIG_ECHO_HEADING("Stepper motor currents:");
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR_P(
PSTR(" M907 X"), stepper.motor_current_setting[0]
, SP_Z_STR, stepper.motor_current_setting[1]
, SP_E_STR, stepper.motor_current_setting[2]
);
#if HAS_MOTOR_CURRENT_PWM
SERIAL_ECHOLNPAIR_P(
PSTR(" M907 X"), stepper.motor_current_setting[0]
, SP_Z_STR, stepper.motor_current_setting[1]
, SP_E_STR, stepper.motor_current_setting[2]
);
#elif HAS_MOTOR_CURRENT_SPI
SERIAL_ECHOPGM(" M907");
LOOP_L_N(q, MOTOR_CURRENT_COUNT) {
SERIAL_CHAR(' ');
SERIAL_CHAR(axis_codes[q]);
SERIAL_ECHO(stepper.motor_current_setting[q]);
}
#endif
#endif
/**