Merge remote-tracking branch 'refs/remotes/prusa3d/MK2' into MK2

# Conflicts:
#	Firmware/Marlin.h
#	Firmware/Marlin_main.cpp
#	Firmware/language_all.cpp
#	Firmware/language_de.h
#	Firmware/language_en.h
#	Firmware/language_it.h
#	Firmware/mesh_bed_calibration.cpp
#	Firmware/mesh_bed_calibration.h
#	Firmware/ultralcd.cpp
This commit is contained in:
3d-gussner 2017-07-06 10:31:28 +02:00
commit 1924266143
24 changed files with 38261 additions and 8088 deletions

View File

@ -47,6 +47,9 @@
#define EEPROM_TEMP_CAL_ACTIVE (EEPROM_PROBE_TEMP_SHIFT - 1) #define EEPROM_TEMP_CAL_ACTIVE (EEPROM_PROBE_TEMP_SHIFT - 1)
#define EEPROM_BOWDEN_LENGTH (EEPROM_TEMP_CAL_ACTIVE - 2*4) //4 x int for bowden lengths for multimaterial #define EEPROM_BOWDEN_LENGTH (EEPROM_TEMP_CAL_ACTIVE - 2*4) //4 x int for bowden lengths for multimaterial
#define EEPROM_CALIBRATION_STATUS_PINDA (EEPROM_BOWDEN_LENGTH - 1) //0 - not calibrated; 1 - calibrated #define EEPROM_CALIBRATION_STATUS_PINDA (EEPROM_BOWDEN_LENGTH - 1) //0 - not calibrated; 1 - calibrated
#define EEPROM_FILENAME (EEPROM_CALIBRATION_STATUS_PINDA - 8) //8chars to store filename without extension
#define EEPROM_FILE_POSITION (EEPROM_FILENAME - 4) //32 bit for uint32_t file position
// Currently running firmware, each digit stored as uint16_t. // Currently running firmware, each digit stored as uint16_t.
// The flavor differentiates a dev, alpha, beta, release candidate or a release version. // The flavor differentiates a dev, alpha, beta, release candidate or a release version.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,351 +1,355 @@
// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
// License: GPL // License: GPL
#ifndef MARLIN_H #ifndef MARLIN_H
#define MARLIN_H #define MARLIN_H
#define FORCE_INLINE __attribute__((always_inline)) inline #define FORCE_INLINE __attribute__((always_inline)) inline
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <util/delay.h> #include <util/delay.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include "fastio.h" #include "fastio.h"
#include "Configuration.h" #include "Configuration.h"
#include "pins.h" #include "pins.h"
#ifndef AT90USB #ifndef AT90USB
#define HardwareSerial_h // trick to disable the standard HWserial #define HardwareSerial_h // trick to disable the standard HWserial
#endif #endif
#if (ARDUINO >= 100) #if (ARDUINO >= 100)
# include "Arduino.h" # include "Arduino.h"
#else #else
# include "WProgram.h" # include "WProgram.h"
#endif #endif
// Arduino < 1.0.0 does not define this, so we need to do it ourselves // Arduino < 1.0.0 does not define this, so we need to do it ourselves
#ifndef analogInputToDigitalPin #ifndef analogInputToDigitalPin
# define analogInputToDigitalPin(p) ((p) + A0) # define analogInputToDigitalPin(p) ((p) + A0)
#endif #endif
#ifdef AT90USB #ifdef AT90USB
#include "HardwareSerial.h" #include "HardwareSerial.h"
#endif #endif
#include "MarlinSerial.h" #include "MarlinSerial.h"
#ifndef cbi #ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif #endif
#ifndef sbi #ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif #endif
#include "WString.h" #include "WString.h"
#ifdef AT90USB #ifdef AT90USB
#ifdef BTENABLED #ifdef BTENABLED
#define MYSERIAL bt #define MYSERIAL bt
#else #else
#define MYSERIAL Serial #define MYSERIAL Serial
#endif // BTENABLED #endif // BTENABLED
#else #else
#define MYSERIAL MSerial #define MYSERIAL MSerial
#endif #endif
#define SERIAL_PROTOCOL(x) (MYSERIAL.print(x)) #define SERIAL_PROTOCOL(x) (MYSERIAL.print(x))
#define SERIAL_PROTOCOL_F(x,y) (MYSERIAL.print(x,y)) #define SERIAL_PROTOCOL_F(x,y) (MYSERIAL.print(x,y))
#define SERIAL_PROTOCOLPGM(x) (serialprintPGM(PSTR(x))) #define SERIAL_PROTOCOLPGM(x) (serialprintPGM(PSTR(x)))
#define SERIAL_PROTOCOLRPGM(x) (serialprintPGM((x))) #define SERIAL_PROTOCOLRPGM(x) (serialprintPGM((x)))
#define SERIAL_PROTOCOLLN(x) (MYSERIAL.print(x),MYSERIAL.write('\n')) #define SERIAL_PROTOCOLLN(x) (MYSERIAL.print(x),MYSERIAL.write('\n'))
#define SERIAL_PROTOCOLLNPGM(x) (serialprintPGM(PSTR(x)),MYSERIAL.write('\n')) #define SERIAL_PROTOCOLLNPGM(x) (serialprintPGM(PSTR(x)),MYSERIAL.write('\n'))
#define SERIAL_PROTOCOLLNRPGM(x) (serialprintPGM((x)),MYSERIAL.write('\n')) #define SERIAL_PROTOCOLLNRPGM(x) (serialprintPGM((x)),MYSERIAL.write('\n'))
extern const char errormagic[] PROGMEM; extern const char errormagic[] PROGMEM;
extern const char echomagic[] PROGMEM; extern const char echomagic[] PROGMEM;
#define SERIAL_ERROR_START (serialprintPGM(errormagic)) #define SERIAL_ERROR_START (serialprintPGM(errormagic))
#define SERIAL_ERROR(x) SERIAL_PROTOCOL(x) #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
#define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x) #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
#define SERIAL_ERRORRPGM(x) SERIAL_PROTOCOLRPGM(x) #define SERIAL_ERRORRPGM(x) SERIAL_PROTOCOLRPGM(x)
#define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x) #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
#define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x) #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
#define SERIAL_ERRORLNRPGM(x) SERIAL_PROTOCOLLNRPGM(x) #define SERIAL_ERRORLNRPGM(x) SERIAL_PROTOCOLLNRPGM(x)
#define SERIAL_ECHO_START (serialprintPGM(echomagic)) #define SERIAL_ECHO_START (serialprintPGM(echomagic))
#define SERIAL_ECHO(x) SERIAL_PROTOCOL(x) #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
#define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x) #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
#define SERIAL_ECHORPGM(x) SERIAL_PROTOCOLRPGM(x) #define SERIAL_ECHORPGM(x) SERIAL_PROTOCOLRPGM(x)
#define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x) #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
#define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x) #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
#define SERIAL_ECHOLNRPGM(x) SERIAL_PROTOCOLLNRPGM(x) #define SERIAL_ECHOLNRPGM(x) SERIAL_PROTOCOLLNRPGM(x)
#define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value))) #define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
void serial_echopair_P(const char *s_P, float v); void serial_echopair_P(const char *s_P, float v);
void serial_echopair_P(const char *s_P, double v); void serial_echopair_P(const char *s_P, double v);
void serial_echopair_P(const char *s_P, unsigned long v); void serial_echopair_P(const char *s_P, unsigned long v);
//Things to write to serial from Program memory. Saves 400 to 2k of RAM. //Things to write to serial from Program memory. Saves 400 to 2k of RAM.
FORCE_INLINE void serialprintPGM(const char *str) FORCE_INLINE void serialprintPGM(const char *str)
{ {
char ch=pgm_read_byte(str); char ch=pgm_read_byte(str);
while(ch) while(ch)
{ {
MYSERIAL.write(ch); MYSERIAL.write(ch);
ch=pgm_read_byte(++str); ch=pgm_read_byte(++str);
} }
} }
bool is_buffer_empty(); bool is_buffer_empty();
void get_command(); void get_command();
void process_commands(); void process_commands();
void ramming(); void ramming();
void manage_inactivity(bool ignore_stepper_queue=false); void manage_inactivity(bool ignore_stepper_queue=false);
#if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1 #if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1
#define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
#define disable_x() { WRITE(X_ENABLE_PIN,!X_ENABLE_ON); axis_known_position[X_AXIS] = false; } #define disable_x() { WRITE(X_ENABLE_PIN,!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }
#else #else
#define enable_x() ; #define enable_x() ;
#define disable_x() ; #define disable_x() ;
#endif #endif
#if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1 #if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
#ifdef Y_DUAL_STEPPER_DRIVERS #ifdef Y_DUAL_STEPPER_DRIVERS
#define enable_y() { WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, Y_ENABLE_ON); } #define enable_y() { WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, Y_ENABLE_ON); }
#define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, !Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; } #define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, !Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
#else #else
#define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON) #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
#define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; } #define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
#endif #endif
#else #else
#define enable_y() ; #define enable_y() ;
#define disable_y() ; #define disable_y() ;
#endif #endif
#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
#if defined(Z_AXIS_ALWAYS_ON) #if defined(Z_AXIS_ALWAYS_ON)
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } #define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#else #else
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
#define disable_z() ; #define disable_z() ;
#endif #endif
#else #else
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } #define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#else #else
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#endif #endif
#endif #endif
#else #else
#define enable_z() ; #define enable_z() ;
#define disable_z() ; #define disable_z() ;
#endif #endif
//#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 //#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
//#ifdef Z_DUAL_STEPPER_DRIVERS //#ifdef Z_DUAL_STEPPER_DRIVERS
//#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } //#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
//#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } //#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
//#else //#else
//#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) //#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
//#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } //#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
//#endif //#endif
//#else //#else
//#define enable_z() ; //#define enable_z() ;
//#define disable_z() ; //#define disable_z() ;
//#endif //#endif
#if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1) #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
#define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON) #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
#define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON) #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
#else #else
#define enable_e0() /* nothing */ #define enable_e0() /* nothing */
#define disable_e0() /* nothing */ #define disable_e0() /* nothing */
#endif #endif
#if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1) #if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
#define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON) #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
#define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON) #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
#else #else
#define enable_e1() /* nothing */ #define enable_e1() /* nothing */
#define disable_e1() /* nothing */ #define disable_e1() /* nothing */
#endif #endif
#if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1) #if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
#define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON) #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
#define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON) #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
#else #else
#define enable_e2() /* nothing */ #define enable_e2() /* nothing */
#define disable_e2() /* nothing */ #define disable_e2() /* nothing */
#endif #endif
enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5}; enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
void FlushSerialRequestResend(); void FlushSerialRequestResend();
void ClearToSend(); void ClearToSend();
void get_coordinates(); void get_coordinates();
void prepare_move(); void prepare_move();
void kill(const char *full_screen_message = NULL); void kill(const char *full_screen_message = NULL);
void Stop(); void Stop();
bool IsStopped(); bool IsStopped();
//put an ASCII command at the end of the current buffer. //put an ASCII command at the end of the current buffer.
void enquecommand(const char *cmd, bool from_progmem = false); void enquecommand(const char *cmd, bool from_progmem = false);
//put an ASCII command at the end of the current buffer, read from flash //put an ASCII command at the end of the current buffer, read from flash
#define enquecommand_P(cmd) enquecommand(cmd, true) #define enquecommand_P(cmd) enquecommand(cmd, true)
void enquecommand_front(const char *cmd, bool from_progmem = false); void enquecommand_front(const char *cmd, bool from_progmem = false);
//put an ASCII command at the end of the current buffer, read from flash //put an ASCII command at the end of the current buffer, read from flash
#define enquecommand_P(cmd) enquecommand(cmd, true) #define enquecommand_P(cmd) enquecommand(cmd, true)
#define enquecommand_front_P(cmd) enquecommand_front(cmd, true) #define enquecommand_front_P(cmd) enquecommand_front(cmd, true)
void repeatcommand_front(); void repeatcommand_front();
// Remove all lines from the command queue. // Remove all lines from the command queue.
void cmdqueue_reset(); void cmdqueue_reset();
void prepare_arc_move(char isclockwise); void prepare_arc_move(char isclockwise);
void clamp_to_software_endstops(float target[3]); void clamp_to_software_endstops(float target[3]);
void refresh_cmd_timeout(void); void refresh_cmd_timeout(void);
#ifdef FAST_PWM_FAN #ifdef FAST_PWM_FAN
void setPwmFrequency(uint8_t pin, int val); void setPwmFrequency(uint8_t pin, int val);
#endif #endif
#ifndef CRITICAL_SECTION_START #ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli(); #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg; #define CRITICAL_SECTION_END SREG = _sreg;
#endif //CRITICAL_SECTION_START #endif //CRITICAL_SECTION_START
extern float homing_feedrate[]; extern float homing_feedrate[];
extern bool axis_relative_modes[]; extern bool axis_relative_modes[];
extern int feedmultiply; extern int feedmultiply;
extern int extrudemultiply; // Sets extrude multiply factor (in percent) for all extruders extern int extrudemultiply; // Sets extrude multiply factor (in percent) for all extruders
extern bool volumetric_enabled; extern bool volumetric_enabled;
extern int extruder_multiply[EXTRUDERS]; // sets extrude multiply factor (in percent) for each extruder individually extern int extruder_multiply[EXTRUDERS]; // sets extrude multiply factor (in percent) for each extruder individually
extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder. extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
extern float current_position[NUM_AXIS] ; extern float current_position[NUM_AXIS] ;
extern float destination[NUM_AXIS] ; extern float destination[NUM_AXIS] ;
extern float add_homing[3]; extern float add_homing[3];
extern float min_pos[3]; extern float min_pos[3];
extern float max_pos[3]; extern float max_pos[3];
extern bool axis_known_position[3]; extern bool axis_known_position[3];
extern float zprobe_zoffset; extern float zprobe_zoffset;
extern int fanSpeed; extern int fanSpeed;
extern void homeaxis(int axis); extern void homeaxis(int axis);
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
extern unsigned char fanSpeedSoftPwm; extern unsigned char fanSpeedSoftPwm;
#endif #endif
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
extern float filament_width_nominal; //holds the theoretical filament diameter ie., 3.00 or 1.75 extern float filament_width_nominal; //holds the theoretical filament diameter ie., 3.00 or 1.75
extern bool filament_sensor; //indicates that filament sensor readings should control extrusion extern bool filament_sensor; //indicates that filament sensor readings should control extrusion
extern float filament_width_meas; //holds the filament diameter as accurately measured extern float filament_width_meas; //holds the filament diameter as accurately measured
extern signed char measurement_delay[]; //ring buffer to delay measurement extern signed char measurement_delay[]; //ring buffer to delay measurement
extern int delay_index1, delay_index2; //index into ring buffer extern int delay_index1, delay_index2; //index into ring buffer
extern float delay_dist; //delay distance counter extern float delay_dist; //delay distance counter
extern int meas_delay_cm; //delay distance extern int meas_delay_cm; //delay distance
#endif #endif
#ifdef FWRETRACT #ifdef FWRETRACT
extern bool autoretract_enabled; extern bool autoretract_enabled;
extern bool retracted[EXTRUDERS]; extern bool retracted[EXTRUDERS];
extern float retract_length, retract_length_swap, retract_feedrate, retract_zlift; extern float retract_length, retract_length_swap, retract_feedrate, retract_zlift;
extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate; extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
#endif #endif
extern unsigned long starttime; extern unsigned long starttime;
extern unsigned long stoptime; extern unsigned long stoptime;
extern int bowden_length[4]; extern int bowden_length[4];
extern bool is_usb_printing; extern bool is_usb_printing;
extern bool homing_flag; extern bool homing_flag;
extern bool temp_cal_active; extern bool temp_cal_active;
extern bool loading_flag; extern bool loading_flag;
extern unsigned int usb_printing_counter; extern unsigned int usb_printing_counter;
extern unsigned long kicktime; extern unsigned long kicktime;
extern unsigned long total_filament_used; extern unsigned long total_filament_used;
void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time);
extern unsigned int heating_status; extern unsigned int heating_status;
extern unsigned int status_number; extern unsigned int status_number;
extern unsigned int heating_status_counter; extern unsigned int heating_status_counter;
extern bool custom_message; extern bool custom_message;
extern unsigned int custom_message_type; extern unsigned int custom_message_type;
extern unsigned int custom_message_state; extern unsigned int custom_message_state;
extern char snmm_filaments_used; extern char snmm_filaments_used;
extern unsigned long PingTime; extern unsigned long PingTime;
// Handling multiple extruders pins // Handling multiple extruders pins
extern uint8_t active_extruder; extern uint8_t active_extruder;
#ifdef DIGIPOT_I2C #ifdef DIGIPOT_I2C
extern void digipot_i2c_set_current( int channel, float current ); extern void digipot_i2c_set_current( int channel, float current );
extern void digipot_i2c_init(); extern void digipot_i2c_init();
#endif #endif
#endif #endif
//Long pause //Long pause
extern int saved_feedmultiply; extern int saved_feedmultiply;
extern float HotendTempBckp; extern float HotendTempBckp;
extern int fanSpeedBckp; extern int fanSpeedBckp;
extern float pause_lastpos[4]; extern float pause_lastpos[4];
extern unsigned long pause_time; extern unsigned long pause_time;
extern unsigned long start_pause_print; extern unsigned long start_pause_print;
extern bool mesh_bed_leveling_flag; extern bool mesh_bed_leveling_flag;
extern bool mesh_bed_run_from_menu; extern bool mesh_bed_run_from_menu;
extern float distance_from_min[3]; extern float distance_from_min[3];
extern float angleDiff; extern float angleDiff;
extern void calculate_volumetric_multipliers(); extern void calculate_volumetric_multipliers();
// Similar to the default Arduino delay function, // Similar to the default Arduino delay function,
// but it keeps the background tasks running. // but it keeps the background tasks running.
extern void delay_keep_alive(unsigned int ms); extern void delay_keep_alive(unsigned int ms);
extern void check_babystep(); extern void check_babystep();
extern void long_pause(); extern void long_pause();
#ifdef DIS #ifdef DIS
void d_setup(); void d_setup();
float d_ReadData(); float d_ReadData();
void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_points_num, float shift_x, float shift_y); void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_points_num, float shift_x, float shift_y);
#endif #endif
float temp_comp_interpolation(float temperature); float temp_comp_interpolation(float temperature);
void temp_compensation_apply(); void temp_compensation_apply();
void temp_compensation_start(); void temp_compensation_start();
void wait_for_heater(long codenum); void wait_for_heater(long codenum);
void serialecho_temperatures(); void serialecho_temperatures();
extern void save_print_to_eeprom();
extern void restore_print_from_eeprom();
extern void position_menu();

View File

@ -1380,7 +1380,6 @@ void get_command()
continue; continue;
if(serial_char == '\n' || if(serial_char == '\n' ||
serial_char == '\r' || serial_char == '\r' ||
(serial_char == ':' && comment_mode == false) ||
serial_count >= (MAX_CMD_SIZE - 1) ) serial_count >= (MAX_CMD_SIZE - 1) )
{ {
if(!serial_count) { //if empty line if(!serial_count) { //if empty line
@ -3491,6 +3490,7 @@ void process_commands()
starttime=millis(); starttime=millis();
break; break;
case 25: //M25 - Pause SD print case 25: //M25 - Pause SD print
save_print_to_eeprom();
card.pauseSDPrint(); card.pauseSDPrint();
break; break;
case 26: //M26 - Set SD index case 26: //M26 - Set SD index
@ -4379,6 +4379,12 @@ Sigma_Exit:
} }
} }
break; break;
case 110: // M110 - reset line pos
if (code_seen('N'))
gcode_LastN = code_value_long();
else
gcode_LastN = 0;
break;
case 115: // M115 case 115: // M115
if (code_seen('V')) { if (code_seen('V')) {
// Report the Prusa version number. // Report the Prusa version number.
@ -6651,4 +6657,42 @@ void serialecho_temperatures() {
SERIAL_PROTOCOLPGM(" B:"); SERIAL_PROTOCOLPGM(" B:");
SERIAL_PROTOCOL_F(degBed(), 1); SERIAL_PROTOCOL_F(degBed(), 1);
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
} }
void save_print_to_eeprom() {
eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), card.get_sdpos());
}
void restore_print_from_eeprom() {
char cmd[30];
char* c;
char filename[13];
char str[5] = ".gco";
for (int i = 0; i < 8; i++) {
filename[i] = eeprom_read_byte((uint8_t*)EEPROM_FILENAME + i);
}
filename[8] = '\0';
MYSERIAL.print(filename);
strcat(filename, str);
sprintf_P(cmd, PSTR("M23 %s"), filename);
for (c = &cmd[4]; *c; c++)
*c = tolower(*c);
enquecommand(cmd);
uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION));
SERIAL_ECHOPGM("Position read from eeprom:");
MYSERIAL.println(position);
card.setIndex(position);
enquecommand_P(PSTR("M24"));
sprintf_P(cmd, PSTR("M26 S%d"), position);
enquecommand(cmd);
}
void position_menu() {
SERIAL_ECHOPGM("Percent done:");
MYSERIAL.println(card.percentDone());
SERIAL_ECHOPGM("sdpos:");
MYSERIAL.println(card.get_sdpos());
}

File diff suppressed because it is too large Load Diff

View File

@ -1,262 +1,262 @@
/* Arduino Sd2Card Library /* Arduino Sd2Card Library
* Copyright (C) 2009 by William Greiman * Copyright (C) 2009 by William Greiman
* *
* This file is part of the Arduino Sd2Card Library * This file is part of the Arduino Sd2Card Library
* *
* This Library is free software: you can redistribute it and/or modify * This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This Library is distributed in the hope that it will be useful, * This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the Arduino Sd2Card Library. If not, see * along with the Arduino Sd2Card Library. If not, see
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#include "Marlin.h" #include "Marlin.h"
#ifdef SDSUPPORT #ifdef SDSUPPORT
#ifndef Sd2Card_h #ifndef Sd2Card_h
#define Sd2Card_h #define Sd2Card_h
/** /**
* \file * \file
* \brief Sd2Card class for V2 SD/SDHC cards * \brief Sd2Card class for V2 SD/SDHC cards
*/ */
#include "SdFatConfig.h" #include "SdFatConfig.h"
#include "Sd2PinMap.h" #include "Sd2PinMap.h"
#include "SdInfo.h" #include "SdInfo.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// SPI speed is F_CPU/2^(1 + index), 0 <= index <= 6 // SPI speed is F_CPU/2^(1 + index), 0 <= index <= 6
/** Set SCK to max rate of F_CPU/2. See Sd2Card::setSckRate(). */ /** Set SCK to max rate of F_CPU/2. See Sd2Card::setSckRate(). */
uint8_t const SPI_FULL_SPEED = 0; uint8_t const SPI_FULL_SPEED = 0;
/** Set SCK rate to F_CPU/4. See Sd2Card::setSckRate(). */ /** Set SCK rate to F_CPU/4. See Sd2Card::setSckRate(). */
uint8_t const SPI_HALF_SPEED = 1; uint8_t const SPI_HALF_SPEED = 1;
/** Set SCK rate to F_CPU/8. See Sd2Card::setSckRate(). */ /** Set SCK rate to F_CPU/8. See Sd2Card::setSckRate(). */
uint8_t const SPI_QUARTER_SPEED = 2; uint8_t const SPI_QUARTER_SPEED = 2;
/** Set SCK rate to F_CPU/16. See Sd2Card::setSckRate(). */ /** Set SCK rate to F_CPU/16. See Sd2Card::setSckRate(). */
uint8_t const SPI_EIGHTH_SPEED = 3; uint8_t const SPI_EIGHTH_SPEED = 3;
/** Set SCK rate to F_CPU/32. See Sd2Card::setSckRate(). */ /** Set SCK rate to F_CPU/32. See Sd2Card::setSckRate(). */
uint8_t const SPI_SIXTEENTH_SPEED = 4; uint8_t const SPI_SIXTEENTH_SPEED = 4;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** init timeout ms */ /** init timeout ms */
uint16_t const SD_INIT_TIMEOUT = 2000; uint16_t const SD_INIT_TIMEOUT = 2000;
/** erase timeout ms */ /** erase timeout ms */
uint16_t const SD_ERASE_TIMEOUT = 10000; uint16_t const SD_ERASE_TIMEOUT = 10000;
/** read timeout ms */ /** read timeout ms */
uint16_t const SD_READ_TIMEOUT = 300; uint16_t const SD_READ_TIMEOUT = 300;
/** write time out ms */ /** write time out ms */
uint16_t const SD_WRITE_TIMEOUT = 600; uint16_t const SD_WRITE_TIMEOUT = 600;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// SD card errors // SD card errors
/** timeout error for command CMD0 (initialize card in SPI mode) */ /** timeout error for command CMD0 (initialize card in SPI mode) */
uint8_t const SD_CARD_ERROR_CMD0 = 0X1; uint8_t const SD_CARD_ERROR_CMD0 = 0X1;
/** CMD8 was not accepted - not a valid SD card*/ /** CMD8 was not accepted - not a valid SD card*/
uint8_t const SD_CARD_ERROR_CMD8 = 0X2; uint8_t const SD_CARD_ERROR_CMD8 = 0X2;
/** card returned an error response for CMD12 (write stop) */ /** card returned an error response for CMD12 (write stop) */
uint8_t const SD_CARD_ERROR_CMD12 = 0X3; uint8_t const SD_CARD_ERROR_CMD12 = 0X3;
/** card returned an error response for CMD17 (read block) */ /** card returned an error response for CMD17 (read block) */
uint8_t const SD_CARD_ERROR_CMD17 = 0X4; uint8_t const SD_CARD_ERROR_CMD17 = 0X4;
/** card returned an error response for CMD18 (read multiple block) */ /** card returned an error response for CMD18 (read multiple block) */
uint8_t const SD_CARD_ERROR_CMD18 = 0X5; uint8_t const SD_CARD_ERROR_CMD18 = 0X5;
/** card returned an error response for CMD24 (write block) */ /** card returned an error response for CMD24 (write block) */
uint8_t const SD_CARD_ERROR_CMD24 = 0X6; uint8_t const SD_CARD_ERROR_CMD24 = 0X6;
/** WRITE_MULTIPLE_BLOCKS command failed */ /** WRITE_MULTIPLE_BLOCKS command failed */
uint8_t const SD_CARD_ERROR_CMD25 = 0X7; uint8_t const SD_CARD_ERROR_CMD25 = 0X7;
/** card returned an error response for CMD58 (read OCR) */ /** card returned an error response for CMD58 (read OCR) */
uint8_t const SD_CARD_ERROR_CMD58 = 0X8; uint8_t const SD_CARD_ERROR_CMD58 = 0X8;
/** SET_WR_BLK_ERASE_COUNT failed */ /** SET_WR_BLK_ERASE_COUNT failed */
uint8_t const SD_CARD_ERROR_ACMD23 = 0X9; uint8_t const SD_CARD_ERROR_ACMD23 = 0X9;
/** ACMD41 initialization process timeout */ /** ACMD41 initialization process timeout */
uint8_t const SD_CARD_ERROR_ACMD41 = 0XA; uint8_t const SD_CARD_ERROR_ACMD41 = 0XA;
/** card returned a bad CSR version field */ /** card returned a bad CSR version field */
uint8_t const SD_CARD_ERROR_BAD_CSD = 0XB; uint8_t const SD_CARD_ERROR_BAD_CSD = 0XB;
/** erase block group command failed */ /** erase block group command failed */
uint8_t const SD_CARD_ERROR_ERASE = 0XC; uint8_t const SD_CARD_ERROR_ERASE = 0XC;
/** card not capable of single block erase */ /** card not capable of single block erase */
uint8_t const SD_CARD_ERROR_ERASE_SINGLE_BLOCK = 0XD; uint8_t const SD_CARD_ERROR_ERASE_SINGLE_BLOCK = 0XD;
/** Erase sequence timed out */ /** Erase sequence timed out */
uint8_t const SD_CARD_ERROR_ERASE_TIMEOUT = 0XE; uint8_t const SD_CARD_ERROR_ERASE_TIMEOUT = 0XE;
/** card returned an error token instead of read data */ /** card returned an error token instead of read data */
uint8_t const SD_CARD_ERROR_READ = 0XF; uint8_t const SD_CARD_ERROR_READ = 0XF;
/** read CID or CSD failed */ /** read CID or CSD failed */
uint8_t const SD_CARD_ERROR_READ_REG = 0X10; uint8_t const SD_CARD_ERROR_READ_REG = 0X10;
/** timeout while waiting for start of read data */ /** timeout while waiting for start of read data */
uint8_t const SD_CARD_ERROR_READ_TIMEOUT = 0X11; uint8_t const SD_CARD_ERROR_READ_TIMEOUT = 0X11;
/** card did not accept STOP_TRAN_TOKEN */ /** card did not accept STOP_TRAN_TOKEN */
uint8_t const SD_CARD_ERROR_STOP_TRAN = 0X12; uint8_t const SD_CARD_ERROR_STOP_TRAN = 0X12;
/** card returned an error token as a response to a write operation */ /** card returned an error token as a response to a write operation */
uint8_t const SD_CARD_ERROR_WRITE = 0X13; uint8_t const SD_CARD_ERROR_WRITE = 0X13;
/** attempt to write protected block zero */ /** attempt to write protected block zero */
uint8_t const SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0X14; // REMOVE - not used uint8_t const SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0X14; // REMOVE - not used
/** card did not go ready for a multiple block write */ /** card did not go ready for a multiple block write */
uint8_t const SD_CARD_ERROR_WRITE_MULTIPLE = 0X15; uint8_t const SD_CARD_ERROR_WRITE_MULTIPLE = 0X15;
/** card returned an error to a CMD13 status check after a write */ /** card returned an error to a CMD13 status check after a write */
uint8_t const SD_CARD_ERROR_WRITE_PROGRAMMING = 0X16; uint8_t const SD_CARD_ERROR_WRITE_PROGRAMMING = 0X16;
/** timeout occurred during write programming */ /** timeout occurred during write programming */
uint8_t const SD_CARD_ERROR_WRITE_TIMEOUT = 0X17; uint8_t const SD_CARD_ERROR_WRITE_TIMEOUT = 0X17;
/** incorrect rate selected */ /** incorrect rate selected */
uint8_t const SD_CARD_ERROR_SCK_RATE = 0X18; uint8_t const SD_CARD_ERROR_SCK_RATE = 0X18;
/** init() not called */ /** init() not called */
uint8_t const SD_CARD_ERROR_INIT_NOT_CALLED = 0X19; uint8_t const SD_CARD_ERROR_INIT_NOT_CALLED = 0X19;
/** crc check error */ /** crc check error */
uint8_t const SD_CARD_ERROR_CRC = 0X20; uint8_t const SD_CARD_ERROR_CRC = 0X20;
/** Toshiba FlashAir: iSDIO */ /** Toshiba FlashAir: iSDIO */
uint8_t const SD_CARD_ERROR_CMD48 = 0x80; uint8_t const SD_CARD_ERROR_CMD48 = 0x80;
/** Toshiba FlashAir: iSDIO */ /** Toshiba FlashAir: iSDIO */
uint8_t const SD_CARD_ERROR_CMD49 = 0x81; uint8_t const SD_CARD_ERROR_CMD49 = 0x81;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// card types // card types
/** Standard capacity V1 SD card */ /** Standard capacity V1 SD card */
uint8_t const SD_CARD_TYPE_SD1 = 1; uint8_t const SD_CARD_TYPE_SD1 = 1;
/** Standard capacity V2 SD card */ /** Standard capacity V2 SD card */
uint8_t const SD_CARD_TYPE_SD2 = 2; uint8_t const SD_CARD_TYPE_SD2 = 2;
/** High Capacity SD card */ /** High Capacity SD card */
uint8_t const SD_CARD_TYPE_SDHC = 3; uint8_t const SD_CARD_TYPE_SDHC = 3;
/** /**
* define SOFTWARE_SPI to use bit-bang SPI * define SOFTWARE_SPI to use bit-bang SPI
*/ */
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if MEGA_SOFT_SPI && (defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__)) #if MEGA_SOFT_SPI && (defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__))
#define SOFTWARE_SPI #define SOFTWARE_SPI
#elif USE_SOFTWARE_SPI #elif USE_SOFTWARE_SPI
#define SOFTWARE_SPI #define SOFTWARE_SPI
#endif // MEGA_SOFT_SPI #endif // MEGA_SOFT_SPI
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// SPI pin definitions - do not edit here - change in SdFatConfig.h // SPI pin definitions - do not edit here - change in SdFatConfig.h
// //
#ifndef SOFTWARE_SPI #ifndef SOFTWARE_SPI
// hardware pin defs // hardware pin defs
/** The default chip select pin for the SD card is SS. */ /** The default chip select pin for the SD card is SS. */
uint8_t const SD_CHIP_SELECT_PIN = SS_PIN; uint8_t const SD_CHIP_SELECT_PIN = SS_PIN;
// The following three pins must not be redefined for hardware SPI. // The following three pins must not be redefined for hardware SPI.
/** SPI Master Out Slave In pin */ /** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = MOSI_PIN; uint8_t const SPI_MOSI_PIN = MOSI_PIN;
/** SPI Master In Slave Out pin */ /** SPI Master In Slave Out pin */
uint8_t const SPI_MISO_PIN = MISO_PIN; uint8_t const SPI_MISO_PIN = MISO_PIN;
/** SPI Clock pin */ /** SPI Clock pin */
uint8_t const SPI_SCK_PIN = SCK_PIN; uint8_t const SPI_SCK_PIN = SCK_PIN;
#else // SOFTWARE_SPI #else // SOFTWARE_SPI
/** SPI chip select pin */ /** SPI chip select pin */
uint8_t const SD_CHIP_SELECT_PIN = SOFT_SPI_CS_PIN; uint8_t const SD_CHIP_SELECT_PIN = SOFT_SPI_CS_PIN;
/** SPI Master Out Slave In pin */ /** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = SOFT_SPI_MOSI_PIN; uint8_t const SPI_MOSI_PIN = SOFT_SPI_MOSI_PIN;
/** SPI Master In Slave Out pin */ /** SPI Master In Slave Out pin */
uint8_t const SPI_MISO_PIN = SOFT_SPI_MISO_PIN; uint8_t const SPI_MISO_PIN = SOFT_SPI_MISO_PIN;
/** SPI Clock pin */ /** SPI Clock pin */
uint8_t const SPI_SCK_PIN = SOFT_SPI_SCK_PIN; uint8_t const SPI_SCK_PIN = SOFT_SPI_SCK_PIN;
#endif // SOFTWARE_SPI #endif // SOFTWARE_SPI
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** /**
* \class Sd2Card * \class Sd2Card
* \brief Raw access to SD and SDHC flash memory cards. * \brief Raw access to SD and SDHC flash memory cards.
*/ */
class Sd2Card { class Sd2Card {
public: public:
/** Construct an instance of Sd2Card. */ /** Construct an instance of Sd2Card. */
Sd2Card() : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0), flash_air_compatible_(false) {} Sd2Card() : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0), flash_air_compatible_(false) {}
uint32_t cardSize(); uint32_t cardSize();
bool erase(uint32_t firstBlock, uint32_t lastBlock); bool erase(uint32_t firstBlock, uint32_t lastBlock);
bool eraseSingleBlockEnable(); bool eraseSingleBlockEnable();
/** /**
* Set SD error code. * Set SD error code.
* \param[in] code value for error code. * \param[in] code value for error code.
*/ */
void error(uint8_t code) {errorCode_ = code;} void error(uint8_t code) {errorCode_ = code;}
/** /**
* \return error code for last error. See Sd2Card.h for a list of error codes. * \return error code for last error. See Sd2Card.h for a list of error codes.
*/ */
int errorCode() const {return errorCode_;} int errorCode() const {return errorCode_;}
/** \return error data for last error. */ /** \return error data for last error. */
int errorData() const {return status_;} int errorData() const {return status_;}
/** /**
* Initialize an SD flash memory card with default clock rate and chip * Initialize an SD flash memory card with default clock rate and chip
* select pin. See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin). * select pin. See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
* *
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool init(uint8_t sckRateID = SPI_FULL_SPEED, bool init(uint8_t sckRateID = SPI_FULL_SPEED,
uint8_t chipSelectPin = SD_CHIP_SELECT_PIN); uint8_t chipSelectPin = SD_CHIP_SELECT_PIN);
bool readBlock(uint32_t block, uint8_t* dst); bool readBlock(uint32_t block, uint8_t* dst);
/** /**
* Read a card's CID register. The CID contains card identification * Read a card's CID register. The CID contains card identification
* information such as Manufacturer ID, Product name, Product serial * information such as Manufacturer ID, Product name, Product serial
* number and Manufacturing date. * number and Manufacturing date.
* *
* \param[out] cid pointer to area for returned data. * \param[out] cid pointer to area for returned data.
* *
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool readCID(cid_t* cid) { bool readCID(cid_t* cid) {
return readRegister(CMD10, cid); return readRegister(CMD10, cid);
} }
/** /**
* Read a card's CSD register. The CSD contains Card-Specific Data that * Read a card's CSD register. The CSD contains Card-Specific Data that
* provides information regarding access to the card's contents. * provides information regarding access to the card's contents.
* *
* \param[out] csd pointer to area for returned data. * \param[out] csd pointer to area for returned data.
* *
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool readCSD(csd_t* csd) { bool readCSD(csd_t* csd) {
return readRegister(CMD9, csd); return readRegister(CMD9, csd);
} }
bool readData(uint8_t *dst); bool readData(uint8_t *dst);
bool readStart(uint32_t blockNumber); bool readStart(uint32_t blockNumber);
bool readStop(); bool readStop();
bool setSckRate(uint8_t sckRateID); bool setSckRate(uint8_t sckRateID);
/** Return the card type: SD V1, SD V2 or SDHC /** Return the card type: SD V1, SD V2 or SDHC
* \return 0 - SD V1, 1 - SD V2, or 3 - SDHC. * \return 0 - SD V1, 1 - SD V2, or 3 - SDHC.
*/ */
int type() const {return type_;} int type() const {return type_;}
bool writeBlock(uint32_t blockNumber, const uint8_t* src); bool writeBlock(uint32_t blockNumber, const uint8_t* src);
bool writeData(const uint8_t* src); bool writeData(const uint8_t* src);
bool writeStart(uint32_t blockNumber, uint32_t eraseCount); bool writeStart(uint32_t blockNumber, uint32_t eraseCount);
bool writeStop(); bool writeStop();
// Toshiba FlashAir support // Toshiba FlashAir support
uint8_t readExtMemory(uint8_t mio, uint8_t func, uint32_t addr, uint16_t count, uint8_t* dst); uint8_t readExtMemory(uint8_t mio, uint8_t func, uint32_t addr, uint16_t count, uint8_t* dst);
void setFlashAirCompatible(bool flashAirCompatible) { flash_air_compatible_ = flashAirCompatible; } void setFlashAirCompatible(bool flashAirCompatible) { flash_air_compatible_ = flashAirCompatible; }
bool getFlashAirCompatible() const { return flash_air_compatible_; } bool getFlashAirCompatible() const { return flash_air_compatible_; }
private: private:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
uint8_t chipSelectPin_; uint8_t chipSelectPin_;
uint8_t errorCode_; uint8_t errorCode_;
uint8_t spiRate_; uint8_t spiRate_;
uint8_t status_; uint8_t status_;
uint8_t type_; uint8_t type_;
bool flash_air_compatible_; bool flash_air_compatible_;
// private functions // private functions
uint8_t cardAcmd(uint8_t cmd, uint32_t arg) { uint8_t cardAcmd(uint8_t cmd, uint32_t arg) {
cardCommand(CMD55, 0); cardCommand(CMD55, 0);
return cardCommand(cmd, arg); return cardCommand(cmd, arg);
} }
uint8_t cardCommand(uint8_t cmd, uint32_t arg); uint8_t cardCommand(uint8_t cmd, uint32_t arg);
bool readData(uint8_t* dst, uint16_t count); bool readData(uint8_t* dst, uint16_t count);
bool readRegister(uint8_t cmd, void* buf); bool readRegister(uint8_t cmd, void* buf);
void chipSelectHigh(); void chipSelectHigh();
void chipSelectLow(); void chipSelectLow();
void type(uint8_t value) {type_ = value;} void type(uint8_t value) {type_ = value;}
bool waitNotBusy(uint16_t timeoutMillis); bool waitNotBusy(uint16_t timeoutMillis);
bool writeData(uint8_t token, const uint8_t* src); bool writeData(uint8_t token, const uint8_t* src);
// Toshiba FlashAir support // Toshiba FlashAir support
uint8_t waitStartBlock(void); uint8_t waitStartBlock(void);
uint8_t readExt(uint32_t arg, uint8_t* dst, uint16_t count); uint8_t readExt(uint32_t arg, uint8_t* dst, uint16_t count);
}; };
#endif // Sd2Card_h #endif // Sd2Card_h
#endif #endif

View File

