mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 03:27:45 +08:00
videotransmiter
This commit is contained in:
144
User_Code/module/periph/remote_control/videotransmiter.c
Normal file
144
User_Code/module/periph/remote_control/videotransmiter.c
Normal file
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// Created by ASUS on 2025/12/5.
|
||||
//
|
||||
|
||||
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : Image_Transmission.c
|
||||
* @brief : Image_Transmission_Info interfaces functions
|
||||
* @author :
|
||||
* @date : 2025/4/20
|
||||
* @version : v1.0
|
||||
******************************************************************************
|
||||
* @attention : to be tested
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
#include "videotransmiter.h"
|
||||
#include "CRC.h"
|
||||
#include "usart.h"
|
||||
|
||||
__attribute__((section (".AXI_SRAM"))) uint8_t Image_Trans_MultiRx_Buff[2][39];
|
||||
|
||||
Image_Transmission_Info_TypeDef Image_Transmission_Info;
|
||||
VT13_Info_TypeDef VT13_Info;
|
||||
|
||||
static int16_t bit8TObit16(uint8_t change_info[2]);
|
||||
|
||||
void Image_Transmission_Info_Update(uint8_t *Buff)
|
||||
{
|
||||
Image_Transmission_Info.Index = 0;
|
||||
Image_Transmission_Info.DataLength = 0;
|
||||
/*Check the header frame */
|
||||
|
||||
if (Buff[0] == 0xA5)
|
||||
{
|
||||
|
||||
if (Verify_CRC8_Check_Sum(&Buff[0], 5) == true)
|
||||
{
|
||||
|
||||
Image_Transmission_Info.DataLength =
|
||||
(uint16_t) (Buff[Image_Transmission_Info.Index + 2] << 8 | Buff[Image_Transmission_Info.Index + 1])
|
||||
+ FrameHeader_Length + CMDID_Length + CRC16_Length;
|
||||
|
||||
if (Verify_CRC16_Check_Sum(&Buff[Image_Transmission_Info.Index], Image_Transmission_Info.DataLength) ==
|
||||
true)
|
||||
{
|
||||
|
||||
#ifdef CUSTOM_ROBOT_DATA_ID
|
||||
|
||||
if (Image_Transmission_Info.DataLength == 39)
|
||||
{
|
||||
for (uint8_t i = 0; i < 30; i++)
|
||||
{
|
||||
Image_Transmission_Info.custom_robot_data.data[i] = Buff[
|
||||
Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length + i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef REMOTE_CONTROL_ID
|
||||
|
||||
if (Image_Transmission_Info.DataLength == 21)
|
||||
{
|
||||
Image_Transmission_Info.remote_control.mouse_x = bit8TObit16(
|
||||
&Buff[Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length]);
|
||||
Image_Transmission_Info.remote_control.mouse_y = bit8TObit16(
|
||||
&Buff[Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length + 2]);
|
||||
Image_Transmission_Info.remote_control.mouse_z = bit8TObit16(
|
||||
&Buff[Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length + 4]);
|
||||
Image_Transmission_Info.remote_control.left_button_down = Buff[
|
||||
Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length + 6];
|
||||
Image_Transmission_Info.remote_control.right_button_down = Buff[
|
||||
Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length + 7];
|
||||
Image_Transmission_Info.remote_control.Key.keyboard_value = bit8TObit16(
|
||||
&Buff[Image_Transmission_Info.Index + FrameHeader_Length + CMDID_Length + 8]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (Buff[0] == 0xA9)
|
||||
{
|
||||
|
||||
if (Buff[1] == 0x53)
|
||||
{
|
||||
|
||||
VT13_Info_Update(Buff, &VT13_Info);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VT13_Info_Update(uint8_t *Buff, VT13_Info_TypeDef *VT13_Info)
|
||||
{
|
||||
|
||||
if (Verify_CRC16_Check_Sum(&Buff[0], 21) == true)
|
||||
{
|
||||
|
||||
VT13_Info->RC.Channel[0] = ((Buff[2]) | (Buff[3] << 8)) & 0x07FF;
|
||||
VT13_Info->RC.Channel[1] = ((Buff[3] >> 3) | (Buff[4] << 5)) & 0x07FF;
|
||||
VT13_Info->RC.Channel[2] = ((Buff[4] >> 6) | (Buff[5] << 2) | (Buff[6] << 10)) & 0x07FF;
|
||||
VT13_Info->RC.Channel[3] = ((Buff[6] >> 1) | (Buff[7] << 7)) & 0x07FF;
|
||||
VT13_Info->RC.Switch = (Buff[7] >> 4) & 0x03;
|
||||
VT13_Info->RC.Stop = (Buff[7] >> 6) & 0x01;
|
||||
VT13_Info->RC.Left = (Buff[7] >> 7) & 0x01;
|
||||
VT13_Info->RC.Right = (Buff[8]) & 0x01;
|
||||
VT13_Info->RC.Wheel = ((Buff[8] >> 1) | (Buff[9] << 7)) & 0x07FF;
|
||||
VT13_Info->RC.Trigger = (Buff[9] >> 4) & 0x01;
|
||||
|
||||
VT13_Info->RC.Channel[0] -= 1024;
|
||||
VT13_Info->RC.Channel[1] -= 1024;
|
||||
VT13_Info->RC.Channel[2] -= 1024;
|
||||
VT13_Info->RC.Channel[3] -= 1024;
|
||||
VT13_Info->RC.Wheel -= 1024;
|
||||
|
||||
VT13_Info->Mouse.X = (Buff[10] | (Buff[11] << 8));
|
||||
VT13_Info->Mouse.Y = (Buff[12] | (Buff[13] << 8));
|
||||
VT13_Info->Mouse.Z = (Buff[14] | (Buff[15] << 8));
|
||||
|
||||
VT13_Info->Mouse.Press_L = (Buff[16]) & 0x03;
|
||||
VT13_Info->Mouse.Press_R = (Buff[16] >> 2) & 0x03;
|
||||
VT13_Info->Mouse.Press_M = (Buff[16] >> 4) & 0x03;
|
||||
|
||||
VT13_Info->Key.V = (Buff[17] | (Buff[18] << 8));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int16_t bit8TObit16(uint8_t change_info[2])
|
||||
{
|
||||
union
|
||||
{
|
||||
int16_t bit16;
|
||||
uint8_t byte[2];
|
||||
} u16val;
|
||||
|
||||
u16val.byte[0] = change_info[0];
|
||||
u16val.byte[1] = change_info[1];
|
||||
|
||||
return u16val.bit16;
|
||||
}
|
||||
179
User_Code/module/periph/remote_control/videotransmiter.h
Normal file
179
User_Code/module/periph/remote_control/videotransmiter.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : Image_Transmission.h
|
||||
* @brief : The header file of Image_Transmission.c
|
||||
* @author :
|
||||
* @date : 2025/04/20
|
||||
* @version : v1.0
|
||||
******************************************************************************
|
||||
* @attention : None
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef VIDEOTRANSMITER_H
|
||||
#define VIDEOTRANSMITER_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "stdbool.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "math.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define IMAGE_TRANS_RX_LENGTH 39 //frame_header 5bytes , cmd_id 2bytes , data_max 30bytes , crc16 2bytes = bytes
|
||||
|
||||
#define FrameHeader_Length 5U /*!< the length of frame header */
|
||||
#define CMDID_Length 2U /*!< the length of CMD ID */
|
||||
#define CRC16_Length 2U /*!< the length of CRC ID */
|
||||
|
||||
#define CUSTOM_ROBOT_DATA_ID 0x0302U
|
||||
#define ROBOT_CUSTOM_DATA_ID 0x0309U
|
||||
#define REMOTE_CONTROL_ID 0x0304U
|
||||
|
||||
/**
|
||||
* @brief The custom controller sends data to the corresponding robot through the image transmission, id: 0x0302U
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
|
||||
uint8_t data[30];
|
||||
|
||||
} custom_robot_data_t;
|
||||
|
||||
/**
|
||||
* @brief The robot sends data to the custom controller connected to the player end through the image transmission, id: 0x0309U
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
|
||||
uint8_t data[30];
|
||||
|
||||
} robot_custom_data_t;
|
||||
|
||||
/**
|
||||
* @brief The keyboard and mouse remote control data sent to the robot through the image transmission, id: 0x0304U
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
|
||||
int16_t mouse_x;
|
||||
int16_t mouse_y;
|
||||
int16_t mouse_z;
|
||||
int8_t left_button_down;
|
||||
int8_t right_button_down;
|
||||
|
||||
union
|
||||
{
|
||||
uint16_t keyboard_value;
|
||||
|
||||
struct
|
||||
{
|
||||
uint16_t W: 1;
|
||||
uint16_t S: 1;
|
||||
uint16_t A: 1;
|
||||
uint16_t D: 1;
|
||||
uint16_t SHIFT: 1;
|
||||
uint16_t CTRL: 1;
|
||||
uint16_t Q: 1;
|
||||
uint16_t E: 1;
|
||||
uint16_t R: 1;
|
||||
uint16_t F: 1;
|
||||
uint16_t G: 1;
|
||||
uint16_t Z: 1;
|
||||
uint16_t X: 1;
|
||||
uint16_t C: 1;
|
||||
uint16_t V: 1;
|
||||
uint16_t B: 1;
|
||||
} Set;
|
||||
} Key;
|
||||
|
||||
uint16_t reserved;
|
||||
|
||||
} remote_control_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
uint8_t Index;
|
||||
uint16_t DataLength;
|
||||
|
||||
#ifdef CUSTOM_ROBOT_DATA_ID
|
||||
custom_robot_data_t custom_robot_data;
|
||||
#endif
|
||||
|
||||
#ifdef ROBOT_CUSTOM_DATA_ID
|
||||
robot_custom_data_t robot_custom_data;
|
||||
#endif
|
||||
|
||||
#ifdef REMOTE_CONTROL_ID
|
||||
remote_control_t remote_control;
|
||||
#endif
|
||||
} Image_Transmission_Info_TypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
int16_t Channel[4];
|
||||
uint8_t Switch;
|
||||
uint8_t Stop;
|
||||
uint8_t Left;
|
||||
uint8_t Right;
|
||||
int16_t Wheel;
|
||||
uint8_t Trigger;
|
||||
} RC;
|
||||
|
||||
struct
|
||||
{
|
||||
int16_t X;
|
||||
int16_t Y;
|
||||
int16_t Z;
|
||||
uint8_t Press_L;
|
||||
uint8_t Press_R;
|
||||
uint8_t Press_M;
|
||||
} Mouse;
|
||||
|
||||
union
|
||||
{
|
||||
uint16_t V;
|
||||
|
||||
struct
|
||||
{
|
||||
uint16_t W: 1;
|
||||
uint16_t S: 1;
|
||||
uint16_t A: 1;
|
||||
uint16_t D: 1;
|
||||
uint16_t SHIFT: 1;
|
||||
uint16_t CTRL: 1;
|
||||
uint16_t Q: 1;
|
||||
uint16_t E: 1;
|
||||
uint16_t R: 1;
|
||||
uint16_t F: 1;
|
||||
uint16_t G: 1;
|
||||
uint16_t Z: 1;
|
||||
uint16_t X: 1;
|
||||
uint16_t C: 1;
|
||||
uint16_t V: 1;
|
||||
uint16_t B: 1;
|
||||
} Set;
|
||||
} Key;
|
||||
|
||||
} VT13_Info_TypeDef;
|
||||
|
||||
/* Exported variables ---------------------------------------------------------*/
|
||||
extern uint8_t Image_Trans_MultiRx_Buff[2][39];
|
||||
extern VT13_Info_TypeDef VT13_Info;
|
||||
extern Image_Transmission_Info_TypeDef Image_Transmission_Info;
|
||||
|
||||
extern void Robot_Data_to_Custom_(uint8_t *Data);
|
||||
|
||||
extern void Image_Transmission_Info_Update(uint8_t *Buff);
|
||||
|
||||
extern void VT13_Info_Update(uint8_t *Data, VT13_Info_TypeDef *VT13_Info);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user