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.
This commit is contained in:
Markus Hitter 2012-12-03 18:16:34 +01:00
parent d51ec02cdf
commit b10b3db4f8
3 changed files with 36 additions and 22 deletions

View File

@ -632,6 +632,7 @@ void process_gcode_command() {
enqueue(NULL); enqueue(NULL);
break; break;
#ifdef EECONFIG
case 130: case 130:
//? --- M130: heater P factor --- //? --- M130: heater P factor ---
//? Undocumented. //? Undocumented.
@ -682,6 +683,7 @@ void process_gcode_command() {
//? Undocumented. //? Undocumented.
heater_save_settings(); heater_save_settings();
break; break;
#endif /* EECONFIG */
#ifdef DEBUG #ifdef DEBUG
case 136: case 136:

View File

@ -85,6 +85,7 @@ struct {
/// default scaled I limit /// default scaled I limit
#define DEFAULT_I_LIMIT 384 #define DEFAULT_I_LIMIT 384
#ifdef EECONFIG
/// this lives in the eeprom so we can save our PID settings for each heater /// this lives in the eeprom so we can save our PID settings for each heater
typedef struct { typedef struct {
int32_t EE_p_factor; int32_t EE_p_factor;
@ -95,6 +96,7 @@ typedef struct {
} EE_factor; } EE_factor;
EE_factor EEMEM EE_factors[NUM_HEATERS]; EE_factor EEMEM EE_factors[NUM_HEATERS];
#endif /* EECONFIG */
/// \brief initialise heater subsystem /// \brief initialise heater subsystem
/// Set directions, initialise PWM timers, read PID factors from eeprom, etc /// Set directions, initialise PWM timers, read PID factors from eeprom, etc
@ -243,14 +245,20 @@ void heater_init() {
#endif #endif
#ifndef BANG_BANG #ifndef BANG_BANG
// read factors from eeprom #ifdef EECONFIG
heaters_pid[i].p_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_p_factor); // read factors from eeprom
heaters_pid[i].i_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_i_factor); heaters_pid[i].p_factor =
heaters_pid[i].d_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_d_factor); eeprom_read_dword((uint32_t *) &EE_factors[i].EE_p_factor);
heaters_pid[i].i_limit = eeprom_read_word((uint16_t *) &EE_factors[i].EE_i_limit); 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].p_factor = DEFAULT_P;
heaters_pid[i].i_factor = DEFAULT_I; heaters_pid[i].i_factor = DEFAULT_I;
heaters_pid[i].d_factor = DEFAULT_D; heaters_pid[i].d_factor = DEFAULT_D;
@ -268,20 +276,6 @@ void heater_init() {
} while (0); } 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 /** \brief run heater PID algorithm
\param h which heater we're running the loop for \param h which heater we're running the loop for
\param type which temp sensor type this heater is attached to \param type which temp sensor type this heater is attached to
@ -468,6 +462,7 @@ uint8_t heaters_all_off() {
return 255; return 255;
} }
#ifdef EECONFIG
/** \brief set heater P factor /** \brief set heater P factor
\param index heater to change factor for \param index heater to change factor for
\param p scaled P factor \param p scaled P factor
@ -520,6 +515,21 @@ void pid_set_i_limit(heater_t index, int32_t i_limit) {
#endif /* BANG_BANG */ #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 #ifndef EXTRUDER
/** \brief send heater debug info to host /** \brief send heater debug info to host
\param i index of heater to send info for \param i index of heater to send info for

View File

@ -16,7 +16,6 @@ typedef enum
#undef DEFINE_HEATER #undef DEFINE_HEATER
void heater_init(void); void heater_init(void);
void heater_save_settings(void);
void heater_set(heater_t index, uint8_t value); 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); 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_zero(void);
uint8_t heaters_all_off(void); uint8_t heaters_all_off(void);
#ifdef EECONFIG
void pid_set_p(heater_t index, int32_t p); void pid_set_p(heater_t index, int32_t p);
void pid_set_i(heater_t index, int32_t i); void pid_set_i(heater_t index, int32_t i);
void pid_set_d(heater_t index, int32_t d); void pid_set_d(heater_t index, int32_t d);
void pid_set_i_limit(heater_t index, int32_t i_limit); 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); void heater_print(uint16_t i);