添加文件1和文件2

This commit is contained in:
2025-11-27 20:08:38 +08:00
parent 5d4099938c
commit edc427c423
1675 changed files with 1068907 additions and 2830 deletions

125
PTZ/Core/Src/Remote.c Normal file
View File

@@ -0,0 +1,125 @@
#include "main.h"
#include "dma.h"
#include "gpio.h"
#include "Remote.h"
#include "usart.h"
uint8_t Remote_Status=1;
uint8_t Remote_StartFlag=1;
uint8_t dbus_buf[DBUS_BUFLEN];
rc_info_t rc = rc_Init;
extern UART_HandleTypeDef huart3;//remote
//<2F><><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>UART<52><54>DMA<4D><41><EFBFBD>գ<EFBFBD><D5A3><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ж<EFBFBD>
static int uart_receive_dma_no_it(UART_HandleTypeDef* huart, uint8_t* pData, uint32_t Size)
{
uint32_t tmp1 = 0;
tmp1 = huart->RxState;
if (tmp1 == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0))
{
return HAL_ERROR;
}
huart->pRxBuffPtr = pData;
huart->RxXferSize = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
HAL_DMA_Start(huart->hdmarx, (uint32_t)&huart->Instance->DR, (uint32_t)pData, Size);
SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
return HAL_OK;
}
else
{
return HAL_BUSY;
}
}
//<2F><>ʼ<EFBFBD><CABC>
void dbus_uart_init(void)
{
__HAL_UART_CLEAR_IDLEFLAG(&DBUS_HUART);
__HAL_UART_ENABLE_IT(&DBUS_HUART, UART_IT_IDLE);
uart_receive_dma_no_it(&DBUS_HUART, dbus_buf, DBUS_MAX_LEN);
}
//<2F><><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>
Remote_Data Remote_RxData = rc_Init;
void rc_callback_handler(rc_info_t *rc, uint8_t *buff)
{
rc->ch0 = (buff[0] | buff[1] << 8) & 0x07FF;
rc->ch0 -= 1024;
rc->ch1 = (buff[1] >> 3 | buff[2] << 5) & 0x07FF;
rc->ch1 -= 1024;
rc->ch2 = (buff[2] >> 6 | buff[3] << 2 | buff[4] << 10) & 0x07FF;
rc->ch2 -= 1024;
rc->ch3 = (buff[4] >> 1 | buff[5] << 7) & 0x07FF;
rc->ch3 -= 1024;
rc->roll = (buff[16] | (buff[17] << 8)) & 0x07FF;
rc->roll -= 1024;
rc->sw1 = ((buff[5] >> 4) & 0x000C) >> 2;
rc->sw2 = (buff[5] >> 4) & 0x0003;
Remote_RxData.Remote_R_RL = rc->ch0 ;
Remote_RxData.Remote_R_UD = rc->ch1;
Remote_RxData.Remote_L_RL = rc->ch2 ;
Remote_RxData.Remote_L_UD = rc->ch3;
Remote_RxData.Remote_ThumbWheel = rc->roll ;
Remote_RxData.Remote_LS = rc->sw1 ;
Remote_RxData.Remote_RS = rc->sw2 ;
}
//<2F><>ȡDMA<4D><41>ǰʣ<C7B0><CAA3><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>
uint16_t dma_current_data_counter(DMA_Stream_TypeDef *dma_stream)
{
return ((uint16_t)(dma_stream->NDTR));
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6><CFBD><EFBFBD>
static void uart_rx_idle_callback(UART_HandleTypeDef* huart)
{
__HAL_UART_CLEAR_IDLEFLAG(huart);
if (huart == &DBUS_HUART)
{
__HAL_DMA_DISABLE(huart->hdmarx);
if ((DBUS_MAX_LEN - dma_current_data_counter(huart->hdmarx->Instance)) == DBUS_BUFLEN)
{
rc_callback_handler(&rc, dbus_buf);
}
__HAL_DMA_SET_COUNTER(huart->hdmarx, DBUS_MAX_LEN);
__HAL_DMA_ENABLE(huart->hdmarx);
}
}
//<2F>жϽ<D0B6><CFBD><EFBFBD>
void uart_receive_handler(UART_HandleTypeDef *huart)
{
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) &&
__HAL_UART_GET_IT_SOURCE(huart, UART_IT_IDLE))
{
uart_rx_idle_callback(huart);
}
}