mirror of
https://github.com/goldenfishs/MRobot.git
synced 2026-04-01 05:17:13 +08:00
重构User_code目录结构:将文件组织到子文件夹中
主要更改: - 将所有BSP外设文件移动到独立子文件夹(can/, fdcan/, uart/等) - 将所有Component文件移动到独立子文件夹(pid/, filter/, cmd/等) - 将所有Device文件移动到独立子文件夹(dr16/, bmi088/等) - 更新代码生成器以支持新的文件夹结构 - 保持向后兼容性,支持从子文件夹或根目录加载模板 - 添加STRUCTURE.md文档说明新的目录结构 优势: ✅ 更好的代码组织和管理 ✅ 便于添加、删除、修改模板 ✅ 清晰的模块划分 ✅ 向后兼容现有结构
This commit is contained in:
58
assets/User_code/device/ops9/ops9.c
Normal file
58
assets/User_code/device/ops9/ops9.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
ACTION全场定位码盘ops9
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "device/ops9.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
49
assets/User_code/device/ops9/ops9.h
Normal file
49
assets/User_code/device/ops9/ops9.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include <cmsis_os2.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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 -------------------------------------------- */
|
||||
|
||||
int8_t OPS9_init(OPS9_t *ops9);
|
||||
int8_t OPS9_Restart(void);
|
||||
int8_t OPS9_StartDmaRecv(OPS9_t *ops9);
|
||||
bool OPS9_WaitDmaCplt(uint32_t timeout);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user