diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2017-07-07 11:55:23 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-07-07 11:55:23 -0400 |
| commit | 8655d4f4948b2deef7844503c8d690f23ac1a062 (patch) | |
| tree | b2c6effc9d6cd5b5b43933a1e53b8bf17e9e82cf /lib/lufa/Demos/Device/Incomplete/TestAndMeasurement | |
| parent | 1896c76a2928c96f9ab7947bec2ef8dd37623cff (diff) | |
| parent | 60b30c036397cb5627fa374bb930794b225daa29 (diff) | |
| download | qmk_firmware-8655d4f4948b2deef7844503c8d690f23ac1a062.tar.gz qmk_firmware-8655d4f4948b2deef7844503c8d690f23ac1a062.zip | |
Merge commit '60b30c036397cb5627fa374bb930794b225daa29' as 'lib/lufa'
Diffstat (limited to 'lib/lufa/Demos/Device/Incomplete/TestAndMeasurement')
6 files changed, 1104 insertions, 0 deletions
diff --git a/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h new file mode 100644 index 000000000..0ec4635eb --- /dev/null +++ b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Config/LUFAConfig.h | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | /* | ||
| 2 | LUFA Library | ||
| 3 | Copyright (C) Dean Camera, 2017. | ||
| 4 | |||
| 5 | dean [at] fourwalledcubicle [dot] com | ||
| 6 | www.lufa-lib.org | ||
| 7 | */ | ||
| 8 | |||
| 9 | /* | ||
| 10 | Copyright 2017 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 disclaims 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 | /** \file | ||
| 32 | * \brief LUFA Library Configuration Header File | ||
| 33 | * | ||
| 34 | * This header file is used to configure LUFA's compile time options, | ||
| 35 | * as an alternative to the compile time constants supplied through | ||
| 36 | * a makefile. | ||
| 37 | * | ||
| 38 | * For information on what each token does, refer to the LUFA | ||
| 39 | * manual section "Summary of Compile Tokens". | ||
| 40 | */ | ||
| 41 | |||
| 42 | #ifndef _LUFA_CONFIG_H_ | ||
| 43 | #define _LUFA_CONFIG_H_ | ||
| 44 | |||
| 45 | #if (ARCH == ARCH_AVR8) | ||
| 46 | |||
| 47 | /* Non-USB Related Configuration Tokens: */ | ||
| 48 | // #define DISABLE_TERMINAL_CODES | ||
| 49 | |||
| 50 | /* USB Class Driver Related Tokens: */ | ||
| 51 | // #define HID_HOST_BOOT_PROTOCOL_ONLY | ||
| 52 | // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} | ||
| 53 | // #define HID_USAGE_STACK_DEPTH {Insert Value Here} | ||
| 54 | // #define HID_MAX_COLLECTIONS {Insert Value Here} | ||
| 55 | // #define HID_MAX_REPORTITEMS {Insert Value Here} | ||
| 56 | // #define HID_MAX_REPORT_IDS {Insert Value Here} | ||
| 57 | // #define NO_CLASS_DRIVER_AUTOFLUSH | ||
| 58 | |||
| 59 | /* General USB Driver Related Tokens: */ | ||
| 60 | // #define ORDERED_EP_CONFIG | ||
| 61 | #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) | ||
| 62 | #define USB_DEVICE_ONLY | ||
| 63 | // #define USB_HOST_ONLY | ||
| 64 | // #define USB_STREAM_TIMEOUT_MS {Insert Value Here} | ||
| 65 | // #define NO_LIMITED_CONTROLLER_CONNECT | ||
| 66 | // #define NO_SOF_EVENTS | ||
| 67 | |||
| 68 | /* USB Device Mode Driver Related Tokens: */ | ||
| 69 | // #define USE_RAM_DESCRIPTORS | ||
| 70 | #define USE_FLASH_DESCRIPTORS | ||
| 71 | // #define USE_EEPROM_DESCRIPTORS | ||
| 72 | // #define NO_INTERNAL_SERIAL | ||
| 73 | #define FIXED_CONTROL_ENDPOINT_SIZE 8 | ||
| 74 | // #define DEVICE_STATE_AS_GPIOR {Insert Value Here} | ||
| 75 | #define FIXED_NUM_CONFIGURATIONS 1 | ||
| 76 | // #define CONTROL_ONLY_DEVICE | ||
| 77 | #define INTERRUPT_CONTROL_ENDPOINT | ||
| 78 | // #define NO_DEVICE_REMOTE_WAKEUP | ||
| 79 | // #define NO_DEVICE_SELF_POWER | ||
| 80 | |||
| 81 | /* USB Host Mode Driver Related Tokens: */ | ||
| 82 | // #define HOST_STATE_AS_GPIOR {Insert Value Here} | ||
| 83 | // #define USB_HOST_TIMEOUT_MS {Insert Value Here} | ||
| 84 | // #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} | ||
| 85 | // #define NO_AUTO_VBUS_MANAGEMENT | ||
| 86 | // #define INVERTED_VBUS_ENABLE_LINE | ||
| 87 | |||
| 88 | #elif (ARCH == ARCH_XMEGA) | ||
| 89 | |||
| 90 | /* Non-USB Related Configuration Tokens: */ | ||
| 91 | // #define DISABLE_TERMINAL_CODES | ||
| 92 | |||
| 93 | /* USB Class Driver Related Tokens: */ | ||
| 94 | // #define HID_HOST_BOOT_PROTOCOL_ONLY | ||
| 95 | // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} | ||
| 96 | // #define HID_USAGE_STACK_DEPTH {Insert Value Here} | ||
| 97 | // #define HID_MAX_COLLECTIONS {Insert Value Here} | ||
| 98 | // #define HID_MAX_REPORTITEMS {Insert Value Here} | ||
| 99 | // #define HID_MAX_REPORT_IDS {Insert Value Here} | ||
| 100 | // #define NO_CLASS_DRIVER_AUTOFLUSH | ||
| 101 | |||
| 102 | /* General USB Driver Related Tokens: */ | ||
| 103 | #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH) | ||
| 104 | // #define USB_STREAM_TIMEOUT_MS {Insert Value Here} | ||
| 105 | // #define NO_LIMITED_CONTROLLER_CONNECT | ||
| 106 | // #define NO_SOF_EVENTS | ||
| 107 | |||
| 108 | /* USB Device Mode Driver Related Tokens: */ | ||
| 109 | // #define USE_RAM_DESCRIPTORS | ||
| 110 | #define USE_FLASH_DESCRIPTORS | ||
| 111 | // #define USE_EEPROM_DESCRIPTORS | ||
| 112 | // #define NO_INTERNAL_SERIAL | ||
| 113 | #define FIXED_CONTROL_ENDPOINT_SIZE 8 | ||
| 114 | // #define DEVICE_STATE_AS_GPIOR {Insert Value Here} | ||
| 115 | #define FIXED_NUM_CONFIGURATIONS 1 | ||
| 116 | // #define CONTROL_ONLY_DEVICE | ||
| 117 | #define MAX_ENDPOINT_INDEX 4 | ||
| 118 | // #define NO_DEVICE_REMOTE_WAKEUP | ||
| 119 | // #define NO_DEVICE_SELF_POWER | ||
| 120 | |||
| 121 | #else | ||
| 122 | |||
| 123 | #error Unsupported architecture for this LUFA configuration file. | ||
| 124 | |||
| 125 | #endif | ||
| 126 | #endif | ||
diff --git a/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c new file mode 100644 index 000000000..96596c161 --- /dev/null +++ b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c | |||
| @@ -0,0 +1,205 @@ | |||
| 1 | /* | ||
| 2 | LUFA Library | ||
| 3 | Copyright (C) Dean Camera, 2017. | ||
| 4 | |||
| 5 | dean [at] fourwalledcubicle [dot] com | ||
| 6 | www.lufa-lib.org | ||
| 7 | */ | ||
| 8 | |||
| 9 | /* | ||
| 10 | Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) | ||
| 11 | Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com) | ||
| 12 | |||
| 13 | Permission to use, copy, modify, distribute, and sell this | ||
| 14 | software and its documentation for any purpose is hereby granted | ||
| 15 | without fee, provided that the above copyright notice appear in | ||
| 16 | all copies and that both that the copyright notice and this | ||
| 17 | permission notice and warranty disclaimer appear in supporting | ||
| 18 | documentation, and that the name of the author not be used in | ||
| 19 | advertising or publicity pertaining to distribution of the | ||
| 20 | software without specific, written prior permission. | ||
| 21 | |||
| 22 | The author disclaims all warranties with regard to this | ||
| 23 | software, including all implied warranties of merchantability | ||
| 24 | and fitness. In no event shall the author be liable for any | ||
| 25 | special, indirect or consequential damages or any damages | ||
| 26 | whatsoever resulting from loss of use, data or profits, whether | ||
| 27 | in an action of contract, negligence or other tortious action, | ||
| 28 | arising out of or in connection with the use or performance of | ||
| 29 | this software. | ||
| 30 | */ | ||
| 31 | |||
| 32 | /** \file | ||
| 33 | * | ||
| 34 | * USB Device Descriptors, for library use when in USB device mode. Descriptors are special | ||
| 35 | * computer-readable structures which the host requests upon device enumeration, to determine | ||
| 36 | * the device's capabilities and functions. | ||
| 37 | */ | ||
| 38 | |||
| 39 | #include "Descriptors.h" | ||
| 40 | |||
| 41 | |||
| 42 | /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall | ||
| 43 | * device characteristics, including the supported USB version, control endpoint size and the | ||
| 44 | * number of device configurations. The descriptor is read out by the USB host when the enumeration | ||
| 45 | * process begins. | ||
| 46 | */ | ||
| 47 | const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = | ||
| 48 | { | ||
| 49 | .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, | ||
| 50 | |||
| 51 | .USBSpecification = VERSION_BCD(1,1,0), | ||
| 52 | .Class = 0x00, | ||
| 53 | .SubClass = 0x00, | ||
| 54 | .Protocol = 0x00, | ||
| 55 | |||
| 56 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, | ||
| 57 | |||
| 58 | .VendorID = 0x03EB, | ||
| 59 | .ProductID = 0x2065, | ||
| 60 | .ReleaseNumber = VERSION_BCD(0,0,1), | ||
| 61 | |||
| 62 | .ManufacturerStrIndex = STRING_ID_Manufacturer, | ||
| 63 | .ProductStrIndex = STRING_ID_Product, | ||
| 64 | .SerialNumStrIndex = USE_INTERNAL_SERIAL, | ||
| 65 | |||
| 66 | .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS | ||
| 67 | }; | ||
| 68 | |||
| 69 | /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage | ||
| 70 | * of the device in one of its supported configurations, including information about any device interfaces | ||
| 71 | * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting | ||
| 72 | * a configuration so that the host may correctly communicate with the USB device. | ||
| 73 | */ | ||
| 74 | const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | ||
| 75 | { | ||
| 76 | .Config = | ||
| 77 | { | ||
| 78 | .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, | ||
| 79 | |||
| 80 | .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), | ||
| 81 | .TotalInterfaces = 1, | ||
| 82 | |||
| 83 | .ConfigurationNumber = 1, | ||
| 84 | .ConfigurationStrIndex = NO_DESCRIPTOR, | ||
| 85 | |||
| 86 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), | ||
| 87 | |||
| 88 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) | ||
| 89 | }, | ||
| 90 | |||
| 91 | .TM_Interface = | ||
| 92 | { | ||
| 93 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | ||
| 94 | |||
| 95 | .InterfaceNumber = INTERFACE_ID_TestAndMeasurement, | ||
| 96 | .AlternateSetting = 0x00, | ||
| 97 | |||
| 98 | .TotalEndpoints = 3, | ||
| 99 | |||
| 100 | .Class = 0xFE, | ||
| 101 | .SubClass = 0x03, | ||
| 102 | .Protocol = 0x01, | ||
| 103 | |||
| 104 | .InterfaceStrIndex = NO_DESCRIPTOR | ||
| 105 | }, | ||
| 106 | |||
| 107 | .TM_DataOutEndpoint = | ||
| 108 | { | ||
| 109 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | ||
| 110 | |||
| 111 | .EndpointAddress = TMC_OUT_EPADDR, | ||
| 112 | .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | ||
| 113 | .EndpointSize = TMC_IO_EPSIZE, | ||
| 114 | .PollingIntervalMS = 0x05 | ||
| 115 | }, | ||
| 116 | |||
| 117 | .TM_DataInEndpoint = | ||
| 118 | { | ||
| 119 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | ||
| 120 | |||
| 121 | .EndpointAddress = TMC_IN_EPADDR, | ||
| 122 | .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | ||
| 123 | .EndpointSize = TMC_IO_EPSIZE, | ||
| 124 | .PollingIntervalMS = 0x05 | ||
| 125 | }, | ||
| 126 | |||
| 127 | .TM_NotificationEndpoint = | ||
| 128 | { | ||
| 129 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | ||
| 130 | |||
| 131 | .EndpointAddress = TMC_NOTIFICATION_EPADDR, | ||
| 132 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | ||
| 133 | .EndpointSize = TMC_NOTIFICATION_EPSIZE, | ||
| 134 | .PollingIntervalMS = 0xFF | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | |||
| 138 | /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests | ||
| 139 | * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate | ||
| 140 | * via the language ID table available at USB.org what languages the device supports for its string descriptors. | ||
| 141 | */ | ||
| 142 | const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG); | ||
| 143 | |||
| 144 | /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable | ||
| 145 | * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device | ||
| 146 | * Descriptor. | ||
| 147 | */ | ||
| 148 | const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera"); | ||
| 149 | |||
| 150 | /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, | ||
| 151 | * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device | ||
| 152 | * Descriptor. | ||
| 153 | */ | ||
| 154 | const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA TMC Demo"); | ||
| 155 | |||
| 156 | /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" | ||
| 157 | * documentation) by the application code so that the address and size of a requested descriptor can be given | ||
| 158 | * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function | ||
| 159 | * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the | ||
| 160 | * USB host. | ||
| 161 | */ | ||
| 162 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | ||
| 163 | const uint16_t wIndex, | ||
| 164 | const void** const DescriptorAddress) | ||
| 165 | { | ||
| 166 | const uint8_t DescriptorType = (wValue >> 8); | ||
| 167 | const uint8_t DescriptorNumber = (wValue & 0xFF); | ||
| 168 | |||
| 169 | const void* Address = NULL; | ||
| 170 | uint16_t Size = NO_DESCRIPTOR; | ||
| 171 | |||
| 172 | switch (DescriptorType) | ||
| 173 | { | ||
| 174 | case DTYPE_Device: | ||
| 175 | Address = &DeviceDescriptor; | ||
| 176 | Size = sizeof(USB_Descriptor_Device_t); | ||
| 177 | break; | ||
| 178 | case DTYPE_Configuration: | ||
| 179 | Address = &ConfigurationDescriptor; | ||
| 180 | Size = sizeof(USB_Descriptor_Configuration_t); | ||
| 181 | break; | ||
| 182 | case DTYPE_String: | ||
| 183 | switch (DescriptorNumber) | ||
| 184 | { | ||
| 185 | case STRING_ID_Language: | ||
| 186 | Address = &LanguageString; | ||
| 187 | Size = pgm_read_byte(&LanguageString.Header.Size); | ||
| 188 | break; | ||
| 189 | case STRING_ID_Manufacturer: | ||
| 190 | Address = &ManufacturerString; | ||
| 191 | Size = pgm_read_byte(&ManufacturerString.Header.Size); | ||
| 192 | break; | ||
| 193 | case STRING_ID_Product: | ||
| 194 | Address = &ProductString; | ||
| 195 | Size = pgm_read_byte(&ProductString.Header.Size); | ||
| 196 | break; | ||
| 197 | } | ||
| 198 | |||
| 199 | break; | ||
| 200 | } | ||
| 201 | |||
| 202 | *DescriptorAddress = Address; | ||
| 203 | return Size; | ||
| 204 | } | ||
| 205 | |||
diff --git a/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h new file mode 100644 index 000000000..628b63a50 --- /dev/null +++ b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | /* | ||
| 2 | LUFA Library | ||
| 3 | Copyright (C) Dean Camera, 2017. | ||
| 4 | |||
| 5 | dean [at] fourwalledcubicle [dot] com | ||
| 6 | www.lufa-lib.org | ||
| 7 | */ | ||
| 8 | |||
| 9 | /* | ||
| 10 | Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) | ||
| 11 | Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com) | ||
| 12 | |||
| 13 | Permission to use, copy, modify, distribute, and sell this | ||
| 14 | software and its documentation for any purpose is hereby granted | ||
| 15 | without fee, provided that the above copyright notice appear in | ||
| 16 | all copies and that both that the copyright notice and this | ||
| 17 | permission notice and warranty disclaimer appear in supporting | ||
| 18 | documentation, and that the name of the author not be used in | ||
| 19 | advertising or publicity pertaining to distribution of the | ||
| 20 | software without specific, written prior permission. | ||
| 21 | |||
| 22 | The author disclaims all warranties with regard to this | ||
| 23 | software, including all implied warranties of merchantability | ||
| 24 | and fitness. In no event shall the author be liable for any | ||
| 25 | special, indirect or consequential damages or any damages | ||
| 26 | whatsoever resulting from loss of use, data or profits, whether | ||
| 27 | in an action of contract, negligence or other tortious action, | ||
| 28 | arising out of or in connection with the use or performance of | ||
| 29 | this software. | ||
| 30 | */ | ||
| 31 | |||
| 32 | /** \file | ||
| 33 | * | ||
| 34 | * Header file for Descriptors.c. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #ifndef _DESCRIPTORS_H_ | ||
| 38 | #define _DESCRIPTORS_H_ | ||
| 39 | |||
| 40 | /* Includes: */ | ||
| 41 | #include <avr/pgmspace.h> | ||
| 42 | |||
| 43 | #include <LUFA/Drivers/USB/USB.h> | ||
| 44 | |||
| 45 | /* Macros: */ | ||
| 46 | /** Endpoint address of the TMC notification IN endpoint. */ | ||
| 47 | #define TMC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) | ||
| 48 | |||
| 49 | /** Endpoint address of the TMC device-to-host data IN endpoint. */ | ||
| 50 | #define TMC_IN_EPADDR (ENDPOINT_DIR_IN | 3) | ||
| 51 | |||
| 52 | /** Endpoint address of the TMC host-to-device data OUT endpoint. */ | ||
| 53 | #define TMC_OUT_EPADDR (ENDPOINT_DIR_OUT | 4) | ||
| 54 | |||
| 55 | /** Size in bytes of the TMC data endpoints. */ | ||
| 56 | #define TMC_IO_EPSIZE 64 | ||
| 57 | |||
| 58 | /** Size in bytes of the TMC notification endpoint. */ | ||
| 59 | #define TMC_NOTIFICATION_EPSIZE 8 | ||
| 60 | |||
| 61 | /* Type Defines: */ | ||
| 62 | /** Type define for the device configuration descriptor structure. This must be defined in the | ||
| 63 | * application code, as the configuration descriptor contains several sub-descriptors which | ||
| 64 | * vary between devices, and which describe the device's usage to the host. | ||
| 65 | */ | ||
| 66 | typedef struct | ||
| 67 | { | ||
| 68 | USB_Descriptor_Configuration_Header_t Config; | ||
| 69 | |||
| 70 | // Test and Measurement Interface | ||
| 71 | USB_Descriptor_Interface_t TM_Interface; | ||
| 72 | USB_Descriptor_Endpoint_t TM_DataOutEndpoint; | ||
| 73 | USB_Descriptor_Endpoint_t TM_DataInEndpoint; | ||
| 74 | USB_Descriptor_Endpoint_t TM_NotificationEndpoint; | ||
| 75 | } USB_Descriptor_Configuration_t; | ||
| 76 | |||
| 77 | /** Enum for the device interface descriptor IDs within the device. Each interface descriptor | ||
| 78 | * should have a unique ID index associated with it, which can be used to refer to the | ||
| 79 | * interface from other descriptors. | ||
| 80 | */ | ||
| 81 | enum InterfaceDescriptors_t | ||
| 82 | { | ||
| 83 | INTERFACE_ID_TestAndMeasurement = 0, /**< Test and measurement interface descriptor ID */ | ||
| 84 | }; | ||
| 85 | |||
| 86 | /** Enum for the device string descriptor IDs within the device. Each string descriptor should | ||
| 87 | * have a unique ID index associated with it, which can be used to refer to the string from | ||
| 88 | * other descriptors. | ||
| 89 | */ | ||
| 90 | enum StringDescriptors_t | ||
| 91 | { | ||
| 92 | STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */ | ||
| 93 | STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */ | ||
| 94 | STRING_ID_Product = 2, /**< Product string ID */ | ||
| 95 | }; | ||
| 96 | |||
| 97 | /* Function Prototypes: */ | ||
| 98 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | ||
| 99 | const uint16_t wIndex, | ||
| 100 | const void** const DescriptorAddress) | ||
| 101 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); | ||
| 102 | |||
| 103 | #endif | ||
| 104 | |||
diff --git a/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c new file mode 100644 index 000000000..c324be2d1 --- /dev/null +++ b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c | |||
| @@ -0,0 +1,476 @@ | |||
| 1 | /* | ||
| 2 | LUFA Library | ||
| 3 | Copyright (C) Dean Camera, 2017. | ||
| 4 | |||
| 5 | dean [at] fourwalledcubicle [dot] com | ||
| 6 | www.lufa-lib.org | ||
| 7 | */ | ||
| 8 | |||
| 9 | /* | ||
| 10 | Copyright 2017 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 disclaims 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 "TestAndMeasurement.h" | ||
| 32 | |||
| 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. | ||
| 36 | */ | ||
| 37 | TMC_Capabilities_t Capabilities = | ||
| 38 | { | ||
| 39 | .Status = TMC_STATUS_SUCCESS, | ||
| 40 | .TMCVersion = VERSION_BCD(1.00), | ||
| 41 | |||
| 42 | .Interface = | ||
| 43 | { | ||
| 44 | .ListenOnly = false, | ||
| 45 | .TalkOnly = false, | ||
| 46 | .PulseIndicateSupported = false, | ||
| 47 | }, | ||
| 48 | |||
| 49 | .Device = | ||
| 50 | { | ||
| 51 | .SupportsAbortINOnMatch = false, | ||
| 52 | }, | ||
| 53 | }; | ||
| 54 | |||
| 55 | /** Current TMC control request that is being processed */ | ||
| 56 | static uint8_t RequestInProgress = 0; | ||
| 57 | |||
| 58 | /** Stream callback abort flag for bulk IN data */ | ||
| 59 | static bool IsTMCBulkINReset = false; | ||
| 60 | |||
| 61 | /** Stream callback abort flag for bulk OUT data */ | ||
| 62 | static bool IsTMCBulkOUTReset = false; | ||
| 63 | |||
| 64 | /** Last used tag value for data transfers */ | ||
| 65 | static uint8_t CurrentTransferTag = 0; | ||
| 66 | |||
| 67 | /** Length of last data transfer, for reporting to the host in case an in-progress transfer is aborted */ | ||
| 68 | static uint16_t LastTransferLength = 0; | ||
| 69 | |||
| 70 | /** Buffer to hold the next message to sent to the TMC host */ | ||
| 71 | static uint8_t NextResponseBuffer[64]; | ||
| 72 | |||
| 73 | /** Indicates the length of the next response to send */ | ||
| 74 | static uint8_t NextResponseLen; | ||
| 75 | |||
| 76 | /** Main program entry point. This routine contains the overall program flow, including initial | ||
| 77 | * setup of all components and the main program loop. | ||
| 78 | */ | ||
| 79 | int main(void) | ||
| 80 | { | ||
| 81 | SetupHardware(); | ||
| 82 | |||
| 83 | LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); | ||
| 84 | GlobalInterruptEnable(); | ||
| 85 | |||
| 86 | for (;;) | ||
| 87 | { | ||
| 88 | TMC_Task(); | ||
| 89 | USB_USBTask(); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | /** Configures the board hardware and chip peripherals for the demo's functionality. */ | ||
| 94 | void SetupHardware(void) | ||
| 95 | { | ||
| 96 | #if (ARCH == ARCH_AVR8) | ||
| 97 | /* Disable watchdog if enabled by bootloader/fuses */ | ||
| 98 | MCUSR &= ~(1 << WDRF); | ||
| 99 | wdt_disable(); | ||
| 100 | |||
| 101 | /* Disable clock division */ | ||
| 102 | clock_prescale_set(clock_div_1); | ||
| 103 | #elif (ARCH == ARCH_XMEGA) | ||
| 104 | /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */ | ||
| 105 | XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU); | ||
| 106 | XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL); | ||
| 107 | |||
| 108 | /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */ | ||
| 109 | XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); | ||
| 110 | XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); | ||
| 111 | |||
| 112 | PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; | ||
| 113 | #endif | ||
| 114 | |||
| 115 | /* Hardware Initialization */ | ||
| 116 | LEDs_Init(); | ||
| 117 | USB_Init(); | ||
| 118 | } | ||
| 119 | |||
| 120 | /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and | ||
| 121 | * starts the library USB task to begin the enumeration and USB management process. | ||
| 122 | */ | ||
| 123 | void EVENT_USB_Device_Connect(void) | ||
| 124 | { | ||
| 125 | LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); | ||
| 126 | } | ||
| 127 | |||
| 128 | /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via | ||
| 129 | * the status LEDs and stops the USB management and CDC management tasks. | ||
| 130 | */ | ||
| 131 | void EVENT_USB_Device_Disconnect(void) | ||
| 132 | { | ||
| 133 | LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); | ||
| 134 | } | ||
| 135 | |||
| 136 | /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration | ||
| 137 | * of the USB device after enumeration - the device endpoints are configured and the CDC management task started. | ||
| 138 | */ | ||
| 139 | void EVENT_USB_Device_ConfigurationChanged(void) | ||
| 140 | { | ||
| 141 | bool ConfigSuccess = true; | ||
| 142 | |||
| 143 | /* Setup TMC In, Out and Notification Endpoints */ | ||
| 144 | ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, TMC_IO_EPSIZE, 1); | ||
| 145 | ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_IN_EPADDR, EP_TYPE_BULK, TMC_IO_EPSIZE, 1); | ||
| 146 | ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_OUT_EPADDR, EP_TYPE_BULK, TMC_IO_EPSIZE, 1); | ||
| 147 | |||
| 148 | /* Indicate endpoint configuration success or failure */ | ||
| 149 | LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); | ||
| 150 | } | ||
| 151 | |||
| 152 | /** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to | ||
| 153 | * the device from the USB host before passing along unhandled control requests to the library for processing | ||
| 154 | * internally. | ||
| 155 | */ | ||
| 156 | void EVENT_USB_Device_ControlRequest(void) | ||
| 157 | { | ||
| 158 | uint8_t TMCRequestStatus = TMC_STATUS_SUCCESS; | ||
| 159 | |||
| 160 | /* Process TMC specific control requests */ | ||
| 161 | switch (USB_ControlRequest.bRequest) | ||
| 162 | { | ||
| 163 | case Req_InitiateAbortBulkOut: | ||
| 164 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) | ||
| 165 | { | ||
| 166 | /* Check that no split transaction is already in progress and the data transfer tag is valid */ | ||
| 167 | if (RequestInProgress != 0) | ||
| 168 | { | ||
| 169 | TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS; | ||
| 170 | } | ||
| 171 | else if (USB_ControlRequest.wValue != CurrentTransferTag) | ||
| 172 | { | ||
| 173 | TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS; | ||
| 174 | } | ||
| 175 | else | ||
| 176 | { | ||
| 177 | /* Indicate that all in-progress/pending data OUT requests should be aborted */ | ||
| 178 | IsTMCBulkOUTReset = true; | ||
| 179 | |||
| 180 | /* Save the split request for later checking when a new request is received */ | ||
| 181 | RequestInProgress = Req_InitiateAbortBulkOut; | ||
| 182 | } | ||
| 183 | |||
| 184 | Endpoint_ClearSETUP(); | ||
| 185 | |||
| 186 | /* Write the request response byte */ | ||
| 187 | Endpoint_Write_8(TMCRequestStatus); | ||
| 188 | |||
| 189 | Endpoint_ClearIN(); | ||
| 190 | Endpoint_ClearStatusStage(); | ||
| 191 | } | ||
| 192 | |||
| 193 | break; | ||
| 194 | case Req_CheckAbortBulkOutStatus: | ||
| 195 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) | ||
| 196 | { | ||
| 197 | /* Check that an ABORT BULK OUT transaction has been requested and that the request has completed */ | ||
| 198 | if (RequestInProgress != Req_InitiateAbortBulkOut) | ||
| 199 | TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS; | ||
| 200 | else if (IsTMCBulkOUTReset) | ||
| 201 | TMCRequestStatus = TMC_STATUS_PENDING; | ||
| 202 | else | ||
| 203 | RequestInProgress = 0; | ||
| 204 | |||
| 205 | Endpoint_ClearSETUP(); | ||
| 206 | |||
| 207 | /* Write the request response bytes */ | ||
| 208 | Endpoint_Write_8(TMCRequestStatus); | ||
| 209 | Endpoint_Write_16_LE(0); | ||
| 210 | Endpoint_Write_32_LE(LastTransferLength); | ||
| 211 | |||
| 212 | Endpoint_ClearIN(); | ||
| 213 | Endpoint_ClearStatusStage(); | ||
| 214 | } | ||
| 215 | |||
| 216 | break; | ||
| 217 | case Req_InitiateAbortBulkIn: | ||
| 218 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) | ||
| 219 | { | ||
| 220 | /* Check that no split transaction is already in progress and the data transfer tag is valid */ | ||
| 221 | if (RequestInProgress != 0) | ||
| 222 | { | ||
| 223 | TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS; | ||
| 224 | } | ||
| 225 | else if (USB_ControlRequest.wValue != CurrentTransferTag) | ||
| 226 | { | ||
| 227 | TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS; | ||
| 228 | } | ||
| 229 | else | ||
| 230 | { | ||
| 231 | /* Indicate that all in-progress/pending data IN requests should be aborted */ | ||
| 232 | IsTMCBulkINReset = true; | ||
| 233 | |||
| 234 | /* Save the split request for later checking when a new request is received */ | ||
| 235 | RequestInProgress = Req_InitiateAbortBulkIn; | ||
| 236 | } | ||
| 237 | |||
| 238 | Endpoint_ClearSETUP(); | ||
| 239 | |||
| 240 | /* Write the request response bytes */ | ||
| 241 | Endpoint_Write_8(TMCRequestStatus); | ||
| 242 | Endpoint_Write_8(CurrentTransferTag); | ||
| 243 | |||
| 244 | Endpoint_ClearIN(); | ||
| 245 | Endpoint_ClearStatusStage(); | ||
| 246 | } | ||
| 247 | |||
| 248 | break; | ||
| 249 | case Req_CheckAbortBulkInStatus: | ||
| 250 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) | ||
| 251 | { | ||
| 252 | /* Check that an ABORT BULK IN transaction has been requested and that the request has completed */ | ||
| 253 | if (RequestInProgress != Req_InitiateAbortBulkIn) | ||
| 254 | TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS; | ||
| 255 | else if (IsTMCBulkINReset) | ||
| 256 | TMCRequestStatus = TMC_STATUS_PENDING; | ||
| 257 | else | ||
| 258 | RequestInProgress = 0; | ||
| 259 | |||
| 260 | Endpoint_ClearSETUP(); | ||
| 261 | |||
| 262 | /* Write the request response bytes */ | ||
| 263 | Endpoint_Write_8(TMCRequestStatus); | ||
| 264 | Endpoint_Write_16_LE(0); | ||
| 265 | Endpoint_Write_32_LE(LastTransferLength); | ||
| 266 | |||
| 267 | Endpoint_ClearIN(); | ||
| 268 | Endpoint_ClearStatusStage(); | ||
| 269 | } | ||
| 270 | |||
| 271 | break; | ||
| 272 | case Req_InitiateClear: | ||
| 273 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) | ||
| 274 | { | ||
| 275 | /* Check that no split transaction is already in progress */ | ||
| 276 | if (RequestInProgress != 0) | ||
| 277 | { | ||
| 278 | Endpoint_Write_8(TMC_STATUS_SPLIT_IN_PROGRESS); | ||
| 279 | } | ||
| 280 | else | ||
| 281 | { | ||
| 282 | /* Indicate that all in-progress/pending data IN and OUT requests should be aborted */ | ||
| 283 | IsTMCBulkINReset = true; | ||
| 284 | IsTMCBulkOUTReset = true; | ||
| 285 | |||
| 286 | /* Save the split request for later checking when a new request is received */ | ||
| 287 | RequestInProgress = Req_InitiateClear; | ||
| 288 | } | ||
| 289 | |||
| 290 | Endpoint_ClearSETUP(); | ||
| 291 | |||
| 292 | /* Write the request response byte */ | ||
| 293 | Endpoint_Write_8(TMCRequestStatus); | ||
| 294 | |||
| 295 | Endpoint_ClearIN(); | ||
| 296 | Endpoint_ClearStatusStage(); | ||
| 297 | } | ||
| 298 | |||
| 299 | break; | ||
| 300 | case Req_CheckClearStatus: | ||
| 301 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) | ||
| 302 | { | ||
| 303 | /* Check that a CLEAR transaction has been requested and that the request has completed */ | ||
| 304 | if (RequestInProgress != Req_InitiateClear) | ||
| 305 | TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS; | ||
| 306 | else if (IsTMCBulkINReset || IsTMCBulkOUTReset) | ||
| 307 | TMCRequestStatus = TMC_STATUS_PENDING; | ||
| 308 | else | ||
| 309 | RequestInProgress = 0; | ||
| 310 | |||
| 311 | Endpoint_ClearSETUP(); | ||
| 312 | |||
| 313 | /* Write the request response bytes */ | ||
| 314 | Endpoint_Write_8(TMCRequestStatus); | ||
| 315 | Endpoint_Write_8(0); | ||
| 316 | |||
| 317 | Endpoint_ClearIN(); | ||
| 318 | Endpoint_ClearStatusStage(); | ||
| 319 | } | ||
| 320 | |||
| 321 | break; | ||
| 322 | case Req_GetCapabilities: | ||
| 323 | if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) | ||
| 324 | { | ||
| 325 | Endpoint_ClearSETUP(); | ||
| 326 | |||
| 327 | /* Write the device capabilities to the control endpoint */ | ||
| 328 | Endpoint_Write_Control_Stream_LE(&Capabilities, sizeof(TMC_Capabilities_t)); | ||
| 329 | Endpoint_ClearOUT(); | ||
| 330 | } | ||
| 331 | |||
| 332 | break; | ||
| 333 | } | ||
| 334 | } | ||
| 335 | |||
| 336 | void ProcessSentMessage(uint8_t* const Data, const uint8_t Length) | ||
| 337 | { | ||
| 338 | if (strncmp((char*)Data, "*IDN?", 5) == 0) | ||
| 339 | strcpy((char*)NextResponseBuffer, "LUFA TMC DEMO"); | ||
| 340 | |||
| 341 | NextResponseLen = strlen((char*)NextResponseBuffer); | ||
| 342 | } | ||
| 343 | |||
| 344 | uint8_t GetNextMessage(uint8_t* const Data) | ||
| 345 | { | ||
| 346 | strcpy((char*)NextResponseBuffer, "LUFA TMC DEMO"); | ||
| 347 | |||
| 348 | NextResponseLen = strlen((char*)NextResponseBuffer); | ||
| 349 | // --- | ||
| 350 | uint8_t DataLen = MIN(NextResponseLen, 64); | ||
| 351 | |||
| 352 | strlcpy((char*)Data, (char*)NextResponseBuffer, DataLen); | ||
| 353 | |||
| 354 | return DataLen; | ||
| 355 | } | ||
| 356 | |||
| 357 | /** Function to manage TMC data transmission and reception to and from the host. */ | ||
| 358 | void TMC_Task(void) | ||
| 359 | { | ||
| 360 | /* Device must be connected and configured for the task to run */ | ||
| 361 | if (USB_DeviceState != DEVICE_STATE_Configured) | ||
| 362 | return; | ||
| 363 | |||
| 364 | TMC_MessageHeader_t MessageHeader; | ||
| 365 | uint8_t MessagePayload[128]; | ||
| 366 | |||
| 367 | /* Try to read in a TMC message from the interface, process if one is available */ | ||
| 368 | if (ReadTMCHeader(&MessageHeader)) | ||
| 369 | { | ||
| 370 | /* Indicate busy */ | ||
| 371 | LEDs_SetAllLEDs(LEDMASK_USB_BUSY); | ||
| 372 | |||
| 373 | switch (MessageHeader.MessageID) | ||
| 374 | { | ||
| 375 | case TMC_MESSAGEID_DEV_DEP_MSG_OUT: | ||
| 376 | LastTransferLength = 0; | ||
| 377 | while (Endpoint_Read_Stream_LE(MessagePayload, MIN(MessageHeader.TransferSize, sizeof(MessagePayload)), &LastTransferLength) == | ||
| 378 | ENDPOINT_RWSTREAM_IncompleteTransfer) | ||
| 379 | { | ||
| 380 | if (IsTMCBulkOUTReset) | ||
| 381 | break; | ||
| 382 | } | ||
| 383 | |||
| 384 | Endpoint_ClearOUT(); | ||
| 385 | |||
| 386 | ProcessSentMessage(MessagePayload, LastTransferLength); | ||
| 387 | break; | ||
| 388 | case TMC_MESSAGEID_DEV_DEP_MSG_IN: | ||
| 389 | Endpoint_ClearOUT(); | ||
| 390 | |||
| 391 | MessageHeader.TransferSize = GetNextMessage(MessagePayload); | ||
| 392 | MessageHeader.MessageIDSpecific.DeviceOUT.LastMessageTransaction = true; | ||
| 393 | WriteTMCHeader(&MessageHeader); | ||
| 394 | |||
| 395 | LastTransferLength = 0; | ||
| 396 | while (Endpoint_Write_Stream_LE(MessagePayload, MessageHeader.TransferSize, &LastTransferLength) == | ||
| 397 | ENDPOINT_RWSTREAM_IncompleteTransfer) | ||
| 398 | { | ||
| 399 | if (IsTMCBulkINReset) | ||
| 400 | break; | ||
| 401 | } | ||
| 402 | |||
| 403 | Endpoint_ClearIN(); | ||
| 404 | break; | ||
| 405 | default: | ||
| 406 | Endpoint_StallTransaction(); | ||
| 407 | break; | ||
| 408 | } | ||
| 409 | |||
| 410 | LEDs_SetAllLEDs(LEDMASK_USB_READY); | ||
| 411 | } | ||
| 412 | |||
| 413 | /* All pending data has been processed - reset the data abort flags */ | ||
| 414 | IsTMCBulkINReset = false; | ||
| 415 | IsTMCBulkOUTReset = false; | ||
| 416 | } | ||
| 417 | |||
| 418 | /** Attempts to read in the TMC message header from the TMC interface. | ||
| 419 | * | ||
| 420 | * \param[out] MessageHeader Pointer to a location where the read header (if any) should be stored | ||
| 421 | * | ||
| 422 | * \return Boolean \c true if a header was read, \c false otherwise | ||
| 423 | */ | ||
| 424 | bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader) | ||
| 425 | { | ||
| 426 | uint16_t BytesTransferred; | ||
| 427 | uint8_t ErrorCode; | ||
| 428 | |||
| 429 | /* Select the Data Out endpoint */ | ||
| 430 | Endpoint_SelectEndpoint(TMC_OUT_EPADDR); | ||
| 431 | |||
| 432 | /* Abort if no command has been sent from the host */ | ||
| 433 | if (!(Endpoint_IsOUTReceived())) | ||
| 434 | return false; | ||
| 435 | |||
| 436 | /* Read in the header of the command from the host */ | ||
| 437 | BytesTransferred = 0; | ||
| 438 | while ((ErrorCode = Endpoint_Read_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) == | ||
| 439 | ENDPOINT_RWSTREAM_IncompleteTransfer) | ||
| 440 | { | ||
| 441 | if (IsTMCBulkOUTReset) | ||
| 442 | break; | ||
| 443 | } | ||
| 444 | |||
| 445 | /* Store the new command tag value for later use */ | ||
| 446 | CurrentTransferTag = MessageHeader->Tag; | ||
| 447 | |||
| 448 | /* Indicate if the command has been aborted or not */ | ||
| 449 | return (!(IsTMCBulkOUTReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError)); | ||
| 450 | } | ||
| 451 | |||
| 452 | bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader) | ||
| 453 | { | ||
| 454 | uint16_t BytesTransferred; | ||
| 455 | uint8_t ErrorCode; | ||
| 456 | |||
| 457 | /* Set the message tag of the command header */ | ||
| 458 | MessageHeader->Tag = CurrentTransferTag; | ||
| 459 | MessageHeader->InverseTag = ~CurrentTransferTag; | ||
| 460 | |||
| 461 | /* Select the Data In endpoint */ | ||
| 462 | Endpoint_SelectEndpoint(TMC_IN_EPADDR); | ||
| 463 | |||
| 464 | /* Send the command header to the host */ | ||
| 465 | BytesTransferred = 0; | ||
| 466 | while ((ErrorCode = Endpoint_Write_Stream_LE(MessageHeader, sizeof(TMC_MessageHeader_t), &BytesTransferred)) == | ||
| 467 | ENDPOINT_RWSTREAM_IncompleteTransfer) | ||
| 468 | { | ||
| 469 | if (IsTMCBulkINReset) | ||
| 470 | break; | ||
| 471 | } | ||
| 472 | |||
| 473 | /* Indicate if the command has been aborted or not */ | ||
| 474 | return (!(IsTMCBulkINReset) && (ErrorCode == ENDPOINT_RWSTREAM_NoError)); | ||
| 475 | } | ||
| 476 | |||
diff --git a/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h new file mode 100644 index 000000000..50e865bed --- /dev/null +++ b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h | |||
| @@ -0,0 +1,150 @@ | |||
| 1 | /* | ||
| 2 | LUFA Library | ||
| 3 | Copyright (C) Dean Camera, 2017. | ||
| 4 | |||
| 5 | dean [at] fourwalledcubicle [dot] com | ||
| 6 | www.lufa-lib.org | ||
| 7 | */ | ||
| 8 | |||
| 9 | /* | ||
| 10 | Copyright 2017 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 disclaims 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 | #ifndef _TESTANDMEASUREMENT_H_ | ||
| 32 | #define _TESTANDMEASUREMENT_H_ | ||
| 33 | |||
| 34 | /* Includes: */ | ||
| 35 | #include <avr/io.h> | ||
| 36 | #include <avr/wdt.h> | ||
| 37 | #include <avr/power.h> | ||
| 38 | #include <avr/interrupt.h> | ||
| 39 | |||
| 40 | #include "Descriptors.h" | ||
| 41 | |||
| 42 | #include <LUFA/Drivers/Board/LEDs.h> | ||
| 43 | #include <LUFA/Drivers/USB/USB.h> | ||
| 44 | #include <LUFA/Platform/Platform.h> | ||
| 45 | |||
| 46 | /* Macros: */ | ||
| 47 | /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ | ||
| 48 | #define LEDMASK_USB_NOTREADY LEDS_LED1 | ||
| 49 | |||
| 50 | /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ | ||
| 51 | #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) | ||
| 52 | |||
| 53 | /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ | ||
| 54 | #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) | ||
| 55 | |||
| 56 | /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ | ||
| 57 | #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) | ||
| 58 | |||
| 59 | /** LED mask for the library LED driver, to indicate that the USB interface is busy. */ | ||
| 60 | #define LEDMASK_USB_BUSY LEDS_LED2 | ||
| 61 | |||
| 62 | #define Req_InitiateAbortBulkOut 0x01 | ||
| 63 | #define Req_CheckAbortBulkOutStatus 0x02 | ||
| 64 | #define Req_InitiateAbortBulkIn 0x03 | ||
| 65 | #define Req_CheckAbortBulkInStatus 0x04 | ||
| 66 | #define Req_InitiateClear 0x05 | ||
| 67 | #define Req_CheckClearStatus 0x06 | ||
| 68 | #define Req_GetCapabilities 0x07 | ||
| 69 | #define Req_IndicatorPulse 0x40 | ||
| 70 | |||
| 71 | #define TMC_STATUS_SUCCESS 0x01 | ||
| 72 | #define TMC_STATUS_PENDING 0x02 | ||
| 73 | #define TMC_STATUS_FAILED 0x80 | ||
| 74 | #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81 | ||
| 75 | #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82 | ||
| 76 | #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83 | ||
| 77 | |||
| 78 | #define TMC_MESSAGEID_DEV_DEP_MSG_OUT 0x01 | ||
| 79 | #define TMC_MESSAGEID_DEV_DEP_MSG_IN 0x02 | ||
| 80 | #define TMC_MESSAGEID_DEV_VENDOR_OUT 0x7E | ||
| 81 | #define TMC_MESSAGEID_DEV_VENDOR_IN 0x7F | ||
| 82 | |||
| 83 | /* Type Defines */ | ||
| 84 | typedef struct | ||
| 85 | { | ||
| 86 | uint8_t Status; | ||
| 87 | uint8_t Reserved; | ||
| 88 | |||
| 89 | uint16_t TMCVersion; | ||
| 90 | |||
| 91 | struct | ||
| 92 | { | ||
| 93 | unsigned ListenOnly : 1; | ||
| 94 | unsigned TalkOnly : 1; | ||
| 95 | unsigned PulseIndicateSupported : 1; | ||
| 96 | unsigned Reserved : 5; | ||
| 97 | } Interface; | ||
| 98 | |||
| 99 | struct | ||
| 100 | { | ||
| 101 | unsigned SupportsAbortINOnMatch : 1; | ||
| 102 | unsigned Reserved : 7; | ||
| 103 | } Device; | ||
| 104 | |||
| 105 | uint8_t Reserved2[6]; | ||
| 106 | uint8_t Reserved3[12]; | ||
| 107 | } TMC_Capabilities_t; | ||
| 108 | |||
| 109 | typedef struct | ||
| 110 | { | ||
| 111 | uint8_t LastMessageTransaction; | ||
| 112 | uint8_t TermChar; | ||
| 113 | uint8_t Reserved[2]; | ||
| 114 | } TMC_DevOUTMessageHeader_t; | ||
| 115 | |||
| 116 | typedef struct | ||
| 117 | { | ||
| 118 | uint8_t LastMessageTransaction; | ||
| 119 | uint8_t Reserved[3]; | ||
| 120 | } TMC_DevINMessageHeader_t; | ||
| 121 | |||
| 122 | typedef struct | ||
| 123 | { | ||
| 124 | uint8_t MessageID; | ||
| 125 | uint8_t Tag; | ||
| 126 | uint8_t InverseTag; | ||
| 127 | uint8_t Reserved; | ||
| 128 | uint32_t TransferSize; | ||
| 129 | |||
| 130 | union | ||
| 131 | { | ||
| 132 | TMC_DevOUTMessageHeader_t DeviceOUT; | ||
| 133 | TMC_DevINMessageHeader_t DeviceIN; | ||
| 134 | uint32_t VendorSpecific; | ||
| 135 | } MessageIDSpecific; | ||
| 136 | } TMC_MessageHeader_t; | ||
| 137 | |||
| 138 | /* Function Prototypes: */ | ||
| 139 | void SetupHardware(void); | ||
| 140 | void TMC_Task(void); | ||
| 141 | bool ReadTMCHeader(TMC_MessageHeader_t* const MessageHeader); | ||
| 142 | bool WriteTMCHeader(TMC_MessageHeader_t* const MessageHeader); | ||
| 143 | |||
| 144 | void EVENT_USB_Device_Connect(void); | ||
| 145 | void EVENT_USB_Device_Disconnect(void); | ||
| 146 | void EVENT_USB_Device_ConfigurationChanged(void); | ||
| 147 | void EVENT_USB_Device_ControlRequest(void); | ||
| 148 | |||
| 149 | #endif | ||
| 150 | |||
diff --git a/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/makefile b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/makefile new file mode 100644 index 000000000..e0d89ccd7 --- /dev/null +++ b/lib/lufa/Demos/Device/Incomplete/TestAndMeasurement/makefile | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | # | ||
| 2 | # LUFA Library | ||
| 3 | # Copyright (C) Dean Camera, 2017. | ||
| 4 | # | ||
| 5 | # dean [at] fourwalledcubicle [dot] com | ||
| 6 | # www.lufa-lib.org | ||
| 7 | # | ||
| 8 | # -------------------------------------- | ||
| 9 | # LUFA Project Makefile. | ||
| 10 | # -------------------------------------- | ||
| 11 | |||
| 12 | # Run "make help" for target help. | ||
| 13 | |||
| 14 | MCU = at90usb1287 | ||
| 15 | ARCH = AVR8 | ||
| 16 | BOARD = USBKEY | ||
| 17 | F_CPU = 8000000 | ||
| 18 | F_USB = $(F_CPU) | ||
| 19 | OPTIMIZATION = s | ||
| 20 | TARGET = TestAndMeasurement | ||
| 21 | SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) | ||
| 22 | LUFA_PATH = ../../../../LUFA | ||
| 23 | CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ | ||
| 24 | LD_FLAGS = | ||
| 25 | |||
| 26 | # Default target | ||
| 27 | all: | ||
| 28 | |||
| 29 | # Include LUFA-specific DMBS extension modules | ||
| 30 | DMBS_LUFA_PATH ?= $(LUFA_PATH)/Build/LUFA | ||
| 31 | include $(DMBS_LUFA_PATH)/lufa-sources.mk | ||
| 32 | include $(DMBS_LUFA_PATH)/lufa-gcc.mk | ||
| 33 | |||
| 34 | # Include common DMBS build system modules | ||
| 35 | DMBS_PATH ?= $(LUFA_PATH)/Build/DMBS/DMBS | ||
| 36 | include $(DMBS_PATH)/core.mk | ||
| 37 | include $(DMBS_PATH)/cppcheck.mk | ||
| 38 | include $(DMBS_PATH)/doxygen.mk | ||
| 39 | include $(DMBS_PATH)/dfu.mk | ||
| 40 | include $(DMBS_PATH)/gcc.mk | ||
| 41 | include $(DMBS_PATH)/hid.mk | ||
| 42 | include $(DMBS_PATH)/avrdude.mk | ||
| 43 | include $(DMBS_PATH)/atprogram.mk | ||
