176 lines
5.2 KiB
C
Raw Normal View History

2022-03-26 20:51:40 +08:00
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_usbdev.h
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#ifndef __CH58x_USBDEV_H__
#define __CH58x_USBDEV_H__
#ifdef __cplusplus
extern "C" {
#endif
/* HID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define DEF_USB_GET_IDLE 0x02 /* get idle for key or mouse */
#define DEF_USB_GET_PROTOCOL 0x03 /* get protocol for bios type */
#define DEF_USB_SET_REPORT 0x09 /* set report for key */
#define DEF_USB_SET_IDLE 0x0A /* set idle for key or mouse */
#define DEF_USB_SET_PROTOCOL 0x0B /* set protocol for bios type */
/* <20><><EFBFBD>»<EFBFBD><C2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USBģ<42><C4A3><EFBFBD>շ<EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD>9<EFBFBD><39>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>9<EFBFBD><EFBFBD><EFBFBD><E6A3A9><EFBFBD>û<EFBFBD><C3BB>ɸ<EFBFBD><C9B8><EFBFBD>ʵ<EFBFBD><CAB5>ʹ<EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
extern uint8_t *pEP0_RAM_Addr; //ep0(64)+ep4_out(64)+ep4_in(64)
extern uint8_t *pEP1_RAM_Addr; //ep1_out(64)+ep1_in(64)
extern uint8_t *pEP2_RAM_Addr; //ep2_out(64)+ep2_in(64)
extern uint8_t *pEP3_RAM_Addr; //ep3_out(64)+ep3_in(64)
extern uint8_t *pU2EP0_RAM_Addr; //ep0(64)+ep4_out(64)+ep4_in(64)
extern uint8_t *pU2EP1_RAM_Addr; //ep1_out(64)+ep1_in(64)
extern uint8_t *pU2EP2_RAM_Addr; //ep2_out(64)+ep2_in(64)
extern uint8_t *pU2EP3_RAM_Addr; //ep3_out(64)+ep3_in(64)
#define pSetupReqPak ((PUSB_SETUP_REQ)pEP0_RAM_Addr)
#define pEP0_DataBuf (pEP0_RAM_Addr)
#define pEP1_OUT_DataBuf (pEP1_RAM_Addr)
#define pEP1_IN_DataBuf (pEP1_RAM_Addr + 64)
#define pEP2_OUT_DataBuf (pEP2_RAM_Addr)
#define pEP2_IN_DataBuf (pEP2_RAM_Addr + 64)
#define pEP3_OUT_DataBuf (pEP3_RAM_Addr)
#define pEP3_IN_DataBuf (pEP3_RAM_Addr + 64)
#define pEP4_OUT_DataBuf (pEP0_RAM_Addr + 64)
#define pEP4_IN_DataBuf (pEP0_RAM_Addr + 128)
#define pU2SetupReqPak ((PUSB_SETUP_REQ)pU2EP0_RAM_Addr)
#define pU2EP0_DataBuf (pU2EP0_RAM_Addr)
#define pU2EP1_OUT_DataBuf (pU2EP1_RAM_Addr)
#define pU2EP1_IN_DataBuf (pU2EP1_RAM_Addr + 64)
#define pU2EP2_OUT_DataBuf (pU2EP2_RAM_Addr)
#define pU2EP2_IN_DataBuf (pU2EP2_RAM_Addr + 64)
#define pU2EP3_OUT_DataBuf (pU2EP3_RAM_Addr)
#define pU2EP3_IN_DataBuf (pU2EP3_RAM_Addr + 64)
#define pU2EP4_OUT_DataBuf (pU2EP0_RAM_Addr + 64)
#define pU2EP4_IN_DataBuf (pU2EP0_RAM_Addr + 128)
/**
* @brief USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><EFBFBD><EFBFBD>˵8<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void USB_DeviceInit(void);
/**
* @brief USB<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void USB_DevTransProcess(void);
/**
* @brief <EFBFBD>˵<EFBFBD>1<EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
*
* @param l - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP1_OUT_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>2<EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
*
* @param l - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP2_OUT_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>3<EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
*
* @param l - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP3_OUT_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>4<EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
*
* @param l - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP4_OUT_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP1_IN_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP2_IN_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP3_IN_Deal(uint8_t l);
/**
* @brief <EFBFBD>˵<EFBFBD>4<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
*
* @param l - <EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<64B)
*/
void DevEP4_IN_Deal(uint8_t l);
/**
* @brief <EFBFBD><EFBFBD>ѯ<EFBFBD>˵<EFBFBD>1<EFBFBD>Ƿ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return 0-δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (!0)-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define EP1_GetINSta() (R8_UEP1_CTRL & UEP_T_RES_NAK)
/**
* @brief <EFBFBD><EFBFBD>ѯ<EFBFBD>˵<EFBFBD>2<EFBFBD>Ƿ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return 0-δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (!0)-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define EP2_GetINSta() (R8_UEP2_CTRL & UEP_T_RES_NAK)
/**
* @brief <EFBFBD><EFBFBD>ѯ<EFBFBD>˵<EFBFBD>3<EFBFBD>Ƿ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return 0-δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (!0)-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define EP3_GetINSta() (R8_UEP3_CTRL & UEP_T_RES_NAK)
/**
* @brief <EFBFBD><EFBFBD>ѯ<EFBFBD>˵<EFBFBD>4<EFBFBD>Ƿ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return 0-δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (!0)-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define EP4_GetINSta() (R8_UEP4_CTRL & UEP_T_RES_NAK)
void USB2_DeviceInit(void); /* USB2<42><EFBFBD><E8B1B8><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>˵㣬8<E3A3AC><38>ͨ<EFBFBD><CDA8> */
void USB2_DevTransProcess(void); /* USB2<42>豸Ӧ<E8B1B8><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4B4A6> */
void U2DevEP1_OUT_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>1<EFBFBD>´<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP2_OUT_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>2<EFBFBD>´<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP3_OUT_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>3<EFBFBD>´<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP4_OUT_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>4<EFBFBD>´<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP1_IN_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>1<EFBFBD>ϴ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP2_IN_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>2<EFBFBD>ϴ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP3_IN_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>3<EFBFBD>ϴ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void U2DevEP4_IN_Deal(uint8_t l); /* <20><EFBFBD>˵<EFBFBD>4<EFBFBD>ϴ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
// 0-δ<><CEB4><EFBFBD><EFBFBD> (!0)-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define U2EP1_GetINSta() (R8_U2EP1_CTRL & UEP_T_RES_NAK) /* <20><>ѯ<EFBFBD>˵<EFBFBD>1<EFBFBD>Ƿ<EFBFBD><C7B7>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
#define U2EP2_GetINSta() (R8_U2EP2_CTRL & UEP_T_RES_NAK) /* <20><>ѯ<EFBFBD>˵<EFBFBD>2<EFBFBD>Ƿ<EFBFBD><C7B7>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
#define U2EP3_GetINSta() (R8_U2EP3_CTRL & UEP_T_RES_NAK) /* <20><>ѯ<EFBFBD>˵<EFBFBD>3<EFBFBD>Ƿ<EFBFBD><C7B7>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
#define U2EP4_GetINSta() (R8_U2EP4_CTRL & UEP_T_RES_NAK) /* <20><>ѯ<EFBFBD>˵<EFBFBD>4<EFBFBD>Ƿ<EFBFBD><C7B7>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
#ifdef __cplusplus
}
#endif
#endif // __CH58x_USBDEV_H__