Lines Matching +full:step +full:- +full:down
2 * SPDX-FileCopyrightText: Copyright (c) 2024 Carl Zeiss Meditec AG
3 * SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
4 * SPDX-License-Identifier: Apache-2.0
49 struct gpio_stepper_data *data = dev->data; in stepper_motor_set_coil_charge()
50 const struct gpio_stepper_config *config = dev->config; in stepper_motor_set_coil_charge()
53 (void)gpio_pin_set_dt(&config->control_pins[i], in stepper_motor_set_coil_charge()
54 half_step_lookup_table[data->coil_charge][i]); in stepper_motor_set_coil_charge()
61 struct gpio_stepper_data *data = dev->data; in increment_coil_charge()
63 if (data->coil_charge == NUM_CONTROL_PINS * MAX_MICRO_STEP_RES - data->step_gap) { in increment_coil_charge()
64 data->coil_charge = 0; in increment_coil_charge()
66 data->coil_charge = data->coil_charge + data->step_gap; in increment_coil_charge()
72 struct gpio_stepper_data *data = dev->data; in decrement_coil_charge()
74 if (data->coil_charge == 0) { in decrement_coil_charge()
75 data->coil_charge = NUM_CONTROL_PINS * MAX_MICRO_STEP_RES - data->step_gap; in decrement_coil_charge()
77 data->coil_charge = data->coil_charge - data->step_gap; in decrement_coil_charge()
83 const struct gpio_stepper_config *config = dev->config; in power_down_coils()
86 const int err = gpio_pin_set_dt(&config->control_pins[i], 0u); in power_down_coils()
89 LOG_ERR("Failed to power down coil %d", i); in power_down_coils()
98 const struct gpio_stepper_config *config = dev->config; in update_coil_charge()
99 struct gpio_stepper_data *data = dev->data; in update_coil_charge()
101 if (data->direction == STEPPER_DIRECTION_POSITIVE) { in update_coil_charge()
102 config->invert_direction ? decrement_coil_charge(dev) : increment_coil_charge(dev); in update_coil_charge()
103 data->actual_position++; in update_coil_charge()
104 } else if (data->direction == STEPPER_DIRECTION_NEGATIVE) { in update_coil_charge()
105 config->invert_direction ? increment_coil_charge(dev) : decrement_coil_charge(dev); in update_coil_charge()
106 data->actual_position--; in update_coil_charge()
112 if (data->step_count > 0) { in update_remaining_steps()
113 data->step_count--; in update_remaining_steps()
114 (void)k_work_reschedule(&data->stepper_dwork, K_USEC(data->delay_in_us)); in update_remaining_steps()
115 } else if (data->step_count < 0) { in update_remaining_steps()
116 data->step_count++; in update_remaining_steps()
117 (void)k_work_reschedule(&data->stepper_dwork, K_USEC(data->delay_in_us)); in update_remaining_steps()
119 if (!data->callback) { in update_remaining_steps()
123 data->callback(data->dev, STEPPER_EVENT_STEPS_COMPLETED, data->event_cb_user_data); in update_remaining_steps()
129 struct gpio_stepper_data *data = dev->data; in update_direction_from_step_count()
131 if (data->step_count > 0) { in update_direction_from_step_count()
132 data->direction = STEPPER_DIRECTION_POSITIVE; in update_direction_from_step_count()
133 } else if (data->step_count < 0) { in update_direction_from_step_count()
134 data->direction = STEPPER_DIRECTION_NEGATIVE; in update_direction_from_step_count()
136 LOG_ERR("Step count is zero"); in update_direction_from_step_count()
142 struct gpio_stepper_data *data = dev->data; in position_mode_task()
144 if (data->step_count) { in position_mode_task()
148 update_remaining_steps(dev->data); in position_mode_task()
153 struct gpio_stepper_data *data = dev->data; in velocity_mode_task()
157 (void)k_work_reschedule(&data->stepper_dwork, K_USEC(data->delay_in_us)); in velocity_mode_task()
166 K_SPINLOCK(&data->lock) { in stepper_work_step_handler()
167 switch (data->run_mode) { in stepper_work_step_handler()
169 position_mode_task(data->dev); in stepper_work_step_handler()
172 velocity_mode_task(data->dev); in stepper_work_step_handler()
175 LOG_WRN("Unsupported run mode %d", data->run_mode); in stepper_work_step_handler()
183 struct gpio_stepper_data *data = dev->data; in gpio_stepper_move_by()
185 if (!data->is_enabled) { in gpio_stepper_move_by()
187 return -ECANCELED; in gpio_stepper_move_by()
190 if (data->delay_in_us == 0) { in gpio_stepper_move_by()
192 return -EINVAL; in gpio_stepper_move_by()
194 K_SPINLOCK(&data->lock) { in gpio_stepper_move_by()
195 data->run_mode = STEPPER_RUN_MODE_POSITION; in gpio_stepper_move_by()
196 data->step_count = micro_steps; in gpio_stepper_move_by()
198 (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); in gpio_stepper_move_by()
205 struct gpio_stepper_data *data = dev->data; in gpio_stepper_set_reference_position()
207 K_SPINLOCK(&data->lock) { in gpio_stepper_set_reference_position()
208 data->actual_position = position; in gpio_stepper_set_reference_position()
215 struct gpio_stepper_data *data = dev->data; in gpio_stepper_get_actual_position()
217 K_SPINLOCK(&data->lock) { in gpio_stepper_get_actual_position()
218 *position = data->actual_position; in gpio_stepper_get_actual_position()
225 struct gpio_stepper_data *data = dev->data; in gpio_stepper_move_to()
227 if (!data->is_enabled) { in gpio_stepper_move_to()
229 return -ECANCELED; in gpio_stepper_move_to()
232 if (data->delay_in_us == 0) { in gpio_stepper_move_to()
234 return -EINVAL; in gpio_stepper_move_to()
236 K_SPINLOCK(&data->lock) { in gpio_stepper_move_to()
237 data->run_mode = STEPPER_RUN_MODE_POSITION; in gpio_stepper_move_to()
238 data->step_count = micro_steps - data->actual_position; in gpio_stepper_move_to()
240 (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); in gpio_stepper_move_to()
247 struct gpio_stepper_data *data = dev->data; in gpio_stepper_is_moving()
249 *is_moving = k_work_delayable_is_pending(&data->stepper_dwork); in gpio_stepper_is_moving()
256 struct gpio_stepper_data *data = dev->data; in gpio_stepper_set_max_velocity()
260 return -EINVAL; in gpio_stepper_set_max_velocity()
265 return -EINVAL; in gpio_stepper_set_max_velocity()
268 K_SPINLOCK(&data->lock) { in gpio_stepper_set_max_velocity()
269 data->delay_in_us = USEC_PER_SEC / velocity; in gpio_stepper_set_max_velocity()
278 struct gpio_stepper_data *data = dev->data; in gpio_stepper_run()
280 if (!data->is_enabled) { in gpio_stepper_run()
282 return -ECANCELED; in gpio_stepper_run()
285 K_SPINLOCK(&data->lock) { in gpio_stepper_run()
286 data->run_mode = STEPPER_RUN_MODE_VELOCITY; in gpio_stepper_run()
287 data->direction = direction; in gpio_stepper_run()
289 data->delay_in_us = USEC_PER_SEC / velocity; in gpio_stepper_run()
290 (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); in gpio_stepper_run()
292 (void)k_work_cancel_delayable(&data->stepper_dwork); in gpio_stepper_run()
301 struct gpio_stepper_data *data = dev->data; in gpio_stepper_set_micro_step_res()
303 K_SPINLOCK(&data->lock) { in gpio_stepper_set_micro_step_res()
307 data->step_gap = MAX_MICRO_STEP_RES >> (micro_step_res - 1); in gpio_stepper_set_micro_step_res()
310 LOG_ERR("Unsupported micro step resolution %d", micro_step_res); in gpio_stepper_set_micro_step_res()
311 return -ENOTSUP; in gpio_stepper_set_micro_step_res()
320 struct gpio_stepper_data *data = dev->data; in gpio_stepper_get_micro_step_res()
321 *micro_step_res = MAX_MICRO_STEP_RES >> (data->step_gap - 1); in gpio_stepper_get_micro_step_res()
328 struct gpio_stepper_data *data = dev->data; in gpio_stepper_set_event_callback()
330 K_SPINLOCK(&data->lock) { in gpio_stepper_set_event_callback()
331 data->callback = callback; in gpio_stepper_set_event_callback()
333 data->event_cb_user_data = user_data; in gpio_stepper_set_event_callback()
339 struct gpio_stepper_data *data = dev->data; in gpio_stepper_enable()
341 K_SPINLOCK(&data->lock) { in gpio_stepper_enable()
343 data->is_enabled = enable; in gpio_stepper_enable()
346 (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); in gpio_stepper_enable()
348 (void)k_work_cancel_delayable(&data->stepper_dwork); in gpio_stepper_enable()
352 return -EIO; in gpio_stepper_enable()
361 struct gpio_stepper_data *data = dev->data; in gpio_stepper_init()
362 const struct gpio_stepper_config *config = dev->config; in gpio_stepper_init()
364 data->dev = dev; in gpio_stepper_init()
365 LOG_DBG("Initializing %s gpio_stepper with %d pin", dev->name, NUM_CONTROL_PINS); in gpio_stepper_init()
367 (void)gpio_pin_configure_dt(&config->control_pins[n_pin], GPIO_OUTPUT_INACTIVE); in gpio_stepper_init()
369 k_work_init_delayable(&data->stepper_dwork, stepper_work_step_handler); in gpio_stepper_init()
397 .step_gap = MAX_MICRO_STEP_RES >> (DT_INST_PROP(inst, micro_step_res) - 1), \