@ -1,368 +1,368 @@
/* Arduino SdFat Library /* Arduino SdFat Library
* Copyright (C) 2010 by William Greiman * Copyright (C) 2010 by William Greiman
* *
* This file is part of the Arduino SdFat Library * This file is part of the Arduino SdFat Library
* *
* This Library is free software: you can redistribute it and/or modify * This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This Library is distributed in the hope that it will be useful, * This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the Arduino SdFat Library. If not, see * along with the Arduino SdFat Library. If not, see
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
// Warning this file was generated by a program. // Warning this file was generated by a program.
#include "Marlin.h" #include "Marlin.h"
#ifdef SDSUPPORT #ifdef SDSUPPORT
#ifndef Sd2PinMap_h #ifndef Sd2PinMap_h
#define Sd2PinMap_h #define Sd2PinMap_h
#include <avr/io.h> #include <avr/io.h>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** struct for mapping digital pins */ /** struct for mapping digital pins */
struct pin_map_t { struct pin_map_t {
volatile uint8_t* ddr; volatile uint8_t* ddr;
volatile uint8_t* pin; volatile uint8_t* pin;
volatile uint8_t* port; volatile uint8_t* port;
uint8_t bit; uint8_t bit;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if defined(__AVR_ATmega1280__)\ #if defined(__AVR_ATmega1280__)\
|| defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2560__)
// Mega // Mega
// Two Wire (aka I2C) ports // Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 20; // D1 uint8_t const SDA_PIN = 20; // D1
uint8_t const SCL_PIN = 21; // D0 uint8_t const SCL_PIN = 21; // D0
#undef MOSI_PIN #undef MOSI_PIN
#undef MISO_PIN #undef MISO_PIN
// SPI port // SPI port
uint8_t const SS_PIN = 53; // B0 uint8_t const SS_PIN = 53; // B0
uint8_t const MOSI_PIN = 51; // B2 uint8_t const MOSI_PIN = 51; // B2
uint8_t const MISO_PIN = 50; // B3 uint8_t const MISO_PIN = 50; // B3
uint8_t const SCK_PIN = 52; // B1 uint8_t const SCK_PIN = 52; // B1
static const pin_map_t digitalPinMap[] = { static const pin_map_t digitalPinMap[] = {
{&DDRE, &PINE, &PORTE, 0}, // E0 0 {&DDRE, &PINE, &PORTE, 0}, // E0 0
{&DDRE, &PINE, &PORTE, 1}, // E1 1 {&DDRE, &PINE, &PORTE, 1}, // E1 1
{&DDRE, &PINE, &PORTE, 4}, // E4 2 {&DDRE, &PINE, &PORTE, 4}, // E4 2
{&DDRE, &PINE, &PORTE, 5}, // E5 3 {&DDRE, &PINE, &PORTE, 5}, // E5 3
{&DDRG, &PING, &PORTG, 5}, // G5 4 {&DDRG, &PING, &PORTG, 5}, // G5 4
{&DDRE, &PINE, &PORTE, 3}, // E3 5 {&DDRE, &PINE, &PORTE, 3}, // E3 5
{&DDRH, &PINH, &PORTH, 3}, // H3 6 {&DDRH, &PINH, &PORTH, 3}, // H3 6
{&DDRH, &PINH, &PORTH, 4}, // H4 7 {&DDRH, &PINH, &PORTH, 4}, // H4 7
{&DDRH, &PINH, &PORTH, 5}, // H5 8 {&DDRH, &PINH, &PORTH, 5}, // H5 8
{&DDRH, &PINH, &PORTH, 6}, // H6 9 {&DDRH, &PINH, &PORTH, 6}, // H6 9
{&DDRB, &PINB, &PORTB, 4}, // B4 10 {&DDRB, &PINB, &PORTB, 4}, // B4 10
{&DDRB, &PINB, &PORTB, 5}, // B5 11 {&DDRB, &PINB, &PORTB, 5}, // B5 11
{&DDRB, &PINB, &PORTB, 6}, // B6 12 {&DDRB, &PINB, &PORTB, 6}, // B6 12
{&DDRB, &PINB, &PORTB, 7}, // B7 13 {&DDRB, &PINB, &PORTB, 7}, // B7 13
{&DDRJ, &PINJ, &PORTJ, 1}, // J1 14 {&DDRJ, &PINJ, &PORTJ, 1}, // J1 14
{&DDRJ, &PINJ, &PORTJ, 0}, // J0 15 {&DDRJ, &PINJ, &PORTJ, 0}, // J0 15
{&DDRH, &PINH, &PORTH, 1}, // H1 16 {&DDRH, &PINH, &PORTH, 1}, // H1 16
{&DDRH, &PINH, &PORTH, 0}, // H0 17 {&DDRH, &PINH, &PORTH, 0}, // H0 17
{&DDRD, &PIND, &PORTD, 3}, // D3 18 {&DDRD, &PIND, &PORTD, 3}, // D3 18
{&DDRD, &PIND, &PORTD, 2}, // D2 19 {&DDRD, &PIND, &PORTD, 2}, // D2 19
{&DDRD, &PIND, &PORTD, 1}, // D1 20 {&DDRD, &PIND, &PORTD, 1}, // D1 20
{&DDRD, &PIND, &PORTD, 0}, // D0 21 {&DDRD, &PIND, &PORTD, 0}, // D0 21
{&DDRA, &PINA, &PORTA, 0}, // A0 22 {&DDRA, &PINA, &PORTA, 0}, // A0 22
{&DDRA, &PINA, &PORTA, 1}, // A1 23 {&DDRA, &PINA, &PORTA, 1}, // A1 23
{&DDRA, &PINA, &PORTA, 2}, // A2 24 {&DDRA, &PINA, &PORTA, 2}, // A2 24
{&DDRA, &PINA, &PORTA, 3}, // A3 25 {&DDRA, &PINA, &PORTA, 3}, // A3 25
{&DDRA, &PINA, &PORTA, 4}, // A4 26 {&DDRA, &PINA, &PORTA, 4}, // A4 26
{&DDRA, &PINA, &PORTA, 5}, // A5 27 {&DDRA, &PINA, &PORTA, 5}, // A5 27
{&DDRA, &PINA, &PORTA, 6}, // A6 28 {&DDRA, &PINA, &PORTA, 6}, // A6 28
{&DDRA, &PINA, &PORTA, 7}, // A7 29 {&DDRA, &PINA, &PORTA, 7}, // A7 29
{&DDRC, &PINC, &PORTC, 7}, // C7 30 {&DDRC, &PINC, &PORTC, 7}, // C7 30
{&DDRC, &PINC, &PORTC, 6}, // C6 31 {&DDRC, &PINC, &PORTC, 6}, // C6 31
{&DDRC, &PINC, &PORTC, 5}, // C5 32 {&DDRC, &PINC, &PORTC, 5}, // C5 32
{&DDRC, &PINC, &PORTC, 4}, // C4 33 {&DDRC, &PINC, &PORTC, 4}, // C4 33
{&DDRC, &PINC, &PORTC, 3}, // C3 34 {&DDRC, &PINC, &PORTC, 3}, // C3 34
{&DDRC, &PINC, &PORTC, 2}, // C2 35 {&DDRC, &PINC, &PORTC, 2}, // C2 35
{&DDRC, &PINC, &PORTC, 1}, // C1 36 {&DDRC, &PINC, &PORTC, 1}, // C1 36
{&DDRC, &PINC, &PORTC, 0}, // C0 37 {&DDRC, &PINC, &PORTC, 0}, // C0 37
{&DDRD, &PIND, &PORTD, 7}, // D7 38 {&DDRD, &PIND, &PORTD, 7}, // D7 38
{&DDRG, &PING, &PORTG, 2}, // G2 39 {&DDRG, &PING, &PORTG, 2}, // G2 39
{&DDRG, &PING, &PORTG, 1}, // G1 40 {&DDRG, &PING, &PORTG, 1}, // G1 40
{&DDRG, &PING, &PORTG, 0}, // G0 41 {&DDRG, &PING, &PORTG, 0}, // G0 41
{&DDRL, &PINL, &PORTL, 7}, // L7 42 {&DDRL, &PINL, &PORTL, 7}, // L7 42
{&DDRL, &PINL, &PORTL, 6}, // L6 43 {&DDRL, &PINL, &PORTL, 6}, // L6 43
{&DDRL, &PINL, &PORTL, 5}, // L5 44 {&DDRL, &PINL, &PORTL, 5}, // L5 44
{&DDRL, &PINL, &PORTL, 4}, // L4 45 {&DDRL, &PINL, &PORTL, 4}, // L4 45
{&DDRL, &PINL, &PORTL, 3}, // L3 46 {&DDRL, &PINL, &PORTL, 3}, // L3 46
{&DDRL, &PINL, &PORTL, 2}, // L2 47 {&DDRL, &PINL, &PORTL, 2}, // L2 47
{&DDRL, &PINL, &PORTL, 1}, // L1 48 {&DDRL, &PINL, &PORTL, 1}, // L1 48
{&DDRL, &PINL, &PORTL, 0}, // L0 49 {&DDRL, &PINL, &PORTL, 0}, // L0 49
{&DDRB, &PINB, &PORTB, 3}, // B3 50 {&DDRB, &PINB, &PORTB, 3}, // B3 50
{&DDRB, &PINB, &PORTB, 2}, // B2 51 {&DDRB, &PINB, &PORTB, 2}, // B2 51
{&DDRB, &PINB, &PORTB, 1}, // B1 52 {&DDRB, &PINB, &PORTB, 1}, // B1 52
{&DDRB, &PINB, &PORTB, 0}, // B0 53 {&DDRB, &PINB, &PORTB, 0}, // B0 53
{&DDRF, &PINF, &PORTF, 0}, // F0 54 {&DDRF, &PINF, &PORTF, 0}, // F0 54
{&DDRF, &PINF, &PORTF, 1}, // F1 55 {&DDRF, &PINF, &PORTF, 1}, // F1 55
{&DDRF, &PINF, &PORTF, 2}, // F2 56 {&DDRF, &PINF, &PORTF, 2}, // F2 56
{&DDRF, &PINF, &PORTF, 3}, // F3 57 {&DDRF, &PINF, &PORTF, 3}, // F3 57
{&DDRF, &PINF, &PORTF, 4}, // F4 58 {&DDRF, &PINF, &PORTF, 4}, // F4 58
{&DDRF, &PINF, &PORTF, 5}, // F5 59 {&DDRF, &PINF, &PORTF, 5}, // F5 59
{&DDRF, &PINF, &PORTF, 6}, // F6 60 {&DDRF, &PINF, &PORTF, 6}, // F6 60
{&DDRF, &PINF, &PORTF, 7}, // F7 61 {&DDRF, &PINF, &PORTF, 7}, // F7 61
{&DDRK, &PINK, &PORTK, 0}, // K0 62 {&DDRK, &PINK, &PORTK, 0}, // K0 62
{&DDRK, &PINK, &PORTK, 1}, // K1 63 {&DDRK, &PINK, &PORTK, 1}, // K1 63
{&DDRK, &PINK, &PORTK, 2}, // K2 64 {&DDRK, &PINK, &PORTK, 2}, // K2 64
{&DDRK, &PINK, &PORTK, 3}, // K3 65 {&DDRK, &PINK, &PORTK, 3}, // K3 65
{&DDRK, &PINK, &PORTK, 4}, // K4 66 {&DDRK, &PINK, &PORTK, 4}, // K4 66
{&DDRK, &PINK, &PORTK, 5}, // K5 67 {&DDRK, &PINK, &PORTK, 5}, // K5 67
{&DDRK, &PINK, &PORTK, 6}, // K6 68 {&DDRK, &PINK, &PORTK, 6}, // K6 68
{&DDRK, &PINK, &PORTK, 7} // K7 69 {&DDRK, &PINK, &PORTK, 7} // K7 69
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#elif defined(__AVR_ATmega644P__)\ #elif defined(__AVR_ATmega644P__)\
|| defined(__AVR_ATmega644__)\ || defined(__AVR_ATmega644__)\
|| defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284P__)
// Sanguino // Sanguino
// Two Wire (aka I2C) ports // Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 17; // C1 uint8_t const SDA_PIN = 17; // C1
uint8_t const SCL_PIN = 18; // C2 uint8_t const SCL_PIN = 18; // C2
// SPI port // SPI port
uint8_t const SS_PIN = 4; // B4 uint8_t const SS_PIN = 4; // B4
uint8_t const MOSI_PIN = 5; // B5 uint8_t const MOSI_PIN = 5; // B5
uint8_t const MISO_PIN = 6; // B6 uint8_t const MISO_PIN = 6; // B6
uint8_t const SCK_PIN = 7; // B7 uint8_t const SCK_PIN = 7; // B7
static const pin_map_t digitalPinMap[] = { static const pin_map_t digitalPinMap[] = {
{&DDRB, &PINB, &PORTB, 0}, // B0 0 {&DDRB, &PINB, &PORTB, 0}, // B0 0
{&DDRB, &PINB, &PORTB, 1}, // B1 1 {&DDRB, &PINB, &PORTB, 1}, // B1 1
{&DDRB, &PINB, &PORTB, 2}, // B2 2 {&DDRB, &PINB, &PORTB, 2}, // B2 2
{&DDRB, &PINB, &PORTB, 3}, // B3 3 {&DDRB, &PINB, &PORTB, 3}, // B3 3
{&DDRB, &PINB, &PORTB, 4}, // B4 4 {&DDRB, &PINB, &PORTB, 4}, // B4 4
{&DDRB, &PINB, &PORTB, 5}, // B5 5 {&DDRB, &PINB, &PORTB, 5}, // B5 5
{&DDRB, &PINB, &PORTB, 6}, // B6 6 {&DDRB, &PINB, &PORTB, 6}, // B6 6
{&DDRB, &PINB, &PORTB, 7}, // B7 7 {&DDRB, &PINB, &PORTB, 7}, // B7 7
{&DDRD, &PIND, &PORTD, 0}, // D0 8 {&DDRD, &PIND, &PORTD, 0}, // D0 8
{&DDRD, &PIND, &PORTD, 1}, // D1 9 {&DDRD, &PIND, &PORTD, 1}, // D1 9
{&DDRD, &PIND, &PORTD, 2}, // D2 10 {&DDRD, &PIND, &PORTD, 2}, // D2 10
{&DDRD, &PIND, &PORTD, 3}, // D3 11 {&DDRD, &PIND, &PORTD, 3}, // D3 11
{&DDRD, &PIND, &PORTD, 4}, // D4 12 {&DDRD, &PIND, &PORTD, 4}, // D4 12
{&DDRD, &PIND, &PORTD, 5}, // D5 13 {&DDRD, &PIND, &PORTD, 5}, // D5 13
{&DDRD, &PIND, &PORTD, 6}, // D6 14 {&DDRD, &PIND, &PORTD, 6}, // D6 14
{&DDRD, &PIND, &PORTD, 7}, // D7 15 {&DDRD, &PIND, &PORTD, 7}, // D7 15
{&DDRC, &PINC, &PORTC, 0}, // C0 16 {&DDRC, &PINC, &PORTC, 0}, // C0 16
{&DDRC, &PINC, &PORTC, 1}, // C1 17 {&DDRC, &PINC, &PORTC, 1}, // C1 17
{&DDRC, &PINC, &PORTC, 2}, // C2 18 {&DDRC, &PINC, &PORTC, 2}, // C2 18
{&DDRC, &PINC, &PORTC, 3}, // C3 19 {&DDRC, &PINC, &PORTC, 3}, // C3 19
{&DDRC, &PINC, &PORTC, 4}, // C4 20 {&DDRC, &PINC, &PORTC, 4}, // C4 20
{&DDRC, &PINC, &PORTC, 5}, // C5 21 {&DDRC, &PINC, &PORTC, 5}, // C5 21
{&DDRC, &PINC, &PORTC, 6}, // C6 22 {&DDRC, &PINC, &PORTC, 6}, // C6 22
{&DDRC, &PINC, &PORTC, 7}, // C7 23 {&DDRC, &PINC, &PORTC, 7}, // C7 23
{&DDRA, &PINA, &PORTA, 7}, // A7 24 {&DDRA, &PINA, &PORTA, 7}, // A7 24
{&DDRA, &PINA, &PORTA, 6}, // A6 25 {&DDRA, &PINA, &PORTA, 6}, // A6 25
{&DDRA, &PINA, &PORTA, 5}, // A5 26 {&DDRA, &PINA, &PORTA, 5}, // A5 26
{&DDRA, &PINA, &PORTA, 4}, // A4 27 {&DDRA, &PINA, &PORTA, 4}, // A4 27
{&DDRA, &PINA, &PORTA, 3}, // A3 28 {&DDRA, &PINA, &PORTA, 3}, // A3 28
{&DDRA, &PINA, &PORTA, 2}, // A2 29 {&DDRA, &PINA, &PORTA, 2}, // A2 29
{&DDRA, &PINA, &PORTA, 1}, // A1 30 {&DDRA, &PINA, &PORTA, 1}, // A1 30
{&DDRA, &PINA, &PORTA, 0} // A0 31 {&DDRA, &PINA, &PORTA, 0} // A0 31
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#elif defined(__AVR_ATmega32U4__) #elif defined(__AVR_ATmega32U4__)
// Teensy 2.0 // Teensy 2.0
// Two Wire (aka I2C) ports // Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 6; // D1 uint8_t const SDA_PIN = 6; // D1
uint8_t const SCL_PIN = 5; // D0 uint8_t const SCL_PIN = 5; // D0
// SPI port // SPI port
uint8_t const SS_PIN = 0; // B0 uint8_t const SS_PIN = 0; // B0
uint8_t const MOSI_PIN = 2; // B2 uint8_t const MOSI_PIN = 2; // B2
uint8_t const MISO_PIN = 3; // B3 uint8_t const MISO_PIN = 3; // B3
uint8_t const SCK_PIN = 1; // B1 uint8_t const SCK_PIN = 1; // B1
static const pin_map_t digitalPinMap[] = { static const pin_map_t digitalPinMap[] = {
{&DDRB, &PINB, &PORTB, 0}, // B0 0 {&DDRB, &PINB, &PORTB, 0}, // B0 0
{&DDRB, &PINB, &PORTB, 1}, // B1 1 {&DDRB, &PINB, &PORTB, 1}, // B1 1
{&DDRB, &PINB, &PORTB, 2}, // B2 2 {&DDRB, &PINB, &PORTB, 2}, // B2 2
{&DDRB, &PINB, &PORTB, 3}, // B3 3 {&DDRB, &PINB, &PORTB, 3}, // B3 3
{&DDRB, &PINB, &PORTB, 7}, // B7 4 {&DDRB, &PINB, &PORTB, 7}, // B7 4
{&DDRD, &PIND, &PORTD, 0}, // D0 5 {&DDRD, &PIND, &PORTD, 0}, // D0 5
{&DDRD, &PIND, &PORTD, 1}, // D1 6 {&DDRD, &PIND, &PORTD, 1}, // D1 6
{&DDRD, &PIND, &PORTD, 2}, // D2 7 {&DDRD, &PIND, &PORTD, 2}, // D2 7
{&DDRD, &PIND, &PORTD, 3}, // D3 8 {&DDRD, &PIND, &PORTD, 3}, // D3 8
{&DDRC, &PINC, &PORTC, 6}, // C6 9 {&DDRC, &PINC, &PORTC, 6}, // C6 9
{&DDRC, &PINC, &PORTC, 7}, // C7 10 {&DDRC, &PINC, &PORTC, 7}, // C7 10
{&DDRD, &PIND, &PORTD, 6}, // D6 11 {&DDRD, &PIND, &PORTD, 6}, // D6 11
{&DDRD, &PIND, &PORTD, 7}, // D7 12 {&DDRD, &PIND, &PORTD, 7}, // D7 12
{&DDRB, &PINB, &PORTB, 4}, // B4 13 {&DDRB, &PINB, &PORTB, 4}, // B4 13
{&DDRB, &PINB, &PORTB, 5}, // B5 14 {&DDRB, &PINB, &PORTB, 5}, // B5 14
{&DDRB, &PINB, &PORTB, 6}, // B6 15 {&DDRB, &PINB, &PORTB, 6}, // B6 15
{&DDRF, &PINF, &PORTF, 7}, // F7 16 {&DDRF, &PINF, &PORTF, 7}, // F7 16
{&DDRF, &PINF, &PORTF, 6}, // F6 17 {&DDRF, &PINF, &PORTF, 6}, // F6 17
{&DDRF, &PINF, &PORTF, 5}, // F5 18 {&DDRF, &PINF, &PORTF, 5}, // F5 18
{&DDRF, &PINF, &PORTF, 4}, // F4 19 {&DDRF, &PINF, &PORTF, 4}, // F4 19
{&DDRF, &PINF, &PORTF, 1}, // F1 20 {&DDRF, &PINF, &PORTF, 1}, // F1 20
{&DDRF, &PINF, &PORTF, 0}, // F0 21 {&DDRF, &PINF, &PORTF, 0}, // F0 21
{&DDRD, &PIND, &PORTD, 4}, // D4 22 {&DDRD, &PIND, &PORTD, 4}, // D4 22
{&DDRD, &PIND, &PORTD, 5}, // D5 23 {&DDRD, &PIND, &PORTD, 5}, // D5 23
{&DDRE, &PINE, &PORTE, 6} // E6 24 {&DDRE, &PINE, &PORTE, 6} // E6 24
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#elif defined(__AVR_AT90USB646__)\ #elif defined(__AVR_AT90USB646__)\
|| defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286__)
// Teensy++ 1.0 & 2.0 // Teensy++ 1.0 & 2.0
// Two Wire (aka I2C) ports // Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 1; // D1 uint8_t const SDA_PIN = 1; // D1
uint8_t const SCL_PIN = 0; // D0 uint8_t const SCL_PIN = 0; // D0
// SPI port // SPI port
uint8_t const SS_PIN = 20; // B0 uint8_t const SS_PIN = 20; // B0
uint8_t const MOSI_PIN = 22; // B2 uint8_t const MOSI_PIN = 22; // B2
uint8_t const MISO_PIN = 23; // B3 uint8_t const MISO_PIN = 23; // B3
uint8_t const SCK_PIN = 21; // B1 uint8_t const SCK_PIN = 21; // B1
static const pin_map_t digitalPinMap[] = { static const pin_map_t digitalPinMap[] = {
{&DDRD, &PIND, &PORTD, 0}, // D0 0 {&DDRD, &PIND, &PORTD, 0}, // D0 0
{&DDRD, &PIND, &PORTD, 1}, // D1 1 {&DDRD, &PIND, &PORTD, 1}, // D1 1
{&DDRD, &PIND, &PORTD, 2}, // D2 2 {&DDRD, &PIND, &PORTD, 2}, // D2 2
{&DDRD, &PIND, &PORTD, 3}, // D3 3 {&DDRD, &PIND, &PORTD, 3}, // D3 3
{&DDRD, &PIND, &PORTD, 4}, // D4 4 {&DDRD, &PIND, &PORTD, 4}, // D4 4
{&DDRD, &PIND, &PORTD, 5}, // D5 5 {&DDRD, &PIND, &PORTD, 5}, // D5 5
{&DDRD, &PIND, &PORTD, 6}, // D6 6 {&DDRD, &PIND, &PORTD, 6}, // D6 6
{&DDRD, &PIND, &PORTD, 7}, // D7 7 {&DDRD, &PIND, &PORTD, 7}, // D7 7
{&DDRE, &PINE, &PORTE, 0}, // E0 8 {&DDRE, &PINE, &PORTE, 0}, // E0 8
{&DDRE, &PINE, &PORTE, 1}, // E1 9 {&DDRE, &PINE, &PORTE, 1}, // E1 9
{&DDRC, &PINC, &PORTC, 0}, // C0 10 {&DDRC, &PINC, &PORTC, 0}, // C0 10
{&DDRC, &PINC, &PORTC, 1}, // C1 11 {&DDRC, &PINC, &PORTC, 1}, // C1 11
{&DDRC, &PINC, &PORTC, 2}, // C2 12 {&DDRC, &PINC, &PORTC, 2}, // C2 12
{&DDRC, &PINC, &PORTC, 3}, // C3 13 {&DDRC, &PINC, &PORTC, 3}, // C3 13
{&DDRC, &PINC, &PORTC, 4}, // C4 14 {&DDRC, &PINC, &PORTC, 4}, // C4 14
{&DDRC, &PINC, &PORTC, 5}, // C5 15 {&DDRC, &PINC, &PORTC, 5}, // C5 15
{&DDRC, &PINC, &PORTC, 6}, // C6 16 {&DDRC, &PINC, &PORTC, 6}, // C6 16
{&DDRC, &PINC, &PORTC, 7}, // C7 17 {&DDRC, &PINC, &PORTC, 7}, // C7 17
{&DDRE, &PINE, &PORTE, 6}, // E6 18 {&DDRE, &PINE, &PORTE, 6}, // E6 18
{&DDRE, &PINE, &PORTE, 7}, // E7 19 {&DDRE, &PINE, &PORTE, 7}, // E7 19
{&DDRB, &PINB, &PORTB, 0}, // B0 20 {&DDRB, &PINB, &PORTB, 0}, // B0 20
{&DDRB, &PINB, &PORTB, 1}, // B1 21 {&DDRB, &PINB, &PORTB, 1}, // B1 21
{&DDRB, &PINB, &PORTB, 2}, // B2 22 {&DDRB, &PINB, &PORTB, 2}, // B2 22
{&DDRB, &PINB, &PORTB, 3}, // B3 23 {&DDRB, &PINB, &PORTB, 3}, // B3 23
{&DDRB, &PINB, &PORTB, 4}, // B4 24 {&DDRB, &PINB, &PORTB, 4}, // B4 24
{&DDRB, &PINB, &PORTB, 5}, // B5 25 {&DDRB, &PINB, &PORTB, 5}, // B5 25
{&DDRB, &PINB, &PORTB, 6}, // B6 26 {&DDRB, &PINB, &PORTB, 6}, // B6 26
{&DDRB, &PINB, &PORTB, 7}, // B7 27 {&DDRB, &PINB, &PORTB, 7}, // B7 27
{&DDRA, &PINA, &PORTA, 0}, // A0 28 {&DDRA, &PINA, &PORTA, 0}, // A0 28
{&DDRA, &PINA, &PORTA, 1}, // A1 29 {&DDRA, &PINA, &PORTA, 1}, // A1 29
{&DDRA, &PINA, &PORTA, 2}, // A2 30 {&DDRA, &PINA, &PORTA, 2}, // A2 30
{&DDRA, &PINA, &PORTA, 3}, // A3 31 {&DDRA, &PINA, &PORTA, 3}, // A3 31
{&DDRA, &PINA, &PORTA, 4}, // A4 32 {&DDRA, &PINA, &PORTA, 4}, // A4 32
{&DDRA, &PINA, &PORTA, 5}, // A5 33 {&DDRA, &PINA, &PORTA, 5}, // A5 33
{&DDRA, &PINA, &PORTA, 6}, // A6 34 {&DDRA, &PINA, &PORTA, 6}, // A6 34
{&DDRA, &PINA, &PORTA, 7}, // A7 35 {&DDRA, &PINA, &PORTA, 7}, // A7 35
{&DDRE, &PINE, &PORTE, 4}, // E4 36 {&DDRE, &PINE, &PORTE, 4}, // E4 36
{&DDRE, &PINE, &PORTE, 5}, // E5 37 {&DDRE, &PINE, &PORTE, 5}, // E5 37
{&DDRF, &PINF, &PORTF, 0}, // F0 38 {&DDRF, &PINF, &PORTF, 0}, // F0 38
{&DDRF, &PINF, &PORTF, 1}, // F1 39 {&DDRF, &PINF, &PORTF, 1}, // F1 39
{&DDRF, &PINF, &PORTF, 2}, // F2 40 {&DDRF, &PINF, &PORTF, 2}, // F2 40
{&DDRF, &PINF, &PORTF, 3}, // F3 41 {&DDRF, &PINF, &PORTF, 3}, // F3 41
{&DDRF, &PINF, &PORTF, 4}, // F4 42 {&DDRF, &PINF, &PORTF, 4}, // F4 42
{&DDRF, &PINF, &PORTF, 5}, // F5 43 {&DDRF, &PINF, &PORTF, 5}, // F5 43
{&DDRF, &PINF, &PORTF, 6}, // F6 44 {&DDRF, &PINF, &PORTF, 6}, // F6 44
{&DDRF, &PINF, &PORTF, 7} // F7 45 {&DDRF, &PINF, &PORTF, 7} // F7 45
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#elif defined(__AVR_ATmega168__)\ #elif defined(__AVR_ATmega168__)\
||defined(__AVR_ATmega168P__)\ ||defined(__AVR_ATmega168P__)\
||defined(__AVR_ATmega328P__) ||defined(__AVR_ATmega328P__)
// 168 and 328 Arduinos // 168 and 328 Arduinos
// Two Wire (aka I2C) ports // Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 18; // C4 uint8_t const SDA_PIN = 18; // C4
uint8_t const SCL_PIN = 19; // C5 uint8_t const SCL_PIN = 19; // C5
// SPI port // SPI port
uint8_t const SS_PIN = 10; // B2 uint8_t const SS_PIN = 10; // B2
uint8_t const MOSI_PIN = 11; // B3 uint8_t const MOSI_PIN = 11; // B3
uint8_t const MISO_PIN = 12; // B4 uint8_t const MISO_PIN = 12; // B4
uint8_t const SCK_PIN = 13; // B5 uint8_t const SCK_PIN = 13; // B5
static const pin_map_t digitalPinMap[] = { static const pin_map_t digitalPinMap[] = {
{&DDRD, &PIND, &PORTD, 0}, // D0 0 {&DDRD, &PIND, &PORTD, 0}, // D0 0
{&DDRD, &PIND, &PORTD, 1}, // D1 1 {&DDRD, &PIND, &PORTD, 1}, // D1 1
{&DDRD, &PIND, &PORTD, 2}, // D2 2 {&DDRD, &PIND, &PORTD, 2}, // D2 2
{&DDRD, &PIND, &PORTD, 3}, // D3 3 {&DDRD, &PIND, &PORTD, 3}, // D3 3
{&DDRD, &PIND, &PORTD, 4}, // D4 4 {&DDRD, &PIND, &PORTD, 4}, // D4 4
{&DDRD, &PIND, &PORTD, 5}, // D5 5 {&DDRD, &PIND, &PORTD, 5}, // D5 5
{&DDRD, &PIND, &PORTD, 6}, // D6 6 {&DDRD, &PIND, &PORTD, 6}, // D6 6
{&DDRD, &PIND, &PORTD, 7}, // D7 7 {&DDRD, &PIND, &PORTD, 7}, // D7 7
{&DDRB, &PINB, &PORTB, 0}, // B0 8 {&DDRB, &PINB, &PORTB, 0}, // B0 8
{&DDRB, &PINB, &PORTB, 1}, // B1 9 {&DDRB, &PINB, &PORTB, 1}, // B1 9
{&DDRB, &PINB, &PORTB, 2}, // B2 10 {&DDRB, &PINB, &PORTB, 2}, // B2 10
{&DDRB, &PINB, &PORTB, 3}, // B3 11 {&DDRB, &PINB, &PORTB, 3}, // B3 11
{&DDRB, &PINB, &PORTB, 4}, // B4 12 {&DDRB, &PINB, &PORTB, 4}, // B4 12
{&DDRB, &PINB, &PORTB, 5}, // B5 13 {&DDRB, &PINB, &PORTB, 5}, // B5 13
{&DDRC, &PINC, &PORTC, 0}, // C0 14 {&DDRC, &PINC, &PORTC, 0}, // C0 14
{&DDRC, &PINC, &PORTC, 1}, // C1 15 {&DDRC, &PINC, &PORTC, 1}, // C1 15
{&DDRC, &PINC, &PORTC, 2}, // C2 16 {&DDRC, &PINC, &PORTC, 2}, // C2 16
{&DDRC, &PINC, &PORTC, 3}, // C3 17 {&DDRC, &PINC, &PORTC, 3}, // C3 17
{&DDRC, &PINC, &PORTC, 4}, // C4 18 {&DDRC, &PINC, &PORTC, 4}, // C4 18
{&DDRC, &PINC, &PORTC, 5} // C5 19 {&DDRC, &PINC, &PORTC, 5} // C5 19
}; };
#else // defined(__AVR_ATmega1280__) #else // defined(__AVR_ATmega1280__)
#error unknown chip #error unknown chip
#endif // defined(__AVR_ATmega1280__) #endif // defined(__AVR_ATmega1280__)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t); static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
uint8_t badPinNumber(void) uint8_t badPinNumber(void)
__attribute__((error("Pin number is too large or not a constant"))); __attribute__((error("Pin number is too large or not a constant")));
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
bool getPinMode(uint8_t pin) { bool getPinMode(uint8_t pin) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1; return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
} else { } else {
return badPinNumber(); return badPinNumber();
} }
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void setPinMode(uint8_t pin, uint8_t mode) { void setPinMode(uint8_t pin, uint8_t mode) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
if (mode) { if (mode) {
*digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit; *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
} else { } else {
*digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit); *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
} }
} else { } else {
badPinNumber(); badPinNumber();
} }
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
bool fastDigitalRead(uint8_t pin) { bool fastDigitalRead(uint8_t pin) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1; return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
} else { } else {
return badPinNumber(); return badPinNumber();
} }
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, uint8_t value) { void fastDigitalWrite(uint8_t pin, uint8_t value) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
if (value) { if (value) {
*digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit; *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
} else { } else {
*digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit); *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
} }
} else { } else {
badPinNumber(); badPinNumber();
} }
} }
#endif // Sd2PinMap_h #endif // Sd2PinMap_h
#endif #endif

View File

@ -1,51 +1,51 @@
/* Arduino SdFat Library /* Arduino SdFat Library
* Copyright (C) 2008 by William Greiman * Copyright (C) 2008 by William Greiman
* *
* This file is part of the Arduino SdFat Library * This file is part of the Arduino SdFat Library
* *
* This Library is free software: you can redistribute it and/or modify * This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This Library is distributed in the hope that it will be useful, * This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the Arduino SdFat Library. If not, see * along with the Arduino SdFat Library. If not, see
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#include "Marlin.h" #include "Marlin.h"
#ifdef SDSUPPORT #ifdef SDSUPPORT
#ifndef SdFatUtil_h #ifndef SdFatUtil_h
#define SdFatUtil_h #define SdFatUtil_h
/** /**
* \file * \file
* \brief Useful utility functions. * \brief Useful utility functions.
*/ */
#include "Marlin.h" #include "Marlin.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
/** Store and print a string in flash memory.*/ /** Store and print a string in flash memory.*/
#define PgmPrint(x) SerialPrint_P(PSTR(x)) #define PgmPrint(x) SerialPrint_P(PSTR(x))
/** Store and print a string in flash memory followed by a CR/LF.*/ /** Store and print a string in flash memory followed by a CR/LF.*/
#define PgmPrintln(x) SerialPrintln_P(PSTR(x)) #define PgmPrintln(x) SerialPrintln_P(PSTR(x))
namespace SdFatUtil { namespace SdFatUtil {
int FreeRam(); int FreeRam();
void print_P( PGM_P str); void print_P( PGM_P str);
void println_P( PGM_P str); void println_P( PGM_P str);
void SerialPrint_P(PGM_P str); void SerialPrint_P(PGM_P str);
void SerialPrintln_P(PGM_P str); void SerialPrintln_P(PGM_P str);
void set_stack_guard(); void set_stack_guard();
bool test_stack_integrity(); bool test_stack_integrity();
uint32_t get_stack_guard_test_value(); uint32_t get_stack_guard_test_value();
} }
using namespace SdFatUtil; // NOLINT using namespace SdFatUtil; // NOLINT
#endif // #define SdFatUtil_h #endif // #define SdFatUtil_h
#endif #endif

