3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
31 #include "TestAndMeasurement.h"
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.
37 TMC_Capabilities_t Capabilities
=
39 .Status
= TMC_REQUEST_STATUS_SUCCESS
,
40 .TMCVersion
= VERSION_BCD(1.00),
46 .PulseIndicateSupported
= true,
51 .SupportsAbortINOnMatch
= false,
56 /** Main program entry point. This routine contains the overall program flow, including initial
57 * setup of all components and the main program loop.
63 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
73 /** Configures the board hardware and chip peripherals for the demo's functionality. */
74 void SetupHardware(void)
76 /* Disable watchdog if enabled by bootloader/fuses */
77 MCUSR
&= ~(1 << WDRF
);
80 /* Disable clock division */
81 clock_prescale_set(clock_div_1
);
83 /* Hardware Initialization */
88 void EVENT_USB_Device_Connect(void)
90 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
93 void EVENT_USB_Device_Disconnect(void)
95 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
98 void EVENT_USB_Device_ConfigurationChanged(void)
100 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
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
)))
107 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
110 if (!(Endpoint_ConfigureEndpoint(TMC_OUT_EPNUM
, EP_TYPE_BULK
,
111 ENDPOINT_DIR_OUT
, TMC_IO_EPSIZE
,
112 ENDPOINT_BANK_SINGLE
)))
114 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
118 void EVENT_USB_Device_UnhandledControlRequest(void)
120 switch (USB_ControlRequest
.bRequest
)
122 case Req_InitiateAbortBulkOut
:
123 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_ENDPOINT
))
129 case Req_CheckAbortBulkOutStatus
:
130 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_ENDPOINT
))
136 case Req_InitiateAbortBulkIn
:
137 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_ENDPOINT
))
143 case Req_CheckAbortBulkInStatus
:
144 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_ENDPOINT
))
150 case Req_InitiateClear
:
151 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
))
157 case Req_CheckClearStatus
:
158 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
))
164 case Req_GetCapabilities
:
165 if (USB_ControlRequest
.bmRequestType
== (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
))
167 /* Acknowledge the SETUP packet, ready for data transfer */
168 Endpoint_ClearSETUP();
170 /* Write the device capabilities to the control endpoint */
171 Endpoint_Write_Control_Stream_LE(&Capabilities
, sizeof(TMC_Capabilities_t
));
173 /* Finalize the stream transfer to send the last packet or clear the host abort */
183 /* Device must be connected and configured for the task to run */
184 if (USB_DeviceState
!= DEVICE_STATE_Configured
)
187 Endpoint_SelectEndpoint(TMC_OUT_EPNUM
);
189 if (Endpoint_IsOUTReceived())
191 // TEMP - Indicate data received
192 LEDs_SetAllLEDs(LEDS_ALL_LEDS
);