annotate usb.c @ 56:09f8d879afb9

Make it louder.
author darius@Inchoate
date Wed, 29 Oct 2008 17:45:50 +1030
parents 5898fba6593c
children
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"
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
9 #include "1wire.h"
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
10
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
11 /* Maximum FIFO sizes for each endpoint */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
12 #define EP0_FIFO_SZ 16
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
13 #define EP1_FIFO_SZ 16
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
14 #define EP2_FIFO_SZ 64
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
15
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
16 /* PDIUSBD12 mode */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
17 #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
18 * Clock running = 0, No Lazy Clock = 0
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
19 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
20 #define D12_MODE_1 0x02 /* SOF mode = 0, Set-to-one = 0, Clock div = 2 (16Mhz) */
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
21
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
22 /* Debugging stuff */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
23 void uart_putsP(const char *addr);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
24 void uart_puts(const char *addr);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
25 int uart_putc(char c);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
26 void uart_puts_dec(uint8_t a, uint8_t l);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
27 void uart_puts_hex(uint8_t a);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
28
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
29 void parsebuf(uint8_t *buffer, uint8_t ep);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
30
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
31 /* USB administrivia */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
32 uint8_t deviceaddress;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
33 uint8_t deviceconfigured;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
34
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
35 /* Endpoint buffers and such */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
36 /* EP0 in */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
37 static const uint8_t *sendbuffer0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
38 static uint8_t sendbytes0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
39
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
40 /* EP0 out */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
41 /* This is unbuffered as we don't handle packets > EP0_FIFO_SZ */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
42
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
43 /* EP1 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
44 /* Unbuffered as yet */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
45 static uint8_t packet1[270];
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
46 static uint16_t packetlen1;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
47
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
48 /* EP2 in */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
49 static const uint8_t *sendbuffer2;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
50 static uint8_t sendbytes2;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
51
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
52 /* EP2 out */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
53 static uint8_t packet2[270];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
54 static uint16_t packetlen2;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
55
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
56 /* XXX: Not actually used */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
57 void (*bootloader)(void) = (void*)0xe000;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
58
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
59 /* Device/endpoint/etc descriptions */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
60 const USB_DEVICE_DESCRIPTOR DeviceDescriptor = {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
61 sizeof(USB_DEVICE_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
62 TYPE_DEVICE_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
63 0x0110, /* bcdUSB USB Version 1.1 */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
64 0, /* bDeviceClass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
65 0, /* bDeviceSubclass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
66 0, /* bDeviceProtocol */
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
67 EP0_FIFO_SZ, /* bMaxPacketSize in Bytes */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
68 0x4753, /* idVendor (unofficial GS) */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
69 0x0001, /* idProduct */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
70 0x0100, /* bcdDevice */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
71 1, /* iManufacturer String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
72 2, /* iProduct String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
73 3, /* iSerialNumber String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
74 1 /* bNumberConfigurations */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
75 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
76
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
77 const USB_CONFIG_DATA ConfigurationDescriptor = {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
78 { /* configuration descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
79 sizeof(USB_CONFIGURATION_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
80 TYPE_CONFIGURATION_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
81 sizeof(USB_CONFIG_DATA), /* wTotalLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
82 2, /* bNumInterfaces */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
83 1, /* bConfigurationValue */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
84 0, /* iConfiguration String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
85 0x80, /* bmAttributes Bus Powered, No Remote Wakeup */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
86 100/2 /* bMaxPower in mA */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
87 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
88 { /* interface descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
89 sizeof(USB_INTERFACE_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
90 TYPE_INTERFACE_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
91 0, /* bInterface Number */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
92 0, /* bAlternateSetting */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
93 2, /* bNumEndpoints */
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
94 0xff, /* bInterfaceClass (Vendor specific) */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
95 0x02, /* bInterfaceSubClass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
96 0x00, /* bInterfaceProtocol */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
97 0 /* iInterface String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
98 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
99 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
100 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
101 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
102 0x02, /* bEndpoint Address EP2 OUT */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
103 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
104 0x0040, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
105 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
106 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
107 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
108 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
109 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
110 0x82, /* bEndpoint Address EP2 IN */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
111 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
112 0x0040, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
113 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
114 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
115 { /* interface descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
116 sizeof(USB_INTERFACE_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
117 TYPE_INTERFACE_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
118 1, /* bInterface Number */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
119 0, /* bAlternateSetting */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
120 2, /* bNumEndpoints */
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
121 0xff, /* bInterfaceClass (Vendor specific) */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
122 0x02, /* bInterfaceSubClass */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
123 0x00, /* bInterfaceProtocol */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
124 0 /* iInterface String Index */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
125 },
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
126 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
127 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
128 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
129 0x01, /* bEndpoint Address EP1 OUT */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
130 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
131 0x0010, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
132 0x00 /* bInterval */
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 { /* endpoint descriptor */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
135 sizeof(USB_ENDPOINT_DESCRIPTOR), /* bLength */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
136 TYPE_ENDPOINT_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
137 0x81, /* bEndpoint Address EP1 IN */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
138 0x02, /* bmAttributes - Bulk */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
139 0x0010, /* wMaxPacketSize */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
140 0x00 /* bInterval */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
141 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
142 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
143 const LANGID_DESCRIPTOR LANGID_Descriptor = { /* LANGID String Descriptor
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
144 * Zero */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
145 sizeof(LANGID_DESCRIPTOR), /* bLength - must match string below */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
146 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
147 0x0409 /* LANGID US English */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
148 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
149
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
150 STRING_DESCRIPTOR Manufacturer_Descriptor = {
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
151 sizeof(STRING_DESCRIPTOR) + 32, /* bLength */
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
152 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
153 "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
154 * UNICODE */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
155 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
156
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
157 STRING_DESCRIPTOR Product_Descriptor = {
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
158 sizeof(STRING_DESCRIPTOR) + 48, /* bLength */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
159 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
160 /* ProductString in
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
161 * UNICODE */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
162 "R\0S\0""-\0""4\0""8\0""5\0"" \0M\0u\0l\0t\0i\0d\0r\0o\0p\0 \0A\0d\0a\0p\0t\0e\0r\0"
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
163 /* XXX: dunno why I need the double quote magic above.. */
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
164 };
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
165
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
166 STRING_DESCRIPTOR Serial_Descriptor;
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
167 STRING_DESCRIPTOR EE_Serial_Descriptor __attribute__ ((section (".eeprom"))) = { /* SerialString 3 */
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
168 sizeof(STRING_DESCRIPTOR) + 20, /* bLength - must match string below */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
169 TYPE_STRING_DESCRIPTOR, /* bDescriptorType */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
170 "1\02\03\0"
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
171 };
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
172
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
173 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
174 ** d12_get_data
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
175 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
176 ** Read a data byte
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
177 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
178 uint8_t
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
179 d12_get_data(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
180 uint8_t data;
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
181
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
182 _delay_us(1);
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
183 PDICTL &= ~_BV(PDIA0); /* Data phase */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
184 PDIDDR = 0x00; /* Set to input */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
185 PDICTL &= ~_BV(PDIRD); /* Pull RD_N low */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
186 PDICTL &= ~_BV(PDIRD); /* Delay 40ns */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
187 PDICTL &= ~_BV(PDIRD);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
188 PDICTL &= ~_BV(PDIRD);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
189 data = PINA; /* Read the data */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
190 PDICTL |= _BV(PDIRD); /* Pull RD_N high */
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
191
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
192 return(data);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
193 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
194
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
195 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
196 ** d12_set_data
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
197 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
198 ** Write a data byte
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
199 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
200 void
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
201 d12_set_data(uint8_t data) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
202 _delay_us(1);
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
203 PDICTL &= ~_BV(PDIA0); /* Data phase */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
204 PDIDDR = 0xff; /* Set to output */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
205 PDIPORT = data; /* Put the data on the bus */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
206 PDICTL &= ~_BV(PDIWR); /* Pull WR_N low */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
207 PDICTL &= ~_BV(PDIWR); /* Delay 40ns */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
208 PDICTL &= ~_BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
209 PDICTL &= ~_BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
210 PDICTL |= _BV(PDIWR); /* Pull WR_N high */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
211 PDICTL |= _BV(PDIWR); /* Delay 40 ns */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
212 PDICTL |= _BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
213 PDICTL |= _BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
214 PDIDDR = 0x00; /* Back to input */
23
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
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
217 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
218 ** d12_set_cmd
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
219 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
220 ** Start a command
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
221 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
222 void
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
223 d12_set_cmd(uint8_t cmd) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
224 _delay_us(1);
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
225 PDICTL |= _BV(PDIA0); /* Command phase */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
226 PDIDDR = 0xff; /* Set to output */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
227 PDIPORT = cmd; /* Put the data on the bus */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
228 PDICTL &= ~_BV(PDIWR); /* Pull WR_N low */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
229 PDICTL &= ~_BV(PDIWR); /* Delay 40ns */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
230 PDICTL &= ~_BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
231 PDICTL &= ~_BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
232 PDICTL |= _BV(PDIWR); /* Pull WR_N high */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
233 PDICTL |= _BV(PDIWR); /* Delay 40ns */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
234 PDICTL |= _BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
235 PDICTL |= _BV(PDIWR);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
236 PDIDDR = 0x00; /* Back to input */
23
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
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
239 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
240 ** d12_write_cmd
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
241 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
242 ** Issue a command with associated data
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
243 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
244 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
245 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
246 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
247
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
248 d12_set_cmd(command);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
249 if (count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
250 for (i = 0; i < count; i++) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
251 d12_set_data(buffer[i]);
23
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 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
254 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
255
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
256 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
257 ** d12_read_cmd
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
258 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
259 ** Issue a command and read back the data
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
260 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
261 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
262 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
263 uint8_t i;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
264
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
265 d12_set_cmd(command);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
266 if (count) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
267 for (i = 0; i < count; i++) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
268 buffer[i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
269 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
270 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
271 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
272
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
273 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
274 ** usb_init
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
275 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
276 ** Configure the PDIUSBD12
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
277 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
278 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
279 usb_init(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
280 uint8_t buffer[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
281
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
282 /* Check the device is present */
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
283 d12_read_cmd(D12_READ_CHIP_ID, buffer, 2);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
284 if (buffer[0] != 0x12 || buffer[1] != 0x10) {
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
285 uart_putsP(PSTR("PDIUSBD12 does not appear to be present/working, chip ID = 0x"));
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
286 uart_puts_hex(buffer[0]);
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
287 uart_puts_hex(buffer[1]);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
288 uart_putsP(PSTR(", expected 0x1210\r\n"));
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
289 return;
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
290 }
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
291
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
292 /* pull EE_Serial_Descriptor into RAM */
26
350e8655cbb7 - Remove some #if'd out code.
darius
parents: 23
diff changeset
293 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
294
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
295 /* Set Address to zero (default) and enable function */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
296 buffer[0] = 0x80;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
297 d12_write_cmd(D12_SET_ADDRESS_ENABLE, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
298
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
299 /* Enable function generic endpoints */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
300 buffer[0] = 0x01;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
301 d12_write_cmd(D12_SET_ENDPOINT_ENABLE, buffer, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
302
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
303 /* Configure the device (soft connect off) */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
304 buffer[0] = D12_MODE_0 & 0xef;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
305 buffer[1] = D12_MODE_1;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
306 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
307
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
308 /* Delay long enough for the PC to notice the disconnect */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
309 _delay_us(1000);
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 buffer[0] |= 0x10; /* Soft connect on */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
312 d12_write_cmd(D12_SET_MODE, buffer, 2);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
313
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
314 /* Endpoint 2 IN/OUT IRQ enable */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
315 buffer[0] = 0xc0;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
316 d12_write_cmd(D12_SET_DMA, buffer, 1);
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
317
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
318 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
319
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
320 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
321 ** usb_intr
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
322 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
323 ** Process any pending interrupts
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
324 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
325 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
326 usb_intr(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
327 uint8_t irq[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
328 uint8_t buffer[8];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
329
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
330 d12_read_cmd(D12_READ_INTERRUPT_REGISTER, irq, 2);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
331
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
332 /* Why do we get interrupts when this is 0? */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
333 if (irq[0] == 0)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
334 return;
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
335
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
336 uart_putsP(PSTR("usb_intr() called\r\n"));
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
337
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
338 if (irq[0] & D12_INT_BUS_RESET) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
339 uart_putsP(PSTR("Bus reset\r\n"));
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
340 usb_init();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
341 return;
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
344 if (irq[0] & D12_INT_SUSPEND) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
345 uart_putsP(PSTR("Suspend change\r\n"));
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
346 }
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 if (irq[0] & D12_INT_EP0_IN) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
349 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP0_IN, buffer, 1);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
350 if ((buffer[0] & D12_LAST_TRAN_ERRMSK) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
351 uart_putsP(PSTR("EP0_IN error "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
352 uart_puts_hex((buffer[0] & D12_LAST_TRAN_ERRMSK) >> 1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
353 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
354 }
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
355
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
356 /* Handle any outgoing data for EP0 */
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
357 d12_send_data_ep0();
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
358 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
359
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
360 /* Handle configuration and misc stuff */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
361 if (irq[0] & D12_INT_EP0_OUT) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
362 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP0_OUT, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
363 if ((buffer[0] & D12_LAST_TRAN_ERRMSK) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
364 uart_putsP(PSTR("EP0_OUT error "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
365 uart_puts_hex((buffer[0] & D12_LAST_TRAN_ERRMSK) >> 1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
366 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
367 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
368
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
369 if (buffer[0] & D12_LAST_TRAN_SETUP)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
370 d12_handle_setup();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
371 else {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
372 /* Data packet */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
373 }
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
374 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
375
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
376 /* 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
377 if (irq[0] & D12_INT_EP1_IN) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
378 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP1_IN, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
379 if ((buffer[0] & D12_LAST_TRAN_ERRMSK) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
380 uart_putsP(PSTR("EP1_IN error "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
381 uart_puts_hex((buffer[0] & D12_LAST_TRAN_ERRMSK) >> 1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
382 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
383 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
384
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
385 /* Select endpoint */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
386 d12_read_cmd(D12_ENDPOINT_EP1_IN, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
387
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
388 if (buffer[0] & 0x01)
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
389 uart_putsP(PSTR("EP1_IN is full\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
390
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
391 if (buffer[0] & 0x02)
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
392 uart_putsP(PSTR("EP1_IN is stalled\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
393
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
394 d12_write_endpt(D12_ENDPOINT_EP1_IN, NULL, 0);
23
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
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
397 /* 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
398 if (irq[0] & D12_INT_EP1_OUT) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
399 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP1_OUT, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
400 if ((buffer[0] & D12_LAST_TRAN_ERRMSK) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
401 uart_putsP(PSTR("EP1_OUT error "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
402 uart_puts_hex((buffer[0] & D12_LAST_TRAN_ERRMSK) >> 1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
403 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
404 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
405
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
406 d12_receive_data_ep1();
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
407 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
408
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
409 if (irq[0] & D12_INT_EP2_IN) {
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
410 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP2_IN, buffer, 1);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
411 if ((buffer[0] & D12_LAST_TRAN_ERRMSK) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
412 uart_putsP(PSTR("EP2_IN error "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
413 uart_puts_hex((buffer[0] & D12_LAST_TRAN_ERRMSK) >> 1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
414 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
415 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
416
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
417 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
418 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
419
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
420 if (irq[0] & D12_INT_EP2_OUT) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
421 d12_read_cmd(D12_READ_LAST_TRANSACTION + D12_ENDPOINT_EP2_OUT, buffer, 1);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
422 if ((buffer[0] & D12_LAST_TRAN_ERRMSK) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
423 uart_putsP(PSTR("EP2_OUT error "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
424 uart_puts_hex((buffer[0] & D12_LAST_TRAN_ERRMSK) >> 1);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
425 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
426 }
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
427 d12_receive_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
428 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
429 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
430
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
431 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
432 ** usb_gendata
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
433 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
434 ** Fake up some data for testing purposes
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
435 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
436 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
437 usb_gendata(void) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
438 packet2[0] = 'a';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
439 packet2[1] = 'b';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
440 packet2[2] = 'c';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
441 packet2[3] = '\n';
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
442 packet2[4] = '\r';
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
443 sendbytes2 = 5;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
444 sendbuffer2 = (uint8_t *)&packet2[0];
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
445
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
446 /* Kick off the data transfer */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
447 d12_send_data_ep2();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
448 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
449
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
450 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
451 ** d12_handle_setup
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
452 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
453 ** Handle setup packet stuff for endpoint 0
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
454 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
455 void
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
456 d12_handle_setup(void) {
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
457 uint8_t buffer[2];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
458 USB_SETUP_REQUEST setuppkt;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
459
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
460 /* Read the setup packet */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
461 d12_read_endpt(D12_ENDPOINT_EP0_OUT, (uint8_t *)&setuppkt);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
462
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
463 /* Ack the packet to EP0_OUT */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
464 d12_write_cmd(D12_ENDPOINT_EP0_OUT, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
465 d12_write_cmd(D12_ACK_SETUP, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
466 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
467
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
468 /* Ack the packet to EP0_IN */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
469 d12_write_cmd(D12_ENDPOINT_EP0_IN, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
470 d12_write_cmd(D12_ACK_SETUP, NULL, 0);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
471
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
472 /* Parse request type */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
473 switch (setuppkt.bmRequestType & 0x7f) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
474 case STANDARD_DEVICE_REQUEST:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
475 switch (setuppkt.bRequest) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
476 case GET_STATUS:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
477 /* Get status request should return remote
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
478 * wakeup and self powered status
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
479 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
480 buffer[0] = 0x01;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
481 buffer[1] = 0x00;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
482 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
483 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
484 case CLEAR_FEATURE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
485 case SET_FEATURE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
486 /* We don't support DEVICE_REMOTE_WAKEUP or
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
487 * TEST_MODE
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
488 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
489
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
490 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
491 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
492 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
493
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
494 case SET_ADDRESS:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
495 deviceaddress = setuppkt.wValue | 0x80;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
496 d12_write_cmd(D12_SET_ADDRESS_ENABLE, &deviceaddress, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
497 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
498 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
499
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
500 case GET_DESCRIPTOR:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
501 d12_getdescriptor(&setuppkt);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
502 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
503
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
504 case GET_CONFIGURATION:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
505 d12_write_endpt(D12_ENDPOINT_EP0_IN, &deviceconfigured, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
506 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
507
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
508 case SET_CONFIGURATION:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
509 deviceconfigured = setuppkt.wValue & 0xff;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
510 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
511 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
512
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
513
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
514 case SET_DESCRIPTOR:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
515 default:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
516 /* Unsupported, stall */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
517 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
518 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
519 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
520 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
521 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
522
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
523 case STANDARD_INTERFACE_REQUEST:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
524 switch (setuppkt.bRequest) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
525 case GET_STATUS:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
526 /* Should return 0, 0 (reserved) */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
527 buffer[0] = 0x00;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
528 buffer[1] = 0x00;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
529 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
530 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
531
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
532 case SET_INTERFACE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
533 if (setuppkt.wIndex == 0 && setuppkt.wValue == 0)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
534 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
535 else {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
536 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
537 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
538 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
539
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
540 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
541
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
542 case GET_INTERFACE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
543 /* Can only handle interface 0 ... */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
544 if (setuppkt.wIndex == 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
545 buffer[0] = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
546 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 1);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
547 break;
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
548 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
549 /* .. otherwise fall through to error */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
550
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
551 case CLEAR_FEATURE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
552 case SET_FEATURE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
553 default:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
554 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
555 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
556 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
557 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
558 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
559
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
560 case STANDARD_ENDPOINT_REQUEST:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
561 switch (setuppkt.bRequest) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
562 case CLEAR_FEATURE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
563 case SET_FEATURE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
564 /* Halt(stall) is required to be implemented on
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
565 * interrupt and bulk endpoints.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
566 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
567 if (setuppkt.wValue == ENDPOINT_HALT) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
568 if (setuppkt.bRequest == CLEAR_FEATURE)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
569 buffer[0] = 0x00;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
570 else
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
571 buffer[0] = 0x01;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
572 switch (setuppkt.wIndex & 0xFF) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
573 case 0x01:
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
574 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
575 D12_ENDPOINT_EP1_OUT, buffer, 1);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
576 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
577 case 0x81:
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
578 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
579 D12_ENDPOINT_EP1_IN, buffer, 1);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
580 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
581 case 0x02:
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
582 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
583 D12_ENDPOINT_EP2_OUT, buffer, 1);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
584 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
585 case 0x82:
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
586 d12_write_cmd(D12_SET_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
587 D12_ENDPOINT_EP2_IN, buffer, 1);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
588 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
589 default: /* Invalid Endpoint -
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
590 * RequestError */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
591 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
592 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
593 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
594 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
595 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
596 } else {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
597 /*
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
598 * No other Features for Endpoint -
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
599 * Request Error
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
600 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
601 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
602 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
603 }
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
604 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
605
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
606 case GET_STATUS:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
607 /*
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
608 * Get Status Request to Endpoint should
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
609 * return Halt Status in D0 for Interrupt and Bulk
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
610 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
611 switch (setuppkt.wIndex & 0xFF) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
612 case 0x01:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
613 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
614 D12_ENDPOINT_EP1_OUT, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
615 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
616 case 0x81:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
617 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
618 D12_ENDPOINT_EP1_IN, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
619 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
620 case 0x02:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
621 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
622 D12_ENDPOINT_EP2_OUT, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
623 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
624 case 0x82:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
625 d12_read_cmd(D12_READ_ENDPOINT_STATUS + \
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
626 D12_ENDPOINT_EP2_IN, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
627 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
628 default: /* Invalid Endpoint -
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
629 * RequestError */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
630 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
631 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
632 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
633 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
634 if (buffer[0] & 0x08)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
635 buffer[0] = 0x01;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
636 else
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
637 buffer[0] = 0x00;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
638 buffer[1] = 0x00;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
639 d12_write_endpt(D12_ENDPOINT_EP0_IN, buffer, 2);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
640 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
641
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
642 default:
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
643 /* Unsupported - Request Error - Stall */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
644 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
645 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
646 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
647 }
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
648 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
649 case VENDOR_DEVICE_REQUEST:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
650 case VENDOR_ENDPOINT_REQUEST:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
651 switch (setuppkt.bRequest) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
652 case VENDOR_RESET:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
653 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
654 _delay_us(1000);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
655 /* disconnect from USB */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
656 buffer[0] = D12_MODE_0 & 0xef;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
657 buffer[1] = D12_MODE_1;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
658 d12_write_cmd(D12_SET_MODE, buffer, 2);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
659 _delay_us(1000);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
660 cli();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
661 reset();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
662 /* NOT REACHED */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
663 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
664
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
665 case VENDOR_UPDATE:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
666 d12_write_endpt(D12_ENDPOINT_EP0_IN, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
667 _delay_us(1000);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
668 /* disconnect from USB */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
669 buffer[0] = D12_MODE_0 & 0xef;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
670 buffer[1] = D12_MODE_1;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
671 d12_write_cmd(D12_SET_MODE, buffer, 2);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
672 _delay_us(1000);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
673 cli();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
674 bootloader();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
675 /* NOT REACHED */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
676 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
677
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
678 default:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
679 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
680 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
681 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
682 }
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
683 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
684 case VENDOR_INTERFACE_REQUEST:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
685 switch (setuppkt.bRequest) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
686 default:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
687 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
688 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
689 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
690 }
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
691 break;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
692 default:
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
693 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
694 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
695 break;
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 }
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
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
700 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
701 ** reset
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
702 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
703 ** Reset the micro by triggering the watchdog timer.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
704 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
705 */
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
706 void
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
707 reset(void) {
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
708 uart_putsP(PSTR("Resetting!\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
709 _delay_us(1000);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
710
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
711 /* Disable the interrupts */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
712 MCUCR = _BV(IVCE);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
713 MCUCR = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
714
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
715 /* Enable watchdog, smallest prescaler */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
716 WDTCR = _BV(WDE);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
717
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
718 /* Wait for oblivion! */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
719 for (;;)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
720 ;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
721 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
722
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
723 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
724 ** d12_getdescriptor
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
725 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
726 ** Handle returning the various descriptor to the host
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
727 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
728 ** Note: that we need to truncate the request because the host first
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
729 ** requests the first 2 bytes to find out then size, then requests the
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
730 ** rest.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
731 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
732 void
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
733 d12_getdescriptor(USB_SETUP_REQUEST *setuppkt) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
734 switch ((setuppkt->wValue & 0xff00) >> 8) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
735 case TYPE_DEVICE_DESCRIPTOR:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
736 sendbuffer0 = (const uint8_t *)&DeviceDescriptor;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
737 sendbytes0 = DeviceDescriptor.bLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
738 if (sendbytes0 >= setuppkt->wLength)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
739 sendbytes0 = setuppkt->wLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
740
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
741 d12_send_data_ep0();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
742 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
743
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
744 case TYPE_CONFIGURATION_DESCRIPTOR:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
745 sendbuffer0 = (const uint8_t *)&ConfigurationDescriptor;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
746 sendbytes0 = sizeof(ConfigurationDescriptor);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
747 if (sendbytes0 >= setuppkt->wLength)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
748 sendbytes0 = setuppkt->wLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
749
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
750 d12_send_data_ep0();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
751 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
752
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
753 case TYPE_STRING_DESCRIPTOR:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
754 switch (setuppkt->wValue & 0xFF) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
755 case 0:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
756 sendbuffer0 = (const uint8_t *)&LANGID_Descriptor;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
757 sendbytes0 = LANGID_Descriptor.bLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
758 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
759
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
760 case 1:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
761 sendbuffer0 = (const uint8_t *)&Manufacturer_Descriptor;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
762 sendbytes0 = Manufacturer_Descriptor.bLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
763 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
764
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
765 case 2:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
766 sendbuffer0 = (const uint8_t *)&Product_Descriptor;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
767 sendbytes0 = Product_Descriptor.bLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
768 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
769
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
770 case 3:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
771 sendbuffer0 = (const uint8_t *)&Serial_Descriptor;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
772 sendbytes0 = Serial_Descriptor.bLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
773 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
774
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
775 default:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
776 sendbuffer0 = NULL;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
777 sendbytes0 = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
778 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
779 if (sendbytes0 >= setuppkt->wLength)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
780 sendbytes0 = setuppkt->wLength;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
781
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
782 d12_send_data_ep0();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
783 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
784
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
785 default:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
786 d12_stallendpt(D12_ENDPOINT_EP0_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
787 d12_stallendpt(D12_ENDPOINT_EP0_OUT);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
788 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
789 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
790 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
791
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
792 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
793 ** d12_stallendpt
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
794 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
795 ** Stall the nominated endpoint.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
796 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
797 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
798 void
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
799 d12_stallendpt(uint8_t ep) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
800 uint8_t buffer[] = {0x01};
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
801
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
802 d12_write_cmd(D12_SET_ENDPOINT_STATUS + ep, buffer, 1);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
803 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
804
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
805 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
806 ** d12_read_cmd
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
807 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
808 ** Read data from the nominated endpoint if it's full.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
809 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
810 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
811 uint8_t
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
812 d12_read_endpt(uint8_t endpt, uint8_t *buffer) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
813 uint8_t d12header[2], status, i;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
814
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
815 d12header[1] = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
816
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
817 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
818 d12_read_cmd(endpt, &status, 1);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
819
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
820 /* Check if buffer is Full */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
821 if (status & 0x01) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
822 d12_set_cmd(D12_READ_BUFFER);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
823 d12header[0] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
824 d12header[1] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
825 if (d12header[1]) {
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
826 for (i = 0; i < d12header[1]; i++)
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
827 buffer[i] = d12_get_data();
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
828 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
829 /* Allow new packets to be accepted */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
830 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
831
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
832 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
833 return d12header[1];
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
834 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
835
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
836 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
837 ** d12_read_cmd
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
838 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
839 ** Write data to the nominated endpoint.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
840 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
841 */
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
842 void
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
843 d12_write_endpt(uint8_t endpt, const uint8_t *buffer, uint8_t bytes) {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
844 uint8_t status, i;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
845
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
846 /* Select Endpoint */
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
847 d12_read_cmd(endpt, &status, 1);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
848 if ((status & 0x01) != 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
849 uart_putsP(PSTR("Endpoint "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
850 uart_puts_dec(endpt / 2, 0);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
851 uart_putsP(PSTR(" IN is full..\r\n"));
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
852 return;
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
853 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
854
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
855 /* Write Header */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
856 d12_set_cmd(D12_WRITE_BUFFER);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
857 d12_set_data(0x00);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
858 d12_set_data(bytes);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
859 /* Write Packet */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
860 if (bytes) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
861 for (i = 0; i < bytes; i++)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
862 d12_set_data(buffer[i]);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
863 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
864 /* Validate buffer */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
865 d12_write_cmd(D12_VALIDATE_BUFFER, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
866 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
867
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
868 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
869 ** d12_send_data_ep0
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
870 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
871 ** Send the next FIFOs worth of data to the endpoint and update the
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
872 ** pointer and counters.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
873 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
874 ** d12_send_data_epX should be collapsed together but it's more
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
875 ** complex than it looks.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
876 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
877 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
878 void
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
879 d12_send_data_ep0(void) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
880 uint8_t status;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
881
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
882 /* Select endpoint */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
883 d12_read_cmd(D12_ENDPOINT_EP0_IN, &status, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
884
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
885 if (status & 0x01) /* Bail if the buffer is full */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
886 return;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
887
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
888 if (sendbytes0 == 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
889 /* Nothing to do */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
890 } else if (sendbytes0 >= EP0_FIFO_SZ) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
891 /* Write another EP0_FIFO_SZ Bytes to buffer and send */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
892 d12_write_endpt(D12_ENDPOINT_EP0_IN, sendbuffer0, EP0_FIFO_SZ);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
893 sendbuffer0 += EP0_FIFO_SZ;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
894 sendbytes0 -= EP0_FIFO_SZ;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
895 } else {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
896 /* Buffer must have less than EP0_FIFO_SZ bytes left */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
897 d12_write_endpt(D12_ENDPOINT_EP0_IN, sendbuffer0, sendbytes0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
898 sendbytes0 = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
899 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
900 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
901
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
902 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
903 ** d12_send_data_ep2
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
904 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
905 ** Send the next FIFOs worth of data to the endpoint and update the
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
906 ** pointer and counters.
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
907 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
908 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
909 void
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
910 d12_send_data_ep2(void) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
911 uint8_t status;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
912
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
913 /* Select endpoint */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
914 d12_read_cmd(D12_ENDPOINT_EP2_IN, &status, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
915
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
916 if (status & 0x01) /* Bail if the buffer is full */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
917 return;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
918
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
919 if (sendbytes2 == 0) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
920 /* Nothing to do */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
921 } else if (sendbytes2 >= EP2_FIFO_SZ) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
922 /* Write another EP2_FIFO_SZ Bytes to buffer and send */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
923 d12_write_endpt(D12_ENDPOINT_EP2_IN, sendbuffer2, EP2_FIFO_SZ);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
924 sendbuffer2 += EP2_FIFO_SZ;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
925 sendbytes2 -= EP2_FIFO_SZ;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
926 } else {
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
927 /* Buffer must have less than EP2_FIFO_SZ bytes left */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
928 d12_write_endpt(D12_ENDPOINT_EP2_IN, sendbuffer2, sendbytes2);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
929 sendbytes2 = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
930 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
931 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
932
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
933 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
934 ** d12_receive_data_ep2
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
935 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
936 ** Get the next FIFOs worth of data from the endpoint
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
937 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
938 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
939 void
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
940 d12_receive_data_ep2(void) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
941 uint8_t d12header[2], bytes, i, status;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
942
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
943 /* Select Endpoint */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
944 d12_read_cmd(D12_ENDPOINT_EP2_OUT, &status, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
945
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
946 if (!(status & 0x01)) /* Bail if the buffer is empty */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
947 return;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
948
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
949 /* Read header */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
950 d12_set_cmd(D12_READ_BUFFER);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
951 d12header[0] = d12_get_data();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
952 d12header[1] = d12_get_data();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
953 bytes = d12header[1];
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
954
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
955 packetlen2 = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
956
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
957 for (i = 0; i < bytes; i++)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
958 packet2[i] = d12_get_data();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
959
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
960 packetlen2 += bytes;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
961
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
962 /* Allow new packets to be accepted */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
963 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
964
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
965 uart_putsP(PSTR("Got "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
966 uart_puts_dec(bytes, 0);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
967 uart_putsP(PSTR(" bytes from the host\r\n"));
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
968
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
969 parsebuf(packet2, D12_ENDPOINT_EP2_IN);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
970
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
971 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
972
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
973 /*******************************************************************************
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
974 ** d12_receive_data_ep1
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
975 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
976 ** Get the next FIFOs worth of data from the endpoint
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
977 **
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
978 */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
979 void
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
980 d12_receive_data_ep1(void) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
981 uint8_t d12header[2], bytes, i, status;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
982
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
983 /* Select Endpoint */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
984 d12_read_cmd(D12_ENDPOINT_EP1_OUT, &status, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
985
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
986 /* Check if Buffer is Full */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
987 if (!(status & 0x01))
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
988 return;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
989
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
990 /* Read header */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
991 d12_set_cmd(D12_READ_BUFFER);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
992 d12header[0] = d12_get_data();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
993 d12header[1] = d12_get_data();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
994 bytes = d12header[1];
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
995
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
996 packetlen1 = 0;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
997
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
998 for (i = 0; i < bytes; i++)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
999 packet1[i] = d12_get_data();
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1000
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1001 packetlen1 += bytes;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1002
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1003 uart_putsP(PSTR("Got "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1004 uart_puts_dec(bytes, 0);
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1005 uart_putsP(PSTR(" bytes from the host\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1006
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1007 /* Allow new packets to be accepted */
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1008 d12_write_cmd(D12_CLEAR_BUFFER, NULL, 0);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1009
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1010 parsebuf(packet1, D12_ENDPOINT_EP1_IN);
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1011 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1012
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1013 void
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1014 parsebuf(uint8_t *buffer, uint8_t ep) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1015 int i;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1016
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1017 switch (buffer[0]) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1018 case 0x00:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1019 uart_putsP(PSTR("OWTouchReset()\r\n"));
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
1020 buffer[0] = OWTouchReset();
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1021 d12_write_endpt(ep, buffer, 1);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1022 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1023
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1024 case 0x01:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1025 uart_putsP(PSTR("OWFirst()\r\n"));
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
1026 buffer[0] = OWFirst(&buffer[1], 1, 0);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1027 for (i = 0; i < 9; i++) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1028 uart_puts_hex(buffer[i + 1]);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1029 uart_putsP(PSTR(" "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1030 }
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1031 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1032 d12_write_endpt(ep, buffer, 9);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1033 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1034
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1035 case 0x02:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1036 uart_putsP(PSTR("OWNext()\r\n"));
35
fed32b382de2 Tidy up, hide details behind macros to make it more obvious what we
darius
parents: 31
diff changeset
1037 buffer[0] = OWNext(&buffer[1], 1, 0);
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1038 d12_write_endpt(ep, buffer, 9);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1039 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1040
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1041 case 0x03:
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1042 uart_putsP(PSTR(" bytes, asked to do temperature conversion for "));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1043 for (i = 0; i < 8; i++) {
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1044 uart_puts_hex(buffer[i + 1]);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1045 if (i != 7)
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1046 uart_putsP(PSTR(":"));
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1047 }
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1048
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1049 uart_putsP(PSTR("\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1050 d12_write_endpt(ep, buffer, 9);
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1051
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1052 break;
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1053
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1054 default:
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 35
diff changeset
1055 uart_putsP(PSTR("Unknown command on endpoint 1\r\n"));
31
4e417d84365e - Rename some more functions to be consistent.
darius
parents: 26
diff changeset
1056 break;
23
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1057 }
845934a4e7fe Add code to talk to a Phillips PDIUSBB12.
darius
parents:
diff changeset
1058 }