Referee/User/device/vt13.h

116 lines
3.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include <stdint.h>
#include <stdbool.h>
#include "component/user_math.h"
#include "device.h"
/* Exported constants ------------------------------------------------------- */
#define VT13_CH_VALUE_MIN (364u)
#define VT13_CH_VALUE_MID (1024u)
#define VT13_CH_VALUE_MAX (1684u)
/* Exported types ----------------------------------------------------------- */
/* 图传接收端 21 字节数据帧原始结构 */
typedef struct __packed {
uint8_t header1; /* 帧头10xA9 [cite: 164] */
uint8_t header2; /* 帧头20x53 [cite: 164] */
/* 连续 64 bits 的位域提取 */
uint64_t ch_r_x : 11; /* 通道 0右摇杆水平 [cite: 164] */
uint64_t ch_r_y : 11; /* 通道 1右摇杆竖直 [cite: 164] */
uint64_t ch_l_y : 11; /* 通道 2左摇杆竖直 [cite: 164] */
uint64_t ch_l_x : 11; /* 通道 3左摇杆水平 [cite: 165] */
uint64_t mode : 2; /* 挡位切换开关 [cite: 165] */
uint64_t pause : 1; /* 暂停按键 [cite: 165] */
uint64_t custom_l : 1; /* 自定义按键(左) [cite: 165] */
uint64_t custom_r : 1; /* 自定义按键(右) [cite: 165] */
uint64_t dial : 11; /* 拨轮 [cite: 165] */
uint64_t trigger : 1; /* 扳机键 [cite: 165] */
uint64_t res1 : 3; /* 补齐至 80 offset */
int16_t mouse_x; /* 鼠标 X 轴 [cite: 165] */
int16_t mouse_y; /* 鼠标 Y 轴 [cite: 165] */
int16_t mouse_z; /* 鼠标 Z 轴 [cite: 165] */
/* 连续 8 bits 的位域提取 */
uint8_t mouse_l : 2; /* 鼠标左键 */
uint8_t mouse_r : 2; /* 鼠标右键 */
uint8_t mouse_m : 2; /* 鼠标中键 */
uint8_t res2 : 2; /* 补齐至 136 offset */
uint16_t keyboard; /* 键盘按键位映射 */
uint16_t crc16; /* CRC 校验 */
} VT13_RawData_t;
/* 模式开关枚举 */
typedef enum {
VT13_MODE_C = 0, /* [cite: 165] */
VT13_MODE_N = 1, /* [cite: 165] */
VT13_MODE_S = 2, /* [cite: 165] */
} VT13_Mode_t;
/* 键盘按键值映射,依据文档 bit0-bit15 定义 */
typedef enum {
VT13_KEY_W = 0, VT13_KEY_S, VT13_KEY_A, VT13_KEY_D,
VT13_KEY_SHIFT, VT13_KEY_CTRL, VT13_KEY_Q, VT13_KEY_E,
VT13_KEY_R, VT13_KEY_F, VT13_KEY_G, VT13_KEY_Z,
VT13_KEY_X, VT13_KEY_C, VT13_KEY_V, VT13_KEY_B,
VT13_KEY_NUM
} VT13_Key_t;
/* 解析后的数据结构 */
typedef struct {
float ch_l_x; /* 左侧摇杆水平,右为正 [-1.0~1.0] */
float ch_l_y; /* 左侧摇杆竖直,上为正 [-1.0~1.0] */
float ch_r_x; /* 右侧摇杆水平,右为正 [-1.0~1.0] */
float ch_r_y; /* 右侧摇杆竖直,上为正 [-1.0~1.0] */
float dial; /* 拨轮值 [-1.0~1.0] */
VT13_Mode_t mode; /* 挡位切换开关 [cite: 165] */
bool pause; /* 暂停按键按下为 true [cite: 165] */
bool custom_l; /* 左自定义键按下为 true [cite: 165] */
bool custom_r; /* 右自定义键按下为 true [cite: 165] */
bool trigger; /* 扳机键按下为 true [cite: 165] */
struct {
int16_t x; /* 鼠标横向移动,负向左 [cite: 165] */
int16_t y; /* 鼠标纵向移动,负向后 [cite: 165] */
int16_t z; /* 鼠标滚轮速度,负向后 [cite: 165] */
bool l_click;
bool r_click;
bool m_click;
} mouse;
union {
bool key[VT13_KEY_NUM];
uint16_t value;
} keyboard;
} VT13_Data_t;
typedef struct {
DEVICE_Header_t header;
VT13_RawData_t raw_data;
VT13_Data_t data;
} VT13_t;
/* Exported functions prototypes -------------------------------------------- */
int8_t VT13_Init(VT13_t *vtm);
int8_t VT13_Restart(void);
int8_t VT13_StartDmaRecv(VT13_t *vtm);
bool VT13_WaitDmaCplt(uint32_t timeout);
int8_t VT13_ParseData(VT13_t *vtm);
int8_t VT13_Offline(VT13_t *vtm);
#ifdef __cplusplus
}
#endif