Skip to content

Commit d25b1d1

Browse files
jilaypandyadkalowsk
authored andcommitted
drivers: stepper: add check for inval resolution in set_microstep_res
Add check for invalid microstep resolution directly in api to avoid the check in each and every driver Set microstep resolution is made a mandatory function now as all stepper drivers support it and hence should implement it Signed-off-by: Jilay Pandya <[email protected]>
1 parent 945ddf0 commit d25b1d1

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

drivers/stepper/adi_tmc/tmc50xx.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,6 @@ int tmc50xx_stepper_set_max_velocity(const struct device *dev, uint32_t velocity
370370
static int tmc50xx_stepper_set_micro_step_res(const struct device *dev,
371371
enum stepper_micro_step_resolution res)
372372
{
373-
if (!VALID_MICRO_STEP_RES(res)) {
374-
LOG_ERR("Invalid micro step resolution %d", res);
375-
return -ENOTSUP;
376-
}
377-
378373
const struct tmc50xx_stepper_config *config = dev->config;
379374
uint32_t reg_value;
380375
int err;

drivers/stepper/adi_tmc/tmc51xx/tmc51xx.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,6 @@ int tmc51xx_stepper_set_max_velocity(const struct device *dev, uint32_t velocity
406406
static int tmc51xx_stepper_set_micro_step_res(const struct device *dev,
407407
enum stepper_micro_step_resolution res)
408408
{
409-
if (!VALID_MICRO_STEP_RES(res)) {
410-
LOG_ERR("Invalid micro step resolution %d", res);
411-
return -ENOTSUP;
412-
}
413-
414409
uint32_t reg_value;
415410
int err;
416411

include/zephyr/drivers/stepper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static inline int z_impl_stepper_disable(const struct device *dev)
280280
*
281281
* @retval -EIO General input / output error
282282
* @retval -ENOSYS If not implemented by device driver
283+
* @retval -EINVAL If the requested resolution is invalid
283284
* @retval -ENOTSUP If the requested resolution is not supported
284285
* @retval 0 Success
285286
*/
@@ -294,6 +295,10 @@ static inline int z_impl_stepper_set_micro_step_res(const struct device *dev,
294295
if (api->set_micro_step_res == NULL) {
295296
return -ENOSYS;
296297
}
298+
299+
if (!VALID_MICRO_STEP_RES(resolution)) {
300+
return -EINVAL;
301+
}
297302
return api->set_micro_step_res(dev, resolution);
298303
}
299304

tests/drivers/stepper/stepper_api/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ static void stepper_before(void *f)
8888

8989
ZTEST_SUITE(stepper, NULL, stepper_setup, stepper_before, NULL, NULL);
9090

91-
ZTEST_F(stepper, test_set_micro_step_res_incorrect)
91+
ZTEST_F(stepper, test_set_micro_step_res_invalid)
9292
{
9393
int ret = stepper_set_micro_step_res(fixture->dev, 127);
9494

95-
zassert_equal(ret, -ENOTSUP, "Incorrect micro step resolution should return -ENOTSUP");
95+
zassert_equal(ret, -EINVAL, "Invalid micro step resolution should return -EINVAL");
9696
}
9797

9898
ZTEST_F(stepper, test_get_micro_step_res)

0 commit comments

Comments
 (0)