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 /** Main program entry point. This routine contains the overall program flow, including initial 
  54  *  setup of all components and the main program loop. 
  60         LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
); 
  69 /** Configures the board hardware and chip peripherals for the demo's functionality. */ 
  70 void SetupHardware(void) 
  72         /* Disable watchdog if enabled by bootloader/fuses */ 
  73         MCUSR 
&= ~(1 << WDRF
); 
  76         /* Disable clock division */ 
  77         clock_prescale_set(clock_div_1
); 
  79         /* Hardware Initialization */ 
  82         SerialStream_Init(9600, false); 
  85 void EVENT_USB_Device_Connect(void) 
  87         LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
); 
  90 void EVENT_USB_Device_Disconnect(void) 
  92         LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
); 
  95 void EVENT_USB_Device_ConfigurationChanged(void) 
  97         LEDs_SetAllLEDs(LEDMASK_USB_READY
); 
  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
))) 
 104                 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
); 
 107         if (!(Endpoint_ConfigureEndpoint(SIDESHOW_OUT_EPNUM
, EP_TYPE_BULK
, 
 108                                              ENDPOINT_DIR_OUT
, SIDESHOW_IO_EPSIZE
, 
 109                                          ENDPOINT_BANK_SINGLE
))) 
 111                 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
); 
 115 void EVENT_USB_Device_UnhandledControlRequest(void) 
 117         /* Process UFI specific control requests */ 
 118         switch (USB_ControlRequest
.bRequest
) 
 120                 case REQ_GetOSFeatureDescriptor
: 
 121                         if (USB_ControlRequest
.bmRequestType 
== (REQDIR_DEVICETOHOST 
| REQTYPE_VENDOR 
| REQREC_DEVICE
)) 
 123                                 void*    DescriptorPointer
; 
 124                                 uint16_t DescriptorSize
; 
 126                                 if (!(USB_GetOSFeatureDescriptor(USB_ControlRequest
.wValue
, USB_ControlRequest
.wIndex
, 
 127                                                                  &DescriptorPointer
, &DescriptorSize
))) 
 132                                 Endpoint_ClearSETUP(); 
 134                                 Endpoint_Write_Control_PStream_LE(DescriptorPointer
, DescriptorSize
); 
 142 void SideShow_Task(void) 
 144         /* Device must be connected and configured for the task to run */ 
 145         if (USB_DeviceState 
!= DEVICE_STATE_Configured
) 
 148         /* Select the SideShow data out endpoint */ 
 149         Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM
); 
 151         /* Check to see if a new SideShow message has been received */ 
 152         if (Endpoint_IsReadWriteAllowed()) 
 154                 /* Process the received SideShow message */ 
 155                 Sideshow_ProcessCommandPacket();