Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions drivers/stepper/gpio_stepper_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
uint32_t delay_in_us;
int32_t step_count;
void *event_cb_user_data;
bool latch;
};

static int stepper_motor_set_coil_charge(const struct device *dev)
Expand Down Expand Up @@ -108,6 +109,11 @@
update_coil_charge(dev);
}
update_remaining_steps(dev->data);
if (data -> step_count == 0 && !data->latch) {
for (uint8_t n_pin = 0; n_pin < NUM_CONTROL_PINS; n_pin++) {
(void)gpio_pin_set_dt(&config->control_pins[n_pin], 0);
}
}
}

static void velocity_mode_task(const struct device *dev)
Expand All @@ -125,8 +131,8 @@
struct gpio_stepper_data *data =
CONTAINER_OF(dwork, struct gpio_stepper_data, stepper_dwork);

K_SPINLOCK(&data->lock) {

Check failure on line 134 in drivers/stepper/gpio_stepper_controller.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

drivers/stepper/gpio_stepper_controller.c:134 spaces prohibited around that '->' (ctx:WxW)
switch (data->run_mode) {

Check notice on line 135 in drivers/stepper/gpio_stepper_controller.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/stepper/gpio_stepper_controller.c:135 - if (data -> step_count == 0 && !data->latch) { + if (data->step_count == 0 && !data->latch) {
case STEPPER_RUN_MODE_POSITION:
position_mode_task(data->dev);
break;
Expand Down Expand Up @@ -296,6 +302,20 @@
return 0;
}

static int gpio_stepper_set_latch(const struct device *dev, bool is_latch_after_movement)
{
struct gpio_stepper_data *data = dev->data;
data->latch = is_latch_after_movement;
return 0;
}

static int gpio_stepper_is_latch(const struct device *dev, bool* latching_state)
{
struct gpio_stepper_data *data = dev->data;
*latching_state = data->latch;
return 0;
}

static int gpio_stepper_motor_controller_init(const struct device *dev)
{
struct gpio_stepper_data *data = dev->data;
Expand All @@ -307,12 +327,12 @@
for (uint8_t n_pin = 0; n_pin < NUM_CONTROL_PINS; n_pin++) {
(void)gpio_pin_configure_dt(&config->control_pins[n_pin], GPIO_OUTPUT_INACTIVE);
}
k_work_init_delayable(&data->stepper_dwork, stepper_work_step_handler);

Check warning on line 330 in drivers/stepper/gpio_stepper_controller.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

drivers/stepper/gpio_stepper_controller.c:330 Missing a blank line after declarations
return 0;
}

#define GPIO_STEPPER_DEVICE_DATA_DEFINE(child) \

Check failure on line 334 in drivers/stepper/gpio_stepper_controller.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

drivers/stepper/gpio_stepper_controller.c:334 "foo* bar" should be "foo *bar"
static struct gpio_stepper_data gpio_stepper_data_##child = { \

Check notice on line 335 in drivers/stepper/gpio_stepper_controller.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/stepper/gpio_stepper_controller.c:335 -static int gpio_stepper_is_latch(const struct device *dev, bool* latching_state) +static int gpio_stepper_is_latch(const struct device *dev, bool *latching_state)
.step_gap = MAX_MICRO_STEP_RES >> (DT_PROP(child, micro_step_res) - 1), \
}; \
BUILD_ASSERT(DT_PROP(child, micro_step_res) <= STEPPER_MICRO_STEP_2, \
Expand Down Expand Up @@ -340,6 +360,8 @@
.enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode, \
.set_micro_step_res = gpio_stepper_set_micro_step_res, \
.get_micro_step_res = gpio_stepper_get_micro_step_res, \
.set_latch = gpio_stepper_set_latch, \
.is_latch = gpio_stepper_is_latch, \
.set_event_callback = gpio_stepper_set_event_callback, };

#define GPIO_STEPPER_DEVICE_DEFINE(child) \
Expand Down
48 changes: 48 additions & 0 deletions include/zephyr/drivers/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,23 @@
typedef int (*stepper_set_event_callback_t)(const struct device *dev,
stepper_event_callback_t callback, void *user_data);

/**
* @brief Set the stepper latch after movement.
*
* @see stepper_set_latch() for details.

Check failure on line 190 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

include/zephyr/drivers/stepper.h:190 trailing whitespace
*/
typedef int (*stepper_set_latch_t)(const struct device *dev,
const bool is_latch_after_movement);


/**
* @brief Get the stepper latch state.
*
* @see stepper_is_latch() for details.
*/
typedef int (*stepper_is_latch_t)(const struct device *dev, bool* is_latch_after_movement);

Check failure on line 202 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

include/zephyr/drivers/stepper.h:202 "foo* bar" should be "foo *bar"
/**

Check notice on line 203 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/stepper.h:203 - * + * * @see stepper_set_latch() for details. */ -typedef int (*stepper_set_latch_t)(const struct device *dev, - const bool is_latch_after_movement); - +typedef int (*stepper_set_latch_t)(const struct device *dev, const bool is_latch_after_movement); /** * @brief Get the stepper latch state. * * @see stepper_is_latch() for details. */ -typedef int (*stepper_is_latch_t)(const struct device *dev, bool* is_latch_after_movement); +typedef int (*stepper_is_latch_t)(const struct device *dev, bool *is_latch_after_movement);
* @brief Stepper Motor Controller API
*/
__subsystem struct stepper_driver_api {
Expand All @@ -199,6 +215,8 @@
stepper_is_moving_t is_moving;
stepper_enable_constant_velocity_mode_t enable_constant_velocity_mode;
stepper_set_event_callback_t set_event_callback;
stepper_set_latch_t set_latch;
stepper_is_latch_t is_latch;
};

/**
Expand Down Expand Up @@ -462,6 +480,36 @@
return api->set_event_callback(dev, callback, user_data);
}

/**
* @brief Set whether the stepper motor should latch after movement.
*
* @param dev Pointer to the device structure for the stepper motor.
* @param is_latch_after_movement Boolean indicating whether the motor should latch after movement.
* @retval -EIO General input / output error
* @retval 0 Success
*/
__syscall int stepper_set_latch(const struct device *dev, bool is_latch_after_movement);

static inline int z_impl_stepper_set_latch(const struct device *dev, bool is_latch_after_movement) {
const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;

Check failure on line 494 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

include/zephyr/drivers/stepper.h:494 open brace '{' following function definitions go on the next line
return api->set_latch(dev, is_latch_after_movement);

Check warning on line 495 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

include/zephyr/drivers/stepper.h:495 please, no spaces at the start of a line
}

Check warning on line 496 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

include/zephyr/drivers/stepper.h:496 Missing a blank line after declarations

Check warning on line 496 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

include/zephyr/drivers/stepper.h:496 please, no spaces at the start of a line

Check notice on line 497 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/stepper.h:497 -static inline int z_impl_stepper_set_latch(const struct device *dev, bool is_latch_after_movement) { - const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; - return api->set_latch(dev, is_latch_after_movement); +static inline int z_impl_stepper_set_latch(const struct device *dev, bool is_latch_after_movement) +{ + const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; + return api->set_latch(dev, is_latch_after_movement);
/**
* @brief Get the current latch configuration of the stepper motor.
*
* @param dev Pointer to the device structure for the stepper motor.
* @param latching_state Pointer to a boolean where the latch state will be stored.
* @retval -EIO General input / output error
* @retval 0 Success
*/
__syscall int stepper_is_latch(const struct device *dev, bool* latching_state);

Check failure on line 507 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

include/zephyr/drivers/stepper.h:507 "foo* bar" should be "foo *bar"
static inline int z_impl_stepper_is_latch(const struct device *dev, bool* latching_state) {
const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;

Check failure on line 509 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

include/zephyr/drivers/stepper.h:509 "foo* bar" should be "foo *bar"

Check failure on line 509 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

include/zephyr/drivers/stepper.h:509 open brace '{' following function definitions go on the next line
return api->is_latch(dev, latching_state);

Check warning on line 510 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

include/zephyr/drivers/stepper.h:510 please, no spaces at the start of a line
}

Check warning on line 511 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

include/zephyr/drivers/stepper.h:511 Missing a blank line after declarations

Check warning on line 511 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

include/zephyr/drivers/stepper.h:511 please, no spaces at the start of a line

Check notice on line 512 in include/zephyr/drivers/stepper.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/stepper.h:512 -__syscall int stepper_is_latch(const struct device *dev, bool* latching_state); - -static inline int z_impl_stepper_is_latch(const struct device *dev, bool* latching_state) { - const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; - return api->is_latch(dev, latching_state); +__syscall int stepper_is_latch(const struct device *dev, bool *latching_state); + +static inline int z_impl_stepper_is_latch(const struct device *dev, bool *latching_state) +{ + const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; + return api->is_latch(dev, latching_state);
/**
* @}
*/
Expand Down
Loading