mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-23 19:25:09 +08:00
代码规范 usbvpc文档
This commit is contained in:
@@ -1,5 +1,31 @@
|
||||
//
|
||||
// Created by tuxmonkey on 2025/10/28.
|
||||
//
|
||||
/**
|
||||
* @file bsp_vpc.c
|
||||
* @author your name (you@domain.com)
|
||||
* @brief usb是单例bsp,因此不保存实例
|
||||
* @version 0.1
|
||||
* @date 2023-02-09
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bsp_vpc.h"
|
||||
#include "bsp_vpc.h"
|
||||
#include "bsp_log.h"
|
||||
#include "bsp_dwt.h"
|
||||
|
||||
static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2048
|
||||
// 注意usb单个数据包(Full speed模式下)最大为64byte,超出可能会出现丢包情况
|
||||
|
||||
uint8_t *USBInit(USB_Init_Config_s usb_conf)
|
||||
{
|
||||
// usb的软件复位(模拟拔插)在usbd_conf.c中的HAL_PCD_MspInit()中
|
||||
bsp_usb_rx_buffer = CDCInitRxbufferNcallback(usb_conf.tx_cbk, usb_conf.rx_cbk); // 获取接收数据指针
|
||||
// usb的接收回调函数会在这里被设置,并将数据保存在bsp_usb_rx_buffer中
|
||||
LOGINFO("USB init success");
|
||||
return bsp_usb_rx_buffer;
|
||||
}
|
||||
|
||||
void USBTransmit(uint8_t *buffer, uint16_t len)
|
||||
{
|
||||
CDC_Transmit_HS(buffer, len); // 发送
|
||||
}
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
//
|
||||
// Created by tuxmonkey on 2025/10/28.
|
||||
//
|
||||
/**
|
||||
* @file bsp_vpc.h
|
||||
* @author your name (you@domain.com)
|
||||
* @brief 提供对usb vpc(virtal com port)的操作接口,hid和msf考虑后续添加
|
||||
* @attention 这一版usb修改了usbd_cdc_if.c中的CDC_Receive_FS函数,若使用cube生成后会被覆盖.后续需要由usbcdciftemplate创建一套自己的模板
|
||||
* @version 0.1
|
||||
* @date 2025-11-25
|
||||
*
|
||||
* @copyright Copyright (c) 2025
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "usb_device.h"
|
||||
#include "usbd_cdc.h"
|
||||
#include "usbd_conf.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
|
||||
#ifndef TRONONEH7_SCAFFOLD_BSP_VPC_H
|
||||
#define TRONONEH7_SCAFFOLD_BSP_VPC_H
|
||||
typedef struct
|
||||
{
|
||||
USBCallback tx_cbk;
|
||||
USBCallback rx_cbk;
|
||||
} USB_Init_Config_s;
|
||||
|
||||
#endif //TRONONEH7_SCAFFOLD_BSP_VPC_H
|
||||
/* @note 虚拟串口的波特率/校验位/数据位等动态可变,取决于上位机的设定 */
|
||||
/* 使用时不需要关心这些设置(作为从机) */
|
||||
|
||||
uint8_t *USBInit(USB_Init_Config_s usb_conf); // bsp初始化时调用会重新枚举设备
|
||||
|
||||
void USBTransmit(uint8_t *buffer, uint16_t len); // 通过usb发送数据
|
||||
|
||||
Reference in New Issue
Block a user