Files
player/Project/Src/USB/USB_APP/usbd_usr.c
2025-06-27 00:32:57 +08:00

141 lines
3.0 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.

#include "usbd_usr.h"
#include "usb_dcd_int.h"
#include <stdio.h>
#include "usbd_desc.h"
#include "usbd_cdc_core.h"
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//ALIENTEK STM32开发板
//USBD-USR 代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//创建日期:2016/1/21
//版本V1.0
//版权所有,盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
//All rights reserved
//*******************************************************************************
//修改信息
//无
//////////////////////////////////////////////////////////////////////////////////
//表示USB连接状态
//0,没有连接;
//1,已经连接;
static vu8 bDeviceState=0; //默认没有连接
__ALIGN_BEGIN static USB_OTG_CORE_HANDLE USB_OTG_dev={0} __ALIGN_END;
//USB OTG 中断服务函数
//处理所有USB中断
void OTG_FS_IRQHandler(void)
{
USBD_OTG_ISR_Handler(&USB_OTG_dev);
}
//指向DEVICE_PROP结构体
//USB Device 用户回调函数.
static USBD_Usr_cb_TypeDef USR_cb =
{
USBD_USR_Init,
USBD_USR_DeviceReset,
USBD_USR_DeviceConfigured,
USBD_USR_DeviceSuspended,
USBD_USR_DeviceResumed,
USBD_USR_DeviceConnected,
USBD_USR_DeviceDisconnected,
};
//USB Device 用户自定义初始化函数
void USBD_USR_Init(void)
{
//printf("USBD_USR_Init\r\n");
}
//USB Device 复位
//speed:USB速度,0,高速;1,全速;其他,错误.
void USBD_USR_DeviceReset (uint8_t speed)
{
switch (speed)
{
case USB_OTG_SPEED_HIGH:
// printf("USB Device Library v1.1.0 [HS]\r\n");
break;
case USB_OTG_SPEED_FULL:
// printf("USB Device Library v1.1.0 [FS]\r\n");
break;
default:
// printf("USB Device Library v1.1.0 [??]\r\n");
break;
}
}
//USB Device 配置成功
void USBD_USR_DeviceConfigured (void)
{
bDeviceState=1;
// printf("MSC Interface started.\r\n");
}
//USB Device挂起
void USBD_USR_DeviceSuspended(void)
{
bDeviceState=0;
// printf("Device In suspend mode.\r\n");
}
//USB Device恢复
void USBD_USR_DeviceResumed(void)
{
// printf("Device Resumed\r\n");
}
//USB Device连接成功
void USBD_USR_DeviceConnected (void)
{
bDeviceState=1;
// printf("USB Device Connected.\r\n");
}
//USB Device未连接
void USBD_USR_DeviceDisconnected (void)
{
bDeviceState=0;
// printf("USB Device Disconnected.\r\n");
}
void USBD_InitAsVcp (void)
{
USBD_Init(&USB_OTG_dev,USB_OTG_HS_CORE_ID,&USR_desc,&USBD_CDC_cb,&USR_cb);
}
void USBD_OTG_ISR_USER (void)
{
USBD_OTG_ISR_Handler (&USB_OTG_dev);
//u32 st=USB_OTG_READ_REG32(&(&USB_OTG_dev)->regs.GREGS->GINTSTS );
u32 st=*(u32 *)0x4004001c;
//st=*(u32 *)0x40040020;
if (st==0)
{
return;
}
}
void OTG_HS_EP1_IN_ISR_USER (void)
{
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
USBD_OTG_EP1IN_ISR_Handler (&USB_OTG_dev);
#endif
}
void OTG_HS_EP1_OUT_ISR_USER (void)
{
#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
USBD_OTG_EP1OUT_ISR_Handler (&USB_OTG_dev);
#endif
}