endstop: Rename mcu end_stop commands to endstop

Rename the commands.

The main reason for this change is to force a micro-controller code
updated (due to important bugfix in 7fefe52d).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-07-12 08:09:30 -04:00
parent 7fefe52df7
commit 28aa2f507a
3 changed files with 51 additions and 51 deletions

View File

@ -161,15 +161,15 @@ This section lists some commonly used config commands.
clock ticks since the last step. It is used as a check on the clock ticks since the last step. It is used as a check on the
maximum stepper velocity that a stepper may have before stopping. maximum stepper velocity that a stepper may have before stopping.
* `config_end_stop oid=%c pin=%c pull_up=%c stepper_count=%c` : This * `config_endstop oid=%c pin=%c pull_up=%c stepper_count=%c` : This
command creates an internal "endstop" object. It is used to specify command creates an internal "endstop" object. It is used to specify
the endstop pins and to enable "homing" operations (see the the endstop pins and to enable "homing" operations (see the
end_stop_home command below). The command will configure the endstop_home command below). The command will configure the
specified pin in digital input mode. The 'pull_up' parameter specified pin in digital input mode. The 'pull_up' parameter
determines whether hardware provided pullup resistors for the pin determines whether hardware provided pullup resistors for the pin
(if available) will be enabled. The 'stepper_count' parameter (if available) will be enabled. The 'stepper_count' parameter
specifies the maximum number of steppers that this endstop may need specifies the maximum number of steppers that this endstop may need
to halt during a homing operation (see end_stop_home below). to halt during a homing operation (see endstop_home below).
* `config_spi oid=%c bus=%u pin=%u mode=%u rate=%u shutdown_msg=%*s` : * `config_spi oid=%c bus=%u pin=%u mode=%u rate=%u shutdown_msg=%*s` :
This command creates an internal SPI object. It is used with This command creates an internal SPI object. It is used with
@ -260,9 +260,9 @@ Stepper commands
number of steps generated with dir=1 minus the total number of steps number of steps generated with dir=1 minus the total number of steps
generated with dir=0. generated with dir=0.
* `end_stop_home oid=%c clock=%u sample_ticks=%u sample_count=%c * `endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c
rest_ticks=%u pin_value=%c` : This command is used during stepper rest_ticks=%u pin_value=%c` : This command is used during stepper
"homing" operations. To use this command a 'config_end_stop' command "homing" operations. To use this command a 'config_endstop' command
with the same 'oid' parameter must have been issued during with the same 'oid' parameter must have been issued during
micro-controller configuration. When this command is invoked, the micro-controller configuration. When this command is invoked, the
micro-controller will sample the endstop pin every 'rest_ticks' micro-controller will sample the endstop pin every 'rest_ticks'

View File

