parent
b551bdae76
commit
b317786110
|
|
@ -198,17 +198,6 @@ static const M500_conf default_conf PROGMEM =
|
|||
};
|
||||
|
||||
|
||||
static bool is_uninitialized(void* addr, uint8_t len)
|
||||
{
|
||||
while(len--)
|
||||
{
|
||||
if(reinterpret_cast<uint8_t*>(addr)[len] != 0xff)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! @brief Read M500 configuration
|
||||
//! @retval true Succeeded. Stored settings retrieved or default settings retrieved in case EEPROM cs was empty.
|
||||
//! @retval false Failed. Default settings has been retrieved, because of version mismatch
|
||||
|
|
@ -219,28 +208,24 @@ bool Config_RetrieveSettings()
|
|||
// SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << cs.version << "]");
|
||||
if (strncmp_P(ver, cs.version, sizeof(EEPROM_VERSION)) == 0) // version number match
|
||||
{
|
||||
// Initialize arc interpolation settings in eeprom if they are not already
|
||||
eeprom_init_default_float(&EEPROM_M500_base->mm_per_arc_segment, pgm_read_float(&default_conf.mm_per_arc_segment));
|
||||
eeprom_init_default_float(&EEPROM_M500_base->min_mm_per_arc_segment, pgm_read_float(&default_conf.min_mm_per_arc_segment));
|
||||
eeprom_init_default_byte(&EEPROM_M500_base->n_arc_correction, pgm_read_byte(&default_conf.n_arc_correction));
|
||||
eeprom_init_default_word(&EEPROM_M500_base->min_arc_segments, pgm_read_word(&default_conf.min_arc_segments));
|
||||
eeprom_init_default_word(&EEPROM_M500_base->arc_segments_per_sec, pgm_read_word(&default_conf.arc_segments_per_sec));
|
||||
|
||||
// Initialize the travel_acceleration in eeprom if not already
|
||||
eeprom_init_default_float(&EEPROM_M500_base->travel_acceleration, pgm_read_float(&default_conf.travel_acceleration));
|
||||
|
||||
// Initialize the max_feedrate_silent and max_acceleration_units_per_sq_second_silent in eeprom if not already
|
||||
eeprom_init_default_block(&EEPROM_M500_base->max_feedrate_silent, sizeof(EEPROM_M500_base->max_feedrate_silent), default_conf.max_feedrate_silent);
|
||||
eeprom_init_default_block(&EEPROM_M500_base->max_acceleration_units_per_sq_second_silent, sizeof(EEPROM_M500_base->max_acceleration_units_per_sq_second_silent), default_conf.max_acceleration_units_per_sq_second_silent);
|
||||
|
||||
// load the CS to RAM
|
||||
eeprom_read_block(reinterpret_cast<uint8_t*>(&cs), reinterpret_cast<uint8_t*>(EEPROM_M500_base), sizeof(cs));
|
||||
calculate_extruder_multipliers();
|
||||
|
||||
//if max_feedrate_silent and max_acceleration_units_per_sq_second_silent were never stored to eeprom, use default values:
|
||||
for (uint8_t i = 0; i < (sizeof(cs.max_feedrate_silent)/sizeof(cs.max_feedrate_silent[0])); ++i)
|
||||
{
|
||||
const uint32_t erased = 0xffffffff;
|
||||
if (is_uninitialized(&(cs.max_feedrate_silent[i]), sizeof(float))) {
|
||||
memcpy_P(&cs.max_feedrate_silent[i],&default_conf.max_feedrate_silent[i], sizeof(cs.max_feedrate_silent[i]));
|
||||
}
|
||||
if (erased == cs.max_acceleration_units_per_sq_second_silent[i]) {
|
||||
memcpy_P(&cs.max_acceleration_units_per_sq_second_silent[i],&default_conf.max_acceleration_units_per_sq_second_silent[i],sizeof(cs.max_acceleration_units_per_sq_second_silent[i]));
|
||||
}
|
||||
}
|
||||
// Initialize arc interpolation settings if they are not already
|
||||
if (is_uninitialized(&cs.mm_per_arc_segment, sizeof(cs.mm_per_arc_segment))) cs.mm_per_arc_segment = default_conf.mm_per_arc_segment;
|
||||
if (is_uninitialized(&cs.min_mm_per_arc_segment, sizeof(cs.min_mm_per_arc_segment))) cs.min_mm_per_arc_segment = default_conf.min_mm_per_arc_segment;
|
||||
if (is_uninitialized(&cs.n_arc_correction, sizeof(cs.n_arc_correction))) cs.n_arc_correction = default_conf.n_arc_correction;
|
||||
if (is_uninitialized(&cs.min_arc_segments, sizeof(cs.min_arc_segments))) cs.min_arc_segments = default_conf.min_arc_segments;
|
||||
if (is_uninitialized(&cs.arc_segments_per_sec, sizeof(cs.arc_segments_per_sec))) cs.arc_segments_per_sec = default_conf.arc_segments_per_sec;
|
||||
|
||||
|
||||
#ifdef TMC2130
|
||||
for (uint8_t j = X_AXIS; j <= Y_AXIS; j++)
|
||||
{
|
||||
|
|
@ -265,9 +250,6 @@ bool Config_RetrieveSettings()
|
|||
tmc2130_set_res(E_AXIS, cs.axis_ustep_resolution[E_AXIS]);
|
||||
#endif //TMC2130
|
||||
|
||||
if(is_uninitialized(&cs.travel_acceleration, sizeof(cs.travel_acceleration)))
|
||||
cs.travel_acceleration = cs.acceleration;
|
||||
|
||||
reset_acceleration_rates();
|
||||
|
||||
// Call updatePID (similar to when we have processed M301)
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ typedef struct
|
|||
// Arc Interpolation Settings, configurable via M214
|
||||
float mm_per_arc_segment;
|
||||
float min_mm_per_arc_segment;
|
||||
unsigned char n_arc_correction; // If equal to zero, this is disabled
|
||||
unsigned short min_arc_segments; // If equal to zero, this is disabled
|
||||
unsigned short arc_segments_per_sec; // If equal to zero, this is disabled
|
||||
uint8_t n_arc_correction; // If equal to zero, this is disabled
|
||||
uint16_t min_arc_segments; // If equal to zero, this is disabled
|
||||
uint16_t arc_segments_per_sec; // If equal to zero, this is disabled
|
||||
} M500_conf;
|
||||
|
||||
extern M500_conf cs;
|
||||
|
|
|
|||
|
|
@ -140,15 +140,23 @@ bool __attribute__((noinline)) eeprom_is_sheet_initialized(uint8_t sheet_num) {
|
|||
return (eeprom_read_word(reinterpret_cast<uint16_t*>(&(EEPROM_Sheets_base->s[sheet_num].z_offset))) != EEPROM_EMPTY_VALUE16);
|
||||
}
|
||||
|
||||
|
||||
bool __attribute__((noinline)) eeprom_is_initialized_block(const void *__p, size_t __n) {
|
||||
const uint8_t *top = (const uint8_t*)__p + __n;
|
||||
for (const uint8_t *p = (const uint8_t *)__p; p < top; p++) {
|
||||
if (eeprom_read_byte(p) != EEPROM_EMPTY_VALUE)
|
||||
const uint8_t *p = (const uint8_t*)__p;
|
||||
while (__n--) {
|
||||
if (eeprom_read_byte(p++) != EEPROM_EMPTY_VALUE)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void eeprom_update_block_P(const void *__src, void *__dst, size_t __n) {
|
||||
const uint8_t *src = (const uint8_t*)__src;
|
||||
uint8_t *dst = (uint8_t*)__dst;
|
||||
while (__n--) {
|
||||
eeprom_update_byte(dst++, pgm_read_byte(src++));
|
||||
}
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) eeprom_increment_byte(uint8_t *__p) {
|
||||
eeprom_write_byte(__p, eeprom_read_byte(__p) + 1);
|
||||
|
|
@ -191,7 +199,17 @@ void __attribute__((noinline)) eeprom_init_default_dword(uint32_t *__p, uint32_t
|
|||
eeprom_write_dword(__p, def);
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) eeprom_init_default_float(float *__p, float def) {
|
||||
if (eeprom_read_dword((uint32_t*)__p) == EEPROM_EMPTY_VALUE32)
|
||||
eeprom_write_float(__p, def);
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) eeprom_init_default_block(void *__p, size_t __n, const void *def) {
|
||||
if (!eeprom_is_initialized_block(__p, __n))
|
||||
eeprom_update_block(def, __p, __n);
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) eeprom_init_default_block_P(void *__p, size_t __n, const void *def) {
|
||||
if (!eeprom_is_initialized_block(__p, __n))
|
||||
eeprom_update_block_P(def, __p, __n);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -614,6 +614,7 @@ void eeprom_switch_to_next_sheet();
|
|||
bool eeprom_is_sheet_initialized(uint8_t sheet_num);
|
||||
|
||||
bool eeprom_is_initialized_block(const void *__p, size_t __n);
|
||||
void eeprom_update_block_P(const void *__src, void *__dst, size_t __n);
|
||||
|
||||
void eeprom_increment_byte(uint8_t *__p);
|
||||
void eeprom_increment_word(uint16_t *__p);
|
||||
|
|
@ -626,7 +627,9 @@ void eeprom_add_dword(uint32_t *__p, uint32_t add);
|
|||
void eeprom_init_default_byte(uint8_t *__p, uint8_t def);
|
||||
void eeprom_init_default_word(uint16_t *__p, uint16_t def);
|
||||
void eeprom_init_default_dword(uint32_t *__p, uint32_t def);
|
||||
void eeprom_init_default_float(float *__p, float def);
|
||||
void eeprom_init_default_block(void *__p, size_t __n, const void *def);
|
||||
void eeprom_init_default_block_P(void *__p, size_t __n, const void *def);
|
||||
#endif
|
||||
|
||||
#endif // EEPROM_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue