Fix MIT license language to make its intent clearer.
[pub/USBasp.git] / Demos / Device / Incomplete / Sideshow / Sideshow.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /*
32 SideShow Class demonstration application. This give a reference
33 for implementing Microsoft SideShow compatible devices in an
34 embedded environment. SideShow allows for gadget data displayed
35 on a Windows Vista or later machine to also be displayed on an
36 externally connected interactive display. Upon enumeration, this will
37 appear as a new SideShow device which can have gadgets loaded onto
38 it.
39
40 Note that while the incoming content is buffered in packet struct
41 form, the data is not actually displayed. It is left to the user to
42 write sufficient code to read out the packed data for display to a
43 screen.
44
45 Installed gadgets can be accessed through the InstalledApplications
46 array, with entries that have their InUse flag set being active. As
47 only the active content is displayed on the device due to memory
48 constraints, new content can be requested as needed.
49 */
50
51 #include "Sideshow.h"
52
53 /** Main program entry point. This routine contains the overall program flow, including initial
54 * setup of all components and the main program loop.
55 */
56 int main(void)
57 {
58 SetupHardware();
59
60 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
61
62 for (;;)
63 {
64 SideShow_Task();
65 USB_USBTask();
66 }
67 }
68
69 /** Configures the board hardware and chip peripherals for the demo's functionality. */
70 void SetupHardware(void)
71 {
72 /* Disable watchdog if enabled by bootloader/fuses */
73 MCUSR &= ~(1 << WDRF);
74 wdt_disable();
75
76 /* Disable clock division */
77 clock_prescale_set(clock_div_1);
78
79 /* Hardware Initialization */
80 LEDs_Init();
81 USB_Init();
82 SerialStream_Init(9600, false);
83 }
84
85 void EVENT_USB_Device_Connect(void)
86 {
87 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
88 }
89
90 void EVENT_USB_Device_Disconnect(void)
91 {
92 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
93 }
94
95 void EVENT_USB_Device_ConfigurationChanged(void)
96 {
97 LEDs_SetAllLEDs(LEDMASK_USB_READY);
98
99 /* Setup Sideshow In and Out Endpoints */
100 if (!(Endpoint_ConfigureEndpoint(SIDESHOW_IN_EPNUM, EP_TYPE_BULK,
101 ENDPOINT_DIR_IN, SIDESHOW_IO_EPSIZE,
102 ENDPOINT_BANK_SINGLE)))
103 {
104 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
105 }
106
107 if (!(Endpoint_ConfigureEndpoint(SIDESHOW_OUT_EPNUM, EP_TYPE_BULK,
108 ENDPOINT_DIR_OUT, SIDESHOW_IO_EPSIZE,
109 ENDPOINT_BANK_SINGLE)))
110 {
111 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
112 }
113 }
114
115 void EVENT_USB_Device_UnhandledControlRequest(void)
116 {
117 /* Process UFI specific control requests */
118 switch (USB_ControlRequest.bRequest)
119 {
120 case REQ_GetOSFeatureDescriptor:
121 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE))
122 {
123 void* DescriptorPointer;
124 uint16_t DescriptorSize;
125
126 if (!(USB_GetOSFeatureDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex,
127 &DescriptorPointer, &DescriptorSize)))
128 {
129 return;
130 }
131
132 Endpoint_ClearSETUP();
133
134 Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);
135 Endpoint_ClearOUT();
136 }
137
138 break;
139 }
140 }
141
142 void SideShow_Task(void)
143 {
144 /* Device must be connected and configured for the task to run */
145 if (USB_DeviceState != DEVICE_STATE_Configured)
146 return;
147
148 /* Select the SideShow data out endpoint */
149 Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM);
150
151 /* Check to see if a new SideShow message has been received */
152 if (Endpoint_IsReadWriteAllowed())
153 {
154 /* Process the received SideShow message */
155 Sideshow_ProcessCommandPacket();
156 }
157 }