16 #define NULL (void *)0;
19 #define HI8(word) (uint8_t)(((uint16_t)word >> 8) & 0xff)
20 #define LO8(word) (uint8_t)((uint16_t)word & 0xff)
23 #define STALL_EP0() (EP0CS |= EP0STALL)
24 #define CLEAR_IRQ() (EXIF &= ~USBINT)
29 #define DESCRIPTOR_TYPE_DEVICE 0x01
30 #define DESCRIPTOR_TYPE_CONFIGURATION 0x02
31 #define DESCRIPTOR_TYPE_STRING 0x03
32 #define DESCRIPTOR_TYPE_INTERFACE 0x04
33 #define DESCRIPTOR_TYPE_ENDPOINT 0x05
35 #define STR_DESCR(len, ...) { len * 2 + 2, DESCRIPTOR_TYPE_STRING, { __VA_ARGS__ } }
118 extern volatile bool EP2_in;
140 #define USB_DIR_OUT 0x00
141 #define USB_DIR_IN 0x80
143 #define USB_REQ_TYPE_STANDARD (0x00 << 5)
144 #define USB_REQ_TYPE_CLASS (0x01 << 5)
145 #define USB_REQ_TYPE_VENDOR (0x02 << 5)
146 #define USB_REQ_TYPE_RESERVED (0x03 << 5)
148 #define USB_RECIP_DEVICE 0x00
149 #define USB_RECIP_INTERFACE 0x01
150 #define USB_RECIP_ENDPOINT 0x02
151 #define USB_RECIP_OTHER 0x03
156 #define CF_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
157 #define CF_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
158 #define CF_ENDPOINT (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
161 #define GC_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
164 #define GD_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
167 #define GI_INTERFACE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
170 #define GS_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
171 #define GS_INTERFACE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
172 #define GS_ENDPOINT (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
177 #define SC_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
180 #define SD_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
183 #define SF_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
184 #define SF_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
185 #define SF_ENDPOINT (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
188 #define SI_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
191 #define SY_ENDPOINT (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
195 #define CLEAR_FEATURE 1
197 #define SET_FEATURE 3
199 #define SET_ADDRESS 5
200 #define GET_DESCRIPTOR 6
201 #define SET_DESCRIPTOR 7
202 #define GET_CONFIGURATION 8
203 #define SET_CONFIGURATION 9
204 #define GET_INTERFACE 10
205 #define SET_INTERFACE 11
206 #define SYNCH_FRAME 12
209 #define DEVICE_REMOTE_WAKEUP 1
210 #define ENDPOINT_HALT 0
All information in this file was taken from the EZ-USB Technical Reference Manual,...
uint16_t wIndex
Field that varies according to request.
uint8_t bRequest
Specific request.
uint8_t bmRequestType
Characteristics of a request.
uint16_t wValue
Field that varies according to request.
uint16_t wLength
Number of bytes to transfer in data stage.
USB Configuration Descriptor.
uint16_t wTotalLength
Combined total length of all descriptors.
uint8_t MaxPower
Maximum power consumption in 2 mA units.
uint8_t bDescriptorType
CONFIGURATION descriptor type.
uint8_t bNumInterfaces
Number of interfaces in this configuration.
uint8_t bmAttributes
Configuration characteristics.
uint8_t bLength
Size of this descriptor in bytes.
uint8_t iConfiguration
Index of configuration string descriptor.
uint8_t bConfigurationValue
Value used to select this configuration.
uint16_t idVendor
USB Vendor ID.
uint8_t iSerialNumber
Index of string descriptor containing serial #.
uint16_t bcdDevice
Device Release Number (BCD).
uint8_t bDeviceProtocol
Protocol code.
uint8_t bNumConfigurations
Number of possible configurations.
uint16_t idProduct
USB Product ID.
uint16_t bcdUSB
USB specification release number (BCD).
uint8_t bDeviceClass
Class code.
uint8_t bMaxPacketSize0
Maximum packet size for EP0 (8, 16, 32, 64).
uint8_t iProduct
Index of product string descriptor.
uint8_t iManufacturer
Index of manufacturer string descriptor.
uint8_t bDescriptorType
DEVICE Descriptor Type.
uint8_t bDeviceSubClass
Subclass code.
uint8_t bLength
Size of this descriptor in bytes.
uint16_t wMaxPacketSize
Maximum packet size for this endpoint.
uint8_t bEndpointAddress
Endpoint Address: USB 1.1 spec, table 9-10.
uint8_t bInterval
Polling interval (in ms) for this endpoint.
uint8_t bmAttributes
Endpoint Attributes: USB 1.1 spec, table 9-10.
uint8_t bDescriptorType
ENDPOINT descriptor type.
uint8_t bLength
Size of this descriptor in bytes.
USB Interface Descriptor.
uint8_t bInterfaceProtocol
Protocol code.
uint8_t bNumEndpoints
Number of endpoints used by this interface.
uint8_t iInterface
Index of interface string descriptor.
uint8_t bDescriptorType
INTERFACE descriptor type.
uint8_t bLength
Size of this descriptor in bytes.
uint8_t bInterfaceSubclass
Subclass code.
uint8_t bAlternateSetting
Value used to select alternate setting.
uint8_t bInterfaceClass
Class code.
uint8_t bInterfaceNumber
Interface number.
uint16_t wLANGID[]
LANGID codes.
uint8_t bLength
Size of this descriptor in bytes.
uint8_t bDescriptorType
STRING descriptor type.
uint8_t bDescriptorType
STRING descriptor type.
uint8_t bLength
Size of this descriptor in bytes.
uint16_t bString[]
UNICODE encoded string.
bool usb_handle_clear_feature(void)
Handle CLEAR_FEATURE request.
__xdata uint8_t * usb_get_endpoint_cs_reg(uint8_t ep)
Return the control/status register for an endpoint.
void usb_handle_setup_data(void)
Handle the arrival of a USB Control Setup Packet.
void usb_reset_data_toggle(uint8_t ep)
void usb_handle_set_interface(void)
Handle SET_INTERFACE request.
bool usb_handle_get_descriptor(void)
Handle GET_DESCRIPTOR request.
bool usb_handle_get_status(void)
Handle GET_STATUS request.
void usb_init(void)
USB initialization.
bool usb_handle_set_feature(void)
Handle SET_FEATURE request.