From cf4575b94a3c65e6535a159fc71fc885aebc2620 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Aug 2019 14:02:40 -0700 Subject: Fix the LUFA lib to use a submodule instead of just files (#6245) * Remove LUFA files * Update descriptions for newer version of LUFA * Create PR6245.md * Fix CDC(Serial) type errors * Fix missed merge conflict for AUDIO_DTYPE_CSInterface --- .../MassStorageKeyboard/Config/AppConfig.h | 50 - .../MassStorageKeyboard/Config/LUFAConfig.h | 126 - .../ClassDriver/MassStorageKeyboard/Descriptors.c | 254 --- .../ClassDriver/MassStorageKeyboard/Descriptors.h | 111 - .../MassStorageKeyboard/Lib/DataflashManager.c | 534 ----- .../MassStorageKeyboard/Lib/DataflashManager.h | 87 - .../ClassDriver/MassStorageKeyboard/Lib/SCSI.c | 349 --- .../ClassDriver/MassStorageKeyboard/Lib/SCSI.h | 89 - .../MassStorageKeyboard/MassStorageKeyboard.c | 270 --- .../MassStorageKeyboard/MassStorageKeyboard.h | 100 - .../MassStorageKeyboard/MassStorageKeyboard.txt | 100 - .../Device/ClassDriver/MassStorageKeyboard/asf.xml | 70 - .../ClassDriver/MassStorageKeyboard/doxyfile | 2395 -------------------- .../ClassDriver/MassStorageKeyboard/makefile | 43 - 14 files changed, 4578 deletions(-) delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/AppConfig.h delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.h delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.c delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.h delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.c delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.h delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.h delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.txt delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/asf.xml delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/doxyfile delete mode 100644 lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/makefile (limited to 'lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard') diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/AppConfig.h b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/AppConfig.h deleted file mode 100644 index b18b2c4149..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/AppConfig.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief Application Configuration Header File - * - * This is a header file which is be used to configure some of - * the application's compile time options, as an alternative to - * specifying the compile time constants supplied through a - * makefile or build system. - * - * For information on what each token does, refer to the - * \ref Sec_Options section of the application documentation. - */ - -#ifndef _APP_CONFIG_H_ -#define _APP_CONFIG_H_ - - #define TOTAL_LUNS 1 - - #define DISK_READ_ONLY false - -#endif diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h deleted file mode 100644 index 62549878d6..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Config/LUFAConfig.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief LUFA Library Configuration Header File - * - * This header file is used to configure LUFA's compile time options, - * as an alternative to the compile time constants supplied through - * a makefile. - * - * For information on what each token does, refer to the LUFA - * manual section "Summary of Compile Tokens". - */ - -#ifndef _LUFA_CONFIG_H_ -#define _LUFA_CONFIG_H_ - - #if (ARCH == ARCH_AVR8) - - /* Non-USB Related Configuration Tokens: */ -// #define DISABLE_TERMINAL_CODES - - /* USB Class Driver Related Tokens: */ -// #define HID_HOST_BOOT_PROTOCOL_ONLY -// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} -// #define HID_USAGE_STACK_DEPTH {Insert Value Here} -// #define HID_MAX_COLLECTIONS {Insert Value Here} -// #define HID_MAX_REPORTITEMS {Insert Value Here} -// #define HID_MAX_REPORT_IDS {Insert Value Here} -// #define NO_CLASS_DRIVER_AUTOFLUSH - - /* General USB Driver Related Tokens: */ -// #define ORDERED_EP_CONFIG - #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) - #define USB_DEVICE_ONLY -// #define USB_HOST_ONLY -// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} -// #define NO_LIMITED_CONTROLLER_CONNECT -// #define NO_SOF_EVENTS - - /* USB Device Mode Driver Related Tokens: */ -// #define USE_RAM_DESCRIPTORS - #define USE_FLASH_DESCRIPTORS -// #define USE_EEPROM_DESCRIPTORS -// #define NO_INTERNAL_SERIAL - #define FIXED_CONTROL_ENDPOINT_SIZE 8 -// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} - #define FIXED_NUM_CONFIGURATIONS 1 -// #define CONTROL_ONLY_DEVICE - #define INTERRUPT_CONTROL_ENDPOINT -// #define NO_DEVICE_REMOTE_WAKEUP -// #define NO_DEVICE_SELF_POWER - - /* USB Host Mode Driver Related Tokens: */ -// #define HOST_STATE_AS_GPIOR {Insert Value Here} -// #define USB_HOST_TIMEOUT_MS {Insert Value Here} -// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} -// #define NO_AUTO_VBUS_MANAGEMENT -// #define INVERTED_VBUS_ENABLE_LINE - - #elif (ARCH == ARCH_XMEGA) - - /* Non-USB Related Configuration Tokens: */ -// #define DISABLE_TERMINAL_CODES - - /* USB Class Driver Related Tokens: */ -// #define HID_HOST_BOOT_PROTOCOL_ONLY -// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} -// #define HID_USAGE_STACK_DEPTH {Insert Value Here} -// #define HID_MAX_COLLECTIONS {Insert Value Here} -// #define HID_MAX_REPORTITEMS {Insert Value Here} -// #define HID_MAX_REPORT_IDS {Insert Value Here} -// #define NO_CLASS_DRIVER_AUTOFLUSH - - /* General USB Driver Related Tokens: */ - #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH) -// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} -// #define NO_LIMITED_CONTROLLER_CONNECT -// #define NO_SOF_EVENTS - - /* USB Device Mode Driver Related Tokens: */ -// #define USE_RAM_DESCRIPTORS - #define USE_FLASH_DESCRIPTORS -// #define USE_EEPROM_DESCRIPTORS -// #define NO_INTERNAL_SERIAL - #define FIXED_CONTROL_ENDPOINT_SIZE 8 -// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} - #define FIXED_NUM_CONFIGURATIONS 1 -// #define CONTROL_ONLY_DEVICE - #define MAX_ENDPOINT_INDEX 5 -// #define NO_DEVICE_REMOTE_WAKEUP -// #define NO_DEVICE_SELF_POWER - - #else - - #error Unsupported architecture for this LUFA configuration file. - - #endif -#endif diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c deleted file mode 100644 index 15cbc63b26..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Matthias Hullin (lufa [at] matthias [dot] hullin [dot] net) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * USB Device Descriptors, for library use when in USB device mode. Descriptors are special - * computer-readable structures which the host requests upon device enumeration, to determine - * the device's capabilities and functions. - */ - -#include "Descriptors.h" - - -/** HID class report descriptor. This is a special descriptor constructed with values from the - * USBIF HID class specification to describe the reports and capabilities of the HID device. This - * descriptor is parsed by the host and its contents used to determine what data (and in what encoding) - * the device will send, and what it may be sent back from the host. Refer to the HID specification for - * more details on HID report descriptors. - */ -const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = -{ - /* Use the HID class driver's standard Keyboard report. - * Max simultaneous keys: 6 - */ - HID_DESCRIPTOR_KEYBOARD(6) -}; - -/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall - * device characteristics, including the supported USB version, control endpoint size and the - * number of device configurations. The descriptor is read out by the USB host when the enumeration - * process begins. - */ -const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = -{ - .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, - - .USBSpecification = VERSION_BCD(1,1,0), - .Class = USB_CSCP_NoDeviceClass, - .SubClass = USB_CSCP_NoDeviceSubclass, - .Protocol = USB_CSCP_NoDeviceProtocol, - - .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, - - .VendorID = 0x03EB, - .ProductID = 0x2061, - .ReleaseNumber = VERSION_BCD(0,0,1), - - .ManufacturerStrIndex = STRING_ID_Manufacturer, - .ProductStrIndex = STRING_ID_Product, - .SerialNumStrIndex = USE_INTERNAL_SERIAL, - - .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS -}; - -/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage - * of the device in one of its supported configurations, including information about any device interfaces - * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting - * a configuration so that the host may correctly communicate with the USB device. - */ -const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = -{ - .Config = - { - .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, - - .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), - .TotalInterfaces = 2, - - .ConfigurationNumber = 1, - .ConfigurationStrIndex = NO_DESCRIPTOR, - - .ConfigAttributes = USB_CONFIG_ATTR_RESERVED, - - .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) - }, - - .MS_Interface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - - .InterfaceNumber = INTERFACE_ID_MassStorage, - .AlternateSetting = 0, - - .TotalEndpoints = 2, - - .Class = MS_CSCP_MassStorageClass, - .SubClass = MS_CSCP_SCSITransparentSubclass, - .Protocol = MS_CSCP_BulkOnlyTransportProtocol, - - .InterfaceStrIndex = NO_DESCRIPTOR - }, - - .MS_DataInEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = MASS_STORAGE_IN_EPADDR, - .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = MASS_STORAGE_IO_EPSIZE, - .PollingIntervalMS = 0x05 - }, - - .MS_DataOutEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = MASS_STORAGE_OUT_EPADDR, - .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = MASS_STORAGE_IO_EPSIZE, - .PollingIntervalMS = 0x05 - }, - - .HID_KeyboardInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - - .InterfaceNumber = INTERFACE_ID_Keyboard, - .AlternateSetting = 0, - - .TotalEndpoints = 1, - - .Class = HID_CSCP_HIDClass, - .SubClass = HID_CSCP_BootSubclass, - .Protocol = HID_CSCP_KeyboardBootProtocol, - - .InterfaceStrIndex = NO_DESCRIPTOR - }, - - .HID_KeyboardHID = - { - .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - - .HIDSpec = VERSION_BCD(1,1,1), - .CountryCode = 0x00, - .TotalReportDescriptors = 1, - .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(KeyboardReport) - }, - - .HID_ReportINEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = KEYBOARD_EPADDR, - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = KEYBOARD_EPSIZE, - .PollingIntervalMS = 0x05 - }, -}; - -/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests - * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate - * via the language ID table available at USB.org what languages the device supports for its string descriptors. - */ -const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG); - -/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable - * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device - * Descriptor. - */ -const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera"); - -/** Product descriptor string. This is a Unicode string containing the product's details in human readable form, - * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device - * Descriptor. - */ -const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA Mass Storage and Keyboard Demo"); - -/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" - * documentation) by the application code so that the address and size of a requested descriptor can be given - * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function - * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the - * USB host. - */ -uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, - const uint16_t wIndex, - const void** const DescriptorAddress) -{ - const uint8_t DescriptorType = (wValue >> 8); - const uint8_t DescriptorNumber = (wValue & 0xFF); - - const void* Address = NULL; - uint16_t Size = NO_DESCRIPTOR; - - switch (DescriptorType) - { - case DTYPE_Device: - Address = &DeviceDescriptor; - Size = sizeof(USB_Descriptor_Device_t); - break; - case DTYPE_Configuration: - Address = &ConfigurationDescriptor; - Size = sizeof(USB_Descriptor_Configuration_t); - break; - case DTYPE_String: - switch (DescriptorNumber) - { - case STRING_ID_Language: - Address = &LanguageString; - Size = pgm_read_byte(&LanguageString.Header.Size); - break; - case STRING_ID_Manufacturer: - Address = &ManufacturerString; - Size = pgm_read_byte(&ManufacturerString.Header.Size); - break; - case STRING_ID_Product: - Address = &ProductString; - Size = pgm_read_byte(&ProductString.Header.Size); - break; - } - - break; - case HID_DTYPE_HID: - Address = &ConfigurationDescriptor.HID_KeyboardHID; - Size = sizeof(USB_HID_Descriptor_HID_t); - break; - case HID_DTYPE_Report: - Address = &KeyboardReport; - Size = sizeof(KeyboardReport); - break; - } - - *DescriptorAddress = Address; - return Size; -} - diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.h b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.h deleted file mode 100644 index b16e900e4e..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Matthias Hullin (lufa [at] matthias [dot] hullin [dot] net) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for Descriptors.c. - */ - -#ifndef _DESCRIPTORS_H_ -#define _DESCRIPTORS_H_ - - /* Includes: */ - #include - - #include - - #include "Config/AppConfig.h" - - /* Macros: */ - /** Endpoint address of the Keyboard HID reporting IN endpoint. */ - #define KEYBOARD_EPADDR (ENDPOINT_DIR_IN | 1) - - /** Size in bytes of the Keyboard HID reporting IN endpoint. */ - #define KEYBOARD_EPSIZE 8 - - /** Endpoint address of the Mass Storage device-to-host data IN endpoint. */ - #define MASS_STORAGE_IN_EPADDR (ENDPOINT_DIR_IN | 3) - - /** Endpoint address of the Mass Storage host-to-device data OUT endpoint. */ - #define MASS_STORAGE_OUT_EPADDR (ENDPOINT_DIR_OUT | 4) - - /** Size in bytes of the Mass Storage data endpoints. */ - #define MASS_STORAGE_IO_EPSIZE 64 - - /* Type Defines: */ - /** Type define for the device configuration descriptor structure. This must be defined in the - * application code, as the configuration descriptor contains several sub-descriptors which - * vary between devices, and which describe the device's usage to the host. - */ - typedef struct - { - USB_Descriptor_Configuration_Header_t Config; - - // Mass Storage Interface - USB_Descriptor_Interface_t MS_Interface; - USB_Descriptor_Endpoint_t MS_DataInEndpoint; - USB_Descriptor_Endpoint_t MS_DataOutEndpoint; - - // Generic HID Interface - USB_Descriptor_Interface_t HID_KeyboardInterface; - USB_HID_Descriptor_HID_t HID_KeyboardHID; - USB_Descriptor_Endpoint_t HID_ReportINEndpoint; - } USB_Descriptor_Configuration_t; - - /** Enum for the device interface descriptor IDs within the device. Each interface descriptor - * should have a unique ID index associated with it, which can be used to refer to the - * interface from other descriptors. - */ - enum InterfaceDescriptors_t - { - INTERFACE_ID_MassStorage = 0, /**< Mass storage interface descriptor ID */ - INTERFACE_ID_Keyboard = 1, /**< Keyboard interface descriptor ID */ - }; - - /** Enum for the device string descriptor IDs within the device. Each string descriptor should - * have a unique ID index associated with it, which can be used to refer to the string from - * other descriptors. - */ - enum StringDescriptors_t - { - STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */ - STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */ - STRING_ID_Product = 2, /**< Product string ID */ - }; - - /* Function Prototypes: */ - uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, - const uint16_t wIndex, - const void** const DescriptorAddress) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); - -#endif - diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.c b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.c deleted file mode 100644 index c0fd16ccc4..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.c +++ /dev/null @@ -1,534 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Functions to manage the physical Dataflash media, including reading and writing of - * blocks of data. These functions are called by the SCSI layer when data must be stored - * or retrieved to/from the physical storage media. If a different media is used (such - * as a SD card or EEPROM), functions similar to these will need to be generated. - */ - -#define INCLUDE_FROM_DATAFLASHMANAGER_C -#include "DataflashManager.h" - -/** Writes blocks (OS blocks, not Dataflash pages) to the storage medium, the board Dataflash IC(s), from - * the pre-selected data OUT endpoint. This routine reads in OS sized blocks from the endpoint and writes - * them to the Dataflash in Dataflash page sized blocks. - * - * \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state - * \param[in] BlockAddress Data block starting address for the write sequence - * \param[in] TotalBlocks Number of blocks of data to write - */ -void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, - const uint32_t BlockAddress, - uint16_t TotalBlocks) -{ - uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE); - uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE); - uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4); - bool UsingSecondBuffer = false; - - /* Select the correct starting Dataflash IC for the block requested */ - Dataflash_SelectChipFromPage(CurrDFPage); - -#if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE) - /* Copy selected dataflash's current page contents to the Dataflash buffer */ - Dataflash_SendByte(DF_CMD_MAINMEMTOBUFF1); - Dataflash_SendAddressBytes(CurrDFPage, 0); - Dataflash_WaitWhileBusy(); -#endif - - /* Send the Dataflash buffer write command */ - Dataflash_SendByte(DF_CMD_BUFF1WRITE); - Dataflash_SendAddressBytes(0, CurrDFPageByte); - - /* Wait until endpoint is ready before continuing */ - if (Endpoint_WaitUntilReady()) - return; - - while (TotalBlocks) - { - uint8_t BytesInBlockDiv16 = 0; - - /* Write an endpoint packet sized data block to the Dataflash */ - while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) - { - /* Check if the endpoint is currently empty */ - if (!(Endpoint_IsReadWriteAllowed())) - { - /* Clear the current endpoint bank */ - Endpoint_ClearOUT(); - - /* Wait until the host has sent another packet */ - if (Endpoint_WaitUntilReady()) - return; - } - - /* Check if end of Dataflash page reached */ - if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4)) - { - /* Write the Dataflash buffer contents back to the Dataflash page */ - Dataflash_WaitWhileBusy(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE); - Dataflash_SendAddressBytes(CurrDFPage, 0); - - /* Reset the Dataflash buffer counter, increment the page counter */ - CurrDFPageByteDiv16 = 0; - CurrDFPage++; - - /* Once all the Dataflash ICs have had their first buffers filled, switch buffers to maintain throughput */ - if (Dataflash_GetSelectedChip() == DATAFLASH_CHIP_MASK(DATAFLASH_TOTALCHIPS)) - UsingSecondBuffer = !(UsingSecondBuffer); - - /* Select the next Dataflash chip based on the new Dataflash page index */ - Dataflash_SelectChipFromPage(CurrDFPage); - -#if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE) - /* If less than one Dataflash page remaining, copy over the existing page to preserve trailing data */ - if ((TotalBlocks * (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) < (DATAFLASH_PAGE_SIZE >> 4)) - { - /* Copy selected dataflash's current page contents to the Dataflash buffer */ - Dataflash_WaitWhileBusy(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_MAINMEMTOBUFF2 : DF_CMD_MAINMEMTOBUFF1); - Dataflash_SendAddressBytes(CurrDFPage, 0); - Dataflash_WaitWhileBusy(); - } -#endif - - /* Send the Dataflash buffer write command */ - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2WRITE : DF_CMD_BUFF1WRITE); - Dataflash_SendAddressBytes(0, 0); - } - - /* Write one 16-byte chunk of data to the Dataflash */ - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - Dataflash_SendByte(Endpoint_Read_8()); - - /* Increment the Dataflash page 16 byte block counter */ - CurrDFPageByteDiv16++; - - /* Increment the block 16 byte block counter */ - BytesInBlockDiv16++; - - /* Check if the current command is being aborted by the host */ - if (MSInterfaceInfo->State.IsMassStoreReset) - return; - } - - /* Decrement the blocks remaining counter */ - TotalBlocks--; - } - - /* Write the Dataflash buffer contents back to the Dataflash page */ - Dataflash_WaitWhileBusy(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE); - Dataflash_SendAddressBytes(CurrDFPage, 0x00); - Dataflash_WaitWhileBusy(); - - /* If the endpoint is empty, clear it ready for the next packet from the host */ - if (!(Endpoint_IsReadWriteAllowed())) - Endpoint_ClearOUT(); - - /* Deselect all Dataflash chips */ - Dataflash_DeselectChip(); -} - -/** Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board Dataflash IC(s), into - * the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the Dataflash - * and writes them in OS sized blocks to the endpoint. - * - * \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state - * \param[in] BlockAddress Data block starting address for the read sequence - * \param[in] TotalBlocks Number of blocks of data to read - */ -void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, - const uint32_t BlockAddress, - uint16_t TotalBlocks) -{ - uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE); - uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE); - uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4); - - /* Select the correct starting Dataflash IC for the block requested */ - Dataflash_SelectChipFromPage(CurrDFPage); - - /* Send the Dataflash main memory page read command */ - Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD); - Dataflash_SendAddressBytes(CurrDFPage, CurrDFPageByte); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - - /* Wait until endpoint is ready before continuing */ - if (Endpoint_WaitUntilReady()) - return; - - while (TotalBlocks) - { - uint8_t BytesInBlockDiv16 = 0; - - /* Read an endpoint packet sized data block from the Dataflash */ - while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) - { - /* Check if the endpoint is currently full */ - if (!(Endpoint_IsReadWriteAllowed())) - { - /* Clear the endpoint bank to send its contents to the host */ - Endpoint_ClearIN(); - - /* Wait until the endpoint is ready for more data */ - if (Endpoint_WaitUntilReady()) - return; - } - - /* Check if end of Dataflash page reached */ - if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4)) - { - /* Reset the Dataflash buffer counter, increment the page counter */ - CurrDFPageByteDiv16 = 0; - CurrDFPage++; - - /* Select the next Dataflash chip based on the new Dataflash page index */ - Dataflash_SelectChipFromPage(CurrDFPage); - - /* Send the Dataflash main memory page read command */ - Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD); - Dataflash_SendAddressBytes(CurrDFPage, 0); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - } - - /* Read one 16-byte chunk of data from the Dataflash */ - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - Endpoint_Write_8(Dataflash_ReceiveByte()); - - /* Increment the Dataflash page 16 byte block counter */ - CurrDFPageByteDiv16++; - - /* Increment the block 16 byte block counter */ - BytesInBlockDiv16++; - - /* Check if the current command is being aborted by the host */ - if (MSInterfaceInfo->State.IsMassStoreReset) - return; - } - - /* Decrement the blocks remaining counter */ - TotalBlocks--; - } - - /* If the endpoint is full, send its contents to the host */ - if (!(Endpoint_IsReadWriteAllowed())) - Endpoint_ClearIN(); - - /* Deselect all Dataflash chips */ - Dataflash_DeselectChip(); -} - -/** Writes blocks (OS blocks, not Dataflash pages) to the storage medium, the board Dataflash IC(s), from - * the given RAM buffer. This routine reads in OS sized blocks from the buffer and writes them to the - * Dataflash in Dataflash page sized blocks. This can be linked to FAT libraries to write files to the - * Dataflash. - * - * \param[in] BlockAddress Data block starting address for the write sequence - * \param[in] TotalBlocks Number of blocks of data to write - * \param[in] BufferPtr Pointer to the data source RAM buffer - */ -void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress, - uint16_t TotalBlocks, - uint8_t* BufferPtr) -{ - uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE); - uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE); - uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4); - bool UsingSecondBuffer = false; - - /* Select the correct starting Dataflash IC for the block requested */ - Dataflash_SelectChipFromPage(CurrDFPage); - -#if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE) - /* Copy selected dataflash's current page contents to the Dataflash buffer */ - Dataflash_SendByte(DF_CMD_MAINMEMTOBUFF1); - Dataflash_SendAddressBytes(CurrDFPage, 0); - Dataflash_WaitWhileBusy(); -#endif - - /* Send the Dataflash buffer write command */ - Dataflash_SendByte(DF_CMD_BUFF1WRITE); - Dataflash_SendAddressBytes(0, CurrDFPageByte); - - while (TotalBlocks) - { - uint8_t BytesInBlockDiv16 = 0; - - /* Write an endpoint packet sized data block to the Dataflash */ - while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) - { - /* Check if end of Dataflash page reached */ - if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4)) - { - /* Write the Dataflash buffer contents back to the Dataflash page */ - Dataflash_WaitWhileBusy(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE); - Dataflash_SendAddressBytes(CurrDFPage, 0); - - /* Reset the Dataflash buffer counter, increment the page counter */ - CurrDFPageByteDiv16 = 0; - CurrDFPage++; - - /* Once all the Dataflash ICs have had their first buffers filled, switch buffers to maintain throughput */ - if (Dataflash_GetSelectedChip() == DATAFLASH_CHIP_MASK(DATAFLASH_TOTALCHIPS)) - UsingSecondBuffer = !(UsingSecondBuffer); - - /* Select the next Dataflash chip based on the new Dataflash page index */ - Dataflash_SelectChipFromPage(CurrDFPage); - -#if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE) - /* If less than one Dataflash page remaining, copy over the existing page to preserve trailing data */ - if ((TotalBlocks * (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) < (DATAFLASH_PAGE_SIZE >> 4)) - { - /* Copy selected dataflash's current page contents to the Dataflash buffer */ - Dataflash_WaitWhileBusy(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_MAINMEMTOBUFF2 : DF_CMD_MAINMEMTOBUFF1); - Dataflash_SendAddressBytes(CurrDFPage, 0); - Dataflash_WaitWhileBusy(); - } -#endif - - /* Send the Dataflash buffer write command */ - Dataflash_ToggleSelectedChipCS(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2WRITE : DF_CMD_BUFF1WRITE); - Dataflash_SendAddressBytes(0, 0); - } - - /* Write one 16-byte chunk of data to the Dataflash */ - for (uint8_t ByteNum = 0; ByteNum < 16; ByteNum++) - Dataflash_SendByte(*(BufferPtr++)); - - /* Increment the Dataflash page 16 byte block counter */ - CurrDFPageByteDiv16++; - - /* Increment the block 16 byte block counter */ - BytesInBlockDiv16++; - } - - /* Decrement the blocks remaining counter */ - TotalBlocks--; - } - - /* Write the Dataflash buffer contents back to the Dataflash page */ - Dataflash_WaitWhileBusy(); - Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE); - Dataflash_SendAddressBytes(CurrDFPage, 0x00); - Dataflash_WaitWhileBusy(); - - /* Deselect all Dataflash chips */ - Dataflash_DeselectChip(); -} - -/** Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board Dataflash IC(s), into - * the preallocated RAM buffer. This routine reads in Dataflash page sized blocks from the Dataflash - * and writes them in OS sized blocks to the given buffer. This can be linked to FAT libraries to read - * the files stored on the Dataflash. - * - * \param[in] BlockAddress Data block starting address for the read sequence - * \param[in] TotalBlocks Number of blocks of data to read - * \param[out] BufferPtr Pointer to the data destination RAM buffer - */ -void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress, - uint16_t TotalBlocks, - uint8_t* BufferPtr) -{ - uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE); - uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE); - uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4); - - /* Select the correct starting Dataflash IC for the block requested */ - Dataflash_SelectChipFromPage(CurrDFPage); - - /* Send the Dataflash main memory page read command */ - Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD); - Dataflash_SendAddressBytes(CurrDFPage, CurrDFPageByte); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - - while (TotalBlocks) - { - uint8_t BytesInBlockDiv16 = 0; - - /* Read an endpoint packet sized data block from the Dataflash */ - while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) - { - /* Check if end of Dataflash page reached */ - if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4)) - { - /* Reset the Dataflash buffer counter, increment the page counter */ - CurrDFPageByteDiv16 = 0; - CurrDFPage++; - - /* Select the next Dataflash chip based on the new Dataflash page index */ - Dataflash_SelectChipFromPage(CurrDFPage); - - /* Send the Dataflash main memory page read command */ - Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD); - Dataflash_SendAddressBytes(CurrDFPage, 0); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - Dataflash_SendByte(0x00); - } - - /* Read one 16-byte chunk of data from the Dataflash */ - for (uint8_t ByteNum = 0; ByteNum < 16; ByteNum++) - *(BufferPtr++) = Dataflash_ReceiveByte(); - - /* Increment the Dataflash page 16 byte block counter */ - CurrDFPageByteDiv16++; - - /* Increment the block 16 byte block counter */ - BytesInBlockDiv16++; - } - - /* Decrement the blocks remaining counter */ - TotalBlocks--; - } - - /* Deselect all Dataflash chips */ - Dataflash_DeselectChip(); -} - -/** Disables the Dataflash memory write protection bits on the board Dataflash ICs, if enabled. */ -void DataflashManager_ResetDataflashProtections(void) -{ - /* Select first Dataflash chip, send the read status register command */ - Dataflash_SelectChip(DATAFLASH_CHIP1); - Dataflash_SendByte(DF_CMD_GETSTATUS); - - /* Check if sector protection is enabled */ - if (Dataflash_ReceiveByte() & DF_STATUS_SECTORPROTECTION_ON) - { - Dataflash_ToggleSelectedChipCS(); - - /* Send the commands to disable sector protection */ - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[0]); - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[1]); - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[2]); - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[3]); - } - - /* Select second Dataflash chip (if present on selected board), send read status register command */ - #if (DATAFLASH_TOTALCHIPS == 2) - Dataflash_SelectChip(DATAFLASH_CHIP2); - Dataflash_SendByte(DF_CMD_GETSTATUS); - - /* Check if sector protection is enabled */ - if (Dataflash_ReceiveByte() & DF_STATUS_SECTORPROTECTION_ON) - { - Dataflash_ToggleSelectedChipCS(); - - /* Send the commands to disable sector protection */ - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[0]); - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[1]); - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[2]); - Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[3]); - } - #endif - - /* Deselect current Dataflash chip */ - Dataflash_DeselectChip(); -} - -/** Performs a simple test on the attached Dataflash IC(s) to ensure that they are working. - * - * \return Boolean \c true if all media chips are working, \c false otherwise - */ -bool DataflashManager_CheckDataflashOperation(void) -{ - uint8_t ReturnByte; - - /* Test first Dataflash IC is present and responding to commands */ - Dataflash_SelectChip(DATAFLASH_CHIP1); - Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO); - ReturnByte = Dataflash_ReceiveByte(); - Dataflash_DeselectChip(); - - /* If returned data is invalid, fail the command */ - if (ReturnByte != DF_MANUFACTURER_ATMEL) - return false; - - #if (DATAFLASH_TOTALCHIPS == 2) - /* Test second Dataflash IC is present and responding to commands */ - Dataflash_SelectChip(DATAFLASH_CHIP2); - Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO); - ReturnByte = Dataflash_ReceiveByte(); - Dataflash_DeselectChip(); - - /* If returned data is invalid, fail the command */ - if (ReturnByte != DF_MANUFACTURER_ATMEL) - return false; - #endif - - return true; -} - diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.h b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.h deleted file mode 100644 index 076847a7d6..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/DataflashManager.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for DataflashManager.c. - */ - -#ifndef _DATAFLASH_MANAGER_H_ -#define _DATAFLASH_MANAGER_H_ - - /* Includes: */ - #include - - #include "../MassStorageKeyboard.h" - #include "../Descriptors.h" - #include "Config/AppConfig.h" - - #include - #include - #include - - /* Preprocessor Checks: */ - #if (DATAFLASH_PAGE_SIZE % 16) - #error Dataflash page size must be a multiple of 16 bytes. - #endif - - /* Defines: */ - /** Total number of bytes of the storage medium, comprised of one or more Dataflash ICs. */ - #define VIRTUAL_MEMORY_BYTES ((uint32_t)DATAFLASH_PAGES * DATAFLASH_PAGE_SIZE * DATAFLASH_TOTALCHIPS) - - /** Block size of the device. This is kept at 512 to remain compatible with the OS despite the underlying - * storage media (Dataflash) using a different native block size. - */ - #define VIRTUAL_MEMORY_BLOCK_SIZE 512 - - /** Total number of blocks of the virtual memory for reporting to the host as the device's total capacity. */ - #define VIRTUAL_MEMORY_BLOCKS (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE) - - /** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */ - #define LUN_MEDIA_BLOCKS (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS) - - /* Function Prototypes: */ - void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, - const uint32_t BlockAddress, - uint16_t TotalBlocks); - void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, - const uint32_t BlockAddress, - uint16_t TotalBlocks); - void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress, - uint16_t TotalBlocks, - uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3); - void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress, - uint16_t TotalBlocks, - uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3); - void DataflashManager_ResetDataflashProtections(void); - bool DataflashManager_CheckDataflashOperation(void); - -#endif - diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.c b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.c deleted file mode 100644 index 8780d1603d..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * SCSI command processing routines, for SCSI commands issued by the host. Mass Storage - * devices use a thin "Bulk-Only Transport" protocol for issuing commands and status information, - * which wrap around standard SCSI device commands for controlling the actual storage medium. - */ - -#define INCLUDE_FROM_SCSI_C -#include "SCSI.h" - -/** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's - * features and capabilities. - */ -static const SCSI_Inquiry_Response_t InquiryData = - { - .DeviceType = DEVICE_TYPE_BLOCK, - .PeripheralQualifier = 0, - - .Removable = true, - - .Version = 0, - - .ResponseDataFormat = 2, - .NormACA = false, - .TrmTsk = false, - .AERC = false, - - .AdditionalLength = 0x1F, - - .SoftReset = false, - .CmdQue = false, - .Linked = false, - .Sync = false, - .WideBus16Bit = false, - .WideBus32Bit = false, - .RelAddr = false, - - .VendorID = "LUFA", - .ProductID = "Dataflash Disk", - .RevisionID = {'0','.','0','0'}, - }; - -/** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE - * command is issued. This gives information on exactly why the last command failed to complete. - */ -static SCSI_Request_Sense_Response_t SenseData = - { - .ResponseCode = 0x70, - .AdditionalLength = 0x0A, - }; - - -/** Main routine to process the SCSI command located in the Command Block Wrapper read from the host. This dispatches - * to the appropriate SCSI command handling routine if the issued command is supported by the device, else it returns - * a command failure due to a ILLEGAL REQUEST. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * - * \return Boolean \c true if the command completed successfully, \c false otherwise - */ -bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) -{ - bool CommandSuccess = false; - - /* Run the appropriate SCSI command hander function based on the passed command */ - switch (MSInterfaceInfo->State.CommandBlock.SCSICommandData[0]) - { - case SCSI_CMD_INQUIRY: - CommandSuccess = SCSI_Command_Inquiry(MSInterfaceInfo); - break; - case SCSI_CMD_REQUEST_SENSE: - CommandSuccess = SCSI_Command_Request_Sense(MSInterfaceInfo); - break; - case SCSI_CMD_READ_CAPACITY_10: - CommandSuccess = SCSI_Command_Read_Capacity_10(MSInterfaceInfo); - break; - case SCSI_CMD_SEND_DIAGNOSTIC: - CommandSuccess = SCSI_Command_Send_Diagnostic(MSInterfaceInfo); - break; - case SCSI_CMD_WRITE_10: - CommandSuccess = SCSI_Command_ReadWrite_10(MSInterfaceInfo, DATA_WRITE); - break; - case SCSI_CMD_READ_10: - CommandSuccess = SCSI_Command_ReadWrite_10(MSInterfaceInfo, DATA_READ); - break; - case SCSI_CMD_MODE_SENSE_6: - CommandSuccess = SCSI_Command_ModeSense_6(MSInterfaceInfo); - break; - case SCSI_CMD_START_STOP_UNIT: - case SCSI_CMD_TEST_UNIT_READY: - case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: - case SCSI_CMD_VERIFY_10: - /* These commands should just succeed, no handling required */ - CommandSuccess = true; - MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0; - break; - default: - /* Update the SENSE key to reflect the invalid command */ - SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST, - SCSI_ASENSE_INVALID_COMMAND, - SCSI_ASENSEQ_NO_QUALIFIER); - break; - } - - /* Check if command was successfully processed */ - if (CommandSuccess) - { - SCSI_SET_SENSE(SCSI_SENSE_KEY_GOOD, - SCSI_ASENSE_NO_ADDITIONAL_INFORMATION, - SCSI_ASENSEQ_NO_QUALIFIER); - - return true; - } - - return false; -} - -/** Command processing for an issued SCSI INQUIRY command. This command returns information about the device's features - * and capabilities to the host. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * - * \return Boolean \c true if the command completed successfully, \c false otherwise. - */ -static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) -{ - uint16_t AllocationLength = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[3]); - uint16_t BytesTransferred = MIN(AllocationLength, sizeof(InquiryData)); - - /* Only the standard INQUIRY data is supported, check if any optional INQUIRY bits set */ - if ((MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) || - MSInterfaceInfo->State.CommandBlock.SCSICommandData[2]) - { - /* Optional but unsupported bits set - update the SENSE key and fail the request */ - SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST, - SCSI_ASENSE_INVALID_FIELD_IN_CDB, - SCSI_ASENSEQ_NO_QUALIFIER); - - return false; - } - - Endpoint_Write_Stream_LE(&InquiryData, BytesTransferred, NULL); - - /* Pad out remaining bytes with 0x00 */ - Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL); - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearIN(); - - /* Succeed the command and update the bytes transferred counter */ - MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred; - - return true; -} - -/** Command processing for an issued SCSI REQUEST SENSE command. This command returns information about the last issued command, - * including the error code and additional error information so that the host can determine why a command failed to complete. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * - * \return Boolean \c true if the command completed successfully, \c false otherwise. - */ -static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) -{ - uint8_t AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4]; - uint8_t BytesTransferred = MIN(AllocationLength, sizeof(SenseData)); - - Endpoint_Write_Stream_LE(&SenseData, BytesTransferred, NULL); - Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL); - Endpoint_ClearIN(); - - /* Succeed the command and update the bytes transferred counter */ - MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred; - - return true; -} - -/** Command processing for an issued SCSI READ CAPACITY (10) command. This command returns information about the device's capacity - * on the selected Logical Unit (drive), as a number of OS-sized blocks. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * - * \return Boolean \c true if the command completed successfully, \c false otherwise. - */ -static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) -{ - uint32_t LastBlockAddressInLUN = (LUN_MEDIA_BLOCKS - 1); - uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE; - - Endpoint_Write_Stream_BE(&LastBlockAddressInLUN, sizeof(LastBlockAddressInLUN), NULL); - Endpoint_Write_Stream_BE(&MediaBlockSize, sizeof(MediaBlockSize), NULL); - Endpoint_ClearIN(); - - /* Succeed the command and update the bytes transferred counter */ - MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 8; - - return true; -} - -/** Command processing for an issued SCSI SEND DIAGNOSTIC command. This command performs a quick check of the Dataflash ICs on the - * board, and indicates if they are present and functioning correctly. Only the Self-Test portion of the diagnostic command is - * supported. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * - * \return Boolean \c true if the command completed successfully, \c false otherwise. - */ -static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) -{ - /* Check to see if the SELF TEST bit is not set */ - if (!(MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & (1 << 2))) - { - /* Only self-test supported - update SENSE key and fail the command */ - SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST, - SCSI_ASENSE_INVALID_FIELD_IN_CDB, - SCSI_ASENSEQ_NO_QUALIFIER); - - return false; - } - - /* Check to see if all attached Dataflash ICs are functional */ - if (!(DataflashManager_CheckDataflashOperation())) - { - /* Update SENSE key with a hardware error condition and return command fail */ - SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR, - SCSI_ASENSE_NO_ADDITIONAL_INFORMATION, - SCSI_ASENSEQ_NO_QUALIFIER); - - return false; - } - - /* Succeed the command and update the bytes transferred counter */ - MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0; - - return true; -} - -/** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address - * and total number of blocks to process, then calls the appropriate low-level Dataflash routine to handle the actual - * reading and writing of the data. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * \param[in] IsDataRead Indicates if the command is a READ (10) command or WRITE (10) command (DATA_READ or DATA_WRITE) - * - * \return Boolean \c true if the command completed successfully, \c false otherwise. - */ -static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, - const bool IsDataRead) -{ - uint32_t BlockAddress; - uint16_t TotalBlocks; - - /* Check if the disk is write protected or not */ - if ((IsDataRead == DATA_WRITE) && DISK_READ_ONLY) - { - /* Block address is invalid, update SENSE key and return command fail */ - SCSI_SET_SENSE(SCSI_SENSE_KEY_DATA_PROTECT, - SCSI_ASENSE_WRITE_PROTECTED, - SCSI_ASENSEQ_NO_QUALIFIER); - - return false; - } - - /* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */ - BlockAddress = SwapEndian_32(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[2]); - - /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to reverse the byte order) */ - TotalBlocks = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[7]); - - /* Check if the block address is outside the maximum allowable value for the LUN */ - if (BlockAddress >= LUN_MEDIA_BLOCKS) - { - /* Block address is invalid, update SENSE key and return command fail */ - SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST, - SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE, - SCSI_ASENSEQ_NO_QUALIFIER); - - return false; - } - - #if (TOTAL_LUNS > 1) - /* Adjust the given block address to the real media address based on the selected LUN */ - BlockAddress += ((uint32_t)MSInterfaceInfo->State.CommandBlock.LUN * LUN_MEDIA_BLOCKS); - #endif - - /* Determine if the packet is a READ (10) or WRITE (10) command, call appropriate function */ - if (IsDataRead == DATA_READ) - DataflashManager_ReadBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks); - else - DataflashManager_WriteBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks); - - /* Update the bytes transferred counter and succeed the command */ - MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE); - - return true; -} - -/** Command processing for an issued SCSI MODE SENSE (6) command. This command returns various informational pages about - * the SCSI device, as well as the device's Write Protect status. - * - * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with - * - * \return Boolean \c true if the command completed successfully, \c false otherwise. - */ -static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) -{ - /* Send an empty header response with the Write Protect flag status */ - Endpoint_Write_8(0x00); - Endpoint_Write_8(0x00); - Endpoint_Write_8(DISK_READ_ONLY ? 0x80 : 0x00); - Endpoint_Write_8(0x00); - Endpoint_ClearIN(); - - /* Update the bytes transferred counter and succeed the command */ - MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 4; - - return true; -} - diff --git a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.h b/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.h deleted file mode 100644 index c442e45386..0000000000 --- a/lib/lufa/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/SCSI.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2017. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaims all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising o