Skip to content

Commit a8f3ef3

Browse files
committed
squash stepper_control driver
Signed-off-by: Jilay Pandya <[email protected]>
1 parent f789bf1 commit a8f3ef3

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

drivers/stepper_control/zephyr_stepper_motion_control/stepper_control.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ static int z_stepper_motion_control_move_to(const struct device *dev, int32_t mi
150150
return z_stepper_motion_control_move_by(dev, steps_to_move);
151151
}
152152

153-
static int z_stepper_motion_control_run(const struct device *dev, const enum stepper_direction direction)
153+
static int z_stepper_motion_control_run(const struct device *dev,
154+
const enum stepper_direction direction)
154155
{
155156
const struct stepper_motion_control_config *config = dev->config;
156157
struct stepper_motion_control_data *data = dev->data;
@@ -186,7 +187,8 @@ static int z_stepper_motion_control_stop(const struct device *dev)
186187
return 0;
187188
}
188189

189-
static int z_stepper_motion_control_set_reference_position(const struct device *dev, int32_t position)
190+
static int z_stepper_motion_control_set_reference_position(const struct device *dev,
191+
int32_t position)
190192
{
191193
struct stepper_motion_control_data *data = dev->data;
192194

@@ -207,7 +209,7 @@ static int z_stepper_motion_control_get_actual_position(const struct device *dev
207209
}
208210

209211
static int z_stepper_motion_control_set_step_interval(const struct device *dev,
210-
uint64_t microstep_interval_ns)
212+
uint64_t microstep_interval_ns)
211213
{
212214
const struct stepper_motion_control_config *config = dev->config;
213215
struct stepper_motion_control_data *data = dev->data;
@@ -289,7 +291,8 @@ static void velocity_mode_task(const struct device *dev)
289291
}
290292
}
291293

