3      Copyright (C) Dean Camera, 2011. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2011  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 "DiskDevice.h" 
  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. 
  38 USB_ClassInfo_MS_Device_t DiskDevice_MS_Interface 
= 
  44                                 .DataINEndpointNumber      
= MASS_STORAGE_IN_EPNUM
, 
  45                                 .DataINEndpointSize        
= MASS_STORAGE_IO_EPSIZE
, 
  46                                 .DataINEndpointDoubleBank  
= false, 
  48                                 .DataOUTEndpointNumber     
= MASS_STORAGE_OUT_EPNUM
, 
  49                                 .DataOUTEndpointSize       
= MASS_STORAGE_IO_EPSIZE
, 
  50                                 .DataOUTEndpointDoubleBank 
= false, 
  57 void DiskDevice_USBTask(void) 
  59         MS_Device_USBTask(&DiskDevice_MS_Interface
); 
  62 /** Event handler for the library USB Connection event. */ 
  63 void EVENT_USB_Device_Connect(void) 
  65         LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
); 
  68 /** Event handler for the library USB Disconnection event. */ 
  69 void EVENT_USB_Device_Disconnect(void) 
  71         LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
); 
  74 /** Event handler for the library USB Configuration Changed event. */ 
  75 void EVENT_USB_Device_ConfigurationChanged(void) 
  77         bool ConfigSuccess 
= true; 
  79         ConfigSuccess 
&= MS_Device_ConfigureEndpoints(&DiskDevice_MS_Interface
); 
  81         LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY 
: LEDMASK_USB_ERROR
); 
  84 /** Event handler for the library USB Control Request reception event. */ 
  85 void EVENT_USB_Device_ControlRequest(void) 
  87         MS_Device_ProcessControlRequest(&DiskDevice_MS_Interface
); 
  90 /** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed. 
  92  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface configuration structure being referenced 
  94 bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t
* const MSInterfaceInfo
) 
  98         LEDs_SetAllLEDs(LEDMASK_USB_BUSY
); 
  99         CommandSuccess 
= SCSI_DecodeSCSICommand(MSInterfaceInfo
); 
 100         LEDs_SetAllLEDs(LEDMASK_USB_READY
); 
 102         return CommandSuccess
;