Mercurial > ~darius > hgwebdir.cgi > avr
diff usb.h @ 23:845934a4e7fe
Add code to talk to a Phillips PDIUSBB12.
author | darius |
---|---|
date | Mon, 12 Dec 2005 23:32:59 +1030 |
parents | |
children | 4e417d84365e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usb.h Mon Dec 12 23:32:59 2005 +1030 @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2003 Bernd Walter + * All rights reserved. + */ + +/* Example Source Code for USB Enumeration using a PDIUSBD11 connected to a PIC16F87x + * Copyright 2001 Craig Peacock, Craig.Peacock@beyondlogic.org + * 31th December 2001 http://www.beyondlogic.org + */ + +typedef struct { + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} USB_SETUP_REQUEST; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} USB_DEVICE_DESCRIPTOR; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} USB_ENDPOINT_DESCRIPTOR; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t MaxPower; +} USB_CONFIGURATION_DESCRIPTOR; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} USB_INTERFACE_DESCRIPTOR; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wHIDClassSpecComp; + uint8_t bCountry; + uint8_t bNumDescriptors; + uint8_t b1stDescType; + uint16_t w1stDescLength; +} USB_HID_DESCRIPTOR; + +typedef struct { + USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor; + USB_INTERFACE_DESCRIPTOR InterfaceDescriptor0; + USB_ENDPOINT_DESCRIPTOR EndpointDescriptor00; + USB_ENDPOINT_DESCRIPTOR EndpointDescriptor01; + USB_INTERFACE_DESCRIPTOR InterfaceDescriptor1; + USB_ENDPOINT_DESCRIPTOR EndpointDescriptor10; + USB_ENDPOINT_DESCRIPTOR EndpointDescriptor11; +} USB_CONFIG_DATA; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + char bString[]; +} STRING_DESCRIPTOR; + +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wLANGID0; +} LANGID_DESCRIPTOR; + +#define D12_SET_ADDRESS_ENABLE 0xD0 +#define D12_SET_ENDPOINT_ENABLE 0xD8 +#define D12_SET_MODE 0xF3 +#define D12_SET_DMA 0xFB +#define D12_READ_INTERRUPT_REGISTER 0xF4 +#define D12_READ_BUFFER 0xF0 +#define D12_WRITE_BUFFER 0xF0 +#define D12_ACK_SETUP 0xF1 +#define D12_CLEAR_BUFFER 0xF2 +#define D12_VALIDATE_BUFFER 0xFA +#define D12_READ_LAST_TRANSACTION 0x40 +#define D12_SET_ENDPOINT_STATUS 0x40 +#define D12_READ_ENDPOINT_STATUS 0x80 + +#define D12_ENDPOINT_EP0_OUT 0x00 +#define D12_ENDPOINT_EP0_IN 0x01 +#define D12_ENDPOINT_EP1_OUT 0x02 +#define D12_ENDPOINT_EP1_IN 0x03 +#define D12_ENDPOINT_EP2_OUT 0x04 +#define D12_ENDPOINT_EP2_IN 0x05 + +#define D12_INT_EP0_OUT 0x01 +#define D12_INT_EP0_IN 0x02 +#define D12_INT_EP1_OUT 0x04 +#define D12_INT_EP1_IN 0x08 +#define D12_INT_EP2_OUT 0x10 +#define D12_INT_EP2_IN 0x20 +#define D12_INT_BUS_RESET 0x40 +#define D12_INT_SUSPEND 0x80 + +#define D12_LAST_TRAN_SETUP 0x20 + +#define STANDARD_DEVICE_REQUEST 0x00 +#define STANDARD_INTERFACE_REQUEST 0x01 +#define STANDARD_ENDPOINT_REQUEST 0x02 +#define VENDOR_DEVICE_REQUEST 0x40 +#define VENDOR_INTERFACE_REQUEST 0x41 +#define VENDOR_ENDPOINT_REQUEST 0x42 + +#define GET_STATUS 0 +#define CLEAR_FEATURE 1 +#define SET_FEATURE 3 +#define SET_ADDRESS 5 +#define GET_DESCRIPTOR 6 +#define SET_DESCRIPTOR 7 +#define GET_CONFIGURATION 8 +#define SET_CONFIGURATION 9 +#define GET_INTERFACE 10 +#define SET_INTERFACE 11 +#define SYNCH_FRAME 12 + +#define VENDOR_UPDATE 126 +#define VENDOR_RESET 127 + +#define ENDPOINT_HALT 0 + +#define TYPE_DEVICE_DESCRIPTOR 1 +#define TYPE_CONFIGURATION_DESCRIPTOR 2 +#define TYPE_STRING_DESCRIPTOR 3 +#define TYPE_INTERFACE_DESCRIPTOR 4 +#define TYPE_ENDPOINT_DESCRIPTOR 5 +#define TYPE_HID_DESCRIPTOR 0x21 + +#define USB_ENDPOINT_TYPE_CONTROL 0x00 +#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 +#define USB_ENDPOINT_TYPE_BULK 0x02 +#define USB_ENDPOINT_TYPE_INTERRUPT 0x03 + +/* Function prototypes */ +uint8_t d12_get_data(void); +void d12_set_data(uint8_t data); +void d12_set_cmd(uint8_t cmd); +void d12_write_cmd(uint8_t command, const uint8_t *buffer, uint8_t count); +void d12_read_cmd(uint8_t command, uint8_t *buffer, uint8_t count); +uint8_t d12_read_endpt(uint8_t endpt, uint8_t *buffer); + +void d12_ep0_irq(void); +void d12_getdescriptor(USB_SETUP_REQUEST *SetupPacket); +void d12_stallctrlendpt(void); +uint8_t d12_read_endpt(uint8_t endpt, uint8_t *buffer); +void d12_write_endpt(uint8_t endpt, const uint8_t *buffer, uint8_t bytes); +void d12_write_buffer_ep0(void); +void d12_send_data_ep2(void); +void d12_receive_data_ep2(void); + +static void reset(void); + +void usb_init(void); +void usb_intr(void); +void usb_gendata(void);