Skip to content

Commit e5026d4

Browse files
dipakgmxkartben
authored andcommitted
drivers: stepper: simplify event detection config
Simplified by removing redundant options and enabled automatic fallback to ramp status polling when diag0 pin is unavailable for event detection. Signed-off-by: Dipak Shetty <shetty.dipak@gmx.com>
1 parent b9ba0d2 commit e5026d4

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

drivers/stepper/adi_tmc/Kconfig.tmc_rampgen_template

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
22
# SPDX-License-Identifier: Apache-2.0
33

4-
config STEPPER_ADI_$(module)_RAMPSTAT_POLL
5-
bool "$(module-str) poll ramp status"
6-
depends on STEPPER_ADI_$(module)
7-
default y
8-
help
9-
When enabled, the ramp status will be polled on TMC, to check for events:
10-
- TMC_POS_REACHED_EVENT
11-
- TMC_STOP_SG_EVENT
12-
- TMC_STOP_LEFT_EVENT
13-
- TMC_STOP_RIGHT_EVENT
14-
154
config STEPPER_ADI_$(module)_RAMPSTAT_POLL_INTERVAL_IN_MSEC
165
int "$(module-str) poll ramp status interval in ms"
17-
depends on STEPPER_ADI_$(module)_RAMPSTAT_POLL
6+
depends on !$(dt_compat_any_has_prop,$(DT_COMPAT_ADI_$(module)),diag0-gpios)
187
default 100
198
help
20-
The interval in ms to poll the ramp status on TMC.
9+
When DIAG0 pin is not available, the driver automatically falls back to
10+
polling. This setting controls how frequently (in milliseconds) the driver
11+
polls the ramp status register to detect events like position reached, stall
12+
or end stop triggered.
2113

2214
config STEPPER_ADI_$(module)_RAMPSTAT_POLL_STALLGUARD_LOG
2315
bool "log $(module-str) stallguard"
24-
depends on STEPPER_ADI_$(module)_RAMPSTAT_POLL
2516
default n
2617
help
2718
Enable stallguard log while polling rampstat.

drivers/stepper/adi_tmc/tmc50xx.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ struct tmc50xx_config {
3030
struct tmc50xx_stepper_data {
3131
struct k_work_delayable stallguard_dwork;
3232
/* Work item to run the callback in a thread context. */
33-
#ifdef CONFIG_STEPPER_ADI_TMC50XX_RAMPSTAT_POLL
3433
struct k_work_delayable rampstat_callback_dwork;
35-
#endif
3634
/* device pointer required to access config in k_work */
3735
const struct device *stepper;
3836
stepper_event_callback_t callback;
@@ -177,7 +175,6 @@ static void stallguard_work_handler(struct k_work *work)
177175
}
178176
}
179177

180-
#ifdef CONFIG_STEPPER_ADI_TMC50XX_RAMPSTAT_POLL
181178

182179
static void execute_callback(const struct device *dev, const enum stepper_event event)
183180
{
@@ -297,8 +294,6 @@ static void rampstat_work_handler(struct k_work *work)
297294
}
298295
}
299296

300-
#endif
301-
302297
static int tmc50xx_stepper_enable(const struct device *dev)
303298
{
304299
LOG_DBG("Enabling Stepper motor controller %s", dev->name);
@@ -486,11 +481,9 @@ static int tmc50xx_stepper_move_to(const struct device *dev, const int32_t micro
486481
k_work_reschedule(&data->stallguard_dwork,
487482
K_MSEC(config->sg_velocity_check_interval_ms));
488483
}
489-
#ifdef CONFIG_STEPPER_ADI_TMC50XX_RAMPSTAT_POLL
490484
if (data->callback) {
491485
rampstat_work_reschedule(&data->rampstat_callback_dwork);
492486
}
493-
#endif
494487
return 0;
495488
}
496489

@@ -546,11 +539,9 @@ static int tmc50xx_stepper_run(const struct device *dev, const enum stepper_dire
546539
k_work_reschedule(&data->stallguard_dwork,
547540
K_MSEC(config->sg_velocity_check_interval_ms));
548541
}
549-
#ifdef CONFIG_STEPPER_ADI_TMC50XX_RAMPSTAT_POLL
550542
if (data->callback) {
551543
rampstat_work_reschedule(&data->rampstat_callback_dwork);
552544
}
553-
#endif
554545
return 0;
555546
}
556547

@@ -695,10 +686,8 @@ static int tmc50xx_stepper_init(const struct device *dev)
695686
}
696687
#endif
697688

698-
#if CONFIG_STEPPER_ADI_TMC50XX_RAMPSTAT_POLL
699689
k_work_init_delayable(&data->rampstat_callback_dwork, rampstat_work_handler);
700690
rampstat_work_reschedule(&data->rampstat_callback_dwork);
701-
#endif
702691
err = tmc50xx_stepper_set_micro_step_res(dev, stepper_config->default_micro_step_res);
703692
if (err != 0) {
704693
return -EIO;

0 commit comments

Comments
 (0)