/* ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef MCUCONF_H #define MCUCONF_H /* * SPC564Axx drivers configuration. * The following settings override the default settings present in * the various device driver implementation headers. * Note that the settings for each driver only have effect if the whole * driver is enabled in halconf.h. * * IRQ priorities: * 1...15 Lowest...Highest. * DMA priorities: * 0...15 Highest...Lowest. */ #define SPC564Axx_MCUCONF /* * HAL driver system settings. */ #define SPC5_NO_INIT FALSE #define SPC5_CLK_BYPASS FALSE #define SPC5_ALLOW_OVERCLOCK FALSE #define SPC5_CLK_PREDIV_VALUE 2 #define SPC5_CLK_MFD_VALUE 75 #define SPC5_CLK_RFD SPC5_RFD_DIV2 #define SPC5_FLASH_BIUCR (BIUCR_BANK1_TOO | \ BIUCR_MASTER4_PREFETCH | \ BIUCR_MASTER0_PREFETCH | \ BIUCR_DPFEN | \ BIUCR_IPFEN | \ BIUCR_PFLIM_ON_MISS | \ BIUCR_BFEN) #define SPC5_EMIOS_GPRE_VALUE 20 /* * EDMA driver settings. */ #define SPC5_EDMA_CR_SETTING (EDMA_CR_GRP3PRI(3) | \ EDMA_CR_GRP2PRI(2) | \ EDMA_CR_GRP1PRI(1) | \ EDMA_CR_GRP0PRI(0) | \ EDMA_CR_EMLM | \ EDMA_CR_ERGA) #define SPC5_EDMA_GROUP0_PRIORITIES 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 #define SPC5_EDMA_GROUP1_PRIORITIES 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 #define SPC5_EDMA_GROUP2_PRIORITIES 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 #define SPC5_EDMA_GROUP3_PRIORITIES 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 #define SPC5_EDMA_ERROR_IRQ_PRIO 12 #define SPC5_EDMA_ERROR_HANDLER() osalSysHalt("DMA failure") /* * ADC driver settings. */ #define SPC5_ADC_USE_ADC0_Q0 FALSE #define SPC5_ADC_USE_ADC0_Q1 FALSE #define SPC5_ADC_USE_ADC0_Q2 FALSE #define SPC5_ADC_USE_ADC1_Q3 FALSE #define SPC5_ADC_USE_ADC1_Q4 FALSE #define SPC5_ADC_USE_ADC1_Q5 FALSE #define SPC5_ADC_FIFO0_DMA_IRQ_PRIO 12 #define SPC5_ADC_FIFO1_DMA_IRQ_PRIO 12 #define SPC5_ADC_FIFO2_DMA_IRQ_PRIO 12 #define SPC5_ADC_FIFO3_DMA_IRQ_PRIO 12 #define SPC5_ADC_FIFO4_DMA_IRQ_PRIO 12 #define SPC5_ADC_FIFO5_DMA_IRQ_PRIO 12 #define SPC5_ADC_CR_CLK_PS ADC_CR_CLK_PS(5) #define SPC5_ADC_PUDCR {ADC_PUDCR_NONE,ADC_PUDCR_NONE,ADC_PUDCR_NONE,ADC_PUDCR_NONE,ADC_PUDCR_NONE,ADC_PUDCR_NONE,ADC_PUDCR_NONE,ADC_PUDCR_NONE} /* * SERIAL driver system settings. */ #define SPC5_USE_ESCIA TRUE #define SPC5_USE_ESCIB FALSE #define SPC5_USE_ESCIC FALSE #define SPC5_ESCIA_PRIORITY 8 #define SPC5_ESCIB_PRIORITY 8 #define SPC5_ESCIC_PRIORITY 8 /* * SPI driver system settings. */ #define SPC5_SPI_USE_DSPI1 FALSE #define SPC5_SPI_USE_DSPI2 FALSE #define SPC5_SPI_USE_DSPI3 FALSE #define SPC5_SPI_DMA_MODE SPC5_SPI_DMA_RX_ONLY #define SPC5_SPI_DSPI1_MCR (0 | SPC5_MCR_PCSIS0 | SPC5_MCR_PCSIS1 | SPC5_MCR_PCSIS2 | SPC5_MCR_PCSIS3 | SPC5_MCR_PCSIS4 | SPC5_MCR_PCSIS5 | SPC5_MCR_PCSIS6 | SPC5_MCR_PCSIS7) #define SPC5_SPI_DSPI2_MCR (0 | SPC5_MCR_PCSIS0 | SPC5_MCR_PCSIS1 | SPC5_MCR_PCSIS2 | SPC5_MCR_PCSIS3 | SPC5_MCR_PCSIS4 | SPC5_MCR_PCSIS5 | SPC5_MCR_PCSIS6 | SPC5_MCR_PCSIS7) #define SPC5_SPI_DSPI3_MCR (0 | SPC5_MCR_PCSIS0 | SPC5_MCR_PCSIS1 | SPC5_MCR_PCSIS2 | SPC5_MCR_PCSIS3 | SPC5_MCR_PCSIS4 | SPC5_MCR_PCSIS5 | SPC5_MCR_PCSIS6 | SPC5_MCR_PCSIS7) #define SPC5_SPI_DSPI1_DMA_IRQ_PRIO 10 #define SPC5_SPI_DSPI2_DMA_IRQ_PRIO 10 #define SPC5_SPI_DSPI3_DMA_IRQ_PRIO 10 #define SPC5_SPI_DSPI1_IRQ_PRIO 10 #define SPC5_SPI_DSPI2_IRQ_PRIO 10 #define SPC5_SPI_DSPI3_IRQ_PRIO 10 #define SPC5_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DSPI DMA failure") /* * ICU driver system settings. */ #define SPC5_ICU_USE_EMIOS_CH1 FALSE #define SPC5_ICU_USE_EMIOS_CH2 FALSE #define SPC5_ICU_USE_EMIOS_CH3 FALSE #define SPC5_ICU_USE_EMIOS_CH4 FALSE #define SPC5_ICU_USE_EMIOS_CH5 FALSE #define SPC5_ICU_USE_EMIOS_CH6 FALSE #define SPC5_ICU_USE_EMIOS_CH11 FALSE #define SPC5_ICU_USE_EMIOS_CH13 FALSE #define SPC5_ICU_USE_EMIOS_CH7 FALSE #define SPC5_ICU_USE_EMIOS_CH16 FALSE #define SPC5_ICU_USE_EMIOS_CH17 FALSE #define SPC5_ICU_USE_EMIOS_CH18 FALSE #define SPC5_EMIOS_FLAG_F1_PRIORITY 8 #define SPC5_EMIOS_FLAG_F2_PRIORITY 8 #define SPC5_EMIOS_FLAG_F3_PRIORITY 8 #define SPC5_EMIOS_FLAG_F4_PRIORITY 8 #define SPC5_EMIOS_FLAG_F5_PRIORITY 8 #define SPC5_EMIOS_FLAG_F6_PRIORITY 8 #define SPC5_EMIOS_FLAG_F11_PRIORITY 8 #define SPC5_EMIOS_FLAG_F13_PRIORITY 8 #define SPC5_EMIOS_FLAG_F7_PRIORITY 8 #define SPC5_EMIOS_FLAG_F16_PRIORITY 8 #define SPC5_EMIOS_FLAG_F17_PRIORITY 8 #define SPC5_EMIOS_FLAG_F18_PRIORITY 8 /* * PWM driver system settings. */ #define SPC5_PWM_USE_EMIOS_CH0 FALSE #define SPC5_PWM_USE_EMIOS_CH8 FALSE #define SPC5_PWM_USE_EMIOS_CH9 FALSE #define SPC5_PWM_USE_EMIOS_CH10 FALSE #define SPC5_PWM_USE_EMIOS_CH12 FALSE #define SPC5_PWM_USE_EMIOS_CH14 FALSE #define SPC5_PWM_USE_EMIOS_CH15 FALSE #define SPC5_PWM_USE_EMIOS_CH23 FALSE #define SPC5_PWM_USE_EMIOS_CH19 FALSE #define SPC5_PWM_USE_EMIOS_CH20 FALSE #define SPC5_PWM_USE_EMIOS_CH21 FALSE #define SPC5_PWM_USE_EMIOS_CH22 FALSE #define SPC5_EMIOS_FLAG_F0_PRIORITY 8 #define SPC5_EMIOS_FLAG_F8_PRIORITY 8 #define SPC5_EMIOS_FLAG_F9_PRIORITY 8 #define SPC5_EMIOS_FLAG_F10_PRIORITY 8 #define SPC5_EMIOS_FLAG_F12_PRIORITY 8 #define SPC5_EMIOS_FLAG_F14_PRIORITY 8 #define SPC5_EMIOS_FLAG_F15_PRIORITY 8 #define SPC5_EMIOS_FLAG_F23_PRIORITY 8 #define SPC5_EMIOS_FLAG_F19_PRIORITY 8 #define SPC5_EMIOS_FLAG_F20_PRIORITY 8 #define SPC5_EMIOS_FLAG_F21_PRIORITY 8 #define SPC5_EMIOS_FLAG_F22_PRIORITY 8 /* * CAN driver system settings. */ #define SPC5_CAN_USE_FILTERS FALSE #define SPC5_CAN_USE_FLEXCAN0 FALSE #define SPC5_CAN_FLEXCAN0_USE_EXT_CLK FALSE #define SPC5_CAN_FLEXCAN0_IRQ_PRIORITY 11 #define SPC5_CAN_USE_FLEXCAN1 FALSE #define SPC5_CAN_FLEXCAN1_USE_EXT_CLK FALSE #define SPC5_CAN_FLEXCAN1_IRQ_PRIORITY 11 #define SPC5_CAN_USE_FLEXCAN2 FALSE #define SPC5_CAN_FLEXCAN2_USE_EXT_CLK FALSE #define SPC5_CAN_FLEXCAN2_IRQ_PRIORITY 11 #endif /* MCUCONF_H */ 3' href='#n153'>153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
/*
             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 2012  Simon Foster (simon.foster [at] inbox [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
 *
 *  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"

/* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
 * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
 * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
 * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
 * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
 * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
 * port location).
 */