View File

@ -1,95 +1,95 @@
/* Arduino SdFat Library /* Arduino SdFat Library
* Copyright (C) 2009 by William Greiman * Copyright (C) 2009 by William Greiman
* *
* This file is part of the Arduino SdFat Library * This file is part of the Arduino SdFat Library
* *
* This Library is free software: you can redistribute it and/or modify * This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This Library is distributed in the hope that it will be useful, * This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the Arduino SdFat Library. If not, see * along with the Arduino SdFat Library. If not, see
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#include "Marlin.h" #include "Marlin.h"
#ifdef SDSUPPORT #ifdef SDSUPPORT
#include "SdFile.h" #include "SdFile.h"
/** Create a file object and open it in the current working directory. /** Create a file object and open it in the current working directory.
* *
* \param[in] path A path with a valid 8.3 DOS name for a file to be opened. * \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
* *
* \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
* OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t). * OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
*/ */
SdFile::SdFile(const char* path, uint8_t oflag) : SdBaseFile(path, oflag) { SdFile::SdFile(const char* path, uint8_t oflag) : SdBaseFile(path, oflag) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Write data to an open file. /** Write data to an open file.
* *
* \note Data is moved to the cache but may not be written to the * \note Data is moved to the cache but may not be written to the
* storage device until sync() is called. * storage device until sync() is called.
* *
* \param[in] buf Pointer to the location of the data to be written. * \param[in] buf Pointer to the location of the data to be written.
* *
* \param[in] nbyte Number of bytes to write. * \param[in] nbyte Number of bytes to write.
* *
* \return For success write() returns the number of bytes written, always * \return For success write() returns the number of bytes written, always
* \a nbyte. If an error occurs, write() returns -1. Possible errors * \a nbyte. If an error occurs, write() returns -1. Possible errors
* include write() is called before a file has been opened, write is called * include write() is called before a file has been opened, write is called
* for a read-only file, device is full, a corrupt file system or an I/O error. * for a read-only file, device is full, a corrupt file system or an I/O error.
* *
*/ */
int16_t SdFile::write(const void* buf, uint16_t nbyte) { int16_t SdFile::write(const void* buf, uint16_t nbyte) {
return SdBaseFile::write(buf, nbyte); return SdBaseFile::write(buf, nbyte);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Write a byte to a file. Required by the Arduino Print class. /** Write a byte to a file. Required by the Arduino Print class.
* \param[in] b the byte to be written. * \param[in] b the byte to be written.
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
#if ARDUINO >= 100 #if ARDUINO >= 100
size_t SdFile::write(uint8_t b) size_t SdFile::write(uint8_t b)
{ {
return SdBaseFile::write(&b, 1); return SdBaseFile::write(&b, 1);
} }
#else #else
void SdFile::write(uint8_t b) void SdFile::write(uint8_t b)
{ {
SdBaseFile::write(&b, 1); SdBaseFile::write(&b, 1);
} }
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Write a string to a file. Used by the Arduino Print class. /** Write a string to a file. Used by the Arduino Print class.
* \param[in] str Pointer to the string. * \param[in] str Pointer to the string.
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
void SdFile::write(const char* str) { void SdFile::write(const char* str) {
SdBaseFile::write(str, strlen(str)); SdBaseFile::write(str, strlen(str));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Write a PROGMEM string to a file. /** Write a PROGMEM string to a file.
* \param[in] str Pointer to the PROGMEM string. * \param[in] str Pointer to the PROGMEM string.
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
void SdFile::write_P(PGM_P str) { void SdFile::write_P(PGM_P str) {
for (uint8_t c; (c = pgm_read_byte(str)); str++) write(c); for (uint8_t c; (c = pgm_read_byte(str)); str++) write(c);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Write a PROGMEM string followed by CR/LF to a file. /** Write a PROGMEM string followed by CR/LF to a file.
* \param[in] str Pointer to the PROGMEM string. * \param[in] str Pointer to the PROGMEM string.
* Use writeError to check for errors. * Use writeError to check for errors.
*/ */
void SdFile::writeln_P(PGM_P str) { void SdFile::writeln_P(PGM_P str) {
write_P(str); write_P(str);
write_P(PSTR("\r\n")); write_P(PSTR("\r\n"));
} }
#endif #endif

View File

@ -1,286 +1,286 @@
/* Arduino Sd2Card Library /* Arduino Sd2Card Library
* Copyright (C) 2009 by William Greiman * Copyright (C) 2009 by William Greiman
* *
* This file is part of the Arduino Sd2Card Library * This file is part of the Arduino Sd2Card Library
* *
* This Library is free software: you can redistribute it and/or modify * This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This Library is distributed in the hope that it will be useful, * This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the Arduino Sd2Card Library. If not, see * along with the Arduino Sd2Card Library. If not, see
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#include "Marlin.h" #include "Marlin.h"
#ifdef SDSUPPORT #ifdef SDSUPPORT
#ifndef SdInfo_h #ifndef SdInfo_h
#define SdInfo_h #define SdInfo_h
#include <stdint.h> #include <stdint.h>
// Based on the document: // Based on the document:
// //
// SD Specifications // SD Specifications
// Part 1 // Part 1
// Physical Layer // Physical Layer
// Simplified Specification // Simplified Specification
// Version 3.01 // Version 3.01
// May 18, 2010 // May 18, 2010
// //
// http://www.sdcard.org/developers/tech/sdcard/pls/simplified_specs // http://www.sdcard.org/developers/tech/sdcard/pls/simplified_specs
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// SD card commands // SD card commands
/** GO_IDLE_STATE - init card in spi mode if CS low */ /** GO_IDLE_STATE - init card in spi mode if CS low */
uint8_t const CMD0 = 0X00; uint8_t const CMD0 = 0X00;
/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/ /** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
uint8_t const CMD8 = 0X08; uint8_t const CMD8 = 0X08;
/** SEND_CSD - read the Card Specific Data (CSD register) */ /** SEND_CSD - read the Card Specific Data (CSD register) */
uint8_t const CMD9 = 0X09; uint8_t const CMD9 = 0X09;
/** SEND_CID - read the card identification information (CID register) */ /** SEND_CID - read the card identification information (CID register) */
uint8_t const CMD10 = 0X0A; uint8_t const CMD10 = 0X0A;
/** STOP_TRANSMISSION - end multiple block read sequence */ /** STOP_TRANSMISSION - end multiple block read sequence */
uint8_t const CMD12 = 0X0C; uint8_t const CMD12 = 0X0C;
/** SEND_STATUS - read the card status register */ /** SEND_STATUS - read the card status register */
uint8_t const CMD13 = 0X0D; uint8_t const CMD13 = 0X0D;
/** READ_SINGLE_BLOCK - read a single data block from the card */ /** READ_SINGLE_BLOCK - read a single data block from the card */
uint8_t const CMD17 = 0X11; uint8_t const CMD17 = 0X11;
/** READ_MULTIPLE_BLOCK - read a multiple data blocks from the card */ /** READ_MULTIPLE_BLOCK - read a multiple data blocks from the card */
uint8_t const CMD18 = 0X12; uint8_t const CMD18 = 0X12;
/** WRITE_BLOCK - write a single data block to the card */ /** WRITE_BLOCK - write a single data block to the card */
uint8_t const CMD24 = 0X18; uint8_t const CMD24 = 0X18;
/** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */ /** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
uint8_t const CMD25 = 0X19; uint8_t const CMD25 = 0X19;
/** ERASE_WR_BLK_START - sets the address of the first block to be erased */ /** ERASE_WR_BLK_START - sets the address of the first block to be erased */
uint8_t const CMD32 = 0X20; uint8_t const CMD32 = 0X20;
/** ERASE_WR_BLK_END - sets the address of the last block of the continuous /** ERASE_WR_BLK_END - sets the address of the last block of the continuous
range to be erased*/ range to be erased*/
uint8_t const CMD33 = 0X21; uint8_t const CMD33 = 0X21;
/** ERASE - erase all previously selected blocks */ /** ERASE - erase all previously selected blocks */
uint8_t const CMD38 = 0X26; uint8_t const CMD38 = 0X26;
/** Toshiba FlashAir: iSDIO */ /** Toshiba FlashAir: iSDIO */
uint8_t const CMD48 = 0x30; uint8_t const CMD48 = 0x30;
/** Toshiba FlashAir: iSDIO */ /** Toshiba FlashAir: iSDIO */
uint8_t const CMD49 = 0x31; uint8_t const CMD49 = 0x31;
/** APP_CMD - escape for application specific command */ /** APP_CMD - escape for application specific command */
uint8_t const CMD55 = 0X37; uint8_t const CMD55 = 0X37;
/** READ_OCR - read the OCR register of a card */ /** READ_OCR - read the OCR register of a card */
uint8_t const CMD58 = 0X3A; uint8_t const CMD58 = 0X3A;
/** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be /** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be
pre-erased before writing */ pre-erased before writing */
uint8_t const ACMD23 = 0X17; uint8_t const ACMD23 = 0X17;
/** SD_SEND_OP_COMD - Sends host capacity support information and /** SD_SEND_OP_COMD - Sends host capacity support information and
activates the card's initialization process */ activates the card's initialization process */
uint8_t const ACMD41 = 0X29; uint8_t const ACMD41 = 0X29;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** status for card in the ready state */ /** status for card in the ready state */
uint8_t const R1_READY_STATE = 0X00; uint8_t const R1_READY_STATE = 0X00;
/** status for card in the idle state */ /** status for card in the idle state */
uint8_t const R1_IDLE_STATE = 0X01; uint8_t const R1_IDLE_STATE = 0X01;
/** status bit for illegal command */ /** status bit for illegal command */
uint8_t const R1_ILLEGAL_COMMAND = 0X04; uint8_t const R1_ILLEGAL_COMMAND = 0X04;
/** start data token for read or write single block*/ /** start data token for read or write single block*/
uint8_t const DATA_START_BLOCK = 0XFE; uint8_t const DATA_START_BLOCK = 0XFE;
/** stop token for write multiple blocks*/ /** stop token for write multiple blocks*/
uint8_t const STOP_TRAN_TOKEN = 0XFD; uint8_t const STOP_TRAN_TOKEN = 0XFD;
/** start data token for write multiple blocks*/ /** start data token for write multiple blocks*/
uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC; uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC;
/** mask for data response tokens after a write block operation */ /** mask for data response tokens after a write block operation */
uint8_t const DATA_RES_MASK = 0X1F; uint8_t const DATA_RES_MASK = 0X1F;
/** write data accepted token */ /** write data accepted token */
uint8_t const DATA_RES_ACCEPTED = 0X05; uint8_t const DATA_RES_ACCEPTED = 0X05;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Card IDentification (CID) register */ /** Card IDentification (CID) register */
typedef struct CID { typedef struct CID {
// byte 0 // byte 0
/** Manufacturer ID */ /** Manufacturer ID */
unsigned char mid; unsigned char mid;
// byte 1-2 // byte 1-2
/** OEM/Application ID */ /** OEM/Application ID */
char oid[2]; char oid[2];
// byte 3-7 // byte 3-7
/** Product name */ /** Product name */
char pnm[5]; char pnm[5];
// byte 8 // byte 8
/** Product revision least significant digit */ /** Product revision least significant digit */
unsigned char prv_m : 4; unsigned char prv_m : 4;
/** Product revision most significant digit */ /** Product revision most significant digit */
unsigned char prv_n : 4; unsigned char prv_n : 4;
// byte 9-12 // byte 9-12
/** Product serial number */ /** Product serial number */
uint32_t psn; uint32_t psn;
// byte 13 // byte 13
/** Manufacturing date year low digit */ /** Manufacturing date year low digit */
unsigned char mdt_year_high : 4; unsigned char mdt_year_high : 4;
/** not used */ /** not used */
unsigned char reserved : 4; unsigned char reserved : 4;
// byte 14 // byte 14
/** Manufacturing date month */ /** Manufacturing date month */
unsigned char mdt_month : 4; unsigned char mdt_month : 4;
/** Manufacturing date year low digit */ /** Manufacturing date year low digit */
unsigned char mdt_year_low :4; unsigned char mdt_year_low :4;
// byte 15 // byte 15
/** not used always 1 */ /** not used always 1 */
unsigned char always1 : 1; unsigned char always1 : 1;
/** CRC7 checksum */ /** CRC7 checksum */
unsigned char crc : 7; unsigned char crc : 7;
}cid_t; }cid_t;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** CSD for version 1.00 cards */ /** CSD for version 1.00 cards */
typedef struct CSDV1 { typedef struct CSDV1 {
// byte 0 // byte 0
unsigned char reserved1 : 6; unsigned char reserved1 : 6;
unsigned char csd_ver : 2; unsigned char csd_ver : 2;
// byte 1 // byte 1
unsigned char taac; unsigned char taac;
// byte 2 // byte 2
unsigned char nsac; unsigned char nsac;
// byte 3 // byte 3
unsigned char tran_speed; unsigned char tran_speed;
// byte 4 // byte 4
unsigned char ccc_high; unsigned char ccc_high;
// byte 5 // byte 5
unsigned char read_bl_len : 4; unsigned char read_bl_len : 4;
unsigned char ccc_low : 4; unsigned char ccc_low : 4;
// byte 6 // byte 6
unsigned char c_size_high : 2; unsigned char c_size_high : 2;
unsigned char reserved2 : 2; unsigned char reserved2 : 2;
unsigned char dsr_imp : 1; unsigned char dsr_imp : 1;
unsigned char read_blk_misalign :1; unsigned char read_blk_misalign :1;
unsigned char write_blk_misalign : 1; unsigned char write_blk_misalign : 1;
unsigned char read_bl_partial : 1; unsigned char read_bl_partial : 1;
// byte 7 // byte 7
unsigned char c_size_mid; unsigned char c_size_mid;
// byte 8 // byte 8
unsigned char vdd_r_curr_max : 3; unsigned char vdd_r_curr_max : 3;
unsigned char vdd_r_curr_min : 3; unsigned char vdd_r_curr_min : 3;
unsigned char c_size_low :2; unsigned char c_size_low :2;
// byte 9 // byte 9
unsigned char c_size_mult_high : 2; unsigned char c_size_mult_high : 2;
unsigned char vdd_w_cur_max : 3; unsigned char vdd_w_cur_max : 3;
unsigned char vdd_w_curr_min : 3; unsigned char vdd_w_curr_min : 3;
// byte 10 // byte 10
unsigned char sector_size_high : 6; unsigned char sector_size_high : 6;
unsigned char erase_blk_en : 1; unsigned char erase_blk_en : 1;
unsigned char c_size_mult_low : 1; unsigned char c_size_mult_low : 1;
// byte 11 // byte 11
unsigned char wp_grp_size : 7; unsigned char wp_grp_size : 7;
unsigned char sector_size_low : 1; unsigned char sector_size_low : 1;
// byte 12 // byte 12
unsigned char write_bl_len_high : 2; unsigned char write_bl_len_high : 2;
unsigned char r2w_factor : 3; unsigned char r2w_factor : 3;
unsigned char reserved3 : 2; unsigned char reserved3 : 2;
unsigned char wp_grp_enable : 1; unsigned char wp_grp_enable : 1;
// byte 13 // byte 13
unsigned char reserved4 : 5; unsigned char reserved4 : 5;
unsigned char write_partial : 1; unsigned char write_partial : 1;
unsigned char write_bl_len_low : 2; unsigned char write_bl_len_low : 2;
// byte 14 // byte 14
unsigned char reserved5: 2; unsigned char reserved5: 2;
unsigned char file_format : 2; unsigned char file_format : 2;
unsigned char tmp_write_protect : 1; unsigned char tmp_write_protect : 1;
unsigned char perm_write_protect : 1; unsigned char perm_write_protect : 1;
unsigned char copy : 1; unsigned char copy : 1;
/** Indicates the file format on the card */ /** Indicates the file format on the card */
unsigned char file_format_grp : 1; unsigned char file_format_grp : 1;
// byte 15 // byte 15
unsigned char always1 : 1; unsigned char always1 : 1;
unsigned char crc : 7; unsigned char crc : 7;
}csd1_t; }csd1_t;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** CSD for version 2.00 cards */ /** CSD for version 2.00 cards */
typedef struct CSDV2 { typedef struct CSDV2 {
// byte 0 // byte 0
unsigned char reserved1 : 6; unsigned char reserved1 : 6;
unsigned char csd_ver : 2; unsigned char csd_ver : 2;
// byte 1 // byte 1
/** fixed to 0X0E */ /** fixed to 0X0E */
unsigned char taac; unsigned char taac;
// byte 2 // byte 2
/** fixed to 0 */ /** fixed to 0 */
unsigned char nsac; unsigned char nsac;
// byte 3 // byte 3
unsigned char tran_speed; unsigned char tran_speed;
// byte 4 // byte 4
unsigned char ccc_high; unsigned char ccc_high;
// byte 5 // byte 5
/** This field is fixed to 9h, which indicates READ_BL_LEN=512 Byte */ /** This field is fixed to 9h, which indicates READ_BL_LEN=512 Byte */
unsigned char read_bl_len : 4; unsigned char read_bl_len : 4;
unsigned char ccc_low : 4; unsigned char ccc_low : 4;
// byte 6 // byte 6
/** not used */ /** not used */
unsigned char reserved2 : 4; unsigned char reserved2 : 4;
unsigned char dsr_imp : 1; unsigned char dsr_imp : 1;
/** fixed to 0 */ /** fixed to 0 */
unsigned char read_blk_misalign :1; unsigned char read_blk_misalign :1;
/** fixed to 0 */ /** fixed to 0 */
unsigned char write_blk_misalign : 1; unsigned char write_blk_misalign : 1;
/** fixed to 0 - no partial read */ /** fixed to 0 - no partial read */
unsigned char read_bl_partial : 1; unsigned char read_bl_partial : 1;
// byte 7 // byte 7
/** not used */ /** not used */
unsigned char reserved3 : 2; unsigned char reserved3 : 2;
/** high part of card size */ /** high part of card size */
unsigned char c_size_high : 6; unsigned char c_size_high : 6;
// byte 8 // byte 8
/** middle part of card size */ /** middle part of card size */
unsigned char c_size_mid; unsigned char c_size_mid;
// byte 9 // byte 9
/** low part of card size */ /** low part of card size */
unsigned char c_size_low; unsigned char c_size_low;
// byte 10 // byte 10
/** sector size is fixed at 64 KB */ /** sector size is fixed at 64 KB */
unsigned char sector_size_high : 6; unsigned char sector_size_high : 6;
/** fixed to 1 - erase single is supported */ /** fixed to 1 - erase single is supported */
unsigned char erase_blk_en : 1; unsigned char erase_blk_en : 1;
/** not used */ /** not used */
unsigned char reserved4 : 1; unsigned char reserved4 : 1;
// byte 11 // byte 11
unsigned char wp_grp_size : 7; unsigned char wp_grp_size : 7;
/** sector size is fixed at 64 KB */ /** sector size is fixed at 64 KB */
unsigned char sector_size_low : 1; unsigned char sector_size_low : 1;
// byte 12 // byte 12
/** write_bl_len fixed for 512 byte blocks */ /** write_bl_len fixed for 512 byte blocks */
unsigned char write_bl_len_high : 2; unsigned char write_bl_len_high : 2;
/** fixed value of 2 */ /** fixed value of 2 */
unsigned char r2w_factor : 3; unsigned char r2w_factor : 3;
/** not used */ /** not used */
unsigned char reserved5 : 2; unsigned char reserved5 : 2;
/** fixed value of 0 - no write protect groups */ /** fixed value of 0 - no write protect groups */
unsigned char wp_grp_enable : 1; unsigned char wp_grp_enable : 1;
// byte 13 // byte 13
unsigned char reserved6 : 5; unsigned char reserved6 : 5;
/** always zero - no partial block read*/ /** always zero - no partial block read*/
unsigned char write_partial : 1; unsigned char write_partial : 1;
/** write_bl_len fixed for 512 byte blocks */ /** write_bl_len fixed for 512 byte blocks */
unsigned char write_bl_len_low : 2; unsigned char write_bl_len_low : 2;
// byte 14 // byte 14
unsigned char reserved7: 2; unsigned char reserved7: 2;
/** Do not use always 0 */ /** Do not use always 0 */
unsigned char file_format : 2; unsigned char file_format : 2;
unsigned char tmp_write_protect : 1; unsigned char tmp_write_protect : 1;
unsigned char perm_write_protect : 1; unsigned char perm_write_protect : 1;
unsigned char copy : 1; unsigned char copy : 1;
/** Do not use always 0 */ /** Do not use always 0 */
unsigned char file_format_grp : 1; unsigned char file_format_grp : 1;
// byte 15 // byte 15
/** not used always 1 */ /** not used always 1 */
unsigned char always1 : 1; unsigned char always1 : 1;
/** checksum */ /** checksum */
unsigned char crc : 7; unsigned char crc : 7;
}csd2_t; }csd2_t;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** union of old and new style CSD register */ /** union of old and new style CSD register */
union csd_t { union csd_t {
csd1_t v1; csd1_t v1;
csd2_t v2; csd2_t v2;
}; };
#endif // SdInfo_h #endif // SdInfo_h
#endif #endif

View File

@ -1,405 +1,405 @@
/* Arduino SdFat Library /* Arduino SdFat Library
* Copyright (C) 2009 by William Greiman * Copyright (C) 2009 by William Greiman
* *
* This file is part of the Arduino SdFat Library * This file is part of the Arduino SdFat Library
* *
* This Library is free software: you can redistribute it and/or modify * This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This Library is distributed in the hope that it will be useful, * This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the Arduino SdFat Library. If not, see * along with the Arduino SdFat Library. If not, see
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#include "Marlin.h" #include "Marlin.h"
#ifdef SDSUPPORT #ifdef SDSUPPORT
#include "SdVolume.h" #include "SdVolume.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if !USE_MULTIPLE_CARDS #if !USE_MULTIPLE_CARDS
// raw block cache // raw block cache
uint32_t SdVolume::cacheBlockNumber_; // current block number uint32_t SdVolume::cacheBlockNumber_; // current block number
cache_t SdVolume::cacheBuffer_; // 512 byte cache for Sd2Card cache_t SdVolume::cacheBuffer_; // 512 byte cache for Sd2Card
Sd2Card* SdVolume::sdCard_; // pointer to SD card object Sd2Card* SdVolume::sdCard_; // pointer to SD card object
bool SdVolume::cacheDirty_; // cacheFlush() will write block if true bool SdVolume::cacheDirty_; // cacheFlush() will write block if true
uint32_t SdVolume::cacheMirrorBlock_; // mirror block for second FAT uint32_t SdVolume::cacheMirrorBlock_; // mirror block for second FAT
#endif // USE_MULTIPLE_CARDS #endif // USE_MULTIPLE_CARDS
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// find a contiguous group of clusters // find a contiguous group of clusters
bool SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) { bool SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) {
// start of group // start of group
uint32_t bgnCluster; uint32_t bgnCluster;
// end of group // end of group
uint32_t endCluster; uint32_t endCluster;
// last cluster of FAT // last cluster of FAT
uint32_t fatEnd = clusterCount_ + 1; uint32_t fatEnd = clusterCount_ + 1;
// flag to save place to start next search // flag to save place to start next search
bool setStart; bool setStart;
// set search start cluster // set search start cluster
if (*curCluster) { if (*curCluster) {
// try to make file contiguous // try to make file contiguous
bgnCluster = *curCluster + 1; bgnCluster = *curCluster + 1;
// don't save new start location // don't save new start location
setStart = false; setStart = false;
} else { } else {
// start at likely place for free cluster // start at likely place for free cluster
bgnCluster = allocSearchStart_; bgnCluster = allocSearchStart_;
// save next search start if one cluster // save next search start if one cluster
setStart = count == 1; setStart = count == 1;
} }
// end of group // end of group
endCluster = bgnCluster; endCluster = bgnCluster;
// search the FAT for free clusters // search the FAT for free clusters
for (uint32_t n = 0;; n++, endCluster++) { for (uint32_t n = 0;; n++, endCluster++) {
// can't find space checked all clusters // can't find space checked all clusters
if (n >= clusterCount_) goto fail; if (n >= clusterCount_) goto fail;
// past end - start from beginning of FAT // past end - start from beginning of FAT
if (endCluster > fatEnd) { if (endCluster > fatEnd) {
bgnCluster = endCluster = 2; bgnCluster = endCluster = 2;
} }
uint32_t f; uint32_t f;
if (!fatGet(endCluster, &f)) goto fail; if (!fatGet(endCluster, &f)) goto fail;
if (f != 0) { if (f != 0) {
// cluster in use try next cluster as bgnCluster // cluster in use try next cluster as bgnCluster
bgnCluster = endCluster + 1; bgnCluster = endCluster + 1;
} else if ((endCluster - bgnCluster + 1) == count) { } else if ((endCluster - bgnCluster + 1) == count) {
// done - found space // done - found space
break; break;
} }
} }
// mark end of chain // mark end of chain
if (!fatPutEOC(endCluster)) goto fail; if (!fatPutEOC(endCluster)) goto fail;
// link clusters // link clusters
while (endCluster > bgnCluster) { while (endCluster > bgnCluster) {
if (!fatPut(endCluster - 1, endCluster)) goto fail; if (!fatPut(endCluster - 1, endCluster)) goto fail;
endCluster--; endCluster--;
} }
if (*curCluster != 0) { if (*curCluster != 0) {
// connect chains // connect chains
if (!fatPut(*curCluster, bgnCluster)) goto fail; if (!fatPut(*curCluster, bgnCluster)) goto fail;
} }
// return first cluster number to caller // return first cluster number to caller
*curCluster = bgnCluster; *curCluster = bgnCluster;
// remember possible next free cluster // remember possible next free cluster
if (setStart) allocSearchStart_ = bgnCluster + 1; if (setStart) allocSearchStart_ = bgnCluster + 1;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool SdVolume::cacheFlush() { bool SdVolume::cacheFlush() {
if (cacheDirty_) { if (cacheDirty_) {
if (!sdCard_->writeBlock(cacheBlockNumber_, cacheBuffer_.data)) { if (!sdCard_->writeBlock(cacheBlockNumber_, cacheBuffer_.data)) {
goto fail; goto fail;
} }
// mirror FAT tables // mirror FAT tables
if (cacheMirrorBlock_) { if (cacheMirrorBlock_) {
if (!sdCard_->writeBlock(cacheMirrorBlock_, cacheBuffer_.data)) { if (!sdCard_->writeBlock(cacheMirrorBlock_, cacheBuffer_.data)) {
goto fail; goto fail;
} }
cacheMirrorBlock_ = 0; cacheMirrorBlock_ = 0;
} }
cacheDirty_ = 0; cacheDirty_ = 0;
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool SdVolume::cacheRawBlock(uint32_t blockNumber, bool dirty) { bool SdVolume::cacheRawBlock(uint32_t blockNumber, bool dirty) {
if (cacheBlockNumber_ != blockNumber) { if (cacheBlockNumber_ != blockNumber) {
if (!cacheFlush()) goto fail; if (!cacheFlush()) goto fail;
if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) goto fail; if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) goto fail;
cacheBlockNumber_ = blockNumber; cacheBlockNumber_ = blockNumber;
} }
if (dirty) cacheDirty_ = true; if (dirty) cacheDirty_ = true;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// return the size in bytes of a cluster chain // return the size in bytes of a cluster chain
bool SdVolume::chainSize(uint32_t cluster, uint32_t* size) { bool SdVolume::chainSize(uint32_t cluster, uint32_t* size) {
uint32_t s = 0; uint32_t s = 0;
do { do {
if (!fatGet(cluster, &cluster)) goto fail; if (!fatGet(cluster, &cluster)) goto fail;
s += 512UL << clusterSizeShift_; s += 512UL << clusterSizeShift_;
} while (!isEOC(cluster)); } while (!isEOC(cluster));
*size = s; *size = s;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Fetch a FAT entry // Fetch a FAT entry
bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) { bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
uint32_t lba; uint32_t lba;
if (cluster > (clusterCount_ + 1)) goto fail; if (cluster > (clusterCount_ + 1)) goto fail;
if (FAT12_SUPPORT && fatType_ == 12) { if (FAT12_SUPPORT && fatType_ == 12) {
uint16_t index = cluster; uint16_t index = cluster;
index += index >> 1; index += index >> 1;
lba = fatStartBlock_ + (index >> 9); lba = fatStartBlock_ + (index >> 9);
if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail; if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
index &= 0X1FF; index &= 0X1FF;
uint16_t tmp = cacheBuffer_.data[index]; uint16_t tmp = cacheBuffer_.data[index];
index++; index++;
if (index == 512) { if (index == 512) {
if (!cacheRawBlock(lba + 1, CACHE_FOR_READ)) goto fail; if (!cacheRawBlock(lba + 1, CACHE_FOR_READ)) goto fail;
index = 0; index = 0;
} }
tmp |= cacheBuffer_.data[index] << 8; tmp |= cacheBuffer_.data[index] << 8;
*value = cluster & 1 ? tmp >> 4 : tmp & 0XFFF; *value = cluster & 1 ? tmp >> 4 : tmp & 0XFFF;
return true; return true;
} }
if (fatType_ == 16) { if (fatType_ == 16) {
lba = fatStartBlock_ + (cluster >> 8); lba = fatStartBlock_ + (cluster >> 8);
} else if (fatType_ == 32) { } else if (fatType_ == 32) {
lba = fatStartBlock_ + (cluster >> 7); lba = fatStartBlock_ + (cluster >> 7);
} else { } else {
goto fail; goto fail;
} }
if (lba != cacheBlockNumber_) { if (lba != cacheBlockNumber_) {
if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail; if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
} }
if (fatType_ == 16) { if (fatType_ == 16) {
*value = cacheBuffer_.fat16[cluster & 0XFF]; *value = cacheBuffer_.fat16[cluster & 0XFF];
} else { } else {
*value = cacheBuffer_.fat32[cluster & 0X7F] & FAT32MASK; *value = cacheBuffer_.fat32[cluster & 0X7F] & FAT32MASK;
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Store a FAT entry // Store a FAT entry
bool SdVolume::fatPut(uint32_t cluster, uint32_t value) { bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
uint32_t lba; uint32_t lba;
// error if reserved cluster // error if reserved cluster
if (cluster < 2) goto fail; if (cluster < 2) goto fail;
// error if not in FAT // error if not in FAT
if (cluster > (clusterCount_ + 1)) goto fail; if (cluster > (clusterCount_ + 1)) goto fail;
if (FAT12_SUPPORT && fatType_ == 12) { if (FAT12_SUPPORT && fatType_ == 12) {
uint16_t index = cluster; uint16_t index = cluster;
index += index >> 1; index += index >> 1;
lba = fatStartBlock_ + (index >> 9); lba = fatStartBlock_ + (index >> 9);
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail; if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
// mirror second FAT // mirror second FAT
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_; if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
index &= 0X1FF; index &= 0X1FF;
uint8_t tmp = value; uint8_t tmp = value;
if (cluster & 1) { if (cluster & 1) {
tmp = (cacheBuffer_.data[index] & 0XF) | tmp << 4; tmp = (cacheBuffer_.data[index] & 0XF) | tmp << 4;
} }
cacheBuffer_.data[index] = tmp; cacheBuffer_.data[index] = tmp;
index++; index++;
if (index == 512) { if (index == 512) {
lba++; lba++;
index = 0; index = 0;
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail; if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
// mirror second FAT // mirror second FAT
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_; if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
} }
tmp = value >> 4; tmp = value >> 4;
if (!(cluster & 1)) { if (!(cluster & 1)) {
tmp = ((cacheBuffer_.data[index] & 0XF0)) | tmp >> 4; tmp = ((cacheBuffer_.data[index] & 0XF0)) | tmp >> 4;
} }
cacheBuffer_.data[index] = tmp; cacheBuffer_.data[index] = tmp;
return true; return true;
} }
if (fatType_ == 16) { if (fatType_ == 16) {
lba = fatStartBlock_ + (cluster >> 8); lba = fatStartBlock_ + (cluster >> 8);
} else if (fatType_ == 32) { } else if (fatType_ == 32) {
lba = fatStartBlock_ + (cluster >> 7); lba = fatStartBlock_ + (cluster >> 7);
} else { } else {
goto fail; goto fail;
} }
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail; if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
// store entry // store entry
if (fatType_ == 16) { if (fatType_ == 16) {
cacheBuffer_.fat16[cluster & 0XFF] = value; cacheBuffer_.fat16[cluster & 0XFF] = value;
} else { } else {
cacheBuffer_.fat32[cluster & 0X7F] = value; cacheBuffer_.fat32[cluster & 0X7F] = value;
} }
// mirror second FAT // mirror second FAT
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_; if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// free a cluster chain // free a cluster chain
bool SdVolume::freeChain(uint32_t cluster) { bool SdVolume::freeChain(uint32_t cluster) {
uint32_t next; uint32_t next;
// clear free cluster location // clear free cluster location
allocSearchStart_ = 2; allocSearchStart_ = 2;
do { do {
if (!fatGet(cluster, &next)) goto fail; if (!fatGet(cluster, &next)) goto fail;
// free cluster // free cluster
if (!fatPut(cluster, 0)) goto fail; if (!fatPut(cluster, 0)) goto fail;
cluster = next; cluster = next;
} while (!isEOC(cluster)); } while (!isEOC(cluster));
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Volume free space in clusters. /** Volume free space in clusters.
* *
* \return Count of free clusters for success or -1 if an error occurs. * \return Count of free clusters for success or -1 if an error occurs.
*/ */
int32_t SdVolume::freeClusterCount() { int32_t SdVolume::freeClusterCount() {
uint32_t free = 0; uint32_t free = 0;
uint16_t n; uint16_t n;
uint32_t todo = clusterCount_ + 2; uint32_t todo = clusterCount_ + 2;
if (fatType_ == 16) { if (fatType_ == 16) {
n = 256; n = 256;
} else if (fatType_ == 32) { } else if (fatType_ == 32) {
n = 128; n = 128;
} else { } else {
// put FAT12 here // put FAT12 here
return -1; return -1;
} }
for (uint32_t lba = fatStartBlock_; todo; todo -= n, lba++) { for (uint32_t lba = fatStartBlock_; todo; todo -= n, lba++) {
if (!cacheRawBlock(lba, CACHE_FOR_READ)) return -1; if (!cacheRawBlock(lba, CACHE_FOR_READ)) return -1;
if (todo < n) n = todo; if (todo < n) n = todo;
if (fatType_ == 16) { if (fatType_ == 16) {
for (uint16_t i = 0; i < n; i++) { for (uint16_t i = 0; i < n; i++) {
if (cacheBuffer_.fat16[i] == 0) free++; if (cacheBuffer_.fat16[i] == 0) free++;
} }
} else { } else {
for (uint16_t i = 0; i < n; i++) { for (uint16_t i = 0; i < n; i++) {
if (cacheBuffer_.fat32[i] == 0) free++; if (cacheBuffer_.fat32[i] == 0) free++;
} }
} }
} }
return free; return free;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Initialize a FAT volume. /** Initialize a FAT volume.
* *
* \param[in] dev The SD card where the volume is located. * \param[in] dev The SD card where the volume is located.
* *
* \param[in] part The partition to be used. Legal values for \a part are * \param[in] part The partition to be used. Legal values for \a part are
* 1-4 to use the corresponding partition on a device formatted with * 1-4 to use the corresponding partition on a device formatted with
* a MBR, Master Boot Record, or zero if the device is formatted as * a MBR, Master Boot Record, or zero if the device is formatted as
* a super floppy with the FAT boot sector in block zero. * a super floppy with the FAT boot sector in block zero.
* *
* \return The value one, true, is returned for success and * \return The value one, true, is returned for success and
* the value zero, false, is returned for failure. Reasons for * the value zero, false, is returned for failure. Reasons for
* failure include not finding a valid partition, not finding a valid * failure include not finding a valid partition, not finding a valid
* FAT file system in the specified partition or an I/O error. * FAT file system in the specified partition or an I/O error.
*/ */
bool SdVolume::init(Sd2Card* dev, uint8_t part) { bool SdVolume::init(Sd2Card* dev, uint8_t part) {
uint32_t totalBlocks; uint32_t totalBlocks;
uint32_t volumeStartBlock = 0; uint32_t volumeStartBlock = 0;
fat32_boot_t* fbs; fat32_boot_t* fbs;
sdCard_ = dev; sdCard_ = dev;
fatType_ = 0; fatType_ = 0;
allocSearchStart_ = 2; allocSearchStart_ = 2;
cacheDirty_ = 0; // cacheFlush() will write block if true cacheDirty_ = 0; // cacheFlush() will write block if true
cacheMirrorBlock_ = 0; cacheMirrorBlock_ = 0;
cacheBlockNumber_ = 0XFFFFFFFF; cacheBlockNumber_ = 0XFFFFFFFF;
// if part == 0 assume super floppy with FAT boot sector in block zero // if part == 0 assume super floppy with FAT boot sector in block zero
// if part > 0 assume mbr volume with partition table // if part > 0 assume mbr volume with partition table
if (part) { if (part) {
if (part > 4)goto fail; if (part > 4)goto fail;
if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail; if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail;
part_t* p = &cacheBuffer_.mbr.part[part-1]; part_t* p = &cacheBuffer_.mbr.part[part-1];
if ((p->boot & 0X7F) !=0 || if ((p->boot & 0X7F) !=0 ||
p->totalSectors < 100 || p->totalSectors < 100 ||
p->firstSector == 0) { p->firstSector == 0) {
// not a valid partition // not a valid partition
goto fail; goto fail;
} }
volumeStartBlock = p->firstSector; volumeStartBlock = p->firstSector;
} }
if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail; if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail;
fbs = &cacheBuffer_.fbs32; fbs = &cacheBuffer_.fbs32;
if (fbs->bytesPerSector != 512 || if (fbs->bytesPerSector != 512 ||
fbs->fatCount == 0 || fbs->fatCount == 0 ||
fbs->reservedSectorCount == 0 || fbs->reservedSectorCount == 0 ||
fbs->sectorsPerCluster == 0) { fbs->sectorsPerCluster == 0) {
// not valid FAT volume // not valid FAT volume
goto fail; goto fail;
} }
fatCount_ = fbs->fatCount; fatCount_ = fbs->fatCount;
blocksPerCluster_ = fbs->sectorsPerCluster; blocksPerCluster_ = fbs->sectorsPerCluster;
// determine shift that is same as multiply by blocksPerCluster_ // determine shift that is same as multiply by blocksPerCluster_
clusterSizeShift_ = 0; clusterSizeShift_ = 0;
while (blocksPerCluster_ != (1 << clusterSizeShift_)) { while (blocksPerCluster_ != (1 << clusterSizeShift_)) {
// error if not power of 2 // error if not power of 2
if (clusterSizeShift_++ > 7) goto fail; if (clusterSizeShift_++ > 7) goto fail;
} }
blocksPerFat_ = fbs->sectorsPerFat16 ? blocksPerFat_ = fbs->sectorsPerFat16 ?
fbs->sectorsPerFat16 : fbs->sectorsPerFat32; fbs->sectorsPerFat16 : fbs->sectorsPerFat32;
fatStartBlock_ = volumeStartBlock + fbs->reservedSectorCount; fatStartBlock_ = volumeStartBlock + fbs->reservedSectorCount;
// count for FAT16 zero for FAT32 // count for FAT16 zero for FAT32
rootDirEntryCount_ = fbs->rootDirEntryCount; rootDirEntryCount_ = fbs->rootDirEntryCount;
// directory start for FAT16 dataStart for FAT32 // directory start for FAT16 dataStart for FAT32
rootDirStart_ = fatStartBlock_ + fbs->fatCount * blocksPerFat_; rootDirStart_ = fatStartBlock_ + fbs->fatCount * blocksPerFat_;
// data start for FAT16 and FAT32 // data start for FAT16 and FAT32
dataStartBlock_ = rootDirStart_ + ((32 * fbs->rootDirEntryCount + 511)/512); dataStartBlock_ = rootDirStart_ + ((32 * fbs->rootDirEntryCount + 511)/512);
// total blocks for FAT16 or FAT32 // total blocks for FAT16 or FAT32
totalBlocks = fbs->totalSectors16 ? totalBlocks = fbs->totalSectors16 ?
fbs->totalSectors16 : fbs->totalSectors32; fbs->totalSectors16 : fbs->totalSectors32;
// total data blocks // total data blocks
clusterCount_ = totalBlocks - (dataStartBlock_ - volumeStartBlock); clusterCount_ = totalBlocks - (dataStartBlock_ - volumeStartBlock);
// divide by cluster size to get cluster count // divide by cluster size to get cluster count
clusterCount_ >>= clusterSizeShift_; clusterCount_ >>= clusterSizeShift_;
// FAT type is determined by cluster count // FAT type is determined by cluster count
if (clusterCount_ < 4085) { if (clusterCount_ < 4085) {
fatType_ = 12; fatType_ = 12;
if (!FAT12_SUPPORT) goto fail; if (!FAT12_SUPPORT) goto fail;
} else if (clusterCount_ < 65525) { } else if (clusterCount_ < 65525) {
fatType_ = 16; fatType_ = 16;
} else { } else {
rootDirStart_ = fbs->fat32RootCluster; rootDirStart_ = fbs->fat32RootCluster;
fatType_ = 32; fatType_ = 32;
} }
return true; return true;
fail: fail:
return false; return false;
} }
#endif #endif

View File

@ -47,6 +47,7 @@ public:
FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);}; FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);};
FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;}; FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;};
FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;}; FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;};
FORCE_INLINE uint32_t get_sdpos() { if (!isFileOpen()) return 0; else return(sdpos); };
bool ToshibaFlashAir_isEnabled() const { return card.getFlashAirCompatible(); } bool ToshibaFlashAir_isEnabled() const { return card.getFlashAirCompatible(); }
void ToshibaFlashAir_enable(bool enable) { card.setFlashAirCompatible(enable); } void ToshibaFlashAir_enable(bool enable) { card.setFlashAirCompatible(enable); }

