3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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.
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
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 Vista machine to also be displayed on an externally connected
36 interactive display. Upon enumeration on a Vista system, this will
37 appear as a new SideShow device which can have gadgets loaded onto
40 Note that while the incomming 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
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.
53 USB Class: Sideshow Device (Microsoft Only)
54 USB Subclass: Bulk Only
55 Relevant Standards: Microsoft Sideshow Specification
56 Microsoft OS Descriptors Specification
58 Usable Speeds: Full Speed Mode
63 /* Project Tags, for reading out using the ButtLoad project */
64 BUTTLOADTAG(ProjName
, "LUFA Sideshow App");
65 BUTTLOADTAG(BuildTime
, __TIME__
);
66 BUTTLOADTAG(BuildDate
, __DATE__
);
67 BUTTLOADTAG(LUFAVersion
, "LUFA V" LUFA_VERSION_STRING
);
69 /* Scheduler Task List */
72 { Task
: USB_USBTask
, TaskStatus
: TASK_STOP
},
73 { Task
: USB_Sideshow
, TaskStatus
: TASK_STOP
},
78 /* Disable watchdog if enabled by bootloader/fuses */
79 MCUSR
&= ~(1 << WDRF
);
82 /* Disable Clock Division */
83 SetSystemClockPrescaler(0);
85 /* Hardware Initialization */
86 SerialStream_Init(9600, false);
90 /* Indicate USB not ready */
91 LEDs_SetAllLEDs(LEDS_LED1
| LEDS_LED3
);
93 /* Initialize Scheduler so that it can be used */
96 /* Initialize USB Subsystem */
99 /* Scheduling - routine never returns, so put this last in the main function */
103 EVENT_HANDLER(USB_Connect
)
105 /* Start USB management task */
106 Scheduler_SetTaskMode(USB_USBTask
, TASK_RUN
);
108 /* Indicate USB enumerating */
109 LEDs_SetAllLEDs(LEDS_LED1
| LEDS_LED4
);
112 EVENT_HANDLER(USB_Disconnect
)
114 /* Stop running mass storage and USB management tasks */
115 Scheduler_SetTaskMode(USB_Sideshow
, TASK_STOP
);
116 Scheduler_SetTaskMode(USB_USBTask
, TASK_STOP
);
118 /* Indicate USB not ready */
119 LEDs_SetAllLEDs(LEDS_LED1
| LEDS_LED3
);
122 EVENT_HANDLER(USB_ConfigurationChanged
)
124 /* Setup Sideshow In and Out Endpoints */
125 Endpoint_ConfigureEndpoint(SIDESHOW_IN_EPNUM
, EP_TYPE_BULK
,
126 ENDPOINT_DIR_IN
, SIDESHOW_IO_EPSIZE
,
127 ENDPOINT_BANK_SINGLE
);
129 Endpoint_ConfigureEndpoint(SIDESHOW_OUT_EPNUM
, EP_TYPE_BULK
,
130 ENDPOINT_DIR_OUT
, SIDESHOW_IO_EPSIZE
,
131 ENDPOINT_BANK_SINGLE
);
133 /* Indicate USB connected and ready */
134 LEDs_SetAllLEDs(LEDS_LED2
| LEDS_LED4
);
136 /* Start Sideshow task */
137 Scheduler_SetTaskMode(USB_Sideshow
, TASK_RUN
);
140 EVENT_HANDLER(USB_UnhandledControlPacket
)
142 /* Process UFI specific control requests */
145 case REQ_GetOSFeatureDescriptor
:
146 if (bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_VENDOR
| REQREC_DEVICE
))
148 uint16_t wValue
= Endpoint_Read_Word_LE();
149 uint16_t wIndex
= Endpoint_Read_Word_LE();
150 uint16_t wLength
= Endpoint_Read_Word_LE();
152 void* DescriptorPointer
;
153 uint16_t DescriptorSize
;
157 if (!(USB_GetOSFeatureDescriptor(wValue
, wIndex
, &DescriptorPointer
, &DescriptorSize
)))
160 Endpoint_ClearSetupReceived();
162 if (wLength
> DescriptorSize
)
163 wLength
= DescriptorSize
;
165 while (wLength
&& (!(Endpoint_IsSetupOUTReceived())))
167 while (!(Endpoint_IsSetupINReady()));
169 while (wLength
&& (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize
))
171 #if defined(USE_RAM_DESCRIPTORS)
172 Endpoint_Write_Byte(*((uint8_t*)DescriptorPointer
++));
173 #elif defined (USE_EEPROM_DESCRIPTORS)
174 Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer
++));
176 Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer
++));
182 SendZLP
= (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize
);
183 Endpoint_ClearSetupIN();
186 if (Endpoint_IsSetupOUTReceived())
188 Endpoint_ClearSetupOUT();
194 while (!(Endpoint_IsSetupINReady()));
195 Endpoint_ClearSetupIN();
198 while (!(Endpoint_IsSetupOUTReceived()));
199 Endpoint_ClearSetupOUT();
208 /* Check if the USB System is connected to a Host */
211 /* Select the SideShow data out endpoint */
212 Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM
);
214 /* Check to see if a new SideShow message has been received */
215 if (Endpoint_ReadWriteAllowed())
217 /* Process the received SideShow message */
218 Sideshow_ProcessCommandPacket();