📄 upsd3400_usb.h
字号:
/*--------------------------------------------------------------------------
upsd3400_usb.h
Version:
September 13, 2005 - Version 1.1 - Updated disclaimer, renamed file.
March 22, 2005 - Version 1.0 - Initial Release.
Description: USB structures and constants.
Copyright (c) 2005 ST Microelectronics
THIS INFORMATION (or THIS SOFTWARE or THIS DOCUMENT) IS FOR GUIDANCE ONLY. ST
MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
SOFTWARE nor for any infringement of patents or other rights of third parties
which may result from its use. ST MICROELECTRONICS SHALL NOT BE HELD LIABLE FOR
ANY DIRECT, INDIRECT INCIDENTAL OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY
CLAIMS ARISING IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE,
OR USE OF THIS SOFTWARE. Specifications mentioned in this publication are
subject to change without notice. This publication supersedes and replaces all
information previously supplied. STMicroelectronics products are not authorized
for use as critical components in life support devices or systems without the
express written approval of STMicroelectronics.
--------------------------------------------------------------------------*/
#ifndef UPSD3400_USB_H
#define UPSD3400_USB_H
#define USB_BASE_ADDR 0x7000 // USB FIFO mapped in XDATA space
#define EP0_PKT_SIZE 0x40 // 64 bytes
#define EP1_PKT_SIZE 0x40 // 64 bytes
#define EP3_PKT_SIZE 0x40 // 64 bytes
#define EP1_ADDR (0x81) // test now
#define EP3_ADDR (0x01)
//-- Data Type Definitions ---------------------------------------------------
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned char BOOL;
// iword - Intel word structure
typedef struct
{
uchar lo;
uchar hi;
}
iword;
// USB device descriptor
typedef struct
{
uchar bLength; // Size of this Descriptor in Bytes
uchar bDescriptorType; // Descriptor Type (=1)
iword bcdUSB; // USB Spec Release Number in BCD
uchar bDeviceClass; // Device Class Code
uchar bDeviceSubClass; // Device Subclass Code
uchar bDeviceProtocol; // Device Protocol Code
uchar bMaxPacketSize0; // Maximum Packet Size for EP0
iword idVendor; // Vendor ID
iword idProduct; // Product ID
iword bcdDevice; // Device Release Number in BCD
uchar iManufacturer; // Index of String Desc for Manufacturer
uchar iProduct; // Index of String Desc for Product
uchar iSerialNumber; // Index of String Desc for SerNo
uchar bNumConfigurations; // Number of possible Configurations
}
device_descriptor;
// USB configuration descriptor
typedef struct
{
uchar bLength; // Size of this Descriptor in Bytes
uchar bDescriptorType; // Descriptor Type (=2)
iword wTotalLength; // Total Length of Data for this Conf
uchar bNumInterfaces; // No of Interfaces supported by this Conf
uchar bConfigurationValue; // Designator Value for *this* Configuration
uchar iConfiguration; // Index of String Desc for this Conf
uchar bmAttributes; // Configuration Characteristics (see below)
uchar bMaxPower; // Max. Power Consumption in this Conf (*2mA)
}
configuration_descriptor;
// USB interface descriptor
typedef struct
{
uchar bLength; // Size of this Descriptor in Bytes
uchar bDescriptorType; // Descriptor Type (=4)
uchar bInterfaceNumber; // Number of *this* Interface (0..)
uchar bAlternateSetting; // Alternative for this Interface (if any)
uchar bNumEndpoints; // No of EPs used by this IF (excl. EP0)
uchar bInterfaceClass; // Interface Class Code
uchar bInterfaceSubClass; // Interface Subclass Code
uchar bInterfaceProtocol; // Interface Protocol Code
uchar iInterface; // Index of String Desc for this Interface
}
interface_descriptor;
// USB endpoint descriptor
typedef struct
{
uchar bLength; // Size of this Descriptor in Bytes
uchar bDescriptorType; // Descriptor Type (=5)
uchar bEndpointAddress; // Endpoint Address (Number + Direction)
uchar bmAttributes; // Endpoint Attributes (Transfer Type)
iword wMaxPacketSize; // Max. Endpoint Packet Size
uchar bInterval; // Polling Interval (Interrupt) in ms
}
endpoint_descriptor;
// USB SETUP packet
typedef struct
{
uchar bmRequestType; // Characteristics (Direction,Type,Recipient)
uchar bRequest; // Standard Request Code
iword wValue; // Value Field
iword wIndex; // Index or Offset Field
iword wLength; // Number of Bytes to transfer (Data Stage)
}
setup_buffer;
// USB Status Codes
#define US_ATTACHED 0x00
#define US_POWERED 0x01
#define US_DEFAULT 0x02
#define US_ADDRESSED 0x03
#define US_CONFIGURED 0x04
#define US_SUSPENDED 0x10
//EP state
#define US_EPDEFAULT 0x00
#define US_EPSTALL 0x01
// USB Standard Device Request Codes
#define GET_STATUS 0x00
#define CLEAR_FEATURE 0x01
#define SET_FEATURE 0x03
#define SET_ADDRESS 0x05
#define GET_DESCRIPTOR 0x06
#define SET_DESCRIPTOR 0x07 // optional
#define GET_CONFIGURATION 0x08
#define SET_CONFIGURATION 0x09
#define GET_INTERFACE 0x0A
#define SET_INTERFACE 0x0B
#define SYNCH_FRAME 0x0C // optional
// SETUP packet request types
#define CLASS_INTERFACE_TO_DEVICE 0x21
#define CLASS_INTERFACE_TO_HOST 0xA1
// HID class specific requests
#define HID_GET_REPORT 0x01
#define HID_GET_IDLE 0x02
#define HID_SET_REPORT 0x09
#define HID_SET_IDLE 0x0A
#define REQUEST_COMPLETE 0xff // not part of the Standard - just
// a Flag to indicate that the recent
// request has been finished
// Descriptor Types
#define DT_DEVICE 1
#define DT_CONFIGURATION 2
#define DT_STRING 3
#define DT_INTERFACE 4
#define DT_ENDPOINT 5
#define DT_HID_CLASS 0x21
#define DT_HID_REPORT 0x22
#define DT_HID_PHYSICALD 0x23
//UPAIR
#define PR1IN 0x01
#define PR3IN 0x02
#define PR1OUT 0x04
#define PR3OUT 0x08
//UIE0
#define RESUMEIE 0x01
#define EOPIE 0x02
#define SUSPENDIE 0x04
#define RSTIE 0x08
//UIE1
#define IN0IE 0x01
#define IN1IE 0x02
#define IN2IE 0x04
#define IN3IE 0x08
#define IN4IE 0x10
//UIE2
#define OUT0IE 0x01
#define OUT1IE 0x02
#define OUT2IE 0x04
#define OUT3IE 0x08
#define OUT4IE 0x10
//UIE3
#define NAK0IE 0x01
#define NAK1IE 0x02
#define NAK2IE 0x04
#define NAK3IE 0x08
#define NAK4IE 0x10
//UCTL
#define WAKEUP 0x01
#define VISIBLE 0x02
#define USBEN 0x04
//USTA
#define SETUP 0x04
//USEL
#define INDIR 0x00
#define OUTDIR 0x80
#define SELEP0 0x00
#define SELEP1 0x01
#define SELEP2 0x02
#define SELEP3 0x03
#define SELEP4 0x04
//UCON
#define EPFIFO_BSY 0x01
#define TOGGLE 0x02
#define STALL 0x04
#define ENABLE_FIFO 0x08
#define IN0F 0x01
#define IN1F 0x02
#define IN2F 0x04
#define IN3F 0x08
#define IN4F 0x10
#define OUT0F 0x01
#define OUT1F 0x02
#define OUT2F 0x04
#define OUT3F 0x08
#define OUT4F 0x10
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -