Prusa3d Marlin fork
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 <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef stepper_h
22 #define stepper_h
23 
24 #include "planner.h"
25 
26 #define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
27 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
28 
29 #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
30 extern bool abort_on_endstop_hit;
31 #endif
32 
33 // Initialize and start the stepper motor subsystem
34 void st_init();
35 
36 // Interrupt Service Routines
37 
38 void isr();
39 
40 // Block until all buffered steps are executed
41 void st_synchronize();
42 
43 // Set current position in steps
44 void st_set_position(const long *pos);
45 void st_set_e_position(const long &e);
46 
47 // Get current position in steps
48 long st_get_position(uint8_t axis);
49 
50 // Get current x and y position in steps
51 void st_get_position_xy(long &x, long &y);
52 
53 // Get current position in mm
54 float st_get_position_mm(uint8_t axis);
55 
56 
57 // Call this function just before re-enabling the stepper driver interrupt and the global interrupts
58 // to avoid a stepper timer overflow.
59 void st_reset_timer();
60 
61 void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
62 bool endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops();
63 bool endstop_z_hit_on_purpose();
64 
65 
66 bool enable_endstops(bool check); // Enable/disable endstop checking. Return the old value.
67 bool enable_z_endstop(bool check);
68 void invert_z_endstop(bool endstop_invert);
69 
70 void checkStepperErrors(); //Print errors detected by the stepper
71 
72 extern block_t *current_block; // A pointer to the block currently being traced
73 extern volatile long count_position[NUM_AXIS];
74 
75 void quickStop();
76 #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
77 void digitalPotWrite(int address, int value);
78 #endif //defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
79 
80 #ifndef TMC2130
81 void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
82 void microstep_mode(uint8_t driver, uint8_t stepping);
83 void st_current_init();
84 void st_current_set(uint8_t driver, int current);
85 void microstep_init();
86 void microstep_readings();
87 #endif
88 
89 #ifdef BABYSTEPPING
90  void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
91 #endif
92 
93 #endif
Definition: planner.h:71