1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: CC0-1.0 5 */ 6 7 #pragma once 8 9 #include "esp_err.h" 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 typedef struct step_motor_driver_io_s step_motor_driver_io_t; 16 17 typedef step_motor_driver_io_t *step_motor_driver_io_handle_t; 18 19 typedef enum { 20 STEP_MOTOR_DIRECTION_NEGATIVE = 0, STEP_MOTOR_DIRECTION_POSITIVE 21 } step_direction; 22 23 /** 24 * @brief init low part of driver 25 * GPIO configuration, Bus initializing... 26 */ 27 typedef esp_err_t (*step_motor_driver_io_init)(step_motor_driver_io_t *handle); 28 /** 29 * @brief set rotation direction 30 */ 31 typedef esp_err_t (*step_motor_driver_io_set_direction)(step_motor_driver_io_t *handle, step_direction direction); 32 /** 33 * @brief enable/disable sleep mode if supported 34 */ 35 typedef esp_err_t (*step_motor_driver_io_enable_sleep)(step_motor_driver_io_t *handle, bool enabled); 36 /** 37 * @brief enable/disable output if supported 38 */ 39 typedef esp_err_t (*step_motor_driver_io_enable_output)(step_motor_driver_io_t *handle, bool enabled); 40 /** 41 * @brief set microstep configuration if supported. 42 * param microstep is treated as denominator. a input of 16 means 1/16 step 43 * should return ESP_ERR_NOT_SUPPORTED if not supported 44 */ 45 typedef esp_err_t (*step_motor_driver_io_set_microstep)(step_motor_driver_io_t *handle, uint16_t microstep); 46 /** 47 * @brief reset low part of driver 48 */ 49 typedef esp_err_t (*step_motor_driver_io_reset)(step_motor_driver_io_t *handle); 50 /** 51 * @brief deinit low part of driver 52 */ 53 typedef esp_err_t (*step_motor_driver_io_deinit)(step_motor_driver_io_t *handle); 54 55 /** 56 * @brief Driver IC specified control logic 57 * 58 * leave callback pointer NULL if action is not supported 59 */ 60 struct step_motor_driver_io_s { 61 step_motor_driver_io_init init; /*!< callback to init low part driver */ 62 step_motor_driver_io_set_direction set_direction; /*!< callback to set rotate direction */ 63 step_motor_driver_io_enable_sleep enable_sleep; /*!< callback to enable sleep mode */ 64 step_motor_driver_io_enable_output enable_output; /*!< callback to enable output */ 65 step_motor_driver_io_set_microstep set_microstep; /*!< callback to set microstep configuration */ 66 bool step_triggered_edge; /*!< true if step is triggered by positive edge, otherwise false */ 67 uint32_t pulse_low_period_us; /*!< minimum low level pulse width on step pin */ 68 uint32_t pulse_high_period_us; /*!< minimum high level pulse width on step pin */ 69 step_motor_driver_io_reset trigger_reset; /*!< callback to trigger a reset on low part driver */ 70 step_motor_driver_io_deinit deinit; /*!< callback to deinit low part driver */ 71 }; 72 73 #ifdef __cplusplus 74 } 75 #endif 76