#if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
	#warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
#endif

/** 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                  = CDC_CSCP_CDCClass,
	.SubClass               = CDC_CSCP_NoSpecificSubclass,
	.Protocol               = CDC_CSCP_NoSpecificProtocol,

	.Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,

	.VendorID               = 0x03EB,
	.ProductID              = 0x204B,
	.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 | USB_CONFIG_ATTR_SELFPOWERED),

			.MaxPowerConsumption    = USB_CONFIG_POWER_MA(100)
		},

	.CDC_CCI_Interface =
		{
			.Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},

			.InterfaceNumber        = INTERFACE_ID_CDC_CCI,
			.AlternateSetting       = 0,

			.TotalEndpoints         = 1,

			.Class                  = CDC_CSCP_CDCClass,
			.SubClass               = CDC_CSCP_ACMSubclass,
			.Protocol               = CDC_CSCP_ATCommandProtocol,

			.InterfaceStrIndex      = NO_DESCRIPTOR
		},

	.CDC_Functional_Header =
		{
			.Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
			.Subtype                = CDC_DSUBTYPE_CSInterface_Header,

			.CDCSpecification       = VERSION_BCD(1,1,0),
		},

	.CDC_Functional_ACM =
		{
			.Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
			.Subtype                = CDC_DSUBTYPE_CSInterface_ACM,

			.Capabilities           = 0x06,
		},

	.CDC_Functional_Union =
		{
			.Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
			.Subtype                = CDC_DSUBTYPE_CSInterface_Union,

			.MasterInterfaceNumber  = INTERFACE_ID_CDC_CCI,
			.SlaveInterfaceNumber   = INTERFACE_ID_CDC_DCI,
		},

	.CDC_NotificationEndpoint =
		{
			.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},

			.EndpointAddress        = CDC_NOTIFICATION_EPADDR,
			.Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
			.EndpointSize           = CDC_NOTIFICATION_EPSIZE,
			.PollingIntervalMS      = 0xFF
		},

	.CDC_DCI_Interface =
		{
			.Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},

			.InterfaceNumber        = INTERFACE_ID_CDC_DCI,
			.AlternateSetting       = 0,

			.TotalEndpoints         = 2,

			.Class                  = CDC_CSCP_CDCDataClass,
			.SubClass               = CDC_CSCP_NoDataSubclass,
			.Protocol               = CDC_CSCP_NoDataProtocol,

			.InterfaceStrIndex      = NO_DESCRIPTOR
		},

	.CDC_DataOutEndpoint =
		{
			.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},

			.EndpointAddress        = CDC_RX_EPADDR,
			.Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
			.EndpointSize           = CDC_TXRX_EPSIZE,
			.PollingIntervalMS      = 0x05
		},

	.CDC_DataInEndpoint =
		{
			.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},

			.EndpointAddress        = CDC_TX_EPADDR,
			.Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
			.EndpointSize           = CDC_TXRX_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"Simon Foster");

/** 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"USB-HD44780 Adapter");

/** 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;
	}

	*DescriptorAddress = Address;
	return Size;
}