@ -155,21 +155,21 @@ class MCU_endstop:
def _build_config(self): def _build_config(self):
self._oid = self._mcu.create_oid() self._oid = self._mcu.create_oid()
self._mcu.add_config_cmd( self._mcu.add_config_cmd(
"config_end_stop oid=%d pin=%s pull_up=%d stepper_count=%d" % ( "config_endstop oid=%d pin=%s pull_up=%d stepper_count=%d" % (
self._oid, self._pin, self._pullup, len(self._steppers))) self._oid, self._pin, self._pullup, len(self._steppers)))
self._mcu.add_config_cmd( self._mcu.add_config_cmd(
"end_stop_home oid=%d clock=0 sample_ticks=0 sample_count=0" "endstop_home oid=%d clock=0 sample_ticks=0 sample_count=0"
" rest_ticks=0 pin_value=0" % (self._oid,), is_init=True) " rest_ticks=0 pin_value=0" % (self._oid,), is_init=True)
for i, s in enumerate(self._steppers): for i, s in enumerate(self._steppers):
self._mcu.add_config_cmd( self._mcu.add_config_cmd(
"end_stop_set_stepper oid=%d pos=%d stepper_oid=%d" % ( "endstop_set_stepper oid=%d pos=%d stepper_oid=%d" % (
self._oid, i, s.get_oid()), is_init=True) self._oid, i, s.get_oid()), is_init=True)
cmd_queue = self._mcu.alloc_command_queue() cmd_queue = self._mcu.alloc_command_queue()
self._home_cmd = self._mcu.lookup_command( self._home_cmd = self._mcu.lookup_command(
"end_stop_home oid=%c clock=%u sample_ticks=%u sample_count=%c" "endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c"
" rest_ticks=%u pin_value=%c", cq=cmd_queue) " rest_ticks=%u pin_value=%c", cq=cmd_queue)
self._query_cmd = self._mcu.lookup_command( self._query_cmd = self._mcu.lookup_command(
"end_stop_query_state oid=%c", cq=cmd_queue) "endstop_query_state oid=%c", cq=cmd_queue)
def home_prepare(self): def home_prepare(self):
pass pass
def home_start(self, print_time, sample_time, sample_count, rest_time, def home_start(self, print_time, sample_time, sample_count, rest_time,
@ -183,16 +183,16 @@ class MCU_endstop:
self._home_end_time = self._reactor.NEVER self._home_end_time = self._reactor.NEVER
self._trigger_completion = self._reactor.completion() self._trigger_completion = self._reactor.completion()
self._home_completion = self._reactor.completion() self._home_completion = self._reactor.completion()
self._mcu.register_response(self._handle_end_stop_state, self._mcu.register_response(self._handle_endstop_state,
"end_stop_state", self._oid) "endstop_state", self._oid)
self._home_cmd.send( self._home_cmd.send(
[self._oid, clock, self._mcu.seconds_to_clock(sample_time), [self._oid, clock, self._mcu.seconds_to_clock(sample_time),
sample_count, rest_ticks, triggered ^ self._invert], sample_count, rest_ticks, triggered ^ self._invert],
reqclock=clock) reqclock=clock)
self._home_completion = self._reactor.register_callback( self._home_completion = self._reactor.register_callback(
self._home_retry) self._home_retry)
def _handle_end_stop_state(self, params): def _handle_endstop_state(self, params):
logging.debug("end_stop_state %s", params) logging.debug("endstop_state %s", params)
if params['#sent_time'] >= self._min_query_time: if params['#sent_time'] >= self._min_query_time:
if params['homing']: if params['homing']:
self._last_sent_time = params['#sent_time'] self._last_sent_time = params['#sent_time']
@ -222,7 +222,7 @@ class MCU_endstop:
def home_wait(self, home_end_time): def home_wait(self, home_end_time):
self._home_end_time = home_end_time self._home_end_time = home_end_time
did_trigger = self._home_completion.wait() did_trigger = self._home_completion.wait()
self._mcu.register_response(None, "end_stop_state", self._oid) self._mcu.register_response(None, "endstop_state", self._oid)
self._home_cmd.send([self._oid, 0, 0, 0, 0, 0]) self._home_cmd.send([self._oid, 0, 0, 0, 0, 0])
for s in self._steppers: for s in self._steppers:
s.note_homing_end(did_trigger=did_trigger) s.note_homing_end(did_trigger=did_trigger)
@ -235,7 +235,7 @@ class MCU_endstop:
if self._mcu.is_fileoutput(): if self._mcu.is_fileoutput():
return 0 return 0
params = self._query_cmd.send_with_response( params = self._query_cmd.send_with_response(
[self._oid], "end_stop_state", self._oid, minclock=clock) [self._oid], "endstop_state", self._oid, minclock=clock)
return params['pin_value'] ^ self._invert return params['pin_value'] ^ self._invert
class MCU_digital_out: class MCU_digital_out:

View File

@ -11,7 +11,7 @@
#include "sched.h" // struct timer #include "sched.h" // struct timer
#include "stepper.h" // stepper_stop #include "stepper.h" // stepper_stop
struct end_stop { struct endstop {
struct timer time; struct timer time;
struct gpio_in pin; struct gpio_in pin;
uint32_t rest_time, sample_time, nextwake; uint32_t rest_time, sample_time, nextwake;
@ -24,7 +24,7 @@ enum { ESF_PIN_HIGH=1<<0, ESF_HOMING=1<<1, ESF_REPORT=1<<2 };
static struct task_wake endstop_wake; static struct task_wake endstop_wake;
static void static void
stop_steppers(struct end_stop *e) stop_steppers(struct endstop *e)
{ {
e->flags = ESF_REPORT; e->flags = ESF_REPORT;
uint8_t count = e->stepper_count; uint8_t count = e->stepper_count;
@ -34,13 +34,13 @@ stop_steppers(struct end_stop *e)
sched_wake_task(&endstop_wake); sched_wake_task(&endstop_wake);
} }
static uint_fast8_t end_stop_oversample_event(struct timer *t); static uint_fast8_t endstop_oversample_event(struct timer *t);
// Timer callback for an end stop // Timer callback for an end stop
static uint_fast8_t static uint_fast8_t
end_stop_event(struct timer *t) endstop_event(struct timer *t)
{ {
struct end_stop *e = container_of(t, struct end_stop, time); struct endstop *e = container_of(t, struct endstop, time);
uint8_t val = gpio_in_read(e->pin); uint8_t val = gpio_in_read(e->pin);
uint32_t nextwake = e->time.waketime + e->rest_time; uint32_t nextwake = e->time.waketime + e->rest_time;
if ((val ? ~e->flags : e->flags) & ESF_PIN_HIGH) { if ((val ? ~e->flags : e->flags) & ESF_PIN_HIGH) {
@ -49,19 +49,19 @@ end_stop_event(struct timer *t)
return SF_RESCHEDULE; return SF_RESCHEDULE;
} }
e->nextwake = nextwake; e->nextwake = nextwake;
e->time.func = end_stop_oversample_event; e->time.func = endstop_oversample_event;
return end_stop_oversample_event(t); return endstop_oversample_event(t);
} }
// Timer callback for an end stop that is sampling extra times // Timer callback for an end stop that is sampling extra times
static uint_fast8_t static uint_fast8_t
end_stop_oversample_event(struct timer *t) endstop_oversample_event(struct timer *t)
{ {
struct end_stop *e = container_of(t, struct end_stop, time); struct endstop *e = container_of(t, struct endstop, time);
uint8_t val = gpio_in_read(e->pin); uint8_t val = gpio_in_read(e->pin);
if ((val ? ~e->flags : e->flags) & ESF_PIN_HIGH) { if ((val ? ~e->flags : e->flags) & ESF_PIN_HIGH) {
// No longer matching - reschedule for the next attempt // No longer matching - reschedule for the next attempt
e->time.func = end_stop_event; e->time.func = endstop_event;
e->time.waketime = e->nextwake; e->time.waketime = e->nextwake;
e->trigger_count = e->sample_count; e->trigger_count = e->sample_count;
return SF_RESCHEDULE; return SF_RESCHEDULE;
@ -77,36 +77,36 @@ end_stop_oversample_event(struct timer *t)
} }
void void
command_config_end_stop(uint32_t *args) command_config_endstop(uint32_t *args)
{ {
uint8_t stepper_count = args[3]; uint8_t stepper_count = args[3];
struct end_stop *e = oid_alloc( struct endstop *e = oid_alloc(
args[0], command_config_end_stop args[0], command_config_endstop
, sizeof(*e) + sizeof(e->steppers[0]) * stepper_count); , sizeof(*e) + sizeof(e->steppers[0]) * stepper_count);
e->pin = gpio_in_setup(args[1], args[2]); e->pin = gpio_in_setup(args[1], args[2]);
e->stepper_count = stepper_count; e->stepper_count = stepper_count;
e->sample_count = 1; e->sample_count = 1;
} }
DECL_COMMAND(command_config_end_stop, DECL_COMMAND(command_config_endstop,
"config_end_stop oid=%c pin=%c pull_up=%c stepper_count=%c"); "config_endstop oid=%c pin=%c pull_up=%c stepper_count=%c");
void void
command_end_stop_set_stepper(uint32_t *args) command_endstop_set_stepper(uint32_t *args)
{ {
struct end_stop *e = oid_lookup(args[0], command_config_end_stop); struct endstop *e = oid_lookup(args[0], command_config_endstop);
uint8_t pos = args[1]; uint8_t pos = args[1];
if (pos >= e->stepper_count) if (pos >= e->stepper_count)
shutdown("Set stepper past maximum stepper count"); shutdown("Set stepper past maximum stepper count");
e->steppers[pos] = stepper_oid_lookup(args[2]); e->steppers[pos] = stepper_oid_lookup(args[2]);
} }
DECL_COMMAND(command_end_stop_set_stepper, DECL_COMMAND(command_endstop_set_stepper,
"end_stop_set_stepper oid=%c pos=%c stepper_oid=%c"); "endstop_set_stepper oid=%c pos=%c stepper_oid=%c");
// Home an axis // Home an axis
void void
command_end_stop_home(uint32_t *args) command_endstop_home(uint32_t *args)
{ {
struct end_stop *e = oid_lookup(args[0], command_config_end_stop); struct endstop *e = oid_lookup(args[0], command_config_endstop);
sched_del_timer(&e->time); sched_del_timer(&e->time);
e->time.waketime = args[1]; e->time.waketime = args[1];
e->sample_time = args[2]; e->sample_time = args[2];
@ -117,47 +117,47 @@ command_end_stop_home(uint32_t *args)
return; return;
} }
e->rest_time = args[4]; e->rest_time = args[4];
e->time.func = end_stop_event; e->time.func = endstop_event;
e->trigger_count = e->sample_count; e->trigger_count = e->sample_count;
e->flags = ESF_HOMING | (args[5] ? ESF_PIN_HIGH : 0); e->flags = ESF_HOMING | (args[5] ? ESF_PIN_HIGH : 0);
sched_add_timer(&e->time); sched_add_timer(&e->time);
} }
DECL_COMMAND(command_end_stop_home, DECL_COMMAND(command_endstop_home,
"end_stop_home oid=%c clock=%u sample_ticks=%u sample_count=%c" "endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c"
" rest_ticks=%u pin_value=%c"); " rest_ticks=%u pin_value=%c");
static void static void
end_stop_report(uint8_t oid, struct end_stop *e) endstop_report(uint8_t oid, struct endstop *e)
{ {
irq_disable(); irq_disable();
uint8_t eflags = e->flags; uint8_t eflags = e->flags;
e->flags &= ~ESF_REPORT; e->flags &= ~ESF_REPORT;
irq_enable(); irq_enable();
sendf("end_stop_state oid=%c homing=%c pin_value=%c" sendf("endstop_state oid=%c homing=%c pin_value=%c"
, oid, !!(eflags & ESF_HOMING), gpio_in_read(e->pin)); , oid, !!(eflags & ESF_HOMING), gpio_in_read(e->pin));
} }
void void
command_end_stop_query_state(uint32_t *args) command_endstop_query_state(uint32_t *args)
{ {
uint8_t oid = args[0]; uint8_t oid = args[0];
struct end_stop *e = oid_lookup(oid, command_config_end_stop); struct endstop *e = oid_lookup(oid, command_config_endstop);
end_stop_report(oid, e); endstop_report(oid, e);
} }
DECL_COMMAND(command_end_stop_query_state, "end_stop_query_state oid=%c"); DECL_COMMAND(command_endstop_query_state, "endstop_query_state oid=%c");
void void
end_stop_task(void) endstop_task(void)
{ {
if (!sched_check_wake(&endstop_wake)) if (!sched_check_wake(&endstop_wake))
return; return;
uint8_t oid; uint8_t oid;
struct end_stop *e; struct endstop *e;
foreach_oid(oid, e, command_config_end_stop) { foreach_oid(oid, e, command_config_endstop) {
if (!(e->flags & ESF_REPORT)) if (!(e->flags & ESF_REPORT))
continue; continue;
end_stop_report(oid, e); endstop_report(oid, e);
} }
} }
DECL_TASK(end_stop_task); DECL_TASK(endstop_task);