2022-03-26 20:51:40 +08:00

112 lines
3.2 KiB
C
Raw 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.

/********************************** (C) COPYRIGHT *******************************
* File Name : CH58x_usbdev.c
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#include "CH58x_common.h"
uint8_t *pEP0_RAM_Addr;
uint8_t *pEP1_RAM_Addr;
uint8_t *pEP2_RAM_Addr;
uint8_t *pEP3_RAM_Addr;
/*********************************************************************
* @fn USB_DeviceInit
*
* @brief USB<53><EFBFBD><E8B1B8><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>˵㣬8<E3A3AC><38>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>
*
* @param none
*
* @return none
*/
void USB_DeviceInit(void)
{
R8_USB_CTRL = 0x00; // <20><><EFBFBD>趨ģʽ<><C8A1> RB_UC_CLR_ALL
R8_UEP4_1_MOD = RB_UEP4_RX_EN | RB_UEP4_TX_EN | RB_UEP1_RX_EN | RB_UEP1_TX_EN; // <20>˵<EFBFBD>4 OUT+IN,<2C>˵<EFBFBD>1 OUT+IN
R8_UEP2_3_MOD = RB_UEP2_RX_EN | RB_UEP2_TX_EN | RB_UEP3_RX_EN | RB_UEP3_TX_EN; // <20>˵<EFBFBD>2 OUT+IN,<2C>˵<EFBFBD>3 OUT+IN
R16_UEP0_DMA = (uint16_t)(uint32_t)pEP0_RAM_Addr;
R16_UEP1_DMA = (uint16_t)(uint32_t)pEP1_RAM_Addr;
R16_UEP2_DMA = (uint16_t)(uint32_t)pEP2_RAM_Addr;
R16_UEP3_DMA = (uint16_t)(uint32_t)pEP3_RAM_Addr;
R8_UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
R8_UEP1_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK | RB_UEP_AUTO_TOG;
R8_UEP2_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK | RB_UEP_AUTO_TOG;
R8_UEP3_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK | RB_UEP_AUTO_TOG;
R8_UEP4_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
R8_USB_DEV_AD = 0x00;
R8_USB_CTRL = RB_UC_DEV_PU_EN | RB_UC_INT_BUSY | RB_UC_DMA_EN; // <20><><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8>DMA<4D><41><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ڼ<EFBFBD><DABC>жϱ<D0B6>־δ<D6BE><CEB4><EFBFBD><EFBFBD>ǰ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>NAK
R16_PIN_ANALOG_IE |= RB_PIN_USB_IE | RB_PIN_USB_DP_PU; // <20><>ֹUSB<53>˿ڸ<CBBF><DAB8>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
R8_USB_INT_FG = 0xFF; // <20><><EFBFBD>жϱ<D0B6>־
R8_UDEV_CTRL = RB_UD_PD_DIS | RB_UD_PORT_EN; // <20><><EFBFBD><EFBFBD>USB<53>˿<EFBFBD>
R8_USB_INT_EN = RB_UIE_SUSPEND | RB_UIE_BUS_RST | RB_UIE_TRANSFER;
}
/*********************************************************************
* @fn DevEP1_IN_Deal
*
* @brief <20>˵<EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
*
* @return none
*/
void DevEP1_IN_Deal(uint8_t l)
{
R8_UEP1_T_LEN = l;
R8_UEP1_CTRL = (R8_UEP1_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
}
/*********************************************************************
* @fn DevEP2_IN_Deal
*
* @brief <20>˵<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
*
* @return none
*/
void DevEP2_IN_Deal(uint8_t l)
{
R8_UEP2_T_LEN = l;
R8_UEP2_CTRL = (R8_UEP2_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
}
/*********************************************************************
* @fn DevEP3_IN_Deal
*
* @brief <20>˵<EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
*
* @return none
*/
void DevEP3_IN_Deal(uint8_t l)
{
R8_UEP3_T_LEN = l;
R8_UEP3_CTRL = (R8_UEP3_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
}
/*********************************************************************
* @fn DevEP4_IN_Deal
*
* @brief <20>˵<EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
*
* @return none
*/
void DevEP4_IN_Deal(uint8_t l)
{
R8_UEP4_T_LEN = l;
R8_UEP4_CTRL = (R8_UEP4_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
}