sensor_2026/HARDWARE/MOTOR/motor_driver.h

38 lines
992 B
C

// motor_driver.h
#ifndef __MOTOR_DRIVER_H
#define __MOTOR_DRIVER_H
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
// 引脚定义
#define MOTOR_IN1_GPIO_PORT GPIOE
#define MOTOR_IN1_GPIO_PIN GPIO_Pin_9
#define MOTOR_IN1_GPIO_CLK RCC_AHB1Periph_GPIOE
#define MOTOR_IN2_GPIO_PORT GPIOE
#define MOTOR_IN2_GPIO_PIN GPIO_Pin_13
#define MOTOR_IN2_GPIO_CLK RCC_AHB1Periph_GPIOE
#define MOTOR_FAULT_GPIO_PORT GPIOE
#define MOTOR_FAULT_GPIO_PIN GPIO_Pin_4
#define MOTOR_FAULT_GPIO_CLK RCC_AHB1Periph_GPIOE
// 电机状态
typedef enum {
MOTOR_STOP = 0, // 停止(滑行)
MOTOR_FORWARD, // 正转
MOTOR_REVERSE, // 反转
MOTOR_BRAKE // 刹车
} MotorState;
// 函数声明
void DRV8832_Init(void);
void Motor_Control(MotorState state);
uint8_t Motor_GetFaultStatus(void);
void Motor_SetSpeed(uint8_t speed, MotorState direction);
void PWM_Timer_Init(void);
#endif /* __MOTOR_DRIVER_H */