|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -#define DT_DRV_COMPAT zephyr_gpio_steppers |
| 7 | +#define DT_DRV_COMPAT zephyr_gpio_stepper |
8 | 8 |
|
9 | 9 | #include <zephyr/drivers/gpio.h> |
10 | 10 | #include <zephyr/kernel.h> |
@@ -338,62 +338,50 @@ static int gpio_stepper_enable(const struct device *dev, bool enable) |
338 | 338 | return 0; |
339 | 339 | } |
340 | 340 |
|
341 | | -static int gpio_stepper_motor_controller_init(const struct device *dev) |
| 341 | +static int gpio_stepper_init(const struct device *dev) |
342 | 342 | { |
343 | 343 | struct gpio_stepper_data *data = dev->data; |
344 | 344 | const struct gpio_stepper_config *config = dev->config; |
345 | 345 |
|
346 | 346 | data->dev = dev; |
347 | | - LOG_DBG("Initializing %s gpio_stepper_motor_controller with %d pin", dev->name, |
348 | | - NUM_CONTROL_PINS); |
| 347 | + LOG_DBG("Initializing %s gpio_stepper with %d pin", dev->name, NUM_CONTROL_PINS); |
349 | 348 | for (uint8_t n_pin = 0; n_pin < NUM_CONTROL_PINS; n_pin++) { |
350 | 349 | (void)gpio_pin_configure_dt(&config->control_pins[n_pin], GPIO_OUTPUT_INACTIVE); |
351 | 350 | } |
352 | 351 | k_work_init_delayable(&data->stepper_dwork, stepper_work_step_handler); |
353 | 352 | return 0; |
354 | 353 | } |
355 | 354 |
|
356 | | -#define GPIO_STEPPER_DEVICE_DATA_DEFINE(child) \ |
357 | | - static struct gpio_stepper_data gpio_stepper_data_##child = { \ |
358 | | - .step_gap = MAX_MICRO_STEP_RES >> (DT_PROP(child, micro_step_res) - 1), \ |
359 | | - }; \ |
360 | | - BUILD_ASSERT(DT_PROP(child, micro_step_res) <= STEPPER_MICRO_STEP_2, \ |
361 | | - "gpio_stepper_controller driver supports up to 2 micro steps"); |
362 | | - |
363 | | -#define GPIO_STEPPER_DEVICE_CONFIG_DEFINE(child) \ |
364 | | - static const struct gpio_dt_spec gpio_stepper_motor_control_pins_##child[] = { \ |
365 | | - DT_FOREACH_PROP_ELEM_SEP(child, gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)), \ |
366 | | - }; \ |
367 | | - BUILD_ASSERT( \ |
368 | | - ARRAY_SIZE(gpio_stepper_motor_control_pins_##child) == 4, \ |
369 | | - "gpio_stepper_controller driver currently supports only 4 wire configuration"); \ |
370 | | - static const struct gpio_stepper_config gpio_stepper_config_##child = { \ |
371 | | - .invert_direction = DT_PROP(child, invert_direction), \ |
372 | | - .control_pins = gpio_stepper_motor_control_pins_##child}; |
373 | | - |
374 | | -#define GPIO_STEPPER_API_DEFINE(child) \ |
375 | | - static const struct stepper_driver_api gpio_stepper_api_##child = { \ |
376 | | - .enable = gpio_stepper_enable, \ |
377 | | - .move = gpio_stepper_move, \ |
378 | | - .is_moving = gpio_stepper_is_moving, \ |
379 | | - .set_actual_position = gpio_stepper_set_actual_position, \ |
380 | | - .get_actual_position = gpio_stepper_get_actual_position, \ |
381 | | - .set_target_position = gpio_stepper_set_target_position, \ |
382 | | - .set_max_velocity = gpio_stepper_set_max_velocity, \ |
383 | | - .enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode, \ |
384 | | - .set_micro_step_res = gpio_stepper_set_micro_step_res, \ |
385 | | - .get_micro_step_res = gpio_stepper_get_micro_step_res, \ |
386 | | - .set_event_callback = gpio_stepper_set_event_callback, }; |
387 | | - |
388 | | -#define GPIO_STEPPER_DEVICE_DEFINE(child) \ |
389 | | - DEVICE_DT_DEFINE(child, gpio_stepper_motor_controller_init, NULL, \ |
390 | | - &gpio_stepper_data_##child, &gpio_stepper_config_##child, POST_KERNEL, \ |
391 | | - CONFIG_STEPPER_INIT_PRIORITY, &gpio_stepper_api_##child); |
392 | | - |
393 | | -#define GPIO_STEPPER_CONTROLLER_DEFINE(inst) \ |
394 | | - DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_CONFIG_DEFINE); \ |
395 | | - DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_DATA_DEFINE); \ |
396 | | - DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_API_DEFINE); \ |
397 | | - DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_DEFINE); |
398 | | - |
399 | | -DT_INST_FOREACH_STATUS_OKAY(GPIO_STEPPER_CONTROLLER_DEFINE) |
| 355 | +static const struct stepper_driver_api gpio_stepper_api = { |
| 356 | + .enable = gpio_stepper_enable, |
| 357 | + .move = gpio_stepper_move, |
| 358 | + .is_moving = gpio_stepper_is_moving, |
| 359 | + .set_actual_position = gpio_stepper_set_actual_position, |
| 360 | + .get_actual_position = gpio_stepper_get_actual_position, |
| 361 | + .set_target_position = gpio_stepper_set_target_position, |
| 362 | + .set_max_velocity = gpio_stepper_set_max_velocity, |
| 363 | + .enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode, |
| 364 | + .set_micro_step_res = gpio_stepper_set_micro_step_res, |
| 365 | + .get_micro_step_res = gpio_stepper_get_micro_step_res, |
| 366 | + .set_event_callback = gpio_stepper_set_event_callback, |
| 367 | +}; |
| 368 | + |
| 369 | +#define GPIO_STEPPER_DEFINE(inst) \ |
| 370 | + static const struct gpio_dt_spec gpio_stepper_motor_control_pins_##inst[] = { \ |
| 371 | + DT_INST_FOREACH_PROP_ELEM_SEP(inst, gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)), \ |
| 372 | + }; \ |
| 373 | + BUILD_ASSERT(ARRAY_SIZE(gpio_stepper_motor_control_pins_##inst) == 4, \ |
| 374 | + "gpio_stepper_controller driver currently supports only 4 wire configuration"); \ |
| 375 | + static const struct gpio_stepper_config gpio_stepper_config_##inst = { \ |
| 376 | + .invert_direction = DT_INST_PROP(inst, invert_direction), \ |
| 377 | + .control_pins = gpio_stepper_motor_control_pins_##inst}; \ |
| 378 | + static struct gpio_stepper_data gpio_stepper_data_##inst = { \ |
| 379 | + .step_gap = MAX_MICRO_STEP_RES >> (DT_INST_PROP(inst, micro_step_res) - 1), \ |
| 380 | + }; \ |
| 381 | + BUILD_ASSERT(DT_INST_PROP(inst, micro_step_res) <= STEPPER_MICRO_STEP_2, \ |
| 382 | + "gpio_stepper_controller driver supports up to 2 micro steps"); \ |
| 383 | + DEVICE_DT_INST_DEFINE(inst, gpio_stepper_init, NULL, &gpio_stepper_data_##inst, \ |
| 384 | + &gpio_stepper_config_##inst, POST_KERNEL, \ |
| 385 | + CONFIG_STEPPER_INIT_PRIORITY, &gpio_stepper_api); |
| 386 | + |
| 387 | +DT_INST_FOREACH_STATUS_OKAY(GPIO_STEPPER_DEFINE) |
0 commit comments