CH592_Makefile_Template/sdk/StdPeriphDriver/inc/CH59x_usbdev.h
2023-12-21 22:44:09 +07:00

153 lines
4.1 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 : CH59x_usbdev.h
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
*********************************************************************************
* 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.
*******************************************************************************/
#ifndef __CH59x_USBDEV_H__
#define __CH59x_USBDEV_H__
#ifdef __cplusplus
extern "C" {
#endif
/* HID类请求 */
#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 */
/* 以下缓存区是USB模块收发使用的数据缓冲区总共9个通道9块缓存用户可根据实际使用的通道数定义相应缓存区 */
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)
#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)
/**
* @brief USB设备功能初始化4个端点8个通道。
*/
void USB_DeviceInit(void);
/**
* @brief USB设备应答传输处理
*/
void USB_DevTransProcess(void);
/**
* @brief 端点1下传数据处理
*
* @param l - 待处理数据长度(<64B)
*/
void DevEP1_OUT_Deal(uint8_t l);
/**
* @brief 端点2下传数据处理
*
* @param l - 待处理数据长度(<64B)
*/
void DevEP2_OUT_Deal(uint8_t l);
/**
* @brief 端点3下传数据处理
*
* @param l - 待处理数据长度(<64B)
*/
void DevEP3_OUT_Deal(uint8_t l);
/**
* @brief 端点4下传数据处理
*
* @param l - 待处理数据长度(<64B)
*/
void DevEP4_OUT_Deal(uint8_t l);
/**
* @brief 端点1数据上传
*
* @param l - 上传数据长度(<64B)
*/
void DevEP1_IN_Deal(uint8_t l);
/**
* @brief 端点2数据上传
*
* @param l - 上传数据长度(<64B)
*/
void DevEP2_IN_Deal(uint8_t l);
/**
* @brief 端点3数据上传
*
* @param l - 上传数据长度(<64B)
*/
void DevEP3_IN_Deal(uint8_t l);
/**
* @brief 端点4数据上传
*
* @param l - 上传数据长度(<64B)
*/
void DevEP4_IN_Deal(uint8_t l);
/**
* @brief 查询端点1是否上传完成
*
* @return 0-未完成 (!0)-已完成
*/
#define EP1_GetINSta() (R8_UEP1_CTRL & UEP_T_RES_NAK)
/**
* @brief 查询端点2是否上传完成
*
* @return 0-未完成 (!0)-已完成
*/
#define EP2_GetINSta() (R8_UEP2_CTRL & UEP_T_RES_NAK)
/**
* @brief 查询端点3是否上传完成
*
* @return 0-未完成 (!0)-已完成
*/
#define EP3_GetINSta() (R8_UEP3_CTRL & UEP_T_RES_NAK)
/**
* @brief 查询端点4是否上传完成
*
* @return 0-未完成 (!0)-已完成
*/
#define EP4_GetINSta() (R8_UEP4_CTRL & UEP_T_RES_NAK)
/**
* @brief 关闭USB上拉电阻
*/
#define USB_DisablePin() (R16_PIN_ANALOG_IE &= ~(RB_PIN_USB_IE | RB_PIN_USB_DP_PU))
/**
* @brief 关闭USB
*/
#define USB_Disable() (R32_USB_CONTROL = 0)
#ifdef __cplusplus
}
#endif
#endif // __CH59x_USBDEV_H__