annotate usb.c @ 23:845934a4e7fe

Add code to talk to a Phillips PDIUSBB12.
author darius
date Mon, 12 Dec 2005 23:32:59 +1030
parents
children 350e8655cbb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1 #include <stdlib.h>
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
2 #include <avr/io.h>
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
3 #include <avr/pgmspace.h>
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
4 #include <avr/interrupt.h>
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
5 #include <avr/eeprom.h>
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
6 #include <util/delay.h>
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
7
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
8 #include "usb.h"
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
9
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
10 #define EP0_SIZE 16
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
11
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
12 #define D12_MODE_0 0x14 /* Endpoint config = 0, SoftConnect = 1, IRQ Mode = 1,
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
13 * Clock running = 0, No Lazy Clock = 0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
14 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
15 #define D12_MODE_1 0x02 /* SOF mode = 0, Set-to-one = 0, Clock div = 2 (16Mhz) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
16 /* Debugging stuff */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
17 void uart_putsP(const char *addr);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
18 void uart_puts(const char *addr);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
19 int uart_putc(char c);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
20 void uart_puts_dec(uint8_t a, uint8_t l);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
21 void uart_puts_hex(uint8_t a);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
22
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
23 /* USB administrivia */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
24 uint8_t deviceaddress;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
25 uint8_t deviceconfigured;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
26
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
27 /* End point buffer points and such */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
28 const uint8_t *pSendBuffer;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
29 uint8_t BytesToSend;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
30 static uint8_t send_Bytes;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
31 static uint8_t exact_Bytes;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
32
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
33 static const uint8_t *pSendBuffer2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
34 static uint8_t BytesToSend2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
35
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
36 /* Data packet buffer */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
37 static uint8_t send_packet2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
38 static uint8_t packet2[270];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
39 static uint16_t packetlen2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
40
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
41 /* XXX: Not actually used */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
42 void (*bootloader)(void) = (void*)0xe000;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
43
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
44 /* Device/endpoint/etc descriptions */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
45 const USB_DEVICE_DESCRIPTOR DeviceDescriptor = {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
46 sizeof(USB_DEVICE_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
47 TYPE_DEVICE_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
48 0x0110, /* bcdUSB USB Version 1.1 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
49 0, /* bDeviceClass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
50 0, /* bDeviceSubclass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
51 0, /* bDeviceProtocol */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
52 EP0_SIZE, /* bMaxPacketSize in Bytes */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
53 0x4753, /* idVendor (inofficial GS) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
54 0x0001, /* idProduct */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
55 0x0100, /* bcdDevice */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
56 1, /* iManufacturer String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
57 2, /* iProduct String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
58 3, /* iSerialNumber String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
59 1 /* bNumberConfigurations */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
60 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
61
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
62 const USB_CONFIG_DATA ConfigurationDescriptor = {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
63 { /* configuration descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
64 sizeof(USB_CONFIGURATION_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
65 TYPE_CONFIGURATION_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
66 sizeof(USB_CONFIG_DATA), /* wTotalLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
67 2, /* bNumInterfaces */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
68 1, /* bConfigurationValue */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
69 0, /* iConfiguration String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
70 0x80, /* bmAttributes Bus Powered, No Remote Wakeup */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
71 100/2 /* bMaxPower in mA */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
72 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
73 { /* interface descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
74 sizeof(USB_INTERFACE_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
75 TYPE_INTERFACE_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
76 0, /* bInterface Number */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
77 0, /* bAlternateSetting */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
78 2, /* bNumEndpoints */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
79 0xFF, /* bInterfaceClass (Vendor specific) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
80 0x02, /* bInterfaceSubClass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
81 0x00, /* bInterfaceProtocol */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
82 0 /* iInterface String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
83 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
84 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
85 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
86 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
87 0x02, /* bEndpoint Address EP2 OUT */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
88 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
89 0x0040, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
90 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
91 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
92 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
93 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
94 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
95 0x82, /* bEndpoint Address EP2 IN */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
96 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
97 0x0040, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
98 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
99 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
100 { /* interface descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
101 sizeof(USB_INTERFACE_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
102 TYPE_INTERFACE_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
103 1, /* bInterface Number */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
104 0, /* bAlternateSetting */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
105 2, /* bNumEndpoints */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
106 0xFF, /* bInterfaceClass (Vendor specific) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
107 0x02, /* bInterfaceSubClass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
108 0x00, /* bInterfaceProtocol */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
109 0 /* iInterface String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
110 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
111 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
112 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
113 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
114 0x01, /* bEndpoint Address EP1 OUT */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
115 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
116 0x0010, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
117 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
118 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
119 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
120 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
121 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
122 0x81, /* bEndpoint Address EP1 IN */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
123 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
124 0x0010, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
125 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
126 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
127 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
128 const LANGID_DESCRIPTOR LANGID_Descriptor = { /* LANGID String Descriptor
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
129 * Zero */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
130 sizeof(LANGID_DESCRIPTOR), /* bLength - must match string below */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
131 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
132 0x0409 /* LANGID US English */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
133 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
134
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
135 /* These are really STRING_DESCRIPTOR's but we can't statically
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
136 * declare them as that and have the compiler generate the right size
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
137 * structure */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
138 typedef struct {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
139 uint8_t bLenght;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
140 uint8_t bDescriptorType;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
141 char bString[32];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
142 } MANUFACTURER_DESCRIPTOR, *PMANUFACTURER_DESCRIPTOR;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
143
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
144 const MANUFACTURER_DESCRIPTOR Manufacturer_Descriptor = { /* ManufacturerString 1 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
145 sizeof(MANUFACTURER_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
146 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
147 "G\0e\0n\0e\0s\0i\0s\0 \0S\0o\0f\0t\0w\0a\0r\0e\0" /* ManufacturerString in
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
148 * UNICODE */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
149 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
150
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
151 typedef struct {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
152 uint8_t bLenght;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
153 uint8_t bDescriptorType;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
154 char bString[48];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
155 } PRODUCT_DESCRIPTOR, *PPRODUCT_DESCRIPTOR;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
156
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
157 const PRODUCT_DESCRIPTOR Product_Descriptor = { /* ProductString 2 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
158 sizeof(PRODUCT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
159 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
160 /* ProductString in
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
161 * UNICODE */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
162 "R\0S\0""-\0""4\0""8\0""5\0"" \0M\0u\0l\0t\0i\0d\0r\0o\0p\0 \0A\0d\0a\0p\0t\0e\0r\0"
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
163 /* XXX: dunno why I need the double quote magic above.. */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
164 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
165
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
166 typedef struct {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
167 uint8_t bLenght;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
168 uint8_t bDescriptorType;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
169 char bString[20];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
170 } SERIAL_DESCRIPTOR, *PSERIAL_DESCRIPTOR;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
171
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
172 const SERIAL_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
173 sizeof(SERIAL_DESCRIPTOR), /* bLength - must match string below */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
174 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
175 "1\02\03\0"
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
176 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
177
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
178 SERIAL_DESCRIPTOR Serial_Descriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
179
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
180 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
181 * The PDIUSBD12 is wired up like so
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
182 *
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
183 * PDI AVR
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
184 * ======================
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
185 * D7:0 <=> PA7:0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
186 * INT_N => PB0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
187 * RD_N <= PB1
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
188 * WR_N <= PB2
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
189 * A0 <= PB3 (0 = data, 1 = cmd)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
190 * SUSPEND <=> PB4
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
191 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
192 uint8_t
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
193 d12_get_data(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
194 uint8_t data;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
195 #if 0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
196 _delay_us(1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
197 #endif
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
198 PORTB &= ~_BV(PB3); /* Data phase */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
199 DDRA = 0x00; /* Set to input */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
200 PORTB &= ~_BV(PB1); /* Pull RD_N low */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
201 PORTB &= ~_BV(PB1); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
202 PORTB &= ~_BV(PB1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
203 PORTB &= ~_BV(PB1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
204 data = PINA; /* Read the data */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
205 PORTB |= _BV(PB1); /* Pull RD_N high */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
206 return(data);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
207 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
208
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
209 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
210 set_d12_data(uint8_t data) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
211 #if 0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
212 _delay_us(1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
213 #endif
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
214 PORTB &= ~_BV(PB3); /* Data phase */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
215 DDRA = 0xff; /* Set to output */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
216 PORTA = data; /* Put the data on the bus */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
217 PORTB &= ~_BV(PB2); /* Pull WR_N low */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
218 PORTB &= ~_BV(PB2); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
219 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
220 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
221 PORTB |= _BV(PB2); /* Pull WR_N high */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
222 PORTB |= _BV(PB2); /* Delay 40 ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
223 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
224 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
225 DDRA = 0x00; /* Back to input */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
226 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
227
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
228 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
229 set_d12_cmd(uint8_t cmd) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
230 #if 0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
231 _delay_us(1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
232 #endif
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
233 PORTB |= _BV(PB3); /* Command phase */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
234 DDRA = 0xff; /* Set to output */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
235 PORTA = cmd; /* Put the data on the bus */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
236 PORTB &= ~_BV(PB2); /* Pull WR_N low */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
237 PORTB &= ~_BV(PB2); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
238 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
239 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
240 PORTB |= _BV(PB2); /* Pull WR_N high */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
241 PORTB |= _BV(PB2); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
242 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
243 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
244 DDRA = 0x00; /* Back to input */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
245 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
246
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
247 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
248 d12_write_cmd(uint8_t command, const uint8_t *buffer, uint8_t count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
249 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
250
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
251 set_d12_cmd(command);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
252 #if 0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
253 _delay_us(1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
254 #endif
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
255 if (count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
256 for (i = 0; i < count; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
257 set_d12_data(buffer[i]);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
258 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
259 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
260 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
261
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
262 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
263 d12_read_cmd(uint8_t command, uint8_t *buffer, uint8_t count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
264 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
265
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
266 set_d12_cmd(command);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
267 if (count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
268 for (i = 0; i < count; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
269 buffer[i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
270 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
271 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
272 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
273
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
274 /* Set up the PDIUSBD12 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
275 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
276 usb_init(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
277 uint8_t buffer[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
278
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
279 /* pull EE_Serial_Descriptor into RAM */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
280 eeprom_read_block(&Serial_Descriptor, &EE_Serial_Descriptor, sizeof(Serial_Descriptor));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
281
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
282 /* Set Address to zero (default) and enable function */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
283 buffer[0] = 0x80;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
284 d12_write_cmd(D12_SET_ADDRESS_ENABLE, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
285
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
286 /* Enable function generic endpoints */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
287 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
288 d12_write_cmd(D12_SET_ENDPOINT_ENABLE, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
289
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
290 /* Configure the device (soft connect off) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
291 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
292 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
293 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
294
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
295 /* Delay long enough for the PC to notice the disconnect */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
296 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
297
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
298 buffer[0] |= 0x10; /* Soft connect on */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
299 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
300
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
301 /* Endpoint 2 IN/OUT IRQ enable */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
302 buffer[0] = 0xc0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
303 d12_write_cmd(D12_SET_DMA, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
304 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
305
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
306 /* Process an interrupt */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
307 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
308 usb_intr(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
309 uint8_t irq[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
310 uint8_t buffer[8];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
311
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
312 d12_read_cmd(D12_READ_INTERRUPT_REGISTER, (uint8_t *)&irq, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
313
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
314 /* Why do we get interrupts when this is 0? */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
315 if (irq[0] == 0)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
316 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
317
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
318 if (irq[0] & D12_INT_BUS_RESET) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
319 uart_putsP(PSTR("Bus reset\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
320 usb_init();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
321 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
322 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
323
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
324 if (irq[0] & D12_INT_SUSPEND) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
325 uart_putsP(PSTR("Suspend change\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
326 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
327
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
328 if (irq[0] & D12_INT_EP0_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
329 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP0_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
330
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
331 /* Handle any outgoing data for EP0 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
332 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
333 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
334
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
335 /* Handle configuration and misc stuff */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
336 if (irq[0] & D12_INT_EP0_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
337 d12_ep0_irq();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
338 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
339
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
340 /* EPx_IN is when the host has had a packet of data and is expecting more */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
341 if (irq[0] & D12_INT_EP1_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
342 /* XXX: Not yet implemented */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
343 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
344
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
345 /* EPx_OUT is when we have gotten a packet from the host */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
346 if (irq[0] & D12_INT_EP1_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
347 /* XXX: Not yet implemented */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
348 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
349
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
350 if (irq[0] & D12_INT_EP2_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
351 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP2_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
352 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
353 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
354
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
355 if (irq[0] & D12_INT_EP2_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
356 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP2_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
357 d12_receive_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
358 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
359 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
360
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
361 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
362 usb_gendata(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
363 packet2[0] = 'a';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
364 packet2[1] = 'b';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
365 packet2[2] = 'c';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
366 packet2[3] = '\n';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
367 packet2[4] = '\r';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
368 BytesToSend2 = 5;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
369 pSendBuffer2 = (uint8_t *)&packet2[0];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
370 send_packet2 = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
371
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
372 /* Kick off the data transfer */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
373 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
374 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
375
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
376 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
377 d12_ep0_irq(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
378 uint8_t buffer[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
379 USB_SETUP_REQUEST setuppkt;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
380
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
381 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP0_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
382
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
383 if (buffer[0] & D12_LAST_TRAN_SETUP) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
384 /* Read the setup packet */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
385 d12_read_endpt(D12_ENDPOINT_EP0_OUT, (uint8_t *)&setuppkt);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
386
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
387 /* Ack the packet to EP0_OUT */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
388 d12_write_cmd(D12_ENDPOINT_EP0_OUT, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
389 d12_write_cmd(D12_ACK_SETUP, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
390 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
391
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
392 /* Ack the packet to EP0_IN */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
393 d12_write_cmd(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
394 d12_write_cmd(D12_ACK_SETUP, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
395
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
396 /* It's a new xfer, so forget about any old one */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
397 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
398
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
399 /* Parse request type */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
400 switch (setuppkt.bmRequestType & 0x7f) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
401 case STANDARD_DEVICE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
402 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
403 case GET_STATUS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
404 /* Get status request should return remote
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
405 * wakeup and self powered status
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
406 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
407 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
408 buffer[1] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
409 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
410 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
411 case CLEAR_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
412 case SET_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
413 /* We don't support DEVICE_REMOTE_WAKEUP or
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
414 * TEST_MODE
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
415 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
416 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
417 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
418
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
419 case SET_ADDRESS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
420 deviceaddress = setuppkt.wValue | 0x80;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
421 d12_write_cmd(D12_SET_ADDRESS_ENABLE, &deviceaddress, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
422 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
423 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
424
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
425 case GET_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
426 d12_getdescriptor(&setuppkt);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
427 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
428
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
429 case GET_CONFIGURATION:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
430 d12_write_endpt(D12_ENDPOINT_EP0_IN, &deviceconfigured, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
431 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
432
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
433 case SET_CONFIGURATION:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
434 deviceconfigured = setuppkt.wValue & 0xff;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
435 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
436 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
437
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
438
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
439 case SET_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
440 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
441 /* Unsupported, stall */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
442 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
443 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
444 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
445 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
446
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
447 case STANDARD_INTERFACE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
448 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
449 case GET_STATUS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
450 /* Should return 0, 0 (reserved) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
451 buffer[0] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
452 buffer[1] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
453 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
454 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
455
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
456 case SET_INTERFACE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
457 if (setuppkt.wIndex == 0 && setuppkt.wValue == 0)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
458 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
459 else
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
460 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
461 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
462
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
463 case GET_INTERFACE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
464 /* Can only handle interface 0 ... */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
465 if (setuppkt.wIndex == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
466 buffer[0] = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
467 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
468 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
469 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
470 /* .. otherwise fall through to error */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
471
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
472 case CLEAR_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
473 case SET_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
474 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
475 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
476 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
477 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
478 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
479
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
480 case STANDARD_ENDPOINT_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
481 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
482 case CLEAR_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
483 case SET_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
484 /* Halt(stall) is required to be implemented on
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
485 * interrupt and bulk endpoints.
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
486 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
487 if (setuppkt.wValue == ENDPOINT_HALT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
488 if (setuppkt.bRequest == CLEAR_FEATURE)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
489 buffer[0] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
490 else
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
491 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
492 switch (setuppkt.wIndex & 0xFF) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
493 case 0x01:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
494 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
495 D12_ENDPOINT_EP1_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
496 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
497 case 0x81:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
498 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
499 D12_ENDPOINT_EP1_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
500 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
501 case 0x02:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
502 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
503 D12_ENDPOINT_EP2_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
504 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
505 case 0x82:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
506 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
507 D12_ENDPOINT_EP2_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
508 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
509 default: /* Invalid Endpoint -
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
510 * RequestError */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
511 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
512 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
513 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
514 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
515 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
516 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
517 * No other Features for Endpoint -
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
518 * Request Error
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
519 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
520 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
521 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
522 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
523
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
524 case GET_STATUS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
525 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
526 * Get Status Request to Endpoint should
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
527 * return Halt Status in D0 for Interrupt and Bulk
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
528 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
529 switch (setuppkt.wIndex & 0xFF) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
530 case 0x01:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
531 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
532 D12_ENDPOINT_EP1_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
533 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
534 case 0x81:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
535 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
536 D12_ENDPOINT_EP1_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
537 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
538 case 0x02:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
539 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
540 D12_ENDPOINT_EP2_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
541 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
542 case 0x82:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
543 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
544 D12_ENDPOINT_EP2_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
545 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
546 default: /* Invalid Endpoint -
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
547 * RequestError */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
548 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
549 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
550 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
551 if (buffer[0] & 0x08)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
552 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
553 else
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
554 buffer[0] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
555 buffer[1] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
556 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
557 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
558
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
559 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
560 /* Unsupported - Request Error - Stall */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
561 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
562 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
563 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
564 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
565 case VENDOR_DEVICE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
566 case VENDOR_ENDPOINT_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
567 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
568 case VENDOR_RESET:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
569 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
570 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
571 /* disconnect from USB */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
572 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
573 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
574 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
575 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
576 cli();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
577 reset();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
578 /* NOT REACHED */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
579 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
580 case VENDOR_UPDATE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
581 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
582 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
583 /* disconnect from USB */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
584 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
585 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
586 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
587 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
588 cli();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
589 bootloader();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
590 /* NOT REACHED */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
591 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
592 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
593 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
594 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
595 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
596 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
597 case VENDOR_INTERFACE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
598 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
599 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
600 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
601 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
602 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
603 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
604 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
605 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
606 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
607 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
608 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
609 /* This is a Data Packet */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
610 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
611
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
612 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
613
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
614 /* Reset the micro
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
615 static void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
616 reset(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
617 MCUCR = _BV(IVCE);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
618 MCUCR = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
619 WDTCR = _BV(WDE);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
620 for (;;)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
621 ;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
622 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
623
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
624 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
625 d12_getdescriptor(USB_SETUP_REQUEST *setuppkt) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
626 switch ((setuppkt->wValue & 0xff00) >> 8) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
627 case TYPE_DEVICE_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
628 pSendBuffer = (const uint8_t *)&DeviceDescriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
629 BytesToSend = DeviceDescriptor.bLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
630 send_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
631 if (BytesToSend >= setuppkt->wLength) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
632 BytesToSend = setuppkt->wLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
633 exact_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
634 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
635 exact_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
636 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
637 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
638 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
639
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
640 case TYPE_CONFIGURATION_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
641 pSendBuffer = (const uint8_t *)&ConfigurationDescriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
642 BytesToSend = sizeof(ConfigurationDescriptor);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
643 send_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
644 if (BytesToSend >= setuppkt->wLength) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
645 BytesToSend = setuppkt->wLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
646 exact_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
647 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
648 exact_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
649 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
650 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
651 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
652
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
653 case TYPE_STRING_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
654 switch (setuppkt->wValue & 0xFF) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
655
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
656 case 0:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
657 pSendBuffer = (const uint8_t *)&LANGID_Descriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
658 BytesToSend = sizeof(LANGID_Descriptor);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
659 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
660
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
661 case 1:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
662 pSendBuffer = (const uint8_t *)&Manufacturer_Descriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
663 BytesToSend = sizeof(Manufacturer_Descriptor);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
664 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
665
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
666 case 2:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
667 pSendBuffer = (const uint8_t *)&Product_Descriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
668 BytesToSend = sizeof(Product_Descriptor);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
669 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
670
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
671 case 3:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
672 pSendBuffer = (const uint8_t *)&Serial_Descriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
673 BytesToSend = sizeof(Serial_Descriptor);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
674 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
675
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
676 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
677 pSendBuffer = NULL;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
678 BytesToSend = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
679 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
680 send_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
681 if (BytesToSend >= setuppkt->wLength) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
682 BytesToSend = setuppkt->wLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
683 exact_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
684 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
685 exact_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
686 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
687 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
688 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
689 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
690 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
691 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
692 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
693 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
694
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
695
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
696 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
697 d12_stallctrlendpt(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
698 uint8_t Buffer[] = {0x01};
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
699 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
700 * 9.2.7 RequestError - return STALL PID in response to next DATA
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
701 * Stage Transaction
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
702 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
703 d12_write_cmd(D12_SET_ENDPOINT_STATUS + D12_ENDPOINT_EP0_IN, Buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
704 /* or in the status stage of the message. */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
705 d12_write_cmd(D12_SET_ENDPOINT_STATUS + D12_ENDPOINT_EP0_OUT, Buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
706 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
707
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
708 uint8_t
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
709 d12_read_endpt(uint8_t endpt, uint8_t *buffer) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
710 uint8_t d12header[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
711 uint8_t status = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
712 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
713
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
714 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
715 d12_read_cmd(endpt, &status, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
716
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
717 /* Check if Buffer is Full */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
718 if (status & 0x01) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
719 set_d12_cmd(D12_READ_BUFFER);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
720 d12header[0] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
721 d12header[1] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
722 if (d12header[1]) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
723 for (i = 0; i < d12header[1]; i++)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
724 buffer[i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
725 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
726 /* Allow new packets to be accepted */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
727 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
728
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
729 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
730 return d12header[1];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
731 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
732
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
733 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
734 d12_write_endpt(uint8_t endpt, const uint8_t *buffer, uint8_t bytes) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
735 uint8_t status = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
736 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
737
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
738 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
739 d12_read_cmd(endpt, &status, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
740 /* Write Header */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
741 set_d12_cmd(D12_WRITE_BUFFER);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
742 set_d12_data(0x00);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
743 set_d12_data(bytes);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
744 /* Write Packet */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
745 if (bytes) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
746 for (i = 0; i < bytes; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
747 set_d12_data(buffer[i]);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
748 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
749 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
750 /* Validate Buffer */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
751 d12_write_cmd(D12_VALIDATE_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
752 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
753
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
754 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
755 d12_write_buffer_ep0(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
756 uint8_t BufferStatus = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
757
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
758 if (send_Bytes == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
759 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
760 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
761
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
762 /* Read Buffer Full Status */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
763 d12_read_cmd(D12_ENDPOINT_EP0_IN, &BufferStatus, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
764 if (BufferStatus != 0) {/* Buffer Full */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
765 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
766 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
767
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
768 if (BytesToSend == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
769 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
770 * If BytesToSend is Zero and we get called again, assume
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
771 * buffer is smaller
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
772 * than Setup Request Size and indicate end by sending Zero
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
773 * Lenght packet
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
774 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
775 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
776 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
777 } else if (BytesToSend >= EP0_SIZE) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
778 /* Write another EP0_SIZE Bytes to buffer and send */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
779 d12_write_endpt(D12_ENDPOINT_EP0_IN, pSendBuffer, EP0_SIZE);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
780 pSendBuffer += EP0_SIZE;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
781 BytesToSend -= EP0_SIZE;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
782 if (BytesToSend == 0 && exact_Bytes) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
783 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
784 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
785 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
786 /* Buffer must have less than EP0_SIZE bytes left */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
787 d12_write_endpt(D12_ENDPOINT_EP0_IN, pSendBuffer, BytesToSend);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
788
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
789 BytesToSend = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
790 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
791 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
792 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
793
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
794 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
795 d12_send_data_ep2(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
796 uint8_t BufferStatus = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
797
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
798 /* Read Buffer Full Status */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
799 d12_read_cmd(D12_ENDPOINT_EP2_IN, &BufferStatus, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
800 if (BufferStatus == 0) { /* Buffer Empty */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
801 if (BytesToSend2 == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
802 /* Nothing to do */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
803 send_packet2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
804 } else if (BytesToSend2 >= 64) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
805 /* Write another 64 Bytes to buffer and send */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
806 d12_write_endpt(D12_ENDPOINT_EP2_IN, pSendBuffer2, 64);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
807 pSendBuffer2 += 64;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
808 BytesToSend2 -= 64;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
809 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
810 /* Buffer must have less than 64 bytes left */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
811 d12_write_endpt(D12_ENDPOINT_EP2_IN, pSendBuffer2, BytesToSend2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
812 BytesToSend2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
813 send_packet2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
814 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
815 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
816 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
817
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
818 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
819 d12_receive_data_ep2(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
820 uint8_t D12Header[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
821 uint8_t bytes;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
822 uint8_t BufferStatus = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
823 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
824
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
825 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
826 d12_read_cmd(D12_ENDPOINT_EP2_OUT, &BufferStatus, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
827 /* Check if Buffer is Full */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
828 if (BufferStatus & 0x01) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
829 /* Read header */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
830 set_d12_cmd(D12_READ_BUFFER);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
831 D12Header[0] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
832 D12Header[1] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
833 bytes = D12Header[1];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
834 /* TODO check if the packet is not too long */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
835 uart_putsP(PSTR("Got data\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
836 for (i = 0; i < bytes; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
837 packet2[packetlen2 + i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
838 uart_puts_hex(packet2[packetlen2 + i]);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
839 uart_putsP(PSTR(" "));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
840 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
841 uart_putsP(PSTR("\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
842 packetlen2 += bytes;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
843 /* Allow new packets to be accepted */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
844 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
845 if (bytes == 0 || bytes < 64) { /* request complete */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
846 pSendBuffer2 = packet2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
847 send_packet2 = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
848 packetlen2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
849 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
850 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
851 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
852 }