diff --git a/Makefile b/Makefile index a56244d..149d70d 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ OBJCOPY = $(ARCH)objcopy OPTIMIZE = -Os -ffunction-sections -finline-functions-called-once -mcall-prologues # OPTIMIZE = -O0 -CFLAGS = -g -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -save-temps +CFLAGS = -g -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -save-temps -Winline LDFLAGS = -Wl,--as-needed -Wl,--gc-sections LIBS = -lm LIBDEPS = diff --git a/dda_maths.h b/dda_maths.h index 23d284c..01c0023 100644 --- a/dda_maths.h +++ b/dda_maths.h @@ -13,14 +13,36 @@ const int32_t muldivQR(int32_t multiplicand, uint32_t qn, uint32_t rn, uint32_t divisor); -// convert micrometer distances to motor step distances -#define um_to_steps_x(distance) muldivQR(distance, \ - STEPS_PER_M_X / 1000000UL, STEPS_PER_M_X % 1000000UL, 1000000UL); -#define um_to_steps_y(distance) muldivQR(distance, \ - STEPS_PER_M_Y / 1000000UL, STEPS_PER_M_Y % 1000000UL, 1000000UL); -#define um_to_steps_z(distance) muldivQR(distance, \ - STEPS_PER_M_Z / 1000000UL, STEPS_PER_M_Z % 1000000UL, 1000000UL); -#define um_to_steps_e(distance) muldivQR(distance, \ - STEPS_PER_M_E / 1000000UL, STEPS_PER_M_E % 1000000UL, 1000000UL); +/* + micrometer distance <=> motor step distance conversions +*/ +// Like shown in the patch attached to this post: +// http://forums.reprap.org/read.php?147,89710,130225#msg-130225 , +// it might be worth pre-calculating muldivQR()'s qn and rn in dda_init() +// as soon as STEPS_PER_M_{XYZE} is no longer a compile-time variable. + +static int32_t um_to_steps_x(int32_t) __attribute__ ((always_inline)); +inline int32_t um_to_steps_x(int32_t distance) { + return muldivQR(distance, STEPS_PER_M_X / 1000000UL, + STEPS_PER_M_X % 1000000UL, 1000000UL); +} + +static int32_t um_to_steps_y(int32_t) __attribute__ ((always_inline)); +inline int32_t um_to_steps_y(int32_t distance) { + return muldivQR(distance, STEPS_PER_M_Y / 1000000UL, + STEPS_PER_M_Y % 1000000UL, 1000000UL); +} + +static int32_t um_to_steps_z(int32_t) __attribute__ ((always_inline)); +inline int32_t um_to_steps_z(int32_t distance) { + return muldivQR(distance, STEPS_PER_M_Z / 1000000UL, + STEPS_PER_M_Z % 1000000UL, 1000000UL); +} + +static int32_t um_to_steps_e(int32_t) __attribute__ ((always_inline)); +inline int32_t um_to_steps_e(int32_t distance) { + return muldivQR(distance, STEPS_PER_M_E / 1000000UL, + STEPS_PER_M_E % 1000000UL, 1000000UL); +} #endif /* _DDA_MATHS_H */