├── README.md ├── images ├── smartcore-tete.jpg ├── smartcore-top.jpg ├── smartcore-front.jpg ├── smartcore-sfeer.jpg ├── bouchon logo groot.jpg ├── smartcore diagonal.jpg └── smartcore-front 220.jpg ├── firmware ├── mk7 │ └── Marlin │ │ ├── COPYING │ │ ├── Menu Plans.xlsx │ │ ├── LCD Menu Tree.pdf │ │ ├── BlinkM.h │ │ ├── ConfigurationStore.h │ │ ├── watchdog.h │ │ ├── BlinkM.cpp │ │ ├── qr_solve.h │ │ ├── motion_control.h │ │ ├── create_speed_lookuptable.py │ │ ├── SdFatUtil.h │ │ ├── SdFile.h │ │ ├── digipot_mcp4451.cpp │ │ ├── vector_3.h │ │ ├── Marlin.ino │ │ ├── watchdog.cpp │ │ ├── SdFatUtil.cpp │ │ ├── cardreader.h │ │ ├── SdFile.cpp │ │ ├── LiquidCrystalRus.h │ │ ├── ultralcd.h │ │ ├── ultralcd_st7920_u8glib_rrd.h │ │ ├── SdFatConfig.h │ │ ├── stepper.h │ │ ├── vector_3.cpp │ │ ├── temperature.h │ │ ├── createTemperatureLookupMarlin.py │ │ ├── Servo.h │ │ ├── MarlinSerial.h │ │ ├── motion_control.cpp │ │ ├── planner.h │ │ └── MarlinSerial.cpp └── mk8 │ └── Marlin │ ├── COPYING │ ├── Menu Plans.xlsx │ ├── LCD Menu Tree.pdf │ ├── BlinkM.h │ ├── ConfigurationStore.h │ ├── watchdog.h │ ├── BlinkM.cpp │ ├── qr_solve.h │ ├── motion_control.h │ ├── create_speed_lookuptable.py │ ├── SdFatUtil.h │ ├── SdFile.h │ ├── digipot_mcp4451.cpp │ ├── vector_3.h │ ├── Marlin.ino │ ├── watchdog.cpp │ ├── SdFatUtil.cpp │ ├── cardreader.h │ ├── SdFile.cpp │ ├── LiquidCrystalRus.h │ ├── ultralcd.h │ ├── ultralcd_st7920_u8glib_rrd.h │ ├── SdFatConfig.h │ ├── stepper.h │ ├── vector_3.cpp │ ├── temperature.h │ ├── createTemperatureLookupMarlin.py │ ├── Servo.h │ ├── MarlinSerial.h │ ├── motion_control.cpp │ ├── planner.h │ └── MarlinSerial.cpp ├── stl ├── separate parts │ ├── head.stl │ ├── Zslide.stl │ ├── fixalim.stl │ ├── XYmotor_left.stl │ ├── Yslide_left.stl │ ├── Yslide_right.stl │ ├── head_8mmrods.stl │ ├── jhead_attach.stl │ ├── XYmotor_right.stl │ ├── jhead_adaptor.stl │ ├── ramps_support.stl │ ├── spoolholder32.stl │ ├── XYbearings_left.stl │ ├── XYbearings_right.stl │ ├── endstopYsupport.stl │ ├── extruder_mk8_top.stl │ ├── extruder_mk8_bottom.stl │ └── supportcable bigsize.stl ├── smartrapcore_plate1.stl ├── smartrapcore_plate2.stl └── smartrapcore_plate3.stl ├── sources ├── blender │ ├── sc_12_plates.blend │ ├── sc_12_plates.blend1 │ ├── sc_12_plates.blend2 │ └── smartrapcore.blend └── openjscad │ └── support extruder.jscad └── profiles └── slic3r └── smartcore_slic3r.ini /README.md: -------------------------------------------------------------------------------- 1 | # smartcore 2 | the simple and cheap corexy from smartfriendz 3 | -------------------------------------------------------------------------------- /images/smartcore-tete.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/smartcore-tete.jpg -------------------------------------------------------------------------------- /images/smartcore-top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/smartcore-top.jpg -------------------------------------------------------------------------------- /firmware/mk7/Marlin/COPYING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/firmware/mk7/Marlin/COPYING -------------------------------------------------------------------------------- /firmware/mk8/Marlin/COPYING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/firmware/mk8/Marlin/COPYING -------------------------------------------------------------------------------- /images/smartcore-front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/smartcore-front.jpg -------------------------------------------------------------------------------- /images/smartcore-sfeer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/smartcore-sfeer.jpg -------------------------------------------------------------------------------- /stl/separate parts/head.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/head.stl -------------------------------------------------------------------------------- /stl/smartrapcore_plate1.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/smartrapcore_plate1.stl -------------------------------------------------------------------------------- /stl/smartrapcore_plate2.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/smartrapcore_plate2.stl -------------------------------------------------------------------------------- /stl/smartrapcore_plate3.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/smartrapcore_plate3.stl -------------------------------------------------------------------------------- /images/bouchon logo groot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/bouchon logo groot.jpg -------------------------------------------------------------------------------- /images/smartcore diagonal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/smartcore diagonal.jpg -------------------------------------------------------------------------------- /images/smartcore-front 220.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/images/smartcore-front 220.jpg -------------------------------------------------------------------------------- /stl/separate parts/Zslide.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/Zslide.stl -------------------------------------------------------------------------------- /stl/separate parts/fixalim.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/fixalim.stl -------------------------------------------------------------------------------- /firmware/mk7/Marlin/Menu Plans.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/firmware/mk7/Marlin/Menu Plans.xlsx -------------------------------------------------------------------------------- /firmware/mk8/Marlin/Menu Plans.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/firmware/mk8/Marlin/Menu Plans.xlsx -------------------------------------------------------------------------------- /sources/blender/sc_12_plates.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/sources/blender/sc_12_plates.blend -------------------------------------------------------------------------------- /sources/blender/sc_12_plates.blend1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/sources/blender/sc_12_plates.blend1 -------------------------------------------------------------------------------- /sources/blender/sc_12_plates.blend2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/sources/blender/sc_12_plates.blend2 -------------------------------------------------------------------------------- /sources/blender/smartrapcore.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/sources/blender/smartrapcore.blend -------------------------------------------------------------------------------- /stl/separate parts/XYmotor_left.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/XYmotor_left.stl -------------------------------------------------------------------------------- /stl/separate parts/Yslide_left.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/Yslide_left.stl -------------------------------------------------------------------------------- /stl/separate parts/Yslide_right.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/Yslide_right.stl -------------------------------------------------------------------------------- /stl/separate parts/head_8mmrods.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/head_8mmrods.stl -------------------------------------------------------------------------------- /stl/separate parts/jhead_attach.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/jhead_attach.stl -------------------------------------------------------------------------------- /firmware/mk7/Marlin/LCD Menu Tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/firmware/mk7/Marlin/LCD Menu Tree.pdf -------------------------------------------------------------------------------- /firmware/mk8/Marlin/LCD Menu Tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/firmware/mk8/Marlin/LCD Menu Tree.pdf -------------------------------------------------------------------------------- /stl/separate parts/XYmotor_right.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/XYmotor_right.stl -------------------------------------------------------------------------------- /stl/separate parts/jhead_adaptor.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/jhead_adaptor.stl -------------------------------------------------------------------------------- /stl/separate parts/ramps_support.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/ramps_support.stl -------------------------------------------------------------------------------- /stl/separate parts/spoolholder32.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/spoolholder32.stl -------------------------------------------------------------------------------- /stl/separate parts/XYbearings_left.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/XYbearings_left.stl -------------------------------------------------------------------------------- /stl/separate parts/XYbearings_right.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/XYbearings_right.stl -------------------------------------------------------------------------------- /stl/separate parts/endstopYsupport.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/endstopYsupport.stl -------------------------------------------------------------------------------- /stl/separate parts/extruder_mk8_top.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/extruder_mk8_top.stl -------------------------------------------------------------------------------- /stl/separate parts/extruder_mk8_bottom.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/extruder_mk8_bottom.stl -------------------------------------------------------------------------------- /stl/separate parts/supportcable bigsize.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartfriendz/smartcore/HEAD/stl/separate parts/supportcable bigsize.stl -------------------------------------------------------------------------------- /firmware/mk7/Marlin/BlinkM.h: -------------------------------------------------------------------------------- 1 | /* 2 | BlinkM.h 3 | Library header file for BlinkM library 4 | */ 5 | #if (ARDUINO >= 100) 6 | # include "Arduino.h" 7 | #else 8 | # include "WProgram.h" 9 | #endif 10 | 11 | #include "Wire.h" 12 | 13 | void SendColors(byte red, byte grn, byte blu); 14 | 15 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/BlinkM.h: -------------------------------------------------------------------------------- 1 | /* 2 | BlinkM.h 3 | Library header file for BlinkM library 4 | */ 5 | #if (ARDUINO >= 100) 6 | # include "Arduino.h" 7 | #else 8 | # include "WProgram.h" 9 | #endif 10 | 11 | #include "Wire.h" 12 | 13 | void SendColors(byte red, byte grn, byte blu); 14 | 15 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/ConfigurationStore.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_STORE_H 2 | #define CONFIG_STORE_H 3 | 4 | #include "Configuration.h" 5 | 6 | void Config_ResetDefault(); 7 | 8 | #ifndef DISABLE_M503 9 | void Config_PrintSettings(); 10 | #else 11 | FORCE_INLINE void Config_PrintSettings() {} 12 | #endif 13 | 14 | #ifdef EEPROM_SETTINGS 15 | void Config_StoreSettings(); 16 | void Config_RetrieveSettings(); 17 | #else 18 | FORCE_INLINE void Config_StoreSettings() {} 19 | FORCE_INLINE void Config_RetrieveSettings() { Config_ResetDefault(); Config_PrintSettings(); } 20 | #endif 21 | 22 | #endif//CONFIG_STORE_H 23 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/ConfigurationStore.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_STORE_H 2 | #define CONFIG_STORE_H 3 | 4 | #include "Configuration.h" 5 | 6 | void Config_ResetDefault(); 7 | 8 | #ifndef DISABLE_M503 9 | void Config_PrintSettings(); 10 | #else 11 | FORCE_INLINE void Config_PrintSettings() {} 12 | #endif 13 | 14 | #ifdef EEPROM_SETTINGS 15 | void Config_StoreSettings(); 16 | void Config_RetrieveSettings(); 17 | #else 18 | FORCE_INLINE void Config_StoreSettings() {} 19 | FORCE_INLINE void Config_RetrieveSettings() { Config_ResetDefault(); Config_PrintSettings(); } 20 | #endif 21 | 22 | #endif//CONFIG_STORE_H 23 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/watchdog.h: -------------------------------------------------------------------------------- 1 | #ifndef WATCHDOG_H 2 | #define WATCHDOG_H 3 | 4 | #include "Marlin.h" 5 | 6 | #ifdef USE_WATCHDOG 7 | // initialize watch dog with a 1 sec interrupt time 8 | void watchdog_init(); 9 | // pad the dog/reset watchdog. MUST be called at least every second after the first watchdog_init or AVR will go into emergency procedures.. 10 | void watchdog_reset(); 11 | #else 12 | //If we do not have a watchdog, then we can have empty functions which are optimized away. 13 | FORCE_INLINE void watchdog_init() {}; 14 | FORCE_INLINE void watchdog_reset() {}; 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/watchdog.h: -------------------------------------------------------------------------------- 1 | #ifndef WATCHDOG_H 2 | #define WATCHDOG_H 3 | 4 | #include "Marlin.h" 5 | 6 | #ifdef USE_WATCHDOG 7 | // initialize watch dog with a 1 sec interrupt time 8 | void watchdog_init(); 9 | // pad the dog/reset watchdog. MUST be called at least every second after the first watchdog_init or AVR will go into emergency procedures.. 10 | void watchdog_reset(); 11 | #else 12 | //If we do not have a watchdog, then we can have empty functions which are optimized away. 13 | FORCE_INLINE void watchdog_init() {}; 14 | FORCE_INLINE void watchdog_reset() {}; 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/BlinkM.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BlinkM.cpp - Library for controlling a BlinkM over i2c 3 | Created by Tim Koster, August 21 2013. 4 | */ 5 | #include "Marlin.h" 6 | #ifdef BLINKM 7 | 8 | #if (ARDUINO >= 100) 9 | # include "Arduino.h" 10 | #else 11 | # include "WProgram.h" 12 | #endif 13 | 14 | #include "BlinkM.h" 15 | 16 | void SendColors(byte red, byte grn, byte blu) 17 | { 18 | Wire.begin(); 19 | Wire.beginTransmission(0x09); 20 | Wire.write('o'); //to disable ongoing script, only needs to be used once 21 | Wire.write('n'); 22 | Wire.write(red); 23 | Wire.write(grn); 24 | Wire.write(blu); 25 | Wire.endTransmission(); 26 | } 27 | 28 | #endif //BLINKM 29 | 30 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/BlinkM.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BlinkM.cpp - Library for controlling a BlinkM over i2c 3 | Created by Tim Koster, August 21 2013. 4 | */ 5 | #include "Marlin.h" 6 | #ifdef BLINKM 7 | 8 | #if (ARDUINO >= 100) 9 | # include "Arduino.h" 10 | #else 11 | # include "WProgram.h" 12 | #endif 13 | 14 | #include "BlinkM.h" 15 | 16 | void SendColors(byte red, byte grn, byte blu) 17 | { 18 | Wire.begin(); 19 | Wire.beginTransmission(0x09); 20 | Wire.write('o'); //to disable ongoing script, only needs to be used once 21 | Wire.write('n'); 22 | Wire.write(red); 23 | Wire.write(grn); 24 | Wire.write(blu); 25 | Wire.endTransmission(); 26 | } 27 | 28 | #endif //BLINKM 29 | 30 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/qr_solve.h: -------------------------------------------------------------------------------- 1 | #include "Configuration.h" 2 | 3 | #ifdef AUTO_BED_LEVELING_GRID 4 | 5 | void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy ); 6 | double ddot ( int n, double dx[], int incx, double dy[], int incy ); 7 | double dnrm2 ( int n, double x[], int incx ); 8 | void dqrank ( double a[], int lda, int m, int n, double tol, int *kr, 9 | int jpvt[], double qraux[] ); 10 | void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[], 11 | double work[], int job ); 12 | int dqrls ( double a[], int lda, int m, int n, double tol, int *kr, double b[], 13 | double x[], double rsd[], int jpvt[], double qraux[], int itask ); 14 | void dqrlss ( double a[], int lda, int m, int n, int kr, double b[], double x[], 15 | double rsd[], int jpvt[], double qraux[] ); 16 | int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[], 17 | double qy[], double qty[], double b[], double rsd[], double ab[], int job ); 18 | void dscal ( int n, double sa, double x[], int incx ); 19 | void dswap ( int n, double x[], int incx, double y[], int incy ); 20 | double *qr_solve ( int m, int n, double a[], double b[] ); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/qr_solve.h: -------------------------------------------------------------------------------- 1 | #include "Configuration.h" 2 | 3 | #ifdef AUTO_BED_LEVELING_GRID 4 | 5 | void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy ); 6 | double ddot ( int n, double dx[], int incx, double dy[], int incy ); 7 | double dnrm2 ( int n, double x[], int incx ); 8 | void dqrank ( double a[], int lda, int m, int n, double tol, int *kr, 9 | int jpvt[], double qraux[] ); 10 | void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[], 11 | double work[], int job ); 12 | int dqrls ( double a[], int lda, int m, int n, double tol, int *kr, double b[], 13 | double x[], double rsd[], int jpvt[], double qraux[], int itask ); 14 | void dqrlss ( double a[], int lda, int m, int n, int kr, double b[], double x[], 15 | double rsd[], int jpvt[], double qraux[] ); 16 | int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[], 17 | double qy[], double qty[], double b[], double rsd[], double ab[], int job ); 18 | void dscal ( int n, double sa, double x[], int incx ); 19 | void dswap ( int n, double x[], int incx, double y[], int incy ); 20 | double *qr_solve ( int m, int n, double a[], double b[] ); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/motion_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | motion_control.h - high level interface for issuing motion commands 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef motion_control_h 23 | #define motion_control_h 24 | 25 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 26 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 27 | // the direction of helical travel, radius == circle radius, isclockwise boolean. Used 28 | // for vector transformation direction. 29 | void mc_arc(float *position, float *target, float *offset, unsigned char axis_0, unsigned char axis_1, 30 | unsigned char axis_linear, float feed_rate, float radius, unsigned char isclockwise, uint8_t extruder); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/motion_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | motion_control.h - high level interface for issuing motion commands 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef motion_control_h 23 | #define motion_control_h 24 | 25 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 26 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 27 | // the direction of helical travel, radius == circle radius, isclockwise boolean. Used 28 | // for vector transformation direction. 29 | void mc_arc(float *position, float *target, float *offset, unsigned char axis_0, unsigned char axis_1, 30 | unsigned char axis_linear, float feed_rate, float radius, unsigned char isclockwise, uint8_t extruder); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /sources/openjscad/support extruder.jscad: -------------------------------------------------------------------------------- 1 | /********** 2 | 3 | Smartcore : Support d'extruder 4 | 5 | author: smartfriendz 6 | licence : GPL 7 | 8 | ***********/ 9 | 10 | function main() { 11 | 12 | var hauteur = 7, rayon = 10, vb = 2.5, tm3 = 3, m3 = 1.5, diam = rayon*2, largeur = diam; 13 | 14 | return difference( 15 | 16 | union( 17 | 18 | cylinder({r:rayon,h:hauteur}), //Demie cerle bas 19 | cube({size:[largeur,diam+54,hauteur]}).translate([-rayon,0,0]), //Corps support moteur 20 | cube({size:[largeur/2,largeur+diam,hauteur]}).translate([rayon,(54+diam)/2-diam,0]), //Patte cercle milieu 21 | cylinder({r:rayon,h:hauteur}).translate([0,diam+54,0]), //Demie cercle haut 22 | cylinder({r:rayon,h:hauteur}).translate([largeur,(diam+54)/2,0]) //Demie cercle milieu 23 | 24 | ), 25 | 26 | cylinder({r:vb,h:hauteur}), //Vis bois bas 27 | cylinder({r:vb,h:hauteur}).translate([diam,(diam+54)/2,0]), //Vis bois milieu 28 | cylinder({r:vb,h:hauteur}).translate([0,diam+54,0]), //Vis bois haut 29 | cylinder({r:tm3,h:2}).translate([0,(diam+54)/2-15.5,hauteur-2]), //Trou tête m3 bas 30 | cylinder({r:tm3,h:2}).translate([0,(diam+54)/2+15.5,hauteur-2]), //Trou tête m3 haut 31 | cylinder({r:m3,h:hauteur}).translate([0,(diam+54)/2-15.5,0]), //Trou m3 bas 32 | cylinder({r:m3,h:hauteur}).translate([0,(diam+54)/2+15.5,0]), //Trou m3 haut 33 | cylinder({r:rayon,h:hauteur}).translate([largeur,(diam+54)/2-diam,0]), //Filet 34 | cylinder({r:rayon,h:hauteur}).translate([largeur,(diam+54)/2+diam,0]) //Filet 35 | 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/create_speed_lookuptable.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ Generate the stepper delay lookup table for Marlin firmware. """ 4 | 5 | import argparse 6 | 7 | __author__ = "Ben Gamari " 8 | __copyright__ = "Copyright 2012, Ben Gamari" 9 | __license__ = "GPL" 10 | 11 | parser = argparse.ArgumentParser(description=__doc__) 12 | parser.add_argument('-f', '--cpu-freq', type=int, default=16, help='CPU clockrate in MHz (default=16)') 13 | parser.add_argument('-d', '--divider', type=int, default=8, help='Timer/counter pre-scale divider (default=8)') 14 | args = parser.parse_args() 15 | 16 | cpu_freq = args.cpu_freq * 1000000 17 | timer_freq = cpu_freq / args.divider 18 | 19 | print "#ifndef SPEED_LOOKUPTABLE_H" 20 | print "#define SPEED_LOOKUPTABLE_H" 21 | print 22 | print '#include "Marlin.h"' 23 | print 24 | 25 | print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {" 26 | a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ] 27 | b = [ a[i] - a[i+1] for i in range(255) ] 28 | b.append(b[-1]) 29 | for i in range(32): 30 | print " ", 31 | for j in range(8): 32 | print "{%d, %d}," % (a[8*i+j], b[8*i+j]), 33 | print 34 | print "};" 35 | print 36 | 37 | print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {" 38 | a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ] 39 | b = [ a[i] - a[i+1] for i in range(255) ] 40 | b.append(b[-1]) 41 | for i in range(32): 42 | print " ", 43 | for j in range(8): 44 | print "{%d, %d}," % (a[8*i+j], b[8*i+j]), 45 | print 46 | print "};" 47 | print 48 | 49 | print "#endif" 50 | 51 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/create_speed_lookuptable.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ Generate the stepper delay lookup table for Marlin firmware. """ 4 | 5 | import argparse 6 | 7 | __author__ = "Ben Gamari " 8 | __copyright__ = "Copyright 2012, Ben Gamari" 9 | __license__ = "GPL" 10 | 11 | parser = argparse.ArgumentParser(description=__doc__) 12 | parser.add_argument('-f', '--cpu-freq', type=int, default=16, help='CPU clockrate in MHz (default=16)') 13 | parser.add_argument('-d', '--divider', type=int, default=8, help='Timer/counter pre-scale divider (default=8)') 14 | args = parser.parse_args() 15 | 16 | cpu_freq = args.cpu_freq * 1000000 17 | timer_freq = cpu_freq / args.divider 18 | 19 | print "#ifndef SPEED_LOOKUPTABLE_H" 20 | print "#define SPEED_LOOKUPTABLE_H" 21 | print 22 | print '#include "Marlin.h"' 23 | print 24 | 25 | print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {" 26 | a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ] 27 | b = [ a[i] - a[i+1] for i in range(255) ] 28 | b.append(b[-1]) 29 | for i in range(32): 30 | print " ", 31 | for j in range(8): 32 | print "{%d, %d}," % (a[8*i+j], b[8*i+j]), 33 | print 34 | print "};" 35 | print 36 | 37 | print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {" 38 | a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ] 39 | b = [ a[i] - a[i+1] for i in range(255) ] 40 | b.append(b[-1]) 41 | for i in range(32): 42 | print " ", 43 | for j in range(8): 44 | print "{%d, %d}," % (a[8*i+j], b[8*i+j]), 45 | print 46 | print "};" 47 | print 48 | 49 | print "#endif" 50 | 51 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/SdFatUtil.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2008 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #include "Marlin.h" 21 | #ifdef SDSUPPORT 22 | 23 | #ifndef SdFatUtil_h 24 | #define SdFatUtil_h 25 | /** 26 | * \file 27 | * \brief Useful utility functions. 28 | */ 29 | #include "Marlin.h" 30 | #include "MarlinSerial.h" 31 | /** Store and print a string in flash memory.*/ 32 | #define PgmPrint(x) SerialPrint_P(PSTR(x)) 33 | /** Store and print a string in flash memory followed by a CR/LF.*/ 34 | #define PgmPrintln(x) SerialPrintln_P(PSTR(x)) 35 | 36 | namespace SdFatUtil { 37 | int FreeRam(); 38 | void print_P( PGM_P str); 39 | void println_P( PGM_P str); 40 | void SerialPrint_P(PGM_P str); 41 | void SerialPrintln_P(PGM_P str); 42 | } 43 | 44 | using namespace SdFatUtil; // NOLINT 45 | #endif // #define SdFatUtil_h 46 | 47 | 48 | #endif -------------------------------------------------------------------------------- /firmware/mk8/Marlin/SdFatUtil.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2008 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #include "Marlin.h" 21 | #ifdef SDSUPPORT 22 | 23 | #ifndef SdFatUtil_h 24 | #define SdFatUtil_h 25 | /** 26 | * \file 27 | * \brief Useful utility functions. 28 | */ 29 | #include "Marlin.h" 30 | #include "MarlinSerial.h" 31 | /** Store and print a string in flash memory.*/ 32 | #define PgmPrint(x) SerialPrint_P(PSTR(x)) 33 | /** Store and print a string in flash memory followed by a CR/LF.*/ 34 | #define PgmPrintln(x) SerialPrintln_P(PSTR(x)) 35 | 36 | namespace SdFatUtil { 37 | int FreeRam(); 38 | void print_P( PGM_P str); 39 | void println_P( PGM_P str); 40 | void SerialPrint_P(PGM_P str); 41 | void SerialPrintln_P(PGM_P str); 42 | } 43 | 44 | using namespace SdFatUtil; // NOLINT 45 | #endif // #define SdFatUtil_h 46 | 47 | 48 | #endif -------------------------------------------------------------------------------- /firmware/mk7/Marlin/SdFile.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2009 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | /** 21 | * \file 22 | * \brief SdFile class 23 | */ 24 | #include "Marlin.h" 25 | 26 | #ifdef SDSUPPORT 27 | #include "SdBaseFile.h" 28 | #include 29 | #ifndef SdFile_h 30 | #define SdFile_h 31 | //------------------------------------------------------------------------------ 32 | /** 33 | * \class SdFile 34 | * \brief SdBaseFile with Print. 35 | */ 36 | class SdFile : public SdBaseFile, public Print { 37 | public: 38 | SdFile() {} 39 | SdFile(const char* name, uint8_t oflag); 40 | #if ARDUINO >= 100 41 | size_t write(uint8_t b); 42 | #else 43 | void write(uint8_t b); 44 | #endif 45 | 46 | int16_t write(const void* buf, uint16_t nbyte); 47 | void write(const char* str); 48 | void write_P(PGM_P str); 49 | void writeln_P(PGM_P str); 50 | }; 51 | #endif // SdFile_h 52 | 53 | 54 | #endif -------------------------------------------------------------------------------- /firmware/mk8/Marlin/SdFile.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2009 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | /** 21 | * \file 22 | * \brief SdFile class 23 | */ 24 | #include "Marlin.h" 25 | 26 | #ifdef SDSUPPORT 27 | #include "SdBaseFile.h" 28 | #include 29 | #ifndef SdFile_h 30 | #define SdFile_h 31 | //------------------------------------------------------------------------------ 32 | /** 33 | * \class SdFile 34 | * \brief SdBaseFile with Print. 35 | */ 36 | class SdFile : public SdBaseFile, public Print { 37 | public: 38 | SdFile() {} 39 | SdFile(const char* name, uint8_t oflag); 40 | #if ARDUINO >= 100 41 | size_t write(uint8_t b); 42 | #else 43 | void write(uint8_t b); 44 | #endif 45 | 46 | int16_t write(const void* buf, uint16_t nbyte); 47 | void write(const char* str); 48 | void write_P(PGM_P str); 49 | void writeln_P(PGM_P str); 50 | }; 51 | #endif // SdFile_h 52 | 53 | 54 | #endif -------------------------------------------------------------------------------- /firmware/mk7/Marlin/digipot_mcp4451.cpp: -------------------------------------------------------------------------------- 1 | #include "Configuration.h" 2 | 3 | #ifdef DIGIPOT_I2C 4 | #include "Stream.h" 5 | #include "utility/twi.h" 6 | #include "Wire.h" 7 | 8 | // Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro 9 | #if MOTHERBOARD == 88 10 | #define DIGIPOT_I2C_FACTOR 117.96 11 | #define DIGIPOT_I2C_MAX_CURRENT 1.736 12 | #else 13 | #define DIGIPOT_I2C_FACTOR 106.7 14 | #define DIGIPOT_I2C_MAX_CURRENT 2.5 15 | #endif 16 | 17 | static byte current_to_wiper( float current ){ 18 | return byte(ceil(float((DIGIPOT_I2C_FACTOR*current)))); 19 | } 20 | 21 | static void i2c_send(byte addr, byte a, byte b) 22 | { 23 | Wire.beginTransmission(addr); 24 | Wire.write(a); 25 | Wire.write(b); 26 | Wire.endTransmission(); 27 | } 28 | 29 | // This is for the MCP4451 I2C based digipot 30 | void digipot_i2c_set_current( int channel, float current ) 31 | { 32 | current = min( (float) max( current, 0.0f ), DIGIPOT_I2C_MAX_CURRENT); 33 | // these addresses are specific to Azteeg X3 Pro, can be set to others, 34 | // In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1 35 | byte addr= 0x2C; // channel 0-3 36 | if(channel >= 4) { 37 | addr= 0x2E; // channel 4-7 38 | channel-= 4; 39 | } 40 | 41 | // Initial setup 42 | i2c_send( addr, 0x40, 0xff ); 43 | i2c_send( addr, 0xA0, 0xff ); 44 | 45 | // Set actual wiper value 46 | byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 }; 47 | i2c_send( addr, addresses[channel], current_to_wiper(current) ); 48 | } 49 | 50 | void digipot_i2c_init() 51 | { 52 | const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS; 53 | Wire.begin(); 54 | // setup initial currents as defined in Configuration_adv.h 55 | for(int i=0;i<=sizeof(digipot_motor_current)/sizeof(float);i++) { 56 | digipot_i2c_set_current(i, digipot_motor_current[i]); 57 | } 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/digipot_mcp4451.cpp: -------------------------------------------------------------------------------- 1 | #include "Configuration.h" 2 | 3 | #ifdef DIGIPOT_I2C 4 | #include "Stream.h" 5 | #include "utility/twi.h" 6 | #include "Wire.h" 7 | 8 | // Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro 9 | #if MOTHERBOARD == 88 10 | #define DIGIPOT_I2C_FACTOR 117.96 11 | #define DIGIPOT_I2C_MAX_CURRENT 1.736 12 | #else 13 | #define DIGIPOT_I2C_FACTOR 106.7 14 | #define DIGIPOT_I2C_MAX_CURRENT 2.5 15 | #endif 16 | 17 | static byte current_to_wiper( float current ){ 18 | return byte(ceil(float((DIGIPOT_I2C_FACTOR*current)))); 19 | } 20 | 21 | static void i2c_send(byte addr, byte a, byte b) 22 | { 23 | Wire.beginTransmission(addr); 24 | Wire.write(a); 25 | Wire.write(b); 26 | Wire.endTransmission(); 27 | } 28 | 29 | // This is for the MCP4451 I2C based digipot 30 | void digipot_i2c_set_current( int channel, float current ) 31 | { 32 | current = min( (float) max( current, 0.0f ), DIGIPOT_I2C_MAX_CURRENT); 33 | // these addresses are specific to Azteeg X3 Pro, can be set to others, 34 | // In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1 35 | byte addr= 0x2C; // channel 0-3 36 | if(channel >= 4) { 37 | addr= 0x2E; // channel 4-7 38 | channel-= 4; 39 | } 40 | 41 | // Initial setup 42 | i2c_send( addr, 0x40, 0xff ); 43 | i2c_send( addr, 0xA0, 0xff ); 44 | 45 | // Set actual wiper value 46 | byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 }; 47 | i2c_send( addr, addresses[channel], current_to_wiper(current) ); 48 | } 49 | 50 | void digipot_i2c_init() 51 | { 52 | const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS; 53 | Wire.begin(); 54 | // setup initial currents as defined in Configuration_adv.h 55 | for(int i=0;i<=sizeof(digipot_motor_current)/sizeof(float);i++) { 56 | digipot_i2c_set_current(i, digipot_motor_current[i]); 57 | } 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/vector_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | vector_3.cpp - Vector library for bed leveling 3 | Copyright (c) 2012 Lars Brubaker. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef VECTOR_3_H 20 | #define VECTOR_3_H 21 | 22 | #ifdef ENABLE_AUTO_BED_LEVELING 23 | class matrix_3x3; 24 | 25 | struct vector_3 26 | { 27 | float x, y, z; 28 | 29 | vector_3(); 30 | vector_3(float x, float y, float z); 31 | 32 | static vector_3 cross(vector_3 a, vector_3 b); 33 | 34 | vector_3 operator+(vector_3 v); 35 | vector_3 operator-(vector_3 v); 36 | void normalize(); 37 | float get_length(); 38 | vector_3 get_normal(); 39 | 40 | void debug(char* title); 41 | 42 | void apply_rotation(matrix_3x3 matrix); 43 | }; 44 | 45 | struct matrix_3x3 46 | { 47 | float matrix[9]; 48 | 49 | static matrix_3x3 create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2); 50 | static matrix_3x3 create_look_at(vector_3 target); 51 | static matrix_3x3 transpose(matrix_3x3 original); 52 | 53 | void set_to_identity(); 54 | 55 | void debug(char* title); 56 | }; 57 | 58 | 59 | void apply_rotation_xyz(matrix_3x3 rotationMatrix, float &x, float& y, float& z); 60 | #endif // ENABLE_AUTO_BED_LEVELING 61 | 62 | #endif // VECTOR_3_H 63 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/vector_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | vector_3.cpp - Vector library for bed leveling 3 | Copyright (c) 2012 Lars Brubaker. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef VECTOR_3_H 20 | #define VECTOR_3_H 21 | 22 | #ifdef ENABLE_AUTO_BED_LEVELING 23 | class matrix_3x3; 24 | 25 | struct vector_3 26 | { 27 | float x, y, z; 28 | 29 | vector_3(); 30 | vector_3(float x, float y, float z); 31 | 32 | static vector_3 cross(vector_3 a, vector_3 b); 33 | 34 | vector_3 operator+(vector_3 v); 35 | vector_3 operator-(vector_3 v); 36 | void normalize(); 37 | float get_length(); 38 | vector_3 get_normal(); 39 | 40 | void debug(char* title); 41 | 42 | void apply_rotation(matrix_3x3 matrix); 43 | }; 44 | 45 | struct matrix_3x3 46 | { 47 | float matrix[9]; 48 | 49 | static matrix_3x3 create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2); 50 | static matrix_3x3 create_look_at(vector_3 target); 51 | static matrix_3x3 transpose(matrix_3x3 original); 52 | 53 | void set_to_identity(); 54 | 55 | void debug(char* title); 56 | }; 57 | 58 | 59 | void apply_rotation_xyz(matrix_3x3 rotationMatrix, float &x, float& y, float& z); 60 | #endif // ENABLE_AUTO_BED_LEVELING 61 | 62 | #endif // VECTOR_3_H 63 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/Marlin.ino: -------------------------------------------------------------------------------- 1 | /* -*- c++ -*- */ 2 | 3 | /* 4 | Reprap firmware based on Sprinter and grbl. 5 | Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | */ 20 | 21 | /* 22 | This firmware is a mashup between Sprinter and grbl. 23 | (https://github.com/kliment/Sprinter) 24 | (https://github.com/simen/grbl/tree) 25 | 26 | It has preliminary support for Matthew Roberts advance algorithm 27 | http://reprap.org/pipermail/reprap-dev/2011-May/003323.html 28 | */ 29 | 30 | /* All the implementation is done in *.cpp files to get better compatibility with avr-gcc without the Arduino IDE */ 31 | /* Use this file to help the Arduino IDE find which Arduino libraries are needed and to keep documentation on GCode */ 32 | 33 | #include "Configuration.h" 34 | #include "pins.h" 35 | 36 | #ifdef ULTRA_LCD 37 | #if defined(LCD_I2C_TYPE_PCF8575) 38 | #include 39 | #include 40 | #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008) 41 | #include 42 | #include 43 | #elif defined(DOGLCD) 44 | #include // library for graphics LCD by Oli Kraus (https://code.google.com/p/u8glib/) 45 | #else 46 | #include // library for character LCD 47 | #endif 48 | #endif 49 | 50 | #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 51 | #include 52 | #endif 53 | 54 | #if defined(DIGIPOT_I2C) 55 | #include 56 | #endif 57 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/Marlin.ino: -------------------------------------------------------------------------------- 1 | /* -*- c++ -*- */ 2 | 3 | /* 4 | Reprap firmware based on Sprinter and grbl. 5 | Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | */ 20 | 21 | /* 22 | This firmware is a mashup between Sprinter and grbl. 23 | (https://github.com/kliment/Sprinter) 24 | (https://github.com/simen/grbl/tree) 25 | 26 | It has preliminary support for Matthew Roberts advance algorithm 27 | http://reprap.org/pipermail/reprap-dev/2011-May/003323.html 28 | */ 29 | 30 | /* All the implementation is done in *.cpp files to get better compatibility with avr-gcc without the Arduino IDE */ 31 | /* Use this file to help the Arduino IDE find which Arduino libraries are needed and to keep documentation on GCode */ 32 | 33 | #include "Configuration.h" 34 | #include "pins.h" 35 | 36 | #ifdef ULTRA_LCD 37 | #if defined(LCD_I2C_TYPE_PCF8575) 38 | #include 39 | #include 40 | #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008) 41 | #include 42 | #include 43 | #elif defined(DOGLCD) 44 | #include // library for graphics LCD by Oli Kraus (https://code.google.com/p/u8glib/) 45 | #else 46 | #include // library for character LCD 47 | #endif 48 | #endif 49 | 50 | #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 51 | #include 52 | #endif 53 | 54 | #if defined(DIGIPOT_I2C) 55 | #include 56 | #endif 57 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/watchdog.cpp: -------------------------------------------------------------------------------- 1 | #include "Marlin.h" 2 | 3 | #ifdef USE_WATCHDOG 4 | #include 5 | 6 | #include "watchdog.h" 7 | #include "ultralcd.h" 8 | 9 | //=========================================================================== 10 | //=============================private variables ============================ 11 | //=========================================================================== 12 | 13 | //=========================================================================== 14 | //=============================functinos ============================ 15 | //=========================================================================== 16 | 17 | 18 | /// intialise watch dog with a 4 sec interrupt time 19 | void watchdog_init() 20 | { 21 | #ifdef WATCHDOG_RESET_MANUAL 22 | //We enable the watchdog timer, but only for the interrupt. 23 | //Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details. 24 | wdt_reset(); 25 | _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE); 26 | _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S; 27 | #else 28 | wdt_enable(WDTO_4S); 29 | #endif 30 | } 31 | 32 | /// reset watchdog. MUST be called every 1s after init or avr will reset. 33 | void watchdog_reset() 34 | { 35 | wdt_reset(); 36 | } 37 | 38 | //=========================================================================== 39 | //=============================ISR ============================ 40 | //=========================================================================== 41 | 42 | //Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled. 43 | #ifdef WATCHDOG_RESET_MANUAL 44 | ISR(WDT_vect) 45 | { 46 | //TODO: This message gets overwritten by the kill() call 47 | LCD_ALERTMESSAGEPGM("ERR:Please Reset");//16 characters so it fits on a 16x2 display 48 | lcd_update(); 49 | SERIAL_ERROR_START; 50 | SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer."); 51 | kill(); //kill blocks 52 | while(1); //wait for user or serial reset 53 | } 54 | #endif//RESET_MANUAL 55 | 56 | #endif//USE_WATCHDOG 57 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/watchdog.cpp: -------------------------------------------------------------------------------- 1 | #include "Marlin.h" 2 | 3 | #ifdef USE_WATCHDOG 4 | #include 5 | 6 | #include "watchdog.h" 7 | #include "ultralcd.h" 8 | 9 | //=========================================================================== 10 | //=============================private variables ============================ 11 | //=========================================================================== 12 | 13 | //=========================================================================== 14 | //=============================functinos ============================ 15 | //=========================================================================== 16 | 17 | 18 | /// intialise watch dog with a 4 sec interrupt time 19 | void watchdog_init() 20 | { 21 | #ifdef WATCHDOG_RESET_MANUAL 22 | //We enable the watchdog timer, but only for the interrupt. 23 | //Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details. 24 | wdt_reset(); 25 | _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE); 26 | _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S; 27 | #else 28 | wdt_enable(WDTO_4S); 29 | #endif 30 | } 31 | 32 | /// reset watchdog. MUST be called every 1s after init or avr will reset. 33 | void watchdog_reset() 34 | { 35 | wdt_reset(); 36 | } 37 | 38 | //=========================================================================== 39 | //=============================ISR ============================ 40 | //=========================================================================== 41 | 42 | //Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled. 43 | #ifdef WATCHDOG_RESET_MANUAL 44 | ISR(WDT_vect) 45 | { 46 | //TODO: This message gets overwritten by the kill() call 47 | LCD_ALERTMESSAGEPGM("ERR:Please Reset");//16 characters so it fits on a 16x2 display 48 | lcd_update(); 49 | SERIAL_ERROR_START; 50 | SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer."); 51 | kill(); //kill blocks 52 | while(1); //wait for user or serial reset 53 | } 54 | #endif//RESET_MANUAL 55 | 56 | #endif//USE_WATCHDOG 57 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/SdFatUtil.cpp: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2008 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #include "Marlin.h" 21 | 22 | #ifdef SDSUPPORT 23 | #include "SdFatUtil.h" 24 | 25 | //------------------------------------------------------------------------------ 26 | /** Amount of free RAM 27 | * \return The number of free bytes. 28 | */ 29 | int SdFatUtil::FreeRam() { 30 | extern int __bss_end; 31 | extern int* __brkval; 32 | int free_memory; 33 | if (reinterpret_cast(__brkval) == 0) { 34 | // if no heap use from end of bss section 35 | free_memory = reinterpret_cast(&free_memory) 36 | - reinterpret_cast(&__bss_end); 37 | } else { 38 | // use from top of stack to heap 39 | free_memory = reinterpret_cast(&free_memory) 40 | - reinterpret_cast(__brkval); 41 | } 42 | return free_memory; 43 | } 44 | //------------------------------------------------------------------------------ 45 | /** %Print a string in flash memory. 46 | * 47 | * \param[in] pr Print object for output. 48 | * \param[in] str Pointer to string stored in flash memory. 49 | */ 50 | void SdFatUtil::print_P( PGM_P str) { 51 | for (uint8_t c; (c = pgm_read_byte(str)); str++) MYSERIAL.write(c); 52 | } 53 | //------------------------------------------------------------------------------ 54 | /** %Print a string in flash memory followed by a CR/LF. 55 | * 56 | * \param[in] pr Print object for output. 57 | * \param[in] str Pointer to string stored in flash memory. 58 | */ 59 | void SdFatUtil::println_P( PGM_P str) { 60 | print_P( str); 61 | MYSERIAL.println(); 62 | } 63 | //------------------------------------------------------------------------------ 64 | /** %Print a string in flash memory to Serial. 65 | * 66 | * \param[in] str Pointer to string stored in flash memory. 67 | */ 68 | void SdFatUtil::SerialPrint_P(PGM_P str) { 69 | print_P(str); 70 | } 71 | //------------------------------------------------------------------------------ 72 | /** %Print a string in flash memory to Serial followed by a CR/LF. 73 | * 74 | * \param[in] str Pointer to string stored in flash memory. 75 | */ 76 | void SdFatUtil::SerialPrintln_P(PGM_P str) { 77 | println_P( str); 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/SdFatUtil.cpp: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2008 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #include "Marlin.h" 21 | 22 | #ifdef SDSUPPORT 23 | #include "SdFatUtil.h" 24 | 25 | //------------------------------------------------------------------------------ 26 | /** Amount of free RAM 27 | * \return The number of free bytes. 28 | */ 29 | int SdFatUtil::FreeRam() { 30 | extern int __bss_end; 31 | extern int* __brkval; 32 | int free_memory; 33 | if (reinterpret_cast(__brkval) == 0) { 34 | // if no heap use from end of bss section 35 | free_memory = reinterpret_cast(&free_memory) 36 | - reinterpret_cast(&__bss_end); 37 | } else { 38 | // use from top of stack to heap 39 | free_memory = reinterpret_cast(&free_memory) 40 | - reinterpret_cast(__brkval); 41 | } 42 | return free_memory; 43 | } 44 | //------------------------------------------------------------------------------ 45 | /** %Print a string in flash memory. 46 | * 47 | * \param[in] pr Print object for output. 48 | * \param[in] str Pointer to string stored in flash memory. 49 | */ 50 | void SdFatUtil::print_P( PGM_P str) { 51 | for (uint8_t c; (c = pgm_read_byte(str)); str++) MYSERIAL.write(c); 52 | } 53 | //------------------------------------------------------------------------------ 54 | /** %Print a string in flash memory followed by a CR/LF. 55 | * 56 | * \param[in] pr Print object for output. 57 | * \param[in] str Pointer to string stored in flash memory. 58 | */ 59 | void SdFatUtil::println_P( PGM_P str) { 60 | print_P( str); 61 | MYSERIAL.println(); 62 | } 63 | //------------------------------------------------------------------------------ 64 | /** %Print a string in flash memory to Serial. 65 | * 66 | * \param[in] str Pointer to string stored in flash memory. 67 | */ 68 | void SdFatUtil::SerialPrint_P(PGM_P str) { 69 | print_P(str); 70 | } 71 | //------------------------------------------------------------------------------ 72 | /** %Print a string in flash memory to Serial followed by a CR/LF. 73 | * 74 | * \param[in] str Pointer to string stored in flash memory. 75 | */ 76 | void SdFatUtil::SerialPrintln_P(PGM_P str) { 77 | println_P( str); 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/cardreader.h: -------------------------------------------------------------------------------- 1 | #ifndef CARDREADER_H 2 | #define CARDREADER_H 3 | 4 | #ifdef SDSUPPORT 5 | 6 | #define MAX_DIR_DEPTH 10 7 | 8 | #include "SdFile.h" 9 | enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename}; 10 | class CardReader 11 | { 12 | public: 13 | CardReader(); 14 | 15 | void initsd(); 16 | void write_command(char *buf); 17 | //files auto[0-9].g on the sd card are performed in a row 18 | //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset 19 | 20 | void checkautostart(bool x); 21 | void openFile(char* name,bool read,bool replace_current=true); 22 | void openLogFile(char* name); 23 | void removeFile(char* name); 24 | void closefile(bool store_location=false); 25 | void release(); 26 | void startFileprint(); 27 | void pauseSDPrint(); 28 | void getStatus(); 29 | void printingHasFinished(); 30 | 31 | void getfilename(const uint8_t nr); 32 | uint16_t getnrfilenames(); 33 | 34 | void getAbsFilename(char *t); 35 | 36 | 37 | void ls(); 38 | void chdir(const char * relpath); 39 | void updir(); 40 | void setroot(); 41 | 42 | 43 | FORCE_INLINE bool isFileOpen() { return file.isOpen(); } 44 | FORCE_INLINE bool eof() { return sdpos>=filesize ;}; 45 | FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();}; 46 | FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);}; 47 | FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;}; 48 | FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;}; 49 | 50 | public: 51 | bool saving; 52 | bool logging; 53 | bool sdprinting ; 54 | bool cardOK ; 55 | char filename[13]; 56 | char longFilename[LONG_FILENAME_LENGTH]; 57 | bool filenameIsDir; 58 | int lastnr; //last number of the autostart; 59 | private: 60 | SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH]; 61 | uint16_t workDirDepth; 62 | Sd2Card card; 63 | SdVolume volume; 64 | SdFile file; 65 | #define SD_PROCEDURE_DEPTH 1 66 | #define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) 67 | uint8_t file_subcall_ctr; 68 | uint32_t filespos[SD_PROCEDURE_DEPTH]; 69 | char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; 70 | uint32_t filesize; 71 | //int16_t n; 72 | unsigned long autostart_atmillis; 73 | uint32_t sdpos ; 74 | 75 | bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. 76 | 77 | LsAction lsAction; //stored for recursion. 78 | int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory. 79 | char* diveDirName; 80 | void lsDive(const char *prepend,SdFile parent); 81 | }; 82 | extern CardReader card; 83 | #define IS_SD_PRINTING (card.sdprinting) 84 | 85 | #if (SDCARDDETECT > -1) 86 | # ifdef SDCARDDETECTINVERTED 87 | # define IS_SD_INSERTED (READ(SDCARDDETECT)!=0) 88 | # else 89 | # define IS_SD_INSERTED (READ(SDCARDDETECT)==0) 90 | # endif //SDCARDTETECTINVERTED 91 | #else 92 | //If we don't have a card detect line, aways asume the card is inserted 93 | # define IS_SD_INSERTED true 94 | #endif 95 | 96 | #else 97 | 98 | #define IS_SD_PRINTING (false) 99 | 100 | #endif //SDSUPPORT 101 | #endif 102 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/cardreader.h: -------------------------------------------------------------------------------- 1 | #ifndef CARDREADER_H 2 | #define CARDREADER_H 3 | 4 | #ifdef SDSUPPORT 5 | 6 | #define MAX_DIR_DEPTH 10 7 | 8 | #include "SdFile.h" 9 | enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename}; 10 | class CardReader 11 | { 12 | public: 13 | CardReader(); 14 | 15 | void initsd(); 16 | void write_command(char *buf); 17 | //files auto[0-9].g on the sd card are performed in a row 18 | //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset 19 | 20 | void checkautostart(bool x); 21 | void openFile(char* name,bool read,bool replace_current=true); 22 | void openLogFile(char* name); 23 | void removeFile(char* name); 24 | void closefile(bool store_location=false); 25 | void release(); 26 | void startFileprint(); 27 | void pauseSDPrint(); 28 | void getStatus(); 29 | void printingHasFinished(); 30 | 31 | void getfilename(const uint8_t nr); 32 | uint16_t getnrfilenames(); 33 | 34 | void getAbsFilename(char *t); 35 | 36 | 37 | void ls(); 38 | void chdir(const char * relpath); 39 | void updir(); 40 | void setroot(); 41 | 42 | 43 | FORCE_INLINE bool isFileOpen() { return file.isOpen(); } 44 | FORCE_INLINE bool eof() { return sdpos>=filesize ;}; 45 | FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();}; 46 | FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);}; 47 | FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;}; 48 | FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;}; 49 | 50 | public: 51 | bool saving; 52 | bool logging; 53 | bool sdprinting ; 54 | bool cardOK ; 55 | char filename[13]; 56 | char longFilename[LONG_FILENAME_LENGTH]; 57 | bool filenameIsDir; 58 | int lastnr; //last number of the autostart; 59 | private: 60 | SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH]; 61 | uint16_t workDirDepth; 62 | Sd2Card card; 63 | SdVolume volume; 64 | SdFile file; 65 | #define SD_PROCEDURE_DEPTH 1 66 | #define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) 67 | uint8_t file_subcall_ctr; 68 | uint32_t filespos[SD_PROCEDURE_DEPTH]; 69 | char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; 70 | uint32_t filesize; 71 | //int16_t n; 72 | unsigned long autostart_atmillis; 73 | uint32_t sdpos ; 74 | 75 | bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. 76 | 77 | LsAction lsAction; //stored for recursion. 78 | int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory. 79 | char* diveDirName; 80 | void lsDive(const char *prepend,SdFile parent); 81 | }; 82 | extern CardReader card; 83 | #define IS_SD_PRINTING (card.sdprinting) 84 | 85 | #if (SDCARDDETECT > -1) 86 | # ifdef SDCARDDETECTINVERTED 87 | # define IS_SD_INSERTED (READ(SDCARDDETECT)!=0) 88 | # else 89 | # define IS_SD_INSERTED (READ(SDCARDDETECT)==0) 90 | # endif //SDCARDTETECTINVERTED 91 | #else 92 | //If we don't have a card detect line, aways asume the card is inserted 93 | # define IS_SD_INSERTED true 94 | #endif 95 | 96 | #else 97 | 98 | #define IS_SD_PRINTING (false) 99 | 100 | #endif //SDSUPPORT 101 | #endif 102 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/SdFile.cpp: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2009 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #include "Marlin.h" 21 | 22 | #ifdef SDSUPPORT 23 | #include "SdFile.h" 24 | /** Create a file object and open it in the current working directory. 25 | * 26 | * \param[in] path A path with a valid 8.3 DOS name for a file to be opened. 27 | * 28 | * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive 29 | * OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t). 30 | */ 31 | SdFile::SdFile(const char* path, uint8_t oflag) : SdBaseFile(path, oflag) { 32 | } 33 | //------------------------------------------------------------------------------ 34 | /** Write data to an open file. 35 | * 36 | * \note Data is moved to the cache but may not be written to the 37 | * storage device until sync() is called. 38 | * 39 | * \param[in] buf Pointer to the location of the data to be written. 40 | * 41 | * \param[in] nbyte Number of bytes to write. 42 | * 43 | * \return For success write() returns the number of bytes written, always 44 | * \a nbyte. If an error occurs, write() returns -1. Possible errors 45 | * include write() is called before a file has been opened, write is called 46 | * for a read-only file, device is full, a corrupt file system or an I/O error. 47 | * 48 | */ 49 | int16_t SdFile::write(const void* buf, uint16_t nbyte) { 50 | return SdBaseFile::write(buf, nbyte); 51 | } 52 | //------------------------------------------------------------------------------ 53 | /** Write a byte to a file. Required by the Arduino Print class. 54 | * \param[in] b the byte to be written. 55 | * Use writeError to check for errors. 56 | */ 57 | #if ARDUINO >= 100 58 | size_t SdFile::write(uint8_t b) 59 | { 60 | return SdBaseFile::write(&b, 1); 61 | } 62 | #else 63 | void SdFile::write(uint8_t b) 64 | { 65 | SdBaseFile::write(&b, 1); 66 | } 67 | #endif 68 | //------------------------------------------------------------------------------ 69 | /** Write a string to a file. Used by the Arduino Print class. 70 | * \param[in] str Pointer to the string. 71 | * Use writeError to check for errors. 72 | */ 73 | void SdFile::write(const char* str) { 74 | SdBaseFile::write(str, strlen(str)); 75 | } 76 | //------------------------------------------------------------------------------ 77 | /** Write a PROGMEM string to a file. 78 | * \param[in] str Pointer to the PROGMEM string. 79 | * Use writeError to check for errors. 80 | */ 81 | void SdFile::write_P(PGM_P str) { 82 | for (uint8_t c; (c = pgm_read_byte(str)); str++) write(c); 83 | } 84 | //------------------------------------------------------------------------------ 85 | /** Write a PROGMEM string followed by CR/LF to a file. 86 | * \param[in] str Pointer to the PROGMEM string. 87 | * Use writeError to check for errors. 88 | */ 89 | void SdFile::writeln_P(PGM_P str) { 90 | write_P(str); 91 | write_P(PSTR("\r\n")); 92 | } 93 | 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/SdFile.cpp: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2009 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | #include "Marlin.h" 21 | 22 | #ifdef SDSUPPORT 23 | #include "SdFile.h" 24 | /** Create a file object and open it in the current working directory. 25 | * 26 | * \param[in] path A path with a valid 8.3 DOS name for a file to be opened. 27 | * 28 | * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive 29 | * OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t). 30 | */ 31 | SdFile::SdFile(const char* path, uint8_t oflag) : SdBaseFile(path, oflag) { 32 | } 33 | //------------------------------------------------------------------------------ 34 | /** Write data to an open file. 35 | * 36 | * \note Data is moved to the cache but may not be written to the 37 | * storage device until sync() is called. 38 | * 39 | * \param[in] buf Pointer to the location of the data to be written. 40 | * 41 | * \param[in] nbyte Number of bytes to write. 42 | * 43 | * \return For success write() returns the number of bytes written, always 44 | * \a nbyte. If an error occurs, write() returns -1. Possible errors 45 | * include write() is called before a file has been opened, write is called 46 | * for a read-only file, device is full, a corrupt file system or an I/O error. 47 | * 48 | */ 49 | int16_t SdFile::write(const void* buf, uint16_t nbyte) { 50 | return SdBaseFile::write(buf, nbyte); 51 | } 52 | //------------------------------------------------------------------------------ 53 | /** Write a byte to a file. Required by the Arduino Print class. 54 | * \param[in] b the byte to be written. 55 | * Use writeError to check for errors. 56 | */ 57 | #if ARDUINO >= 100 58 | size_t SdFile::write(uint8_t b) 59 | { 60 | return SdBaseFile::write(&b, 1); 61 | } 62 | #else 63 | void SdFile::write(uint8_t b) 64 | { 65 | SdBaseFile::write(&b, 1); 66 | } 67 | #endif 68 | //------------------------------------------------------------------------------ 69 | /** Write a string to a file. Used by the Arduino Print class. 70 | * \param[in] str Pointer to the string. 71 | * Use writeError to check for errors. 72 | */ 73 | void SdFile::write(const char* str) { 74 | SdBaseFile::write(str, strlen(str)); 75 | } 76 | //------------------------------------------------------------------------------ 77 | /** Write a PROGMEM string to a file. 78 | * \param[in] str Pointer to the PROGMEM string. 79 | * Use writeError to check for errors. 80 | */ 81 | void SdFile::write_P(PGM_P str) { 82 | for (uint8_t c; (c = pgm_read_byte(str)); str++) write(c); 83 | } 84 | //------------------------------------------------------------------------------ 85 | /** Write a PROGMEM string followed by CR/LF to a file. 86 | * \param[in] str Pointer to the PROGMEM string. 87 | * Use writeError to check for errors. 88 | */ 89 | void SdFile::writeln_P(PGM_P str) { 90 | write_P(str); 91 | write_P(PSTR("\r\n")); 92 | } 93 | 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/LiquidCrystalRus.h: -------------------------------------------------------------------------------- 1 | // 2 | // based on LiquidCrystal library from ArduinoIDE, see http://arduino.cc 3 | // modified 27 Jul 2011 4 | // by Ilya V. Danilov http://mk90.ru/ 5 | // 6 | 7 | #ifndef LiquidCrystalRus_h 8 | #define LiquidCrystalRus_h 9 | 10 | #include 11 | #include "Print.h" 12 | 13 | // commands 14 | #define LCD_CLEARDISPLAY 0x01 15 | #define LCD_RETURNHOME 0x02 16 | #define LCD_ENTRYMODESET 0x04 17 | #define LCD_DISPLAYCONTROL 0x08 18 | #define LCD_CURSORSHIFT 0x10 19 | #define LCD_FUNCTIONSET 0x20 20 | #define LCD_SETCGRAMADDR 0x40 21 | #define LCD_SETDDRAMADDR 0x80 22 | 23 | // flags for display entry mode 24 | #define LCD_ENTRYRIGHT 0x00 25 | #define LCD_ENTRYLEFT 0x02 26 | #define LCD_ENTRYSHIFTINCREMENT 0x01 27 | #define LCD_ENTRYSHIFTDECREMENT 0x00 28 | 29 | // flags for display on/off control 30 | #define LCD_DISPLAYON 0x04 31 | #define LCD_DISPLAYOFF 0x00 32 | #define LCD_CURSORON 0x02 33 | #define LCD_CURSOROFF 0x00 34 | #define LCD_BLINKON 0x01 35 | #define LCD_BLINKOFF 0x00 36 | 37 | // flags for display/cursor shift 38 | #define LCD_DISPLAYMOVE 0x08 39 | #define LCD_CURSORMOVE 0x00 40 | #define LCD_MOVERIGHT 0x04 41 | #define LCD_MOVELEFT 0x00 42 | 43 | // flags for function set 44 | #define LCD_8BITMODE 0x10 45 | #define LCD_4BITMODE 0x00 46 | #define LCD_2LINE 0x08 47 | #define LCD_1LINE 0x00 48 | #define LCD_5x10DOTS 0x04 49 | #define LCD_5x8DOTS 0x00 50 | 51 | // enum for 52 | #define LCD_DRAM_Normal 0x00 53 | #define LCD_DRAM_WH1601 0x01 54 | 55 | 56 | class LiquidCrystalRus : public Print { 57 | public: 58 | LiquidCrystalRus(uint8_t rs, uint8_t enable, 59 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 60 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 61 | LiquidCrystalRus(uint8_t rs, uint8_t rw, uint8_t enable, 62 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 63 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 64 | LiquidCrystalRus(uint8_t rs, uint8_t rw, uint8_t enable, 65 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 66 | LiquidCrystalRus(uint8_t rs, uint8_t enable, 67 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 68 | 69 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 70 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 71 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 72 | 73 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 74 | 75 | void clear(); 76 | void home(); 77 | 78 | void noDisplay(); 79 | void display(); 80 | void noBlink(); 81 | void blink(); 82 | void noCursor(); 83 | void cursor(); 84 | void scrollDisplayLeft(); 85 | void scrollDisplayRight(); 86 | void leftToRight(); 87 | void rightToLeft(); 88 | void autoscroll(); 89 | void noAutoscroll(); 90 | 91 | void createChar(uint8_t, uint8_t[]); 92 | void setCursor(uint8_t, uint8_t); 93 | 94 | #if defined(ARDUINO) && ARDUINO >= 100 95 | virtual size_t write(uint8_t); 96 | using Print::write; 97 | #else 98 | virtual void write(uint8_t); 99 | #endif 100 | 101 | void command(uint8_t); 102 | 103 | void setDRAMModel(uint8_t); 104 | 105 | private: 106 | void send(uint8_t, uint8_t); 107 | void writeNbits(uint8_t, uint8_t); 108 | uint8_t recv(uint8_t); 109 | uint8_t readNbits(uint8_t); 110 | void pulseEnable(); 111 | 112 | uint8_t _rs_pin; // LOW: command. HIGH: character. 113 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 114 | uint8_t _enable_pin; // activated by a HIGH pulse. 115 | uint8_t _data_pins[8]; 116 | 117 | uint8_t _displayfunction; 118 | uint8_t _displaycontrol; 119 | uint8_t _displaymode; 120 | 121 | uint8_t _initialized; 122 | 123 | uint8_t _numlines,_currline; 124 | 125 | uint8_t _dram_model; 126 | uint8_t utf_hi_char; // UTF-8 high part 127 | }; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/LiquidCrystalRus.h: -------------------------------------------------------------------------------- 1 | // 2 | // based on LiquidCrystal library from ArduinoIDE, see http://arduino.cc 3 | // modified 27 Jul 2011 4 | // by Ilya V. Danilov http://mk90.ru/ 5 | // 6 | 7 | #ifndef LiquidCrystalRus_h 8 | #define LiquidCrystalRus_h 9 | 10 | #include 11 | #include "Print.h" 12 | 13 | // commands 14 | #define LCD_CLEARDISPLAY 0x01 15 | #define LCD_RETURNHOME 0x02 16 | #define LCD_ENTRYMODESET 0x04 17 | #define LCD_DISPLAYCONTROL 0x08 18 | #define LCD_CURSORSHIFT 0x10 19 | #define LCD_FUNCTIONSET 0x20 20 | #define LCD_SETCGRAMADDR 0x40 21 | #define LCD_SETDDRAMADDR 0x80 22 | 23 | // flags for display entry mode 24 | #define LCD_ENTRYRIGHT 0x00 25 | #define LCD_ENTRYLEFT 0x02 26 | #define LCD_ENTRYSHIFTINCREMENT 0x01 27 | #define LCD_ENTRYSHIFTDECREMENT 0x00 28 | 29 | // flags for display on/off control 30 | #define LCD_DISPLAYON 0x04 31 | #define LCD_DISPLAYOFF 0x00 32 | #define LCD_CURSORON 0x02 33 | #define LCD_CURSOROFF 0x00 34 | #define LCD_BLINKON 0x01 35 | #define LCD_BLINKOFF 0x00 36 | 37 | // flags for display/cursor shift 38 | #define LCD_DISPLAYMOVE 0x08 39 | #define LCD_CURSORMOVE 0x00 40 | #define LCD_MOVERIGHT 0x04 41 | #define LCD_MOVELEFT 0x00 42 | 43 | // flags for function set 44 | #define LCD_8BITMODE 0x10 45 | #define LCD_4BITMODE 0x00 46 | #define LCD_2LINE 0x08 47 | #define LCD_1LINE 0x00 48 | #define LCD_5x10DOTS 0x04 49 | #define LCD_5x8DOTS 0x00 50 | 51 | // enum for 52 | #define LCD_DRAM_Normal 0x00 53 | #define LCD_DRAM_WH1601 0x01 54 | 55 | 56 | class LiquidCrystalRus : public Print { 57 | public: 58 | LiquidCrystalRus(uint8_t rs, uint8_t enable, 59 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 60 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 61 | LiquidCrystalRus(uint8_t rs, uint8_t rw, uint8_t enable, 62 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 63 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 64 | LiquidCrystalRus(uint8_t rs, uint8_t rw, uint8_t enable, 65 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 66 | LiquidCrystalRus(uint8_t rs, uint8_t enable, 67 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 68 | 69 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 70 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 71 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 72 | 73 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 74 | 75 | void clear(); 76 | void home(); 77 | 78 | void noDisplay(); 79 | void display(); 80 | void noBlink(); 81 | void blink(); 82 | void noCursor(); 83 | void cursor(); 84 | void scrollDisplayLeft(); 85 | void scrollDisplayRight(); 86 | void leftToRight(); 87 | void rightToLeft(); 88 | void autoscroll(); 89 | void noAutoscroll(); 90 | 91 | void createChar(uint8_t, uint8_t[]); 92 | void setCursor(uint8_t, uint8_t); 93 | 94 | #if defined(ARDUINO) && ARDUINO >= 100 95 | virtual size_t write(uint8_t); 96 | using Print::write; 97 | #else 98 | virtual void write(uint8_t); 99 | #endif 100 | 101 | void command(uint8_t); 102 | 103 | void setDRAMModel(uint8_t); 104 | 105 | private: 106 | void send(uint8_t, uint8_t); 107 | void writeNbits(uint8_t, uint8_t); 108 | uint8_t recv(uint8_t); 109 | uint8_t readNbits(uint8_t); 110 | void pulseEnable(); 111 | 112 | uint8_t _rs_pin; // LOW: command. HIGH: character. 113 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 114 | uint8_t _enable_pin; // activated by a HIGH pulse. 115 | uint8_t _data_pins[8]; 116 | 117 | uint8_t _displayfunction; 118 | uint8_t _displaycontrol; 119 | uint8_t _displaymode; 120 | 121 | uint8_t _initialized; 122 | 123 | uint8_t _numlines,_currline; 124 | 125 | uint8_t _dram_model; 126 | uint8_t utf_hi_char; // UTF-8 high part 127 | }; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /profiles/slic3r/smartcore_slic3r.ini: -------------------------------------------------------------------------------- 1 | # generated by Slic3r 1.0.0RC2 on Fri Jan 30 12:49:54 2015 2 | avoid_crossing_perimeters = 0 3 | bed_size = 190,180 4 | bed_temperature = 0 5 | bottom_solid_layers = 3 6 | bridge_acceleration = 0 7 | bridge_fan_speed = 90 8 | bridge_flow_ratio = 1 9 | bridge_speed = 60 10 | brim_width = 0 11 | complete_objects = 0 12 | cooling = 13 | default_acceleration = 0 14 | disable_fan_first_layers = 0 15 | duplicate = 1 16 | duplicate_distance = 6 17 | duplicate_grid = 1,1 18 | end_gcode = M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nG1 Z80 ; get down the platformenough 19 | external_perimeter_speed = 70% 20 | external_perimeters_first = 0 21 | extra_perimeters = 1 22 | extruder_clearance_height = 20 23 | extruder_clearance_radius = 20 24 | extruder_offset = 0x0 25 | extrusion_axis = E 26 | extrusion_multiplier = 1 27 | extrusion_width = 0 28 | fan_always_on = 29 | fan_below_layer_time = 60 30 | filament_diameter = 1.75 31 | fill_angle = 45 32 | fill_density = 0.35 33 | fill_pattern = rectilinear 34 | first_layer_acceleration = 0 35 | first_layer_bed_temperature = 0 36 | first_layer_extrusion_width = 200% 37 | first_layer_height = 0.30 38 | first_layer_speed = 40% 39 | first_layer_temperature = 200 40 | g0 = 0 41 | gap_fill_speed = 20 42 | gcode_arcs = 0 43 | gcode_comments = 0 44 | gcode_flavor = reprap 45 | infill_acceleration = 0 46 | infill_every_layers = 1 47 | infill_extruder = 1 48 | infill_extrusion_width = 0 49 | infill_first = 0 50 | infill_only_where_needed = 0 51 | infill_speed = 70 52 | layer_gcode = 53 | layer_height = 0.30 54 | max_fan_speed = 90 55 | min_fan_speed = 80 56 | min_print_speed = 10 57 | min_skirt_length = 0 58 | notes = 59 | nozzle_diameter = 0.4 60 | only_retract_when_crossing_perimeters = 1 61 | ooze_prevention = 0 62 | output_filename_format = [input_filename_base].gcode 63 | overhangs = 1 64 | perimeter_acceleration = 0 65 | perimeter_extruder = 1 66 | perimeter_extrusion_width = 0 67 | perimeter_speed = 40 68 | perimeters = 3 69 | post_process = 70 | print_center = 95,90 71 | raft_layers = 0 72 | randomize_start = 0 73 | resolution = 0 74 | retract_before_travel = 2 75 | retract_layer_change = 1 76 | retract_length = 4.5 77 | retract_length_toolchange = 10 78 | retract_lift = 0 79 | retract_restart_extra = 0 80 | retract_restart_extra_toolchange = 0 81 | retract_speed = 40 82 | rotate = 0 83 | scale = 1 84 | skirt_distance = 2 85 | skirt_height = 1 86 | skirts = 1 87 | slowdown_below_layer_time = 30 88 | small_perimeter_speed = 40 89 | solid_fill_pattern = rectilinear 90 | solid_infill_below_area = 70 91 | solid_infill_every_layers = 0 92 | solid_infill_extrusion_width = 0 93 | solid_infill_speed = 70 94 | spiral_vase = 0 95 | standby_temperature_delta = -5 96 | start_gcode = M851 Z-1\nM109 S[first_layer_temperature_0];set extruder temp and start heating\nG28 X0 Y0 ;home X and Y and Z\nG1 Y30 F3000\nG28 Z0 F3000\nG29 ;probe bed\nG90; set absolute coordinates\nG92 E0; reset extruder distance 97 | start_perimeters_at_concave_points = 0 98 | start_perimeters_at_non_overhang = 0 99 | support_material = 100 | support_material_angle = 0 101 | support_material_enforce_layers = 0 102 | support_material_extruder = 1 103 | support_material_extrusion_width = 0 104 | support_material_interface_extruder = 1 105 | support_material_interface_layers = 0 106 | support_material_interface_spacing = 0 107 | support_material_pattern = rectilinear 108 | support_material_spacing = 2.5 109 | support_material_speed = 60 110 | support_material_threshold = 0 111 | temperature = 200 112 | thin_walls = 1 113 | threads = 2 114 | toolchange_gcode = 115 | top_infill_extrusion_width = 0 116 | top_solid_infill_speed = 70 117 | top_solid_layers = 3 118 | travel_speed = 130 119 | use_firmware_retraction = 0 120 | use_relative_e_distances = 0 121 | vibration_limit = 0 122 | wipe = 1 123 | z_offset = 0 124 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/ultralcd.h: -------------------------------------------------------------------------------- 1 | #ifndef ULTRALCD_H 2 | #define ULTRALCD_H 3 | 4 | #include "Marlin.h" 5 | 6 | #ifdef ULTRA_LCD 7 | 8 | void lcd_update(); 9 | void lcd_init(); 10 | void lcd_setstatus(const char* message); 11 | void lcd_setstatuspgm(const char* message); 12 | void lcd_setalertstatuspgm(const char* message); 13 | void lcd_reset_alert_level(); 14 | 15 | #ifdef DOGLCD 16 | extern int lcd_contrast; 17 | void lcd_setcontrast(uint8_t value); 18 | #endif 19 | 20 | static unsigned char blink = 0; // Variable for visualization of fan rotation in GLCD 21 | 22 | #define LCD_MESSAGEPGM(x) lcd_setstatuspgm(PSTR(x)) 23 | #define LCD_ALERTMESSAGEPGM(x) lcd_setalertstatuspgm(PSTR(x)) 24 | 25 | #define LCD_UPDATE_INTERVAL 100 26 | #define LCD_TIMEOUT_TO_STATUS 15000 27 | 28 | #ifdef ULTIPANEL 29 | void lcd_buttons_update(); 30 | extern volatile uint8_t buttons; //the last checked buttons in a bit array. 31 | #ifdef REPRAPWORLD_KEYPAD 32 | extern volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shift register values 33 | #endif 34 | #else 35 | FORCE_INLINE void lcd_buttons_update() {} 36 | #endif 37 | 38 | extern int plaPreheatHotendTemp; 39 | extern int plaPreheatHPBTemp; 40 | extern int plaPreheatFanSpeed; 41 | 42 | extern int absPreheatHotendTemp; 43 | extern int absPreheatHPBTemp; 44 | extern int absPreheatFanSpeed; 45 | 46 | extern bool cancel_heatup; 47 | 48 | void lcd_buzz(long duration,uint16_t freq); 49 | bool lcd_clicked(); 50 | 51 | #ifdef NEWPANEL 52 | #define EN_C (1< 23 | 24 | static void ST7920_SWSPI_SND_8BIT(uint8_t val) 25 | { 26 | uint8_t i; 27 | for( i=0; i<8; i++ ) 28 | { 29 | WRITE(ST7920_CLK_PIN,0); 30 | WRITE(ST7920_DAT_PIN,val&0x80); 31 | val<<=1; 32 | WRITE(ST7920_CLK_PIN,1); 33 | } 34 | } 35 | 36 | #define ST7920_CS() {WRITE(ST7920_CS_PIN,1);u8g_10MicroDelay();} 37 | #define ST7920_NCS() {WRITE(ST7920_CS_PIN,0);} 38 | #define ST7920_SET_CMD() {ST7920_SWSPI_SND_8BIT(0xf8);u8g_10MicroDelay();} 39 | #define ST7920_SET_DAT() {ST7920_SWSPI_SND_8BIT(0xfa);u8g_10MicroDelay();} 40 | #define ST7920_WRITE_BYTE(a) {ST7920_SWSPI_SND_8BIT((a)&0xf0);ST7920_SWSPI_SND_8BIT((a)<<4);u8g_10MicroDelay();} 41 | #define ST7920_WRITE_BYTES(p,l) {uint8_t i;for(i=0;idev_mem); 84 | y = pb->p.page_y0; 85 | ptr = (uint8_t*)pb->buf; 86 | 87 | ST7920_CS(); 88 | for( i = 0; i < PAGE_HEIGHT; i ++ ) 89 | { 90 | ST7920_SET_CMD(); 91 | if ( y < 32 ) 92 | { 93 | ST7920_WRITE_BYTE(0x80 | y); //y 94 | ST7920_WRITE_BYTE(0x80); //x=0 95 | } 96 | else 97 | { 98 | ST7920_WRITE_BYTE(0x80 | (y-32)); //y 99 | ST7920_WRITE_BYTE(0x80 | 8); //x=64 100 | } 101 | 102 | ST7920_SET_DAT(); 103 | ST7920_WRITE_BYTES(ptr,WIDTH/8); //ptr is incremented inside of macro 104 | y++; 105 | } 106 | ST7920_NCS(); 107 | } 108 | break; 109 | } 110 | #if PAGE_HEIGHT == 8 111 | return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg); 112 | #elif PAGE_HEIGHT == 16 113 | return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg); 114 | #else 115 | return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg); 116 | #endif 117 | } 118 | 119 | uint8_t u8g_dev_st7920_128x64_rrd_buf[WIDTH*(PAGE_HEIGHT/8)] U8G_NOCOMMON; 120 | u8g_pb_t u8g_dev_st7920_128x64_rrd_pb = {{PAGE_HEIGHT,HEIGHT,0,0,0},WIDTH,u8g_dev_st7920_128x64_rrd_buf}; 121 | u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = {u8g_dev_rrd_st7920_128x64_fn,&u8g_dev_st7920_128x64_rrd_pb,&u8g_com_null_fn}; 122 | 123 | class U8GLIB_ST7920_128X64_RRD : public U8GLIB 124 | { 125 | public: 126 | U8GLIB_ST7920_128X64_RRD(uint8_t dummy) : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi) {} 127 | }; 128 | 129 | 130 | #endif //U8GLIB_ST7920 131 | #endif //ULCDST7920_H 132 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/ultralcd_st7920_u8glib_rrd.h: -------------------------------------------------------------------------------- 1 | #ifndef ULCDST7920_H 2 | #define ULCDST7920_H 3 | 4 | #include "Marlin.h" 5 | 6 | #ifdef U8GLIB_ST7920 7 | 8 | //set optimization so ARDUINO optimizes this file 9 | #pragma GCC optimize (3) 10 | 11 | #define ST7920_CLK_PIN LCD_PINS_D4 12 | #define ST7920_DAT_PIN LCD_PINS_ENABLE 13 | #define ST7920_CS_PIN LCD_PINS_RS 14 | 15 | //#define PAGE_HEIGHT 8 //128 byte framebuffer 16 | //#define PAGE_HEIGHT 16 //256 byte framebuffer 17 | #define PAGE_HEIGHT 32 //512 byte framebuffer 18 | 19 | #define WIDTH 128 20 | #define HEIGHT 64 21 | 22 | #include 23 | 24 | static void ST7920_SWSPI_SND_8BIT(uint8_t val) 25 | { 26 | uint8_t i; 27 | for( i=0; i<8; i++ ) 28 | { 29 | WRITE(ST7920_CLK_PIN,0); 30 | WRITE(ST7920_DAT_PIN,val&0x80); 31 | val<<=1; 32 | WRITE(ST7920_CLK_PIN,1); 33 | } 34 | } 35 | 36 | #define ST7920_CS() {WRITE(ST7920_CS_PIN,1);u8g_10MicroDelay();} 37 | #define ST7920_NCS() {WRITE(ST7920_CS_PIN,0);} 38 | #define ST7920_SET_CMD() {ST7920_SWSPI_SND_8BIT(0xf8);u8g_10MicroDelay();} 39 | #define ST7920_SET_DAT() {ST7920_SWSPI_SND_8BIT(0xfa);u8g_10MicroDelay();} 40 | #define ST7920_WRITE_BYTE(a) {ST7920_SWSPI_SND_8BIT((a)&0xf0);ST7920_SWSPI_SND_8BIT((a)<<4);u8g_10MicroDelay();} 41 | #define ST7920_WRITE_BYTES(p,l) {uint8_t i;for(i=0;idev_mem); 84 | y = pb->p.page_y0; 85 | ptr = (uint8_t*)pb->buf; 86 | 87 | ST7920_CS(); 88 | for( i = 0; i < PAGE_HEIGHT; i ++ ) 89 | { 90 | ST7920_SET_CMD(); 91 | if ( y < 32 ) 92 | { 93 | ST7920_WRITE_BYTE(0x80 | y); //y 94 | ST7920_WRITE_BYTE(0x80); //x=0 95 | } 96 | else 97 | { 98 | ST7920_WRITE_BYTE(0x80 | (y-32)); //y 99 | ST7920_WRITE_BYTE(0x80 | 8); //x=64 100 | } 101 | 102 | ST7920_SET_DAT(); 103 | ST7920_WRITE_BYTES(ptr,WIDTH/8); //ptr is incremented inside of macro 104 | y++; 105 | } 106 | ST7920_NCS(); 107 | } 108 | break; 109 | } 110 | #if PAGE_HEIGHT == 8 111 | return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg); 112 | #elif PAGE_HEIGHT == 16 113 | return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg); 114 | #else 115 | return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg); 116 | #endif 117 | } 118 | 119 | uint8_t u8g_dev_st7920_128x64_rrd_buf[WIDTH*(PAGE_HEIGHT/8)] U8G_NOCOMMON; 120 | u8g_pb_t u8g_dev_st7920_128x64_rrd_pb = {{PAGE_HEIGHT,HEIGHT,0,0,0},WIDTH,u8g_dev_st7920_128x64_rrd_buf}; 121 | u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = {u8g_dev_rrd_st7920_128x64_fn,&u8g_dev_st7920_128x64_rrd_pb,&u8g_com_null_fn}; 122 | 123 | class U8GLIB_ST7920_128X64_RRD : public U8GLIB 124 | { 125 | public: 126 | U8GLIB_ST7920_128X64_RRD(uint8_t dummy) : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi) {} 127 | }; 128 | 129 | 130 | #endif //U8GLIB_ST7920 131 | #endif //ULCDST7920_H 132 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/SdFatConfig.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2009 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | /** 21 | * \file 22 | * \brief configuration definitions 23 | */ 24 | #include "Marlin.h" 25 | #ifdef SDSUPPORT 26 | 27 | #ifndef SdFatConfig_h 28 | #define SdFatConfig_h 29 | #include 30 | //------------------------------------------------------------------------------ 31 | /** 32 | * To use multiple SD cards set USE_MULTIPLE_CARDS nonzero. 33 | * 34 | * Using multiple cards costs 400 - 500 bytes of flash. 35 | * 36 | * Each card requires about 550 bytes of SRAM so use of a Mega is recommended. 37 | */ 38 | #define USE_MULTIPLE_CARDS 0 39 | //------------------------------------------------------------------------------ 40 | /** 41 | * Call flush for endl if ENDL_CALLS_FLUSH is nonzero 42 | * 43 | * The standard for iostreams is to call flush. This is very costly for 44 | * SdFat. Each call to flush causes 2048 bytes of I/O to the SD. 45 | * 46 | * SdFat has a single 512 byte buffer for SD I/O so it must write the current 47 | * data block to the SD, read the directory block from the SD, update the 48 | * directory entry, write the directory block to the SD and read the data 49 | * block back into the buffer. 50 | * 51 | * The SD flash memory controller is not designed for this many rewrites 52 | * so performance may be reduced by more than a factor of 100. 53 | * 54 | * If ENDL_CALLS_FLUSH is zero, you must call flush and/or close to force 55 | * all data to be written to the SD. 56 | */ 57 | #define ENDL_CALLS_FLUSH 0 58 | //------------------------------------------------------------------------------ 59 | /** 60 | * Allow use of deprecated functions if ALLOW_DEPRECATED_FUNCTIONS is nonzero 61 | */ 62 | #define ALLOW_DEPRECATED_FUNCTIONS 1 63 | //------------------------------------------------------------------------------ 64 | /** 65 | * Allow FAT12 volumes if FAT12_SUPPORT is nonzero. 66 | * FAT12 has not been well tested. 67 | */ 68 | #define FAT12_SUPPORT 0 69 | //------------------------------------------------------------------------------ 70 | /** 71 | * SPI init rate for SD initialization commands. Must be 5 (F_CPU/64) 72 | * or 6 (F_CPU/128). 73 | */ 74 | #define SPI_SD_INIT_RATE 5 75 | //------------------------------------------------------------------------------ 76 | /** 77 | * Set the SS pin high for hardware SPI. If SS is chip select for another SPI 78 | * device this will disable that device during the SD init phase. 79 | */ 80 | #define SET_SPI_SS_HIGH 1 81 | //------------------------------------------------------------------------------ 82 | /** 83 | * Define MEGA_SOFT_SPI nonzero to use software SPI on Mega Arduinos. 84 | * Pins used are SS 10, MOSI 11, MISO 12, and SCK 13. 85 | * 86 | * MEGA_SOFT_SPI allows an unmodified Adafruit GPS Shield to be used 87 | * on Mega Arduinos. Software SPI works well with GPS Shield V1.1 88 | * but many SD cards will fail with GPS Shield V1.0. 89 | */ 90 | #define MEGA_SOFT_SPI 0 91 | //------------------------------------------------------------------------------ 92 | /** 93 | * Set USE_SOFTWARE_SPI nonzero to always use software SPI. 94 | */ 95 | #define USE_SOFTWARE_SPI 0 96 | // define software SPI pins so Mega can use unmodified 168/328 shields 97 | /** Software SPI chip select pin for the SD */ 98 | uint8_t const SOFT_SPI_CS_PIN = 10; 99 | /** Software SPI Master Out Slave In pin */ 100 | uint8_t const SOFT_SPI_MOSI_PIN = 11; 101 | /** Software SPI Master In Slave Out pin */ 102 | uint8_t const SOFT_SPI_MISO_PIN = 12; 103 | /** Software SPI Clock pin */ 104 | uint8_t const SOFT_SPI_SCK_PIN = 13; 105 | //------------------------------------------------------------------------------ 106 | /** 107 | * The __cxa_pure_virtual function is an error handler that is invoked when 108 | * a pure virtual function is called. 109 | */ 110 | #define USE_CXA_PURE_VIRTUAL 1 111 | /** 112 | * Defines for long (vfat) filenames 113 | */ 114 | /** Number of VFAT entries used. Every entry has 13 UTF-16 characters */ 115 | #define MAX_VFAT_ENTRIES (2) 116 | /** Total size of the buffer used to store the long filenames */ 117 | #define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1) 118 | #endif // SdFatConfig_h 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/SdFatConfig.h: -------------------------------------------------------------------------------- 1 | /* Arduino SdFat Library 2 | * Copyright (C) 2009 by William Greiman 3 | * 4 | * This file is part of the Arduino SdFat Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino SdFat Library. If not, see 18 | * . 19 | */ 20 | /** 21 | * \file 22 | * \brief configuration definitions 23 | */ 24 | #include "Marlin.h" 25 | #ifdef SDSUPPORT 26 | 27 | #ifndef SdFatConfig_h 28 | #define SdFatConfig_h 29 | #include 30 | //------------------------------------------------------------------------------ 31 | /** 32 | * To use multiple SD cards set USE_MULTIPLE_CARDS nonzero. 33 | * 34 | * Using multiple cards costs 400 - 500 bytes of flash. 35 | * 36 | * Each card requires about 550 bytes of SRAM so use of a Mega is recommended. 37 | */ 38 | #define USE_MULTIPLE_CARDS 0 39 | //------------------------------------------------------------------------------ 40 | /** 41 | * Call flush for endl if ENDL_CALLS_FLUSH is nonzero 42 | * 43 | * The standard for iostreams is to call flush. This is very costly for 44 | * SdFat. Each call to flush causes 2048 bytes of I/O to the SD. 45 | * 46 | * SdFat has a single 512 byte buffer for SD I/O so it must write the current 47 | * data block to the SD, read the directory block from the SD, update the 48 | * directory entry, write the directory block to the SD and read the data 49 | * block back into the buffer. 50 | * 51 | * The SD flash memory controller is not designed for this many rewrites 52 | * so performance may be reduced by more than a factor of 100. 53 | * 54 | * If ENDL_CALLS_FLUSH is zero, you must call flush and/or close to force 55 | * all data to be written to the SD. 56 | */ 57 | #define ENDL_CALLS_FLUSH 0 58 | //------------------------------------------------------------------------------ 59 | /** 60 | * Allow use of deprecated functions if ALLOW_DEPRECATED_FUNCTIONS is nonzero 61 | */ 62 | #define ALLOW_DEPRECATED_FUNCTIONS 1 63 | //------------------------------------------------------------------------------ 64 | /** 65 | * Allow FAT12 volumes if FAT12_SUPPORT is nonzero. 66 | * FAT12 has not been well tested. 67 | */ 68 | #define FAT12_SUPPORT 0 69 | //------------------------------------------------------------------------------ 70 | /** 71 | * SPI init rate for SD initialization commands. Must be 5 (F_CPU/64) 72 | * or 6 (F_CPU/128). 73 | */ 74 | #define SPI_SD_INIT_RATE 5 75 | //------------------------------------------------------------------------------ 76 | /** 77 | * Set the SS pin high for hardware SPI. If SS is chip select for another SPI 78 | * device this will disable that device during the SD init phase. 79 | */ 80 | #define SET_SPI_SS_HIGH 1 81 | //------------------------------------------------------------------------------ 82 | /** 83 | * Define MEGA_SOFT_SPI nonzero to use software SPI on Mega Arduinos. 84 | * Pins used are SS 10, MOSI 11, MISO 12, and SCK 13. 85 | * 86 | * MEGA_SOFT_SPI allows an unmodified Adafruit GPS Shield to be used 87 | * on Mega Arduinos. Software SPI works well with GPS Shield V1.1 88 | * but many SD cards will fail with GPS Shield V1.0. 89 | */ 90 | #define MEGA_SOFT_SPI 0 91 | //------------------------------------------------------------------------------ 92 | /** 93 | * Set USE_SOFTWARE_SPI nonzero to always use software SPI. 94 | */ 95 | #define USE_SOFTWARE_SPI 0 96 | // define software SPI pins so Mega can use unmodified 168/328 shields 97 | /** Software SPI chip select pin for the SD */ 98 | uint8_t const SOFT_SPI_CS_PIN = 10; 99 | /** Software SPI Master Out Slave In pin */ 100 | uint8_t const SOFT_SPI_MOSI_PIN = 11; 101 | /** Software SPI Master In Slave Out pin */ 102 | uint8_t const SOFT_SPI_MISO_PIN = 12; 103 | /** Software SPI Clock pin */ 104 | uint8_t const SOFT_SPI_SCK_PIN = 13; 105 | //------------------------------------------------------------------------------ 106 | /** 107 | * The __cxa_pure_virtual function is an error handler that is invoked when 108 | * a pure virtual function is called. 109 | */ 110 | #define USE_CXA_PURE_VIRTUAL 1 111 | /** 112 | * Defines for long (vfat) filenames 113 | */ 114 | /** Number of VFAT entries used. Every entry has 13 UTF-16 characters */ 115 | #define MAX_VFAT_ENTRIES (2) 116 | /** Total size of the buffer used to store the long filenames */ 117 | #define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1) 118 | #endif // SdFatConfig_h 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef stepper_h 22 | #define stepper_h 23 | 24 | #include "planner.h" 25 | 26 | #if EXTRUDERS > 2 27 | #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { WRITE(E2_STEP_PIN, v); } else { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}} 28 | #define NORM_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, !INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}} 29 | #define REV_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}} 30 | #elif EXTRUDERS > 1 31 | #ifndef DUAL_X_CARRIAGE 32 | #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }} 33 | #define NORM_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }} 34 | #define REV_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }} 35 | #else 36 | extern bool extruder_duplication_enabled; 37 | #define WRITE_E_STEP(v) { if(extruder_duplication_enabled) { WRITE(E0_STEP_PIN, v); WRITE(E1_STEP_PIN, v); } else if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }} 38 | #define NORM_E_DIR() { if(extruder_duplication_enabled) { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }} 39 | #define REV_E_DIR() { if(extruder_duplication_enabled) { WRITE(E0_DIR_PIN, INVERT_E0_DIR); WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }} 40 | #endif 41 | #else 42 | #define WRITE_E_STEP(v) WRITE(E0_STEP_PIN, v) 43 | #define NORM_E_DIR() WRITE(E0_DIR_PIN, !INVERT_E0_DIR) 44 | #define REV_E_DIR() WRITE(E0_DIR_PIN, INVERT_E0_DIR) 45 | #endif 46 | 47 | #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED 48 | extern bool abort_on_endstop_hit; 49 | #endif 50 | 51 | // Initialize and start the stepper motor subsystem 52 | void st_init(); 53 | 54 | // Block until all buffered steps are executed 55 | void st_synchronize(); 56 | 57 | // Set current position in steps 58 | void st_set_position(const long &x, const long &y, const long &z, const long &e); 59 | void st_set_e_position(const long &e); 60 | 61 | // Get current position in steps 62 | long st_get_position(uint8_t axis); 63 | 64 | #ifdef ENABLE_AUTO_BED_LEVELING 65 | // Get current position in mm 66 | float st_get_position_mm(uint8_t axis); 67 | #endif //ENABLE_AUTO_BED_LEVELING 68 | 69 | // The stepper subsystem goes to sleep when it runs out of things to execute. Call this 70 | // to notify the subsystem that it is time to go to work. 71 | void st_wake_up(); 72 | 73 | 74 | void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered 75 | void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops(); 76 | 77 | void enable_endstops(bool check); // Enable/disable endstop checking 78 | 79 | void checkStepperErrors(); //Print errors detected by the stepper 80 | 81 | void finishAndDisableSteppers(); 82 | 83 | extern block_t *current_block; // A pointer to the block currently being traced 84 | 85 | void quickStop(); 86 | 87 | void digitalPotWrite(int address, int value); 88 | void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2); 89 | void microstep_mode(uint8_t driver, uint8_t stepping); 90 | void digipot_init(); 91 | void digipot_current(uint8_t driver, int current); 92 | void microstep_init(); 93 | void microstep_readings(); 94 | 95 | #ifdef BABYSTEPPING 96 | void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention 97 | #endif 98 | 99 | 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef stepper_h 22 | #define stepper_h 23 | 24 | #include "planner.h" 25 | 26 | #if EXTRUDERS > 2 27 | #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { WRITE(E2_STEP_PIN, v); } else { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}} 28 | #define NORM_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, !INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}} 29 | #define REV_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}} 30 | #elif EXTRUDERS > 1 31 | #ifndef DUAL_X_CARRIAGE 32 | #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }} 33 | #define NORM_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }} 34 | #define REV_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }} 35 | #else 36 | extern bool extruder_duplication_enabled; 37 | #define WRITE_E_STEP(v) { if(extruder_duplication_enabled) { WRITE(E0_STEP_PIN, v); WRITE(E1_STEP_PIN, v); } else if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }} 38 | #define NORM_E_DIR() { if(extruder_duplication_enabled) { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }} 39 | #define REV_E_DIR() { if(extruder_duplication_enabled) { WRITE(E0_DIR_PIN, INVERT_E0_DIR); WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }} 40 | #endif 41 | #else 42 | #define WRITE_E_STEP(v) WRITE(E0_STEP_PIN, v) 43 | #define NORM_E_DIR() WRITE(E0_DIR_PIN, !INVERT_E0_DIR) 44 | #define REV_E_DIR() WRITE(E0_DIR_PIN, INVERT_E0_DIR) 45 | #endif 46 | 47 | #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED 48 | extern bool abort_on_endstop_hit; 49 | #endif 50 | 51 | // Initialize and start the stepper motor subsystem 52 | void st_init(); 53 | 54 | // Block until all buffered steps are executed 55 | void st_synchronize(); 56 | 57 | // Set current position in steps 58 | void st_set_position(const long &x, const long &y, const long &z, const long &e); 59 | void st_set_e_position(const long &e); 60 | 61 | // Get current position in steps 62 | long st_get_position(uint8_t axis); 63 | 64 | #ifdef ENABLE_AUTO_BED_LEVELING 65 | // Get current position in mm 66 | float st_get_position_mm(uint8_t axis); 67 | #endif //ENABLE_AUTO_BED_LEVELING 68 | 69 | // The stepper subsystem goes to sleep when it runs out of things to execute. Call this 70 | // to notify the subsystem that it is time to go to work. 71 | void st_wake_up(); 72 | 73 | 74 | void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered 75 | void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops(); 76 | 77 | void enable_endstops(bool check); // Enable/disable endstop checking 78 | 79 | void checkStepperErrors(); //Print errors detected by the stepper 80 | 81 | void finishAndDisableSteppers(); 82 | 83 | extern block_t *current_block; // A pointer to the block currently being traced 84 | 85 | void quickStop(); 86 | 87 | void digitalPotWrite(int address, int value); 88 | void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2); 89 | void microstep_mode(uint8_t driver, uint8_t stepping); 90 | void digipot_init(); 91 | void digipot_current(uint8_t driver, int current); 92 | void microstep_init(); 93 | void microstep_readings(); 94 | 95 | #ifdef BABYSTEPPING 96 | void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention 97 | #endif 98 | 99 | 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/vector_3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | vector_3.cpp - Vector library for bed leveling 3 | Copyright (c) 2012 Lars Brubaker. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #include 20 | #include "Marlin.h" 21 | 22 | #ifdef ENABLE_AUTO_BED_LEVELING 23 | #include "vector_3.h" 24 | 25 | vector_3::vector_3() : x(0), y(0), z(0) { } 26 | 27 | vector_3::vector_3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { } 28 | 29 | vector_3 vector_3::cross(vector_3 left, vector_3 right) 30 | { 31 | return vector_3(left.y * right.z - left.z * right.y, 32 | left.z * right.x - left.x * right.z, 33 | left.x * right.y - left.y * right.x); 34 | } 35 | 36 | vector_3 vector_3::operator+(vector_3 v) 37 | { 38 | return vector_3((x + v.x), (y + v.y), (z + v.z)); 39 | } 40 | 41 | vector_3 vector_3::operator-(vector_3 v) 42 | { 43 | return vector_3((x - v.x), (y - v.y), (z - v.z)); 44 | } 45 | 46 | vector_3 vector_3::get_normal() 47 | { 48 | vector_3 normalized = vector_3(x, y, z); 49 | normalized.normalize(); 50 | return normalized; 51 | } 52 | 53 | float vector_3::get_length() 54 | { 55 | float length = sqrt((x * x) + (y * y) + (z * z)); 56 | return length; 57 | } 58 | 59 | void vector_3::normalize() 60 | { 61 | float length = get_length(); 62 | x /= length; 63 | y /= length; 64 | z /= length; 65 | } 66 | 67 | void vector_3::apply_rotation(matrix_3x3 matrix) 68 | { 69 | float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0]; 70 | float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1]; 71 | float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2]; 72 | 73 | x = resultX; 74 | y = resultY; 75 | z = resultZ; 76 | } 77 | 78 | void vector_3::debug(char* title) 79 | { 80 | SERIAL_PROTOCOL(title); 81 | SERIAL_PROTOCOLPGM(" x: "); 82 | SERIAL_PROTOCOL(x); 83 | SERIAL_PROTOCOLPGM(" y: "); 84 | SERIAL_PROTOCOL(y); 85 | SERIAL_PROTOCOLPGM(" z: "); 86 | SERIAL_PROTOCOL(z); 87 | SERIAL_PROTOCOLPGM("\n"); 88 | } 89 | 90 | void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z) 91 | { 92 | vector_3 vector = vector_3(x, y, z); 93 | vector.apply_rotation(matrix); 94 | x = vector.x; 95 | y = vector.y; 96 | z = vector.z; 97 | } 98 | 99 | matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2) 100 | { 101 | //row_0.debug("row_0"); 102 | //row_1.debug("row_1"); 103 | //row_2.debug("row_2"); 104 | matrix_3x3 new_matrix; 105 | new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; 106 | new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; 107 | new_matrix.matrix[6] = row_2.x; new_matrix.matrix[7] = row_2.y; new_matrix.matrix[8] = row_2.z; 108 | //new_matrix.debug("new_matrix"); 109 | 110 | return new_matrix; 111 | } 112 | 113 | void matrix_3x3::set_to_identity() 114 | { 115 | matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; 116 | matrix[3] = 0; matrix[4] = 1; matrix[5] = 0; 117 | matrix[6] = 0; matrix[7] = 0; matrix[8] = 1; 118 | } 119 | 120 | matrix_3x3 matrix_3x3::create_look_at(vector_3 target) 121 | { 122 | vector_3 z_row = target.get_normal(); 123 | vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal(); 124 | vector_3 y_row = vector_3::cross(z_row, x_row).get_normal(); 125 | 126 | // x_row.debug("x_row"); 127 | // y_row.debug("y_row"); 128 | // z_row.debug("z_row"); 129 | 130 | 131 | // create the matrix already correctly transposed 132 | matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row); 133 | 134 | // rot.debug("rot"); 135 | return rot; 136 | } 137 | 138 | 139 | matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) 140 | { 141 | matrix_3x3 new_matrix; 142 | new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; 143 | new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; 144 | new_matrix.matrix[6] = original.matrix[2]; new_matrix.matrix[7] = original.matrix[5]; new_matrix.matrix[8] = original.matrix[8]; 145 | return new_matrix; 146 | } 147 | 148 | void matrix_3x3::debug(char* title) 149 | { 150 | SERIAL_PROTOCOL(title); 151 | SERIAL_PROTOCOL("\n"); 152 | int count = 0; 153 | for(int i=0; i<3; i++) 154 | { 155 | for(int j=0; j<3; j++) 156 | { 157 | SERIAL_PROTOCOL(matrix[count]); 158 | SERIAL_PROTOCOLPGM(" "); 159 | count++; 160 | } 161 | 162 | SERIAL_PROTOCOLPGM("\n"); 163 | } 164 | } 165 | 166 | #endif // #ifdef ENABLE_AUTO_BED_LEVELING 167 | 168 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/vector_3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | vector_3.cpp - Vector library for bed leveling 3 | Copyright (c) 2012 Lars Brubaker. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #include 20 | #include "Marlin.h" 21 | 22 | #ifdef ENABLE_AUTO_BED_LEVELING 23 | #include "vector_3.h" 24 | 25 | vector_3::vector_3() : x(0), y(0), z(0) { } 26 | 27 | vector_3::vector_3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { } 28 | 29 | vector_3 vector_3::cross(vector_3 left, vector_3 right) 30 | { 31 | return vector_3(left.y * right.z - left.z * right.y, 32 | left.z * right.x - left.x * right.z, 33 | left.x * right.y - left.y * right.x); 34 | } 35 | 36 | vector_3 vector_3::operator+(vector_3 v) 37 | { 38 | return vector_3((x + v.x), (y + v.y), (z + v.z)); 39 | } 40 | 41 | vector_3 vector_3::operator-(vector_3 v) 42 | { 43 | return vector_3((x - v.x), (y - v.y), (z - v.z)); 44 | } 45 | 46 | vector_3 vector_3::get_normal() 47 | { 48 | vector_3 normalized = vector_3(x, y, z); 49 | normalized.normalize(); 50 | return normalized; 51 | } 52 | 53 | float vector_3::get_length() 54 | { 55 | float length = sqrt((x * x) + (y * y) + (z * z)); 56 | return length; 57 | } 58 | 59 | void vector_3::normalize() 60 | { 61 | float length = get_length(); 62 | x /= length; 63 | y /= length; 64 | z /= length; 65 | } 66 | 67 | void vector_3::apply_rotation(matrix_3x3 matrix) 68 | { 69 | float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0]; 70 | float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1]; 71 | float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2]; 72 | 73 | x = resultX; 74 | y = resultY; 75 | z = resultZ; 76 | } 77 | 78 | void vector_3::debug(char* title) 79 | { 80 | SERIAL_PROTOCOL(title); 81 | SERIAL_PROTOCOLPGM(" x: "); 82 | SERIAL_PROTOCOL(x); 83 | SERIAL_PROTOCOLPGM(" y: "); 84 | SERIAL_PROTOCOL(y); 85 | SERIAL_PROTOCOLPGM(" z: "); 86 | SERIAL_PROTOCOL(z); 87 | SERIAL_PROTOCOLPGM("\n"); 88 | } 89 | 90 | void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z) 91 | { 92 | vector_3 vector = vector_3(x, y, z); 93 | vector.apply_rotation(matrix); 94 | x = vector.x; 95 | y = vector.y; 96 | z = vector.z; 97 | } 98 | 99 | matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2) 100 | { 101 | //row_0.debug("row_0"); 102 | //row_1.debug("row_1"); 103 | //row_2.debug("row_2"); 104 | matrix_3x3 new_matrix; 105 | new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; 106 | new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; 107 | new_matrix.matrix[6] = row_2.x; new_matrix.matrix[7] = row_2.y; new_matrix.matrix[8] = row_2.z; 108 | //new_matrix.debug("new_matrix"); 109 | 110 | return new_matrix; 111 | } 112 | 113 | void matrix_3x3::set_to_identity() 114 | { 115 | matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; 116 | matrix[3] = 0; matrix[4] = 1; matrix[5] = 0; 117 | matrix[6] = 0; matrix[7] = 0; matrix[8] = 1; 118 | } 119 | 120 | matrix_3x3 matrix_3x3::create_look_at(vector_3 target) 121 | { 122 | vector_3 z_row = target.get_normal(); 123 | vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal(); 124 | vector_3 y_row = vector_3::cross(z_row, x_row).get_normal(); 125 | 126 | // x_row.debug("x_row"); 127 | // y_row.debug("y_row"); 128 | // z_row.debug("z_row"); 129 | 130 | 131 | // create the matrix already correctly transposed 132 | matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row); 133 | 134 | // rot.debug("rot"); 135 | return rot; 136 | } 137 | 138 | 139 | matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) 140 | { 141 | matrix_3x3 new_matrix; 142 | new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; 143 | new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; 144 | new_matrix.matrix[6] = original.matrix[2]; new_matrix.matrix[7] = original.matrix[5]; new_matrix.matrix[8] = original.matrix[8]; 145 | return new_matrix; 146 | } 147 | 148 | void matrix_3x3::debug(char* title) 149 | { 150 | SERIAL_PROTOCOL(title); 151 | SERIAL_PROTOCOL("\n"); 152 | int count = 0; 153 | for(int i=0; i<3; i++) 154 | { 155 | for(int j=0; j<3; j++) 156 | { 157 | SERIAL_PROTOCOL(matrix[count]); 158 | SERIAL_PROTOCOLPGM(" "); 159 | count++; 160 | } 161 | 162 | SERIAL_PROTOCOLPGM("\n"); 163 | } 164 | } 165 | 166 | #endif // #ifdef ENABLE_AUTO_BED_LEVELING 167 | 168 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/temperature.h: -------------------------------------------------------------------------------- 1 | /* 2 | temperature.h - temperature controller 3 | Part of Marlin 4 | 5 | Copyright (c) 2011 Erik van der Zalm 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef temperature_h 22 | #define temperature_h 23 | 24 | #include "Marlin.h" 25 | #include "planner.h" 26 | #ifdef PID_ADD_EXTRUSION_RATE 27 | #include "stepper.h" 28 | #endif 29 | 30 | // public functions 31 | void tp_init(); //initialize the heating 32 | void manage_heater(); //it is critical that this is called periodically. 33 | 34 | #ifdef FILAMENT_SENSOR 35 | // For converting raw Filament Width to milimeters 36 | float analog2widthFil(); 37 | 38 | // For converting raw Filament Width to an extrusion ratio 39 | int widthFil_to_size_ratio(); 40 | #endif 41 | 42 | // low level conversion routines 43 | // do not use these routines and variables outside of temperature.cpp 44 | extern int target_temperature[EXTRUDERS]; 45 | extern float current_temperature[EXTRUDERS]; 46 | #ifdef SHOW_TEMP_ADC_VALUES 47 | extern int current_temperature_raw[EXTRUDERS]; 48 | extern int current_temperature_bed_raw; 49 | #endif 50 | extern int target_temperature_bed; 51 | extern float current_temperature_bed; 52 | #ifdef TEMP_SENSOR_1_AS_REDUNDANT 53 | extern float redundant_temperature; 54 | #endif 55 | 56 | #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 57 | extern unsigned char soft_pwm_bed; 58 | #endif 59 | 60 | #ifdef PIDTEMP 61 | extern float Kp,Ki,Kd,Kc; 62 | float scalePID_i(float i); 63 | float scalePID_d(float d); 64 | float unscalePID_i(float i); 65 | float unscalePID_d(float d); 66 | 67 | #endif 68 | #ifdef PIDTEMPBED 69 | extern float bedKp,bedKi,bedKd; 70 | #endif 71 | 72 | 73 | #ifdef BABYSTEPPING 74 | extern volatile int babystepsTodo[3]; 75 | #endif 76 | 77 | //high level conversion routines, for use outside of temperature.cpp 78 | //inline so that there is no performance decrease. 79 | //deg=degreeCelsius 80 | 81 | FORCE_INLINE float degHotend(uint8_t extruder) { 82 | return current_temperature[extruder]; 83 | }; 84 | 85 | #ifdef SHOW_TEMP_ADC_VALUES 86 | FORCE_INLINE float rawHotendTemp(uint8_t extruder) { 87 | return current_temperature_raw[extruder]; 88 | }; 89 | 90 | FORCE_INLINE float rawBedTemp() { 91 | return current_temperature_bed_raw; 92 | }; 93 | #endif 94 | 95 | FORCE_INLINE float degBed() { 96 | return current_temperature_bed; 97 | }; 98 | 99 | FORCE_INLINE float degTargetHotend(uint8_t extruder) { 100 | return target_temperature[extruder]; 101 | }; 102 | 103 | FORCE_INLINE float degTargetBed() { 104 | return target_temperature_bed; 105 | }; 106 | 107 | FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { 108 | target_temperature[extruder] = celsius; 109 | }; 110 | 111 | FORCE_INLINE void setTargetBed(const float &celsius) { 112 | target_temperature_bed = celsius; 113 | }; 114 | 115 | FORCE_INLINE bool isHeatingHotend(uint8_t extruder){ 116 | return target_temperature[extruder] > current_temperature[extruder]; 117 | }; 118 | 119 | FORCE_INLINE bool isHeatingBed() { 120 | return target_temperature_bed > current_temperature_bed; 121 | }; 122 | 123 | FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { 124 | return target_temperature[extruder] < current_temperature[extruder]; 125 | }; 126 | 127 | FORCE_INLINE bool isCoolingBed() { 128 | return target_temperature_bed < current_temperature_bed; 129 | }; 130 | 131 | #define degHotend0() degHotend(0) 132 | #define degTargetHotend0() degTargetHotend(0) 133 | #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0) 134 | #define isHeatingHotend0() isHeatingHotend(0) 135 | #define isCoolingHotend0() isCoolingHotend(0) 136 | #if EXTRUDERS > 1 137 | #define degHotend1() degHotend(1) 138 | #define degTargetHotend1() degTargetHotend(1) 139 | #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1) 140 | #define isHeatingHotend1() isHeatingHotend(1) 141 | #define isCoolingHotend1() isCoolingHotend(1) 142 | #else 143 | #define setTargetHotend1(_celsius) do{}while(0) 144 | #endif 145 | #if EXTRUDERS > 2 146 | #define degHotend2() degHotend(2) 147 | #define degTargetHotend2() degTargetHotend(2) 148 | #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2) 149 | #define isHeatingHotend2() isHeatingHotend(2) 150 | #define isCoolingHotend2() isCoolingHotend(2) 151 | #else 152 | #define setTargetHotend2(_celsius) do{}while(0) 153 | #endif 154 | #if EXTRUDERS > 3 155 | #error Invalid number of extruders 156 | #endif 157 | 158 | 159 | 160 | int getHeaterPower(int heater); 161 | void disable_heater(); 162 | void setWatch(); 163 | void updatePID(); 164 | 165 | #ifdef THERMAL_RUNAWAY_PROTECTION_PERIOD && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 166 | void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc); 167 | static int thermal_runaway_state_machine[3]; // = {0,0,0}; 168 | static unsigned long thermal_runaway_timer[3]; // = {0,0,0}; 169 | static bool thermal_runaway = false; 170 | #if TEMP_SENSOR_BED != 0 171 | static int thermal_runaway_bed_state_machine; 172 | static unsigned long thermal_runaway_bed_timer; 173 | #endif 174 | #endif 175 | 176 | FORCE_INLINE void autotempShutdown(){ 177 | #ifdef AUTOTEMP 178 | if(autotemp_enabled) 179 | { 180 | autotemp_enabled=false; 181 | if(degTargetHotend(active_extruder)>autotemp_min) 182 | setTargetHotend(0,active_extruder); 183 | } 184 | #endif 185 | } 186 | 187 | void PID_autotune(float temp, int extruder, int ncycles); 188 | 189 | #endif 190 | 191 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/temperature.h: -------------------------------------------------------------------------------- 1 | /* 2 | temperature.h - temperature controller 3 | Part of Marlin 4 | 5 | Copyright (c) 2011 Erik van der Zalm 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef temperature_h 22 | #define temperature_h 23 | 24 | #include "Marlin.h" 25 | #include "planner.h" 26 | #ifdef PID_ADD_EXTRUSION_RATE 27 | #include "stepper.h" 28 | #endif 29 | 30 | // public functions 31 | void tp_init(); //initialize the heating 32 | void manage_heater(); //it is critical that this is called periodically. 33 | 34 | #ifdef FILAMENT_SENSOR 35 | // For converting raw Filament Width to milimeters 36 | float analog2widthFil(); 37 | 38 | // For converting raw Filament Width to an extrusion ratio 39 | int widthFil_to_size_ratio(); 40 | #endif 41 | 42 | // low level conversion routines 43 | // do not use these routines and variables outside of temperature.cpp 44 | extern int target_temperature[EXTRUDERS]; 45 | extern float current_temperature[EXTRUDERS]; 46 | #ifdef SHOW_TEMP_ADC_VALUES 47 | extern int current_temperature_raw[EXTRUDERS]; 48 | extern int current_temperature_bed_raw; 49 | #endif 50 | extern int target_temperature_bed; 51 | extern float current_temperature_bed; 52 | #ifdef TEMP_SENSOR_1_AS_REDUNDANT 53 | extern float redundant_temperature; 54 | #endif 55 | 56 | #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 57 | extern unsigned char soft_pwm_bed; 58 | #endif 59 | 60 | #ifdef PIDTEMP 61 | extern float Kp,Ki,Kd,Kc; 62 | float scalePID_i(float i); 63 | float scalePID_d(float d); 64 | float unscalePID_i(float i); 65 | float unscalePID_d(float d); 66 | 67 | #endif 68 | #ifdef PIDTEMPBED 69 | extern float bedKp,bedKi,bedKd; 70 | #endif 71 | 72 | 73 | #ifdef BABYSTEPPING 74 | extern volatile int babystepsTodo[3]; 75 | #endif 76 | 77 | //high level conversion routines, for use outside of temperature.cpp 78 | //inline so that there is no performance decrease. 79 | //deg=degreeCelsius 80 | 81 | FORCE_INLINE float degHotend(uint8_t extruder) { 82 | return current_temperature[extruder]; 83 | }; 84 | 85 | #ifdef SHOW_TEMP_ADC_VALUES 86 | FORCE_INLINE float rawHotendTemp(uint8_t extruder) { 87 | return current_temperature_raw[extruder]; 88 | }; 89 | 90 | FORCE_INLINE float rawBedTemp() { 91 | return current_temperature_bed_raw; 92 | }; 93 | #endif 94 | 95 | FORCE_INLINE float degBed() { 96 | return current_temperature_bed; 97 | }; 98 | 99 | FORCE_INLINE float degTargetHotend(uint8_t extruder) { 100 | return target_temperature[extruder]; 101 | }; 102 | 103 | FORCE_INLINE float degTargetBed() { 104 | return target_temperature_bed; 105 | }; 106 | 107 | FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { 108 | target_temperature[extruder] = celsius; 109 | }; 110 | 111 | FORCE_INLINE void setTargetBed(const float &celsius) { 112 | target_temperature_bed = celsius; 113 | }; 114 | 115 | FORCE_INLINE bool isHeatingHotend(uint8_t extruder){ 116 | return target_temperature[extruder] > current_temperature[extruder]; 117 | }; 118 | 119 | FORCE_INLINE bool isHeatingBed() { 120 | return target_temperature_bed > current_temperature_bed; 121 | }; 122 | 123 | FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { 124 | return target_temperature[extruder] < current_temperature[extruder]; 125 | }; 126 | 127 | FORCE_INLINE bool isCoolingBed() { 128 | return target_temperature_bed < current_temperature_bed; 129 | }; 130 | 131 | #define degHotend0() degHotend(0) 132 | #define degTargetHotend0() degTargetHotend(0) 133 | #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0) 134 | #define isHeatingHotend0() isHeatingHotend(0) 135 | #define isCoolingHotend0() isCoolingHotend(0) 136 | #if EXTRUDERS > 1 137 | #define degHotend1() degHotend(1) 138 | #define degTargetHotend1() degTargetHotend(1) 139 | #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1) 140 | #define isHeatingHotend1() isHeatingHotend(1) 141 | #define isCoolingHotend1() isCoolingHotend(1) 142 | #else 143 | #define setTargetHotend1(_celsius) do{}while(0) 144 | #endif 145 | #if EXTRUDERS > 2 146 | #define degHotend2() degHotend(2) 147 | #define degTargetHotend2() degTargetHotend(2) 148 | #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2) 149 | #define isHeatingHotend2() isHeatingHotend(2) 150 | #define isCoolingHotend2() isCoolingHotend(2) 151 | #else 152 | #define setTargetHotend2(_celsius) do{}while(0) 153 | #endif 154 | #if EXTRUDERS > 3 155 | #error Invalid number of extruders 156 | #endif 157 | 158 | 159 | 160 | int getHeaterPower(int heater); 161 | void disable_heater(); 162 | void setWatch(); 163 | void updatePID(); 164 | 165 | #ifdef THERMAL_RUNAWAY_PROTECTION_PERIOD && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 166 | void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc); 167 | static int thermal_runaway_state_machine[3]; // = {0,0,0}; 168 | static unsigned long thermal_runaway_timer[3]; // = {0,0,0}; 169 | static bool thermal_runaway = false; 170 | #if TEMP_SENSOR_BED != 0 171 | static int thermal_runaway_bed_state_machine; 172 | static unsigned long thermal_runaway_bed_timer; 173 | #endif 174 | #endif 175 | 176 | FORCE_INLINE void autotempShutdown(){ 177 | #ifdef AUTOTEMP 178 | if(autotemp_enabled) 179 | { 180 | autotemp_enabled=false; 181 | if(degTargetHotend(active_extruder)>autotemp_min) 182 | setTargetHotend(0,active_extruder); 183 | } 184 | #endif 185 | } 186 | 187 | void PID_autotune(float temp, int extruder, int ncycles); 188 | 189 | #endif 190 | 191 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/createTemperatureLookupMarlin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Creates a C code lookup table for doing ADC to temperature conversion 4 | # on a microcontroller 5 | # based on: http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html 6 | """Thermistor Value Lookup Table Generator 7 | 8 | Generates lookup to temperature values for use in a microcontroller in C format based on: 9 | http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html 10 | 11 | The main use is for Arduino programs that read data from the circuit board described here: 12 | http://make.rrrf.org/ts-1.0 13 | 14 | Usage: python createTemperatureLookup.py [options] 15 | 16 | Options: 17 | -h, --help show this help 18 | --rp=... pull-up resistor 19 | --t1=ttt:rrr low temperature temperature:resistance point (around 25C) 20 | --t2=ttt:rrr middle temperature temperature:resistance point (around 150C) 21 | --t3=ttt:rrr high temperature temperature:resistance point (around 250C) 22 | --num-temps=... the number of temperature points to calculate (default: 20) 23 | """ 24 | 25 | from math import * 26 | import sys 27 | import getopt 28 | 29 | class Thermistor: 30 | "Class to do the thermistor maths" 31 | def __init__(self, rp, t1, r1, t2, r2, t3, r3): 32 | t1 = t1 + 273.15 # low temperature (25C) 33 | r1 = r1 # resistance at low temperature 34 | t2 = t2 + 273.15 # middle temperature (150C) 35 | r2 = r2 # resistance at middle temperature 36 | t3 = t3 + 273.15 # high temperature (250C) 37 | r3 = r3 # resistance at high temperature 38 | self.rp = rp # pull-up resistance 39 | self.vadc = 5.0 # ADC reference 40 | self.vcc = 5.0 # supply voltage to potential divider 41 | a1 = log(r1) 42 | a2 = log(r2) 43 | a3 = log(r3) 44 | z = a1 - a2 45 | y = a1 - a3 46 | x = 1/t1 - 1/t2 47 | w = 1/t1 - 1/t3 48 | v = pow(a1,3) - pow(a2,3) 49 | u = pow(a1,3) - pow(a3,3) 50 | c3 = (x-z*w/y)/(v-z*u/y) 51 | c2 = (x-c3*v)/z 52 | c1 = 1/t1-c3*pow(a1,3)-c2*a1 53 | self.c1 = c1 54 | self.c2 = c2 55 | self.c3 = c3 56 | 57 | def res(self,adc): 58 | "Convert ADC reading into a resolution" 59 | res = self.temp(adc)-self.temp(adc+1) 60 | return res 61 | 62 | def v(self,adc): 63 | "Convert ADC reading into a Voltage" 64 | v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage 65 | return v 66 | 67 | def r(self,adc): 68 | "Convert ADC reading into a resistance in Ohms" 69 | v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage 70 | r = self.rp * v / (self.vcc - v) # resistance of thermistor 71 | return r 72 | 73 | def temp(self,adc): 74 | "Convert ADC reading into a temperature in Celcius" 75 | v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage 76 | r = self.rp * v / (self.vcc - v) # resistance of thermistor 77 | lnr = log(r) 78 | Tinv = self.c1 + (self.c2*lnr) + (self.c3*pow(lnr,3)) 79 | return (1/Tinv) - 273.15 # temperature 80 | 81 | def adc(self,temp): 82 | "Convert temperature into a ADC reading" 83 | y = (self.c1 - (1/(temp+273.15))) / (2*self.c3) 84 | x = sqrt(pow(self.c2 / (3*self.c3),3) + pow(y,2)) 85 | r = exp(pow(x-y,1.0/3) - pow(x+y,1.0/3)) # resistance of thermistor 86 | return (r / (self.rp + r)) * (1024) 87 | 88 | def main(argv): 89 | 90 | rp = 4700; 91 | t1 = 25; 92 | r1 = 100000; 93 | t2 = 150; 94 | r2 = 1641.9; 95 | t3 = 250; 96 | r3 = 226.15; 97 | num_temps = int(36); 98 | 99 | try: 100 | opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="]) 101 | except getopt.GetoptError as err: 102 | print str(err) 103 | usage() 104 | sys.exit(2) 105 | 106 | for opt, arg in opts: 107 | if opt in ("-h", "--help"): 108 | usage() 109 | sys.exit() 110 | elif opt == "--rp": 111 | rp = int(arg) 112 | elif opt == "--t1": 113 | arg = arg.split(':') 114 | t1 = float( arg[0]) 115 | r1 = float( arg[1]) 116 | elif opt == "--t2": 117 | arg = arg.split(':') 118 | t2 = float( arg[0]) 119 | r2 = float( arg[1]) 120 | elif opt == "--t3": 121 | arg = arg.split(':') 122 | t3 = float( arg[0]) 123 | r3 = float( arg[1]) 124 | elif opt == "--num-temps": 125 | num_temps = int(arg) 126 | 127 | max_adc = (1024 ) - 1 128 | min_temp = 0 129 | max_temp = 350 130 | increment = int(max_adc/(num_temps-1)); 131 | 132 | t = Thermistor(rp, t1, r1, t2, r2, t3, r3) 133 | tmp = (min_temp - max_temp) / (num_temps-1) 134 | print tmp 135 | temps = range(max_temp, min_temp + tmp, tmp); 136 | 137 | print "// Thermistor lookup table for Marlin" 138 | print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) 139 | print "// Steinhart-Hart Coefficients: %.15g, %.15g, %.15g " % (t.c1, t.c2, t.c3) 140 | print "//#define NUMTEMPS %s" % (len(temps)) 141 | print "const short temptable[NUMTEMPS][2] PROGMEM = {" 142 | 143 | counter = 0 144 | for temp in temps: 145 | counter = counter +1 146 | if counter == len(temps): 147 | print " {(short)(%.2f*OVERSAMPLENR), %s} // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) 148 | else: 149 | print " {(short)(%.2f*OVERSAMPLENR), %s}, // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) 150 | print "};" 151 | 152 | def usage(): 153 | print __doc__ 154 | 155 | if __name__ == "__main__": 156 | main(sys.argv[1:]) 157 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/createTemperatureLookupMarlin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Creates a C code lookup table for doing ADC to temperature conversion 4 | # on a microcontroller 5 | # based on: http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html 6 | """Thermistor Value Lookup Table Generator 7 | 8 | Generates lookup to temperature values for use in a microcontroller in C format based on: 9 | http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html 10 | 11 | The main use is for Arduino programs that read data from the circuit board described here: 12 | http://make.rrrf.org/ts-1.0 13 | 14 | Usage: python createTemperatureLookup.py [options] 15 | 16 | Options: 17 | -h, --help show this help 18 | --rp=... pull-up resistor 19 | --t1=ttt:rrr low temperature temperature:resistance point (around 25C) 20 | --t2=ttt:rrr middle temperature temperature:resistance point (around 150C) 21 | --t3=ttt:rrr high temperature temperature:resistance point (around 250C) 22 | --num-temps=... the number of temperature points to calculate (default: 20) 23 | """ 24 | 25 | from math import * 26 | import sys 27 | import getopt 28 | 29 | class Thermistor: 30 | "Class to do the thermistor maths" 31 | def __init__(self, rp, t1, r1, t2, r2, t3, r3): 32 | t1 = t1 + 273.15 # low temperature (25C) 33 | r1 = r1 # resistance at low temperature 34 | t2 = t2 + 273.15 # middle temperature (150C) 35 | r2 = r2 # resistance at middle temperature 36 | t3 = t3 + 273.15 # high temperature (250C) 37 | r3 = r3 # resistance at high temperature 38 | self.rp = rp # pull-up resistance 39 | self.vadc = 5.0 # ADC reference 40 | self.vcc = 5.0 # supply voltage to potential divider 41 | a1 = log(r1) 42 | a2 = log(r2) 43 | a3 = log(r3) 44 | z = a1 - a2 45 | y = a1 - a3 46 | x = 1/t1 - 1/t2 47 | w = 1/t1 - 1/t3 48 | v = pow(a1,3) - pow(a2,3) 49 | u = pow(a1,3) - pow(a3,3) 50 | c3 = (x-z*w/y)/(v-z*u/y) 51 | c2 = (x-c3*v)/z 52 | c1 = 1/t1-c3*pow(a1,3)-c2*a1 53 | self.c1 = c1 54 | self.c2 = c2 55 | self.c3 = c3 56 | 57 | def res(self,adc): 58 | "Convert ADC reading into a resolution" 59 | res = self.temp(adc)-self.temp(adc+1) 60 | return res 61 | 62 | def v(self,adc): 63 | "Convert ADC reading into a Voltage" 64 | v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage 65 | return v 66 | 67 | def r(self,adc): 68 | "Convert ADC reading into a resistance in Ohms" 69 | v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage 70 | r = self.rp * v / (self.vcc - v) # resistance of thermistor 71 | return r 72 | 73 | def temp(self,adc): 74 | "Convert ADC reading into a temperature in Celcius" 75 | v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage 76 | r = self.rp * v / (self.vcc - v) # resistance of thermistor 77 | lnr = log(r) 78 | Tinv = self.c1 + (self.c2*lnr) + (self.c3*pow(lnr,3)) 79 | return (1/Tinv) - 273.15 # temperature 80 | 81 | def adc(self,temp): 82 | "Convert temperature into a ADC reading" 83 | y = (self.c1 - (1/(temp+273.15))) / (2*self.c3) 84 | x = sqrt(pow(self.c2 / (3*self.c3),3) + pow(y,2)) 85 | r = exp(pow(x-y,1.0/3) - pow(x+y,1.0/3)) # resistance of thermistor 86 | return (r / (self.rp + r)) * (1024) 87 | 88 | def main(argv): 89 | 90 | rp = 4700; 91 | t1 = 25; 92 | r1 = 100000; 93 | t2 = 150; 94 | r2 = 1641.9; 95 | t3 = 250; 96 | r3 = 226.15; 97 | num_temps = int(36); 98 | 99 | try: 100 | opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="]) 101 | except getopt.GetoptError as err: 102 | print str(err) 103 | usage() 104 | sys.exit(2) 105 | 106 | for opt, arg in opts: 107 | if opt in ("-h", "--help"): 108 | usage() 109 | sys.exit() 110 | elif opt == "--rp": 111 | rp = int(arg) 112 | elif opt == "--t1": 113 | arg = arg.split(':') 114 | t1 = float( arg[0]) 115 | r1 = float( arg[1]) 116 | elif opt == "--t2": 117 | arg = arg.split(':') 118 | t2 = float( arg[0]) 119 | r2 = float( arg[1]) 120 | elif opt == "--t3": 121 | arg = arg.split(':') 122 | t3 = float( arg[0]) 123 | r3 = float( arg[1]) 124 | elif opt == "--num-temps": 125 | num_temps = int(arg) 126 | 127 | max_adc = (1024 ) - 1 128 | min_temp = 0 129 | max_temp = 350 130 | increment = int(max_adc/(num_temps-1)); 131 | 132 | t = Thermistor(rp, t1, r1, t2, r2, t3, r3) 133 | tmp = (min_temp - max_temp) / (num_temps-1) 134 | print tmp 135 | temps = range(max_temp, min_temp + tmp, tmp); 136 | 137 | print "// Thermistor lookup table for Marlin" 138 | print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) 139 | print "// Steinhart-Hart Coefficients: %.15g, %.15g, %.15g " % (t.c1, t.c2, t.c3) 140 | print "//#define NUMTEMPS %s" % (len(temps)) 141 | print "const short temptable[NUMTEMPS][2] PROGMEM = {" 142 | 143 | counter = 0 144 | for temp in temps: 145 | counter = counter +1 146 | if counter == len(temps): 147 | print " {(short)(%.2f*OVERSAMPLENR), %s} // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) 148 | else: 149 | print " {(short)(%.2f*OVERSAMPLENR), %s}, // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp))) 150 | print "};" 151 | 152 | def usage(): 153 | print __doc__ 154 | 155 | if __name__ == "__main__": 156 | main(sys.argv[1:]) 157 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/Servo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 3 | Copyright (c) 2009 Michael Margolis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /* 21 | 22 | A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. 23 | The servos are pulsed in the background using the value most recently written using the write() method 24 | 25 | Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. 26 | Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. 27 | The sequence used to seize timers is defined in timers.h 28 | 29 | The methods are: 30 | 31 | Servo - Class for manipulating servo motors connected to Arduino pins. 32 | 33 | attach(pin ) - Attaches a servo motor to an i/o pin. 34 | attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds 35 | default min is 544, max is 2400 36 | 37 | write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) 38 | writeMicroseconds() - Sets the servo pulse width in microseconds 39 | read() - Gets the last written servo pulse width as an angle between 0 and 180. 40 | readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) 41 | attached() - Returns true if there is a servo attached. 42 | detach() - Stops an attached servos from pulsing its i/o pin. 43 | */ 44 | 45 | #ifndef Servo_h 46 | #define Servo_h 47 | 48 | #include 49 | 50 | /* 51 | * Defines for 16 bit timers used with Servo library 52 | * 53 | * If _useTimerX is defined then TimerX is a 16 bit timer on the current board 54 | * timer16_Sequence_t enumerates the sequence that the timers should be allocated 55 | * _Nbr_16timers indicates how many 16 bit timers are available. 56 | * 57 | */ 58 | 59 | // Say which 16 bit timers can be used and in what order 60 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 61 | #define _useTimer5 62 | //#define _useTimer1 63 | #define _useTimer3 64 | #define _useTimer4 65 | //typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; 66 | typedef enum { _timer5, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; 67 | 68 | #elif defined(__AVR_ATmega32U4__) 69 | //#define _useTimer1 70 | #define _useTimer3 71 | //typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; 72 | typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; 73 | 74 | #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) 75 | #define _useTimer3 76 | //#define _useTimer1 77 | //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; 78 | typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; 79 | 80 | #elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) ||defined(__AVR_ATmega2561__) 81 | #define _useTimer3 82 | //#define _useTimer1 83 | //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; 84 | typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; 85 | 86 | #else // everything else 87 | //#define _useTimer1 88 | //typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; 89 | typedef enum { _Nbr_16timers } timer16_Sequence_t ; 90 | #endif 91 | 92 | #define Servo_VERSION 2 // software version of this library 93 | 94 | #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo 95 | #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo 96 | #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached 97 | #define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds 98 | 99 | #define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer 100 | #define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER) 101 | 102 | #define INVALID_SERVO 255 // flag indicating an invalid servo index 103 | 104 | typedef struct { 105 | uint8_t nbr :6 ; // a pin number from 0 to 63 106 | uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false 107 | } ServoPin_t ; 108 | 109 | typedef struct { 110 | ServoPin_t Pin; 111 | unsigned int ticks; 112 | } servo_t; 113 | 114 | class Servo 115 | { 116 | public: 117 | Servo(); 118 | uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure 119 | uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. 120 | void detach(); 121 | void write(int value); // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds 122 | void writeMicroseconds(int value); // Write pulse width in microseconds 123 | int read(); // returns current pulse width as an angle between 0 and 180 degrees 124 | int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) 125 | bool attached(); // return true if this servo is attached, otherwise false 126 | #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0) 127 | int pin; // store the hardware pin of the servo 128 | #endif 129 | private: 130 | uint8_t servoIndex; // index into the channel data for this servo 131 | int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH 132 | int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH 133 | }; 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/Servo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 3 | Copyright (c) 2009 Michael Margolis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /* 21 | 22 | A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. 23 | The servos are pulsed in the background using the value most recently written using the write() method 24 | 25 | Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. 26 | Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. 27 | The sequence used to seize timers is defined in timers.h 28 | 29 | The methods are: 30 | 31 | Servo - Class for manipulating servo motors connected to Arduino pins. 32 | 33 | attach(pin ) - Attaches a servo motor to an i/o pin. 34 | attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds 35 | default min is 544, max is 2400 36 | 37 | write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) 38 | writeMicroseconds() - Sets the servo pulse width in microseconds 39 | read() - Gets the last written servo pulse width as an angle between 0 and 180. 40 | readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) 41 | attached() - Returns true if there is a servo attached. 42 | detach() - Stops an attached servos from pulsing its i/o pin. 43 | */ 44 | 45 | #ifndef Servo_h 46 | #define Servo_h 47 | 48 | #include 49 | 50 | /* 51 | * Defines for 16 bit timers used with Servo library 52 | * 53 | * If _useTimerX is defined then TimerX is a 16 bit timer on the current board 54 | * timer16_Sequence_t enumerates the sequence that the timers should be allocated 55 | * _Nbr_16timers indicates how many 16 bit timers are available. 56 | * 57 | */ 58 | 59 | // Say which 16 bit timers can be used and in what order 60 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 61 | #define _useTimer5 62 | //#define _useTimer1 63 | #define _useTimer3 64 | #define _useTimer4 65 | //typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; 66 | typedef enum { _timer5, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; 67 | 68 | #elif defined(__AVR_ATmega32U4__) 69 | //#define _useTimer1 70 | #define _useTimer3 71 | //typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; 72 | typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; 73 | 74 | #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) 75 | #define _useTimer3 76 | //#define _useTimer1 77 | //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; 78 | typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; 79 | 80 | #elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) ||defined(__AVR_ATmega2561__) 81 | #define _useTimer3 82 | //#define _useTimer1 83 | //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; 84 | typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; 85 | 86 | #else // everything else 87 | //#define _useTimer1 88 | //typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; 89 | typedef enum { _Nbr_16timers } timer16_Sequence_t ; 90 | #endif 91 | 92 | #define Servo_VERSION 2 // software version of this library 93 | 94 | #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo 95 | #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo 96 | #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached 97 | #define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds 98 | 99 | #define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer 100 | #define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER) 101 | 102 | #define INVALID_SERVO 255 // flag indicating an invalid servo index 103 | 104 | typedef struct { 105 | uint8_t nbr :6 ; // a pin number from 0 to 63 106 | uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false 107 | } ServoPin_t ; 108 | 109 | typedef struct { 110 | ServoPin_t Pin; 111 | unsigned int ticks; 112 | } servo_t; 113 | 114 | class Servo 115 | { 116 | public: 117 | Servo(); 118 | uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure 119 | uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. 120 | void detach(); 121 | void write(int value); // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds 122 | void writeMicroseconds(int value); // Write pulse width in microseconds 123 | int read(); // returns current pulse width as an angle between 0 and 180 degrees 124 | int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) 125 | bool attached(); // return true if this servo is attached, otherwise false 126 | #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0) 127 | int pin; // store the hardware pin of the servo 128 | #endif 129 | private: 130 | uint8_t servoIndex; // index into the channel data for this servo 131 | int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH 132 | int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH 133 | }; 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/MarlinSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 28 September 2010 by Mark Sproul 20 | */ 21 | 22 | #ifndef MarlinSerial_h 23 | #define MarlinSerial_h 24 | #include "Marlin.h" 25 | 26 | #if !defined(SERIAL_PORT) 27 | #define SERIAL_PORT 0 28 | #endif 29 | 30 | // The presence of the UBRRH register is used to detect a UART. 31 | #define UART_PRESENT(port) ((port == 0 && (defined(UBRRH) || defined(UBRR0H))) || \ 32 | (port == 1 && defined(UBRR1H)) || (port == 2 && defined(UBRR2H)) || \ 33 | (port == 3 && defined(UBRR3H))) 34 | 35 | // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor 36 | // requires two levels of indirection to expand macro values properly) 37 | #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) 38 | #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary 39 | #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix 40 | #else 41 | #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix 42 | #endif 43 | 44 | // Registers used by MarlinSerial class (these are expanded 45 | // depending on selected serial port 46 | #define M_UCSRxA SERIAL_REGNAME(UCSR,SERIAL_PORT,A) // defines M_UCSRxA to be UCSRnA where n is the serial port number 47 | #define M_UCSRxB SERIAL_REGNAME(UCSR,SERIAL_PORT,B) 48 | #define M_RXENx SERIAL_REGNAME(RXEN,SERIAL_PORT,) 49 | #define M_TXENx SERIAL_REGNAME(TXEN,SERIAL_PORT,) 50 | #define M_RXCIEx SERIAL_REGNAME(RXCIE,SERIAL_PORT,) 51 | #define M_UDREx SERIAL_REGNAME(UDRE,SERIAL_PORT,) 52 | #define M_UDRx SERIAL_REGNAME(UDR,SERIAL_PORT,) 53 | #define M_UBRRxH SERIAL_REGNAME(UBRR,SERIAL_PORT,H) 54 | #define M_UBRRxL SERIAL_REGNAME(UBRR,SERIAL_PORT,L) 55 | #define M_RXCx SERIAL_REGNAME(RXC,SERIAL_PORT,) 56 | #define M_USARTx_RX_vect SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect) 57 | #define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,) 58 | 59 | 60 | 61 | #define DEC 10 62 | #define HEX 16 63 | #define OCT 8 64 | #define BIN 2 65 | #define BYTE 0 66 | 67 | 68 | #ifndef AT90USB 69 | // Define constants and variables for buffering incoming serial data. We're 70 | // using a ring buffer (I think), in which rx_buffer_head is the index of the 71 | // location to which to write the next incoming character and rx_buffer_tail 72 | // is the index of the location from which to read. 73 | #define RX_BUFFER_SIZE 128 74 | 75 | 76 | struct ring_buffer 77 | { 78 | unsigned char buffer[RX_BUFFER_SIZE]; 79 | int head; 80 | int tail; 81 | }; 82 | 83 | #if UART_PRESENT(SERIAL_PORT) 84 | extern ring_buffer rx_buffer; 85 | #endif 86 | 87 | class MarlinSerial //: public Stream 88 | { 89 | 90 | public: 91 | MarlinSerial(); 92 | void begin(long); 93 | void end(); 94 | int peek(void); 95 | int read(void); 96 | void flush(void); 97 | 98 | FORCE_INLINE int available(void) 99 | { 100 | return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE; 101 | } 102 | 103 | FORCE_INLINE void write(uint8_t c) 104 | { 105 | while (!((M_UCSRxA) & (1 << M_UDREx))) 106 | ; 107 | 108 | M_UDRx = c; 109 | } 110 | 111 | 112 | FORCE_INLINE void checkRx(void) 113 | { 114 | if((M_UCSRxA & (1<. 20 | */ 21 | 22 | #include "Marlin.h" 23 | #include "stepper.h" 24 | #include "planner.h" 25 | 26 | // The arc is approximated by generating a huge number of tiny, linear segments. The length of each 27 | // segment is configured in settings.mm_per_arc_segment. 28 | void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1, 29 | uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise, uint8_t extruder) 30 | { 31 | // int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled(); 32 | // plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc 33 | float center_axis0 = position[axis_0] + offset[axis_0]; 34 | float center_axis1 = position[axis_1] + offset[axis_1]; 35 | float linear_travel = target[axis_linear] - position[axis_linear]; 36 | float extruder_travel = target[E_AXIS] - position[E_AXIS]; 37 | float r_axis0 = -offset[axis_0]; // Radius vector from center to current location 38 | float r_axis1 = -offset[axis_1]; 39 | float rt_axis0 = target[axis_0] - center_axis0; 40 | float rt_axis1 = target[axis_1] - center_axis1; 41 | 42 | // CCW angle between position and target from circle center. Only one atan2() trig computation required. 43 | float angular_travel = atan2(r_axis0*rt_axis1-r_axis1*rt_axis0, r_axis0*rt_axis0+r_axis1*rt_axis1); 44 | if (angular_travel < 0) { angular_travel += 2*M_PI; } 45 | if (isclockwise) { angular_travel -= 2*M_PI; } 46 | 47 | //20141002:full circle for G03 did not work, e.g. G03 X80 Y80 I20 J0 F2000 is giving an Angle of zero so head is not moving 48 | //to compensate when start pos = target pos && angle is zero -> angle = 2Pi 49 | if (position[axis_0] == target[axis_0] && position[axis_1] == target[axis_1] && angular_travel == 0) 50 | { 51 | angular_travel += 2*M_PI; 52 | } 53 | //end fix G03 54 | 55 | float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel)); 56 | if (millimeters_of_travel < 0.001) { return; } 57 | uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT); 58 | if(segments == 0) segments = 1; 59 | 60 | /* 61 | // Multiply inverse feed_rate to compensate for the fact that this movement is approximated 62 | // by a number of discrete segments. The inverse feed_rate should be correct for the sum of 63 | // all segments. 64 | if (invert_feed_rate) { feed_rate *= segments; } 65 | */ 66 | float theta_per_segment = angular_travel/segments; 67 | float linear_per_segment = linear_travel/segments; 68 | float extruder_per_segment = extruder_travel/segments; 69 | 70 | /* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector, 71 | and phi is the angle of rotation. Based on the solution approach by Jens Geisler. 72 | r_T = [cos(phi) -sin(phi); 73 | sin(phi) cos(phi] * r ; 74 | 75 | For arc generation, the center of the circle is the axis of rotation and the radius vector is 76 | defined from the circle center to the initial position. Each line segment is formed by successive 77 | vector rotations. This requires only two cos() and sin() computations to form the rotation 78 | matrix for the duration of the entire arc. Error may accumulate from numerical round-off, since 79 | all double numbers are single precision on the Arduino. (True double precision will not have 80 | round off issues for CNC applications.) Single precision error can accumulate to be greater than 81 | tool precision in some cases. Therefore, arc path correction is implemented. 82 | 83 | Small angle approximation may be used to reduce computation overhead further. This approximation 84 | holds for everything, but very small circles and large mm_per_arc_segment values. In other words, 85 | theta_per_segment would need to be greater than 0.1 rad and N_ARC_CORRECTION would need to be large 86 | to cause an appreciable drift error. N_ARC_CORRECTION~=25 is more than small enough to correct for 87 | numerical drift error. N_ARC_CORRECTION may be on the order a hundred(s) before error becomes an 88 | issue for CNC machines with the single precision Arduino calculations. 89 | 90 | This approximation also allows mc_arc to immediately insert a line segment into the planner 91 | without the initial overhead of computing cos() or sin(). By the time the arc needs to be applied 92 | a correction, the planner should have caught up to the lag caused by the initial mc_arc overhead. 93 | This is important when there are successive arc motions. 94 | */ 95 | // Vector rotation matrix values 96 | float cos_T = 1-0.5*theta_per_segment*theta_per_segment; // Small angle approximation 97 | float sin_T = theta_per_segment; 98 | 99 | float arc_target[4]; 100 | float sin_Ti; 101 | float cos_Ti; 102 | float r_axisi; 103 | uint16_t i; 104 | int8_t count = 0; 105 | 106 | // Initialize the linear axis 107 | arc_target[axis_linear] = position[axis_linear]; 108 | 109 | // Initialize the extruder axis 110 | arc_target[E_AXIS] = position[E_AXIS]; 111 | 112 | for (i = 1; i. 20 | */ 21 | 22 | #include "Marlin.h" 23 | #include "stepper.h" 24 | #include "planner.h" 25 | 26 | // The arc is approximated by generating a huge number of tiny, linear segments. The length of each 27 | // segment is configured in settings.mm_per_arc_segment. 28 | void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1, 29 | uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise, uint8_t extruder) 30 | { 31 | // int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled(); 32 | // plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc 33 | float center_axis0 = position[axis_0] + offset[axis_0]; 34 | float center_axis1 = position[axis_1] + offset[axis_1]; 35 | float linear_travel = target[axis_linear] - position[axis_linear]; 36 | float extruder_travel = target[E_AXIS] - position[E_AXIS]; 37 | float r_axis0 = -offset[axis_0]; // Radius vector from center to current location 38 | float r_axis1 = -offset[axis_1]; 39 | float rt_axis0 = target[axis_0] - center_axis0; 40 | float rt_axis1 = target[axis_1] - center_axis1; 41 | 42 | // CCW angle between position and target from circle center. Only one atan2() trig computation required. 43 | float angular_travel = atan2(r_axis0*rt_axis1-r_axis1*rt_axis0, r_axis0*rt_axis0+r_axis1*rt_axis1); 44 | if (angular_travel < 0) { angular_travel += 2*M_PI; } 45 | if (isclockwise) { angular_travel -= 2*M_PI; } 46 | 47 | //20141002:full circle for G03 did not work, e.g. G03 X80 Y80 I20 J0 F2000 is giving an Angle of zero so head is not moving 48 | //to compensate when start pos = target pos && angle is zero -> angle = 2Pi 49 | if (position[axis_0] == target[axis_0] && position[axis_1] == target[axis_1] && angular_travel == 0) 50 | { 51 | angular_travel += 2*M_PI; 52 | } 53 | //end fix G03 54 | 55 | float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel)); 56 | if (millimeters_of_travel < 0.001) { return; } 57 | uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT); 58 | if(segments == 0) segments = 1; 59 | 60 | /* 61 | // Multiply inverse feed_rate to compensate for the fact that this movement is approximated 62 | // by a number of discrete segments. The inverse feed_rate should be correct for the sum of 63 | // all segments. 64 | if (invert_feed_rate) { feed_rate *= segments; } 65 | */ 66 | float theta_per_segment = angular_travel/segments; 67 | float linear_per_segment = linear_travel/segments; 68 | float extruder_per_segment = extruder_travel/segments; 69 | 70 | /* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector, 71 | and phi is the angle of rotation. Based on the solution approach by Jens Geisler. 72 | r_T = [cos(phi) -sin(phi); 73 | sin(phi) cos(phi] * r ; 74 | 75 | For arc generation, the center of the circle is the axis of rotation and the radius vector is 76 | defined from the circle center to the initial position. Each line segment is formed by successive 77 | vector rotations. This requires only two cos() and sin() computations to form the rotation 78 | matrix for the duration of the entire arc. Error may accumulate from numerical round-off, since 79 | all double numbers are single precision on the Arduino. (True double precision will not have 80 | round off issues for CNC applications.) Single precision error can accumulate to be greater than 81 | tool precision in some cases. Therefore, arc path correction is implemented. 82 | 83 | Small angle approximation may be used to reduce computation overhead further. This approximation 84 | holds for everything, but very small circles and large mm_per_arc_segment values. In other words, 85 | theta_per_segment would need to be greater than 0.1 rad and N_ARC_CORRECTION would need to be large 86 | to cause an appreciable drift error. N_ARC_CORRECTION~=25 is more than small enough to correct for 87 | numerical drift error. N_ARC_CORRECTION may be on the order a hundred(s) before error becomes an 88 | issue for CNC machines with the single precision Arduino calculations. 89 | 90 | This approximation also allows mc_arc to immediately insert a line segment into the planner 91 | without the initial overhead of computing cos() or sin(). By the time the arc needs to be applied 92 | a correction, the planner should have caught up to the lag caused by the initial mc_arc overhead. 93 | This is important when there are successive arc motions. 94 | */ 95 | // Vector rotation matrix values 96 | float cos_T = 1-0.5*theta_per_segment*theta_per_segment; // Small angle approximation 97 | float sin_T = theta_per_segment; 98 | 99 | float arc_target[4]; 100 | float sin_Ti; 101 | float cos_Ti; 102 | float r_axisi; 103 | uint16_t i; 104 | int8_t count = 0; 105 | 106 | // Initialize the linear axis 107 | arc_target[axis_linear] = position[axis_linear]; 108 | 109 | // Initialize the extruder axis 110 | arc_target[E_AXIS] = position[E_AXIS]; 111 | 112 | for (i = 1; i. 19 | */ 20 | 21 | // This module is to be considered a sub-module of stepper.c. Please don't include 22 | // this file from any other module. 23 | 24 | #ifndef planner_h 25 | #define planner_h 26 | 27 | #include "Marlin.h" 28 | 29 | #ifdef ENABLE_AUTO_BED_LEVELING 30 | #include "vector_3.h" 31 | #endif // ENABLE_AUTO_BED_LEVELING 32 | 33 | // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in 34 | // the source g-code and may never actually be reached if acceleration management is active. 35 | typedef struct { 36 | // Fields used by the bresenham algorithm for tracing the line 37 | long steps_x, steps_y, steps_z, steps_e; // Step count along each axis 38 | unsigned long step_event_count; // The number of step events required to complete this block 39 | long accelerate_until; // The index of the step event on which to stop acceleration 40 | long decelerate_after; // The index of the step event on which to start decelerating 41 | long acceleration_rate; // The acceleration rate used for acceleration calculation 42 | unsigned char direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) 43 | unsigned char active_extruder; // Selects the active extruder 44 | #ifdef ADVANCE 45 | long advance_rate; 46 | volatile long initial_advance; 47 | volatile long final_advance; 48 | float advance; 49 | #endif 50 | 51 | // Fields used by the motion planner to manage acceleration 52 | // float speed_x, speed_y, speed_z, speed_e; // Nominal mm/sec for each axis 53 | float nominal_speed; // The nominal speed for this block in mm/sec 54 | float entry_speed; // Entry speed at previous-current junction in mm/sec 55 | float max_entry_speed; // Maximum allowable junction entry speed in mm/sec 56 | float millimeters; // The total travel of this block in mm 57 | float acceleration; // acceleration mm/sec^2 58 | unsigned char recalculate_flag; // Planner flag to recalculate trapezoids on entry junction 59 | unsigned char nominal_length_flag; // Planner flag for nominal speed always reached 60 | 61 | // Settings for the trapezoid generator 62 | unsigned long nominal_rate; // The nominal step rate for this block in step_events/sec 63 | unsigned long initial_rate; // The jerk-adjusted step rate at start of block 64 | unsigned long final_rate; // The minimal rate at exit 65 | unsigned long acceleration_st; // acceleration steps/sec^2 66 | unsigned long fan_speed; 67 | #ifdef BARICUDA 68 | unsigned long valve_pressure; 69 | unsigned long e_to_p_pressure; 70 | #endif 71 | volatile char busy; 72 | } block_t; 73 | 74 | #ifdef ENABLE_AUTO_BED_LEVELING 75 | // this holds the required transform to compensate for bed level 76 | extern matrix_3x3 plan_bed_level_matrix; 77 | #endif // #ifdef ENABLE_AUTO_BED_LEVELING 78 | 79 | // Initialize the motion plan subsystem 80 | void plan_init(); 81 | 82 | // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 83 | // millimaters. Feed rate specifies the speed of the motion. 84 | 85 | #ifdef ENABLE_AUTO_BED_LEVELING 86 | void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder); 87 | 88 | // Get the position applying the bed level matrix if enabled 89 | vector_3 plan_get_position(); 90 | #else 91 | void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder); 92 | #endif // ENABLE_AUTO_BED_LEVELING 93 | 94 | // Set position. Used for G92 instructions. 95 | #ifdef ENABLE_AUTO_BED_LEVELING 96 | void plan_set_position(float x, float y, float z, const float &e); 97 | #else 98 | void plan_set_position(const float &x, const float &y, const float &z, const float &e); 99 | #endif // ENABLE_AUTO_BED_LEVELING 100 | 101 | void plan_set_e_position(const float &e); 102 | 103 | 104 | 105 | void check_axes_activity(); 106 | uint8_t movesplanned(); //return the nr of buffered moves 107 | 108 | extern unsigned long minsegmenttime; 109 | extern float max_feedrate[4]; // set the max speeds 110 | extern float axis_steps_per_unit[4]; 111 | extern unsigned long max_acceleration_units_per_sq_second[4]; // Use M201 to override by software 112 | extern float minimumfeedrate; 113 | extern float acceleration; // Normal acceleration mm/s^2 THIS IS THE DEFAULT ACCELERATION for all moves. M204 SXXXX 114 | extern float retract_acceleration; // mm/s^2 filament pull-pack and push-forward while standing still in the other axis M204 TXXXX 115 | extern float max_xy_jerk; //speed than can be stopped at once, if i understand correctly. 116 | extern float max_z_jerk; 117 | extern float max_e_jerk; 118 | extern float mintravelfeedrate; 119 | extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; 120 | 121 | #ifdef AUTOTEMP 122 | extern bool autotemp_enabled; 123 | extern float autotemp_max; 124 | extern float autotemp_min; 125 | extern float autotemp_factor; 126 | #endif 127 | 128 | 129 | 130 | 131 | extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions 132 | extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed 133 | extern volatile unsigned char block_buffer_tail; 134 | // Called when the current block is no longer needed. Discards the block and makes the memory 135 | // availible for new blocks. 136 | FORCE_INLINE void plan_discard_current_block() 137 | { 138 | if (block_buffer_head != block_buffer_tail) { 139 | block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); 140 | } 141 | } 142 | 143 | // Gets the current block. Returns NULL if buffer empty 144 | FORCE_INLINE block_t *plan_get_current_block() 145 | { 146 | if (block_buffer_head == block_buffer_tail) { 147 | return(NULL); 148 | } 149 | block_t *block = &block_buffer[block_buffer_tail]; 150 | block->busy = true; 151 | return(block); 152 | } 153 | 154 | // Returns true if the buffer has a queued block, false otherwise 155 | FORCE_INLINE bool blocks_queued() 156 | { 157 | if (block_buffer_head == block_buffer_tail) { 158 | return false; 159 | } 160 | else 161 | return true; 162 | } 163 | 164 | #ifdef PREVENT_DANGEROUS_EXTRUDE 165 | void set_extrude_min_temp(float temp); 166 | #endif 167 | 168 | void reset_acceleration_rates(); 169 | #endif 170 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/planner.h: -------------------------------------------------------------------------------- 1 | /* 2 | planner.h - buffers movement commands and manages the acceleration profile plan 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | // This module is to be considered a sub-module of stepper.c. Please don't include 22 | // this file from any other module. 23 | 24 | #ifndef planner_h 25 | #define planner_h 26 | 27 | #include "Marlin.h" 28 | 29 | #ifdef ENABLE_AUTO_BED_LEVELING 30 | #include "vector_3.h" 31 | #endif // ENABLE_AUTO_BED_LEVELING 32 | 33 | // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in 34 | // the source g-code and may never actually be reached if acceleration management is active. 35 | typedef struct { 36 | // Fields used by the bresenham algorithm for tracing the line 37 | long steps_x, steps_y, steps_z, steps_e; // Step count along each axis 38 | unsigned long step_event_count; // The number of step events required to complete this block 39 | long accelerate_until; // The index of the step event on which to stop acceleration 40 | long decelerate_after; // The index of the step event on which to start decelerating 41 | long acceleration_rate; // The acceleration rate used for acceleration calculation 42 | unsigned char direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) 43 | unsigned char active_extruder; // Selects the active extruder 44 | #ifdef ADVANCE 45 | long advance_rate; 46 | volatile long initial_advance; 47 | volatile long final_advance; 48 | float advance; 49 | #endif 50 | 51 | // Fields used by the motion planner to manage acceleration 52 | // float speed_x, speed_y, speed_z, speed_e; // Nominal mm/sec for each axis 53 | float nominal_speed; // The nominal speed for this block in mm/sec 54 | float entry_speed; // Entry speed at previous-current junction in mm/sec 55 | float max_entry_speed; // Maximum allowable junction entry speed in mm/sec 56 | float millimeters; // The total travel of this block in mm 57 | float acceleration; // acceleration mm/sec^2 58 | unsigned char recalculate_flag; // Planner flag to recalculate trapezoids on entry junction 59 | unsigned char nominal_length_flag; // Planner flag for nominal speed always reached 60 | 61 | // Settings for the trapezoid generator 62 | unsigned long nominal_rate; // The nominal step rate for this block in step_events/sec 63 | unsigned long initial_rate; // The jerk-adjusted step rate at start of block 64 | unsigned long final_rate; // The minimal rate at exit 65 | unsigned long acceleration_st; // acceleration steps/sec^2 66 | unsigned long fan_speed; 67 | #ifdef BARICUDA 68 | unsigned long valve_pressure; 69 | unsigned long e_to_p_pressure; 70 | #endif 71 | volatile char busy; 72 | } block_t; 73 | 74 | #ifdef ENABLE_AUTO_BED_LEVELING 75 | // this holds the required transform to compensate for bed level 76 | extern matrix_3x3 plan_bed_level_matrix; 77 | #endif // #ifdef ENABLE_AUTO_BED_LEVELING 78 | 79 | // Initialize the motion plan subsystem 80 | void plan_init(); 81 | 82 | // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 83 | // millimaters. Feed rate specifies the speed of the motion. 84 | 85 | #ifdef ENABLE_AUTO_BED_LEVELING 86 | void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder); 87 | 88 | // Get the position applying the bed level matrix if enabled 89 | vector_3 plan_get_position(); 90 | #else 91 | void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder); 92 | #endif // ENABLE_AUTO_BED_LEVELING 93 | 94 | // Set position. Used for G92 instructions. 95 | #ifdef ENABLE_AUTO_BED_LEVELING 96 | void plan_set_position(float x, float y, float z, const float &e); 97 | #else 98 | void plan_set_position(const float &x, const float &y, const float &z, const float &e); 99 | #endif // ENABLE_AUTO_BED_LEVELING 100 | 101 | void plan_set_e_position(const float &e); 102 | 103 | 104 | 105 | void check_axes_activity(); 106 | uint8_t movesplanned(); //return the nr of buffered moves 107 | 108 | extern unsigned long minsegmenttime; 109 | extern float max_feedrate[4]; // set the max speeds 110 | extern float axis_steps_per_unit[4]; 111 | extern unsigned long max_acceleration_units_per_sq_second[4]; // Use M201 to override by software 112 | extern float minimumfeedrate; 113 | extern float acceleration; // Normal acceleration mm/s^2 THIS IS THE DEFAULT ACCELERATION for all moves. M204 SXXXX 114 | extern float retract_acceleration; // mm/s^2 filament pull-pack and push-forward while standing still in the other axis M204 TXXXX 115 | extern float max_xy_jerk; //speed than can be stopped at once, if i understand correctly. 116 | extern float max_z_jerk; 117 | extern float max_e_jerk; 118 | extern float mintravelfeedrate; 119 | extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; 120 | 121 | #ifdef AUTOTEMP 122 | extern bool autotemp_enabled; 123 | extern float autotemp_max; 124 | extern float autotemp_min; 125 | extern float autotemp_factor; 126 | #endif 127 | 128 | 129 | 130 | 131 | extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions 132 | extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed 133 | extern volatile unsigned char block_buffer_tail; 134 | // Called when the current block is no longer needed. Discards the block and makes the memory 135 | // availible for new blocks. 136 | FORCE_INLINE void plan_discard_current_block() 137 | { 138 | if (block_buffer_head != block_buffer_tail) { 139 | block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); 140 | } 141 | } 142 | 143 | // Gets the current block. Returns NULL if buffer empty 144 | FORCE_INLINE block_t *plan_get_current_block() 145 | { 146 | if (block_buffer_head == block_buffer_tail) { 147 | return(NULL); 148 | } 149 | block_t *block = &block_buffer[block_buffer_tail]; 150 | block->busy = true; 151 | return(block); 152 | } 153 | 154 | // Returns true if the buffer has a queued block, false otherwise 155 | FORCE_INLINE bool blocks_queued() 156 | { 157 | if (block_buffer_head == block_buffer_tail) { 158 | return false; 159 | } 160 | else 161 | return true; 162 | } 163 | 164 | #ifdef PREVENT_DANGEROUS_EXTRUDE 165 | void set_extrude_min_temp(float temp); 166 | #endif 167 | 168 | void reset_acceleration_rates(); 169 | #endif 170 | -------------------------------------------------------------------------------- /firmware/mk7/Marlin/MarlinSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | Modified 28 September 2010 by Mark Sproul 21 | */ 22 | 23 | #include "Marlin.h" 24 | #include "MarlinSerial.h" 25 | 26 | #ifndef AT90USB 27 | // this next line disables the entire HardwareSerial.cpp, 28 | // this is so I can support Attiny series and any other chip without a UART 29 | #if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H) 30 | 31 | #if UART_PRESENT(SERIAL_PORT) 32 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 33 | #endif 34 | 35 | FORCE_INLINE void store_char(unsigned char c) 36 | { 37 | int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE; 38 | 39 | // if we should be storing the received character into the location 40 | // just before the tail (meaning that the head would advance to the 41 | // current location of the tail), we're about to overflow the buffer 42 | // and so we don't write the character or advance the head. 43 | if (i != rx_buffer.tail) { 44 | rx_buffer.buffer[rx_buffer.head] = c; 45 | rx_buffer.head = i; 46 | } 47 | } 48 | 49 | 50 | //#elif defined(SIG_USART_RECV) 51 | #if defined(M_USARTx_RX_vect) 52 | // fixed by Mark Sproul this is on the 644/644p 53 | //SIGNAL(SIG_USART_RECV) 54 | SIGNAL(M_USARTx_RX_vect) 55 | { 56 | unsigned char c = M_UDRx; 57 | store_char(c); 58 | } 59 | #endif 60 | 61 | // Constructors //////////////////////////////////////////////////////////////// 62 | 63 | MarlinSerial::MarlinSerial() 64 | { 65 | 66 | } 67 | 68 | // Public Methods ////////////////////////////////////////////////////////////// 69 | 70 | void MarlinSerial::begin(long baud) 71 | { 72 | uint16_t baud_setting; 73 | bool useU2X = true; 74 | 75 | #if F_CPU == 16000000UL && SERIAL_PORT == 0 76 | // hard-coded exception for compatibility with the bootloader shipped 77 | // with the Duemilanove and previous boards and the firmware on the 8U2 78 | // on the Uno and Mega 2560. 79 | if (baud == 57600) { 80 | useU2X = false; 81 | } 82 | #endif 83 | 84 | if (useU2X) { 85 | M_UCSRxA = 1 << M_U2Xx; 86 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 87 | } else { 88 | M_UCSRxA = 0; 89 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 90 | } 91 | 92 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 93 | M_UBRRxH = baud_setting >> 8; 94 | M_UBRRxL = baud_setting; 95 | 96 | sbi(M_UCSRxB, M_RXENx); 97 | sbi(M_UCSRxB, M_TXENx); 98 | sbi(M_UCSRxB, M_RXCIEx); 99 | } 100 | 101 | void MarlinSerial::end() 102 | { 103 | cbi(M_UCSRxB, M_RXENx); 104 | cbi(M_UCSRxB, M_TXENx); 105 | cbi(M_UCSRxB, M_RXCIEx); 106 | } 107 | 108 | 109 | 110 | int MarlinSerial::peek(void) 111 | { 112 | if (rx_buffer.head == rx_buffer.tail) { 113 | return -1; 114 | } else { 115 | return rx_buffer.buffer[rx_buffer.tail]; 116 | } 117 | } 118 | 119 | int MarlinSerial::read(void) 120 | { 121 | // if the head isn't ahead of the tail, we don't have any characters 122 | if (rx_buffer.head == rx_buffer.tail) { 123 | return -1; 124 | } else { 125 | unsigned char c = rx_buffer.buffer[rx_buffer.tail]; 126 | rx_buffer.tail = (unsigned int)(rx_buffer.tail + 1) % RX_BUFFER_SIZE; 127 | return c; 128 | } 129 | } 130 | 131 | void MarlinSerial::flush() 132 | { 133 | // don't reverse this or there may be problems if the RX interrupt 134 | // occurs after reading the value of rx_buffer_head but before writing 135 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 136 | // may be written to rx_buffer_tail, making it appear as if the buffer 137 | // don't reverse this or there may be problems if the RX interrupt 138 | // occurs after reading the value of rx_buffer_head but before writing 139 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 140 | // may be written to rx_buffer_tail, making it appear as if the buffer 141 | // were full, not empty. 142 | rx_buffer.head = rx_buffer.tail; 143 | } 144 | 145 | 146 | 147 | 148 | /// imports from print.h 149 | 150 | 151 | 152 | 153 | void MarlinSerial::print(char c, int base) 154 | { 155 | print((long) c, base); 156 | } 157 | 158 | void MarlinSerial::print(unsigned char b, int base) 159 | { 160 | print((unsigned long) b, base); 161 | } 162 | 163 | void MarlinSerial::print(int n, int base) 164 | { 165 | print((long) n, base); 166 | } 167 | 168 | void MarlinSerial::print(unsigned int n, int base) 169 | { 170 | print((unsigned long) n, base); 171 | } 172 | 173 | void MarlinSerial::print(long n, int base) 174 | { 175 | if (base == 0) { 176 | write(n); 177 | } else if (base == 10) { 178 | if (n < 0) { 179 | print('-'); 180 | n = -n; 181 | } 182 | printNumber(n, 10); 183 | } else { 184 | printNumber(n, base); 185 | } 186 | } 187 | 188 | void MarlinSerial::print(unsigned long n, int base) 189 | { 190 | if (base == 0) write(n); 191 | else printNumber(n, base); 192 | } 193 | 194 | void MarlinSerial::print(double n, int digits) 195 | { 196 | printFloat(n, digits); 197 | } 198 | 199 | void MarlinSerial::println(void) 200 | { 201 | print('\r'); 202 | print('\n'); 203 | } 204 | 205 | void MarlinSerial::println(const String &s) 206 | { 207 | print(s); 208 | println(); 209 | } 210 | 211 | void MarlinSerial::println(const char c[]) 212 | { 213 | print(c); 214 | println(); 215 | } 216 | 217 | void MarlinSerial::println(char c, int base) 218 | { 219 | print(c, base); 220 | println(); 221 | } 222 | 223 | void MarlinSerial::println(unsigned char b, int base) 224 | { 225 | print(b, base); 226 | println(); 227 | } 228 | 229 | void MarlinSerial::println(int n, int base) 230 | { 231 | print(n, base); 232 | println(); 233 | } 234 | 235 | void MarlinSerial::println(unsigned int n, int base) 236 | { 237 | print(n, base); 238 | println(); 239 | } 240 | 241 | void MarlinSerial::println(long n, int base) 242 | { 243 | print(n, base); 244 | println(); 245 | } 246 | 247 | void MarlinSerial::println(unsigned long n, int base) 248 | { 249 | print(n, base); 250 | println(); 251 | } 252 | 253 | void MarlinSerial::println(double n, int digits) 254 | { 255 | print(n, digits); 256 | println(); 257 | } 258 | 259 | // Private Methods ///////////////////////////////////////////////////////////// 260 | 261 | void MarlinSerial::printNumber(unsigned long n, uint8_t base) 262 | { 263 | unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 264 | unsigned long i = 0; 265 | 266 | if (n == 0) { 267 | print('0'); 268 | return; 269 | } 270 | 271 | while (n > 0) { 272 | buf[i++] = n % base; 273 | n /= base; 274 | } 275 | 276 | for (; i > 0; i--) 277 | print((char) (buf[i - 1] < 10 ? 278 | '0' + buf[i - 1] : 279 | 'A' + buf[i - 1] - 10)); 280 | } 281 | 282 | void MarlinSerial::printFloat(double number, uint8_t digits) 283 | { 284 | // Handle negative numbers 285 | if (number < 0.0) 286 | { 287 | print('-'); 288 | number = -number; 289 | } 290 | 291 | // Round correctly so that print(1.999, 2) prints as "2.00" 292 | double rounding = 0.5; 293 | for (uint8_t i=0; i 0) 305 | print("."); 306 | 307 | // Extract digits from the remainder one at a time 308 | while (digits-- > 0) 309 | { 310 | remainder *= 10.0; 311 | int toPrint = int(remainder); 312 | print(toPrint); 313 | remainder -= toPrint; 314 | } 315 | } 316 | // Preinstantiate Objects ////////////////////////////////////////////////////// 317 | 318 | 319 | MarlinSerial MSerial; 320 | 321 | #endif // whole file 322 | #endif // !AT90USB 323 | 324 | // For AT90USB targets use the UART for BT interfacing 325 | #if defined(AT90USB) && defined (BTENABLED) 326 | HardwareSerial bt; 327 | #endif 328 | 329 | -------------------------------------------------------------------------------- /firmware/mk8/Marlin/MarlinSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | Modified 28 September 2010 by Mark Sproul 21 | */ 22 | 23 | #include "Marlin.h" 24 | #include "MarlinSerial.h" 25 | 26 | #ifndef AT90USB 27 | // this next line disables the entire HardwareSerial.cpp, 28 | // this is so I can support Attiny series and any other chip without a UART 29 | #if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H) 30 | 31 | #if UART_PRESENT(SERIAL_PORT) 32 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 33 | #endif 34 | 35 | FORCE_INLINE void store_char(unsigned char c) 36 | { 37 | int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE; 38 | 39 | // if we should be storing the received character into the location 40 | // just before the tail (meaning that the head would advance to the 41 | // current location of the tail), we're about to overflow the buffer 42 | // and so we don't write the character or advance the head. 43 | if (i != rx_buffer.tail) { 44 | rx_buffer.buffer[rx_buffer.head] = c; 45 | rx_buffer.head = i; 46 | } 47 | } 48 | 49 | 50 | //#elif defined(SIG_USART_RECV) 51 | #if defined(M_USARTx_RX_vect) 52 | // fixed by Mark Sproul this is on the 644/644p 53 | //SIGNAL(SIG_USART_RECV) 54 | SIGNAL(M_USARTx_RX_vect) 55 | { 56 | unsigned char c = M_UDRx; 57 | store_char(c); 58 | } 59 | #endif 60 | 61 | // Constructors //////////////////////////////////////////////////////////////// 62 | 63 | MarlinSerial::MarlinSerial() 64 | { 65 | 66 | } 67 | 68 | // Public Methods ////////////////////////////////////////////////////////////// 69 | 70 | void MarlinSerial::begin(long baud) 71 | { 72 | uint16_t baud_setting; 73 | bool useU2X = true; 74 | 75 | #if F_CPU == 16000000UL && SERIAL_PORT == 0 76 | // hard-coded exception for compatibility with the bootloader shipped 77 | // with the Duemilanove and previous boards and the firmware on the 8U2 78 | // on the Uno and Mega 2560. 79 | if (baud == 57600) { 80 | useU2X = false; 81 | } 82 | #endif 83 | 84 | if (useU2X) { 85 | M_UCSRxA = 1 << M_U2Xx; 86 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 87 | } else { 88 | M_UCSRxA = 0; 89 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 90 | } 91 | 92 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 93 | M_UBRRxH = baud_setting >> 8; 94 | M_UBRRxL = baud_setting; 95 | 96 | sbi(M_UCSRxB, M_RXENx); 97 | sbi(M_UCSRxB, M_TXENx); 98 | sbi(M_UCSRxB, M_RXCIEx); 99 | } 100 | 101 | void MarlinSerial::end() 102 | { 103 | cbi(M_UCSRxB, M_RXENx); 104 | cbi(M_UCSRxB, M_TXENx); 105 | cbi(M_UCSRxB, M_RXCIEx); 106 | } 107 | 108 | 109 | 110 | int MarlinSerial::peek(void) 111 | { 112 | if (rx_buffer.head == rx_buffer.tail) { 113 | return -1; 114 | } else { 115 | return rx_buffer.buffer[rx_buffer.tail]; 116 | } 117 | } 118 | 119 | int MarlinSerial::read(void) 120 | { 121 | // if the head isn't ahead of the tail, we don't have any characters 122 | if (rx_buffer.head == rx_buffer.tail) { 123 | return -1; 124 | } else { 125 | unsigned char c = rx_buffer.buffer[rx_buffer.tail]; 126 | rx_buffer.tail = (unsigned int)(rx_buffer.tail + 1) % RX_BUFFER_SIZE; 127 | return c; 128 | } 129 | } 130 | 131 | void MarlinSerial::flush() 132 | { 133 | // don't reverse this or there may be problems if the RX interrupt 134 | // occurs after reading the value of rx_buffer_head but before writing 135 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 136 | // may be written to rx_buffer_tail, making it appear as if the buffer 137 | // don't reverse this or there may be problems if the RX interrupt 138 | // occurs after reading the value of rx_buffer_head but before writing 139 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 140 | // may be written to rx_buffer_tail, making it appear as if the buffer 141 | // were full, not empty. 142 | rx_buffer.head = rx_buffer.tail; 143 | } 144 | 145 | 146 | 147 | 148 | /// imports from print.h 149 | 150 | 151 | 152 | 153 | void MarlinSerial::print(char c, int base) 154 | { 155 | print((long) c, base); 156 | } 157 | 158 | void MarlinSerial::print(unsigned char b, int base) 159 | { 160 | print((unsigned long) b, base); 161 | } 162 | 163 | void MarlinSerial::print(int n, int base) 164 | { 165 | print((long) n, base); 166 | } 167 | 168 | void MarlinSerial::print(unsigned int n, int base) 169 | { 170 | print((unsigned long) n, base); 171 | } 172 | 173 | void MarlinSerial::print(long n, int base) 174 | { 175 | if (base == 0) { 176 | write(n); 177 | } else if (base == 10) { 178 | if (n < 0) { 179 | print('-'); 180 | n = -n; 181 | } 182 | printNumber(n, 10); 183 | } else { 184 | printNumber(n, base); 185 | } 186 | } 187 | 188 | void MarlinSerial::print(unsigned long n, int base) 189 | { 190 | if (base == 0) write(n); 191 | else printNumber(n, base); 192 | } 193 | 194 | void MarlinSerial::print(double n, int digits) 195 | { 196 | printFloat(n, digits); 197 | } 198 | 199 | void MarlinSerial::println(void) 200 | { 201 | print('\r'); 202 | print('\n'); 203 | } 204 | 205 | void MarlinSerial::println(const String &s) 206 | { 207 | print(s); 208 | println(); 209 | } 210 | 211 | void MarlinSerial::println(const char c[]) 212 | { 213 | print(c); 214 | println(); 215 | } 216 | 217 | void MarlinSerial::println(char c, int base) 218 | { 219 | print(c, base); 220 | println(); 221 | } 222 | 223 | void MarlinSerial::println(unsigned char b, int base) 224 | { 225 | print(b, base); 226 | println(); 227 | } 228 | 229 | void MarlinSerial::println(int n, int base) 230 | { 231 | print(n, base); 232 | println(); 233 | } 234 | 235 | void MarlinSerial::println(unsigned int n, int base) 236 | { 237 | print(n, base); 238 | println(); 239 | } 240 | 241 | void MarlinSerial::println(long n, int base) 242 | { 243 | print(n, base); 244 | println(); 245 | } 246 | 247 | void MarlinSerial::println(unsigned long n, int base) 248 | { 249 | print(n, base); 250 | println(); 251 | } 252 | 253 | void MarlinSerial::println(double n, int digits) 254 | { 255 | print(n, digits); 256 | println(); 257 | } 258 | 259 | // Private Methods ///////////////////////////////////////////////////////////// 260 | 261 | void MarlinSerial::printNumber(unsigned long n, uint8_t base) 262 | { 263 | unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 264 | unsigned long i = 0; 265 | 266 | if (n == 0) { 267 | print('0'); 268 | return; 269 | } 270 | 271 | while (n > 0) { 272 | buf[i++] = n % base; 273 | n /= base; 274 | } 275 | 276 | for (; i > 0; i--) 277 | print((char) (buf[i - 1] < 10 ? 278 | '0' + buf[i - 1] : 279 | 'A' + buf[i - 1] - 10)); 280 | } 281 | 282 | void MarlinSerial::printFloat(double number, uint8_t digits) 283 | { 284 | // Handle negative numbers 285 | if (number < 0.0) 286 | { 287 | print('-'); 288 | number = -number; 289 | } 290 | 291 | // Round correctly so that print(1.999, 2) prints as "2.00" 292 | double rounding = 0.5; 293 | for (uint8_t i=0; i 0) 305 | print("."); 306 | 307 | // Extract digits from the remainder one at a time 308 | while (digits-- > 0) 309 | { 310 | remainder *= 10.0; 311 | int toPrint = int(remainder); 312 | print(toPrint); 313 | remainder -= toPrint; 314 | } 315 | } 316 | // Preinstantiate Objects ////////////////////////////////////////////////////// 317 | 318 | 319 | MarlinSerial MSerial; 320 | 321 | #endif // whole file 322 | #endif // !AT90USB 323 | 324 | // For AT90USB targets use the UART for BT interfacing 325 | #if defined(AT90USB) && defined (BTENABLED) 326 | HardwareSerial bt; 327 | #endif 328 | 329 | --------------------------------------------------------------------------------