annotate usb.c @ 27:d5a265299a4b

Test programs to talk to the hardware from a PC
author darius
date Mon, 10 Apr 2006 17:22:17 +0930
parents 350e8655cbb7
children 4e417d84365e
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
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
135 STRING_DESCRIPTOR Manufacturer_Descriptor = {
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
136 sizeof(STRING_DESCRIPTOR) + 32, /* bLength */
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
137 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
138 "G\0e\0n\0e\0s\0i\0s\0 \0S\0o\0f\0t\0w\0a\0r\0e\0" /* ManufacturerString in
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
139 * UNICODE */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
140 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
141
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
142 STRING_DESCRIPTOR Product_Descriptor = {
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
143 sizeof(STRING_DESCRIPTOR) + 48, /* bLength */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
144 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
145 /* ProductString in
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
146 * UNICODE */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
147 "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
148 /* XXX: dunno why I need the double quote magic above.. */
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
149 };
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
150
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
151 STRING_DESCRIPTOR Serial_Descriptor;
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
152 STRING_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
153 sizeof(STRING_DESCRIPTOR) + 20, /* bLength - must match string below */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
154 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
155 "1\02\03\0"
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
158 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
159 * The PDIUSBD12 is wired up like so
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
160 *
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
161 * PDI AVR
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
162 * ======================
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
163 * D7:0 <=> PA7:0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
164 * INT_N => PB0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
165 * RD_N <= PB1
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
166 * WR_N <= PB2
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
167 * A0 <= PB3 (0 = data, 1 = cmd)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
168 * SUSPEND <=> PB4
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
169 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
170 uint8_t
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
171 d12_get_data(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
172 uint8_t data;
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
173
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
174 PORTB &= ~_BV(PB3); /* Data phase */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
175 DDRA = 0x00; /* Set to input */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
176 PORTB &= ~_BV(PB1); /* Pull RD_N low */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
177 PORTB &= ~_BV(PB1); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
178 PORTB &= ~_BV(PB1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
179 PORTB &= ~_BV(PB1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
180 data = PINA; /* Read the data */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
181 PORTB |= _BV(PB1); /* Pull RD_N high */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
182 return(data);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
183 }
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 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
186 set_d12_data(uint8_t data) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
187 PORTB &= ~_BV(PB3); /* Data phase */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
188 DDRA = 0xff; /* Set to output */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
189 PORTA = data; /* Put the data on the bus */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
190 PORTB &= ~_BV(PB2); /* Pull WR_N low */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
191 PORTB &= ~_BV(PB2); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
192 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
193 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
194 PORTB |= _BV(PB2); /* Pull WR_N high */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
195 PORTB |= _BV(PB2); /* Delay 40 ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
196 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
197 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
198 DDRA = 0x00; /* Back to input */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
199 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
200
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
201 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
202 set_d12_cmd(uint8_t cmd) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
203 PORTB |= _BV(PB3); /* Command phase */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
204 DDRA = 0xff; /* Set to output */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
205 PORTA = cmd; /* Put the data on the bus */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
206 PORTB &= ~_BV(PB2); /* Pull WR_N low */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
207 PORTB &= ~_BV(PB2); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
208 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
209 PORTB &= ~_BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
210 PORTB |= _BV(PB2); /* Pull WR_N high */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
211 PORTB |= _BV(PB2); /* Delay 40ns */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
212 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
213 PORTB |= _BV(PB2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
214 DDRA = 0x00; /* Back to input */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
215 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
216
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
217 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
218 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
219 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
220
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
221 set_d12_cmd(command);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
222 if (count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
223 for (i = 0; i < count; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
224 set_d12_data(buffer[i]);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
225 }
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
229 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
230 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
231 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
232
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
233 set_d12_cmd(command);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
234 if (count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
235 for (i = 0; i < count; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
236 buffer[i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
237 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
238 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
239 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
240
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
241 /* Set up the PDIUSBD12 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
242 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
243 usb_init(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
244 uint8_t buffer[2];
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 /* pull EE_Serial_Descriptor into RAM */
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
247 eeprom_read_block(&Serial_Descriptor, &EE_Serial_Descriptor, EE_Serial_Descriptor.bLength);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
248
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
249 /* Set Address to zero (default) and enable function */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
250 buffer[0] = 0x80;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
251 d12_write_cmd(D12_SET_ADDRESS_ENABLE, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
252
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
253 /* Enable function generic endpoints */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
254 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
255 d12_write_cmd(D12_SET_ENDPOINT_ENABLE, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
256
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
257 /* Configure the device (soft connect off) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
258 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
259 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
260 d12_write_cmd(D12_SET_MODE, buffer, 2);
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 /* Delay long enough for the PC to notice the disconnect */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
263 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
264
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
265 buffer[0] |= 0x10; /* Soft connect on */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
266 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
267
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
268 /* Endpoint 2 IN/OUT IRQ enable */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
269 buffer[0] = 0xc0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
270 d12_write_cmd(D12_SET_DMA, buffer, 1);
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 /* Process an interrupt */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
274 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
275 usb_intr(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
276 uint8_t irq[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
277 uint8_t buffer[8];
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 d12_read_cmd(D12_READ_INTERRUPT_REGISTER, (uint8_t *)&irq, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
280
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
281 /* Why do we get interrupts when this is 0? */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
282 if (irq[0] == 0)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
283 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
284
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
285 if (irq[0] & D12_INT_BUS_RESET) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
286 uart_putsP(PSTR("Bus reset\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
287 usb_init();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
288 return;
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
291 if (irq[0] & D12_INT_SUSPEND) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
292 uart_putsP(PSTR("Suspend change\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
293 }
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 if (irq[0] & D12_INT_EP0_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
296 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
297
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
298 /* Handle any outgoing data for EP0 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
299 d12_write_buffer_ep0();
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
302 /* Handle configuration and misc stuff */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
303 if (irq[0] & D12_INT_EP0_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
304 d12_ep0_irq();
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
307 /* 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
308 if (irq[0] & D12_INT_EP1_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
309 /* XXX: Not yet implemented */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
310 }
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 /* 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
313 if (irq[0] & D12_INT_EP1_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
314 /* XXX: Not yet implemented */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
315 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
316
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
317 if (irq[0] & D12_INT_EP2_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
318 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
319 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
320 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
321
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
322 if (irq[0] & D12_INT_EP2_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
323 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
324 d12_receive_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
325 }
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 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
329 usb_gendata(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
330 packet2[0] = 'a';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
331 packet2[1] = 'b';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
332 packet2[2] = 'c';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
333 packet2[3] = '\n';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
334 packet2[4] = '\r';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
335 BytesToSend2 = 5;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
336 pSendBuffer2 = (uint8_t *)&packet2[0];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
337 send_packet2 = 1;
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 /* Kick off the data transfer */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
340 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
341 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
342
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
343 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
344 d12_ep0_irq(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
345 uint8_t buffer[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
346 USB_SETUP_REQUEST setuppkt;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
347
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
348 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
349
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
350 if (buffer[0] & D12_LAST_TRAN_SETUP) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
351 /* Read the setup packet */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
352 d12_read_endpt(D12_ENDPOINT_EP0_OUT, (uint8_t *)&setuppkt);
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 /* Ack the packet to EP0_OUT */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
355 d12_write_cmd(D12_ENDPOINT_EP0_OUT, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
356 d12_write_cmd(D12_ACK_SETUP, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
357 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
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 /* Ack the packet to EP0_IN */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
360 d12_write_cmd(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
361 d12_write_cmd(D12_ACK_SETUP, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
362
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
363 /* It's a new xfer, so forget about any old one */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
364 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
365
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
366 /* Parse request type */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
367 switch (setuppkt.bmRequestType & 0x7f) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
368 case STANDARD_DEVICE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
369 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
370 case GET_STATUS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
371 /* Get status request should return remote
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
372 * wakeup and self powered status
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
373 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
374 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
375 buffer[1] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
376 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
377 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
378 case CLEAR_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
379 case SET_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
380 /* We don't support DEVICE_REMOTE_WAKEUP or
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
381 * TEST_MODE
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 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
384 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
385
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
386 case SET_ADDRESS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
387 deviceaddress = setuppkt.wValue | 0x80;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
388 d12_write_cmd(D12_SET_ADDRESS_ENABLE, &deviceaddress, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
389 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
390 break;
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 case GET_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
393 d12_getdescriptor(&setuppkt);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
394 break;
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 case GET_CONFIGURATION:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
397 d12_write_endpt(D12_ENDPOINT_EP0_IN, &deviceconfigured, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
398 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
399
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
400 case SET_CONFIGURATION:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
401 deviceconfigured = setuppkt.wValue & 0xff;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
402 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
403 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
404
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
405
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
406 case SET_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
407 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
408 /* Unsupported, stall */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
409 d12_stallctrlendpt();
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 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
412 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
413
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
414 case STANDARD_INTERFACE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
415 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
416 case GET_STATUS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
417 /* Should return 0, 0 (reserved) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
418 buffer[0] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
419 buffer[1] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
420 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
421 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
422
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
423 case SET_INTERFACE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
424 if (setuppkt.wIndex == 0 && setuppkt.wValue == 0)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
425 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
426 else
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
427 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
428 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
429
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
430 case GET_INTERFACE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
431 /* Can only handle interface 0 ... */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
432 if (setuppkt.wIndex == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
433 buffer[0] = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
434 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
435 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
436 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
437 /* .. otherwise fall through to error */
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 CLEAR_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
440 case SET_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
441 default:
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_ENDPOINT_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 CLEAR_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
450 case SET_FEATURE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
451 /* Halt(stall) is required to be implemented on
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
452 * interrupt and bulk endpoints.
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
453 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
454 if (setuppkt.wValue == ENDPOINT_HALT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
455 if (setuppkt.bRequest == CLEAR_FEATURE)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
456 buffer[0] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
457 else
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
458 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
459 switch (setuppkt.wIndex & 0xFF) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
460 case 0x01:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
461 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
462 D12_ENDPOINT_EP1_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
463 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
464 case 0x81:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
465 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
466 D12_ENDPOINT_EP1_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
467 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
468 case 0x02:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
469 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
470 D12_ENDPOINT_EP2_OUT, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
471 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
472 case 0x82:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
473 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
474 D12_ENDPOINT_EP2_IN, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
475 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
476 default: /* Invalid Endpoint -
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
477 * RequestError */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
478 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
479 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
480 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
481 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
482 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
483 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
484 * No other Features for Endpoint -
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
485 * Request Error
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 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
488 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
489 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
490
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
491 case GET_STATUS:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
492 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
493 * Get Status Request to Endpoint should
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
494 * return Halt Status in D0 for Interrupt and Bulk
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
495 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
496 switch (setuppkt.wIndex & 0xFF) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
497 case 0x01:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
498 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
499 D12_ENDPOINT_EP1_OUT, 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 0x81:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
502 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
503 D12_ENDPOINT_EP1_IN, 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 0x02:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
506 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
507 D12_ENDPOINT_EP2_OUT, 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 case 0x82:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
510 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
511 D12_ENDPOINT_EP2_IN, buffer, 1);
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 default: /* Invalid Endpoint -
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
514 * RequestError */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
515 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
516 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
517 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
518 if (buffer[0] & 0x08)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
519 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
520 else
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
521 buffer[0] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
522 buffer[1] = 0x00;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
523 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
524 break;
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 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
527 /* Unsupported - Request Error - Stall */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
528 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
529 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
530 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
531 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
532 case VENDOR_DEVICE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
533 case VENDOR_ENDPOINT_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
534 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
535 case VENDOR_RESET:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
536 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
537 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
538 /* disconnect from USB */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
539 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
540 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
541 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
542 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
543 cli();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
544 reset();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
545 /* NOT REACHED */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
546 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
547 case VENDOR_UPDATE:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
548 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
549 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
550 /* disconnect from USB */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
551 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
552 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
553 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
554 _delay_us(1000);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
555 cli();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
556 bootloader();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
557 /* NOT REACHED */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
558 break;
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 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
561 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
562 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
563 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
564 case VENDOR_INTERFACE_REQUEST:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
565 switch (setuppkt.bRequest) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
566 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
567 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
568 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
569 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
570 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
571 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
572 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
573 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
574 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
575 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
576 /* This is a Data Packet */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
577 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
578
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
579 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
580
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
581 /* Reset the micro */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
582 static void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
583 reset(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
584 MCUCR = _BV(IVCE);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
585 MCUCR = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
586 WDTCR = _BV(WDE);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
587 for (;;)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
588 ;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
589 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
590
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
591 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
592 d12_getdescriptor(USB_SETUP_REQUEST *setuppkt) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
593 switch ((setuppkt->wValue & 0xff00) >> 8) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
594 case TYPE_DEVICE_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
595 pSendBuffer = (const uint8_t *)&DeviceDescriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
596 BytesToSend = DeviceDescriptor.bLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
597 send_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
598 if (BytesToSend >= setuppkt->wLength) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
599 BytesToSend = setuppkt->wLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
600 exact_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
601 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
602 exact_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
603 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
604 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
605 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
606
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
607 case TYPE_CONFIGURATION_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
608 pSendBuffer = (const uint8_t *)&ConfigurationDescriptor;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
609 BytesToSend = sizeof(ConfigurationDescriptor);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
610 send_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
611 if (BytesToSend >= setuppkt->wLength) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
612 BytesToSend = setuppkt->wLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
613 exact_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
614 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
615 exact_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
616 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
617 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
618 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
619
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
620 case TYPE_STRING_DESCRIPTOR:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
621 switch (setuppkt->wValue & 0xFF) {
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 case 0:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
624 pSendBuffer = (const uint8_t *)&LANGID_Descriptor;
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
625 BytesToSend = LANGID_Descriptor.bLength;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
626 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
627
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
628 case 1:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
629 pSendBuffer = (const uint8_t *)&Manufacturer_Descriptor;
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
630 BytesToSend = Manufacturer_Descriptor.bLength;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
631 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
632
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
633 case 2:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
634 pSendBuffer = (const uint8_t *)&Product_Descriptor;
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
635 BytesToSend = Product_Descriptor.bLength;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
636 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
637
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
638 case 3:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
639 pSendBuffer = (const uint8_t *)&Serial_Descriptor;
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
640 BytesToSend = Serial_Descriptor.bLength;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
641 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
642
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
643 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
644 pSendBuffer = NULL;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
645 BytesToSend = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
646 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
647 send_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
648 if (BytesToSend >= setuppkt->wLength) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
649 BytesToSend = setuppkt->wLength;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
650 exact_Bytes = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
651 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
652 exact_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
653 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
654 d12_write_buffer_ep0();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
655 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
656 default:
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
657 d12_stallctrlendpt();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
658 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
659 }
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
662
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
663 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
664 d12_stallctrlendpt(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
665 uint8_t Buffer[] = {0x01};
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
666 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
667 * 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
668 * Stage Transaction
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
669 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
670 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
671 /* or in the status stage of the message. */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
672 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
673 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
674
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
675 uint8_t
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
676 d12_read_endpt(uint8_t endpt, uint8_t *buffer) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
677 uint8_t d12header[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
678 uint8_t status = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
679 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
680
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
681 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
682 d12_read_cmd(endpt, &status, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
683
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
684 /* Check if Buffer is Full */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
685 if (status & 0x01) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
686 set_d12_cmd(D12_READ_BUFFER);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
687 d12header[0] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
688 d12header[1] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
689 if (d12header[1]) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
690 for (i = 0; i < d12header[1]; i++)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
691 buffer[i] = d12_get_data();
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 /* Allow new packets to be accepted */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
694 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
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 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
697 return d12header[1];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
698 }
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 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
701 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
702 uint8_t status = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
703 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
704
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
705 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
706 d12_read_cmd(endpt, &status, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
707 /* Write Header */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
708 set_d12_cmd(D12_WRITE_BUFFER);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
709 set_d12_data(0x00);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
710 set_d12_data(bytes);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
711 /* Write Packet */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
712 if (bytes) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
713 for (i = 0; i < bytes; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
714 set_d12_data(buffer[i]);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
715 }
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 /* Validate Buffer */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
718 d12_write_cmd(D12_VALIDATE_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
719 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
720
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
721 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
722 d12_write_buffer_ep0(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
723 uint8_t BufferStatus = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
724
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
725 if (send_Bytes == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
726 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
727 }
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 /* Read Buffer Full Status */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
730 d12_read_cmd(D12_ENDPOINT_EP0_IN, &BufferStatus, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
731 if (BufferStatus != 0) {/* Buffer Full */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
732 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
733 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
734
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
735 if (BytesToSend == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
736 /*
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
737 * If BytesToSend is Zero and we get called again, assume
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
738 * buffer is smaller
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
739 * than Setup Request Size and indicate end by sending Zero
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
740 * Length packet
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
741 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
742 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
743 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
744 } else if (BytesToSend >= EP0_SIZE) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
745 /* Write another EP0_SIZE Bytes to buffer and send */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
746 d12_write_endpt(D12_ENDPOINT_EP0_IN, pSendBuffer, EP0_SIZE);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
747 pSendBuffer += EP0_SIZE;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
748 BytesToSend -= EP0_SIZE;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
749 if (BytesToSend == 0 && exact_Bytes) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
750 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
751 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
752 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
753 /* Buffer must have less than EP0_SIZE bytes left */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
754 d12_write_endpt(D12_ENDPOINT_EP0_IN, pSendBuffer, BytesToSend);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
755
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
756 BytesToSend = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
757 send_Bytes = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
758 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
759 }
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 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
762 d12_send_data_ep2(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
763 uint8_t BufferStatus = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
764
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
765 /* Read Buffer Full Status */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
766 d12_read_cmd(D12_ENDPOINT_EP2_IN, &BufferStatus, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
767 if (BufferStatus == 0) { /* Buffer Empty */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
768 if (BytesToSend2 == 0) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
769 /* Nothing to do */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
770 send_packet2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
771 } else if (BytesToSend2 >= 64) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
772 /* Write another 64 Bytes to buffer and send */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
773 d12_write_endpt(D12_ENDPOINT_EP2_IN, pSendBuffer2, 64);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
774 pSendBuffer2 += 64;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
775 BytesToSend2 -= 64;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
776 } else {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
777 /* Buffer must have less than 64 bytes left */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
778 d12_write_endpt(D12_ENDPOINT_EP2_IN, pSendBuffer2, BytesToSend2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
779 BytesToSend2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
780 send_packet2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
781 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
782 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
783 }
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 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
786 d12_receive_data_ep2(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
787 uint8_t D12Header[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
788 uint8_t bytes;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
789 uint8_t BufferStatus = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
790 uint8_t i;
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 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
793 d12_read_cmd(D12_ENDPOINT_EP2_OUT, &BufferStatus, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
794 /* Check if Buffer is Full */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
795 if (BufferStatus & 0x01) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
796 /* Read header */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
797 set_d12_cmd(D12_READ_BUFFER);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
798 D12Header[0] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
799 D12Header[1] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
800 bytes = D12Header[1];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
801 /* TODO check if the packet is not too long */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
802 uart_putsP(PSTR("Got data\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
803 for (i = 0; i < bytes; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
804 packet2[packetlen2 + i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
805 uart_puts_hex(packet2[packetlen2 + i]);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
806 uart_putsP(PSTR(" "));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
807 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
808 uart_putsP(PSTR("\n\r"));
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
809 packetlen2 += bytes;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
810 /* Allow new packets to be accepted */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
811 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
812 if (bytes == 0 || bytes < 64) { /* request complete */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
813 pSendBuffer2 = packet2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
814 send_packet2 = 1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
815 packetlen2 = 0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
816 d12_send_data_ep2();
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 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
819 }