diff --git a/attic/eeconfig/0001-preliminary-work-on-EEPROM-configuration-storage.patch b/attic/eeconfig/0001-preliminary-work-on-EEPROM-configuration-storage.patch new file mode 100644 index 0000000..63e6fca --- /dev/null +++ b/attic/eeconfig/0001-preliminary-work-on-EEPROM-configuration-storage.patch @@ -0,0 +1,344 @@ +From 555966f5dbd6d6fbdebea84c14bab1b2c88cc43e Mon Sep 17 00:00:00 2001 +From: Michael Moon +Date: Mon, 28 Mar 2011 00:28:01 +1100 +Subject: preliminary work on EEPROM configuration storage + +--- + eeconfig.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ + eeconfig.h | 45 +++++++++++++++++++++++++++++++++++++ + gcode_parse.c | 2 +- + gcode_parse.h | 4 ++-- + gcode_process.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + mendel.c | 4 ++++ + serial.c | 16 +++++++------ + temp.c | 8 ++++++- + 8 files changed, 192 insertions(+), 11 deletions(-) + create mode 100644 eeconfig.c + create mode 100644 eeconfig.h + +diff --git a/eeconfig.c b/eeconfig.c +new file mode 100644 +index 0000000..931866e +--- /dev/null ++++ b/eeconfig.c +@@ -0,0 +1,54 @@ ++#include "eeconfig.h" ++ ++#include ++ ++#include "crc.h" ++#include "config.h" ++#include "clock.h" ++ ++/// in-memory configuration data structure ++eeconfig_struct eeconfig; ++ ++/// in-eeprom configuration data structure ++eeconfig_struct EEMEM EE_config; ++ ++void eeconfig_init() { ++ uint16_t mycrc; ++ eeprom_read_block(&eeconfig, &EE_config, sizeof(eeconfig_struct)); ++ mycrc = crc_block(&eeconfig, sizeof(eeconfig_struct) - sizeof(uint16_t)); ++ if (mycrc != eeconfig.crc) { ++ // set sane defaults ++ eeconfig.steps_per_mm_x = STEPS_PER_MM_X; ++ eeconfig.steps_per_mm_y = STEPS_PER_MM_Y; ++ eeconfig.steps_per_mm_z = STEPS_PER_MM_Z; ++ eeconfig.steps_per_mm_e = STEPS_PER_MM_E; ++ ++ eeconfig.size_x = X_MAX; ++ eeconfig.size_y = Y_MAX; ++ eeconfig.size_z = Z_MAX; ++ ++ eeconfig.max_speed_x = MAXIMUM_FEEDRATE_X; ++ eeconfig.max_speed_y = MAXIMUM_FEEDRATE_Y; ++ eeconfig.max_speed_z = MAXIMUM_FEEDRATE_Z; ++ eeconfig.max_speed_e = MAXIMUM_FEEDRATE_E; ++ ++ eeconfig.max_temp_e = 1000; ++ eeconfig.max_temp_b = 480; ++ eeconfig.max_temp_r = 240; ++ ++ eeconfig.min_endstop_pos_z = Z_MIN; ++ ++ eeconfig.temp_hysteresis = TEMP_HYSTERESIS; ++ eeconfig.temp_residency = TEMP_RESIDENCY_TIME; ++ ++ eeconfig.baud = BAUD; ++ } ++} ++ ++void eeconfig_save() { ++ eeconfig.crc = crc_block(&eeconfig, sizeof(eeconfig_struct) - sizeof(uint16_t)); ++ eeprom_write_block(&eeconfig, &EE_config, sizeof(eeconfig_struct)); ++ do { ++ clock_poll(); ++ } while (eeprom_is_ready() == 0); ++} +diff --git a/eeconfig.h b/eeconfig.h +new file mode 100644 +index 0000000..2b489c0 +--- /dev/null ++++ b/eeconfig.h +@@ -0,0 +1,45 @@ ++#ifndef _EECONFIG_H ++#define _EECONFIG_H ++ ++#include ++ ++typedef struct { ++ uint32_t steps_per_mm_x; ++ uint32_t steps_per_mm_y; ++ uint32_t steps_per_mm_z; ++ uint32_t steps_per_mm_e; ++ ++ uint32_t size_x; ++ uint32_t size_y; ++ uint32_t size_z; ++ ++ uint32_t max_speed_x; ++ uint32_t max_speed_y; ++ uint32_t max_speed_z; ++ uint32_t max_speed_e; ++ ++ uint16_t max_temp_e; ++ uint16_t max_temp_b; ++ uint16_t max_temp_r; ++ ++ uint32_t min_endstop_pos_z; ++ ++ uint16_t temp_hysteresis; ++ uint16_t temp_residency; ++ ++ uint32_t baud; ++ ++ struct { ++ uint16_t adc_value; ++ uint16_t temperature; ++ } temptable[20]; ++ ++ uint16_t crc; ++} eeconfig_struct; ++ ++extern eeconfig_struct eeconfig; ++ ++void eeconfig_init(void); ++void eeconfig_save(void); ++ ++#endif /* _EECONFIG_H */ +diff --git a/gcode_parse.c b/gcode_parse.c +index 0668513..817fe85 100644 +--- a/gcode_parse.c ++++ b/gcode_parse.c +@@ -118,7 +118,7 @@ void gcode_parse_char(uint8_t c) { + case 'M': + next_target.M = read_digit.mantissa; + if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) +- serwrite_uint8(next_target.M); ++ serwrite_uint16(next_target.M); + break; + case 'X': + if (next_target.option_inches) +diff --git a/gcode_parse.h b/gcode_parse.h +index d15716d..216a375 100644 +--- a/gcode_parse.h ++++ b/gcode_parse.h +@@ -44,11 +44,11 @@ typedef struct { + }; + + uint8_t G; ///< G command number +- uint8_t M; ///< M command number ++ uint16_t M; ///< M command number + TARGET target; ///< target position: X, Y, Z, E and F + + int32_t S; ///< S word (various uses) +- uint16_t P; ///< P word (various uses) ++ int32_t P; ///< P word (various uses) + + uint8_t T; ///< T word (tool index) + +diff --git a/gcode_process.c b/gcode_process.c +index 4cb7a41..e97fff6 100644 +--- a/gcode_process.c ++++ b/gcode_process.c +@@ -26,6 +26,7 @@ + #include "clock.h" + #include "config_wrapper.h" + #include "home.h" ++#include "eeconfig.h" + + /// the current tool + uint8_t tool; +@@ -736,15 +737,84 @@ void process_gcode_command() { + + #ifdef DEBUG + case 240: ++ case 340: + //? --- M240: echo off --- + //? Disable echo. + //? This command is only available in DEBUG builds. ++ // EEPROM Configuration as per http://reprap.org/wiki/M-codes_for_EEPROM_config ++ // M244 - set baudrate ++ case 244: ++ if (next_target.seen_S) ++ if (next_target.S >= 1200 && next_target.S <= 1000000) ++ eeconfig.baud = next_target.S; ++ break; ++ // M245 - Write temp table value, S(index), X(adc reading) Y(temperature) ++ /// TODO: check values for sanity ++ case 245: ++ if (next_target.seen_S && next_target.seen_X && next_target.seen_Y) { ++ eeconfig.temptable[next_target.S].adc_value = next_target.target.X; ++ eeconfig.temptable[next_target.S].temperature = next_target.target.Y; ++ } ++ break; ++ // M246 - choose thermistor profile ++ // M247 - set heater PWM, see M135 above ++ // M248 - PID stuff- see M130-M133 above ++ // M249 - temp residency time - wait for all temps to be within target for this long before continuing M109 and friends ++ case 249: ++ if (next_target.seen_P) ++ eeconfig.temp_residency = next_target.P; ++ break; ++ // M250 - Z min endstop position - non-zero to avoid head crashing into bed during homing ++ case 250: ++ if (next_target.seen_Z) ++ eeconfig.min_endstop_pos_z = next_target.target.Z; ++ break; ++ // M251 - set max bed temp (failsafe) ++ case 251: ++ break; ++ // M252 - set max extruder temp (failsafe) ++ // M253 - max speeds ++ case 253: ++ if (next_target.seen_X) ++ eeconfig.max_speed_x = next_target.target.X; ++ if (next_target.seen_Y) ++ eeconfig.max_speed_y = next_target.target.Y; ++ if (next_target.seen_Z) ++ eeconfig.max_speed_z = next_target.target.Z; ++ if (next_target.seen_E) ++ eeconfig.max_speed_e = next_target.target.E; ++ break; ++ // M254 - set build volume ++ case 254: ++ if (next_target.seen_X) ++ eeconfig.size_x = next_target.target.X; ++ if (next_target.seen_Y) ++ eeconfig.size_y = next_target.target.Y; ++ if (next_target.seen_Z) ++ eeconfig.size_z = next_target.target.Z; ++ break; ++ // M255 - set steps per mm ++ case 255: ++ if (next_target.seen_X) ++ eeconfig.steps_per_mm_x = next_target.target.X; ++ if (next_target.seen_Y) ++ eeconfig.steps_per_mm_y = next_target.target.Y; ++ if (next_target.seen_Z) ++ eeconfig.steps_per_mm_z = next_target.target.Z; ++ if (next_target.seen_E) ++ eeconfig.steps_per_mm_e = next_target.target.E; ++ break; ++ ++ ++ // DEBUG ++ #ifdef DEBUG + debug_flags &= ~DEBUG_ECHO; + serial_writestr_P(PSTR("Echo off")); + // newline is sent from gcode_parse after we return + break; + + case 241: ++ case 341: + //? --- M241: echo on --- + //? Enable echo. + //? This command is only available in DEBUG builds. +diff --git a/mendel.c b/mendel.c +index dd9a99c..3f3266c 100644 +--- a/mendel.c ++++ b/mendel.c +@@ -48,6 +48,7 @@ + #include "arduino.h" + #include "clock.h" + #include "intercom.h" ++#include "eeconfig.h" + #include "simulator.h" + + #ifdef SIMINFO +@@ -194,6 +195,9 @@ void io_init(void) { + + /// Startup code, run when we come out of reset + void init(void) { ++ // read config from eeprom ++ eeconfig_init(); ++ + // set up watchdog + wd_init(); + +diff --git a/serial.c b/serial.c +index a7a0bd4..df0f873 100644 +--- a/serial.c ++++ b/serial.c +@@ -14,6 +14,7 @@ + #include "memory_barrier.h" + + #include "arduino.h" ++#include "eeconfig.h" + + /// size of TX and RX buffers. MUST be a \f$2^n\f$ value + #define BUFSIZE 64 +@@ -84,13 +85,14 @@ volatile uint8_t flowflags = FLOWFLAG_SEND_XON; + /// set up baud generator and interrupts, clear buffers + void serial_init() + { +-#if BAUD > 38401 +- UCSR0A = MASK(U2X0); +- UBRR0 = (((F_CPU / 8) / BAUD) - 0.5); +-#else +- UCSR0A = 0; +- UBRR0 = (((F_CPU / 16) / BAUD) - 0.5); +-#endif ++ if (eeconfig.baud > 38401) { ++ UCSR0A = MASK(U2X0); ++ UBRR0 = ((F_CPU / 8) / eeconfig.baud) - 1; ++ } ++ else { ++ UCSR0A = 0; ++ UBRR0 = ((F_CPU / 16) / eeconfig.baud) - 1; ++ } + + UCSR0B = MASK(RXEN0) | MASK(TXEN0); + UCSR0C = MASK(UCSZ01) | MASK(UCSZ00); +diff --git a/temp.c b/temp.c +index dd4253c..be7f702 100644 +--- a/temp.c ++++ b/temp.c +@@ -17,6 +17,7 @@ + #include "debug.h" + #ifndef EXTRUDER + #include "sersendf.h" ++ #include "eeconfig.h" + #endif + #include "heater.h" + #ifdef TEMP_INTERCOM +@@ -331,9 +332,14 @@ uint8_t temp_achieved() { + uint8_t all_ok = 255; + + for (i = 0; i < NUM_TEMP_SENSORS; i++) { ++ #ifndef EXTRUDER + if (temp_sensors_runtime[i].target_temp > 0 && +- temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*100)) ++ temp_sensors_runtime[i].temp_residency < eeconfig.temp_residency*100) + all_ok = 0; ++ #else ++ if (temp_sensors_runtime[i].temp_residency < TEMP_RESIDENCY_TIME*100) ++ all_ok = 0; ++ #endif + } + return all_ok; + } +-- +2.1.0 + diff --git a/attic/eeconfig/0002-documentation.patch b/attic/eeconfig/0002-documentation.patch new file mode 100644 index 0000000..cb13036 --- /dev/null +++ b/attic/eeconfig/0002-documentation.patch @@ -0,0 +1,84 @@ +From 36497dde3047fb7a08a29b473fa2408c61f9e7bb Mon Sep 17 00:00:00 2001 +From: Michael Moon +Date: Mon, 28 Mar 2011 20:57:30 +1100 +Subject: documentation + +--- + eeconfig.h | 44 ++++++++++++++++++++++++-------------------- + 1 file changed, 24 insertions(+), 20 deletions(-) + +diff --git a/eeconfig.h b/eeconfig.h +index 2b489c0..e9a8a70 100644 +--- a/eeconfig.h ++++ b/eeconfig.h +@@ -3,43 +3,47 @@ + + #include + ++/// this doubles as both an in-eeprom and in-memory storage struct for configuration settings + typedef struct { +- uint32_t steps_per_mm_x; +- uint32_t steps_per_mm_y; +- uint32_t steps_per_mm_z; +- uint32_t steps_per_mm_e; ++ uint32_t steps_per_mm_x; ///< steps per mm. critically important for accurate prints ++ uint32_t steps_per_mm_y; ///< steps per mm. critically important for accurate prints ++ uint32_t steps_per_mm_z; ///< steps per mm. critically important for accurate prints ++ uint32_t steps_per_mm_e; ///< steps per mm. critically important for accurate prints + +- uint32_t size_x; +- uint32_t size_y; +- uint32_t size_z; ++ uint32_t size_x; ///< build volume. don't allow axes to move outside an area of this size ++ uint32_t size_y; ///< build volume. don't allow axes to move outside an area of this size ++ uint32_t size_z; ///< build volume. don't allow axes to move outside an area of this size + +- uint32_t max_speed_x; +- uint32_t max_speed_y; +- uint32_t max_speed_z; +- uint32_t max_speed_e; ++ uint32_t max_speed_x; ///< axis speed limit. Any move which requires this axis to go above this speed will have its specified speed reduced, preserving geometry. ++ uint32_t max_speed_y; ///< axis speed limit. Any move which requires this axis to go above this speed will have its specified speed reduced, preserving geometry. ++ uint32_t max_speed_z; ///< axis speed limit. Any move which requires this axis to go above this speed will have its specified speed reduced, preserving geometry. ++ uint32_t max_speed_e; ///< axis speed limit. Any move which requires this axis to go above this speed will have its specified speed reduced, preserving geometry. + +- uint16_t max_temp_e; +- uint16_t max_temp_b; +- uint16_t max_temp_r; ++ uint16_t max_temp_e; ///< do not allow temperature to go above this amount even if host software requests it, assume host software has gone crazy. ++ uint16_t max_temp_b; ///< do not allow temperature to go above this amount even if host software requests it, assume host software has gone crazy. ++ uint16_t max_temp_r; ///< do not allow temperature to go above this amount even if host software requests it, assume host software has gone crazy. + +- uint32_t min_endstop_pos_z; ++ uint32_t min_endstop_pos_z; ///< this is the Z position where the endstop is encountered. This helps prevent the head crashing into the bed while homing. To use, set this value to 3mm or so, then adjust your Z endstop flag so that it trips when your extruder nozzle is 3mm from your bed. + +- uint16_t temp_hysteresis; +- uint16_t temp_residency; ++ uint16_t temp_hysteresis; ///< temperature has to be within target +/- this amount for M109 and friends to continue ++ uint16_t temp_residency; ///< temperature has to be near target for this long for M109 and friends to continue + +- uint32_t baud; ++ uint32_t baud; ///< serial baud rate to communicate at. If changed, does not take effect until reset. \warning if a bad value is progammed, the only way to recover is to re-flash your eeprom from the host. + + struct { + uint16_t adc_value; + uint16_t temperature; +- } temptable[20]; ++ } temptable[20]; ///< the temperature lookup table for linear interpolation of ADC readings -> temperatures + +- uint16_t crc; ++ uint16_t crc; ///< data integrity check. If crc doesn't match data, use defaults instead. + } eeconfig_struct; + + extern eeconfig_struct eeconfig; + ++/// read settings from eeprom + void eeconfig_init(void); ++ ++/// save current settings to eeprom + void eeconfig_save(void); + + #endif /* _EECONFIG_H */ +-- +2.1.0 + diff --git a/attic/eeconfig/0003-wrap-an-ifdef-around-eeconfig-stuff-make-it-optional.patch b/attic/eeconfig/0003-wrap-an-ifdef-around-eeconfig-stuff-make-it-optional.patch new file mode 100644 index 0000000..a2d5cca --- /dev/null +++ b/attic/eeconfig/0003-wrap-an-ifdef-around-eeconfig-stuff-make-it-optional.patch @@ -0,0 +1,318 @@ +From 186d4c39770c36051232dcc8fb35d8e10841875b Mon Sep 17 00:00:00 2001 +From: Michael Moon +Date: Mon, 28 Mar 2011 21:31:58 +1100 +Subject: wrap an ifdef around eeconfig stuff, make it optional and disabled by + default + +--- + config.default.h | 22 +++++++++++++++------- + config.gen3.h | 18 ++++++++++++++---- + config.gen6.h | 16 ++++++++++++---- + config.ramps-v1.2.h | 22 +++++++++++++++------- + eeconfig.c | 4 ++++ + gcode_process.c | 3 ++- + mendel.c | 2 ++ + serial.c | 11 +++++++++++ + temp.c | 38 +++++++++++++++++++++++++++----------- + 9 files changed, 102 insertions(+), 34 deletions(-) + +diff --git a/config.default.h b/config.default.h +index c15969b..62cb3e2 100644 +--- a/config.default.h ++++ b/config.default.h +@@ -515,20 +515,28 @@ DEFINE_HEATER(bed, PB4, 1) + */ + // #define DEBUG + ++/** \def EECONFIG ++ EECONFIG ++ allows runtime reconfiguration of critical variables ++ ++ See http://reprap.org/wiki/M-codes_for_EEPROM_config ++*/ ++// #define EECONFIG ++ + /** \def BANG_BANG +-BANG_BANG +-drops PID loop from heater control, reduces code size significantly (1300 bytes!) +-may allow DEBUG on '168 ++ BANG_BANG ++ drops PID loop from heater control, reduces code size significantly (1300 bytes!) ++ may allow DEBUG on '168 + */ + // #define BANG_BANG + /** \def BANG_BANG_ON +-BANG_BANG_ON +-PWM value for 'on' ++ BANG_BANG_ON ++ PWM value for 'on' + */ + // #define BANG_BANG_ON 200 + /** \def BANG_BANG_OFF +-BANG_BANG_OFF +-PWM value for 'off' ++ BANG_BANG_OFF ++ PWM value for 'off' + */ + // #define BANG_BANG_OFF 45 + +diff --git a/config.gen3.h b/config.gen3.h +index bcbbd75..05f7996 100644 +--- a/config.gen3.h ++++ b/config.gen3.h +@@ -519,19 +519,29 @@ DEFINE_TEMP_SENSOR(bed, TT_INTERCOM, AIO1, 0) + */ + // #define DEBUG + ++/** \def EECONFIG ++EECONFIG ++allows runtime reconfiguration of critical variables ++ ++See http://reprap.org/wiki/M-codes_for_EEPROM_config ++*/ ++// #define EECONFIG ++ + /** \def BANG_BANG + BANG_BANG + drops PID loop from heater control, reduces code size significantly (1300 bytes!) + may allow DEBUG on '168 +-*//** \def BANG_BANG_ON ++*/ ++// #define BANG_BANG ++/** \def BANG_BANG_ON + BANG_BANG_ON + PWM value for 'on' +-*//** \def BANG_BANG_OFF ++*/ ++// #define BANG_BANG_ON 200 ++/** \def BANG_BANG_OFF + BANG_BANG_OFF + PWM value for 'off' + */ +-// #define BANG_BANG +-// #define BANG_BANG_ON 200 + // #define BANG_BANG_OFF 45 + + /** +diff --git a/config.gen6.h b/config.gen6.h +index 7b810e4..96b2e7c 100644 +--- a/config.gen6.h ++++ b/config.gen6.h +@@ -503,6 +503,14 @@ DEFINE_HEATER(extruder, PD6, 1) + */ + // #define DEBUG + ++/** \def EECONFIG ++ EECONFIG ++ allows runtime reconfiguration of critical variables ++ ++ See http://reprap.org/wiki/M-codes_for_EEPROM_config ++*/ ++// #define EECONFIG ++ + /** \def BANG_BANG + BANG_BANG + drops PID loop from heater control, reduces code size significantly (1300 bytes!) +@@ -510,13 +518,13 @@ DEFINE_HEATER(extruder, PD6, 1) + */ + // #define BANG_BANG + /** \def BANG_BANG_ON +-BANG_BANG_ON +-PWM value for 'on' ++ BANG_BANG_ON ++ PWM value for 'on' + */ + // #define BANG_BANG_ON 200 + /** \def BANG_BANG_OFF +-BANG_BANG_OFF +-PWM value for 'off' ++ BANG_BANG_OFF ++ PWM value for 'off' + */ + // #define BANG_BANG_OFF 45 + +diff --git a/config.ramps-v1.2.h b/config.ramps-v1.2.h +index bcb9af8..2486cd7 100644 +--- a/config.ramps-v1.2.h ++++ b/config.ramps-v1.2.h +@@ -512,20 +512,28 @@ DEFINE_HEATER(fan, PH6, 1) + */ + // #define DEBUG + ++/** \def EECONFIG ++ EECONFIG ++ allows runtime reconfiguration of critical variables ++ ++ See http://reprap.org/wiki/M-codes_for_EEPROM_config ++*/ ++// #define EECONFIG ++ + /** \def BANG_BANG +-BANG_BANG +-drops PID loop from heater control, reduces code size significantly (1300 bytes!) +-may allow DEBUG on '168 ++ BANG_BANG ++ drops PID loop from heater control, reduces code size significantly (1300 bytes!) ++ may allow DEBUG on '168 + */ + // #define BANG_BANG + /** \def BANG_BANG_ON +-BANG_BANG_ON +-PWM value for 'on' ++ BANG_BANG_ON ++ PWM value for 'on' + */ + // #define BANG_BANG_ON 200 + /** \def BANG_BANG_OFF +-BANG_BANG_OFF +-PWM value for 'off' ++ BANG_BANG_OFF ++ PWM value for 'off' + */ + // #define BANG_BANG_OFF 45 + +diff --git a/eeconfig.c b/eeconfig.c +index 931866e..105f36d 100644 +--- a/eeconfig.c ++++ b/eeconfig.c +@@ -13,6 +13,7 @@ eeconfig_struct eeconfig; + eeconfig_struct EEMEM EE_config; + + void eeconfig_init() { ++ #ifdef EECONFIG + uint16_t mycrc; + eeprom_read_block(&eeconfig, &EE_config, sizeof(eeconfig_struct)); + mycrc = crc_block(&eeconfig, sizeof(eeconfig_struct) - sizeof(uint16_t)); +@@ -43,12 +44,15 @@ void eeconfig_init() { + + eeconfig.baud = BAUD; + } ++ #endif /* EECONFIG */ + } + + void eeconfig_save() { ++ #ifdef EECONFIG + eeconfig.crc = crc_block(&eeconfig, sizeof(eeconfig_struct) - sizeof(uint16_t)); + eeprom_write_block(&eeconfig, &EE_config, sizeof(eeconfig_struct)); + do { + clock_poll(); + } while (eeprom_is_ready() == 0); ++ #endif /* EECONFIG */ + } +diff --git a/gcode_process.c b/gcode_process.c +index e97fff6..310eed4 100644 +--- a/gcode_process.c ++++ b/gcode_process.c +@@ -741,6 +741,7 @@ void process_gcode_command() { + //? --- M240: echo off --- + //? Disable echo. + //? This command is only available in DEBUG builds. ++ #ifdef EECONFIG + // EEPROM Configuration as per http://reprap.org/wiki/M-codes_for_EEPROM_config + // M244 - set baudrate + case 244: +@@ -804,7 +805,7 @@ void process_gcode_command() { + if (next_target.seen_E) + eeconfig.steps_per_mm_e = next_target.target.E; + break; +- ++ #endif /* EECONFIG */ + + // DEBUG + #ifdef DEBUG +diff --git a/mendel.c b/mendel.c +index 3f3266c..3b55883 100644 +--- a/mendel.c ++++ b/mendel.c +@@ -195,8 +195,10 @@ void io_init(void) { + + /// Startup code, run when we come out of reset + void init(void) { ++ #ifdef EECONFIG + // read config from eeprom + eeconfig_init(); ++ #endif + + // set up watchdog + wd_init(); +diff --git a/serial.c b/serial.c +index df0f873..3050c3a 100644 +--- a/serial.c ++++ b/serial.c +@@ -85,6 +85,7 @@ volatile uint8_t flowflags = FLOWFLAG_SEND_XON; + /// set up baud generator and interrupts, clear buffers + void serial_init() + { ++ #ifdef EECONFIG + if (eeconfig.baud > 38401) { + UCSR0A = MASK(U2X0); + UBRR0 = ((F_CPU / 8) / eeconfig.baud) - 1; +@@ -93,6 +94,16 @@ void serial_init() + UCSR0A = 0; + UBRR0 = ((F_CPU / 16) / eeconfig.baud) - 1; + } ++ #else ++ if (BAUD > 38401) { ++ UCSR0A = MASK(U2X0); ++ UBRR0 = ((F_CPU / 8) / BAUD) - 1; ++ } ++ else { ++ UCSR0A = 0; ++ UBRR0 = ((F_CPU / 16) / BAUD) - 1; ++ } ++ #endif + + UCSR0B = MASK(RXEN0) | MASK(TXEN0); + UCSR0C = MASK(UCSZ01) | MASK(UCSZ00); +diff --git a/temp.c b/temp.c +index be7f702..2acaac4 100644 +--- a/temp.c ++++ b/temp.c +@@ -296,17 +296,33 @@ void temp_sensor_tick() { + (EWMA_SCALE-EWMA_ALPHA) * temp_sensors_runtime[i].last_read_temp + ) / EWMA_SCALE); + } +- if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (TEMP_HYSTERESIS*4)) { +- if (temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*120)) +- temp_sensors_runtime[i].temp_residency++; +- } +- else { +- // Deal with flakey sensors which occasionally report a wrong value +- // by setting residency back, but not entirely to zero. +- if (temp_sensors_runtime[i].temp_residency > 10) +- temp_sensors_runtime[i].temp_residency -= 10; +- else +- temp_sensors_runtime[i].temp_residency = 0; ++ #ifdef EECONFIG ++ if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (eeconfig.temp_hysteresis * 4)) { ++ if (temp_sensors_runtime[i].temp_residency < eeconfig.temp_residency) ++ temp_sensors_runtime[i].temp_residency++; ++ } ++ else { ++ // Deal with flakey sensors which occasionally report a wrong value ++ // by setting residency back, but not entirely to zero. ++ if (temp_sensors_runtime[i].temp_residency > 10) ++ temp_sensors_runtime[i].temp_residency -= 10; ++ else ++ temp_sensors_runtime[i].temp_residency = 0; ++ } ++ #else ++ if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (TEMP_HYSTERESIS*4)) { ++ if (temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*100)) ++ temp_sensors_runtime[i].temp_residency++; ++ } ++ else { ++ // Deal with flakey sensors which occasionally report a wrong value ++ // by setting residency back, but not entirely to zero. ++ if (temp_sensors_runtime[i].temp_residency > 10) ++ temp_sensors_runtime[i].temp_residency -= 10; ++ else ++ temp_sensors_runtime[i].temp_residency = 0; ++ } ++ #endif + } + + if (temp_sensors[i].heater < NUM_HEATERS) { +-- +2.1.0 + diff --git a/attic/eeconfig/0004-merge-cleanup-missed-a-section-in-temp.c.patch b/attic/eeconfig/0004-merge-cleanup-missed-a-section-in-temp.c.patch new file mode 100644 index 0000000..0529595 --- /dev/null +++ b/attic/eeconfig/0004-merge-cleanup-missed-a-section-in-temp.c.patch @@ -0,0 +1,39 @@ +From cc4737093ddf2dc16780ad701c2de0835423a87c Mon Sep 17 00:00:00 2001 +From: Michael Moon +Date: Sat, 4 Jun 2011 03:15:28 +1000 +Subject: merge cleanup, missed a section in temp.c + +Conflicts: + + temp.c +--- + temp.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/temp.c b/temp.c +index 2acaac4..2e39fdc 100644 +--- a/temp.c ++++ b/temp.c +@@ -297,7 +297,7 @@ void temp_sensor_tick() { + ) / EWMA_SCALE); + } + #ifdef EECONFIG +- if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (eeconfig.temp_hysteresis * 4)) { ++ if (labs(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp) < eeconfig.temp_hysteresis) { + if (temp_sensors_runtime[i].temp_residency < eeconfig.temp_residency) + temp_sensors_runtime[i].temp_residency++; + } +@@ -310,8 +310,8 @@ void temp_sensor_tick() { + temp_sensors_runtime[i].temp_residency = 0; + } + #else +- if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (TEMP_HYSTERESIS*4)) { +- if (temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*100)) ++ if (labs(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp) < (TEMP_HYSTERESIS * 4)) { ++ if (temp_sensors_runtime[i].temp_residency < TEMP_RESIDENCY_TIME*100) + temp_sensors_runtime[i].temp_residency++; + } + else { +-- +2.1.0 + diff --git a/attic/eeconfig/README b/attic/eeconfig/README new file mode 100644 index 0000000..4d818b8 --- /dev/null +++ b/attic/eeconfig/README @@ -0,0 +1,18 @@ + +This branch was an attempt to add configuration strorage in the EEPROM. +Similar to Marlin, which allows to do virtually all configuration through +M-codes at runtime. + +The obvious penalty is, some calculations can no longer be done at +compile time and have to be done at runtime. It also increases binary size. +These are the reasons why this branch sat unattended in the repository for a +long time without being moved to experimental/master. If tested at all, +the last tests were done in 2011. + +With the advent of Configtool it becomes even more unlikely this kind of +configuration/calibration ever becomes standard. Whatever can be stored in +EEPROM, Configtool allows to set it at compile time, keeping the firmware +smaller and faster. The only small disadvantage of Configtool is, one has to +do 2 or 3 clicks to build and upload again. + +This branch was last applied to commit d7789ee21721a061eb50ec5fd4d18ed73a6948e3.