@ -348,19 +348,55 @@ ISR(TIMER1_COMPA_vect)
// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
if ( ( out_bits & ( 1 < < X_AXIS ) ) ! = 0 ) {
if ( ( out_bits & ( 1 < < X_AXIS ) ) ! = 0 ) {
# ifdef DUAL_X_CARRIAGE
if ( extruder_duplication_enabled ) {
WRITE ( X_DIR_PIN , INVERT_X_DIR ) ;
WRITE ( X_DIR_PIN , INVERT_X_DIR ) ;
WRITE ( X2_DIR_PIN , INVERT_X_DIR ) ;
}
else {
if ( current_block - > active_extruder ! = 0 )
WRITE ( X2_DIR_PIN , INVERT_X_DIR ) ;
else
WRITE ( X_DIR_PIN , INVERT_X_DIR ) ;
}
# else
WRITE ( X_DIR_PIN , INVERT_X_DIR ) ;
# endif
count_direction [ X_AXIS ] = - 1 ;
count_direction [ X_AXIS ] = - 1 ;
}
}
else {
else {
# ifdef DUAL_X_CARRIAGE
if ( extruder_duplication_enabled ) {
WRITE ( X_DIR_PIN , ! INVERT_X_DIR ) ;
WRITE ( X_DIR_PIN , ! INVERT_X_DIR ) ;
WRITE ( X2_DIR_PIN , ! INVERT_X_DIR ) ;
}
else {
if ( current_block - > active_extruder ! = 0 )
WRITE ( X2_DIR_PIN , ! INVERT_X_DIR ) ;
else
WRITE ( X_DIR_PIN , ! INVERT_X_DIR ) ;
}
# else
WRITE ( X_DIR_PIN , ! INVERT_X_DIR ) ;
# endif
count_direction [ X_AXIS ] = 1 ;
count_direction [ X_AXIS ] = 1 ;
}
}
if ( ( out_bits & ( 1 < < Y_AXIS ) ) ! = 0 ) {
if ( ( out_bits & ( 1 < < Y_AXIS ) ) ! = 0 ) {
WRITE ( Y_DIR_PIN , INVERT_Y_DIR ) ;
WRITE ( Y_DIR_PIN , INVERT_Y_DIR ) ;
# ifdef Y_DUAL_STEPPER_DRIVERS
WRITE ( Y2_DIR_PIN , ! ( INVERT_Y_DIR = = INVERT_Y2_VS_Y_DIR ) ) ;
# endif
count_direction [ Y_AXIS ] = - 1 ;
count_direction [ Y_AXIS ] = - 1 ;
}
}
else {
else {
WRITE ( Y_DIR_PIN , ! INVERT_Y_DIR ) ;
WRITE ( Y_DIR_PIN , ! INVERT_Y_DIR ) ;
# ifdef Y_DUAL_STEPPER_DRIVERS
WRITE ( Y2_DIR_PIN , ( INVERT_Y_DIR = = INVERT_Y2_VS_Y_DIR ) ) ;
# endif
count_direction [ Y_AXIS ] = 1 ;
count_direction [ Y_AXIS ] = 1 ;
}
}
@ -371,9 +407,15 @@ ISR(TIMER1_COMPA_vect)
if ( ( ( ( out_bits & ( 1 < < X_AXIS ) ) ! = 0 ) & & ( out_bits & ( 1 < < Y_AXIS ) ) ! = 0 ) ) { //-X occurs for -A and -B
if ( ( ( ( out_bits & ( 1 < < X_AXIS ) ) ! = 0 ) & & ( out_bits & ( 1 < < Y_AXIS ) ) ! = 0 ) ) { //-X occurs for -A and -B
# endif
# endif
CHECK_ENDSTOPS
CHECK_ENDSTOPS
{
# ifdef DUAL_X_CARRIAGE
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
if ( ( current_block - > active_extruder = = 0 & & X_HOME_DIR = = - 1 )
| | ( current_block - > active_extruder ! = 0 & & X2_HOME_DIR = = - 1 ) )
# endif
{
{
# if defined(X_MIN_PIN) && X_MIN_PIN > -1
# if defined(X_MIN_PIN) && X_MIN_PIN > -1
bool x_min_endstop = ( READ ( X_MIN_PIN ) ! = X_ENDSTOPS_INVERTING ) ;
bool x_min_endstop = ( READ ( X_MIN_PIN ) ! = X_ MIN_ ENDSTOP_INVERTING) ;
if ( x_min_endstop & & old_x_min_endstop & & ( current_block - > steps_x > 0 ) ) {
if ( x_min_endstop & & old_x_min_endstop & & ( current_block - > steps_x > 0 ) ) {
endstops_trigsteps [ X_AXIS ] = count_position [ X_AXIS ] ;
endstops_trigsteps [ X_AXIS ] = count_position [ X_AXIS ] ;
endstop_x_hit = true ;
endstop_x_hit = true ;
@ -383,11 +425,18 @@ ISR(TIMER1_COMPA_vect)
# endif
# endif
}
}
}
}
}
else { // +direction
else { // +direction
CHECK_ENDSTOPS
CHECK_ENDSTOPS
{
# ifdef DUAL_X_CARRIAGE
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
if ( ( current_block - > active_extruder = = 0 & & X_HOME_DIR = = 1 )
| | ( current_block - > active_extruder ! = 0 & & X2_HOME_DIR = = 1 ) )
# endif
{
{
# if defined(X_MAX_PIN) && X_MAX_PIN > -1
# if defined(X_MAX_PIN) && X_MAX_PIN > -1
bool x_max_endstop = ( READ ( X_MAX_PIN ) ! = X_ENDSTOPS_INVERTING ) ;
bool x_max_endstop = ( READ ( X_MAX_PIN ) ! = X_ MAX_ ENDSTOP_INVERTING) ;
if ( x_max_endstop & & old_x_max_endstop & & ( current_block - > steps_x > 0 ) ) {
if ( x_max_endstop & & old_x_max_endstop & & ( current_block - > steps_x > 0 ) ) {
endstops_trigsteps [ X_AXIS ] = count_position [ X_AXIS ] ;
endstops_trigsteps [ X_AXIS ] = count_position [ X_AXIS ] ;
endstop_x_hit = true ;
endstop_x_hit = true ;
@ -397,6 +446,7 @@ ISR(TIMER1_COMPA_vect)
# endif
# endif
}
}
}
}
}
# ifndef COREXY
# ifndef COREXY
if ( ( out_bits & ( 1 < < Y_AXIS ) ) ! = 0 ) { // -direction
if ( ( out_bits & ( 1 < < Y_AXIS ) ) ! = 0 ) { // -direction
@ -406,7 +456,7 @@ ISR(TIMER1_COMPA_vect)
CHECK_ENDSTOPS
CHECK_ENDSTOPS
{
{
# if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
# if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
bool y_min_endstop = ( READ ( Y_MIN_PIN ) ! = Y_ ENDSTOPS _INVERTING) ;
bool y_min_endstop = ( READ ( Y_MIN_PIN ) ! = Y_ MIN_ ENDSTOP_INVERTING) ;
if ( y_min_endstop & & old_y_min_endstop & & ( current_block - > steps_y > 0 ) ) {
if ( y_min_endstop & & old_y_min_endstop & & ( current_block - > steps_y > 0 ) ) {
endstops_trigsteps [ Y_AXIS ] = count_position [ Y_AXIS ] ;
endstops_trigsteps [ Y_AXIS ] = count_position [ Y_AXIS ] ;
endstop_y_hit = true ;
endstop_y_hit = true ;
@ -420,7 +470,7 @@ ISR(TIMER1_COMPA_vect)
CHECK_ENDSTOPS
CHECK_ENDSTOPS
{
{
# if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
# if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
bool y_max_endstop = ( READ ( Y_MAX_PIN ) ! = Y_ ENDSTOPS _INVERTING) ;
bool y_max_endstop = ( READ ( Y_MAX_PIN ) ! = Y_ MAX_ ENDSTOP_INVERTING) ;
if ( y_max_endstop & & old_y_max_endstop & & ( current_block - > steps_y > 0 ) ) {
if ( y_max_endstop & & old_y_max_endstop & & ( current_block - > steps_y > 0 ) ) {
endstops_trigsteps [ Y_AXIS ] = count_position [ Y_AXIS ] ;
endstops_trigsteps [ Y_AXIS ] = count_position [ Y_AXIS ] ;
endstop_y_hit = true ;
endstop_y_hit = true ;
@ -442,7 +492,7 @@ ISR(TIMER1_COMPA_vect)
CHECK_ENDSTOPS
CHECK_ENDSTOPS
{
{
# if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
# if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
bool z_min_endstop = ( READ ( Z_MIN_PIN ) ! = Z_ ENDSTOPS _INVERTING) ;
bool z_min_endstop = ( READ ( Z_MIN_PIN ) ! = Z_ MIN_ ENDSTOP_INVERTING) ;
if ( z_min_endstop & & old_z_min_endstop & & ( current_block - > steps_z > 0 ) ) {
if ( z_min_endstop & & old_z_min_endstop & & ( current_block - > steps_z > 0 ) ) {
endstops_trigsteps [ Z_AXIS ] = count_position [ Z_AXIS ] ;
endstops_trigsteps [ Z_AXIS ] = count_position [ Z_AXIS ] ;
endstop_z_hit = true ;
endstop_z_hit = true ;
@ -463,7 +513,7 @@ ISR(TIMER1_COMPA_vect)
CHECK_ENDSTOPS
CHECK_ENDSTOPS
{
{
# if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
# if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
bool z_max_endstop = ( READ ( Z_MAX_PIN ) ! = Z_ ENDSTOPS _INVERTING) ;
bool z_max_endstop = ( READ ( Z_MAX_PIN ) ! = Z_ MAX_ ENDSTOP_INVERTING) ;
if ( z_max_endstop & & old_z_max_endstop & & ( current_block - > steps_z > 0 ) ) {
if ( z_max_endstop & & old_z_max_endstop & & ( current_block - > steps_z > 0 ) ) {
endstops_trigsteps [ Z_AXIS ] = count_position [ Z_AXIS ] ;
endstops_trigsteps [ Z_AXIS ] = count_position [ Z_AXIS ] ;
endstop_z_hit = true ;
endstop_z_hit = true ;
@ -507,18 +557,53 @@ ISR(TIMER1_COMPA_vect)
counter_x + = current_block - > steps_x ;
counter_x + = current_block - > steps_x ;
if ( counter_x > 0 ) {
if ( counter_x > 0 ) {
# ifdef DUAL_X_CARRIAGE
if ( extruder_duplication_enabled ) {
WRITE ( X_STEP_PIN , ! INVERT_X_STEP_PIN ) ;
WRITE ( X2_STEP_PIN , ! INVERT_X_STEP_PIN ) ;
}
else {
if ( current_block - > active_extruder ! = 0 )
WRITE ( X2_STEP_PIN , ! INVERT_X_STEP_PIN ) ;
else
WRITE ( X_STEP_PIN , ! INVERT_X_STEP_PIN ) ;
WRITE ( X_STEP_PIN , ! INVERT_X_STEP_PIN ) ;
}
# else
WRITE ( X_STEP_PIN , ! INVERT_X_STEP_PIN ) ;
# endif
counter_x - = current_block - > step_event_count ;
counter_x - = current_block - > step_event_count ;
count_position [ X_AXIS ] + = count_direction [ X_AXIS ] ;
count_position [ X_AXIS ] + = count_direction [ X_AXIS ] ;
# ifdef DUAL_X_CARRIAGE
if ( extruder_duplication_enabled ) {
WRITE ( X_STEP_PIN , INVERT_X_STEP_PIN ) ;
WRITE ( X2_STEP_PIN , INVERT_X_STEP_PIN ) ;
}
else {
if ( current_block - > active_extruder ! = 0 )
WRITE ( X2_STEP_PIN , INVERT_X_STEP_PIN ) ;
else
WRITE ( X_STEP_PIN , INVERT_X_STEP_PIN ) ;
WRITE ( X_STEP_PIN , INVERT_X_STEP_PIN ) ;
}
}
# else
WRITE ( X_STEP_PIN , INVERT_X_STEP_PIN ) ;
# endif
}
counter_y + = current_block - > steps_y ;
counter_y + = current_block - > steps_y ;
if ( counter_y > 0 ) {
if ( counter_y > 0 ) {
WRITE ( Y_STEP_PIN , ! INVERT_Y_STEP_PIN ) ;
WRITE ( Y_STEP_PIN , ! INVERT_Y_STEP_PIN ) ;
# ifdef Y_DUAL_STEPPER_DRIVERS
WRITE ( Y2_STEP_PIN , ! INVERT_Y_STEP_PIN ) ;
# endif
counter_y - = current_block - > step_event_count ;
counter_y - = current_block - > step_event_count ;
count_position [ Y_AXIS ] + = count_direction [ Y_AXIS ] ;
count_position [ Y_AXIS ] + = count_direction [ Y_AXIS ] ;
WRITE ( Y_STEP_PIN , INVERT_Y_STEP_PIN ) ;
WRITE ( Y_STEP_PIN , INVERT_Y_STEP_PIN ) ;
# ifdef Y_DUAL_STEPPER_DRIVERS
WRITE ( Y2_STEP_PIN , INVERT_Y_STEP_PIN ) ;
# endif
}
}
counter_z + = current_block - > steps_z ;
counter_z + = current_block - > steps_z ;
@ -685,8 +770,15 @@ void st_init()
# if defined(X_DIR_PIN) && X_DIR_PIN > -1
# if defined(X_DIR_PIN) && X_DIR_PIN > -1
SET_OUTPUT ( X_DIR_PIN ) ;
SET_OUTPUT ( X_DIR_PIN ) ;
# endif
# endif
# if defined(X2_DIR_PIN) && X2_DIR_PIN > -1
SET_OUTPUT ( X2_DIR_PIN ) ;
# endif
# if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
# if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
SET_OUTPUT ( Y_DIR_PIN ) ;
SET_OUTPUT ( Y_DIR_PIN ) ;
# if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_DIR_PIN) && (Y2_DIR_PIN > -1)
SET_OUTPUT ( Y2_DIR_PIN ) ;
# endif
# endif
# endif
# if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
# if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
SET_OUTPUT ( Z_DIR_PIN ) ;
SET_OUTPUT ( Z_DIR_PIN ) ;
@ -711,9 +803,18 @@ void st_init()
SET_OUTPUT ( X_ENABLE_PIN ) ;
SET_OUTPUT ( X_ENABLE_PIN ) ;
if ( ! X_ENABLE_ON ) WRITE ( X_ENABLE_PIN , HIGH ) ;
if ( ! X_ENABLE_ON ) WRITE ( X_ENABLE_PIN , HIGH ) ;
# endif
# endif
# if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
SET_OUTPUT ( X2_ENABLE_PIN ) ;
if ( ! X_ENABLE_ON ) WRITE ( X2_ENABLE_PIN , HIGH ) ;
# endif
# if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
# if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
SET_OUTPUT ( Y_ENABLE_PIN ) ;
SET_OUTPUT ( Y_ENABLE_PIN ) ;
if ( ! Y_ENABLE_ON ) WRITE ( Y_ENABLE_PIN , HIGH ) ;
if ( ! Y_ENABLE_ON ) WRITE ( Y_ENABLE_PIN , HIGH ) ;
# if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_ENABLE_PIN) && (Y2_ENABLE_PIN > -1)
SET_OUTPUT ( Y2_ENABLE_PIN ) ;
if ( ! Y_ENABLE_ON ) WRITE ( Y2_ENABLE_PIN , HIGH ) ;
# endif
# endif
# endif
# if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
# if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
SET_OUTPUT ( Z_ENABLE_PIN ) ;
SET_OUTPUT ( Z_ENABLE_PIN ) ;
@ -788,9 +889,18 @@ void st_init()
WRITE ( X_STEP_PIN , INVERT_X_STEP_PIN ) ;
WRITE ( X_STEP_PIN , INVERT_X_STEP_PIN ) ;
disable_x ( ) ;
disable_x ( ) ;
# endif
# endif
# if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1)
SET_OUTPUT ( X2_STEP_PIN ) ;
WRITE ( X2_STEP_PIN , INVERT_X_STEP_PIN ) ;
disable_x ( ) ;
# endif
# if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
# if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
SET_OUTPUT ( Y_STEP_PIN ) ;
SET_OUTPUT ( Y_STEP_PIN ) ;
WRITE ( Y_STEP_PIN , INVERT_Y_STEP_PIN ) ;
WRITE ( Y_STEP_PIN , INVERT_Y_STEP_PIN ) ;
# if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_STEP_PIN) && (Y2_STEP_PIN > -1)
SET_OUTPUT ( Y2_STEP_PIN ) ;
WRITE ( Y2_STEP_PIN , INVERT_Y_STEP_PIN ) ;
# endif
disable_y ( ) ;
disable_y ( ) ;
# endif
# endif
# if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
# if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)