348 lines
12 KiB
C
Raw Normal View History

2022-03-26 20:51:40 +08:00
/********************************** (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<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ο<EFBFBD>USB_DEVICE_ADDR)
<EFBFBD><EFBFBD>ֵַ <EFBFBD>λ<EFBFBD><EFBFBD>
0x02 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Root-HUB<EFBFBD>µ<EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿHUB
0x1x <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Root-HUB<EFBFBD>µ<EFBFBD><EFBFBD>ⲿHUB<EFBFBD>Ķ˿<EFBFBD>x<EFBFBD>µ<EFBFBD>USB<EFBFBD>,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 <EFBFBD>ر<EFBFBD>ROOT-HUB<EFBFBD>˿<EFBFBD>,ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ر<EFBFBD>,<EFBFBD>˴<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<EFBFBD>״̬
*/
void DisableRootHubPort(void);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ROOT-HUB״̬,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ROOT-HUB<EFBFBD>˿ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>DisableRootHubPort()<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>˿ڹر<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>˿ڵ<EFBFBD>״̬λ
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_SUCCESSΪû<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_USB_CONNECTΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_USB_DISCONΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>
*/
uint8_t AnalyzeRootHub(void);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD>ַ
*
* @param addr - USB<EFBFBD><EFBFBD><EFBFBD>ַ
*/
void SetHostUsbAddr(uint8_t addr);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰUSB<EFBFBD>ٶ<EFBFBD>
*
* @param FullSpeed - USB<EFBFBD>ٶ<EFBFBD>
*/
void SetUsbSpeed(uint8_t FullSpeed);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,Ϊö<EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪĬ<EFBFBD><EFBFBD>Ϊȫ<EFBFBD><EFBFBD>
*/
void ResetRootHubPort(void);
/**
* @brief ʹ<EFBFBD><EFBFBD>ROOT-HUB<EFBFBD>˿<EFBFBD>,<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>bUH_PORT_EN<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>,<EFBFBD><EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_SUCCESSΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_USB_DISCONΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t EnableRootHubPort(void);
/**
* @brief <EFBFBD>ȴ<EFBFBD>USB<EFBFBD>ж<EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_SUCCESS <EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD>߷<EFBFBD><EFBFBD>ͳɹ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_USB_UNKNOWN <EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD>߷<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
uint8_t WaitUSB_Interrupt(void);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>Ķ˵<EFBFBD><EFBFBD><EFBFBD>ַ/PID<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־,<EFBFBD><EFBFBD>20u<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>NAK<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>(0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0xFFFF<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),<EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>,<EFBFBD><EFBFBD>ʱ/<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>,Ӧ<EFBFBD>öԱ<EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>
*
* @param endp_pid - <EFBFBD><EFBFBD><EFBFBD>ƺ͵<EFBFBD>ַ, <EFBFBD><EFBFBD>4λ<EFBFBD><EFBFBD>token_pid<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>4λ<EFBFBD>Ƕ˵<EFBFBD><EFBFBD><EFBFBD>ַ
* @param tog - ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
* @param timeout - <EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>
*
* @return ERR_USB_UNKNOWN <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD>
* ERR_USB_DISCON <EFBFBD><EFBFBD>Ͽ<EFBFBD>
* ERR_USB_CONNECT <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ERR_SUCCESS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t USBHostTransact(uint8_t endp_pid, uint8_t tog, uint32_t timeout);
/**
* @brief ִ<EFBFBD>п<EFBFBD><EFBFBD>ƴ<EFBFBD><EFBFBD><EFBFBD>,8<EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pSetupReq<EFBFBD><EFBFBD>,DataBufΪ<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param DataBuf - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>պͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ôDataBuf<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param RetLen - ʵ<EFBFBD>ʳɹ<EFBFBD><EFBFBD>շ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><EFBFBD>ȱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RetLenָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return ERR_USB_BUF_OVER IN״̬<EFBFBD>׶γ<EFBFBD><EFBFBD><EFBFBD>
* ERR_SUCCESS <EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
*/
uint8_t HostCtrlTransfer(uint8_t *DataBuf, uint8_t *RetLen);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD>ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pReqPkt - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
*/
void CopySetupReqPkg(const uint8_t *pReqPkt);
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> pHOST_TX_RAM_Addr <EFBFBD><EFBFBD>
*
* @return ERR_USB_BUF_OVER <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>
* ERR_SUCCESS <EFBFBD>ɹ<EFBFBD>
*/
uint8_t CtrlGetDeviceDescr(void);
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> pHOST_TX_RAM_Addr <EFBFBD><EFBFBD>
*
* @return ERR_USB_BUF_OVER <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>
* ERR_SUCCESS <EFBFBD>ɹ<EFBFBD>
*/
uint8_t CtrlGetConfigDescr(void);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD>ַ
*
* @param addr - <EFBFBD><EFBFBD><EFBFBD>ַ
*
* @return ERR_SUCCESS <EFBFBD>ɹ<EFBFBD>
*/
uint8_t CtrlSetUsbAddress(uint8_t addr);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param cfg - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
*
* @return ERR_SUCCESS <EFBFBD>ɹ<EFBFBD>
*/
uint8_t CtrlSetUsbConfig(uint8_t cfg);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>STALL
*
* @param endp - <EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>ַ
*
* @return ERR_SUCCESS <EFBFBD>ɹ<EFBFBD>
*/
uint8_t CtrlClearEndpStall(uint8_t endp);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD>ӿ<EFBFBD>
*
* @param cfg - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
*
* @return ERR_SUCCESS <EFBFBD>ɹ<EFBFBD>
*/
uint8_t CtrlSetUsbIntercace(uint8_t cfg);
/**
* @brief USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><EFBFBD>
*/
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 <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>ROOT-HUB<EFBFBD>˿ڵ<EFBFBD>USB<EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t InitRootDevice(void);
/**
* @brief <EFBFBD><EFBFBD>ȡHID<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TxBuffer<EFBFBD><EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t CtrlGetHIDDeviceReport(uint8_t infc);
/**
* @brief <EFBFBD><EFBFBD>ȡHUB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Com_Buffer<EFBFBD><EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t CtrlGetHubDescr(void);
/**
* @brief <EFBFBD><EFBFBD>ѯHUB<EFBFBD>˿<EFBFBD>״̬,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Com_Buffer<EFBFBD><EFBFBD>
*
* @param HubPortIndex - <EFBFBD>˿ں<EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t HubGetPortStatus(uint8_t HubPortIndex);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param HubPortIndex - <EFBFBD>˿ں<EFBFBD>
* @param FeatureSelt - <EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t HubSetPortFeature(uint8_t HubPortIndex, uint8_t FeatureSelt);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param HubPortIndex - <EFBFBD>˿ں<EFBFBD>
* @param FeatureSelt - <EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return <EFBFBD><EFBFBD><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__