Browse Source

drivers: stepper: tmc5xxx: introduce stop function

Introduce stop function in tmc5xxx

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
pull/87630/head
Jilay Pandya 3 weeks ago committed by Benjamin Cabé
parent
commit
08dd7c519a
  1. 21
      drivers/stepper/adi_tmc/tmc50xx.c
  2. 18
      drivers/stepper/adi_tmc/tmc51xx/tmc51xx.c

21
drivers/stepper/adi_tmc/tmc50xx.c

@ -176,7 +176,6 @@ static void stallguard_work_handler(struct k_work *work) @@ -176,7 +176,6 @@ static void stallguard_work_handler(struct k_work *work)
}
}
static void execute_callback(const struct device *dev, const enum stepper_event event)
{
struct tmc50xx_stepper_data *data = dev->data;
@ -543,6 +542,25 @@ static int tmc50xx_stepper_run(const struct device *dev, const enum stepper_dire @@ -543,6 +542,25 @@ static int tmc50xx_stepper_run(const struct device *dev, const enum stepper_dire
return 0;
}
static int tmc50xx_stepper_stop(const struct device *dev)
{
const struct tmc50xx_stepper_config *config = dev->config;
int err;
err = tmc50xx_write(config->controller, TMC50XX_RAMPMODE(config->index),
TMC5XXX_RAMPMODE_POSITIVE_VELOCITY_MODE);
if (err != 0) {
return -EIO;
}
err = tmc50xx_write(config->controller, TMC50XX_VMAX(config->index), 0);
if (err != 0) {
return -EIO;
}
return 0;
}
#ifdef CONFIG_STEPPER_ADI_TMC50XX_RAMP_GEN
int tmc50xx_stepper_set_ramp(const struct device *dev,
@ -704,6 +722,7 @@ static DEVICE_API(stepper, tmc50xx_stepper_api) = { @@ -704,6 +722,7 @@ static DEVICE_API(stepper, tmc50xx_stepper_api) = {
.get_actual_position = tmc50xx_stepper_get_actual_position,
.move_to = tmc50xx_stepper_move_to,
.run = tmc50xx_stepper_run,
.stop = tmc50xx_stepper_stop,
.set_event_callback = tmc50xx_stepper_set_event_callback,
};

18
drivers/stepper/adi_tmc/tmc51xx/tmc51xx.c

@ -781,6 +781,23 @@ static int tmc51xx_init(const struct device *dev) @@ -781,6 +781,23 @@ static int tmc51xx_init(const struct device *dev)
return 0;
}
static int tmc51xx_stepper_stop(const struct device *dev)
{
int err;
err = tmc51xx_write(dev, TMC51XX_RAMPMODE, TMC5XXX_RAMPMODE_POSITIVE_VELOCITY_MODE);
if (err != 0) {
return -EIO;
}
err = tmc51xx_write(dev, TMC51XX_VMAX, 0);
if (err != 0) {
return -EIO;
}
return 0;
}
static DEVICE_API(stepper, tmc51xx_api) = {
.enable = tmc51xx_stepper_enable,
.disable = tmc51xx_stepper_disable,
@ -792,6 +809,7 @@ static DEVICE_API(stepper, tmc51xx_api) = { @@ -792,6 +809,7 @@ static DEVICE_API(stepper, tmc51xx_api) = {
.get_actual_position = tmc51xx_stepper_get_actual_position,
.move_to = tmc51xx_stepper_move_to,
.run = tmc51xx_stepper_run,
.stop = tmc51xx_stepper_stop,
.set_event_callback = tmc51xx_stepper_set_event_callback,
};

Loading…
Cancel
Save