增加了usb虚拟串口的支持,编写了部分bmi088it读取

This commit is contained in:
NeoZng
2023-02-05 14:11:59 +08:00
parent 80df9bca15
commit 637d7de114
10 changed files with 406 additions and 282 deletions

View File

@@ -1 +1,27 @@
#include "bsp_usb.h"
#include "bsp_usb.h"
static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2028
// 注意usb单个数据包(Full speed模式下)最大为64byte,超出可能会出现丢包情况
__weak void USBTransmitCpltCallback(uint32_t len)
{
// 本次发送的数据
UNUSED(len);
// 传输完成会调用此函数,to do something
}
uint8_t *USBInit()
{
USB_ResetPort(USB_OTG_FS); // 上电后重新枚举usb设备
USBTransmit((uint8_t *)"USB DEVICE READY", sizeof("USB DEVICE READY")); // 发送初始化完成信息
bsp_usb_rx_buffer = CDCInitRxbufferNcallback(USBTransmitCpltCallback); // 获取接收数据指针
return bsp_usb_rx_buffer;
}
void USBTransmit(uint8_t *buffer, uint16_t len)
{
CDC_Transmit_FS(buffer, len); // 发送
}

View File

@@ -2,4 +2,19 @@
#include "usbd_cdc.h"
#include "usbd_conf.h"
#include "usbd_desc.h"
#include "usbd_cdc_if.h"
typedef enum
{
USB_CONNECTION_RAWDATA = 0,
USB_CONNECTION_VOFA,
USB_CONNECTION_SEASKY,
} USB_Connection_Type_e; // 选择usb连接模式,默认为原始数据
// 方便调试,也可以不用
/* @note 虚拟串口的波特率/校验位/数据位等动态可变,取决于上位机的设定 */
/* 使用时不需要关心这些设置(作为从机) */
uint8_t *USBInit(); // bsp初始化时调用会重新枚举设备
void USBTransmit(uint8_t *buffer, uint16_t len); // 通过usb发送数据

3
bsp/usb/bsp_usb.md Normal file
View File

@@ -0,0 +1,3 @@
# bsp usb
简单写点,有待优化.