aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-03-04 13:30:06 -0500
committerKevin O'Connor <kevin@koconnor.net>2020-03-04 14:30:41 -0500
commite9e0f59204a5f051ca29d24b9217a86b8d332c31 (patch)
tree70cef9241e9e57c55a40e961600a9827bc60f33a /src
parent63ba7d231eacd231389333de27a7ef66cd31f587 (diff)
downloadkutter-e9e0f59204a5f051ca29d24b9217a86b8d332c31.tar.gz
kutter-e9e0f59204a5f051ca29d24b9217a86b8d332c31.tar.xz
kutter-e9e0f59204a5f051ca29d24b9217a86b8d332c31.zip
stepper: Add some comments on s->position tracking
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/stepper.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/stepper.c b/src/stepper.c
index dfab89df..2e93ccb9 100644
--- a/src/stepper.c
+++ b/src/stepper.c
@@ -62,6 +62,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time)
{
struct stepper_move *m = s->first;
if (!m) {
+ // There is no next move - the queue is empty
if (s->interval - s->add < s->min_stop_interval
&& !(s->flags & SF_NO_NEXT_CHECK))
shutdown("No next step");
@@ -69,6 +70,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time)
return SF_DONE;
}
+ // Load next 'struct stepper_move' into 'struct stepper'
s->next_step_time += m->interval;
s->add = m->add;
s->interval = m->interval + m->add;
@@ -91,6 +93,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time)
}
s->count = (uint32_t)m->count * 2;
}
+ // Add all steps to s->position (stepper_get_position() can calc mid-move)
if (m->flags & MF_DIR) {
s->position = -s->position + m->count;
gpio_out_toggle_noirq(s->dir_pin);
@@ -274,10 +277,12 @@ static uint32_t
stepper_get_position(struct stepper *s)
{
uint32_t position = s->position;
+ // If stepper is mid-move, subtract out steps not yet taken
if (CONFIG_STEP_DELAY <= 0)
position -= s->count;
else
position -= s->count / 2;
+ // The top bit of s->position is an optimized reverse direction flag
if (position & 0x80000000)
return -position;
return position;