r1upper/User/device/remote_control.h
2025-04-12 15:18:06 +08:00

82 lines
2.1 KiB
C
Raw Permalink 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.

/**
****************************(C) COPYRIGHT 2016 DJI****************************
* @file remote_control.c/h
* @brief 遥控器处理遥控器是通过类似SBUS的协议传输利用DMA传输方式节约CPU
* 资源利用串口空闲中断来拉起处理函数同时提供一些掉线重启DMA串口
* 的方式保证热插拔的稳定性。
* @note
* @history
* Version Date Author Modification
* V1.0.0 Dec-26-2018 RM 1. 完成
*
@verbatim
==============================================================================
==============================================================================
@endverbatim
****************************(C) COPYRIGHT 2016 DJI****************************
*/
#ifndef REMOTE_CONTROL_H
#define REMOTE_CONTROL_H
#ifdef __cplusplus
extern "C"{
#endif
#include "struct_typedef.h"
#include "usart.h"
#include <string.h>
#include <stdlib.h>
#define DT7 0
#if DT7==1
#define DBUS_MAX_LEN (50)//通过 UART 串口接收的最大数据长度
#define DBUS_BUFLEN (18)//每个数据帧的长度,即每次从遥控器接收的数据的长度
#define DBUS_HUART huart3
typedef __packed struct
{
int16_t ch0;
int16_t ch1;
int16_t ch2;
int16_t ch3;
int16_t roll;
uint8_t sw1;
uint8_t sw2;
} RC_ctrl_t;
#define rc_Init {0, 0, 0, 0, 0, 0, 0} // 初始化为 0
// 外部变量声明
extern uint8_t dbus_buf[DBUS_BUFLEN];
extern RC_ctrl_t rc;
extern void dbus_uart_init(void);
void rc_callback_handler(RC_ctrl_t *rc, uint8_t *buff);
void uart_receive_handler(UART_HandleTypeDef *huart);
static int uart_receive_dma_no_it(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size);
#else
#define SBUS_RX_BUF_NUM 50u
#define RC_FRAME_LENGTH 25u
typedef struct
{
int16_t ch[4];
int16_t sw[8];
}__attribute__((packed)) RC_ctrl_t;
extern void remote_control_init(void);
static void sbus_to_rc(volatile const uint8_t *sbus_buf, RC_ctrl_t *rc_ctrl);
#endif
#ifdef __cplusplus
}
#endif
#endif