Files
zhengxinandCursor 851e347cf5 初始提交卡包 USB 工程
纳入固件源码、屏幕组件、nand_xfer 工具和文档。忽略本机构建产物、sdkconfig,以及含本机路径的依赖锁。

Co-authored-by: Cursor <[email protected]>
2026-10-13 21:54:50 +08:00

51 lines
1.8 KiB
C

#ifndef __STEP_MOTOT_INIT_H__
#define __STEP_MOTOT_INIT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include "driver/gpio.h"
#include "esp_log.h"
#include "driver/mcpwm_prelude.h"
/* ---- 步进电机引脚 ---- */
#define STEPPER_PIN_A1 GPIO_NUM_20 /* A 相正 */
#define STEPPER_PIN_A2 GPIO_NUM_21 /* A 相负 */
#define STEPPER_PIN_B1 GPIO_NUM_23 /* B 相正 */
#define STEPPER_PIN_B2 GPIO_NUM_22 /* B 相负 */
/* ---- MCPWM 配置 ---- */
#define STEPPER_MCPWM_GROUP 0
#define STEPPER_PWM_RESOL_HZ 4000000U /* 定时器时钟分辨率 4 MHz */
#define STEPPER_PWM_FREQ_HZ 8000U /* PWM 载波频率 8 kHz */
#define STEPPER_DUTY_MAX 1000U /* 占空比满量程,和 A_PULS_DUTY 等变量一致 */
#define STEPPER_STARTUP_DUTY_RAW (STEPPER_DUTY_MAX / 2)
#define STEPPER_OPENLOOP_STEP_HZ 100U /* 上电演示转动的步进频率 */
#define STEPPER_DEFAULT_RUN_STEPS (STEPPER_OPENLOOP_STEP_HZ * 4U)
typedef enum {
STEPPER_DIR_FORWARD = 1,//原为 1
STEPPER_DIR_REVERSE = -1,//原为 -1
} stepper_motor_direction_t;
void stepper_motor_init(void);
void stepper_motor_set_duty_raw(uint16_t a_plus, uint16_t a_minus, uint16_t b_plus, uint16_t b_minus);
void stepper_motor_output_enable(void);
void stepper_motor_output_disable(void);
void stepper_motor_openloop_start(void);
void stepper_motor_openloop_start_dir(stepper_motor_direction_t direction);
void stepper_motor_forward(void);
void stepper_motor_reverse(void);
void stepper_motor_run_steps(stepper_motor_direction_t direction, uint32_t steps);
void stepper_motor_stop(void);
void stepper_motor_openloop_stop(void);
bool stepper_motor_output_is_enabled(void);
stepper_motor_direction_t stepper_motor_get_direction(void);
#ifdef __cplusplus
}
#endif
#endif /* __STEP_MOTOR_INIT_H__ */