Skip to content

Commit

Permalink
Merge pull request #4466 from gudnimg/eeprom-optimisations
Browse files Browse the repository at this point in the history
Optimise EEPROM access in a few places by reading/writing larger blocks
  • Loading branch information
gudnimg authored Oct 27, 2023
2 parents e7f5611 + 3297429 commit 3b10c61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
52 changes: 18 additions & 34 deletions Firmware/mesh_bed_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,9 @@ static inline bool vec_undef(const float v[2])
*/
void world2machine_read_valid(float vec_x[2], float vec_y[2], float cntr[2])
{
vec_x[0] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_X +0));
vec_x[1] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_X +4));
vec_y[0] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y +0));
vec_y[1] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y +4));
cntr[0] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_CENTER+0));
cntr[1] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_CENTER+4));
eeprom_read_block(&vec_x[0], (float*)(EEPROM_BED_CALIBRATION_VEC_X), 8);
eeprom_read_block(&vec_y[0], (float*)(EEPROM_BED_CALIBRATION_VEC_Y), 8);
eeprom_read_block(&cntr[0], (float*)(EEPROM_BED_CALIBRATION_CENTER), 8);

bool reset = false;
if (vec_undef(cntr) || vec_undef(vec_x) || vec_undef(vec_y))
Expand Down Expand Up @@ -2444,15 +2441,12 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
if (result >= 0) {
DBG(_n("Calibration success.\n"));
world2machine_update(vec_x, vec_y, cntr);
#if 1

// Fearlessly store the calibration values into the eeprom.
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_CENTER + 0), cntr[0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_CENTER + 4), cntr[1]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_X + 0), vec_x[0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_X + 4), vec_x[1]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 0), vec_y[0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 4), vec_y[1]);
#endif
eeprom_update_block(&cntr[0], (float*)(EEPROM_BED_CALIBRATION_CENTER), 8);
eeprom_update_block(&vec_x[0], (float*)(EEPROM_BED_CALIBRATION_VEC_X), 8);
eeprom_update_block(&vec_y[0], (float*)(EEPROM_BED_CALIBRATION_VEC_Y), 8);

#ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) {
// Length of the vec_x
Expand Down Expand Up @@ -2735,15 +2729,11 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
}

world2machine_update(vec_x, vec_y, cntr);
#if 1

// Fearlessly store the calibration values into the eeprom.
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_CENTER+0), cntr [0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_CENTER+4), cntr [1]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_X +0), vec_x[0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_X +4), vec_x[1]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y +0), vec_y[0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y +4), vec_y[1]);
#endif
eeprom_update_block(&cntr[0], (float*)(EEPROM_BED_CALIBRATION_CENTER), 8);
eeprom_update_block(&vec_x[0], (float*)(EEPROM_BED_CALIBRATION_VEC_X), 8);
eeprom_update_block(&vec_y[0], (float*)(EEPROM_BED_CALIBRATION_VEC_Y), 8);

// Correct the current_position to match the transformed coordinate system after world2machine_rotation_and_skew and world2machine_shift were set.
world2machine_update_current();
Expand Down Expand Up @@ -3102,18 +3092,12 @@ void babystep_reset()
}

void count_xyz_details(float (&distanceMin)[2]) {
float cntr[2] = {
eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_CENTER + 0)),
eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_CENTER + 4))
};
float vec_x[2] = {
eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_X + 0)),
eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_X + 4))
};
float vec_y[2] = {
eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 0)),
eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 4))
};
float cntr[2];
float vec_x[2];
float vec_y[2];
eeprom_read_block(&cntr[0], (float*)(EEPROM_BED_CALIBRATION_CENTER), 8);
eeprom_read_block(&vec_x[0], (float*)(EEPROM_BED_CALIBRATION_VEC_X), 8);
eeprom_read_block(&vec_y[0], (float*)(EEPROM_BED_CALIBRATION_VEC_Y), 8);
#if 0
a2 = -1 * asin(vec_y[0] / MACHINE_AXIS_SCALE_Y);
a1 = asin(vec_x[1] / MACHINE_AXIS_SCALE_X);
Expand Down
6 changes: 2 additions & 4 deletions Firmware/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2417,8 +2417,7 @@ void thermal_model_load_settings()
thermal_model::data.C = eeprom_read_float((float*)EEPROM_THERMAL_MODEL_C);
thermal_model::data.fS = eeprom_read_float((float*)EEPROM_THERMAL_MODEL_D);
thermal_model_set_lag(eeprom_read_word((uint16_t*)EEPROM_THERMAL_MODEL_L));
for(uint8_t i = 0; i != THERMAL_MODEL_R_SIZE; ++i)
thermal_model::data.R[i] = eeprom_read_float((float*)EEPROM_THERMAL_MODEL_R + i);
eeprom_read_block(&thermal_model::data.R[0], (float*)EEPROM_THERMAL_MODEL_R, THERMAL_MODEL_R_SIZE * sizeof(float));
thermal_model::data.Ta_corr = eeprom_read_float((float*)EEPROM_THERMAL_MODEL_Ta_corr);
thermal_model::data.warn = eeprom_read_float((float*)EEPROM_THERMAL_MODEL_W);
thermal_model::data.err = eeprom_read_float((float*)EEPROM_THERMAL_MODEL_E);
Expand All @@ -2439,8 +2438,7 @@ void thermal_model_save_settings()
eeprom_update_float((float*)EEPROM_THERMAL_MODEL_C, thermal_model::data.C);
eeprom_update_float((float*)EEPROM_THERMAL_MODEL_D, thermal_model::data.fS);
eeprom_update_word((uint16_t*)EEPROM_THERMAL_MODEL_L, thermal_model::data.L);
for(uint8_t i = 0; i != THERMAL_MODEL_R_SIZE; ++i)
eeprom_update_float((float*)EEPROM_THERMAL_MODEL_R + i, thermal_model::data.R[i]);
eeprom_update_block(&thermal_model::data.R[0], (float*)EEPROM_THERMAL_MODEL_R, THERMAL_MODEL_R_SIZE * sizeof(float));
eeprom_update_float((float*)EEPROM_THERMAL_MODEL_Ta_corr, thermal_model::data.Ta_corr);
eeprom_update_float((float*)EEPROM_THERMAL_MODEL_W, thermal_model::data.warn);
eeprom_update_float((float*)EEPROM_THERMAL_MODEL_E, thermal_model::data.err);
Expand Down

0 comments on commit 3b10c61

Please sign in to comment.