1 /* 2 * Copyright 2024 Fabian Blatz <fabianblatz@gmail.com> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_COMMON_H_ 8 #define ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_COMMON_H_ 9 10 /** 11 * @brief Stepper Driver APIs 12 * @defgroup step_dir_stepper Stepper Driver APIs 13 * @ingroup io_interfaces 14 * @{ 15 */ 16 17 #include <zephyr/device.h> 18 /** 19 * @brief Common step direction stepper config. 20 * 21 * This structure **must** be placed first in the driver's config structure. 22 */ 23 struct step_dir_stepper_common_config { 24 struct gpio_dt_spec en_pin; 25 struct gpio_dt_spec m0_pin; 26 struct gpio_dt_spec m1_pin; 27 uint32_t step_width_ns; 28 bool dual_edge; 29 }; 30 31 /** 32 * @brief Initialize common step direction stepper config from devicetree instance. 33 * If the counter property is set, the timing source will be set to the counter timing 34 * source. 35 * 36 * @param node_id The devicetree node identifier. 37 */ 38 #define STEP_DIR_STEPPER_DT_COMMON_CONFIG_INIT(node_id) \ 39 { \ 40 .en_pin = GPIO_DT_SPEC_GET_OR(node_id, en_gpios, {0}), \ 41 .m0_pin = GPIO_DT_SPEC_GET_OR(node_id, m0_gpios, {0}), \ 42 .m1_pin = GPIO_DT_SPEC_GET_OR(node_id, m1_gpios, {0}), \ 43 .dual_edge = DT_PROP_OR(node_id, dual_edge_step, false), \ 44 .step_width_ns = DT_PROP(node_id, step_width_ns), \ 45 } 46 47 /** 48 * @brief Initialize common step direction stepper config from devicetree instance. 49 * @param inst Instance. 50 */ 51 #define STEP_DIR_STEPPER_DT_INST_COMMON_CONFIG_INIT(inst) \ 52 STEP_DIR_STEPPER_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst)) 53 54 55 /** 56 * @brief Validate the offset of the common data structures. 57 * 58 * @param config Name of the config structure. 59 */ 60 #define STEP_DIR_STEPPER_STRUCT_CHECK(config) \ 61 BUILD_ASSERT(offsetof(config, common) == 0, \ 62 "struct step_dir_stepper_common_config must be placed first"); 63 64 /** @} */ 65 66 #endif /* ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_COMMON_H_ */ 67