aboutsummaryrefslogtreecommitdiffstats
path: root/src/stepper.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-03-08 11:29:27 -0500
committerKevin O'Connor <kevin@koconnor.net>2017-03-08 13:37:51 -0500
commit37bac916e7dd7159fe731f313859e31e743f7f23 (patch)
tree4456e490c9fc629b8c9ddf483fb19abb891adf89 /src/stepper.c
parentaffdbbf9ca120da415aff2a8e8dea2847800ee39 (diff)
downloadkutter-37bac916e7dd7159fe731f313859e31e743f7f23.tar.gz
kutter-37bac916e7dd7159fe731f313859e31e743f7f23.tar.xz
kutter-37bac916e7dd7159fe731f313859e31e743f7f23.zip
basecmd: Generalize the "move queue" runtime storage
Detect the maximum size of each "move queue" item during the configuration phase instead of using the stepper move struct. This allows the stepper code to be contained entirely in stepper.c and it allows for future run time allocations from other types of objects. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stepper.c')
-rw-r--r--src/stepper.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/stepper.c b/src/stepper.c
index 23a073b1..b97a7a69 100644
--- a/src/stepper.c
+++ b/src/stepper.c
@@ -17,6 +17,16 @@
* Steppers
****************************************************************/
+struct stepper_move {
+ uint32_t interval;
+ int16_t add;
+ uint16_t count;
+ struct stepper_move *next;
+ uint8_t flags;
+};
+
+enum { MF_DIR=1<<0 };
+
struct stepper {
struct timer time;
uint32_t interval;
@@ -30,13 +40,12 @@ struct stepper {
#endif
struct gpio_out step_pin, dir_pin;
uint32_t position;
- struct move *first, **plast;
+ struct stepper_move *first, **plast;
uint32_t min_stop_interval;
// gcc (pre v6) does better optimization when uint8_t are bitfields
uint8_t flags : 8;
};
-enum { MF_DIR=1<<0 };
enum { SF_LAST_DIR=1<<0, SF_NEXT_DIR=1<<1, SF_INVERT_STEP=1<<2, SF_HAVE_ADD=1<<3,
SF_LAST_RESET=1<<4, SF_NO_NEXT_CHECK=1<<5 };
@@ -44,7 +53,7 @@ enum { SF_LAST_DIR=1<<0, SF_NEXT_DIR=1<<1, SF_INVERT_STEP=1<<2, SF_HAVE_ADD=1<<3
static uint_fast8_t
stepper_load_next(struct stepper *s, uint32_t min_next_time)
{
- struct move *m = s->first;
+ struct stepper_move *m = s->first;
if (!m) {
if (s->interval - s->add < s->min_stop_interval
&& !(s->flags & SF_NO_NEXT_CHECK))
@@ -144,6 +153,7 @@ command_config_stepper(uint32_t *args)
s->dir_pin = gpio_out_setup(args[2], 0);
s->min_stop_interval = args[3];
s->position = -STEPPER_POSITION_BIAS;
+ move_request_size(sizeof(struct stepper_move));
}
DECL_COMMAND(command_config_stepper,
"config_stepper oid=%c step_pin=%c dir_pin=%c"
@@ -154,7 +164,7 @@ void
command_queue_step(uint32_t *args)
{
struct stepper *s = lookup_oid(args[0], command_config_stepper);
- struct move *m = move_alloc();
+ struct stepper_move *m = move_alloc();
m->interval = args[1];
m->count = args[2];
if (!m->count)
@@ -244,7 +254,7 @@ stepper_stop(struct stepper *s)
gpio_out_write(s->dir_pin, 0);
gpio_out_write(s->step_pin, s->flags & SF_INVERT_STEP ? 1 : 0);
while (s->first) {
- struct move *next = s->first->next;
+ struct stepper_move *next = s->first->next;
move_free(s->first);
s->first = next;
}