Added standard keyboard HID report scancode defines (thanks to László Monda).
[pub/USBasp.git] / Demos / Device / Incomplete / Sideshow / Sideshow.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2010 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 sei();
62
63 for (;;)
64 {
65 SideShow_Task();
66 USB_USBTask();
67 }
68 }
69
70 /** Configures the board hardware and chip peripherals for the demo's functionality. */
71 void SetupHardware(void)
72 {
73 /* Disable watchdog if enabled by bootloader/fuses */
74 MCUSR &= ~(1 << WDRF);
75 wdt_disable();
76
77 /* Disable clock division */
78 clock_prescale_set(clock_div_1);
79
80 /* Hardware Initialization */
81 LEDs_Init();
82 USB_Init();
83 SerialStream_Init(9600, false);
84 }
85
86 void EVENT_USB_Device_Connect(void)
87 {
88 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
89 }
90
91 void EVENT_USB_Device_Disconnect(void)
92 {
93 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
94 }
95
96 void EVENT_USB_Device_ConfigurationChanged(void)
97 {
98 bool ConfigSuccess = true;
99
100 /* Setup Sideshow Data Endpoints */
101 ConfigSuccess &= Endpoint_ConfigureEndpoint(SIDESHOW_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
102 SIDESHOW_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
103 ConfigSuccess &= Endpoint_ConfigureEndpoint(SIDESHOW_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
104 SIDESHOW_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
105
106 /* Indicate endpoint configuration success or failure */
107 LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
108 }
109
110 void EVENT_USB_Device_UnhandledControlRequest(void)
111 {
112 switch (USB_ControlRequest.bRequest)
113 {
114 case REQ_GetOSFeatureDescriptor:
115 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE))
116 {
117 const void* DescriptorPointer;
118 uint16_t DescriptorSize = USB_GetOSFeatureDescriptor(USB_ControlRequest.wValue,
119 USB_ControlRequest.wIndex,
120 &DescriptorPointer);
121
122 if (DescriptorSize == NO_DESCRIPTOR)
123 return;
124
125 Endpoint_ClearSETUP();
126
127 Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);
128 Endpoint_ClearOUT();
129 }
130
131 break;
132 }
133 }
134
135 void SideShow_Task(void)
136 {
137 /* Device must be connected and configured for the task to run */
138 if (USB_DeviceState != DEVICE_STATE_Configured)
139 return;
140
141 /* Select the SideShow data out endpoint */
142 Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM);
143
144 /* Check to see if a new SideShow message has been received */
145 if (Endpoint_IsReadWriteAllowed())
146 {
147 /* Process the received SideShow message */
148 Sideshow_ProcessCommandPacket();
149 }
150 }
151