aboutsummaryrefslogtreecommitdiffstats
path: root/src/stepper.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-01-09 13:10:23 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-01-09 13:16:42 -0500
commit2ea7c97bbd3680949a2d89c3c9ab3a2552a25b4b (patch)
tree8ef71fd0ed030b1a52b6246aea5dccc5c72c2ce0 /src/stepper.c
parentc0ea0312e548afe1de8a34a59b179db4ead63f36 (diff)
downloadkutter-2ea7c97bbd3680949a2d89c3c9ab3a2552a25b4b.tar.gz
kutter-2ea7c97bbd3680949a2d89c3c9ab3a2552a25b4b.tar.xz
kutter-2ea7c97bbd3680949a2d89c3c9ab3a2552a25b4b.zip
stepper: Support configuring the stepper pulse length from Kconfig
Allow the stepper pulse length to be configured at compile time from the Kconfig menu system. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stepper.c')
-rw-r--r--src/stepper.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/stepper.c b/src/stepper.c
index 2b967413..8356ff24 100644
--- a/src/stepper.c
+++ b/src/stepper.c
@@ -13,6 +13,8 @@
#include "sched.h" // struct timer
#include "stepper.h" // command_config_stepper
+DECL_CONSTANT(STEP_DELAY, CONFIG_STEP_DELAY);
+
/****************************************************************
* Steppers
@@ -32,7 +34,7 @@ struct stepper {
struct timer time;
uint32_t interval;
int16_t add;
-#if CONFIG_NO_UNSTEP_DELAY
+#if !CONFIG_STEP_DELAY
uint16_t count;
#define next_step_time time.waketime
#else
@@ -68,7 +70,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time)
s->next_step_time += m->interval;
s->add = m->add;
s->interval = m->interval + m->add;
- if (CONFIG_NO_UNSTEP_DELAY) {
+ if (!CONFIG_STEP_DELAY) {
// On slow mcus see if the add can be optimized away
s->flags = m->add ? s->flags | SF_HAVE_ADD : s->flags & ~SF_HAVE_ADD;
s->count = m->count;
@@ -98,14 +100,12 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time)
return SF_RESCHEDULE;
}
-#define UNSTEP_TIME timer_from_us(2)
-
// Timer callback - step the given stepper.
uint_fast8_t
stepper_event(struct timer *t)
{
struct stepper *s = container_of(t, struct stepper, time);
- if (CONFIG_NO_UNSTEP_DELAY) {
+ if (!CONFIG_STEP_DELAY) {
// On slower mcus it is possible to simply step and unstep in
// the same timer event.
gpio_out_toggle_noirq(s->step_pin);
@@ -124,7 +124,8 @@ stepper_event(struct timer *t)
}
// On faster mcus, it is necessary to schedule the unstep event
- uint32_t min_next_time = timer_read_time() + UNSTEP_TIME;
+ uint32_t step_delay = timer_from_us(CONFIG_STEP_DELAY);
+ uint32_t min_next_time = timer_read_time() + step_delay;
gpio_out_toggle_noirq(s->step_pin);
s->count--;
if (likely(s->count & 1))
@@ -242,7 +243,7 @@ static uint32_t
stepper_get_position(struct stepper *s)
{
uint32_t position = s->position;
- if (CONFIG_NO_UNSTEP_DELAY)
+ if (!CONFIG_STEP_DELAY)
position -= s->count;
else
position -= s->count / 2;