95 lines
2.4 KiB
C
95 lines
2.4 KiB
C
/********************************** (C) COPYRIGHT *******************************
|
|
* File Name : main.c
|
|
* Author : WCH
|
|
* Version : V1.0.0
|
|
* Date : 2021/06/06
|
|
* Description : Main program body.
|
|
*********************************************************************************
|
|
* 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.
|
|
*******************************************************************************/
|
|
|
|
/* @Note
|
|
* Compatibility HID Example:
|
|
* This program provides examples of the pass-through of USB-HID data and serial port
|
|
* data based on compatibility HID device. And the data returned by Get_Report request is
|
|
* the data sent by the last Set_Report request.Speed of UART1/2 is 115200bps.
|
|
*
|
|
* Interrupt Transfers:
|
|
* UART2_RX ---> Endpoint2
|
|
* Endpoint1 ---> UART2_TX
|
|
*
|
|
* Note that the first byte is the valid data length and the remaining bytes are
|
|
* the transmission data for interrupt Transfers.
|
|
*
|
|
* Control Transfers:
|
|
* Set_Report ---> UART1_TX
|
|
* Get_Report <--- last Set_Report packet
|
|
*
|
|
* */
|
|
|
|
#include "ch32v20x_usbfs_device.h"
|
|
#include "debug.h"
|
|
#include "usbd_compatibility_hid.h"
|
|
/*********************************************************************
|
|
* @fn Var_Init
|
|
*
|
|
* @brief Software parameter initialisation
|
|
*
|
|
* @return none
|
|
*/
|
|
void Var_Init(void)
|
|
{
|
|
uint16_t i;
|
|
RingBuffer_Comm.LoadPtr = 0;
|
|
RingBuffer_Comm.StopFlag = 0;
|
|
RingBuffer_Comm.DealPtr = 0;
|
|
RingBuffer_Comm.RemainPack = 0;
|
|
for(i=0; i<DEF_Ring_Buffer_Max_Blks; i++)
|
|
{
|
|
RingBuffer_Comm.PackLen[i] = 0;
|
|
}
|
|
}
|
|
|
|
/*********************************************************************
|
|
* @fn main
|
|
*
|
|
* @brief Main program.
|
|
*
|
|
* @return none
|
|
*/
|
|
int main(void)
|
|
{
|
|
Delay_Init();
|
|
USART_Printf_Init( 115200 );
|
|
printf("SystemClk:%d\r\n",SystemCoreClock);
|
|
printf("USBHD Compatibility HID Example\r\n");
|
|
Delay_Ms(10);
|
|
|
|
/* Variables init */
|
|
Var_Init();
|
|
|
|
/* UART2 init */
|
|
UART2_Init();
|
|
UART2_DMA_Init();
|
|
|
|
/* Usb Init */
|
|
USBFS_RCC_Init();
|
|
USBFS_Device_Init(ENABLE);
|
|
NVIC_EnableIRQ(USBHD_IRQn);
|
|
|
|
/* Timer init */
|
|
TIM2_Init();
|
|
|
|
while(1)
|
|
{
|
|
if(USBFS_DevEnumStatus)
|
|
{
|
|
UART2_Rx_Service();
|
|
UART2_Tx_Service();
|
|
HID_Set_Report_Deal();
|
|
}
|
|
}
|
|
}
|