⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch375host.h

📁 USB 1.1 U Device for CH375 & USB 2.0 for CH375A 读写usb超精简的程序
💻 H
字号:
//=================================================================================================
//*************************************************************************************************
// Module Name  : CH375Host.H 
// Device object: 
// Create date  : 2005-11-07 
// Modify date  : 2005-11-16 
// Description  : USB 1.1 Host for CH375 
//                如果设备端不是CH37X,那么分析描述符 CH375中断为查询方式 
// Author       : Li yuanzheng 
// Version      : V1.0 
//*************************************************************************************************
//=================================================================================================
// 

#ifndef __CH375Host_H__
#define __CH375Host_H__

#include "CH375H.H"

//*************************************************************************************************
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 以下的参数需要设定:
#define DELAY_START_value    1            // 根据单片机的时钟选择延时初值 
#define UNKNOWN_USB_DEVICE   0xF1
#define USB_INT_RET_NAK      0x2A         // 00101010B,返回NAK 


//-------------------------------------------------------------------------------------------------
// 并口电路连接方式 : 

//-------------------------------------------------------------------------------------------------
//|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
//|  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  | 10  | 11  | 12  | 13  | 14  | 15  | 16  |
//|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
//|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
//| D0  | D1  | D2  | D3  | D4  | D5  | D6  | D7  | INT | A0  | RD# | WR# | STA | CS  | VCC | GND |
//|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
//-------------------------------------------------------------------------------------------------
//|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
//|                   D0 -- D7                    | P32 | P37 | RD  | WR  | P27 |0xCxx| +5V | GND |
//|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
//-------------------------------------------------------------------------------------------------


//=================================================================================================
// The Standard Descriptors 
//=================================================================================================
// 
//-------------------------------------------------------------------------------------------------
// Device Descriptor Definition 
typedef struct _USB_DEVICE_DESCRIPTOR 
{
	unsigned char  bLength;               // Size of this descriptor in bytes.
	unsigned char  bDescriptorType;       // DEVICE Descriptor Type = 01H.
	unsigned short bcdUSB;                // USB Specification Release Number in Binary-Coded Decimal (i.e. 2.00 is 0x0200).
	unsigned char  bDeviceClass;          // Class code (assigned by USB).
	unsigned char  bDeviceSubClass;       // Subclass code(assigned by USB) if the field does not have a value of FFH.
	unsigned char  bDeviceProtocol;       // Protocol code (assigned by USB).
	unsigned char  bMaxPacketSize0;       // Maximun packet size for endpoint zero.(Only 8,16,32,and 64 are valid)
	unsigned short idVendor;              // Vendor ID (assigned by USB).
	unsigned short idProduct;             // Product ID (assigned by manufacturer).
	unsigned short bcdDevice;             // Device release number in binary-coded decimal.
	unsigned char  iManufacturer;         // Index of string descriptor describing manufacturer.
	unsigned char  iProduct;              // Index of product string descriptor.
	unsigned char  iSerialNumber;         // Index of string descriptor describing the device's serial number.
	unsigned char  bNumConfigurations;    // Number of possible configurations.
} USB_DEV_DESCR, *PUSB_DEV_DESCR;

//-------------------------------------------------------------------------------------------------
// Configuration Descriptors Definition 
typedef struct _USB_CONFIG_DESCRIPTOR 
{
	unsigned char  bLength;               // Size of this descriptor in bytes.
	unsigned char  bDescriptorType;       // Configuration Descriptor Type = 02H.
	unsigned short wTotalLength;          // Total length of data returned for this configuration.Includes the 
	                                      // combined length of all descriptors(configuration,interface,endpoint,
									      // and class or vendor specific)returned for this configuration.
	unsigned char  bNumInterfaces;        // Number of interfaces supported by this configuration.
	unsigned char  bConfigurationvalue;   // Value to use as an argument to Set Configuration to select this configuration.
	unsigned char  iConfiguration;        // Index of string descriptor descrtbing this configuration.
	unsigned char  bmAttributes;          // Configuration characteristics.
	unsigned char  MaxPower;              // Maximum power consumption of USB device from the bus in this specific 
	                                      // configuration when the device is fully operational.Expressed in 2 ma units.
} USB_CFG_DESCR, *PUSB_CFG_DESCR;

//-------------------------------------------------------------------------------------------------
// Interface Descriptors Definition 
typedef struct _USB_INTERF_DESCRIPTOR 
{
	unsigned char bLength;                // Size of this descriptor in bytes.
	unsigned char bDescriptorType;        // Interface Descriptor Type = 04H.
	unsigned char bInterfaceNumber;       // Number of interface.
	unsigned char bAlternateSetting;      // Value used to select alternate setting for the interface identified in the prior field.
	unsigned char bNumEndpoints;          // Number of endpoints used by this interface (excluding endpoint zero).
	unsigned char bInterfaceClass;        // Class code (assigned by USB).
	unsigned char bInterfaceSubClass;     // Subclass code (assigned by USB).
	unsigned char bInterfaceProtocol;     // Protocol code (assigned by USB).
	unsigned char iInterface;             // Index of string decriptor.
} USB_ITF_DESCR, *PUSB_ITF_DESCR;