View File

@ -315,4 +315,4 @@
#define(length=20) MSG_EXTRUDER_1 "Extruder 1" #define(length=20) MSG_EXTRUDER_1 "Extruder 1"
#define(length=20) MSG_EXTRUDER_2 "Extruder 2" #define(length=20) MSG_EXTRUDER_2 "Extruder 2"
#define(length=20) MSG_EXTRUDER_3 "Extruder 3" #define(length=20) MSG_EXTRUDER_3 "Extruder 3"
#define(length=20) MSG_EXTRUDER_4 "Extruder 4" #define(length=20) MSG_EXTRUDER_4 "Extruder 4"

View File

@ -273,9 +273,15 @@
#define MSG_MESH_BED_LEVELING "Mesh Bed Leveling" #define MSG_MESH_BED_LEVELING "Mesh Bed Leveling"
#define MSG_MENU_CALIBRATION "Calibration" #define MSG_MENU_CALIBRATION "Calibration"
<<<<<<< HEAD
#define(length=20) MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF "SD card [normal]" #define(length=20) MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF "SD card [normal]"
#define(length=20) MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON "SD card [FlshAir]" #define(length=20) MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON "SD card [FlshAir]"
#define(length=20) MSG_PRINTER_DISCONNECTED "Printer disconnected" #define(length=20) MSG_PRINTER_DISCONNECTED "Printer disconnected"
=======
#define(length=19, lines=1) MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF "SD card [normal]"
#define(length=19, lines=1) MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON "SD card [FlshAir]"
#define(length=20, lines=1) MSG_PRINTER_DISCONNECTED "Printer disconnected"
>>>>>>> refs/remotes/prusa3d/MK2
#define(length=20, lines=1) MSG_FINISHING_MOVEMENTS "Finishing movements" #define(length=20, lines=1) MSG_FINISHING_MOVEMENTS "Finishing movements"
#define(length=20, lines=1) MSG_PRINT_PAUSED "Print paused" #define(length=20, lines=1) MSG_PRINT_PAUSED "Print paused"
#define(length=20, lines=1) MSG_RESUMING_PRINT "Resuming print" #define(length=20, lines=1) MSG_RESUMING_PRINT "Resuming print"

View File

