aura  0.1
 All Data Structures Functions Variables Modules Pages
main.c
1 #include <arch/antares.h>
2 #include <avr/boot.h>
3 #include <avr/io.h>
4 #include <avr/interrupt.h>
5 #include <util/delay.h>
6 #include <generated/usbconfig.h>
7 #include <arch/vusb/usbportability.h>
8 #include <arch/vusb/usbdrv.h>
9 
10 #include <lib/light_ws2812.h>
11 
12 unsigned char iobuf[16];
13 struct cRGB target[2] = {
14  { 0xff, 0, 0 },
15  { 0xff, 0, 0 }
16 };
17 
18 struct cRGB current[2] = {
19  { 0x00, 0xff, 0 },
20  { 0x00, 0xff, 0 }
21 };
22 
23 
24 uchar usbFunctionSetup(uchar data[8])
25 {
26  usbRequest_t *rq = (void *)data;
27  switch (rq->bRequest) {
28  case 0:
29  target[0].r=rq->wValue.bytes[0];
30  target[0].g=rq->wValue.bytes[1];
31  target[0].b=rq->wValue.bytes[2];
32  ws2812_setleds(&target, 2);
33  break;
34  case 1:
35  ws2812_setleds(&target, 2);
36  _delay_ms(rq->wValue.word);
37  ws2812_setleds(&current, 2);
38  break;
39  case 2: {
40  usbMsgPtr = iobuf;
41  return 8;
42  }
43  case 3:
44  return USB_NO_MSG;
45  }
46 
47  return 0;
48 }
49 
50 uchar usbFunctionWrite(uchar *data, uchar len)
51 {
52  memcpy(iobuf, data, len);
53  return 1;
54 }
55 
56 inline void usbReconnect()
57 {
58  DDRD=0xff;
59  _delay_ms(250);
60  DDRD=0;
61 }
62 
63 ANTARES_INIT_LOW(io_init)
64 {
65  DDRC=1<<2;
66  PORTC=0xff;
67  usbReconnect();
68 }
69 
70 ANTARES_INIT_HIGH(uinit)
71 {
72  usbInit();
73 }
74 
75 
76 ANTARES_APP(usb_app)
77 {
78  while (1) {
79  usbPoll();
80  }
81 }