//-------------------------------------------------------------------------------------------------
// Endpoint Descriptors Definition 
typedef struct _USB_ENDPOINT_DESCRIPTOR 
{
	unsigned char  bLength;               // Size of this descriptor in bytes.
	unsigned char  bDescriptorType;       // Endpoint descriptor type = 05H.
	unsigned char  bEndpointAddress;      // The address of the endpoint on the USB device described by this descriptor.
	unsigned char  bmAttributes;          // This field describes the endpoint's attributes when it is configured 
	                                      // using the Configuration Value.
	unsigned short wMaxPacketSize;        // Maximum packet size this endpoint is capable of sending or receving
	                                      // when this configuration is selected.
	unsigned char  bInterval;             // Interval for polling endpoint for data transfer.
} USB_ENDP_DESCR, *PUSB_ENDP_DESCR; 

//-------------------------------------------------------------------------------------------------
// Device_Qualifier Descriptor 
typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR 
{
	unsigned char  bLength;               // Size of this descriptor in bytes.
	unsigned char  bDescriptorType;       // DEVICE_QUALIFIER descriptor type = 06H.
	unsigned short bcdUSB;                // USB specification version 2.00.
	unsigned char  bDeviceClass;          // Class code (assigned by USB).
	unsigned char  bDeviceSubClass;       // Subclass code(assigned by USB). 
	unsigned char  bDeviceProtocol;       // Protocol code (assigned by USB).
	unsigned char  bMaxPacketSize0;       // Maximun packet size for endpoint zero when operating at other speed.
	unsigned char  bNumConfigurations;    // Number of other-speed configurations.
	unsigned char  reserved;              // Reserved for future use(must = 0).
} USB_DEVQUA_DESCR, *PUSB_DEVQUA_DESCR; 

//-------------------------------------------------------------------------------------------------
// Other Speed Configuration Descriptor 
typedef struct _USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR 
{
	unsigned char  bLength;               // Size of this descriptor in bytes.
	unsigned char  bDescriptorType;       // OTHER SPEED CONFIGURATION descriptor type = 07H.
	unsigned short wTotalLength;          // Total length of data returned.
	unsigned char  bNumberInterfaces;     // Number of interfaces supported by this speed configuration.
	unsigned char  bConfigurationValue;   // Value used to select configuration.
	unsigned char  iConfiguration;        // Index of string descriptor.
	unsigned char  bmAttributes;          // Same as configuration descriptor.
	unsigned char  MaxPower;              // Same as configuration descriptor.
} USB_OTHSPDCON_DESCR,*PUSB_OTHSPDCON_DESCR;

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// The marshal of configuration descriptor 
typedef struct _USB_CONFIG_DESCRIPTOR_LONG 
{
	USB_CFG_DESCR  cfg_descr;             // Configuration Descriptors 
	USB_ITF_DESCR  itf_descr;             // Interface Descriptors 
	USB_ENDP_DESCR endp_descr[4];         // Endpoint Descriptors ( 4 Endpoints )
} USB_CFG_DESCR_LONG, *PUSB_CFG_DESCR_LONG;

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//*************************************************************************************************
// 外部命令码 

//=================================================================================================
//=================================================================================================
// 
extern void CH375_SetUSBMode( unsigned char mode );  // 设置CH37X的工作模式 

extern void CH375_ToggleReceive( void );      // 主机接收成功后,切换DATA0和DATA1实现数据同步 
extern void CH375_ToggleSend( void );         // 主机发送成功后,切换DATA0和DATA1实现数据同步 

extern unsigned char CH375_ClrStall6( void ); // 主机接收失败后,复位设备端的数据同步到DATA0 
extern unsigned char CH375_ClrStall7( void ); // 主机发送失败后,复位设备端的数据同步到DATA0 

extern unsigned char CH375_ReadUSBData( unsigned char *buffer );                // 从CH37X读出数据块 
extern void CH375_WriteUSBData( unsigned char length, unsigned char *buffer );  // 向CH37X写入数据块 

extern unsigned char CH375_IssueToken( unsigned char EndpAndPID );         // 执行USB事务 
extern void CH375_HostSend( unsigned char length, unsigned char *buffer ); // 主机发送 
extern unsigned char CH375_HostReceive( unsigned char *buffer );           // 主机接收, 返回长度 

extern unsigned char CH375_GetDescription( unsigned char type ); // 从设备端获取描述符 
extern unsigned char CH375_SetAddress( unsigned char address );  // 设置设备端的USB地址 
extern unsigned char CH375_SetConfiguration( unsigned char configuration ); // 设置设备端的USB配置 

extern void CH375_Init( void );                   // CH375初始化子程序 
extern unsigned char CH375_InitUSBDevice( void ); // 初始化USB设备,完成设备枚举 

//-------------------------------------------------------------------------------------------------
extern void CH375HostProcess( void );

//=================================================================================================
// Main.C 
extern void mDelayuS( unsigned int usecond );   // 1 us delay 
extern void mDelaymS( unsigned int msecond );   // 1 ms delay 

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -