3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 "MassStorage.h"
33 USB_ClassInfo_MS_t Disk_MS_Interface
=
37 .DataINEndpointNumber
= MASS_STORAGE_IN_EPNUM
,
38 .DataINEndpointSize
= MASS_STORAGE_IO_EPSIZE
,
40 .DataOUTEndpointNumber
= MASS_STORAGE_OUT_EPNUM
,
41 .DataOUTEndpointSize
= MASS_STORAGE_IO_EPSIZE
,
43 .TotalLUNs
= TOTAL_LUNS
,
50 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
54 USB_MS_USBTask(&Disk_MS_Interface
);
59 void SetupHardware(void)
61 /* Disable watchdog if enabled by bootloader/fuses */
62 MCUSR
&= ~(1 << WDRF
);
65 /* Disable clock division */
66 clock_prescale_set(clock_div_1
);
68 /* Hardware Initialization */
70 Dataflash_Init(SPI_SPEED_FCPU_DIV_2
);
73 /* Clear Dataflash sector protections, if enabled */
74 DataflashManager_ResetDataflashProtections();
77 void EVENT_USB_Connect(void)
79 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
82 void EVENT_USB_Disconnect(void)
84 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
87 void EVENT_USB_ConfigurationChanged(void)
89 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
91 if (!(USB_MS_ConfigureEndpoints(&Disk_MS_Interface
)))
92 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
95 void EVENT_USB_UnhandledControlPacket(void)
97 USB_MS_ProcessControlPacket(&Disk_MS_Interface
);
100 bool CALLBACK_USB_MS_SCSICommandReceived(USB_ClassInfo_MS_t
* MSInterfaceInfo
)
104 LEDs_SetAllLEDs(LEDMASK_USB_BUSY
);
105 CommandSuccess
= SCSI_DecodeSCSICommand(MSInterfaceInfo
);
106 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
108 return CommandSuccess
;