292-
static int z_stepper_motion_control_set_mode(const struct device *dev, enum stepper_motion_control_mode mode)
294+
static int z_stepper_motion_control_set_mode(const struct device *dev,
295+
enum stepper_motion_control_mode mode)
293296
{
294297
if (mode == STEPPER_MOTION_CONTROL_MODE_RAMP) {
295298
return -ENOTSUP;
@@ -298,8 +301,8 @@ static int z_stepper_motion_control_set_mode(const struct device *dev, enum step
298301
}
299302

300303
static int z_stepper_motion_control_set_event_callback(const struct device *dev,
301-
stepper_motion_control_event_callback_t cb,
302-
void *user_data)
304+
stepper_motion_control_event_callback_t cb,
305+
void *user_data)
303306
{
304307
struct stepper_motion_control_data *data = dev->data;
305308

@@ -346,7 +349,8 @@ static int stepper_motion_control_init(const struct device *dev)
346349
}
347350
#ifdef CONFIG_ZEPHYR_STEPPER_MOTION_CONTROL_GENERATE_ISR_SAFE_EVENTS
348351

349-
k_msgq_init(&data->event_msgq, data->event_msgq_buffer, sizeof(enum stepper_motion_control_event),
352+
k_msgq_init(&data->event_msgq, data->event_msgq_buffer,
353+
sizeof(enum stepper_motion_control_event),
350354
CONFIG_ZEPHYR_STEPPER_MOTION_CONTROL_EVENT_QUEUE_LEN);
351355
k_work_init(&data->event_callback_work, stepper_work_event_handler);
352356
#endif /* CONFIG_ZEPHYR_STEPPER_MOTION_CONTROL_GENERATE_ISR_SAFE_EVENTS */
@@ -368,21 +372,22 @@ static DEVICE_API(stepper_motion_control, stepper_motion_control_api) = {
368372
.set_event_callback = z_stepper_motion_control_set_event_callback,
369373
};
370374

371-
#define STEPPER_MOTION_CONTROL_DEFINE(inst) \
372-
static const struct stepper_motion_control_config stepper_motion_control_config_##inst = { \
375+
#define STEPPER_MOTION_CONTROL_DEFINE(inst) \
376+
static const struct stepper_motion_control_config stepper_motion_control_config_##inst = { \
373377
.stepper = DEVICE_DT_GET(DT_INST_CHILD(inst, stepper)), \
374378
.timing_config.counter = \
375379
DEVICE_DT_GET_OR_NULL(DT_PHANDLE(DT_DRV_INST(inst), counter)), \
376380
.timing_source = COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, counter), \
377381
(&step_counter_timing_source_api), (&step_work_timing_source_api)), \
378382
}; \
379-
struct stepper_motion_control_data stepper_motion_control_data_##inst = { \
383+
struct stepper_motion_control_data stepper_motion_control_data_##inst = { \
380384
.timing_data.microstep_interval_ns = DT_INST_PROP(inst, step_tick_ns), \
381385
.timing_data.motion_control_dev = DEVICE_DT_GET(DT_DRV_INST(inst)), \
382386
.timing_data.stepper_handle_timing_signal_cb = stepper_handle_timing_signal, \
383387
}; \
384-
DEVICE_DT_INST_DEFINE(inst, stepper_motion_control_init, NULL, &stepper_motion_control_data_##inst, \
385-
&stepper_motion_control_config_##inst, POST_KERNEL, \
388+
DEVICE_DT_INST_DEFINE(inst, stepper_motion_control_init, NULL, \
389+
&stepper_motion_control_data_##inst, \
390+
&stepper_motion_control_config_##inst, POST_KERNEL, \
386391
CONFIG_STEPPER_CONTROL_INIT_PRIORITY, &stepper_motion_control_api);
387392

388393
DT_INST_FOREACH_STATUS_OKAY(STEPPER_MOTION_CONTROL_DEFINE)

samples/drivers/stepper/generic/src/main.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
LOG_MODULE_REGISTER(stepper, CONFIG_STEPPER_LOG_LEVEL);
1515

1616
static const struct device *stepper = DEVICE_DT_GET(DT_ALIAS(stepper));
17-
static const struct device *stepper_motion_control = DEVICE_DT_GET(DT_ALIAS(stepper_motion_control));
17+
static const struct device *stepper_motion_control =
18+
DEVICE_DT_GET(DT_ALIAS(stepper_motion_control));
1819

1920
enum stepper_mode {
2021
STEPPER_MODE_ENABLE,
@@ -34,7 +35,8 @@ static int32_t ping_pong_target_position =
3435
static K_SEM_DEFINE(stepper_generic_sem, 0, 1);
3536

3637
static void stepper_motion_control_callback(const struct device *dev,
37-
const enum stepper_motion_control_event event, void *user_data)
38+
const enum stepper_motion_control_event event,
39+
void *user_data)
3840
{
3941
switch (event) {
4042
case STEPPER_MOTION_CONTROL_EVENT_STEPS_COMPLETED:
@@ -78,7 +80,8 @@ int main(void)
7880
return -ENODEV;
7981
}
8082

81-
stepper_motion_control_set_event_callback(stepper_motion_control, stepper_motion_control_callback, NULL);
83+
stepper_motion_control_set_event_callback(stepper_motion_control,
84+
stepper_motion_control_callback, NULL);
8285
stepper_motion_control_set_reference_position(stepper_motion_control, 0);
8386
stepper_motion_control_set_step_interval(stepper_motion_control, CONFIG_STEP_INTERVAL_NS);
8487

@@ -94,21 +97,25 @@ int main(void)
9497
LOG_INF("mode: stop\n");
9598
break;
9699
case STEPPER_MODE_ROTATE_CW:
97-
stepper_motion_control_run(stepper_motion_control, STEPPER_DIRECTION_POSITIVE);
100+
stepper_motion_control_run(stepper_motion_control,
101+
STEPPER_DIRECTION_POSITIVE);
98102
LOG_INF("mode: rotate cw\n");
99103
break;
100104
case STEPPER_MODE_ROTATE_CCW:
101-
stepper_motion_control_run(stepper_motion_control, STEPPER_DIRECTION_NEGATIVE);
105+
stepper_motion_control_run(stepper_motion_control,
106+
STEPPER_DIRECTION_NEGATIVE);
102107
LOG_INF("mode: rotate ccw\n");
103108
break;
104109
case STEPPER_MODE_PING_PONG_RELATIVE:
105110
ping_pong_target_position *= -1;
106-
stepper_motion_control_move_by(stepper_motion_control, ping_pong_target_position);
111+
stepper_motion_control_move_by(stepper_motion_control,
112+
ping_pong_target_position);
107113
LOG_INF("mode: ping pong relative\n");
108114
break;
109115
case STEPPER_MODE_PING_PONG_ABSOLUTE:
110116
ping_pong_target_position *= -1;
111-
stepper_motion_control_move_to(stepper_motion_control, ping_pong_target_position);
117+
stepper_motion_control_move_to(stepper_motion_control,
118+
ping_pong_target_position);
112119
LOG_INF("mode: ping pong absolute\n");
113120
break;
114121
case STEPPER_MODE_DISABLE:
@@ -125,7 +132,8 @@ static void monitor_thread(void)
125132
for (;;) {
126133
int32_t actual_position;
127134

128-
stepper_motion_control_get_actual_position(stepper_motion_control, &actual_position);
135+
stepper_motion_control_get_actual_position(stepper_motion_control,
136+
&actual_position);
129137
LOG_DBG("Actual position: %d\n", actual_position);
130138
k_sleep(K_MSEC(CONFIG_MONITOR_THREAD_TIMEOUT_MS));
131139
}

0 commit comments

Comments
 (0)