📄 usb.h
字号:
/***********************************************
standard command structure
************************************************/
/* usb standard command structure */
typedef struct
{
kal_uint8 bmRequestType;
kal_uint8 bRequest;
kal_uint16 wValue;
kal_uint16 wIndex;
kal_uint16 wLength;
} Usb_Command;
/***********************************************
standard descriptor structure
************************************************/
/* standard device descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint16 bcdUSB;
kal_uint8 bDeviceClass;
kal_uint8 bDeviceSubClass;
kal_uint8 bDeviceProtocol;
kal_uint8 bMaxPacketSize0;
kal_uint16 idVendor;
kal_uint16 idProduct;
kal_uint16 bcdDevice;
kal_uint8 iManufacturer;
kal_uint8 iProduct;
kal_uint8 iSerialNumber;
kal_uint8 bNumConfigurations;
} Usb_Dev_Dscr;
/* standard configuration descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint16 wTotalLength;
kal_uint8 bNumInterfaces;
kal_uint8 bConfigurationValue;
kal_uint8 iConfiguration;
kal_uint8 bmAttributes;
kal_uint8 bMaxPower;
} Usb_Cfg_Dscr;
/* standard IAD descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint8 bFirstInterface;
kal_uint8 bInterfaceCount;
kal_uint8 bFunctionClass;
kal_uint8 bFunctionSubClass;
kal_uint8 bFunctionProtocol;
kal_uint8 iFunction;
} Usb_IAD_Dscr;
/* standard interface descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint8 bInterfaceNumber;
kal_uint8 bAlternateSetting;
kal_uint8 bNumEndpoints;
kal_uint8 bInterfaceClass;
kal_uint8 bInterfaceSubClass;
kal_uint8 bInterfaceProtocol;
kal_uint8 iInterface;
} Usb_If_Dscr;
/* standard endpoint descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint8 bEndpointAddress;
kal_uint8 bmAttributes;
kal_uint8 wMaxPacketSize[2];
kal_uint8 bInterval;
} Usb_Ep_Dscr;
/* standard string descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint16 wData[1];
}Usb_String_Dscr;
/* standard string descriptor */
typedef struct
{
kal_uint8 bLength;
kal_uint8 bDescriptorType;
kal_uint8 bAttribute;
}Usb_Otg_Dscr;
/***********************************************
implement enum and structure
************************************************/
/* device states */
typedef enum
{
DEVSTATE_DEFAULT = 0,
DEVSTATE_SET_ADDRESS,
DEVSTATE_ADDRESS,
DEVSTATE_CONFIG
} USB_DEVICE_STATE;
/* Endpoint 0 state */
typedef enum
{
USB_EP0_IDLE=0,
USB_EP0_RX,
USB_EP0_TX,
USB_EP0_RX_STATUS
} USB_EP0_STATE;
/* EP0 status */
typedef struct
{
kal_uint8 byFAddr; /* new function address */
kal_int32 nBytesLeft; /* number of bytes left to send in TX mode */
void *pData; /* pointer to data to transmit/receive */
kal_int32 nBytesRecv; /* number of bytes received in RX mode */
} Usb_Ep0_Status;
/* Bulk IN endpoint status */
typedef struct
{
kal_uint8 byEP; /* endpoint number */
void *pData; /* pointer to data buffer */
kal_int32 nBytesLeft; /* number of bytes left to send */
} Usb_EpBIn_Status;
/* Bulk OUT endpoint status */
typedef struct
{
kal_uint8 byEP; /* endpoint number */
void *pData; /* pointer to data buffer */
kal_int32 nBuffLen; /* length of data buffer */
kal_int32 nBytesRecv; /* number of bytes received */
} Usb_EpBOut_Status;
/* interface create function pointer */
typedef void (*usb_create_if_func_ptr)(void *);
/* EP0 rx interrupt handler */
typedef void (*usb_ep0_rx_ptr)(void *);
/* class specific command interrupt handler */
typedef void (*usb_class_specific_handler_ptr)(Usb_Ep0_Status *, Usb_Command*);
/* endpoint interrupt handler */
typedef void (*usb_ep_handler_ptr)(void);
/* EP0 command interrupt handler */
typedef void (*usb_ep0_cmd_ptr)(Usb_Command *pcmd);
/* endpoint information, including endpoint status */
typedef struct
{
union
{
Usb_Ep_Dscr stdep; /* ep descriptor */
kal_uint8 classep[USB_MAX_CLASS_EPDESC_LENGTH];
}epdesc;
kal_uint16 epdscr_size; /* descriptor length */
usb_ep_handler_ptr ep_reset; /* ep reset handler */
union
{
Usb_EpBIn_Status epin_status;
Usb_EpBOut_Status epout_status;
}ep_status; /* ep status */
} Usb_Ep_Info;
/* interface information, including endpoint information and interface information*/
//extern struct Usb_Cdc_If_Dscr;
typedef struct
{
kal_char *interface_name_ptr; /* interface name */
usb_class_specific_handler_ptr if_class_specific_hdlr; /* interface specific handler, handle ep0 class specific request */
kal_uint16 ifdscr_size; /* descriptor length */
union
{
Usb_If_Dscr stdif;
kal_uint8 classif[USB_MAX_IFDSC_LENGTH];
}ifdscr;
Usb_Ep_Info *ep_info[USB_MAX_EP_PER_IF];/* endpoint attach to the interface info */
} Usb_Interface_Info;
/* configuration information */
typedef struct
{
kal_char *cfg_name_ptr; /* config name */
Usb_Cfg_Dscr stdcfg; /* config descriptor */
}Usb_Config_Info;
typedef struct
{
kal_bool b_enable;
kal_uint8 cmd;
usb_ep0_cmd_ptr ep0_cmd_hdlr;
}Usb_EPo_Cmd_Hdler;
/* device information, used for usb level */
typedef struct
{
Usb_Dev_Dscr devdscr;
/* Usb_Config_Info cfg_info[USB_MAX_CONFIG]; */
/* the configuration only one for saving memory */
Usb_Config_Info cfg_info;
Usb_Interface_Info if_info[USB_MAX_INTERFACE];
Usb_Ep_Info ep_bulkin_info[USB_MAX_EP_BULK_IN];
Usb_Ep_Info ep_bulkout_info[USB_MAX_EP_BULK_OUT];
Usb_Ep_Info ep_intr_info[USB_MAX_EP_INTR];
Usb_String_Dscr *resource_string[USB_MAX_STRING];
Usb_IAD_Dscr iad_desc[USB_MAX_IAD];
#ifdef __OTG_ENABLE__
Usb_Otg_Dscr otgdscr;
#endif
kal_uint8 *conf; /*just for descriptor transfer*/
Usb_Command cmd; /*USB_COMMAND*/
USB_DEVICE_TYPE device_type;
USB_DEVICE_STATE nDevState; /*DEVSTATE_CONFIG,DEVSTATE_ADDRESS,DEVSTATE_DEFAULT*/
kal_bool remoteWk;
kal_bool self_powered;
kal_bool usb_comport_boot; /* a flag to check if usb boot as com port */
kal_bool is_configured_now; /* a flag to check that after reset and before set configuration, the all DMA call back messages will be ignored */
kal_uint8 config_num;
kal_uint8 interface_num;
USB_EP0_STATE ep0_state;
Usb_Ep0_Status ep0info;
usb_ep0_rx_ptr ep0_rx_handler;
Usb_EPo_Cmd_Hdler ep0_class_cmd_handler; /* class specific ep0 cmd */
kal_bool usb_config_result; /* configure may be fail */
/* used for resource management*/
kal_uint8 resource_ep_bulkin_number;
kal_uint8 resource_ep_bulkout_number;
kal_uint8 resource_ep_intr_number;
kal_uint8 resource_interface_number;
kal_uint8 resource_string_number;
kal_uint8 resource_iad_number;
#ifdef __USB_MULTI_CHARGE_CURRENT__
#if ( defined(MT6305) || defined(MT6318) )
/* add for multi-configurations*/
kal_uint8 multi_configuration_value[USB_MAX_CONFIG];
kal_uint8 multi_Max_Power[USB_MAX_CONFIG];
#endif
#endif
/* serial string unique for each phone*/
kal_uint16 serial_string[USB_SERIAL_STRING_LEN];
/* customizable variables*/
const USB_DEVICE_PARAM *device_param;
} Usb_Device;
/***********************************************
function and global variable
************************************************/
extern Usb_Device gUsbDevice;
extern void USB_Init_Device_Status(void);
extern void USB_Release_Device_Status(void);
extern void USB_Register_EP0_RxHdlr(usb_ep0_rx_ptr handler);
extern void USB_Register_EP0_Class_CmdHdlr(kal_uint8 cmd, usb_ep0_cmd_ptr handler);
extern void USB_Init(USB_DEVICE_TYPE type, kal_bool b_enable);
extern void USB_Release(void);
extern void USB_Generate_EP0Data(Usb_Ep0_Status*pep0state, Usb_Command*pcmd, void *data, kal_int32 len);
#ifdef __USB_MULTI_CHARGE_CURRENT__
#if ( defined(MT6305) || defined(MT6318) )
extern const kal_uint16 USB_CHARGE_CURRENT[];
extern const kal_uint8 USB_GetChargeCurrentTableSize(void);
#endif
#endif
#endif /* USB_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -