Added start of a low level device Test and Measurement class demo (thanks to Peter...
[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 /** Main program entry point. This routine contains the overall program flow, including initial
34 * setup of all components and the main program loop.
35 */
36 int main(void)
37 {
38 SetupHardware();
39
40 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
41 sei();
42
43 for (;;)
44 {
45 TMC_Task();
46 USB_USBTask();
47 }
48 }
49
50 /** Configures the board hardware and chip peripherals for the demo's functionality. */
51 void SetupHardware(void)
52 {
53 /* Disable watchdog if enabled by bootloader/fuses */
54 MCUSR &= ~(1 << WDRF);
55 wdt_disable();
56
57 /* Disable clock division */
58 clock_prescale_set(clock_div_1);
59
60 /* Hardware Initialization */
61 LEDs_Init();
62 USB_Init();
63 }
64
65 void EVENT_USB_Device_Connect(void)
66 {
67 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
68 }
69
70 void EVENT_USB_Device_Disconnect(void)
71 {
72 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
73 }
74
75 void EVENT_USB_Device_ConfigurationChanged(void)
76 {
77 LEDs_SetAllLEDs(LEDMASK_USB_READY);
78
79 /* Setup TMC In and Out Endpoints */
80 if (!(Endpoint_ConfigureEndpoint(TMC_IN_EPNUM, EP_TYPE_BULK,
81 ENDPOINT_DIR_IN, TMC_IO_EPSIZE,
82 ENDPOINT_BANK_SINGLE)))
83 {
84 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
85 }
86
87 if (!(Endpoint_ConfigureEndpoint(TMC_OUT_EPNUM, EP_TYPE_BULK,
88 ENDPOINT_DIR_OUT, TMC_IO_EPSIZE,
89 ENDPOINT_BANK_SINGLE)))
90 {
91 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
92 }
93 }
94
95 void EVENT_USB_Device_UnhandledControlRequest(void)
96 {
97 switch (USB_ControlRequest.bRequest)
98 {
99 case Req_InitiateAbortBulkOut:
100 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
101 {
102
103 }
104
105 break;
106 case Req_CheckAbortBulkOutStatus:
107 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
108 {
109
110 }
111
112 break;
113 case Req_InitiateAbortBulkIn:
114 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
115 {
116
117 }
118
119 break;
120 case Req_CheckAbortBulkInStatus:
121 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
122 {
123
124 }
125
126 break;
127 case Req_InitiateClear:
128 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
129 {
130
131 }
132
133 break;
134 case Req_CheckClearStatus:
135 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
136 {
137
138 }
139
140 break;
141 case Req_GetCapabilities:
142 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
143 {
144
145 }
146
147 break;
148 }
149 }
150
151 void TMC_Task(void)
152 {
153 /* Device must be connected and configured for the task to run */
154 if (USB_DeviceState != DEVICE_STATE_Configured)
155 return;
156 }