@ -1,289 +1,289 @@
#define WELCOME_MSG CUSTOM_MENDEL_NAME " pronta." #define WELCOME_MSG CUSTOM_MENDEL_NAME " pronta."
#define MSG_SD_INSERTED "SD inserita" #define MSG_SD_INSERTED "SD inserita"
#define MSG_SD_REMOVED "SD rimossa" #define MSG_SD_REMOVED "SD rimossa"
#define MSG_MAIN "Menu principale" #define MSG_MAIN "Menu principale"
#define MSG_DISABLE_STEPPERS "Disabilit motori" #define MSG_DISABLE_STEPPERS "Disabilit motori"
#define MSG_AUTO_HOME "Trova origine" #define MSG_AUTO_HOME "Trova origine"
#define MSG_SET_HOME_OFFSETS "Set home offsets" #define MSG_SET_HOME_OFFSETS "Set home offsets"
#define MSG_SET_ORIGIN "Set origin" #define MSG_SET_ORIGIN "Set origin"
#define MSG_COOLDOWN "Raffredda" #define MSG_COOLDOWN "Raffredda"
#define MSG_SWITCH_PS_ON "Switch power on" #define MSG_SWITCH_PS_ON "Switch power on"
#define MSG_SWITCH_PS_OFF "Switch power off" #define MSG_SWITCH_PS_OFF "Switch power off"
#define MSG_MOVE_AXIS "Muovi asse" #define MSG_MOVE_AXIS "Muovi asse"
#define MSG_MOVE_X "Muovi X" #define MSG_MOVE_X "Muovi X"
#define MSG_MOVE_Y "Muovi Y" #define MSG_MOVE_Y "Muovi Y"
#define MSG_MOVE_Z "Muovi Z" #define MSG_MOVE_Z "Muovi Z"
#define MSG_MOVE_E "Muovi Estrusore" #define MSG_MOVE_E "Muovi Estrusore"
#define MSG_MOVE_01MM "Move 0.1mm" #define MSG_MOVE_01MM "Move 0.1mm"
#define MSG_MOVE_1MM "Move 1mm" #define MSG_MOVE_1MM "Move 1mm"
#define MSG_MOVE_10MM "Move 10mm" #define MSG_MOVE_10MM "Move 10mm"
#define MSG_SPEED "Velocita" #define MSG_SPEED "Velocita"
#define MSG_NOZZLE "Ugello" #define MSG_NOZZLE "Ugello"
#define MSG_NOZZLE1 "Nozzle2" #define MSG_NOZZLE1 "Nozzle2"
#define MSG_NOZZLE2 "Nozzle3" #define MSG_NOZZLE2 "Nozzle3"
#define MSG_BED "Letto" #define MSG_BED "Letto"
#define MSG_FAN_SPEED "Velocita vent." #define MSG_FAN_SPEED "Velocita vent."
#define MSG_FLOW "Flusso" #define MSG_FLOW "Flusso"
#define MSG_TEMPERATURE "Temperatura" #define MSG_TEMPERATURE "Temperatura"
#define MSG_MOTION "Motion" #define MSG_MOTION "Motion"
#define MSG_VOLUMETRIC "Filament" #define MSG_VOLUMETRIC "Filament"
#define MSG_VOLUMETRIC_ENABLED "E in mm3" #define MSG_VOLUMETRIC_ENABLED "E in mm3"
#define MSG_STORE_EPROM "Store memory" #define MSG_STORE_EPROM "Store memory"
#define MSG_LOAD_EPROM "Load memory" #define MSG_LOAD_EPROM "Load memory"
#define MSG_RESTORE_FAILSAFE "Restore failsafe" #define MSG_RESTORE_FAILSAFE "Restore failsafe"
#define MSG_REFRESH "\xF8" "Refresh" #define MSG_REFRESH "\xF8" "Refresh"
#define MSG_WATCH "Schermata info" #define MSG_WATCH "Schermata info"
#define MSG_TUNE "Regola" #define MSG_TUNE "Regola"
#define MSG_PAUSE_PRINT "Metti in pausa" #define MSG_PAUSE_PRINT "Metti in pausa"
#define MSG_RESUME_PRINT "Riprendi stampa" #define MSG_RESUME_PRINT "Riprendi stampa"
#define MSG_STOP_PRINT "Arresta stampa" #define MSG_STOP_PRINT "Arresta stampa"
#define MSG_CARD_MENU "Stampa da SD" #define MSG_CARD_MENU "Stampa da SD"
#define MSG_NO_CARD "Nessuna SD" #define MSG_NO_CARD "Nessuna SD"
#define MSG_DWELL "Sospensione..." #define MSG_DWELL "Sospensione..."
#define MSG_USERWAIT "Attendendo utente" #define MSG_USERWAIT "Attendendo utente"
#define MSG_RESUMING "Riprendi stampa" #define MSG_RESUMING "Riprendi stampa"
#define MSG_PRINT_ABORTED "Stampa abortita" #define MSG_PRINT_ABORTED "Stampa abortita"
#define MSG_NO_MOVE "Nessun movimento." #define MSG_NO_MOVE "Nessun movimento."
#define MSG_KILLED "IN TILT." #define MSG_KILLED "IN TILT."
#define MSG_STOPPED "ARRESTATO." #define MSG_STOPPED "ARRESTATO."
#define MSG_FILAMENTCHANGE "Camb. filamento" #define MSG_FILAMENTCHANGE "Camb. filamento"
#define MSG_INIT_SDCARD "Init. SD card" #define MSG_INIT_SDCARD "Init. SD card"
#define MSG_CNG_SDCARD "Change SD card" #define MSG_CNG_SDCARD "Change SD card"
#define MSG_ZPROBE_OUT "Z probe out. bed" #define MSG_ZPROBE_OUT "Z probe out. bed"
#define MSG_POSITION_UNKNOWN "Home X/Y before Z" #define MSG_POSITION_UNKNOWN "Home X/Y before Z"
#define MSG_ZPROBE_ZOFFSET "Z Offset" #define MSG_ZPROBE_ZOFFSET "Z Offset"
#define MSG_BABYSTEP_X "Babystep X" #define MSG_BABYSTEP_X "Babystep X"
#define MSG_BABYSTEP_Y "Babystep Y" #define MSG_BABYSTEP_Y "Babystep Y"
#define MSG_BABYSTEP_Z "Compensazione Z" #define MSG_BABYSTEP_Z "Compensazione Z"
#define MSG_ADJUSTZ "Autoregolare Z?" #define MSG_ADJUSTZ "Autoregolare Z?"
#define MSG_PICK_Z "Pick print" #define MSG_PICK_Z "Pick print"
#define MSG_SETTINGS "Impostazioni" #define MSG_SETTINGS "Impostazioni"
#define MSG_PREHEAT "Preriscalda" #define MSG_PREHEAT "Preriscalda"
#define MSG_HEATING "Riscaldamento..." #define MSG_HEATING "Riscaldamento..."
#define MSG_SUPPORT "Support" #define MSG_SUPPORT "Support"
#define MSG_YES "Si" #define MSG_YES "Si"
#define MSG_NO "No" #define MSG_NO "No"
#define MSG_NOT_LOADED "Fil. non caricato" #define MSG_NOT_LOADED "Fil. non caricato"
#define MSG_NOT_COLOR "Colore non puro" #define MSG_NOT_COLOR "Colore non puro"
#define MSG_LOADING_COLOR "Caricando colore" #define MSG_LOADING_COLOR "Caricando colore"
#define MSG_CHANGE_SUCCESS "Cambio riuscito!" #define MSG_CHANGE_SUCCESS "Cambio riuscito!"
#define MSG_PRESS "e cliccare manopola" #define MSG_PRESS "e cliccare manopola"
#define MSG_INSERT_FILAMENT "Inserire filamento" #define MSG_INSERT_FILAMENT "Inserire filamento"
#define MSG_CHANGING_FILAMENT "Cambiando filam." #define MSG_CHANGING_FILAMENT "Cambiando filam."
#define MSG_PLEASE_WAIT "Aspetta" #define MSG_PLEASE_WAIT "Aspetta"
#define MSG_PREHEAT_NOZZLE "Preris. ugello!" #define MSG_PREHEAT_NOZZLE "Preris. ugello!"
#define MSG_HEATING_COMPLETE "Riscald. completo" #define MSG_HEATING_COMPLETE "Riscald. completo"
#define MSG_BED_HEATING "Riscald. letto" #define MSG_BED_HEATING "Riscald. letto"
#define MSG_BED_DONE "Piatto fatto." #define MSG_BED_DONE "Piatto fatto."
#define MSG_ERROR "ERRORE:" #define MSG_ERROR "ERRORE:"
#define MSG_CORRECTLY "Cambiato corr.?" #define MSG_CORRECTLY "Cambiato corr.?"
#define MSG_LOADING_FILAMENT "Caricando filam." #define MSG_LOADING_FILAMENT "Caricando filam."
#define MSG_UNLOAD_FILAMENT "Scarica filamento" #define MSG_UNLOAD_FILAMENT "Scarica filamento"
#define MSG_LOAD_FILAMENT "Carica filamento" #define MSG_LOAD_FILAMENT "Carica filamento"
#define MSG_SILENT_MODE_ON "Modo [silenzioso]" #define MSG_SILENT_MODE_ON "Modo [silenzioso]"
#define MSG_SILENT_MODE_OFF "Mode [forte]" #define MSG_SILENT_MODE_OFF "Mode [forte]"
#define MSG_REBOOT "Riavvia stampante" #define MSG_REBOOT "Riavvia stampante"
#define MSG_TAKE_EFFECT " per attualizzare" #define MSG_TAKE_EFFECT " per attualizzare"
#define MSG_Enqueing "enqueing \"" #define MSG_Enqueing "enqueing \""
#define MSG_POWERUP "PowerUp" #define MSG_POWERUP "PowerUp"
#define MSG_CONFIGURATION_VER " Last Updated: " #define MSG_CONFIGURATION_VER " Last Updated: "
#define MSG_FREE_MEMORY " Free Memory: " #define MSG_FREE_MEMORY " Free Memory: "
#define MSG_PLANNER_BUFFER_BYTES " PlannerBufferBytes: " #define MSG_PLANNER_BUFFER_BYTES " PlannerBufferBytes: "
#define MSG_OK "ok" #define MSG_OK "ok"
#define MSG_ERR_CHECKSUM_MISMATCH "checksum mismatch, Last Line: " #define MSG_ERR_CHECKSUM_MISMATCH "checksum mismatch, Last Line: "
#define MSG_ERR_NO_CHECKSUM "No Checksum with line number, Last Line: " #define MSG_ERR_NO_CHECKSUM "No Checksum with line number, Last Line: "
#define MSG_BEGIN_FILE_LIST "Begin file list" #define MSG_BEGIN_FILE_LIST "Begin file list"
#define MSG_END_FILE_LIST "End file list" #define MSG_END_FILE_LIST "End file list"
#define MSG_M104_INVALID_EXTRUDER "M104 Invalid extruder " #define MSG_M104_INVALID_EXTRUDER "M104 Invalid extruder "
#define MSG_M105_INVALID_EXTRUDER "M105 Invalid extruder " #define MSG_M105_INVALID_EXTRUDER "M105 Invalid extruder "
#define MSG_M200_INVALID_EXTRUDER "M200 Invalid extruder " #define MSG_M200_INVALID_EXTRUDER "M200 Invalid extruder "
#define MSG_M218_INVALID_EXTRUDER "M218 Invalid extruder " #define MSG_M218_INVALID_EXTRUDER "M218 Invalid extruder "
#define MSG_M221_INVALID_EXTRUDER "M221 Invalid extruder " #define MSG_M221_INVALID_EXTRUDER "M221 Invalid extruder "
#define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature" #define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature"
#define MSG_M109_INVALID_EXTRUDER "M109 Invalid extruder " #define MSG_M109_INVALID_EXTRUDER "M109 Invalid extruder "
#define MSG_M115_REPORT "FIRMWARE_NAME:Marlin V1.0.2; Sprinter/grbl mashup for gen6 FIRMWARE_URL:" FIRMWARE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" CUSTOM_MENDEL_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID "\n" #define MSG_M115_REPORT "FIRMWARE_NAME:Marlin V1.0.2; Sprinter/grbl mashup for gen6 FIRMWARE_URL:" FIRMWARE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" CUSTOM_MENDEL_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID "\n"
#define MSG_ERR_KILLED "Printer halted. kill() called!" #define MSG_ERR_KILLED "Printer halted. kill() called!"
#define MSG_ERR_STOPPED "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)" #define MSG_ERR_STOPPED "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"
#define MSG_RESEND "Resend: " #define MSG_RESEND "Resend: "
#define MSG_M119_REPORT "Reporting endstop status" #define MSG_M119_REPORT "Reporting endstop status"
#define MSG_ENDSTOP_HIT "TRIGGERED" #define MSG_ENDSTOP_HIT "TRIGGERED"
#define MSG_ENDSTOP_OPEN "open" #define MSG_ENDSTOP_OPEN "open"
#define MSG_SD_CANT_OPEN_SUBDIR "Cannot open subdir" #define MSG_SD_CANT_OPEN_SUBDIR "Cannot open subdir"
#define MSG_SD_INIT_FAIL "SD init fail" #define MSG_SD_INIT_FAIL "SD init fail"
#define MSG_SD_VOL_INIT_FAIL "volume.init failed" #define MSG_SD_VOL_INIT_FAIL "volume.init failed"
#define MSG_SD_OPENROOT_FAIL "openRoot failed" #define MSG_SD_OPENROOT_FAIL "openRoot failed"
#define MSG_SD_CARD_OK "SD card ok" #define MSG_SD_CARD_OK "SD card ok"
#define MSG_SD_WORKDIR_FAIL "workDir open failed" #define MSG_SD_WORKDIR_FAIL "workDir open failed"
#define MSG_SD_OPEN_FILE_FAIL "open failed, File: " #define MSG_SD_OPEN_FILE_FAIL "open failed, File: "
#define MSG_SD_FILE_OPENED "File opened: " #define MSG_SD_FILE_OPENED "File opened: "
#define MSG_SD_FILE_SELECTED "File selected" #define MSG_SD_FILE_SELECTED "File selected"
#define MSG_SD_WRITE_TO_FILE "Writing to file: " #define MSG_SD_WRITE_TO_FILE "Writing to file: "
#define MSG_SD_PRINTING_BYTE "SD printing byte " #define MSG_SD_PRINTING_BYTE "SD printing byte "
#define MSG_SD_NOT_PRINTING "Not SD printing" #define MSG_SD_NOT_PRINTING "Not SD printing"
#define MSG_SD_ERR_WRITE_TO_FILE "error writing to file" #define MSG_SD_ERR_WRITE_TO_FILE "error writing to file"
#define MSG_SD_CANT_ENTER_SUBDIR "Cannot enter subdir: " #define MSG_SD_CANT_ENTER_SUBDIR "Cannot enter subdir: "
#define MSG_STEPPER_TOO_HIGH "Steprate too high: " #define MSG_STEPPER_TOO_HIGH "Steprate too high: "
#define MSG_ENDSTOPS_HIT "endstops hit: " #define MSG_ENDSTOPS_HIT "endstops hit: "
#define MSG_ERR_COLD_EXTRUDE_STOP " cold extrusion prevented" #define MSG_ERR_COLD_EXTRUDE_STOP " cold extrusion prevented"
#define MSG_BABYSTEPPING_X "Babystepping X" #define MSG_BABYSTEPPING_X "Babystepping X"
#define MSG_BABYSTEPPING_Y "Babystepping Y" #define MSG_BABYSTEPPING_Y "Babystepping Y"
#define MSG_BABYSTEPPING_Z "Adjusting Z" #define MSG_BABYSTEPPING_Z "Adjusting Z"
#define MSG_SERIAL_ERROR_MENU_STRUCTURE "Error in menu structure" #define MSG_SERIAL_ERROR_MENU_STRUCTURE "Error in menu structure"
#define MSG_LANGUAGE_NAME "Italiano" #define MSG_LANGUAGE_NAME "Italiano"
#define MSG_LANGUAGE_SELECT "Seleziona lingua" #define MSG_LANGUAGE_SELECT "Seleziona lingua"
#define MSG_PRUSA3D "prusa3d.com" #define MSG_PRUSA3D "prusa3d.com"
#define MSG_PRUSA3D_FORUM "forum.prusa3d.com" #define MSG_PRUSA3D_FORUM "forum.prusa3d.com"
#define MSG_PRUSA3D_HOWTO "howto.prusa3d.com" #define MSG_PRUSA3D_HOWTO "howto.prusa3d.com"
#define MSG_SELFTEST_ERROR "Autotest negativo" #define MSG_SELFTEST_ERROR "Autotest negativo"
#define MSG_SELFTEST_PLEASECHECK "Verificare:" #define MSG_SELFTEST_PLEASECHECK "Verificare:"
#define MSG_SELFTEST_NOTCONNECTED "Non connesso" #define MSG_SELFTEST_NOTCONNECTED "Non connesso"
#define MSG_SELFTEST_HEATERTHERMISTOR "Riscald./Termist." #define MSG_SELFTEST_HEATERTHERMISTOR "Riscald./Termist."
#define MSG_SELFTEST_BEDHEATER "Letto/Riscald." #define MSG_SELFTEST_BEDHEATER "Letto/Riscald."
#define MSG_SELFTEST_WIRINGERROR "Errore cablaggio" #define MSG_SELFTEST_WIRINGERROR "Errore cablaggio"
#define MSG_SELFTEST_ENDSTOPS "Finecorsa (2)" #define MSG_SELFTEST_ENDSTOPS "Finecorsa (2)"
#define MSG_SELFTEST_MOTOR "Motore" #define MSG_SELFTEST_MOTOR "Motore"
#define MSG_SELFTEST_ENDSTOP "Finecorsa" #define MSG_SELFTEST_ENDSTOP "Finecorsa"
#define MSG_SELFTEST_ENDSTOP_NOTHIT "Finec. fuori por." #define MSG_SELFTEST_ENDSTOP_NOTHIT "Finec. fuori por."
#define MSG_SELFTEST_OK "Autotest OK" #define MSG_SELFTEST_OK "Autotest OK"
#define(length=20) MSG_SELFTEST_FAN "Prova del ventilator"; #define(length=20) MSG_SELFTEST_FAN "Prova del ventilator";
#define(length=20) MSG_SELFTEST_COOLING_FAN "Vent di stampa ant.?"; #define(length=20) MSG_SELFTEST_COOLING_FAN "Vent di stampa ant.?";
#define(length=20) MSG_SELFTEST_EXTRUDER_FAN "Vent SX sull'ugello?"; #define(length=20) MSG_SELFTEST_EXTRUDER_FAN "Vent SX sull'ugello?";
#define MSG_SELFTEST_FAN_YES "Gira"; #define MSG_SELFTEST_FAN_YES "Gira";
#define MSG_SELFTEST_FAN_NO "Non si gira"; #define MSG_SELFTEST_FAN_NO "Non si gira";
#define MSG_STATS_TOTALFILAMENT "Filamento tot:" #define MSG_STATS_TOTALFILAMENT "Filamento tot:"
#define MSG_STATS_TOTALPRINTTIME "Tempo stampa tot:" #define MSG_STATS_TOTALPRINTTIME "Tempo stampa tot:"
#define MSG_STATS_FILAMENTUSED "Filamento usato:" #define MSG_STATS_FILAMENTUSED "Filamento usato:"
#define MSG_STATS_PRINTTIME "Tempo di stampa:" #define MSG_STATS_PRINTTIME "Tempo di stampa:"
#define MSG_SELFTEST_START "Avvia autotest" #define MSG_SELFTEST_START "Avvia autotest"
#define MSG_SELFTEST_CHECK_ENDSTOPS "Verifica finecorsa" #define MSG_SELFTEST_CHECK_ENDSTOPS "Verifica finecorsa"
#define MSG_SELFTEST_CHECK_HOTEND "Verifica ugello" #define MSG_SELFTEST_CHECK_HOTEND "Verifica ugello"
#define MSG_SELFTEST_CHECK_X "Verifica asse X" #define MSG_SELFTEST_CHECK_X "Verifica asse X"
#define MSG_SELFTEST_CHECK_Y "Verifica asse Y" #define MSG_SELFTEST_CHECK_Y "Verifica asse Y"
#define MSG_SELFTEST_CHECK_Z "Verifica asse Z" #define MSG_SELFTEST_CHECK_Z "Verifica asse Z"
#define MSG_SELFTEST_CHECK_BED "Verifica letto" #define MSG_SELFTEST_CHECK_BED "Verifica letto"
#define MSG_SELFTEST_CHECK_ALLCORRECT "Nessun errore" #define MSG_SELFTEST_CHECK_ALLCORRECT "Nessun errore"
#define MSG_SELFTEST "Autotest" #define MSG_SELFTEST "Autotest"
#define MSG_SELFTEST_FAILED "Autotest fallito" #define MSG_SELFTEST_FAILED "Autotest fallito"
#define MSG_STATISTICS "Statistiche" #define MSG_STATISTICS "Statistiche"
#define MSG_USB_PRINTING "Stampa da USB" #define MSG_USB_PRINTING "Stampa da USB"
#define MSG_HOMEYZ "Calibra Z" #define MSG_HOMEYZ "Calibra Z"
#define MSG_HOMEYZ_PROGRESS "Calibrando Z" #define MSG_HOMEYZ_PROGRESS "Calibrando Z"
#define MSG_HOMEYZ_DONE "Calibrazione OK" #define MSG_HOMEYZ_DONE "Calibrazione OK"
#define MSG_SHOW_END_STOPS "Stato finecorsa" #define MSG_SHOW_END_STOPS "Stato finecorsa"
#define MSG_CALIBRATE_BED "Calibra XYZ" #define MSG_CALIBRATE_BED "Calibra XYZ"
#define MSG_CALIBRATE_BED_RESET "Reset XYZ calibr." #define MSG_CALIBRATE_BED_RESET "Reset XYZ calibr."
#define MSG_MOVE_CARRIAGE_TO_THE_TOP "Calibrazione XYZ. Ruotare la manopola per alzare il carrello Z fino all'altezza massima. Click per terminare." #define MSG_MOVE_CARRIAGE_TO_THE_TOP "Calibrazione XYZ. Ruotare la manopola per alzare il carrello Z fino all'altezza massima. Click per terminare."
#define MSG_MOVE_CARRIAGE_TO_THE_TOP_Z "Calibrazione Z. Ruotare la manopola per alzare il carrello Z fino all'altezza massima. Click per terminare." #define MSG_MOVE_CARRIAGE_TO_THE_TOP_Z "Calibrazione Z. Ruotare la manopola per alzare il carrello Z fino all'altezza massima. Click per terminare."
#define MSG_CONFIRM_NOZZLE_CLEAN "Pulire l'ugello per la calibrazione, poi fare click." #define MSG_CONFIRM_NOZZLE_CLEAN "Pulire l'ugello per la calibrazione, poi fare click."
#define MSG_CONFIRM_CARRIAGE_AT_THE_TOP "I carrelli Z sin/des sono altezza max?" #define MSG_CONFIRM_CARRIAGE_AT_THE_TOP "I carrelli Z sin/des sono altezza max?"
#define MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Ricerca del letto punto di calibraz." #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Ricerca del letto punto di calibraz."
#define MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " su 4" #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " su 4"
#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Perfezion. il letto punto di calibraz." #define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Perfezion. il letto punto di calibraz."
#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " su 9" #define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " su 9"
#define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Misurare l'altezza di riferimento del punto di calibrazione" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Misurare l'altezza di riferimento del punto di calibrazione"
#define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " su 9" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " su 9"
#define MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Reiterazione " #define MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Reiterazione "
#define MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND "Calibrazione XYZ fallita. Il punto di calibrazione sul letto non e' stato trovato." #define MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND "Calibrazione XYZ fallita. Il punto di calibrazione sul letto non e' stato trovato."
#define MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED "Calibrazione XYZ fallita. Si prega di consultare il manuale." #define MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED "Calibrazione XYZ fallita. Si prega di consultare il manuale."
#define MSG_BED_SKEW_OFFSET_DETECTION_PERFECT "Calibrazione XYZ OK. Gli assi X/Y sono perpendicolari. Complimenti!" #define MSG_BED_SKEW_OFFSET_DETECTION_PERFECT "Calibrazione XYZ OK. Gli assi X/Y sono perpendicolari. Complimenti!"
#define MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD "Calibrazion XYZ corretta. Assi X/Y leggermente storti. Ben fatto!" #define MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD "Calibrazion XYZ corretta. Assi X/Y leggermente storti. Ben fatto!"
#define MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME "Calibrazion XYZ corretta. La distorsione verra' automaticamente compensata." #define MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME "Calibrazion XYZ corretta. La distorsione verra' automaticamente compensata."
#define MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR "Calibrazione XYZ fallita. Punto anteriore sinistro non raggiungibile." #define MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR "Calibrazione XYZ fallita. Punto anteriore sinistro non raggiungibile."
#define MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR "Calibrazione XYZ fallita. Punto anteriore destro non raggiungibile." #define MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR "Calibrazione XYZ fallita. Punto anteriore destro non raggiungibile."
#define MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR "Calibrazione XYZ fallita. Punti anteriori non raggiungibili." #define MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR "Calibrazione XYZ fallita. Punti anteriori non raggiungibili."
#define MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR "Calibrazione XYZ compromessa. Punto anteriore sinistro non raggiungibile." #define MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR "Calibrazione XYZ compromessa. Punto anteriore sinistro non raggiungibile."
#define MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR "Calibrazione XYZ compromessa. Punto anteriore destro non raggiungibile." #define MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR "Calibrazione XYZ compromessa. Punto anteriore destro non raggiungibile."
#define MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR "Calibrazione XYZ compromessa. Punti anteriori non raggiungibili." #define MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR "Calibrazione XYZ compromessa. Punti anteriori non raggiungibili."
#define MSG_BED_LEVELING_FAILED_POINT_LOW "Livellamento letto fallito.NoRispSensor Residui su ugello? In attesa di reset." #define MSG_BED_LEVELING_FAILED_POINT_LOW "Livellamento letto fallito.NoRispSensor Residui su ugello? In attesa di reset."
#define MSG_BED_LEVELING_FAILED_POINT_HIGH "Livellamento letto fallito.Risp sensore troppo prestoIn attesa di reset." #define MSG_BED_LEVELING_FAILED_POINT_HIGH "Livellamento letto fallito.Risp sensore troppo prestoIn attesa di reset."
#define MSG_BED_LEVELING_FAILED_PROBE_DISCONNECTED "Livellamento letto fallito. Sensore discon. o Cavo Dann. In attesa di reset." #define MSG_BED_LEVELING_FAILED_PROBE_DISCONNECTED "Livellamento letto fallito. Sensore discon. o Cavo Dann. In attesa di reset."
#define MSG_NEW_FIRMWARE_AVAILABLE "Nuova versione del firmware disponibile" #define MSG_NEW_FIRMWARE_AVAILABLE "Nuova versione del firmware disponibile"
#define MSG_NEW_FIRMWARE_PLEASE_UPGRADE "Prega aggiorna." #define MSG_NEW_FIRMWARE_PLEASE_UPGRADE "Prega aggiorna."
#define MSG_FOLLOW_CALIBRATION_FLOW "Stampante ancora non calibrata. Si prega di seguire il manuale, capitolo PRIMI PASSI, sezione della calibrazione." #define MSG_FOLLOW_CALIBRATION_FLOW "Stampante ancora non calibrata. Si prega di seguire il manuale, capitolo PRIMI PASSI, sezione della calibrazione."
#define MSG_BABYSTEP_Z_NOT_SET "Distanza tra la punta dell'ugello e la superficie del letto non ancora imposta. Si prega di seguire il manuale, capitolo First steps, sezione First layer calibration." #define MSG_BABYSTEP_Z_NOT_SET "Distanza tra la punta dell'ugello e la superficie del letto non ancora imposta. Si prega di seguire il manuale, capitolo First steps, sezione First layer calibration."
#define MSG_BED_CORRECTION_MENU "Correz. liv.letto" #define MSG_BED_CORRECTION_MENU "Correz. liv.letto"
#define MSG_BED_CORRECTION_LEFT "Sinistra [um]" #define MSG_BED_CORRECTION_LEFT "Sinistra [um]"
#define MSG_BED_CORRECTION_RIGHT "Destra [um]" #define MSG_BED_CORRECTION_RIGHT "Destra [um]"
#define MSG_BED_CORRECTION_FRONT "Fronte [um]" #define MSG_BED_CORRECTION_FRONT "Fronte [um]"
#define MSG_BED_CORRECTION_REAR "Retro [um]" #define MSG_BED_CORRECTION_REAR "Retro [um]"
#define MSG_BED_CORRECTION_RESET "Reset" #define MSG_BED_CORRECTION_RESET "Reset"
#define MSG_MESH_BED_LEVELING "Mesh livel. letto" #define MSG_MESH_BED_LEVELING "Mesh livel. letto"
#define MSG_MENU_CALIBRATION "Calibrazione" #define MSG_MENU_CALIBRATION "Calibrazione"
#define MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF "SD card [normal]" #define MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF "SD card [normal]"
#define MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON "SD card [FlshAir]" #define MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON "SD card [FlshAir]"
#define MSG_LOOSE_PULLEY "Puleggia lenta" #define MSG_LOOSE_PULLEY "Puleggia lenta"
#define MSG_FILAMENT_LOADING_T0 "Inserire filamento nell'estrusore 1. Click per continuare." #define MSG_FILAMENT_LOADING_T0 "Inserire filamento nell'estrusore 1. Click per continuare."
#define MSG_FILAMENT_LOADING_T1 "Inserire filamento nell'estrusore 2. Click per continuare." #define MSG_FILAMENT_LOADING_T1 "Inserire filamento nell'estrusore 2. Click per continuare."
#define MSG_FILAMENT_LOADING_T2 "Inserire filamento nell'estrusore 3. Click per continuare." #define MSG_FILAMENT_LOADING_T2 "Inserire filamento nell'estrusore 3. Click per continuare."
#define MSG_FILAMENT_LOADING_T3 "Inserire filamento nell'estrusore 4. Click per continuare." #define MSG_FILAMENT_LOADING_T3 "Inserire filamento nell'estrusore 4. Click per continuare."
#define MSG_CHANGE_EXTR "Cambio estrusore." #define MSG_CHANGE_EXTR "Cambio estrusore."
#define MSG_FIL_ADJUSTING "Filamento in fase di regolazione. Attendere prego." #define MSG_FIL_ADJUSTING "Filamento in fase di regolazione. Attendere prego."
#define MSG_CONFIRM_NOZZLE_CLEAN_FIL_ADJ "I filamenti sono regolati. Si prega di pulire l'ugello per la calibrazione. Click per continuare." #define MSG_CONFIRM_NOZZLE_CLEAN_FIL_ADJ "I filamenti sono regolati. Si prega di pulire l'ugello per la calibrazione. Click per continuare."
#define MSG_CALIBRATE_E "Calibra E" #define MSG_CALIBRATE_E "Calibra E"
#define MSG_E_CAL_KNOB "Girare la manopola affinche' il segno raggiunga il corpo dell'estrusore. Click per continuare." #define MSG_E_CAL_KNOB "Girare la manopola affinche' il segno raggiunga il corpo dell'estrusore. Click per continuare."
#define MSG_MARK_FIL "Segnare il filamento a 100 mm di distanza dal corpo dell'estrusore. Click per continuare." #define MSG_MARK_FIL "Segnare il filamento a 100 mm di distanza dal corpo dell'estrusore. Click per continuare."
#define MSG_CLEAN_NOZZLE_E "Calibrazione E terminata. Si prega di pulire l'ugello. Click per continuare." #define MSG_CLEAN_NOZZLE_E "Calibrazione E terminata. Si prega di pulire l'ugello. Click per continuare."
#define MSG_WAITING_TEMP "In attesa del raffreddamento della testina e del piatto" #define MSG_WAITING_TEMP "In attesa del raffreddamento della testina e del piatto"
#define MSG_FILAMENT_CLEAN "Il colore e' nitido?" #define MSG_FILAMENT_CLEAN "Il colore e' nitido?"
#define MSG_UNLOADING_FILAMENT "Rilasc. filamento" #define MSG_UNLOADING_FILAMENT "Rilasc. filamento"
#define MSG_PAPER "Porre un foglio sotto l'ugello durante la calibrazione dei primi 4 punti. In caso l'ugello muova il foglio spegnere prontamente la stampante." #define MSG_PAPER "Porre un foglio sotto l'ugello durante la calibrazione dei primi 4 punti. In caso l'ugello muova il foglio spegnere prontamente la stampante."
#define MSG_FINISHING_MOVEMENTS "Arresto in corso" #define MSG_FINISHING_MOVEMENTS "Arresto in corso"
#define MSG_PRINT_PAUSED "Stampa in pausa" #define MSG_PRINT_PAUSED "Stampa in pausa"
#define MSG_RESUMING_PRINT "Stampa in ripresa" #define MSG_RESUMING_PRINT "Stampa in ripresa"
#define MSG_PID_EXTRUDER "Calibrazione PID" #define MSG_PID_EXTRUDER "Calibrazione PID"
#define MSG_SET_TEMPERATURE "Imposta temperatura" #define MSG_SET_TEMPERATURE "Imposta temperatura"
#define MSG_PID_FINISHED "Cal. PID completa" #define MSG_PID_FINISHED "Cal. PID completa"
#define MSG_PID_RUNNING "Cal. PID" #define MSG_PID_RUNNING "Cal. PID"
#define MSG_CALIBRATE_PINDA "Calibrare" #define MSG_CALIBRATE_PINDA "Calibrare"
#define MSG_CALIBRATION_PINDA_MENU "Taratura temp." #define MSG_CALIBRATION_PINDA_MENU "Taratura temp."
#define MSG_PINDA_NOT_CALIBRATED "Taratura della temperatura non ancora eseguita" #define MSG_PINDA_NOT_CALIBRATED "Taratura della temperatura non ancora eseguita"
#define MSG_PINDA_PREHEAT "Riscald. PINDA" #define MSG_PINDA_PREHEAT "Riscald. PINDA"
#define MSG_TEMP_CALIBRATION "Cal. temp. " #define MSG_TEMP_CALIBRATION "Cal. temp. "
#define MSG_TEMP_CALIBRATION_DONE "Taratura temperatura terminata. Fare click per continuare." #define MSG_TEMP_CALIBRATION_DONE "Taratura temperatura terminata. Fare click per continuare."
#define MSG_TEMP_CALIBRATION_ON "Cal. temp. [ON]" #define MSG_TEMP_CALIBRATION_ON "Cal. temp. [ON]"
#define MSG_TEMP_CALIBRATION_OFF "Cal. temp. [OFF]" #define MSG_TEMP_CALIBRATION_OFF "Cal. temp. [OFF]"
#define MSG_LOAD_ALL "Caricare tutti" #define MSG_LOAD_ALL "Caricare tutti"
#define MSG_LOAD_FILAMENT_1 "Caricare fil. 1" #define MSG_LOAD_FILAMENT_1 "Caricare fil. 1"
#define MSG_LOAD_FILAMENT_2 "Caricare fil. 2" #define MSG_LOAD_FILAMENT_2 "Caricare fil. 2"
#define MSG_LOAD_FILAMENT_3 "Caricare fil. 3" #define MSG_LOAD_FILAMENT_3 "Caricare fil. 3"
#define MSG_LOAD_FILAMENT_4 "Caricare fil. 4" #define MSG_LOAD_FILAMENT_4 "Caricare fil. 4"
#define MSG_UNLOAD_FILAMENT_1 "Rilasciare fil. 1" #define MSG_UNLOAD_FILAMENT_1 "Rilasciare fil. 1"
#define MSG_UNLOAD_FILAMENT_2 "Rilasciare fil. 1" #define MSG_UNLOAD_FILAMENT_2 "Rilasciare fil. 1"
#define MSG_UNLOAD_FILAMENT_3 "Rilasciare fil. 1" #define MSG_UNLOAD_FILAMENT_3 "Rilasciare fil. 1"
#define MSG_UNLOAD_FILAMENT_4 "Rilasciare fil. 1" #define MSG_UNLOAD_FILAMENT_4 "Rilasciare fil. 1"
#define MSG_UNLOAD_ALL "Rilasciare tutti" #define MSG_UNLOAD_ALL "Rilasciare tutti"
#define MSG_PREPARE_FILAMENT "Preparare filamento" #define MSG_PREPARE_FILAMENT "Preparare filamento"
#define MSG_ALL "Tutti" #define MSG_ALL "Tutti"
#define MSG_USED "Usati nella stampa" #define MSG_USED "Usati nella stampa"
#define MSG_CURRENT "Attuale" #define MSG_CURRENT "Attuale"
#define MSG_CHOOSE_EXTRUDER "Seleziona estrusore:" #define MSG_CHOOSE_EXTRUDER "Seleziona estrusore:"
#define MSG_EXTRUDER "Estrusore" #define MSG_EXTRUDER "Estrusore"
#define MSG_EXTRUDER_1 "Estrusore 1" #define MSG_EXTRUDER_1 "Estrusore 1"
#define MSG_EXTRUDER_2 "Estrusore 2" #define MSG_EXTRUDER_2 "Estrusore 2"
#define MSG_EXTRUDER_3 "Estrusore 3" #define MSG_EXTRUDER_3 "Estrusore 3"
#define MSG_EXTRUDER_4 "Estrusore 4" #define MSG_EXTRUDER_4 "Estrusore 4"

