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

348 lines
12 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 : CH57x_usbhost.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_USBHOST_H__
#define __CH58x_USBHOST_H__
#ifdef __cplusplus
extern "C" {
#endif
#if DISK_LIB_ENABLE
#if DISK_WITHOUT_USB_HUB
/***************************************** /* <20><>ʹ<EFBFBD><CAB9>U<EFBFBD><55><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>USBhub<75><62><EFBFBD><EFBFBD><E6A3AC>Ҫ<EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><E6B6A8> */
#define FOR_ROOT_UDISK_ONLY
#endif
/***************************************** /* ʹ<><CAB9>U<EFBFBD><55><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5><EFBFBD><E2A3AC>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B6A8>, <20><>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD> */
#define DISK_BASE_BUF_LEN 512 /* Ĭ<>ϵĴ<CFB5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СΪ512<31>ֽ<EFBFBD>,<2C><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>Ϊ2048<34><38><EFBFBD><EFBFBD>4096<39><36>֧<EFBFBD><D6A7>ijЩ<C4B3><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD><55>,Ϊ0<CEAA><30><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9>.H<>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD><E5BBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>pDISK_BASE_BUF<55><46>ָ<EFBFBD><D6B8> */
#endif
// <20><><EFBFBD>ӳ<EFBFBD><D3B3>򷵻<EFBFBD>״̬<D7B4><CCAC>
#define ERR_SUCCESS 0x00 // <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
#define ERR_USB_CONNECT 0x15 /* <20><><EFBFBD>⵽USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>,<2C>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD> */
#define ERR_USB_DISCON 0x16 /* <20><><EFBFBD>⵽USB<53><EFBFBD>Ͽ<EFBFBD><CFBF>¼<EFBFBD>,<2C>Ѿ<EFBFBD><D1BE>Ͽ<EFBFBD> */
#define ERR_USB_BUF_OVER 0x17 /* USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><EFBFBD><E0BBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define ERR_USB_DISK_ERR 0x1F /* USB<53><EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>,<2C>ڳ<EFBFBD>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<53><EFBFBD><E6B4A2><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>,<2C>ڶ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD>𻵻<EFBFBD><F0BBB5BB><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE>Ͽ<EFBFBD> */
#define ERR_USB_TRANSFER 0x20 /* NAK/STALL<4C>ȸ<EFBFBD><C8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x20~0x2F */
#define ERR_USB_UNSUPPORT 0xFB /* <20><>֧<EFBFBD>ֵ<EFBFBD>USB<53>豸*/
#define ERR_USB_UNKNOWN 0xFE /* <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define ERR_AOA_PROTOCOL 0x41 /* Э<><D0AD><EFBFBD><EFBFBD><E6B1BE><EFBFBD><EFBFBD> */
/*USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>,<2C><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>1<EFBFBD><31><EFBFBD>豸*/
#define ROOT_DEV_DISCONNECT 0
#define ROOT_DEV_CONNECTED 1
#define ROOT_DEV_FAILED 2
#define ROOT_DEV_SUCCESS 3
#define DEV_TYPE_KEYBOARD (USB_DEV_CLASS_HID | 0x20)
#define DEV_TYPE_MOUSE (USB_DEV_CLASS_HID | 0x30)
#define DEF_AOA_DEVICE 0xF0
#define DEV_TYPE_UNKNOW 0xFF
/*
Լ<EFBFBD><EFBFBD>: USB<53><EFBFBD><E8B1B8>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>ο<EFBFBD>USB_DEVICE_ADDR)
<EFBFBD><EFBFBD>ֵַ <20>豸λ<E8B1B8><CEBB>
0x02 <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD>ⲿHUB
0x1x <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD><C2B5>ⲿHUB<55>Ķ˿<C4B6>x<EFBFBD>µ<EFBFBD>USB<53>豸,xΪ1~n
*/
#define HUB_MAX_PORTS 4
#define WAIT_USB_TOUT_200US 800 // <20>ȴ<EFBFBD>USB<53>жϳ<D0B6>ʱʱ<CAB1><CAB1>
typedef struct
{
uint8_t DeviceStatus; // <20>豸״̬,0-<2D><><EFBFBD>豸,1-<2D><><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>δ<EFBFBD><CEB4>ʼ<EFBFBD><CABC>,2-<2D><><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ö<EFBFBD><C3B6>ʧ<EFBFBD><CAA7>,3-<2D><><EFBFBD><EFBFBD>ҳ<EFBFBD>ʼ<EFBFBD><CABC>ö<EFBFBD>ٳɹ<D9B3>
uint8_t DeviceAddress; // <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<53><42>ַ
uint8_t DeviceSpeed; // 0Ϊ<30><CEAA><EFBFBD><EFBFBD>,<2C><>0Ϊȫ<CEAA><C8AB>
uint8_t DeviceType; // <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
uint16_t DeviceVID;
uint16_t DevicePID;
uint8_t GpVar[4]; // ͨ<>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ˵<C5B6>
uint8_t GpHUBPortNum; // ͨ<>ñ<EFBFBD><C3B1><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB<55><42><EFBFBD><EFBFBD>ʾHUB<55>˿<EFBFBD><CBBF><EFBFBD>
} _RootHubDev;
typedef struct
{
UINT8 DeviceStatus; // <20>豸״̬,0-<2D><><EFBFBD>豸,1-<2D><><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>δ<EFBFBD><CEB4>ʼ<EFBFBD><CABC>,2-<2D><><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ö<EFBFBD><C3B6>ʧ<EFBFBD><CAA7>,3-<2D><><EFBFBD><EFBFBD>ҳ<EFBFBD>ʼ<EFBFBD><CABC>ö<EFBFBD>ٳɹ<D9B3>
UINT8 DeviceAddress; // <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<53><42>ַ
UINT8 DeviceSpeed; // 0Ϊ<30><CEAA><EFBFBD><EFBFBD>,<2C><>0Ϊȫ<CEAA><C8AB>
UINT8 DeviceType; // <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
UINT16 DeviceVID;
UINT16 DevicePID;
UINT8 GpVar[4]; // ͨ<>ñ<EFBFBD><C3B1><EFBFBD>
} _DevOnHubPort; // <20>ٶ<EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ⲿHUB,ÿ<><C3BF><EFBFBD>ⲿHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB_MAX_PORTS<54><53><EFBFBD>˿<EFBFBD>(<28><><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>)
extern _RootHubDev ThisUsbDev;
extern _DevOnHubPort DevOnHubPort[HUB_MAX_PORTS]; // <20>ٶ<EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ⲿHUB,ÿ<><C3BF><EFBFBD>ⲿHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB_MAX_PORTS<54><53><EFBFBD>˿<EFBFBD>(<28><><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>)
extern uint8_t UsbDevEndp0Size; // USB<53><EFBFBD>Ķ˵<C4B6>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD> */
extern uint8_t FoundNewDev;
extern uint8_t *pHOST_RX_RAM_Addr;
extern uint8_t *pHOST_TX_RAM_Addr;
extern _RootHubDev ThisUsb2Dev;
extern _DevOnHubPort DevOnU2HubPort[HUB_MAX_PORTS]; // <20>ٶ<EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ⲿHUB,ÿ<><C3BF><EFBFBD>ⲿHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB_MAX_PORTS<54><53><EFBFBD>˿<EFBFBD>(<28><><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>)
extern uint8_t Usb2DevEndp0Size; // USB<53><EFBFBD>Ķ˵<C4B6>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD> */
extern uint8_t FoundNewU2Dev;
extern uint8_t *pU2HOST_RX_RAM_Addr;
extern uint8_t *pU2HOST_TX_RAM_Addr;
#define pSetupReq ((PUSB_SETUP_REQ)pHOST_TX_RAM_Addr)
#define pU2SetupReq ((PUSB_SETUP_REQ)pU2HOST_TX_RAM_Addr)
extern uint8_t Com_Buffer[];
extern uint8_t U2Com_Buffer[];
/* <20><><EFBFBD><EFBFBD>ΪUSB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
extern const uint8_t SetupGetDevDescr[]; // <20><>ȡ<EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
extern const uint8_t SetupGetCfgDescr[]; // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
extern const uint8_t SetupSetUsbAddr[]; // <20><><EFBFBD><EFBFBD>USB<53><42>ַ*/
extern const uint8_t SetupSetUsbConfig[]; // <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD>*/
extern const uint8_t SetupSetUsbInterface[]; // <20><><EFBFBD><EFBFBD>USB<53>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>*/
extern const uint8_t SetupClrEndpStall[]; // <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>STALL*/
extern const uint8_t SetupGetU2DevDescr[]; // <20><>ȡ<EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
extern const uint8_t SetupGetU2CfgDescr[]; // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
extern const uint8_t SetupSetUsb2Addr[]; // <20><><EFBFBD><EFBFBD>USB<53><42>ַ*/
extern const uint8_t SetupSetUsb2Config[]; // <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD>*/
extern const uint8_t SetupSetUsb2Interface[]; // <20><><EFBFBD><EFBFBD>USB<53>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>*/
extern const uint8_t SetupClrU2EndpStall[]; // <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>STALL*/
/**
* @brief <20>ر<EFBFBD>ROOT-HUB<55>˿<EFBFBD><><CAB5><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>Ѿ<EFBFBD><D1BE>Զ<EFBFBD><D4B6>ر<EFBFBD>,<2C>˴<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB>ṹ״̬
*/
void DisableRootHubPort(void);
/**
* @brief <20><><EFBFBD><EFBFBD>ROOT-HUB״̬,<2C><><EFBFBD><EFBFBD>ROOT-HUB<55>˿ڵ<CBBF><DAB5><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>DisableRootHubPort()<29><><EFBFBD><EFBFBD>,<2C><><EFBFBD>˿ڹر<DAB9>,<2C><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>,<2C><><EFBFBD><EFBFBD>Ӧ<EFBFBD>˿ڵ<CBBF>״̬λ
*
* @return <20><><EFBFBD><EFBFBD>ERR_SUCCESSΪû<CEAA><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ERR_USB_CONNECTΪ<54><CEAA><EFBFBD><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ERR_USB_DISCONΪ<4E><CEAA><EFBFBD><EFBFBD>Ͽ<EFBFBD>
*/
uint8_t AnalyzeRootHub(void);
/**
* @brief <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8>ַ
*
* @param addr - USB<53><EFBFBD><E8B1B8>ַ
*/
void SetHostUsbAddr(uint8_t addr);
/**
* @brief <20><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD>
*
* @param FullSpeed - USB<53>ٶ<EFBFBD>
*/
void SetUsbSpeed(uint8_t FullSpeed);
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><E8B1B8>,<2C><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>,Ϊö<CEAA><C3B6><EFBFBD>豸׼<E8B1B8><D7BC>,<2C><><EFBFBD><EFBFBD>ΪĬ<CEAA><C4AC>Ϊȫ<CEAA><C8AB>
*/
void ResetRootHubPort(void);
/**
* @brief ʹ<><CAB9>ROOT-HUB<55>˿<EFBFBD>,<2C><>Ӧ<EFBFBD><D3A6>bUH_PORT_EN<45><4E>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>,<2C><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>·<EFBFBD><C2B7><EFBFBD>ʧ<EFBFBD><CAA7>
*
* @return <20><><EFBFBD><EFBFBD>ERR_SUCCESSΪ<53><CEAA><EFBFBD><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ERR_USB_DISCONΪ<4E><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t EnableRootHubPort(void);
/**
* @brief <20>ȴ<EFBFBD>USB<53>ж<EFBFBD>
*
* @return <20><><EFBFBD><EFBFBD>ERR_SUCCESS <20><><EFBFBD>ݽ<EFBFBD><DDBD>ջ<EFBFBD><D5BB>߷<EFBFBD><DFB7>ͳɹ<CDB3>,<2C><><EFBFBD><EFBFBD>ERR_USB_UNKNOWN <20><><EFBFBD>ݽ<EFBFBD><DDBD>ջ<EFBFBD><D5BB>߷<EFBFBD><DFB7><EFBFBD>ʧ<EFBFBD><CAA7>
*/
uint8_t WaitUSB_Interrupt(void);
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ŀ<EFBFBD>Ķ˵<C4B6><CBB5><EFBFBD>ַ/PID<49><44><EFBFBD><EFBFBD><><CDAC><EFBFBD><EFBFBD>־,<2C><>20uSΪ<53><CEAA>λ<EFBFBD><CEBB>NAK<41><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>(0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0xFFFF<46><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),<2C><><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>,<2C><>ʱ/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><><CEAA><EFBFBD><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><>öԱ<C3B6><D4B1>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>
*
* @param endp_pid - <20><><EFBFBD>ƺ͵<C6BA>ַ, <20><><34><CEBB>token_pid<69><64><EFBFBD><EFBFBD>, <20><><34>Ƕ˵<C7B6><CBB5><EFBFBD>ַ
* @param tog - ͬ<><CDAC><EFBFBD><EFBFBD>־
* @param timeout - <20><>ʱʱ<CAB1><CAB1>
*
* @return ERR_USB_UNKNOWN <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>
* ERR_USB_DISCON <20><EFBFBD>Ͽ<EFBFBD>
* ERR_USB_CONNECT <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
* ERR_SUCCESS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t USBHostTransact(uint8_t endp_pid, uint8_t tog, uint32_t timeout);
/**
* @brief ִ<>п<EFBFBD><D0BF>ƴ<EFBFBD><C6B4><EFBFBD>,8<>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pSetupReq<65><71>,DataBufΪ<66><CEAA>ѡ<EFBFBD><D1A1><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param DataBuf - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>պͷ<D5BA><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ôDataBuf<75><66>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param RetLen - ʵ<>ʳɹ<CAB3><C9B9>շ<EFBFBD><D5B7><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD>RetLenָ<6E><D6B8><EFBFBD><EFBFBD><EFBFBD>ֽڱ<D6BD><DAB1><EFBFBD><EFBFBD><EFBFBD>
*
* @return ERR_USB_BUF_OVER IN״̬<D7B4>׶γ<D7B6><CEB3><EFBFBD>
* ERR_SUCCESS <20><><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
*/
uint8_t HostCtrlTransfer(uint8_t *DataBuf, uint8_t *RetLen);
/**
* @brief <20><><EFBFBD>ƿ<EFBFBD><C6BF>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pReqPkt - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
*/
void CopySetupReqPkg(const uint8_t *pReqPkt);
/**
* @brief <20><>ȡ<EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> pHOST_TX_RAM_Addr <20><>
*
* @return ERR_USB_BUF_OVER <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>
* ERR_SUCCESS <20>ɹ<EFBFBD>
*/
uint8_t CtrlGetDeviceDescr(void);
/**
* @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> pHOST_TX_RAM_Addr <20><>
*
* @return ERR_USB_BUF_OVER <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>
* ERR_SUCCESS <20>ɹ<EFBFBD>
*/
uint8_t CtrlGetConfigDescr(void);
/**
* @brief <20><><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8>ַ
*
* @param addr - <20><EFBFBD><E8B1B8>ַ
*
* @return ERR_SUCCESS <20>ɹ<EFBFBD>
*/
uint8_t CtrlSetUsbAddress(uint8_t addr);
/**
* @brief <20><><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
*
* @param cfg - <20><><EFBFBD><EFBFBD>ֵ
*
* @return ERR_SUCCESS <20>ɹ<EFBFBD>
*/
uint8_t CtrlSetUsbConfig(uint8_t cfg);
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>STALL
*
* @param endp - <20>˵<EFBFBD><CBB5><EFBFBD>ַ
*
* @return ERR_SUCCESS <20>ɹ<EFBFBD>
*/
uint8_t CtrlClearEndpStall(uint8_t endp);
/**
* @brief <20><><EFBFBD><EFBFBD>USB<53><EFBFBD>ӿ<EFBFBD>
*
* @param cfg - <20><><EFBFBD><EFBFBD>ֵ
*
* @return ERR_SUCCESS <20>ɹ<EFBFBD>
*/
uint8_t CtrlSetUsbIntercace(uint8_t cfg);
/**
* @brief USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC>
*/
void USB_HostInit(void);
uint8_t EnumAllHubPort(void);// ö<><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD>ⲿHUB<55><42><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>USB<53>
void SelectHubPort(uint8_t HubPortIndex); // HubPortIndex=0ѡ<30><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿ڵ<CBBF><DAB5>ⲿHUB<55><42>ָ<EFBFBD><D6B8><EFBFBD>˿<EFBFBD>
uint16_t SearchTypeDevice(uint8_t type); // <20><>ROOT-HUB<55>Լ<EFBFBD><D4BC>ⲿHUB<55><42><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><E8B1B8><EFBFBD>ڵĶ˿ں<CBBF>,<2C><><EFBFBD><EFBFBD><EFBFBD>˿ں<CBBF>Ϊ0xFFFF<46><46>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
uint8_t SETorOFFNumLock(uint8_t *buf); // NumLock<63>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ж<EFBFBD>
void DisableRootU2HubPort(void); // <20>ر<EFBFBD>ROOT-U2HUB<55>˿<EFBFBD><><CAB5><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>Ѿ<EFBFBD><D1BE>Զ<EFBFBD><D4B6>ر<EFBFBD>,<2C>˴<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB>ṹ״̬
uint8_t AnalyzeRootU2Hub(void); // <20><><EFBFBD><EFBFBD>ROOT-U2HUB״̬,<2C><><EFBFBD><EFBFBD>ROOT-U2HUB<55>˿ڵ<CBBF><DAB5><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
// <20><><EFBFBD><EFBFBD>ERR_SUCCESSΪû<CEAA><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ERR_USB_CONNECTΪ<54><CEAA><EFBFBD><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ERR_USB_DISCONΪ<4E><CEAA><EFBFBD><EFBFBD>Ͽ<EFBFBD>
void SetHostUsb2Addr(uint8_t addr); // <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8>ַ
void SetUsb2Speed(uint8_t FullSpeed); // <20><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD>
void ResetRootU2HubPort(void); // <20><><EFBFBD><EFBFBD><EFBFBD><E8B1B8>,<2C><>λ<EFBFBD><CEBB>Ӧ<EFBFBD>˿ڵ<CBBF><DAB5><EFBFBD><EFBFBD><EFBFBD>,Ϊö<CEAA><C3B6><EFBFBD>豸׼<E8B1B8><D7BC>,<2C><><EFBFBD><EFBFBD>ΪĬ<CEAA><C4AC>Ϊȫ<CEAA><C8AB>
uint8_t EnableRootU2HubPort(void); // ʹ<><CAB9>ROOT-HUB<55>˿<EFBFBD>,<2C><>Ӧ<EFBFBD><D3A6>bUH_PORT_EN<45><4E>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>,<2C><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>·<EFBFBD><C2B7><EFBFBD>ʧ<EFBFBD><CAA7>
void SelectU2HubPort(uint8_t HubPortIndex); // HubPortIndex=0ѡ<30><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿ڵ<CBBF><DAB5>ⲿHUB<55><42>ָ<EFBFBD><D6B8><EFBFBD>˿<EFBFBD>
uint8_t WaitUSB2_Interrupt(void); // <20>ȴ<EFBFBD>USB<53>ж<EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ŀ<EFBFBD>Ķ˵<C4B6><CBB5><EFBFBD>ַ/PID<49><44><EFBFBD><EFBFBD><><CDAC><EFBFBD><EFBFBD>־,<2C><>20uSΪ<53><CEAA>λ<EFBFBD><CEBB>NAK<41><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>(0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0xFFFF<46><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),<2C><><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>,<2C><>ʱ/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t USB2HostTransact(uint8_t endp_pid, uint8_t tog, UINT32 timeout); // endp_pid: <20><><34><CEBB>token_pid<69><64><EFBFBD><EFBFBD>, <20><><34>Ƕ˵<C7B6><CBB5><EFBFBD>ַ
uint8_t U2HostCtrlTransfer(uint8_t *DataBuf, uint8_t *RetLen); // ִ<>п<EFBFBD><D0BF>ƴ<EFBFBD><C6B4><EFBFBD>,8<>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pSetupReq<65><71>,DataBufΪ<66><CEAA>ѡ<EFBFBD><D1A1><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>պͷ<D5BA><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ôDataBuf<75><66>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><>ʳɹ<CAB3><C9B9>շ<EFBFBD><D5B7><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3>ȷ<EFBFBD><C8B7>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>ReqLenָ<6E><D6B8><EFBFBD><EFBFBD><EFBFBD>ֽڱ<D6BD><DAB1><EFBFBD><EFBFBD><EFBFBD>
void CopyU2SetupReqPkg(const uint8_t *pReqPkt); // <20><><EFBFBD>ƿ<EFBFBD><C6BF>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t CtrlGetU2DeviceDescr(void); // <20><>ȡ<EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> pHOST_TX_RAM_Addr <20><>
uint8_t CtrlGetU2ConfigDescr(void); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> pHOST_TX_RAM_Addr <20><>
uint8_t CtrlSetUsb2Address(uint8_t addr); // <20><><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8>ַ
uint8_t CtrlSetUsb2Config(uint8_t cfg); // <20><><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
uint8_t CtrlClearU2EndpStall(uint8_t endp); // <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>STALL
uint8_t CtrlSetUsb2Intercace(uint8_t cfg); // <20><><EFBFBD><EFBFBD>USB<53><EFBFBD>ӿ<EFBFBD>
void USB2_HostInit(void); // <20><>ʼ<EFBFBD><CABC>USB<53><42><EFBFBD><EFBFBD>
/*************************************************************/
/**
* @brief <20><>ʼ<EFBFBD><CABC>ָ<EFBFBD><D6B8>ROOT-HUB<55>˿ڵ<CBBF>USB<53>
*
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t InitRootDevice(void);
/**
* @brief <20><>ȡHID<49><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TxBuffer<65><72>
*
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t CtrlGetHIDDeviceReport(uint8_t infc);
/**
* @brief <20><>ȡHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Com_Buffer<65><72>
*
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t CtrlGetHubDescr(void);
/**
* @brief <20><>ѯHUB<55>˿<EFBFBD>״̬,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Com_Buffer<65><72>
*
* @param HubPortIndex - <20>˿ں<CBBF>
*
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t HubGetPortStatus(uint8_t HubPortIndex);
/**
* @brief <20><><EFBFBD><EFBFBD>HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
*
* @param HubPortIndex - <20>˿ں<CBBF>
* @param FeatureSelt - <20>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
*
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t HubSetPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt);
/**
* @brief <20><><EFBFBD><EFBFBD>HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
*
* @param HubPortIndex - <20>˿ں<CBBF>
* @param FeatureSelt - <20>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
*
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t HubClearPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt);
uint8_t InitRootU2Device(void);
uint8_t EnumAllU2HubPort(void);
uint16_t U2SearchTypeDevice(uint8_t type);
uint8_t U2SETorOFFNumLock(uint8_t *buf);
uint8_t CtrlGetU2HIDDeviceReport(uint8_t infc); // HID<49><44><EFBFBD><EFBFBD><EFBFBD>SET_IDLE<4C><45>GET_REPORT
uint8_t CtrlGetU2HubDescr(void); // <20><>ȡHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TxBuffer<65><72>
uint8_t U2HubGetPortStatus(uint8_t HubPortIndex); // <20><>ѯHUB<55>˿<EFBFBD>״̬,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TxBuffer<65><72>
uint8_t U2HubSetPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt); // <20><><EFBFBD><EFBFBD>HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
uint8_t U2HubClearPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt); // <20><><EFBFBD><EFBFBD>HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
#ifdef __cplusplus
}
#endif
#endif // __CH58x_USBHOST_H__