Skip to content

Commit

Permalink
Make NEW_XYZCAL respect INVERT_*_DIR #defines.
Browse files Browse the repository at this point in the history
  • Loading branch information
metacollin authored and vertigo235 committed Nov 14, 2020
1 parent 396ee0f commit d8756d4
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions Firmware/sm4.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
//#define E0_STEP_PIN 34 //PC3 (+)


#define XDIR INVERT_X_DIR:!INVERT_X_DIR
#define YDIR INVERT_Y_DIR:!INVERT_Y_DIR
#define ZDIR INVERT_Z_DIR:!INVERT_Z_DIR
#define EDIR INVERT_E0_DIR:!INVERT_E0_DIR

uint8_t dir_mask = 0x0F^(INVERT_X_DIR | (INVERT_Y_DIR << 1) | (INVERT_Z_DIR << 2) | (INVERT_E0_DIR << 3));

sm4_stop_cb_t sm4_stop_cb = 0;

sm4_update_pos_cb_t sm4_update_pos_cb = 0;
Expand All @@ -50,15 +57,15 @@ uint8_t sm4_get_dir(uint8_t axis)
switch (axis)
{
#if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3))
case 0: return (PORTL & 2)?0:1;
case 1: return (PORTL & 1)?0:1;
case 2: return (PORTL & 4)?0:1;
case 3: return (PORTL & 64)?1:0;
case 0: return (PORTL & 2)?XDIR;
case 1: return (PORTL & 1)?YDIR;
case 2: return (PORTL & 4)?ZDIR;
case 3: return (PORTL & 64)?EDIR;
#elif ((MOTHERBOARD == BOARD_EINSY_1_0a))
case 0: return (PORTL & 1)?1:0;
case 1: return (PORTL & 2)?0:1;
case 2: return (PORTL & 4)?1:0;
case 3: return (PORTL & 64)?0:1;
case 0: return (PORTL & 1)?XDIR;
case 1: return (PORTL & 2)?YDIR;
case 2: return (PORTL & 4)?ZDIR;
case 3: return (PORTL & 64)?EDIR;
#endif
}
return 0;
Expand All @@ -69,15 +76,15 @@ void sm4_set_dir(uint8_t axis, uint8_t dir)
switch (axis)
{
#if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3))
case 0: if (!dir) PORTL |= 2; else PORTL &= ~2; break;
case 1: if (!dir) PORTL |= 1; else PORTL &= ~1; break;
case 2: if (!dir) PORTL |= 4; else PORTL &= ~4; break;
case 3: if (dir) PORTL |= 64; else PORTL &= ~64; break;
case 0: if (dir == INVERT_X_DIR) PORTL |= 2; else PORTL &= ~2; break;
case 1: if (dir == INVERT_Y_DIR) PORTL |= 1; else PORTL &= ~1; break;
case 2: if (dir == INVERT_Z_DIR) PORTL |= 4; else PORTL &= ~4; break;
case 3: if (dir == INVERT_E0_DIR) PORTL |= 64; else PORTL &= ~64; break;
#elif ((MOTHERBOARD == BOARD_EINSY_1_0a))
case 0: if (dir) PORTL |= 1; else PORTL &= ~1; break;
case 1: if (!dir) PORTL |= 2; else PORTL &= ~2; break;
case 2: if (dir) PORTL |= 4; else PORTL &= ~4; break;
case 3: if (!dir) PORTL |= 64; else PORTL &= ~64; break;
case 0: if (dir == INVERT_X_DIR) PORTL |= 1; else PORTL &= ~1; break;
case 1: if (dir == INVERT_Y_DIR) PORTL |= 2; else PORTL &= ~2; break;
case 2: if (dir == INVERT_Z_DIR) PORTL |= 4; else PORTL &= ~4; break;
case 3: if (dir == INVERT_E0_DIR) PORTL |= 64; else PORTL &= ~64; break;
#endif
}
asm("nop");
Expand All @@ -93,13 +100,13 @@ uint8_t sm4_get_dir_bits(void)
if (portL & 1) dir_bits |= 2;
if (portL & 4) dir_bits |= 4;
if (portL & 64) dir_bits |= 8;
dir_bits ^= 0x07; //invert XYZ, do not invert E
dir_bits ^= dir_mask;
#elif ((MOTHERBOARD == BOARD_EINSY_1_0a))
if (portL & 1) dir_bits |= 1;
if (portL & 2) dir_bits |= 2;
if (portL & 4) dir_bits |= 4;
if (portL & 64) dir_bits |= 8;
dir_bits ^= 0x0a; //invert YE, do not invert XZ
dir_bits ^= dir_mask;
#endif
return dir_bits;
}
Expand All @@ -110,13 +117,13 @@ void sm4_set_dir_bits(uint8_t dir_bits)
portL &= 0xb8; //set direction bits to zero
//TODO -optimize in asm
#if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3))
dir_bits ^= 0x07; //invert XYZ, do not invert E
dir_bits ^= dir_mask;
if (dir_bits & 1) portL |= 2; //set X direction bit
if (dir_bits & 2) portL |= 1; //set Y direction bit
if (dir_bits & 4) portL |= 4; //set Z direction bit
if (dir_bits & 8) portL |= 64; //set E direction bit
#elif ((MOTHERBOARD == BOARD_EINSY_1_0a))
dir_bits ^= 0x0a; //invert YE, do not invert XZ
dir_bits ^= dir_mask;
if (dir_bits & 1) portL |= 1; //set X direction bit
if (dir_bits & 2) portL |= 2; //set Y direction bit
if (dir_bits & 4) portL |= 4; //set Z direction bit
Expand Down

0 comments on commit d8756d4

Please sign in to comment.