mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
112 lines
3.3 KiB
C
112 lines
3.3 KiB
C
/********************************** (C) COPYRIGHT *******************************
|
||
* File Name : CH58x_usb2dev.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 *pU2EP0_RAM_Addr;
|
||
uint8_t *pU2EP1_RAM_Addr;
|
||
uint8_t *pU2EP2_RAM_Addr;
|
||
uint8_t *pU2EP3_RAM_Addr;
|
||
|
||
/*********************************************************************
|
||
* @fn USB2_DeviceInit
|
||
*
|
||
* @brief USB2<42>豸<EFBFBD><E8B1B8><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>˵㣬8<E3A3AC><38>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>
|
||
*
|
||
* @param none
|
||
*
|
||
* @return none
|
||
*/
|
||
void USB2_DeviceInit(void)
|
||
{
|
||
R8_USB2_CTRL = 0x00; // <20><><EFBFBD>趨ģʽ,ȡ<><C8A1> RB_UC_CLR_ALL
|
||
|
||
R8_U2EP4_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_U2EP2_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_U2EP0_DMA = (uint16_t)(uint32_t)pU2EP0_RAM_Addr;
|
||
R16_U2EP1_DMA = (uint16_t)(uint32_t)pU2EP1_RAM_Addr;
|
||
R16_U2EP2_DMA = (uint16_t)(uint32_t)pU2EP2_RAM_Addr;
|
||
R16_U2EP3_DMA = (uint16_t)(uint32_t)pU2EP3_RAM_Addr;
|
||
|
||
R8_U2EP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
|
||
R8_U2EP1_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK | RB_UEP_AUTO_TOG;
|
||
R8_U2EP2_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK | RB_UEP_AUTO_TOG;
|
||
R8_U2EP3_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK | RB_UEP_AUTO_TOG;
|
||
R8_U2EP4_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
|
||
|
||
R8_USB2_DEV_AD = 0x00;
|
||
R8_USB2_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_USB2_IE | RB_PIN_USB2_DP_PU; // <20><>ֹUSB<53>˿ڸ<CBBF><DAB8>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
R8_USB2_INT_FG = 0xFF; // <20><><EFBFBD>жϱ<D0B6>־
|
||
R8_U2DEV_CTRL = RB_UD_PD_DIS | RB_UD_PORT_EN; // <20><><EFBFBD><EFBFBD>USB<53>˿<EFBFBD>
|
||
R8_USB2_INT_EN = RB_UIE_SUSPEND | RB_UIE_BUS_RST | RB_UIE_TRANSFER;
|
||
}
|
||
|
||
/*********************************************************************
|
||
* @fn U2DevEP1_IN_Deal
|
||
*
|
||
* @brief U2<55>˵<EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
|
||
*
|
||
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
|
||
*
|
||
* @return none
|
||
*/
|
||
void U2DevEP1_IN_Deal(uint8_t l)
|
||
{
|
||
R8_U2EP1_T_LEN = l;
|
||
R8_U2EP1_CTRL = (R8_U2EP1_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
|
||
}
|
||
|
||
/*********************************************************************
|
||
* @fn U2DevEP2_IN_Deal
|
||
*
|
||
* @brief U2<55>˵<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
|
||
*
|
||
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
|
||
*
|
||
* @return none
|
||
*/
|
||
void U2DevEP2_IN_Deal(uint8_t l)
|
||
{
|
||
R8_U2EP2_T_LEN = l;
|
||
R8_U2EP2_CTRL = (R8_U2EP2_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
|
||
}
|
||
|
||
/*********************************************************************
|
||
* @fn U2DevEP3_IN_Deal
|
||
*
|
||
* @brief U2<55>˵<EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
|
||
*
|
||
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
|
||
*
|
||
* @return none
|
||
*/
|
||
void U2DevEP3_IN_Deal(uint8_t l)
|
||
{
|
||
R8_U2EP3_T_LEN = l;
|
||
R8_U2EP3_CTRL = (R8_U2EP3_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
|
||
}
|
||
|
||
/*********************************************************************
|
||
* @fn U2DevEP4_IN_Deal
|
||
*
|
||
* @brief U2<55>˵<EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
|
||
*
|
||
* @param l - <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<64B)
|
||
*
|
||
* @return none
|
||
*/
|
||
void U2DevEP4_IN_Deal(uint8_t l)
|
||
{
|
||
R8_U2EP4_T_LEN = l;
|
||
R8_U2EP4_CTRL = (R8_U2EP4_CTRL & ~MASK_UEP_T_RES) | UEP_T_RES_ACK;
|
||
}
|