Skip to content

Commit c0862d6

Browse files
committed
drivers: stepper: tmc5xxx: introduce stop function
Introduce stop function in tmc5xxx Signed-off-by: Jilay Pandya <[email protected]>
1 parent 9a0ddfc commit c0862d6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

drivers/stepper/adi_tmc/tmc50xx.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static void stallguard_work_handler(struct k_work *work)
176176
}
177177
}
178178

179-
180179
static void execute_callback(const struct device *dev, const enum stepper_event event)
181180
{
182181
struct tmc50xx_stepper_data *data = dev->data;
@@ -548,6 +547,23 @@ static int tmc50xx_stepper_run(const struct device *dev, const enum stepper_dire
548547
return 0;
549548
}
550549

550+
static int tmc50xx_stepper_stop(const struct device *dev)
551+
{
552+
const struct tmc50xx_stepper_config *config = dev->config;
553+
int err;
554+
555+
err = tmc50xx_write(config->controller, TMC50XX_RAMPMODE(config->index),
556+
TMC5XXX_RAMPMODE_POSITIVE_VELOCITY_MODE);
557+
if (err != 0) {
558+
return -EIO;
559+
}
560+
err = tmc50xx_write(config->controller, TMC50XX_VMAX(config->index), 0);
561+
if (err != 0) {
562+
return -EIO;
563+
}
564+
return err;
565+
}
566+
551567
#ifdef CONFIG_STEPPER_ADI_TMC50XX_RAMP_GEN
552568

553569
int tmc50xx_stepper_set_ramp(const struct device *dev,
@@ -709,6 +725,7 @@ static DEVICE_API(stepper, tmc50xx_stepper_api) = {
709725
.get_actual_position = tmc50xx_stepper_get_actual_position,
710726
.move_to = tmc50xx_stepper_move_to,
711727
.run = tmc50xx_stepper_run,
728+
.stop = tmc50xx_stepper_stop,
712729
.set_event_callback = tmc50xx_stepper_set_event_callback,
713730
};
714731

drivers/stepper/adi_tmc/tmc51xx/tmc51xx.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,23 @@ static int tmc51xx_init(const struct device *dev)
786786
return 0;
787787
}
788788

789+
static int tmc51xx_stepper_stop(const struct device *dev)
790+
{
791+
const struct tmc51xx_stepper_config *config = dev->config;
792+
int err;
793+
794+
err = tmc51xx_write(config->controller, TMC51XX_RAMPMODE,
795+
TMC5XXX_RAMPMODE_POSITIVE_VELOCITY_MODE);
796+
if (err != 0) {
797+
return -EIO;
798+
}
799+
err = tmc51xx_write(config->controller, TMC51XX_VMAX, 0);
800+
if (err != 0) {
801+
return -EIO;
802+
}
803+
return err;
804+
}
805+
789806
static DEVICE_API(stepper, tmc51xx_api) = {
790807
.enable = tmc51xx_stepper_enable,
791808
.disable = tmc51xx_stepper_disable,
@@ -797,6 +814,7 @@ static DEVICE_API(stepper, tmc51xx_api) = {
797814
.get_actual_position = tmc51xx_stepper_get_actual_position,
798815
.move_to = tmc51xx_stepper_move_to,
799816
.run = tmc51xx_stepper_run,
817+
.stop = tmc51xx_stepper_stop,
800818
.set_event_callback = tmc51xx_stepper_set_event_callback,
801819
};
802820

0 commit comments

Comments
 (0)