diff --git a/assets/User_code/bsp/can.c b/assets/User_code/bsp/can.c index d0376f5..91727db 100644 --- a/assets/User_code/bsp/can.c +++ b/assets/User_code/bsp/can.c @@ -2,7 +2,7 @@ #include "bsp/can.h" #include "bsp/bsp.h" #include -#include +#include #include /* Private define ----------------------------------------------------------- */ diff --git a/assets/User_code/config.csv b/assets/User_code/config.csv index fc088aa..84b7c39 100644 --- a/assets/User_code/config.csv +++ b/assets/User_code/config.csv @@ -1,4 +1,4 @@ bsp,can,dwt,gpio,i2c,mm,spi,uart,pwm,time component,ahrs,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math -device,dr16,bmi088,ist8310,motor,motor_rm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,servo,buzzer,led,ws2812,vofa +device,dr16,bmi088,ist8310,motor,motor_rm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,servo,buzzer,led,ws2812,vofa,ops9 module, \ No newline at end of file diff --git a/assets/User_code/device/config.yaml b/assets/User_code/device/config.yaml index 7472db7..a24a6f6 100644 --- a/assets/User_code/device/config.yaml +++ b/assets/User_code/device/config.yaml @@ -15,6 +15,22 @@ devices: header: "dr16.h" source: "dr16.c" + ops9: + name: "OPS9" + description: "ACTION OPS9 码盘" + dependencies: + bsp: ["uart"] + component: ["user_math"] + bsp_requirements: + - type: "uart" + var_name: "BSP_UART_OPS9" # 需要替换的变量名 + description: "用于接收码盘" + thread_signals: + - name: "SIGNAL_OPS9_RAW_REDY" + files: + header: "ops9.h" + source: "ops9.c" + bmi088: name: "BMI088" description: "BMI088 陀螺仪+加速度计传感器" @@ -81,8 +97,6 @@ devices: dependencies: bsp: ["can", "time", "mm"] component: ["user_math"] - thread_signals: - - name: "SIGNAL_VESC_DATA_REDY" files: header: "motor_vesc.h" source: "motor_vesc.c" @@ -93,8 +107,6 @@ devices: dependencies: bsp: ["can", "time", "mm"] component: ["user_math"] - thread_signals: - - name: "SIGNAL_ODRIVE_DATA_REDY" files: header: "motor_odrive.h" source: "motor_odrive.c" @@ -105,8 +117,6 @@ devices: dependencies: bsp: ["can", "time", "mm"] component: ["user_math"] - thread_signals: - - name: "SIGNAL_RM_MOTOR_DATA_REDY" files: header: "motor_rm.h" source: "motor_rm.c" @@ -155,8 +165,6 @@ devices: dependencies: bsp: ["can", "time"] component: ["user_math"] - thread_signals: - - name: "SIGNAL_DM_IMU_DATA_REDY" files: header: "dm_imu.h" source: "dm_imu.c" @@ -178,8 +186,6 @@ devices: dependencies: bsp: ["can", "time", "mm"] component: ["user_math"] - thread_signals: - - name: "SIGNAL_LK_MOTOR_DATA_REDY" files: header: "motor_lk.h" source: "motor_lk.c" @@ -190,8 +196,6 @@ devices: dependencies: bsp: ["can", "time", "mm"] component: ["user_math"] - thread_signals: - - name: "SIGNAL_LZ_MOTOR_DATA_REDY" files: header: "motor_lz.h" source: "motor_lz.c" diff --git a/assets/User_code/device/ops9.c b/assets/User_code/device/ops9.c new file mode 100644 index 0000000..70cc0aa --- /dev/null +++ b/assets/User_code/device/ops9.c @@ -0,0 +1,58 @@ +/* + ACTION全场定位码盘ops9 +*/ + +/* Includes ----------------------------------------------------------------- */ +#include "device/ops9.h" + +#include + +#include "bsp/uart.h" +#include "bsp/time.h" +/* Private define ----------------------------------------------------------- */ + + +/* Private macro ------------------------------------------------------------ */ +/* Private typedef ---------------------------------------------------------- */ +/* Private variables -------------------------------------------------------- */ +static osThreadId_t thread_alert; +static bool inited = false; + +/* Private function -------------------------------------------------------- */ +static void OPS9_RxCpltCallback(void) { + osThreadFlagsSet(thread_alert, SIGNAL_OPS9_RAW_REDY); + +} + +/* Exported functions ------------------------------------------------------- */ +int8_t OPS9_init(OPS9_t *ops9) { + if (ops9 == NULL) return DEVICE_ERR_NULL; + if (inited) return DEVICE_ERR_INITED; + if ((thread_alert = osThreadGetId()) == NULL) return DEVICE_ERR_NULL; + + BSP_UART_RegisterCallback(BSP_UART_OPS9, BSP_UART_RX_CPLT_CB, + OPS9_RxCpltCallback); + + inited = true; + return DEVICE_OK; +} + +int8_t OPS9_Restart(void) { + __HAL_UART_DISABLE(BSP_UART_GetHandle(BSP_UART_OPS9)); + __HAL_UART_ENABLE(BSP_UART_GetHandle(BSP_UART_OPS9)); + return DEVICE_OK; +} + +int8_t OPS9_StartDmaRecv(OPS9_t *ops9) { + if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_OPS9), + (uint8_t *)&(ops9->data), + sizeof(ops9->data)) == HAL_OK) + return DEVICE_OK; + return DEVICE_ERR; +} + +bool OPS9_WaitDmaCplt(uint32_t timeout) { + return (osThreadFlagsWait(SIGNAL_OPS9_RAW_REDY, osFlagsWaitAll, timeout) == + SIGNAL_OPS9_RAW_REDY); +} + diff --git a/assets/User_code/device/ops9.h b/assets/User_code/device/ops9.h new file mode 100644 index 0000000..9a0a37e --- /dev/null +++ b/assets/User_code/device/ops9.h @@ -0,0 +1,42 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ----------------------------------------------------------------- */ +#include +#include + +#include "component/user_math.h" +#include "device/device.h" +/* Exported constants ------------------------------------------------------- */ + +#define OPS9_HEADER 0x0D0A +#define OPS9_TAIL 0x0A0D + +/* Exported macro ----------------------------------------------------------- */ +/* Exported types ----------------------------------------------------------- */ + +// 数据包结构体 +typedef struct __packed { + uint16_t header; // 2字节 + float yaw; // 4字节 + float pitch; // 4字节 + float roll; // 4字节 + float x; // 4字节 + float y; // 4字节 + float angular_velocity; // 4字节 + uint16_t tail; // 2字节 +} OPS9_Data_t; // 共28字节 + +typedef struct { + DEVICE_Header_t header; // 设备头 + OPS9_Data_t data; // 存储接收到的数据 +} OPS9_t; + +/* Exported functions prototypes -------------------------------------------- */ + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/assets/User_code/task/init.c.template b/assets/User_code/task/init.c.template index d9968ef..5dc631a 100644 --- a/assets/User_code/task/init.c.template +++ b/assets/User_code/task/init.c.template @@ -8,7 +8,7 @@ /* USER INCLUDE BEGIN */ -/* USER INCLUDE BEGIN */ +/* USER INCLUDE END */ /* Private typedef ---------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */