?? usb_inc.h
字號:
#include <stdio.h>
#include <string.h>
#include <At89x52.h>
//*************************************************************************
// basic #defines
//*************************************************************************
#define MAX_ENDPOINTS (unsigned char)0x3
#define EP0_PACKET_SIZE 16
#define EP1_PACKET_SIZE 4
#define EP2_PACKET_SIZE 64
#define USB_IDLE 0
#define USB_TRANSMIT 1
#define USB_RECEIVE 2
#define USB_CLASS_CODE_TEST_CLASS_DEVICE 0xdc
#define USB_SUBCLASS_CODE_TEST_CLASS_D12 0xA0
#define USB_PROTOCOL_CODE_TEST_CLASS_D12 0xB0
//*************************************************************************
// masks
//*************************************************************************
#define USB_RECIPIENT (unsigned char)0x1F
#define USB_RECIPIENT_DEVICE (unsigned char)0x00
#define USB_RECIPIENT_INTERFACE (unsigned char)0x01
#define USB_RECIPIENT_ENDPOINT (unsigned char)0x02
#define USB_REQUEST_TYPE_MASK (unsigned char)0x60
#define USB_STANDARD_REQUEST (unsigned char)0x00
//#define USB_CLASS_REQUEST (unsigned char)0x20
#define USB_VENDOR_REQUEST (unsigned char)0x40
#define USB_REQUEST_MASK (unsigned char)0x0F
#define DEVICE_ADDRESS_MASK 0x7F
/*
//*************************************************************************
// macros
//*************************************************************************
*/
#define SWAP(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
#define MSB(x) (((x) >> 8) & 0xFF)
#define LSB(x) ((x) & 0xFF)
#define FALSE 0
#define TRUE (!FALSE)
#define DISABLE EA=0
#define ENABLE EA=1
/*
//*************************************************************************
// basic typedefs
//*************************************************************************
*/
typedef unsigned char UCHAR;
typedef unsigned short USHORT;
typedef unsigned long ULONG;
typedef unsigned char BOOL;
/*
//*************************************************************************
// structure and union definitions
//*************************************************************************
*/
typedef union _epp_flags
{
struct _flags
{
unsigned char timer : 1;
unsigned char bus_reset : 1;
unsigned char suspend : 1;
unsigned char setup_packet : 1;
unsigned char remote_wakeup : 1;
unsigned char in_isr : 1;
unsigned char control_state : 2;
unsigned char configuration : 1;
unsigned char verbose : 1;
unsigned char ep1_rxdone : 1;
unsigned char setup_dma : 2; // V2.3
unsigned char dma_state : 2;
unsigned char power_down : 1; // Smart Board
} bits;
unsigned short value;
} EPPFLAGS;
typedef struct _device_request
{
unsigned char bmRequestType;
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} DEVICE_REQUEST;
typedef struct _IO_REQUEST {
unsigned short uAddressL;
unsigned char bAddressH;
unsigned short uSize;
unsigned char bCommand;
} IO_REQUEST, *PIO_REQUEST;
#define MAX_CONTROLDATA_SIZE 8
typedef struct _control_xfer
{
DEVICE_REQUEST DeviceRequest;
unsigned short wLength;
unsigned short wCount;
unsigned char * pData;
unsigned char dataBuffer[MAX_CONTROLDATA_SIZE];
} CONTROL_XFER;
/*
//*************************************************************************
// USB utility functions
//*************************************************************************
*/
//extern void D12_SetMode(unsigned char bConfig, unsigned char bClkDiv);
//extern void D12_SetDMA(unsigned char bMode);
//extern unsigned char D12_GetDMA(void);
//extern unsigned char D12_ReadEndpointStatus(unsigned char bEndp);
//extern void D12_SetEndpointStatus(unsigned char bEndp, unsigned char bStalled);
//extern void single_transmit(unsigned char * pData, unsigned char len);
//extern void stall_ep0(void);
//void D12_SendResume(void);
//#define IN_TOKEN_DMA 1
//#define OUT_TOKEN_DMA 0
#define DMA_BUFFER_SIZE 256
#define DMA_IDLE 0
#define DMA_RUNNING 1
#define DMA_PENDING 2
#define SETUP_DMA_REQUEST 0x0471
#define GET_FIRMWARE_VERSION 0x0472
//#define GET_SET_TWAIN_REQUEST 0x0473
#define GET_BUFFER_SIZE 0x0474
/*
typedef struct _TWAIN_FILEINFO {
unsigned char bPage; // bPage bit 7 - 5 map to uSize bit 18 - 16
unsigned char uSizeH; // uSize bit 15 - 8
unsigned char uSizeL; // uSize bit 7 - 0
} TWAIN_FILEINFO, *PTWAIN_FILEINFO;
*/
//USB100.C-宏定義
//===============================================================
//===============================================================
#define MAXIMUM_USB_STRING_LENGTH 255
// values for the bits returned by the USB GET_STATUS command
#define USB_GETSTATUS_SELF_POWERED 0x01
#define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED 0x02
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
#define USB_STRING_DESCRIPTOR_TYPE 0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
#define USB_POWER_DESCRIPTOR_TYPE 0x06
#define USB_DESCRIPTOR_MAKE_TYPE_AND_INDEX(d, i) ((USHORT)((USHORT)d<<8 | i))
//
// Values for bmAttributes field of an
// endpoint descriptor
//
#define USB_ENDPOINT_TYPE_MASK 0x03
#define USB_ENDPOINT_TYPE_CONTROL 0x00
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
#define USB_ENDPOINT_TYPE_BULK 0x02
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
//
// definitions for bits in the bmAttributes field of a
// configuration descriptor.
//
#define USB_CONFIG_POWERED_MASK 0xc0
#define USB_CONFIG_BUS_POWERED 0x80
#define USB_CONFIG_SELF_POWERED 0x40
#define USB_CONFIG_REMOTE_WAKEUP 0x20
//
// Endpoint direction bit, stored in address
//
#define USB_ENDPOINT_DIRECTION_MASK 0x80
// test direction bit in the bEndpointAddress field of
// an endpoint descriptor.
#define USB_ENDPOINT_DIRECTION_OUT(addr) (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
#define USB_ENDPOINT_DIRECTION_IN(addr) ((addr) & USB_ENDPOINT_DIRECTION_MASK)
//
// USB defined request codes
// see chapter 9 of the USB 1.0 specifcation for
// more information.
//
// These are the correct values based on the USB 1.0
// specification
#define USB_REQUEST_GET_STATUS 0x00
#define USB_REQUEST_CLEAR_FEATURE 0x01
#define USB_REQUEST_SET_FEATURE 0x03
#define USB_REQUEST_SET_ADDRESS 0x05
#define USB_REQUEST_GET_DESCRIPTOR 0x06
#define USB_REQUEST_SET_DESCRIPTOR 0x07
#define USB_REQUEST_GET_CONFIGURATION 0x08
#define USB_REQUEST_SET_CONFIGURATION 0x09
#define USB_REQUEST_GET_INTERFACE 0x0A
#define USB_REQUEST_SET_INTERFACE 0x0B
#define USB_REQUEST_SYNC_FRAME 0x0C
//
// defined USB device classes
//
#define USB_DEVICE_CLASS_RESERVED 0x00
#define USB_DEVICE_CLASS_AUDIO 0x01
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
#define USB_DEVICE_CLASS_MONITOR 0x04
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
#define USB_DEVICE_CLASS_POWER 0x06
#define USB_DEVICE_CLASS_PRINTER 0x07
#define USB_DEVICE_CLASS_STORAGE 0x08
#define USB_DEVICE_CLASS_HUB 0x09
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
//
// USB defined Feature selectors
//
#define USB_FEATURE_ENDPOINT_STALL 0x0000
#define USB_FEATURE_REMOTE_WAKEUP 0x0001
#define USB_FEATURE_POWER_D0 0x0002
#define USB_FEATURE_POWER_D1 0x0003
#define USB_FEATURE_POWER_D2 0x0004
#define USB_FEATURE_POWER_D3 0x0005
typedef struct _USB_DEVICE_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
USHORT bcdUSB;
UCHAR bDeviceClass;
UCHAR bDeviceSubClass;
UCHAR bDeviceProtocol;
UCHAR bMaxPacketSize0;
USHORT idVendor;
USHORT idProduct;
USHORT bcdDevice;
UCHAR iManufacturer;
UCHAR iProduct;
UCHAR iSerialNumber;
UCHAR bNumConfigurations;
} USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
typedef struct _USB_ENDPOINT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bEndpointAddress;
UCHAR bmAttributes;
USHORT wMaxPacketSize;
UCHAR bInterval;
} USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
//
// values for bmAttributes Field in
// USB_CONFIGURATION_DESCRIPTOR
//
#define BUS_POWERED 0x80
#define SELF_POWERED 0x40
#define REMOTE_WAKEUP 0x20
typedef struct _USB_CONFIGURATION_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
USHORT wTotalLength;
UCHAR bNumInterfaces;
UCHAR bConfigurationValue;
UCHAR iConfiguration;
UCHAR bmAttributes;
UCHAR MaxPower;
} USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
typedef struct _USB_INTERFACE_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bInterfaceNumber;
UCHAR bAlternateSetting;
UCHAR bNumEndpoints;
UCHAR bInterfaceClass;
UCHAR bInterfaceSubClass;
UCHAR bInterfaceProtocol;
UCHAR iInterface;
} USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -