#ifndef _MOTOR_H
#define _MOTOR_H
#include "user.h"
#define MOTOR_TEST 1

#define MOTOR_GPIO GPIOD
#define MOTOR_FALL_PIN GPIO_Pin_2
#define MOTOR_RISE_PIN GPIO_Pin_3

#define LIMIT_GPIO GPIOB
#define LIMIT_PIN GPIO_Pin_0

#define MOTOR_AD_GPIO GPIOA
#define MOTOR_AD_PIN GPIO_Pin_4

#define MOTOR_DELAY 8
#define MOTOR_DELAY_MS200 20
#define MOTOR_DELAY_MS500 50
#define LIMIT_READ (GPIO_ReadInputDataBit(LIMIT_GPIO,LIMIT_PIN))
typedef enum
{
        motor_stop = 0,
	motor_rise,
	motor_fall,
	motor_delay_ms200,
        motor_delay_ms500,
	motor_turn,
	motor_busy,
        motor_idle

}motor_state;

typedef struct MStr
{
    uint8_t motor_delay;
    uint8_t delay_ms200;
    uint8_t delay_ms500;
}MOTORSTR;

enum CMD_SOURCE
{
    AUTO = 0,
    MANUAL = 1
};

enum MOTOR_CMD
{
    MotorIdel = 0,
    MotorRise,
    MotorFall
};
enum CMD_RESULTS
{
    IDEL = 0,
    RISE_OK,
    FALL_OK,
    RISE_ERROR,
    FALL_ERROR
};
typedef struct
{
    bool HostReportFlag;
    uint8_t HostReportCnt;
    uint8_t HostReportDelay;
    enum CMD_SOURCE MotorCmdSource;
    enum MOTOR_CMD MotorCmd;
    enum CMD_RESULTS MotorActResults;
}MOTOR_STATE_STR;

extern MOTORSTR MotorStr;
extern motor_state motor_cmd;
extern MOTOR_STATE_STR LockCarState;
void motor_init(void);
void motor_contro_act(motor_state *cmd);
void CarAction(bool ReportFlag,uint8_t RepotCnt,enum CMD_SOURCE CmdSource,enum MOTOR_CMD MotorCmd);

#endif
