/********************************** (C) COPYRIGHT *******************************
* File Name : app_km.c
* Author : WCH
* Version : V1.0.0
* Date : 2022/09/01
* Description : The USB host operates the keyboard and mouse.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/********************************************************************************/
/* Header File */
#include "usb_host_config.h"
/*******************************************************************************/
/* Variable Definition */
uint8_t DevDesc_Buf[ 18 ]; // Device Descriptor Buffer
uint8_t Com_Buf[ DEF_COM_BUF_LEN ]; // General Buffer
struct _ROOT_HUB_DEVICE RootHubDev[ DEF_TOTAL_ROOT_HUB ];
struct __HOST_CTL HostCtl[ DEF_TOTAL_ROOT_HUB * DEF_ONE_USB_SUP_DEV_TOTAL ];
extern volatile u8 RxCnt1;
extern u8 RxFlag;
extern u8 RxBuffer1[255];
/*******************************************************************************/
/* Interrupt Function Declaration */
void TIM3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/*********************************************************************
* @fn TIM3_Init
*
* @brief Initialize timer3 for getting keyboard and mouse data.
*
* @param arr - The specific period value.
* psc - The specifies prescaler value.
*
* @return none
*/
void TIM3_Init( uint16_t arr, uint16_t psc )
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure = { 0 };
NVIC_InitTypeDef NVIC_InitStructure = { 0 };
/* Enable timer3 clock */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
/* Initialize timer3 */
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler = psc;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
/* Enable updating timer3 interrupt */
TIM_ITConfig( TIM3, TIM_IT_Update, ENABLE );
/* Configure timer3 interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( &NVIC_InitStructure );
/* Enable timer3 */
TIM_Cmd( TIM3, ENABLE );
/* Enable timer3 interrupt */
NVIC_EnableIRQ( TIM3_IRQn );
}
/*********************************************************************
* @fn TIM3_IRQHandler
*
* @brief This function handles TIM3 global interrupt request.
*
* @return none
*/
void TIM3_IRQHandler( void )
{
uint8_t usb_port;
uint8_t hub_port;
uint8_t index;
uint8_t intf_num, in_num;
if( TIM_GetITStatus( TIM3, TIM_IT_Update ) != RESET )
{
/* Clear interrupt flag */
TIM_ClearITPendingBit( TIM3, TIM_IT_Update );
/* USB HID Device Input Endpoint Timing */
for( usb_port = 0; usb_port < DEF_TOTAL_ROOT_HUB; usb_port++ )
{
if( RootHubDev[ usb_port ].bStatus >= ROOT_DEV_SUCCESS )
{
index = RootHubDev[ usb_port ].DeviceIndex;
if(( RootHubDev[ usb_port ].bType == USB_DEV_CLASS_HID) ||(RootHubDev[ usb_port ].bType == USB_DEV_CLASS_VEN_SPEC ))
{
for( intf_num = 0; intf_num < HostCtl[ index ].InterfaceNum; intf_num++ )
{
for( in_num = 0; in_num < HostCtl[ index ].Interface[ intf_num ].InEndpNum; in_num++ )
{
HostCtl[ index ].Interface[ intf_num ].InEndpTimeCount[ in_num ]++;
}
}
}
else if( RootHubDev[ usb_port ].bType == USB_DEV_CLASS_HUB )
{
HostCtl[ index ].Interface[ 0 ].InEndpTimeCount[ 0 ]++;
for( hub_port = 0; hub_port < RootHubDev[ usb_port ].bPortNum; hub_port++ )
{
if( RootHubDev[ usb_port ].Device[ hub_port ].bStatus >= ROOT_DEV_SUCCESS )
{
index = RootHubDev[ usb_port ].Device[ hub_port ].DeviceIndex;
if( RootHubDev[ usb_port ].Device[ hub_port ].bType == USB_DEV_CLASS_HID )
{
for( intf_num = 0; intf_num < HostCtl[ index ].InterfaceNum; intf_num++ )
{
for( in_num = 0; in_num < HostCtl[ index ].Interface[ intf_num ].InEndpNum; in_num++ )
{
HostCtl[ index ].Interface[ intf_num ].InEndpTimeCount[ in_num ]++;
}
}
}
}
}
}
}
}
}
}
/*********************************************************************
* @fn USBH_CheckRootHubPortStatus
*
* @brief Check status of USB port.
*
* @para index: USB host port
*
* @return The current status of the port.
*/
uint8_t USBH_CheckRootHubPortStatus( uint8_t usb_port )
{
uint8_t s = ERR_USB_UNSUPPORT;
if( usb_port == DEF_USBFS_PORT_INDEX )
{
#if DEF_USBFS_PORT_EN
s = USBFSH_CheckRootHubPortStatus( RootHubDev[ usb_port ].bStatus );
#endif
}
else if( usb_port == DEF_USBHS_PORT_INDEX )
{
#if DEF_USBHS_PORT_EN
s = USBHSH_CheckRootHubPortStatus( RootHubDev[ usb_port ].bStatus );
#endif
}
return s;
}
/*********************************************************************
* @fn USBH_ResetRootHubPort
*
* @brief Reset USB port.
*
* @para index: USB host port
* mod: Reset host port operating mode.
* 0 -> reset and wait end
* 1 -> begin reset
* 2 -> end reset
*
* @return none
*/
void USBH_ResetRootHubPort( uint8_t usb_port, uint8_t mode )
{
if( usb_port == DEF_USBFS_PORT_INDEX )
{
#if DEF_USBFS_PORT_EN
USBFSH_ResetRootHubPort( mode );
#endif
}
else if( usb_port == DEF_USBHS_PORT_INDEX )
{
#if DEF_USBHS_PORT_EN
USBHSH_ResetRootHubPort( mode );
#endif
}
}
/*********************************************************************
* @fn USBH_EnableRootHubPort
*
* @brief Enable USB host port.
*
* @para index: USB host port
*
* @return none
*/
uint8_t USBH_EnableRootHubPort( uint8_t usb_port )
{
uint8_t s = ERR_USB_UNSUPPORT;
if( usb_port == DEF_USBFS_PORT_INDEX )
{
#if DEF_USBFS_PORT_EN
s = USBFSH_EnableRootHubPort( &RootHubDev[ usb_port ].bSpeed );
#endif
}
else if( usb_port == DEF_USBHS_PORT_INDEX )
{
#if DEF_USBHS_PORT_EN
s = USBHSH_EnableRootHubPort( &RootHubDev[ usb_port ].bSpeed );
#endif
}
return s;
}
/*********************************************************************
* @fn USBH_GetDeviceDescr
*
* @brief Get the device descriptor of the USB device.
*
* @para index: USB host port
*
* @return none
*/
uint8_t USBH_GetDeviceDescr( uint8_t usb_port )
{
uint8_t s = ERR_USB_UNSUPPORT;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用CH32V307开发板 USB host 驱动CDC设备(usb 转串口) 芯片为FT232, CP210 和CH340原理相同不在赘述。 使用MounRiver 打开。相比STM32,CH32更具有优势,价格便宜,内置高速PHY,非常适合做USB开发。完全裸机不调用任何系统上的驱动。 文件为整个工程,包含所有文件,直接编译后,下载到官方的EVT开发板中使用USB HS端口,插入FT232线后即可使用。
资源推荐
资源详情
资源评论
收起资源包目录
USB Host 驱动CDC类设备 FT232 (114个子文件)
app_cdc.c 86KB
system_ch32v30x.c 29KB
ch32v30x_usbhs_host.c 21KB
ch32v30x_usbfs_host.c 21KB
usb_host_hub.c 5KB
main.c 5KB
usb_host_hid.c 4KB
ch32v30x_it.c 1KB
.cproject 24KB
main.d 7KB
ch32v30x_usbfs_host.d 6KB
ch32v30x_usbhs_host.d 6KB
usb_host_hid.d 6KB
usb_host_hub.d 6KB
app_cdc.d 6KB
ch32v30x_opa.d 6KB
ch32v30x_dvp.d 6KB
ch32v30x_eth.d 6KB
ch32v30x_rng.d 6KB
debug.d 6KB
ch32v30x_dbgmcu.d 6KB
ch32v30x_usart.d 6KB
ch32v30x_flash.d 6KB
ch32v30x_wwdg.d 6KB
ch32v30x_sdio.d 6KB
ch32v30x_gpio.d 6KB
ch32v30x_misc.d 6KB
ch32v30x_iwdg.d 6KB
ch32v30x_fsmc.d 6KB
ch32v30x_exti.d 6KB
ch32v30x_spi.d 6KB
ch32v30x_bkp.d 6KB
ch32v30x_rtc.d 6KB
ch32v30x_crc.d 6KB
ch32v30x_tim.d 6KB
ch32v30x_rcc.d 6KB
ch32v30x_i2c.d 6KB
ch32v30x_can.d 6KB
ch32v30x_pwr.d 6KB
ch32v30x_adc.d 6KB
ch32v30x_dac.d 6KB
ch32v30x_dma.d 6KB
ch32v30x_it.d 6KB
system_ch32v30x.d 5KB
startup_ch32v30x_D8C.d 130B
core_riscv.d 104B
HOST_CDC.elf 244KB
ch32v30x_usb.h 34KB
usb_host_config.h 6KB
ch32v30x_usbhs_host.h 5KB
ch32v30x_usbfs_host.h 5KB
app_cdc.h 4KB
usb_host_hub.h 2KB
usb_host_hid.h 2KB
ch32v30x_conf.h 1KB
system_ch32v30x.h 1KB
ch32v30x_it.h 757B
HOST_CDC.hex 52KB
HOST_CDC.lst 344KB
makefile 2KB
HOST_CDC.map 209KB
HOST_KM_N.map 209KB
HOST_KM.map 204KB
subdir.mk 25KB
subdir.mk 2KB
subdir.mk 1KB
subdir.mk 1KB
subdir.mk 1KB
subdir.mk 1KB
sources.mk 676B
objects.mk 299B
app_cdc.o 246KB
ch32v30x_tim.o 174KB
ch32v30x_eth.o 168KB
ch32v30x_rcc.o 89KB
ch32v30x_can.o 84KB
ch32v30x_usbhs_host.o 83KB
ch32v30x_adc.o 82KB
ch32v30x_flash.o 82KB
ch32v30x_usbfs_host.o 80KB
ch32v30x_i2c.o 64KB
ch32v30x_usart.o 62KB
ch32v30x_spi.o 51KB
ch32v30x_gpio.o 49KB
ch32v30x_sdio.o 46KB
ch32v30x_fsmc.o 45KB
debug.o 39KB
ch32v30x_pwr.o 37KB
ch32v30x_dma.o 33KB
ch32v30x_rtc.o 32KB
main.o 31KB
ch32v30x_dac.o 31KB
ch32v30x_bkp.o 31KB
usb_host_hub.o 30KB
usb_host_hid.o 27KB
ch32v30x_misc.o 26KB
system_ch32v30x.o 24KB
ch32v30x_exti.o 23KB
core_riscv.o 20KB
ch32v30x_wwdg.o 20KB
共 114 条
- 1
- 2
资源评论
- luy37280002023-12-07感谢楼主,分享这么详细的心得,受益匪浅!
snail_dongbin
- 粉丝: 189
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功