From b10b3db4f8f135a9bd013cfd5833663755fb3fec Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Mon, 3 Dec 2012 18:16:34 +0100 Subject: [PATCH] Wrap EEPROM storage related stuff in #ifdef EECONFIG. Saves a whopping 600 bytes. Let's cross fingers stuff still works. It should, using the hardcoded default values. --- gcode_process.c | 2 ++ heater.c | 52 +++++++++++++++++++++++++++++-------------------- heater.h | 4 +++- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/gcode_process.c b/gcode_process.c index f55961e..fb4362e 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -632,6 +632,7 @@ void process_gcode_command() { enqueue(NULL); break; + #ifdef EECONFIG case 130: //? --- M130: heater P factor --- //? Undocumented. @@ -682,6 +683,7 @@ void process_gcode_command() { //? Undocumented. heater_save_settings(); break; + #endif /* EECONFIG */ #ifdef DEBUG case 136: diff --git a/heater.c b/heater.c index 199aaed..ab1a911 100644 --- a/heater.c +++ b/heater.c @@ -85,6 +85,7 @@ struct { /// default scaled I limit #define DEFAULT_I_LIMIT 384 +#ifdef EECONFIG /// this lives in the eeprom so we can save our PID settings for each heater typedef struct { int32_t EE_p_factor; @@ -95,6 +96,7 @@ typedef struct { } EE_factor; EE_factor EEMEM EE_factors[NUM_HEATERS]; +#endif /* EECONFIG */ /// \brief initialise heater subsystem /// Set directions, initialise PWM timers, read PID factors from eeprom, etc @@ -243,14 +245,20 @@ void heater_init() { #endif #ifndef BANG_BANG - // read factors from eeprom - heaters_pid[i].p_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_p_factor); - heaters_pid[i].i_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_i_factor); - heaters_pid[i].d_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_d_factor); - heaters_pid[i].i_limit = eeprom_read_word((uint16_t *) &EE_factors[i].EE_i_limit); + #ifdef EECONFIG + // read factors from eeprom + heaters_pid[i].p_factor = + eeprom_read_dword((uint32_t *) &EE_factors[i].EE_p_factor); + heaters_pid[i].i_factor = + eeprom_read_dword((uint32_t *) &EE_factors[i].EE_i_factor); + heaters_pid[i].d_factor = + eeprom_read_dword((uint32_t *) &EE_factors[i].EE_d_factor); + heaters_pid[i].i_limit = + eeprom_read_word((uint16_t *) &EE_factors[i].EE_i_limit); -// if ((heaters_pid[i].p_factor == 0) && (heaters_pid[i].i_factor == 0) && (heaters_pid[i].d_factor == 0) && (heaters_pid[i].i_limit == 0)) { - if (crc_block(&heaters_pid[i].p_factor, 14) != eeprom_read_word((uint16_t *) &EE_factors[i].crc)) { + if (crc_block(&heaters_pid[i].p_factor, 14) != eeprom_read_word((uint16_t *) &EE_factors[i].crc)) + #endif /* EECONFIG */ + { heaters_pid[i].p_factor = DEFAULT_P; heaters_pid[i].i_factor = DEFAULT_I; heaters_pid[i].d_factor = DEFAULT_D; @@ -268,20 +276,6 @@ void heater_init() { } while (0); } -/// \brief Write PID factors to eeprom -void heater_save_settings() { - #ifndef BANG_BANG - heater_t i; - for (i = 0; i < NUM_HEATERS; i++) { - eeprom_write_dword((uint32_t *) &EE_factors[i].EE_p_factor, heaters_pid[i].p_factor); - eeprom_write_dword((uint32_t *) &EE_factors[i].EE_i_factor, heaters_pid[i].i_factor); - eeprom_write_dword((uint32_t *) &EE_factors[i].EE_d_factor, heaters_pid[i].d_factor); - eeprom_write_word((uint16_t *) &EE_factors[i].EE_i_limit, heaters_pid[i].i_limit); - eeprom_write_word((uint16_t *) &EE_factors[i].crc, crc_block(&heaters_pid[i].p_factor, 14)); - } - #endif /* BANG_BANG */ -} - /** \brief run heater PID algorithm \param h which heater we're running the loop for \param type which temp sensor type this heater is attached to @@ -468,6 +462,7 @@ uint8_t heaters_all_off() { return 255; } +#ifdef EECONFIG /** \brief set heater P factor \param index heater to change factor for \param p scaled P factor @@ -520,6 +515,21 @@ void pid_set_i_limit(heater_t index, int32_t i_limit) { #endif /* BANG_BANG */ } +/// \brief Write PID factors to eeprom +void heater_save_settings() { + #ifndef BANG_BANG + heater_t i; + for (i = 0; i < NUM_HEATERS; i++) { + eeprom_write_dword((uint32_t *) &EE_factors[i].EE_p_factor, heaters_pid[i].p_factor); + eeprom_write_dword((uint32_t *) &EE_factors[i].EE_i_factor, heaters_pid[i].i_factor); + eeprom_write_dword((uint32_t *) &EE_factors[i].EE_d_factor, heaters_pid[i].d_factor); + eeprom_write_word((uint16_t *) &EE_factors[i].EE_i_limit, heaters_pid[i].i_limit); + eeprom_write_word((uint16_t *) &EE_factors[i].crc, crc_block(&heaters_pid[i].p_factor, 14)); + } + #endif /* BANG_BANG */ +} +#endif /* EECONFIG */ + #ifndef EXTRUDER /** \brief send heater debug info to host \param i index of heater to send info for diff --git a/heater.h b/heater.h index c43c26e..5b9c181 100644 --- a/heater.h +++ b/heater.h @@ -16,7 +16,6 @@ typedef enum #undef DEFINE_HEATER void heater_init(void); -void heater_save_settings(void); void heater_set(heater_t index, uint8_t value); void heater_tick(heater_t h, temp_type_t type, uint16_t current_temp, uint16_t target_temp); @@ -24,10 +23,13 @@ void heater_tick(heater_t h, temp_type_t type, uint16_t current_temp, uint16_t t uint8_t heaters_all_zero(void); uint8_t heaters_all_off(void); +#ifdef EECONFIG void pid_set_p(heater_t index, int32_t p); void pid_set_i(heater_t index, int32_t i); void pid_set_d(heater_t index, int32_t d); void pid_set_i_limit(heater_t index, int32_t i_limit); +void heater_save_settings(void); +#endif /* EECONFIG */ void heater_print(uint16_t i);