File diff suppressed because it is too large Load Diff

View File

@ -1,186 +1,186 @@
#ifndef MESH_BED_CALIBRATION_H #ifndef MESH_BED_CALIBRATION_H
#define MESH_BED_CALIBRATION_H #define MESH_BED_CALIBRATION_H
// Exact positions of the print head above the bed reference points, in the world coordinates. // Exact positions of the print head above the bed reference points, in the world coordinates.
// The world coordinates match the machine coordinates only in case, when the machine // The world coordinates match the machine coordinates only in case, when the machine
// is built properly, the end stops are at the correct positions and the axes are perpendicular. // is built properly, the end stops are at the correct positions and the axes are perpendicular.
extern const float bed_ref_points[] PROGMEM; extern const float bed_ref_points[] PROGMEM;
extern const float bed_skew_angle_mild; extern const float bed_skew_angle_mild;
extern const float bed_skew_angle_extreme; extern const float bed_skew_angle_extreme;
// Is the world2machine correction activated? // Is the world2machine correction activated?
enum World2MachineCorrectionMode enum World2MachineCorrectionMode
{ {
WORLD2MACHINE_CORRECTION_NONE = 0, WORLD2MACHINE_CORRECTION_NONE = 0,
WORLD2MACHINE_CORRECTION_SHIFT = 1, WORLD2MACHINE_CORRECTION_SHIFT = 1,
WORLD2MACHINE_CORRECTION_SKEW = 2, WORLD2MACHINE_CORRECTION_SKEW = 2,
}; };
extern uint8_t world2machine_correction_mode; extern uint8_t world2machine_correction_mode;
// 2x2 transformation matrix from the world coordinates to the machine coordinates. // 2x2 transformation matrix from the world coordinates to the machine coordinates.
// Corrects for the rotation and skew of the machine axes. // Corrects for the rotation and skew of the machine axes.
// Used by the planner's plan_buffer_line() and plan_set_position(). // Used by the planner's plan_buffer_line() and plan_set_position().
extern float world2machine_rotation_and_skew[2][2]; extern float world2machine_rotation_and_skew[2][2];
extern float world2machine_rotation_and_skew_inv[2][2]; extern float world2machine_rotation_and_skew_inv[2][2];
// Shift of the machine zero point, in the machine coordinates. // Shift of the machine zero point, in the machine coordinates.
extern float world2machine_shift[2]; extern float world2machine_shift[2];
// Resets the transformation to identity. // Resets the transformation to identity.
extern void world2machine_reset(); extern void world2machine_reset();
// Resets the transformation to identity and update current_position[X,Y] from the servos. // Resets the transformation to identity and update current_position[X,Y] from the servos.
extern void world2machine_revert_to_uncorrected(); extern void world2machine_revert_to_uncorrected();
// Loads the transformation from the EEPROM, if available. // Loads the transformation from the EEPROM, if available.
extern void world2machine_initialize(); extern void world2machine_initialize();
// When switching from absolute to corrected coordinates, // When switching from absolute to corrected coordinates,
// this will apply an inverse world2machine transformation // this will apply an inverse world2machine transformation
// to current_position[x,y]. // to current_position[x,y].
extern void world2machine_update_current(); extern void world2machine_update_current();
inline void world2machine(const float &x, const float &y, float &out_x, float &out_y) inline void world2machine(const float &x, const float &y, float &out_x, float &out_y)
{ {
if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) { if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) {
// No correction. // No correction.
out_x = x; out_x = x;
out_y = y; out_y = y;
} else { } else {
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) {
// Firs the skew & rotation correction. // Firs the skew & rotation correction.
out_x = world2machine_rotation_and_skew[0][0] * x + world2machine_rotation_and_skew[0][1] * y; out_x = world2machine_rotation_and_skew[0][0] * x + world2machine_rotation_and_skew[0][1] * y;
out_y = world2machine_rotation_and_skew[1][0] * x + world2machine_rotation_and_skew[1][1] * y; out_y = world2machine_rotation_and_skew[1][0] * x + world2machine_rotation_and_skew[1][1] * y;
} }
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) {
// Then add the offset. // Then add the offset.
out_x += world2machine_shift[0]; out_x += world2machine_shift[0];
out_y += world2machine_shift[1]; out_y += world2machine_shift[1];
} }
} }
} }
inline void world2machine(float &x, float &y) inline void world2machine(float &x, float &y)
{ {
if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) { if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) {
// No correction. // No correction.
} else { } else {
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) {
// Firs the skew & rotation correction. // Firs the skew & rotation correction.
float out_x = world2machine_rotation_and_skew[0][0] * x + world2machine_rotation_and_skew[0][1] * y; float out_x = world2machine_rotation_and_skew[0][0] * x + world2machine_rotation_and_skew[0][1] * y;
float out_y = world2machine_rotation_and_skew[1][0] * x + world2machine_rotation_and_skew[1][1] * y; float out_y = world2machine_rotation_and_skew[1][0] * x + world2machine_rotation_and_skew[1][1] * y;
x = out_x; x = out_x;
y = out_y; y = out_y;
} }
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) {
// Then add the offset. // Then add the offset.
x += world2machine_shift[0]; x += world2machine_shift[0];
y += world2machine_shift[1]; y += world2machine_shift[1];
} }
} }
} }
inline void machine2world(float x, float y, float &out_x, float &out_y) inline void machine2world(float x, float y, float &out_x, float &out_y)
{ {
if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) { if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) {
// No correction. // No correction.
out_x = x; out_x = x;
out_y = y; out_y = y;
} else { } else {
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) {
// Then add the offset. // Then add the offset.
x -= world2machine_shift[0]; x -= world2machine_shift[0];
y -= world2machine_shift[1]; y -= world2machine_shift[1];
} }
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) {
// Firs the skew & rotation correction. // Firs the skew & rotation correction.
out_x = world2machine_rotation_and_skew_inv[0][0] * x + world2machine_rotation_and_skew_inv[0][1] * y; out_x = world2machine_rotation_and_skew_inv[0][0] * x + world2machine_rotation_and_skew_inv[0][1] * y;
out_y = world2machine_rotation_and_skew_inv[1][0] * x + world2machine_rotation_and_skew_inv[1][1] * y; out_y = world2machine_rotation_and_skew_inv[1][0] * x + world2machine_rotation_and_skew_inv[1][1] * y;
} }
} }
} }
inline void machine2world(float &x, float &y) inline void machine2world(float &x, float &y)
{ {
if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) { if (world2machine_correction_mode == WORLD2MACHINE_CORRECTION_NONE) {
// No correction. // No correction.
} else { } else {
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SHIFT) {
// Then add the offset. // Then add the offset.
x -= world2machine_shift[0]; x -= world2machine_shift[0];
y -= world2machine_shift[1]; y -= world2machine_shift[1];
} }
if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) { if (world2machine_correction_mode & WORLD2MACHINE_CORRECTION_SKEW) {
// Firs the skew & rotation correction. // Firs the skew & rotation correction.
float out_x = world2machine_rotation_and_skew_inv[0][0] * x + world2machine_rotation_and_skew_inv[0][1] * y; float out_x = world2machine_rotation_and_skew_inv[0][0] * x + world2machine_rotation_and_skew_inv[0][1] * y;
float out_y = world2machine_rotation_and_skew_inv[1][0] * x + world2machine_rotation_and_skew_inv[1][1] * y; float out_y = world2machine_rotation_and_skew_inv[1][0] * x + world2machine_rotation_and_skew_inv[1][1] * y;
x = out_x; x = out_x;
y = out_y; y = out_y;
} }
} }
} }
inline bool world2machine_clamp(float &x, float &y) inline bool world2machine_clamp(float &x, float &y)
{ {
bool clamped = false; bool clamped = false;
float tmpx, tmpy; float tmpx, tmpy;
world2machine(x, y, tmpx, tmpy); world2machine(x, y, tmpx, tmpy);
if (tmpx < X_MIN_POS) { if (tmpx < X_MIN_POS) {
tmpx = X_MIN_POS; tmpx = X_MIN_POS;
clamped = true; clamped = true;
} }
if (tmpy < Y_MIN_POS) { if (tmpy < Y_MIN_POS) {
tmpy = Y_MIN_POS; tmpy = Y_MIN_POS;
clamped = true; clamped = true;
} }
if (tmpx > X_MAX_POS) { if (tmpx > X_MAX_POS) {
tmpx = X_MAX_POS; tmpx = X_MAX_POS;
clamped = true; clamped = true;
} }
if (tmpy > Y_MAX_POS) { if (tmpy > Y_MAX_POS) {
tmpy = Y_MAX_POS; tmpy = Y_MAX_POS;
clamped = true; clamped = true;
} }
if (clamped) if (clamped)
machine2world(tmpx, tmpy, x, y); machine2world(tmpx, tmpy, x, y);
return clamped; return clamped;
} }
extern bool find_bed_induction_sensor_point_z(float minimum_z = -10.f, uint8_t n_iter = 3, int verbosity_level = 0); extern bool find_bed_induction_sensor_point_z(float minimum_z = -10.f, uint8_t n_iter = 3, int verbosity_level = 0);
extern bool find_bed_induction_sensor_point_xy(int verbosity_level = 0); extern bool find_bed_induction_sensor_point_xy(int verbosity_level = 0);
extern void go_home_with_z_lift(); extern void go_home_with_z_lift();
// Positive or zero: ok // Positive or zero: ok
// Negative: failed // Negative: failed
enum BedSkewOffsetDetectionResultType { enum BedSkewOffsetDetectionResultType {
// Detection failed, some point was not found. // Detection failed, some point was not found.
BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND = -1, BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND = -1,
BED_SKEW_OFFSET_DETECTION_FITTING_FAILED = -2, BED_SKEW_OFFSET_DETECTION_FITTING_FAILED = -2,
// Detection finished with success. // Detection finished with success.
BED_SKEW_OFFSET_DETECTION_PERFECT = 0, BED_SKEW_OFFSET_DETECTION_PERFECT = 0,
BED_SKEW_OFFSET_DETECTION_SKEW_MILD = 1, BED_SKEW_OFFSET_DETECTION_SKEW_MILD = 1,
BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME = 2 BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME = 2
}; };
extern BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level, uint8_t &too_far_mask); extern BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level, uint8_t &too_far_mask);
extern BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8_t verbosity_level, uint8_t &too_far_mask); extern BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8_t verbosity_level, uint8_t &too_far_mask);
extern bool sample_mesh_and_store_reference(); extern bool sample_mesh_and_store_reference();
extern void reset_bed_offset_and_skew(); extern void reset_bed_offset_and_skew();
extern bool is_bed_z_jitter_data_valid(); extern bool is_bed_z_jitter_data_valid();
// Scan the mesh bed induction points one by one by a left-right zig-zag movement, // Scan the mesh bed induction points one by one by a left-right zig-zag movement,
// write the trigger coordinates to the serial line. // write the trigger coordinates to the serial line.
// Useful for visualizing the behavior of the bed induction detector. // Useful for visualizing the behavior of the bed induction detector.
extern bool scan_bed_induction_points(int8_t verbosity_level); extern bool scan_bed_induction_points(int8_t verbosity_level);
// Apply Z babystep value from the EEPROM through the planner. // Apply Z babystep value from the EEPROM through the planner.
extern void babystep_apply(); extern void babystep_apply();
// Undo the current Z babystep value. // Undo the current Z babystep value.
extern void babystep_undo(); extern void babystep_undo();
// Reset the current babystep counter without moving the axes. // Reset the current babystep counter without moving the axes.
extern void babystep_reset(); extern void babystep_reset();
extern void count_xyz_details(); extern void count_xyz_details();
#endif /* MESH_BED_CALIBRATION_H */ #endif /* MESH_BED_CALIBRATION_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,211 +1,211 @@
/* /*
temperature.h - temperature controller temperature.h - temperature controller
Part of Marlin Part of Marlin
Copyright (c) 2011 Erik van der Zalm Copyright (c) 2011 Erik van der Zalm
Grbl is free software: you can redistribute it and/or modify Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Grbl is distributed in the hope that it will be useful, Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>. along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef temperature_h #ifndef temperature_h
#define temperature_h #define temperature_h
#include "Marlin.h" #include "Marlin.h"
#include "planner.h" #include "planner.h"
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
#include "stepper.h" #include "stepper.h"
#endif #endif
// public functions // public functions
void tp_init(); //initialize the heating void tp_init(); //initialize the heating
void manage_heater(); //it is critical that this is called periodically. void manage_heater(); //it is critical that this is called periodically.
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
// For converting raw Filament Width to milimeters // For converting raw Filament Width to milimeters
float analog2widthFil(); float analog2widthFil();
// For converting raw Filament Width to an extrusion ratio // For converting raw Filament Width to an extrusion ratio
int widthFil_to_size_ratio(); int widthFil_to_size_ratio();
#endif #endif
// low level conversion routines // low level conversion routines
// do not use these routines and variables outside of temperature.cpp // do not use these routines and variables outside of temperature.cpp
extern int target_temperature[EXTRUDERS]; extern int target_temperature[EXTRUDERS];
extern float current_temperature[EXTRUDERS]; extern float current_temperature[EXTRUDERS];
#ifdef SHOW_TEMP_ADC_VALUES #ifdef SHOW_TEMP_ADC_VALUES
extern int current_temperature_raw[EXTRUDERS]; extern int current_temperature_raw[EXTRUDERS];
extern int current_temperature_bed_raw; extern int current_temperature_bed_raw;
#endif #endif
extern int target_temperature_bed; extern int target_temperature_bed;
extern float current_temperature_bed; extern float current_temperature_bed;
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
extern float redundant_temperature; extern float redundant_temperature;
#endif #endif
#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
extern unsigned char soft_pwm_bed; extern unsigned char soft_pwm_bed;
#endif #endif
#ifdef PIDTEMP #ifdef PIDTEMP
extern int pid_cycle, pid_number_of_cycles; extern int pid_cycle, pid_number_of_cycles;
extern float Kp,Ki,Kd,Kc,_Kp,_Ki,_Kd; extern float Kp,Ki,Kd,Kc,_Kp,_Ki,_Kd;
extern bool pid_tuning_finished; extern bool pid_tuning_finished;
float scalePID_i(float i); float scalePID_i(float i);
float scalePID_d(float d); float scalePID_d(float d);
float unscalePID_i(float i); float unscalePID_i(float i);
float unscalePID_d(float d); float unscalePID_d(float d);
#endif #endif
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
extern float bedKp,bedKi,bedKd; extern float bedKp,bedKi,bedKd;
#endif #endif
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
extern volatile int babystepsTodo[3]; extern volatile int babystepsTodo[3];
#endif #endif
inline void babystepsTodoZadd(int n) inline void babystepsTodoZadd(int n)
{ {
if (n != 0) { if (n != 0) {
CRITICAL_SECTION_START CRITICAL_SECTION_START
babystepsTodo[Z_AXIS] += n; babystepsTodo[Z_AXIS] += n;
CRITICAL_SECTION_END CRITICAL_SECTION_END
} }
} }
inline void babystepsTodoZsubtract(int n) inline void babystepsTodoZsubtract(int n)
{ {
if (n != 0) { if (n != 0) {
CRITICAL_SECTION_START CRITICAL_SECTION_START
babystepsTodo[Z_AXIS] -= n; babystepsTodo[Z_AXIS] -= n;
CRITICAL_SECTION_END CRITICAL_SECTION_END
} }
} }
//high level conversion routines, for use outside of temperature.cpp //high level conversion routines, for use outside of temperature.cpp
//inline so that there is no performance decrease. //inline so that there is no performance decrease.
//deg=degreeCelsius //deg=degreeCelsius
FORCE_INLINE float degHotend(uint8_t extruder) { FORCE_INLINE float degHotend(uint8_t extruder) {
return current_temperature[extruder]; return current_temperature[extruder];
}; };
#ifdef SHOW_TEMP_ADC_VALUES #ifdef SHOW_TEMP_ADC_VALUES
FORCE_INLINE float rawHotendTemp(uint8_t extruder) { FORCE_INLINE float rawHotendTemp(uint8_t extruder) {
return current_temperature_raw[extruder]; return current_temperature_raw[extruder];
}; };
FORCE_INLINE float rawBedTemp() { FORCE_INLINE float rawBedTemp() {
return current_temperature_bed_raw; return current_temperature_bed_raw;
}; };
#endif #endif
FORCE_INLINE float degBed() { FORCE_INLINE float degBed() {
return current_temperature_bed; return current_temperature_bed;
}; };
FORCE_INLINE float degTargetHotend(uint8_t extruder) { FORCE_INLINE float degTargetHotend(uint8_t extruder) {
return target_temperature[extruder]; return target_temperature[extruder];
}; };
FORCE_INLINE float degTargetBed() { FORCE_INLINE float degTargetBed() {
return target_temperature_bed; return target_temperature_bed;
}; };
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
target_temperature[extruder] = celsius; target_temperature[extruder] = celsius;
}; };
FORCE_INLINE void setTargetBed(const float &celsius) { FORCE_INLINE void setTargetBed(const float &celsius) {
target_temperature_bed = celsius; target_temperature_bed = celsius;
}; };
FORCE_INLINE bool isHeatingHotend(uint8_t extruder){ FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
return target_temperature[extruder] > current_temperature[extruder]; return target_temperature[extruder] > current_temperature[extruder];
}; };
FORCE_INLINE bool isHeatingBed() { FORCE_INLINE bool isHeatingBed() {
return target_temperature_bed > current_temperature_bed; return target_temperature_bed > current_temperature_bed;
}; };
FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
return target_temperature[extruder] < current_temperature[extruder]; return target_temperature[extruder] < current_temperature[extruder];
}; };
FORCE_INLINE bool isCoolingBed() { FORCE_INLINE bool isCoolingBed() {
return target_temperature_bed < current_temperature_bed; return target_temperature_bed < current_temperature_bed;
}; };
#define degHotend0() degHotend(0) #define degHotend0() degHotend(0)
#define degTargetHotend0() degTargetHotend(0) #define degTargetHotend0() degTargetHotend(0)
#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0) #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
#define isHeatingHotend0() isHeatingHotend(0) #define isHeatingHotend0() isHeatingHotend(0)
#define isCoolingHotend0() isCoolingHotend(0) #define isCoolingHotend0() isCoolingHotend(0)
#if EXTRUDERS > 1 #if EXTRUDERS > 1
#define degHotend1() degHotend(1) #define degHotend1() degHotend(1)
#define degTargetHotend1() degTargetHotend(1) #define degTargetHotend1() degTargetHotend(1)
#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1) #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
#define isHeatingHotend1() isHeatingHotend(1) #define isHeatingHotend1() isHeatingHotend(1)
#define isCoolingHotend1() isCoolingHotend(1) #define isCoolingHotend1() isCoolingHotend(1)
#else #else
#define setTargetHotend1(_celsius) do{}while(0) #define setTargetHotend1(_celsius) do{}while(0)
#endif #endif
#if EXTRUDERS > 2 #if EXTRUDERS > 2
#define degHotend2() degHotend(2) #define degHotend2() degHotend(2)
#define degTargetHotend2() degTargetHotend(2) #define degTargetHotend2() degTargetHotend(2)
#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2) #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
#define isHeatingHotend2() isHeatingHotend(2) #define isHeatingHotend2() isHeatingHotend(2)
#define isCoolingHotend2() isCoolingHotend(2) #define isCoolingHotend2() isCoolingHotend(2)
#else #else
#define setTargetHotend2(_celsius) do{}while(0) #define setTargetHotend2(_celsius) do{}while(0)
#endif #endif
#if EXTRUDERS > 3 #if EXTRUDERS > 3
#error Invalid number of extruders #error Invalid number of extruders
#endif #endif
#if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0)
static float temp_runaway_status[4]; static float temp_runaway_status[4];
static float temp_runaway_target[4]; static float temp_runaway_target[4];
static float temp_runaway_timer[4]; static float temp_runaway_timer[4];
static int temp_runaway_error_counter[4]; static int temp_runaway_error_counter[4];
void temp_runaway_check(int _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed); void temp_runaway_check(int _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed);
void temp_runaway_stop(bool isPreheat, bool isBed); void temp_runaway_stop(bool isPreheat, bool isBed);
#endif #endif
int getHeaterPower(int heater); int getHeaterPower(int heater);
void disable_heater(); void disable_heater();
void setWatch(); void setWatch();
void updatePID(); void updatePID();
FORCE_INLINE void autotempShutdown(){ FORCE_INLINE void autotempShutdown(){
#ifdef AUTOTEMP #ifdef AUTOTEMP
if(autotemp_enabled) if(autotemp_enabled)
{ {
autotemp_enabled=false; autotemp_enabled=false;
if(degTargetHotend(active_extruder)>autotemp_min) if(degTargetHotend(active_extruder)>autotemp_min)
setTargetHotend(0,active_extruder); setTargetHotend(0,active_extruder);
} }
#endif #endif
} }
void PID_autotune(float temp, int extruder, int ncycles); void PID_autotune(float temp, int extruder, int ncycles);
void setExtruderAutoFanState(int pin, bool state); void setExtruderAutoFanState(int pin, bool state);
void checkExtruderAutoFans(); void checkExtruderAutoFans();
#endif #endif

View File

@ -563,7 +563,7 @@ void lcd_commands()
enquecommand(cmd1); enquecommand(cmd1);
if (axis_relative_modes[3] == true) enquecommand_P(PSTR("M83")); // set extruder to relative mode. if (axis_relative_modes[3] == true) enquecommand_P(PSTR("M83")); // set extruder to relative mode.
else enquecommand_P(PSTR("M82")); // set extruder to absolute mode else enquecommand_P(PSTR("M82")); // set extruder to absolute mode
enquecommand_P(PSTR("G1 E" STRINGIFY((is_multi_material) ? DEFAULT_RETRACTION_MM : DEFAULT_RETRACTION_SM))); //unretract enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION))); //unretract
enquecommand_P(PSTR("G90")); //absolute positioning enquecommand_P(PSTR("G90")); //absolute positioning
lcd_commands_step = 1; lcd_commands_step = 1;
} }
@ -3740,6 +3740,8 @@ static void lcd_main_menu()
MENU_ITEM(back, MSG_WATCH, lcd_status_screen); MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
MENU_ITEM(function, PSTR("restore"), restore_print_from_eeprom);
MENU_ITEM(function, PSTR("position"), position_menu);
/* if (farm_mode && !IS_SD_PRINTING ) /* if (farm_mode && !IS_SD_PRINTING )
{ {
@ -4047,6 +4049,7 @@ void lcd_sdcard_stop()
lcd_return_to_status(); lcd_return_to_status();
lcd_ignore_click(true); lcd_ignore_click(true);
lcd_commands_type = LCD_COMMAND_STOP_PRINT; lcd_commands_type = LCD_COMMAND_STOP_PRINT;
// Turn off the print fan // Turn off the print fan
@ -4897,6 +4900,9 @@ static void menu_action_sdfile(const char* filename, char* longFilename)
for (c = &cmd[4]; *c; c++) for (c = &cmd[4]; *c; c++)
*c = tolower(*c); *c = tolower(*c);
enquecommand(cmd); enquecommand(cmd);
for (int i = 0; i < 8; i++) {
eeprom_write_byte((uint8_t*)EEPROM_FILENAME+i, filename[i]);
}
enquecommand_P(PSTR("M24")); enquecommand_P(PSTR("M24"));
lcd_return_to_status(); lcd_return_to_status();
} }

View File

@ -742,6 +742,7 @@ static void lcd_implementation_status_screen()
if (IS_SD_PRINTING) if (IS_SD_PRINTING)
{ {
lcd.print(itostr3(card.percentDone())); lcd.print(itostr3(card.percentDone()));
card.get_sdpos();
lcd.print('%'); lcd.print('%');
} }
else else

View File

@ -1,288 +1,288 @@
#include "Configuration.h" #include "Configuration.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "language.h" #include "language.h"
#include "util.h" #include "util.h"
// Allocate the version string in the program memory. Otherwise the string lands either on the stack or in the global RAM. // Allocate the version string in the program memory. Otherwise the string lands either on the stack or in the global RAM.
const char FW_VERSION_STR[] PROGMEM = FW_version; const char FW_VERSION_STR[] PROGMEM = FW_version;
const char* FW_VERSION_STR_P() const char* FW_VERSION_STR_P()
{ {
return FW_VERSION_STR; return FW_VERSION_STR;
} }
const char FW_PRUSA3D_MAGIC_STR[] PROGMEM = FW_PRUSA3D_MAGIC; const char FW_PRUSA3D_MAGIC_STR[] PROGMEM = FW_PRUSA3D_MAGIC;
const char* FW_PRUSA3D_MAGIC_STR_P() const char* FW_PRUSA3D_MAGIC_STR_P()
{ {
return FW_PRUSA3D_MAGIC_STR; return FW_PRUSA3D_MAGIC_STR;
} }
const char STR_REVISION_DEV [] PROGMEM = "dev"; const char STR_REVISION_DEV [] PROGMEM = "dev";
const char STR_REVISION_ALPHA[] PROGMEM = "alpha"; const char STR_REVISION_ALPHA[] PROGMEM = "alpha";
const char STR_REVISION_BETA [] PROGMEM = "beta"; const char STR_REVISION_BETA [] PROGMEM = "beta";
const char STR_REVISION_RC [] PROGMEM = "rc"; const char STR_REVISION_RC [] PROGMEM = "rc";
inline bool is_whitespace_or_nl(char c) inline bool is_whitespace_or_nl(char c)
{ {
return c == ' ' || c == '\t' || c == '\n' || c == 'r'; return c == ' ' || c == '\t' || c == '\n' || c == 'r';
} }
inline bool is_whitespace_or_nl_or_eol(char c) inline bool is_whitespace_or_nl_or_eol(char c)
{ {
return c == 0 || c == ' ' || c == '\t' || c == '\n' || c == '\r'; return c == 0 || c == ' ' || c == '\t' || c == '\n' || c == '\r';
} }
inline bool is_digit(char c) inline bool is_digit(char c)
{ {
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }
// Parse a major.minor.revision version number. // Parse a major.minor.revision version number.
// Return true if valid. // Return true if valid.
inline bool parse_version(const char *str, uint16_t version[4]) inline bool parse_version(const char *str, uint16_t version[4])
{ {
#if 0 #if 0
SERIAL_ECHOPGM("Parsing version string "); SERIAL_ECHOPGM("Parsing version string ");
SERIAL_ECHO(str); SERIAL_ECHO(str);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif #endif
const char *major = str; const char *major = str;
const char *p = str; const char *p = str;
while (is_digit(*p)) ++ p; while (is_digit(*p)) ++ p;
if (*p != '.') if (*p != '.')
return false; return false;
const char *minor = ++ p; const char *minor = ++ p;
while (is_digit(*p)) ++ p; while (is_digit(*p)) ++ p;
if (*p != '.') if (*p != '.')
return false; return false;
const char *rev = ++ p; const char *rev = ++ p;
while (is_digit(*p)) ++ p; while (is_digit(*p)) ++ p;
if (! is_whitespace_or_nl_or_eol(*p) && *p != '-') if (! is_whitespace_or_nl_or_eol(*p) && *p != '-')
return false; return false;
char *endptr = NULL; char *endptr = NULL;
version[0] = strtol(major, &endptr, 10); version[0] = strtol(major, &endptr, 10);
if (endptr != minor - 1) if (endptr != minor - 1)
return false; return false;
version[1] = strtol(minor, &endptr, 10); version[1] = strtol(minor, &endptr, 10);
if (endptr != rev - 1) if (endptr != rev - 1)
return false; return false;
version[2] = strtol(rev, &endptr, 10); version[2] = strtol(rev, &endptr, 10);
if (endptr != p) if (endptr != p)
return false; return false;
version[3] = FIRMWARE_REVISION_RELEASED; version[3] = FIRMWARE_REVISION_RELEASED;
if (*p ++ == '-') { if (*p ++ == '-') {
const char *q = p; const char *q = p;
while (! is_whitespace_or_nl_or_eol(*q)) while (! is_whitespace_or_nl_or_eol(*q))
++ q; ++ q;
uint8_t n = q - p; uint8_t n = q - p;
if (n == strlen_P(STR_REVISION_DEV) && strncmp_P(p, STR_REVISION_DEV, n) == 0) if (n == strlen_P(STR_REVISION_DEV) && strncmp_P(p, STR_REVISION_DEV, n) == 0)
version[3] = FIRMWARE_REVISION_DEV; version[3] = FIRMWARE_REVISION_DEV;
else if (n == strlen_P(STR_REVISION_ALPHA) && strncmp_P(p, STR_REVISION_ALPHA, n) == 0) else if (n == strlen_P(STR_REVISION_ALPHA) && strncmp_P(p, STR_REVISION_ALPHA, n) == 0)
version[3] = FIRMWARE_REVISION_ALPHA; version[3] = FIRMWARE_REVISION_ALPHA;
else if (n == strlen_P(STR_REVISION_BETA) && strncmp_P(p, STR_REVISION_BETA, n) == 0) else if (n == strlen_P(STR_REVISION_BETA) && strncmp_P(p, STR_REVISION_BETA, n) == 0)
version[3] = FIRMWARE_REVISION_BETA; version[3] = FIRMWARE_REVISION_BETA;
else if ((n == 2 || n == 3) && p[0] == 'r' && p[1] == 'c') { else if ((n == 2 || n == 3) && p[0] == 'r' && p[1] == 'c') {
if (n == 2) if (n == 2)
version[3] = FIRMWARE_REVISION_RC; version[3] = FIRMWARE_REVISION_RC;
else { else {
if (is_digit(p[2])) if (is_digit(p[2]))
version[3] = FIRMWARE_REVISION_RC + p[2] - '1'; version[3] = FIRMWARE_REVISION_RC + p[2] - '1';
else else
return false; return false;
} }
} else } else
return false; return false;
} }
#if 0 #if 0
SERIAL_ECHOPGM("Version parsed, major: "); SERIAL_ECHOPGM("Version parsed, major: ");
SERIAL_ECHO(version[0]); SERIAL_ECHO(version[0]);
SERIAL_ECHOPGM(", minor: "); SERIAL_ECHOPGM(", minor: ");
SERIAL_ECHO(version[1]); SERIAL_ECHO(version[1]);
SERIAL_ECHOPGM(", revision: "); SERIAL_ECHOPGM(", revision: ");
SERIAL_ECHO(version[2]); SERIAL_ECHO(version[2]);
SERIAL_ECHOPGM(", flavor: "); SERIAL_ECHOPGM(", flavor: ");
SERIAL_ECHO(version[3]); SERIAL_ECHO(version[3]);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif #endif
return true; return true;
} }
inline bool strncmp_PP(const char *p1, const char *p2, uint8_t n) inline bool strncmp_PP(const char *p1, const char *p2, uint8_t n)
{ {
for (; n > 0; -- n, ++ p1, ++ p2) { for (; n > 0; -- n, ++ p1, ++ p2) {
if (pgm_read_byte(p1) < pgm_read_byte(p2)) if (pgm_read_byte(p1) < pgm_read_byte(p2))
return -1; return -1;
if (pgm_read_byte(p1) > pgm_read_byte(p2)) if (pgm_read_byte(p1) > pgm_read_byte(p2))
return 1; return 1;
if (pgm_read_byte(p1) == 0) if (pgm_read_byte(p1) == 0)
return 0; return 0;
} }
return 0; return 0;
} }
// Parse a major.minor.revision version number. // Parse a major.minor.revision version number.
// Return true if valid. // Return true if valid.
inline bool parse_version_P(const char *str, uint16_t version[4]) inline bool parse_version_P(const char *str, uint16_t version[4])
{ {
#if 0 #if 0
SERIAL_ECHOPGM("Parsing version string "); SERIAL_ECHOPGM("Parsing version string ");
SERIAL_ECHORPGM(str); SERIAL_ECHORPGM(str);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif #endif
const char *major = str; const char *major = str;
const char *p = str; const char *p = str;
while (is_digit(char(pgm_read_byte(p)))) ++ p; while (is_digit(char(pgm_read_byte(p)))) ++ p;
if (pgm_read_byte(p) != '.') if (pgm_read_byte(p) != '.')
return false; return false;
const char *minor = ++ p; const char *minor = ++ p;
while (is_digit(char(pgm_read_byte(p)))) ++ p; while (is_digit(char(pgm_read_byte(p)))) ++ p;
if (pgm_read_byte(p) != '.') if (pgm_read_byte(p) != '.')
return false; return false;
const char *rev = ++ p; const char *rev = ++ p;
while (is_digit(char(pgm_read_byte(p)))) ++ p; while (is_digit(char(pgm_read_byte(p)))) ++ p;
if (! is_whitespace_or_nl_or_eol(char(pgm_read_byte(p))) && pgm_read_byte(p) != '-') if (! is_whitespace_or_nl_or_eol(char(pgm_read_byte(p))) && pgm_read_byte(p) != '-')
return false; return false;
char buf[5]; char buf[5];
uint8_t n = minor - major - 1; uint8_t n = minor - major - 1;
if (n > 4) if (n > 4)
return false; return false;
memcpy_P(buf, major, n); buf[n] = 0; memcpy_P(buf, major, n); buf[n] = 0;
char *endptr = NULL; char *endptr = NULL;
version[0] = strtol(buf, &endptr, 10); version[0] = strtol(buf, &endptr, 10);
if (*endptr != 0) if (*endptr != 0)
return false; return false;
n = rev - minor - 1; n = rev - minor - 1;
if (n > 4) if (n > 4)
return false; return false;
memcpy_P(buf, minor, n); buf[n] = 0; memcpy_P(buf, minor, n); buf[n] = 0;
version[1] = strtol(buf, &endptr, 10); version[1] = strtol(buf, &endptr, 10);
if (*endptr != 0) if (*endptr != 0)
return false; return false;
n = p - rev; n = p - rev;
if (n > 4) if (n > 4)
return false; return false;
memcpy_P(buf, rev, n); memcpy_P(buf, rev, n);
buf[n] = 0; buf[n] = 0;
version[2] = strtol(buf, &endptr, 10); version[2] = strtol(buf, &endptr, 10);
if (*endptr != 0) if (*endptr != 0)
return false; return false;
version[3] = FIRMWARE_REVISION_RELEASED; version[3] = FIRMWARE_REVISION_RELEASED;
if (pgm_read_byte(p ++) == '-') { if (pgm_read_byte(p ++) == '-') {
const char *q = p; const char *q = p;
while (! is_whitespace_or_nl_or_eol(char(pgm_read_byte(q)))) while (! is_whitespace_or_nl_or_eol(char(pgm_read_byte(q))))
++ q; ++ q;
n = q - p; n = q - p;
if (n == strlen_P(STR_REVISION_DEV) && strncmp_PP(p, STR_REVISION_DEV, n) == 0) if (n == strlen_P(STR_REVISION_DEV) && strncmp_PP(p, STR_REVISION_DEV, n) == 0)
version[3] = FIRMWARE_REVISION_DEV; version[3] = FIRMWARE_REVISION_DEV;
else if (n == strlen_P(STR_REVISION_ALPHA) && strncmp_PP(p, STR_REVISION_ALPHA, n) == 0) else if (n == strlen_P(STR_REVISION_ALPHA) && strncmp_PP(p, STR_REVISION_ALPHA, n) == 0)
version[3] = FIRMWARE_REVISION_ALPHA; version[3] = FIRMWARE_REVISION_ALPHA;
else if (n == strlen_P(STR_REVISION_BETA) && strncmp_PP(p, STR_REVISION_BETA, n) == 0) else if (n == strlen_P(STR_REVISION_BETA) && strncmp_PP(p, STR_REVISION_BETA, n) == 0)
version[3] = FIRMWARE_REVISION_BETA; version[3] = FIRMWARE_REVISION_BETA;
else if ((n == 2 || n == 3) && strncmp_PP(p, STR_REVISION_RC, 2) == 0) { else if ((n == 2 || n == 3) && strncmp_PP(p, STR_REVISION_RC, 2) == 0) {
if (n == 2) if (n == 2)
version[3] = FIRMWARE_REVISION_RC; version[3] = FIRMWARE_REVISION_RC;
else { else {
p += 2; p += 2;
if (is_digit(pgm_read_byte(p))) if (is_digit(pgm_read_byte(p)))
version[3] = FIRMWARE_REVISION_RC + pgm_read_byte(p) - '1'; version[3] = FIRMWARE_REVISION_RC + pgm_read_byte(p) - '1';
else else
return false; return false;
} }
} else } else
return false; return false;
} }
#if 0 #if 0
SERIAL_ECHOPGM("Version parsed, major: "); SERIAL_ECHOPGM("Version parsed, major: ");
SERIAL_ECHO(version[0]); SERIAL_ECHO(version[0]);
SERIAL_ECHOPGM(", minor: "); SERIAL_ECHOPGM(", minor: ");
SERIAL_ECHO(version[1]); SERIAL_ECHO(version[1]);
SERIAL_ECHOPGM(", revision: "); SERIAL_ECHOPGM(", revision: ");
SERIAL_ECHO(version[2]); SERIAL_ECHO(version[2]);
SERIAL_ECHOPGM(", flavor: "); SERIAL_ECHOPGM(", flavor: ");
SERIAL_ECHO(version[3]); SERIAL_ECHO(version[3]);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif #endif
return true; return true;
} }
// 1 - yes, 0 - false, -1 - error; // 1 - yes, 0 - false, -1 - error;
inline int8_t is_provided_version_newer(const char *version_string) inline int8_t is_provided_version_newer(const char *version_string)
{ {
uint16_t ver_gcode[3], ver_current[3]; uint16_t ver_gcode[3], ver_current[3];
if (! parse_version(version_string, ver_gcode)) if (! parse_version(version_string, ver_gcode))
return -1; return -1;
if (! parse_version_P(FW_VERSION_STR, ver_current)) if (! parse_version_P(FW_VERSION_STR, ver_current))
return 0; // this shall not happen return 0; // this shall not happen
for (uint8_t i = 0; i < 3; ++ i) for (uint8_t i = 0; i < 3; ++ i)
if (ver_gcode[i] > ver_current[i]) if (ver_gcode[i] > ver_current[i])
return 1; return 1;
return 0; return 0;
} }
bool show_upgrade_dialog_if_version_newer(const char *version_string) bool show_upgrade_dialog_if_version_newer(const char *version_string)
{ {
uint16_t ver_gcode[4], ver_current[4]; uint16_t ver_gcode[4], ver_current[4];
if (! parse_version(version_string, ver_gcode)) { if (! parse_version(version_string, ver_gcode)) {
// SERIAL_PROTOCOLLNPGM("parse_version failed"); // SERIAL_PROTOCOLLNPGM("parse_version failed");
return false; return false;
} }
if (! parse_version_P(FW_VERSION_STR, ver_current)) { if (! parse_version_P(FW_VERSION_STR, ver_current)) {
// SERIAL_PROTOCOLLNPGM("parse_version_P failed"); // SERIAL_PROTOCOLLNPGM("parse_version_P failed");
return false; // this shall not happen return false; // this shall not happen
} }
// SERIAL_PROTOCOLLNPGM("versions parsed"); // SERIAL_PROTOCOLLNPGM("versions parsed");
bool upgrade = false; bool upgrade = false;
for (uint8_t i = 0; i < 4; ++ i) { for (uint8_t i = 0; i < 4; ++ i) {
if (ver_gcode[i] > ver_current[i]) { if (ver_gcode[i] > ver_current[i]) {
upgrade = true; upgrade = true;
break; break;
} else if (ver_gcode[i] < ver_current[i]) } else if (ver_gcode[i] < ver_current[i])
break; break;
} }
if (upgrade) { if (upgrade) {
lcd_display_message_fullscreen_P(MSG_NEW_FIRMWARE_AVAILABLE); lcd_display_message_fullscreen_P(MSG_NEW_FIRMWARE_AVAILABLE);
lcd_print_at_PGM(0, 2, PSTR("")); lcd_print_at_PGM(0, 2, PSTR(""));
for (const char *c = version_string; ! is_whitespace_or_nl_or_eol(*c); ++ c) for (const char *c = version_string; ! is_whitespace_or_nl_or_eol(*c); ++ c)
lcd_implementation_write(*c); lcd_implementation_write(*c);
lcd_print_at_PGM(0, 3, MSG_NEW_FIRMWARE_PLEASE_UPGRADE); lcd_print_at_PGM(0, 3, MSG_NEW_FIRMWARE_PLEASE_UPGRADE);
tone(BEEPER, 1000); tone(BEEPER, 1000);
delay_keep_alive(50); delay_keep_alive(50);
noTone(BEEPER); noTone(BEEPER);
delay_keep_alive(500); delay_keep_alive(500);
tone(BEEPER, 1000); tone(BEEPER, 1000);
delay_keep_alive(50); delay_keep_alive(50);
noTone(BEEPER); noTone(BEEPER);
lcd_wait_for_click(); lcd_wait_for_click();
lcd_update_enable(true); lcd_update_enable(true);
lcd_implementation_clear(); lcd_implementation_clear();
lcd_update(); lcd_update();
} }
// Succeeded. // Succeeded.
return true; return true;
} }
void update_current_firmware_version_to_eeprom() void update_current_firmware_version_to_eeprom()
{ {
for (int8_t i = 0; i < FW_PRUSA3D_MAGIC_LEN; ++ i) for (int8_t i = 0; i < FW_PRUSA3D_MAGIC_LEN; ++ i)
eeprom_update_byte((uint8_t*)(EEPROM_FIRMWARE_PRUSA_MAGIC+i), pgm_read_byte(FW_PRUSA3D_MAGIC_STR+i)); eeprom_update_byte((uint8_t*)(EEPROM_FIRMWARE_PRUSA_MAGIC+i), pgm_read_byte(FW_PRUSA3D_MAGIC_STR+i));
uint16_t ver_current[4]; uint16_t ver_current[4];
if (parse_version_P(FW_VERSION_STR, ver_current)) { if (parse_version_P(FW_VERSION_STR, ver_current)) {
eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR, ver_current[0]); eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR, ver_current[0]);
eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR, ver_current[1]); eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR, ver_current[1]);
eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION, ver_current[2]); eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION, ver_current[2]);
// See FirmwareRevisionFlavorType for the definition of firmware flavors. // See FirmwareRevisionFlavorType for the definition of firmware flavors.
eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR, ver_current[3]); eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR, ver_current[3]);
} }
} }

View File

@ -1,35 +1,35 @@
#ifndef UTIL_H #ifndef UTIL_H
#define UTIL_H #define UTIL_H
extern const char* FW_VERSION_STR_P(); extern const char* FW_VERSION_STR_P();
// Definition of a firmware flavor numerical values. // Definition of a firmware flavor numerical values.
enum FirmwareRevisionFlavorType enum FirmwareRevisionFlavorType
{ {
FIRMWARE_REVISION_DEV = 0, FIRMWARE_REVISION_DEV = 0,
FIRMWARE_REVISION_ALPHA = 1, FIRMWARE_REVISION_ALPHA = 1,
FIRMWARE_REVISION_BETA = 2, FIRMWARE_REVISION_BETA = 2,
FIRMWARE_REVISION_RC, FIRMWARE_REVISION_RC,
FIRMWARE_REVISION_RC2, FIRMWARE_REVISION_RC2,
FIRMWARE_REVISION_RC3, FIRMWARE_REVISION_RC3,
FIRMWARE_REVISION_RC4, FIRMWARE_REVISION_RC4,
FIRMWARE_REVISION_RC5, FIRMWARE_REVISION_RC5,
FIRMWARE_REVISION_RELEASED = 127 FIRMWARE_REVISION_RELEASED = 127
}; };
extern bool show_upgrade_dialog_if_version_newer(const char *version_string); extern bool show_upgrade_dialog_if_version_newer(const char *version_string);
extern void update_current_firmware_version_to_eeprom(); extern void update_current_firmware_version_to_eeprom();
inline int8_t eeprom_read_int8(unsigned char* addr) { inline int8_t eeprom_read_int8(unsigned char* addr) {
uint8_t v = eeprom_read_byte(addr); uint8_t v = eeprom_read_byte(addr);
return *reinterpret_cast<int8_t*>(&v); return *reinterpret_cast<int8_t*>(&v);
} }
inline void eeprom_update_int8(unsigned char* addr, int8_t v) { inline void eeprom_update_int8(unsigned char* addr, int8_t v) {
eeprom_update_byte(addr, *reinterpret_cast<uint8_t*>(&v)); eeprom_update_byte(addr, *reinterpret_cast<uint8_t*>(&v));
} }
#endif /* UTIL_H */ #endif /* UTIL_H */