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