Add TMC device capabilities to the incomplete TMC demo.
[pub/USBasp.git] / Demos / Device / Incomplete / TestAndMeasurement / TestAndMeasurement.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
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 #include "TestAndMeasurement.h"
32
33 /** Contains the (usually static) capabilities of the TMC device. This table is requested by the
34 * host upon enumeration to give it information on what features of the Test and Measurement USB
35 * Class the device supports.
36 */
37 TMC_Capabilities_t Capabilities =
38 {
39 .Status = TMC_REQUEST_STATUS_SUCCESS,
40 .TMCVersion = VERSION_BCD(1.00),
41
42 .Interface =
43 {
44 .ListenOnly = false,
45 .TalkOnly = false,
46 .PulseIndicateSupported = true,
47 },
48
49 .Device =
50 {
51 .SupportsAbortINOnMatch = false,
52 },
53 };
54
55
56 /** Main program entry point. This routine contains the overall program flow, including initial
57 * setup of all components and the main program loop.
58 */
59 int main(void)
60 {
61 SetupHardware();
62
63 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
64 sei();
65
66 for (;;)
67 {
68 TMC_Task();
69 USB_USBTask();
70 }
71 }
72
73 /** Configures the board hardware and chip peripherals for the demo's functionality. */
74 void SetupHardware(void)
75 {
76 /* Disable watchdog if enabled by bootloader/fuses */
77 MCUSR &= ~(1 << WDRF);
78 wdt_disable();
79
80 /* Disable clock division */
81 clock_prescale_set(clock_div_1);
82
83 /* Hardware Initialization */
84 LEDs_Init();
85 USB_Init();
86 }
87
88 void EVENT_USB_Device_Connect(void)
89 {
90 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
91 }
92
93 void EVENT_USB_Device_Disconnect(void)
94 {
95 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
96 }
97
98 void EVENT_USB_Device_ConfigurationChanged(void)
99 {
100 LEDs_SetAllLEDs(LEDMASK_USB_READY);
101
102 /* Setup TMC In and Out Endpoints */
103 if (!(Endpoint_ConfigureEndpoint(TMC_IN_EPNUM, EP_TYPE_BULK,
104 ENDPOINT_DIR_IN, TMC_IO_EPSIZE,
105 ENDPOINT_BANK_SINGLE)))
106 {
107 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
108 }
109
110 if (!(Endpoint_ConfigureEndpoint(TMC_OUT_EPNUM, EP_TYPE_BULK,
111 ENDPOINT_DIR_OUT, TMC_IO_EPSIZE,
112 ENDPOINT_BANK_SINGLE)))
113 {
114 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
115 }
116 }
117
118 void EVENT_USB_Device_UnhandledControlRequest(void)
119 {
120 switch (USB_ControlRequest.bRequest)
121 {
122 case Req_InitiateAbortBulkOut:
123 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
124 {
125
126 }
127
128 break;
129 case Req_CheckAbortBulkOutStatus:
130 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
131 {
132
133 }
134
135 break;
136 case Req_InitiateAbortBulkIn:
137 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
138 {
139
140 }
141
142 break;
143 case Req_CheckAbortBulkInStatus:
144 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
145 {
146
147 }
148
149 break;
150 case Req_InitiateClear:
151 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
152 {
153
154 }
155
156 break;
157 case Req_CheckClearStatus:
158 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
159 {
160
161 }
162
163 break;
164 case Req_GetCapabilities:
165 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
166 {
167 /* Acknowledge the SETUP packet, ready for data transfer */
168 Endpoint_ClearSETUP();
169
170 /* Write the device capabilities to the control endpoint */
171 Endpoint_Write_Control_Stream_LE(&Capabilities, sizeof(TMC_Capabilities_t));
172
173 /* Finalize the stream transfer to send the last packet or clear the host abort */
174 Endpoint_ClearOUT();
175 }
176
177 break;
178 }
179 }
180
181 void TMC_Task(void)
182 {
183 /* Device must be connected and configured for the task to run */
184 if (USB_DeviceState != DEVICE_STATE_Configured)
185 return;
186
187 Endpoint_SelectEndpoint(TMC_OUT_EPNUM);
188
189 if (Endpoint_IsOUTReceived())
190 {
191 // TEMP - Indicate data received
192 LEDs_SetAllLEDs(LEDS_ALL_LEDS);
193 Endpoint_ClearOUT();
194 }
195 }