41 lines
840 B
C
41 lines
840 B
C
#include "by_stepper.h"
|
|
|
|
#include <string.h>
|
|
#include <dwt_delay.h>
|
|
#include "by_debug.h"
|
|
|
|
// TODO 是否增加一个动作列表?一般都比较简单吧
|
|
|
|
struct by_stepper_t {
|
|
uint8_t dir;
|
|
stepper_speed_t speed;
|
|
};
|
|
|
|
struct by_stepper_t by_stepper;
|
|
|
|
void by_stepper_init(void)
|
|
{
|
|
memset(&by_stepper, 0x00, sizeof(by_stepper));
|
|
}
|
|
|
|
void by_stepper_set_dir(uint8_t dir)
|
|
{
|
|
by_stepper.dir = dir;
|
|
}
|
|
|
|
void by_stepper_set_speed(stepper_speed_t speed)
|
|
{
|
|
by_stepper.speed = speed;
|
|
}
|
|
|
|
void by_stepper_run(void)
|
|
{
|
|
// 根据预设条件发送脉冲
|
|
gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
|
|
gpio_bits_write(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
|
DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
|
}
|
|
|
|
void by_stepper_stop(void)
|
|
{
|
|
} |