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

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

69 lines
1.7 KiB
C

#ifndef __MOTOR_CONTROL_H__
#define __MOTOR_CONTROL_H__
#ifdef __cplisplus
extern "C" {
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#define MOTOR_WITH_MAGNET_RING 0 //带磁环的时候
#define OLD_MOTOR 0 //旧电机参数
typedef enum
{
MOTOR_POSITION_ZERO = 0,
MOTOR_POSITION_LEFT_15 ,
MOTOR_POSITION_RIGHT_15 ,
MOTOR_POSITION_LEFT_30 ,
MOTOR_POSITION_RIGHT_30 ,
MOTOR_POSITION_LEFT_90 ,
MOTOR_POSITION_RIGHT_90 ,
MOTOR_POSITION_LEFT_180 ,
MOTOR_POSITION_RIGHT_180,
MOTOR_POSITION_LEFT_2 ,//微步
}MOTOR_POSITION;
typedef enum
{
MOTOR_CW,
MOTOR_CCW,
}MOTOR_DIR;
typedef struct
{
uint32_t run_to_left_15;
uint32_t run_to_left_30;
uint32_t run_to_left_90;
uint32_t run_to_left_180;
uint32_t run_to_right_15;
uint32_t run_to_right_30;
uint32_t run_to_right_180;
}MOTOR_RUN_TIME;
extern TaskHandle_t motor_control_handle;
extern MOTOR_DIR motor_dir;
extern MOTOR_POSITION motor_current_position ;
extern MOTOR_POSITION motor_target_position ;
extern SemaphoreHandle_t motor_action_down_sem;
void motor_control_init(void);
void motor_control_task(void *pvParameter);
void motor_run_dir(MOTOR_DIR dir);
/** 串行入队执行;满则丢最旧再入队,避免 Overwrite 丢命令 */
bool motor_post_cmd(uint32_t cmd);
/** play_sticker 方向:左右切换时先排队 0x0A;0x00 在头仍左/右时排队 0x0A;与上次同字节且侧向未变则跳过 */
bool motor_post_play_sticker_direction(uint8_t direction);
void motor_post_cmd_from_isr(uint32_t cmd, BaseType_t *pxHigherPriorityTaskWoken);
#ifdef __cplusplus
}
#endif
#endif