Removed complicated logic for the Endpoint_ConfigureEndpoint() function to use inline...
[pub/USBasp.git] / Projects / Incomplete / StandaloneProgrammer / DiskDevice.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 "DiskDevice.h"
32
33 #if defined(USB_CAN_BE_DEVICE)
34 /** LUFA Mass Storage Class driver interface configuration and state information. This structure is
35 * passed to all Mass Storage Class driver functions, so that multiple instances of the same class
36 * within a device can be differentiated from one another.
37 */
38 USB_ClassInfo_MS_Device_t DiskDevice_MS_Interface =
39 {
40 .Config =
41 {
42 .InterfaceNumber = 0,
43
44 .DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
45 .DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
46 .DataINEndpointDoubleBank = false,
47
48 .DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
49 .DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
50 .DataOUTEndpointDoubleBank = false,
51
52 .TotalLUNs = 1,
53 },
54 };
55
56 void DiskDevice_USBTask(void)
57 {
58 MS_Device_USBTask(&DiskDevice_MS_Interface);
59 }
60
61 /** Event handler for the library USB Connection event. */
62 void EVENT_USB_Device_Connect(void)
63 {
64 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
65 }
66
67 /** Event handler for the library USB Disconnection event. */
68 void EVENT_USB_Device_Disconnect(void)
69 {
70 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
71 }
72
73 /** Event handler for the library USB Configuration Changed event. */
74 void EVENT_USB_Device_ConfigurationChanged(void)
75 {
76 bool ConfigSuccess = true;
77
78 ConfigSuccess &= MS_Device_ConfigureEndpoints(&DiskDevice_MS_Interface);
79
80 LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
81 }
82
83 /** Event handler for the library USB Unhandled Control Request event. */
84 void EVENT_USB_Device_UnhandledControlRequest(void)
85 {
86 MS_Device_ProcessControlRequest(&DiskDevice_MS_Interface);
87 }
88
89 /** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
90 *
91 * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
92 */
93 bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
94 {
95 bool CommandSuccess;
96
97 LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
98 CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
99 LEDs_SetAllLEDs(LEDMASK_USB_READY);
100
101 return CommandSuccess;
102 }
103 #endif