93 lines
1.3 KiB
C
93 lines
1.3 KiB
C
#ifndef __stepmotor_h__
|
|
#define __stepmotor_h__
|
|
#include "gd32f30x_libopt.h"
|
|
#include <stdio.h>
|
|
#include "BSP.h"
|
|
|
|
enum motor_state_t
|
|
{
|
|
motor_stop,
|
|
motor_accelerate,
|
|
motor_speed_max,
|
|
motor_decelerate
|
|
};
|
|
|
|
typedef struct _gpio_group_ {
|
|
|
|
uint32_t port;
|
|
uint32_t pin;
|
|
|
|
}_gpio_group;
|
|
|
|
|
|
typedef struct _stepmotor_{
|
|
|
|
uint8_t channel;
|
|
char * name;
|
|
|
|
_gpio_group start;
|
|
_gpio_group end;
|
|
|
|
_gpio_group pul;
|
|
_gpio_group ena;
|
|
_gpio_group dir;
|
|
|
|
enum motor_state_t state;
|
|
|
|
uint32_t step_delay;
|
|
uint32_t step_count;
|
|
|
|
uint32_t step_len;
|
|
|
|
int32_t step_index;
|
|
|
|
uint32_t step_current;
|
|
|
|
int8_t running;//-1 0 1 从结束往开始走 停止 从开始往结束走
|
|
uint8_t isGetLen;//是否已经获取长度
|
|
|
|
int8_t isGetPos;// -1 get start 0 no act 1 ge end
|
|
|
|
uint32_t stateCount;
|
|
|
|
struct _stepmotor_ *next_ptr;
|
|
|
|
}_stepmotor;
|
|
|
|
|
|
void stepmotor_init(void);
|
|
void stepmotor_thread(void);
|
|
|
|
uint8_t stepmotor_install(_stepmotor *e,char *name,_gpio_group start,
|
|
_gpio_group end,
|
|
_gpio_group pul,
|
|
_gpio_group ena,
|
|
_gpio_group dir);
|
|
|
|
|
|
void stepmotor_getlen(uint16_t channel);
|
|
void stepmotor_act(uint16_t channel,int8_t state);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|