dda_maths.h: make um_to_steps_{xyze}() inline functions.
Size and speed is the same as with #defines, but now there is type checking.
This commit is contained in:
parent
44be918d2a
commit
d49c0745d5
2
Makefile
2
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 =
|
||||
|
|
|
|||
40
dda_maths.h
40
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 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue