Add svn:eol-style property to source files, so that the line endings are correctly converted to the target system's native end of line style.
This commit is contained in:
		
							parent
							
								
									e331b531c6
								
							
						
					
					
						commit
						071e02c6b6
					
				
					 839 changed files with 274562 additions and 274562 deletions
				
			
		|  | @ -1,250 +1,250 @@ | |||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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. | ||||
|  */ | ||||
| USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = | ||||
| { | ||||
| 	0x05, 0x01,          /* Usage Page (Generic Desktop)                       */ | ||||
| 	0x09, 0x04,          /* Usage (Joystick)                                   */ | ||||
| 	0xa1, 0x01,          /* Collection (Application)                           */ | ||||
| 	0x09, 0x01,          /*   Usage (Pointer)                                  */ | ||||
| 	0xa1, 0x00,          /*   Collection (Physical)                            */ | ||||
| 	0x05, 0x01,          /*     Usage Page (Generic Desktop)                   */ | ||||
| 	0x09, 0x30,          /*     Usage (X)                                      */ | ||||
| 	0x09, 0x31,          /*     Usage (Y)                                      */ | ||||
| 	0x15, 0x9c,          /*     Logical Minimum (-100)                         */ | ||||
| 	0x25, 0x64,          /*     Logical Maximum (100)                          */ | ||||
| 	0x75, 0x08,          /*     Report Size (8)                                */ | ||||
| 	0x95, 0x02,          /*     Report Count (2)                               */ | ||||
| 	0x81, 0x82,          /*     Input (Data, Variable, Absolute, Volatile)     */ | ||||
| 	0xc0,                /*   End Collection                                   */ | ||||
| 	0x05, 0x09,          /*   Usage Page (Button)                              */ | ||||
| 	0x09, 0x02,          /*   Usage (Button 2)                                 */ | ||||
| 	0x09, 0x01,          /*   Usage (Button 1)                                 */ | ||||
| 	0x15, 0x00,          /*   Logical Minimum (0)                              */ | ||||
| 	0x25, 0x01,          /*   Logical Maximum (1)                              */ | ||||
| 	0x75, 0x01,          /*   Report Size (1)                                  */ | ||||
| 	0x95, 0x02,          /*   Report Count (2)                                 */ | ||||
| 	0x81, 0x02,          /*   Input (Data, Variable, Absolute)                 */ | ||||
| 	0x75, 0x06,          /*   Report Size (6)                                  */ | ||||
| 	0x95, 0x01,          /*   Report Count (1)                                 */ | ||||
| 	0x81, 0x01,          /*   Input (Constant)                                 */ | ||||
| 	0xc0                 /* End Collection                                     */ | ||||
| }; | ||||
| 
 | ||||
| /** 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. | ||||
|  */ | ||||
| USB_Descriptor_Device_t PROGMEM DeviceDescriptor = | ||||
| { | ||||
| 	.Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, | ||||
| 		 | ||||
| 	.USBSpecification       = VERSION_BCD(01.10), | ||||
| 	.Class                  = 0x00, | ||||
| 	.SubClass               = 0x00, | ||||
| 	.Protocol               = 0x00, | ||||
| 				 | ||||
| 	.Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE, | ||||
| 		 | ||||
| 	.VendorID               = 0x03EB, | ||||
| 	.ProductID              = 0x2043, | ||||
| 	.ReleaseNumber          = 0x0000, | ||||
| 		 | ||||
| 	.ManufacturerStrIndex   = 0x01, | ||||
| 	.ProductStrIndex        = 0x02, | ||||
| 	.SerialNumStrIndex      = NO_DESCRIPTOR, | ||||
| 		 | ||||
| 	.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. | ||||
|  */ | ||||
| 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        = 1, | ||||
| 				 | ||||
| 			.ConfigurationNumber    = 1, | ||||
| 			.ConfigurationStrIndex  = NO_DESCRIPTOR, | ||||
| 				 | ||||
| 			.ConfigAttributes       = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED), | ||||
| 			 | ||||
| 			.MaxPowerConsumption    = USB_CONFIG_POWER_MA(100) | ||||
| 		}, | ||||
| 		 | ||||
| 	.HID_Interface =  | ||||
| 		{ | ||||
| 			.Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | ||||
| 
 | ||||
| 			.InterfaceNumber        = 0x00, | ||||
| 			.AlternateSetting       = 0x00, | ||||
| 			 | ||||
| 			.TotalEndpoints         = 1, | ||||
| 				 | ||||
| 			.Class                  = 0x03, | ||||
| 			.SubClass               = 0x00, | ||||
| 			.Protocol               = 0x00, | ||||
| 				 | ||||
| 			.InterfaceStrIndex      = NO_DESCRIPTOR | ||||
| 		}, | ||||
| 
 | ||||
| 	.HID_JoystickHID =  | ||||
| 		{ | ||||
| 			.Header                 = {.Size = sizeof(USB_Descriptor_HID_t), .Type = DTYPE_HID}, | ||||
| 									  | ||||
| 			.HIDSpec                = VERSION_BCD(01.11), | ||||
| 			.CountryCode            = 0x00, | ||||
| 			.TotalReportDescriptors = 1, | ||||
| 			.HIDReportType          = DTYPE_Report, | ||||
| 			.HIDReportLength        = sizeof(JoystickReport) | ||||
| 		}, | ||||
| 
 | ||||
| 	.HID_ReportINEndpoint =  | ||||
| 		{ | ||||
| 			.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | ||||
| 										  | ||||
| 			.EndpointAddress        = (ENDPOINT_DESCRIPTOR_DIR_IN | JOYSTICK_EPNUM), | ||||
| 			.Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | ||||
| 			.EndpointSize           = JOYSTICK_EPSIZE, | ||||
| 			.PollingIntervalMS      = 0x0A | ||||
| 		}	 | ||||
| }; | ||||
| 
 | ||||
| /** 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. | ||||
|  */ | ||||
| USB_Descriptor_String_t PROGMEM LanguageString = | ||||
| { | ||||
| 	.Header                 = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, | ||||
| 		 | ||||
| 	.UnicodeString          = {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. | ||||
|  */ | ||||
| USB_Descriptor_String_t PROGMEM ManufacturerString = | ||||
| { | ||||
| 	.Header                 = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, | ||||
| 		 | ||||
| 	.UnicodeString          = 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. | ||||
|  */ | ||||
| USB_Descriptor_String_t PROGMEM ProductString = | ||||
| { | ||||
| 	.Header                 = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String}, | ||||
| 		 | ||||
| 	.UnicodeString          = L"LUFA Joystick 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 uint8_t wIndex, void** const DescriptorAddress) | ||||
| { | ||||
| 	const uint8_t  DescriptorType   = (wValue >> 8); | ||||
| 	const uint8_t  DescriptorNumber = (wValue & 0xFF); | ||||
| 
 | ||||
| 	void*    Address = NULL; | ||||
| 	uint16_t Size    = NO_DESCRIPTOR; | ||||
| 
 | ||||
| 	switch (DescriptorType) | ||||
| 	{ | ||||
| 		case DTYPE_Device: | ||||
| 			Address = (void*)&DeviceDescriptor; | ||||
| 			Size    = sizeof(USB_Descriptor_Device_t); | ||||
| 			break; | ||||
| 		case DTYPE_Configuration:  | ||||
| 			Address = (void*)&ConfigurationDescriptor; | ||||
| 			Size    = sizeof(USB_Descriptor_Configuration_t); | ||||
| 			break; | ||||
| 		case DTYPE_String:  | ||||
| 			switch (DescriptorNumber) | ||||
| 			{ | ||||
| 				case 0x00:  | ||||
| 					Address = (void*)&LanguageString; | ||||
| 					Size    = pgm_read_byte(&LanguageString.Header.Size); | ||||
| 					break; | ||||
| 				case 0x01:  | ||||
| 					Address = (void*)&ManufacturerString; | ||||
| 					Size    = pgm_read_byte(&ManufacturerString.Header.Size); | ||||
| 					break; | ||||
| 				case 0x02:  | ||||
| 					Address = (void*)&ProductString; | ||||
| 					Size    = pgm_read_byte(&ProductString.Header.Size); | ||||
| 					break; | ||||
| 			} | ||||
| 			 | ||||
| 			break; | ||||
| 		case DTYPE_HID:  | ||||
| 			Address = (void*)&ConfigurationDescriptor.HID_JoystickHID; | ||||
| 			Size    = sizeof(USB_Descriptor_HID_t); | ||||
| 			break; | ||||
| 		case DTYPE_Report:  | ||||
| 			Address = (void*)&JoystickReport; | ||||
| 			Size    = sizeof(JoystickReport); | ||||
| 			break; | ||||
| 	} | ||||
| 	 | ||||
| 	*DescriptorAddress = Address; | ||||
| 	return Size; | ||||
| } | ||||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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. | ||||
|  */ | ||||
| USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = | ||||
| { | ||||
| 	0x05, 0x01,          /* Usage Page (Generic Desktop)                       */ | ||||
| 	0x09, 0x04,          /* Usage (Joystick)                                   */ | ||||
| 	0xa1, 0x01,          /* Collection (Application)                           */ | ||||
| 	0x09, 0x01,          /*   Usage (Pointer)                                  */ | ||||
| 	0xa1, 0x00,          /*   Collection (Physical)                            */ | ||||
| 	0x05, 0x01,          /*     Usage Page (Generic Desktop)                   */ | ||||
| 	0x09, 0x30,          /*     Usage (X)                                      */ | ||||
| 	0x09, 0x31,          /*     Usage (Y)                                      */ | ||||
| 	0x15, 0x9c,          /*     Logical Minimum (-100)                         */ | ||||
| 	0x25, 0x64,          /*     Logical Maximum (100)                          */ | ||||
| 	0x75, 0x08,          /*     Report Size (8)                                */ | ||||
| 	0x95, 0x02,          /*     Report Count (2)                               */ | ||||
| 	0x81, 0x82,          /*     Input (Data, Variable, Absolute, Volatile)     */ | ||||
| 	0xc0,                /*   End Collection                                   */ | ||||
| 	0x05, 0x09,          /*   Usage Page (Button)                              */ | ||||
| 	0x09, 0x02,          /*   Usage (Button 2)                                 */ | ||||
| 	0x09, 0x01,          /*   Usage (Button 1)                                 */ | ||||
| 	0x15, 0x00,          /*   Logical Minimum (0)                              */ | ||||
| 	0x25, 0x01,          /*   Logical Maximum (1)                              */ | ||||
| 	0x75, 0x01,          /*   Report Size (1)                                  */ | ||||
| 	0x95, 0x02,          /*   Report Count (2)                                 */ | ||||
| 	0x81, 0x02,          /*   Input (Data, Variable, Absolute)                 */ | ||||
| 	0x75, 0x06,          /*   Report Size (6)                                  */ | ||||
| 	0x95, 0x01,          /*   Report Count (1)                                 */ | ||||
| 	0x81, 0x01,          /*   Input (Constant)                                 */ | ||||
| 	0xc0                 /* End Collection                                     */ | ||||
| }; | ||||
| 
 | ||||
| /** 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. | ||||
|  */ | ||||
| USB_Descriptor_Device_t PROGMEM DeviceDescriptor = | ||||
| { | ||||
| 	.Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, | ||||
| 		 | ||||
| 	.USBSpecification       = VERSION_BCD(01.10), | ||||
| 	.Class                  = 0x00, | ||||
| 	.SubClass               = 0x00, | ||||
| 	.Protocol               = 0x00, | ||||
| 				 | ||||
| 	.Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE, | ||||
| 		 | ||||
| 	.VendorID               = 0x03EB, | ||||
| 	.ProductID              = 0x2043, | ||||
| 	.ReleaseNumber          = 0x0000, | ||||
| 		 | ||||
| 	.ManufacturerStrIndex   = 0x01, | ||||
| 	.ProductStrIndex        = 0x02, | ||||
| 	.SerialNumStrIndex      = NO_DESCRIPTOR, | ||||
| 		 | ||||
| 	.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. | ||||
|  */ | ||||
| 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        = 1, | ||||
| 				 | ||||
| 			.ConfigurationNumber    = 1, | ||||
| 			.ConfigurationStrIndex  = NO_DESCRIPTOR, | ||||
| 				 | ||||
| 			.ConfigAttributes       = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED), | ||||
| 			 | ||||
| 			.MaxPowerConsumption    = USB_CONFIG_POWER_MA(100) | ||||
| 		}, | ||||
| 		 | ||||
| 	.HID_Interface =  | ||||
| 		{ | ||||
| 			.Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | ||||
| 
 | ||||
| 			.InterfaceNumber        = 0x00, | ||||
| 			.AlternateSetting       = 0x00, | ||||
| 			 | ||||
| 			.TotalEndpoints         = 1, | ||||
| 				 | ||||
| 			.Class                  = 0x03, | ||||
| 			.SubClass               = 0x00, | ||||
| 			.Protocol               = 0x00, | ||||
| 				 | ||||
| 			.InterfaceStrIndex      = NO_DESCRIPTOR | ||||
| 		}, | ||||
| 
 | ||||
| 	.HID_JoystickHID =  | ||||
| 		{ | ||||
| 			.Header                 = {.Size = sizeof(USB_Descriptor_HID_t), .Type = DTYPE_HID}, | ||||
| 									  | ||||
| 			.HIDSpec                = VERSION_BCD(01.11), | ||||
| 			.CountryCode            = 0x00, | ||||
| 			.TotalReportDescriptors = 1, | ||||
| 			.HIDReportType          = DTYPE_Report, | ||||
| 			.HIDReportLength        = sizeof(JoystickReport) | ||||
| 		}, | ||||
| 
 | ||||
| 	.HID_ReportINEndpoint =  | ||||
| 		{ | ||||
| 			.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | ||||
| 										  | ||||
| 			.EndpointAddress        = (ENDPOINT_DESCRIPTOR_DIR_IN | JOYSTICK_EPNUM), | ||||
| 			.Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | ||||
| 			.EndpointSize           = JOYSTICK_EPSIZE, | ||||
| 			.PollingIntervalMS      = 0x0A | ||||
| 		}	 | ||||
| }; | ||||
| 
 | ||||
| /** 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. | ||||
|  */ | ||||
| USB_Descriptor_String_t PROGMEM LanguageString = | ||||
| { | ||||
| 	.Header                 = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, | ||||
| 		 | ||||
| 	.UnicodeString          = {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. | ||||
|  */ | ||||
| USB_Descriptor_String_t PROGMEM ManufacturerString = | ||||
| { | ||||
| 	.Header                 = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, | ||||
| 		 | ||||
| 	.UnicodeString          = 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. | ||||
|  */ | ||||
| USB_Descriptor_String_t PROGMEM ProductString = | ||||
| { | ||||
| 	.Header                 = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String}, | ||||
| 		 | ||||
| 	.UnicodeString          = L"LUFA Joystick 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 uint8_t wIndex, void** const DescriptorAddress) | ||||
| { | ||||
| 	const uint8_t  DescriptorType   = (wValue >> 8); | ||||
| 	const uint8_t  DescriptorNumber = (wValue & 0xFF); | ||||
| 
 | ||||
| 	void*    Address = NULL; | ||||
| 	uint16_t Size    = NO_DESCRIPTOR; | ||||
| 
 | ||||
| 	switch (DescriptorType) | ||||
| 	{ | ||||
| 		case DTYPE_Device: | ||||
| 			Address = (void*)&DeviceDescriptor; | ||||
| 			Size    = sizeof(USB_Descriptor_Device_t); | ||||
| 			break; | ||||
| 		case DTYPE_Configuration:  | ||||
| 			Address = (void*)&ConfigurationDescriptor; | ||||
| 			Size    = sizeof(USB_Descriptor_Configuration_t); | ||||
| 			break; | ||||
| 		case DTYPE_String:  | ||||
| 			switch (DescriptorNumber) | ||||
| 			{ | ||||
| 				case 0x00:  | ||||
| 					Address = (void*)&LanguageString; | ||||
| 					Size    = pgm_read_byte(&LanguageString.Header.Size); | ||||
| 					break; | ||||
| 				case 0x01:  | ||||
| 					Address = (void*)&ManufacturerString; | ||||
| 					Size    = pgm_read_byte(&ManufacturerString.Header.Size); | ||||
| 					break; | ||||
| 				case 0x02:  | ||||
| 					Address = (void*)&ProductString; | ||||
| 					Size    = pgm_read_byte(&ProductString.Header.Size); | ||||
| 					break; | ||||
| 			} | ||||
| 			 | ||||
| 			break; | ||||
| 		case DTYPE_HID:  | ||||
| 			Address = (void*)&ConfigurationDescriptor.HID_JoystickHID; | ||||
| 			Size    = sizeof(USB_Descriptor_HID_t); | ||||
| 			break; | ||||
| 		case DTYPE_Report:  | ||||
| 			Address = (void*)&JoystickReport; | ||||
| 			Size    = sizeof(JoystickReport); | ||||
| 			break; | ||||
| 	} | ||||
| 	 | ||||
| 	*DescriptorAddress = Address; | ||||
| 	return Size; | ||||
| } | ||||
|  |  | |||
|  | @ -1,93 +1,93 @@ | |||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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 <LUFA/Drivers/USB/USB.h> | ||||
| 
 | ||||
| 		#include <avr/pgmspace.h> | ||||
| 
 | ||||
| 	/* Type Defines: */ | ||||
| 		/** Type define for the HID class specific HID descriptor, to describe the HID device's specifications. Refer to the HID
 | ||||
| 		 *  specification for details on the structure elements. | ||||
| 		 */ | ||||
| 		typedef struct | ||||
| 		{ | ||||
| 			USB_Descriptor_Header_t               Header; | ||||
| 				 | ||||
| 			uint16_t                              HIDSpec; | ||||
| 			uint8_t                               CountryCode; | ||||
| 		 | ||||
| 			uint8_t                               TotalReportDescriptors; | ||||
| 
 | ||||
| 			uint8_t                               HIDReportType; | ||||
| 			uint16_t                              HIDReportLength; | ||||
| 		} USB_Descriptor_HID_t; | ||||
| 
 | ||||
| 		/** Type define for the data type used to store HID report descriptor elements. */ | ||||
| 		typedef uint8_t USB_Descriptor_HIDReport_Datatype_t; | ||||
| 
 | ||||
| 		/** 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; | ||||
| 			USB_Descriptor_Interface_t            HID_Interface; | ||||
| 			USB_Descriptor_HID_t                  HID_JoystickHID; | ||||
| 	        USB_Descriptor_Endpoint_t             HID_ReportINEndpoint; | ||||
| 		} USB_Descriptor_Configuration_t; | ||||
| 					 | ||||
| 	/* Macros: */ | ||||
| 		/** Endpoint number of the Joystick HID reporting IN endpoint. */ | ||||
| 		#define JOYSTICK_EPNUM               1 | ||||
| 
 | ||||
| 		/** Size in bytes of the Joystick HID reporting IN endpoint. */ | ||||
| 		#define JOYSTICK_EPSIZE              8 | ||||
| 
 | ||||
| 		/** Descriptor header type value, to indicate a HID class HID descriptor. */ | ||||
| 		#define DTYPE_HID                 0x21 | ||||
| 		 | ||||
| 		/** Descriptor header type value, to indicate a HID class HID report descriptor. */ | ||||
| 		#define DTYPE_Report              0x22 | ||||
| 
 | ||||
| 	/* Function Prototypes: */ | ||||
| 		uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) | ||||
| 											ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); | ||||
| 
 | ||||
| #endif | ||||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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 <LUFA/Drivers/USB/USB.h> | ||||
| 
 | ||||
| 		#include <avr/pgmspace.h> | ||||
| 
 | ||||
| 	/* Type Defines: */ | ||||
| 		/** Type define for the HID class specific HID descriptor, to describe the HID device's specifications. Refer to the HID
 | ||||
| 		 *  specification for details on the structure elements. | ||||
| 		 */ | ||||
| 		typedef struct | ||||
| 		{ | ||||
| 			USB_Descriptor_Header_t               Header; | ||||
| 				 | ||||
| 			uint16_t                              HIDSpec; | ||||
| 			uint8_t                               CountryCode; | ||||
| 		 | ||||
| 			uint8_t                               TotalReportDescriptors; | ||||
| 
 | ||||
| 			uint8_t                               HIDReportType; | ||||
| 			uint16_t                              HIDReportLength; | ||||
| 		} USB_Descriptor_HID_t; | ||||
| 
 | ||||
| 		/** Type define for the data type used to store HID report descriptor elements. */ | ||||
| 		typedef uint8_t USB_Descriptor_HIDReport_Datatype_t; | ||||
| 
 | ||||
| 		/** 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; | ||||
| 			USB_Descriptor_Interface_t            HID_Interface; | ||||
| 			USB_Descriptor_HID_t                  HID_JoystickHID; | ||||
| 	        USB_Descriptor_Endpoint_t             HID_ReportINEndpoint; | ||||
| 		} USB_Descriptor_Configuration_t; | ||||
| 					 | ||||
| 	/* Macros: */ | ||||
| 		/** Endpoint number of the Joystick HID reporting IN endpoint. */ | ||||
| 		#define JOYSTICK_EPNUM               1 | ||||
| 
 | ||||
| 		/** Size in bytes of the Joystick HID reporting IN endpoint. */ | ||||
| 		#define JOYSTICK_EPSIZE              8 | ||||
| 
 | ||||
| 		/** Descriptor header type value, to indicate a HID class HID descriptor. */ | ||||
| 		#define DTYPE_HID                 0x21 | ||||
| 		 | ||||
| 		/** Descriptor header type value, to indicate a HID class HID report descriptor. */ | ||||
| 		#define DTYPE_Report              0x22 | ||||
| 
 | ||||
| 	/* Function Prototypes: */ | ||||
| 		uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) | ||||
| 											ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -1,209 +1,209 @@ | |||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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
 | ||||
|  * | ||||
|  *  Main source file for the Joystick demo. This file contains the main tasks of the demo and | ||||
|  *  is responsible for the initial application hardware configuration. | ||||
|  */ | ||||
| 
 | ||||
| #include "Joystick.h" | ||||
| 
 | ||||
| /** Main program entry point. This routine configures the hardware required by the application, then
 | ||||
|  *  enters a loop to run the application tasks in sequence. | ||||
|  */ | ||||
| int main(void) | ||||
| { | ||||
| 	SetupHardware(); | ||||
| 	 | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); | ||||
| 	sei(); | ||||
| 
 | ||||
| 	for (;;) | ||||
| 	{ | ||||
| 		HID_Task(); | ||||
| 		USB_USBTask(); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Configures the board hardware and chip peripherals for the demo's functionality. */ | ||||
| void SetupHardware(void) | ||||
| { | ||||
| 	/* Disable watchdog if enabled by bootloader/fuses */ | ||||
| 	MCUSR &= ~(1 << WDRF); | ||||
| 	wdt_disable(); | ||||
| 
 | ||||
| 	/* Disable clock division */ | ||||
| 	clock_prescale_set(clock_div_1); | ||||
| 
 | ||||
| 	/* Hardware Initialization */ | ||||
| 	Joystick_Init(); | ||||
| 	LEDs_Init(); | ||||
| 	Buttons_Init(); | ||||
| 	USB_Init(); | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
 | ||||
|  *  starts the library USB task to begin the enumeration and USB management process. | ||||
|  */ | ||||
| void EVENT_USB_Device_Connect(void) | ||||
| { | ||||
| 	/* Indicate USB enumerating */ | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
 | ||||
|  *  the status LEDs and stops the USB management and joystick reporting tasks. | ||||
|  */ | ||||
| void EVENT_USB_Device_Disconnect(void) | ||||
| { | ||||
| 	/* Indicate USB not ready */ | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
 | ||||
|  *  of the USB device after enumeration - the device endpoints are configured and the joystick reporting task started. | ||||
|  */  | ||||
| void EVENT_USB_Device_ConfigurationChanged(void) | ||||
| { | ||||
| 	/* Indicate USB connected and ready */ | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_READY); | ||||
| 
 | ||||
| 	/* Setup Joystick Report Endpoint */ | ||||
| 	if (!(Endpoint_ConfigureEndpoint(JOYSTICK_EPNUM, EP_TYPE_INTERRUPT, | ||||
| 		                             ENDPOINT_DIR_IN, JOYSTICK_EPSIZE, | ||||
| 	                                 ENDPOINT_BANK_SINGLE))) | ||||
| 	{ | ||||
| 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
 | ||||
|  *  control requests that are not handled internally by the USB library (including the HID commands, which are | ||||
|  *  all issued via the control endpoint), so that they can be handled appropriately for the application. | ||||
|  */ | ||||
| void EVENT_USB_Device_UnhandledControlRequest(void) | ||||
| { | ||||
| 	/* Handle HID Class specific requests */ | ||||
| 	switch (USB_ControlRequest.bRequest) | ||||
| 	{ | ||||
| 		case REQ_GetReport: | ||||
| 			if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) | ||||
| 			{ | ||||
| 				USB_JoystickReport_Data_t JoystickReportData; | ||||
| 				 | ||||
| 				Endpoint_ClearSETUP(); | ||||
| 
 | ||||
| 				/* Create the next HID report to send to the host */				 | ||||
| 				GetNextReport(&JoystickReportData); | ||||
| 					 | ||||
| 				/* Write the report data to the control endpoint */ | ||||
| 				Endpoint_Write_Control_Stream_LE(&JoystickReportData, sizeof(JoystickReportData)); | ||||
| 				 | ||||
| 				/* Finalize the stream transfer to send the last packet or clear the host abort */ | ||||
| 				Endpoint_ClearOUT(); | ||||
| 			} | ||||
| 		 | ||||
| 			break; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Fills the given HID report data structure with the next HID report to send to the host.
 | ||||
|  * | ||||
|  *  \param[out] ReportData  Pointer to a HID report data structure to be filled | ||||
|  * | ||||
|  *  \return Boolean true if the new report differs from the last report, false otherwise | ||||
|  */ | ||||
| bool GetNextReport(USB_JoystickReport_Data_t* ReportData) | ||||
| { | ||||
| 	static uint8_t PrevJoyStatus    = 0; | ||||
| 	static uint8_t PrevButtonStatus = 0; | ||||
| 	uint8_t        JoyStatus_LCL    = Joystick_GetStatus(); | ||||
| 	uint8_t        ButtonStatus_LCL = Buttons_GetStatus(); | ||||
| 	bool           InputChanged     = false; | ||||
| 
 | ||||
| 	/* Clear the report contents */ | ||||
| 	memset(ReportData, 0, sizeof(USB_JoystickReport_Data_t)); | ||||
| 
 | ||||
| 	if (JoyStatus_LCL & JOY_UP) | ||||
| 	  ReportData->Y = -100; | ||||
| 	else if (JoyStatus_LCL & JOY_DOWN) | ||||
| 	  ReportData->Y =  100; | ||||
| 
 | ||||
| 	if (JoyStatus_LCL & JOY_LEFT) | ||||
| 	  ReportData->X = -100; | ||||
| 	else if (JoyStatus_LCL & JOY_RIGHT) | ||||
| 	  ReportData->X =  100; | ||||
| 
 | ||||
| 	if (JoyStatus_LCL & JOY_PRESS) | ||||
| 	  ReportData->Button  = (1 << 1); | ||||
| 	   | ||||
| 	if (ButtonStatus_LCL & BUTTONS_BUTTON1) | ||||
| 	  ReportData->Button |= (1 << 0); | ||||
| 	   | ||||
| 	/* Check if the new report is different to the previous report */ | ||||
| 	InputChanged = (uint8_t)(PrevJoyStatus ^ JoyStatus_LCL) | (uint8_t)(PrevButtonStatus ^ ButtonStatus_LCL); | ||||
| 
 | ||||
| 	/* Save the current joystick status for later comparison */ | ||||
| 	PrevJoyStatus    = JoyStatus_LCL; | ||||
| 	PrevButtonStatus = ButtonStatus_LCL; | ||||
| 
 | ||||
| 	/* Return whether the new report is different to the previous report or not */ | ||||
| 	return InputChanged; | ||||
| } | ||||
| 
 | ||||
| /** Function to manage HID report generation and transmission to the host. */ | ||||
| void HID_Task(void) | ||||
| { | ||||
| 	/* Device must be connected and configured for the task to run */ | ||||
| 	if (USB_DeviceState != DEVICE_STATE_Configured) | ||||
| 	  return; | ||||
|    | ||||
| 	/* Select the Joystick Report Endpoint */ | ||||
| 	Endpoint_SelectEndpoint(JOYSTICK_EPNUM); | ||||
| 
 | ||||
| 	/* Check to see if the host is ready for another packet */ | ||||
| 	if (Endpoint_IsINReady()) | ||||
| 	{ | ||||
| 		USB_JoystickReport_Data_t JoystickReportData; | ||||
| 		 | ||||
| 		/* Create the next HID report to send to the host */ | ||||
| 		GetNextReport(&JoystickReportData); | ||||
| 	 | ||||
| 		/* Write Joystick Report Data */ | ||||
| 		Endpoint_Write_Stream_LE(&JoystickReportData, sizeof(JoystickReportData)); | ||||
| 
 | ||||
| 		/* Finalize the stream transfer to send the last packet */ | ||||
| 		Endpoint_ClearIN(); | ||||
| 		 | ||||
| 		/* Clear the report data afterwards */ | ||||
| 		memset(&JoystickReportData, 0, sizeof(JoystickReportData)); | ||||
| 	} | ||||
| } | ||||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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
 | ||||
|  * | ||||
|  *  Main source file for the Joystick demo. This file contains the main tasks of the demo and | ||||
|  *  is responsible for the initial application hardware configuration. | ||||
|  */ | ||||
| 
 | ||||
| #include "Joystick.h" | ||||
| 
 | ||||
| /** Main program entry point. This routine configures the hardware required by the application, then
 | ||||
|  *  enters a loop to run the application tasks in sequence. | ||||
|  */ | ||||
| int main(void) | ||||
| { | ||||
| 	SetupHardware(); | ||||
| 	 | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); | ||||
| 	sei(); | ||||
| 
 | ||||
| 	for (;;) | ||||
| 	{ | ||||
| 		HID_Task(); | ||||
| 		USB_USBTask(); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Configures the board hardware and chip peripherals for the demo's functionality. */ | ||||
| void SetupHardware(void) | ||||
| { | ||||
| 	/* Disable watchdog if enabled by bootloader/fuses */ | ||||
| 	MCUSR &= ~(1 << WDRF); | ||||
| 	wdt_disable(); | ||||
| 
 | ||||
| 	/* Disable clock division */ | ||||
| 	clock_prescale_set(clock_div_1); | ||||
| 
 | ||||
| 	/* Hardware Initialization */ | ||||
| 	Joystick_Init(); | ||||
| 	LEDs_Init(); | ||||
| 	Buttons_Init(); | ||||
| 	USB_Init(); | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
 | ||||
|  *  starts the library USB task to begin the enumeration and USB management process. | ||||
|  */ | ||||
| void EVENT_USB_Device_Connect(void) | ||||
| { | ||||
| 	/* Indicate USB enumerating */ | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
 | ||||
|  *  the status LEDs and stops the USB management and joystick reporting tasks. | ||||
|  */ | ||||
| void EVENT_USB_Device_Disconnect(void) | ||||
| { | ||||
| 	/* Indicate USB not ready */ | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
 | ||||
|  *  of the USB device after enumeration - the device endpoints are configured and the joystick reporting task started. | ||||
|  */  | ||||
| void EVENT_USB_Device_ConfigurationChanged(void) | ||||
| { | ||||
| 	/* Indicate USB connected and ready */ | ||||
| 	LEDs_SetAllLEDs(LEDMASK_USB_READY); | ||||
| 
 | ||||
| 	/* Setup Joystick Report Endpoint */ | ||||
| 	if (!(Endpoint_ConfigureEndpoint(JOYSTICK_EPNUM, EP_TYPE_INTERRUPT, | ||||
| 		                             ENDPOINT_DIR_IN, JOYSTICK_EPSIZE, | ||||
| 	                                 ENDPOINT_BANK_SINGLE))) | ||||
| 	{ | ||||
| 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
 | ||||
|  *  control requests that are not handled internally by the USB library (including the HID commands, which are | ||||
|  *  all issued via the control endpoint), so that they can be handled appropriately for the application. | ||||
|  */ | ||||
| void EVENT_USB_Device_UnhandledControlRequest(void) | ||||
| { | ||||
| 	/* Handle HID Class specific requests */ | ||||
| 	switch (USB_ControlRequest.bRequest) | ||||
| 	{ | ||||
| 		case REQ_GetReport: | ||||
| 			if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) | ||||
| 			{ | ||||
| 				USB_JoystickReport_Data_t JoystickReportData; | ||||
| 				 | ||||
| 				Endpoint_ClearSETUP(); | ||||
| 
 | ||||
| 				/* Create the next HID report to send to the host */				 | ||||
| 				GetNextReport(&JoystickReportData); | ||||
| 					 | ||||
| 				/* Write the report data to the control endpoint */ | ||||
| 				Endpoint_Write_Control_Stream_LE(&JoystickReportData, sizeof(JoystickReportData)); | ||||
| 				 | ||||
| 				/* Finalize the stream transfer to send the last packet or clear the host abort */ | ||||
| 				Endpoint_ClearOUT(); | ||||
| 			} | ||||
| 		 | ||||
| 			break; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Fills the given HID report data structure with the next HID report to send to the host.
 | ||||
|  * | ||||
|  *  \param[out] ReportData  Pointer to a HID report data structure to be filled | ||||
|  * | ||||
|  *  \return Boolean true if the new report differs from the last report, false otherwise | ||||
|  */ | ||||
| bool GetNextReport(USB_JoystickReport_Data_t* ReportData) | ||||
| { | ||||
| 	static uint8_t PrevJoyStatus    = 0; | ||||
| 	static uint8_t PrevButtonStatus = 0; | ||||
| 	uint8_t        JoyStatus_LCL    = Joystick_GetStatus(); | ||||
| 	uint8_t        ButtonStatus_LCL = Buttons_GetStatus(); | ||||
| 	bool           InputChanged     = false; | ||||
| 
 | ||||
| 	/* Clear the report contents */ | ||||
| 	memset(ReportData, 0, sizeof(USB_JoystickReport_Data_t)); | ||||
| 
 | ||||
| 	if (JoyStatus_LCL & JOY_UP) | ||||
| 	  ReportData->Y = -100; | ||||
| 	else if (JoyStatus_LCL & JOY_DOWN) | ||||
| 	  ReportData->Y =  100; | ||||
| 
 | ||||
| 	if (JoyStatus_LCL & JOY_LEFT) | ||||
| 	  ReportData->X = -100; | ||||
| 	else if (JoyStatus_LCL & JOY_RIGHT) | ||||
| 	  ReportData->X =  100; | ||||
| 
 | ||||
| 	if (JoyStatus_LCL & JOY_PRESS) | ||||
| 	  ReportData->Button  = (1 << 1); | ||||
| 	   | ||||
| 	if (ButtonStatus_LCL & BUTTONS_BUTTON1) | ||||
| 	  ReportData->Button |= (1 << 0); | ||||
| 	   | ||||
| 	/* Check if the new report is different to the previous report */ | ||||
| 	InputChanged = (uint8_t)(PrevJoyStatus ^ JoyStatus_LCL) | (uint8_t)(PrevButtonStatus ^ ButtonStatus_LCL); | ||||
| 
 | ||||
| 	/* Save the current joystick status for later comparison */ | ||||
| 	PrevJoyStatus    = JoyStatus_LCL; | ||||
| 	PrevButtonStatus = ButtonStatus_LCL; | ||||
| 
 | ||||
| 	/* Return whether the new report is different to the previous report or not */ | ||||
| 	return InputChanged; | ||||
| } | ||||
| 
 | ||||
| /** Function to manage HID report generation and transmission to the host. */ | ||||
| void HID_Task(void) | ||||
| { | ||||
| 	/* Device must be connected and configured for the task to run */ | ||||
| 	if (USB_DeviceState != DEVICE_STATE_Configured) | ||||
| 	  return; | ||||
|    | ||||
| 	/* Select the Joystick Report Endpoint */ | ||||
| 	Endpoint_SelectEndpoint(JOYSTICK_EPNUM); | ||||
| 
 | ||||
| 	/* Check to see if the host is ready for another packet */ | ||||
| 	if (Endpoint_IsINReady()) | ||||
| 	{ | ||||
| 		USB_JoystickReport_Data_t JoystickReportData; | ||||
| 		 | ||||
| 		/* Create the next HID report to send to the host */ | ||||
| 		GetNextReport(&JoystickReportData); | ||||
| 	 | ||||
| 		/* Write Joystick Report Data */ | ||||
| 		Endpoint_Write_Stream_LE(&JoystickReportData, sizeof(JoystickReportData)); | ||||
| 
 | ||||
| 		/* Finalize the stream transfer to send the last packet */ | ||||
| 		Endpoint_ClearIN(); | ||||
| 		 | ||||
| 		/* Clear the report data afterwards */ | ||||
| 		memset(&JoystickReportData, 0, sizeof(JoystickReportData)); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -1,92 +1,92 @@ | |||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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 Joystick.c. | ||||
|  */ | ||||
|   | ||||
| #ifndef _JOYSTICK_H_ | ||||
| #define _JOYSTICK_H_ | ||||
| 
 | ||||
| 	/* Includes: */ | ||||
| 		#include <avr/io.h> | ||||
| 		#include <avr/wdt.h> | ||||
| 		#include <avr/power.h> | ||||
| 		#include <avr/interrupt.h> | ||||
| 		#include <string.h> | ||||
| 
 | ||||
| 		#include "Descriptors.h" | ||||
| 
 | ||||
| 		#include <LUFA/Version.h> | ||||
| 		#include <LUFA/Drivers/USB/USB.h> | ||||
| 		#include <LUFA/Drivers/Board/Joystick.h> | ||||
| 		#include <LUFA/Drivers/Board/LEDs.h> | ||||
| 		#include <LUFA/Drivers/Board/Buttons.h> | ||||
| 
 | ||||
| 	/* Macros: */ | ||||
| 		/** HID Class specific request to get the next HID report from the device. */ | ||||
| 		#define REQ_GetReport             0x01 | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ | ||||
| 		#define LEDMASK_USB_NOTREADY      LEDS_LED1 | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ | ||||
| 		#define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3) | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that the USB interface is ready. */ | ||||
| 		#define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4) | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ | ||||
| 		#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3) | ||||
| 	 | ||||
| 	/* Type Defines: */ | ||||
| 		/** Type define for the joystick HID report structure, for creating and sending HID reports to the host PC.
 | ||||
| 		 *  This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c. | ||||
| 		 */ | ||||
| 		typedef struct | ||||
| 		{ | ||||
| 			int8_t  X; /**< Current absolute joystick X position, as a signed 8-bit integer */ | ||||
| 			int8_t  Y; /**< Current absolute joystick Y position, as a signed 8-bit integer */ | ||||
| 			uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */ | ||||
| 		} USB_JoystickReport_Data_t; | ||||
| 
 | ||||
| 	/* Function Prototypes: */ | ||||
| 		void SetupHardware(void); | ||||
| 		void HID_Task(void); | ||||
| 
 | ||||
| 		void EVENT_USB_Device_Connect(void); | ||||
| 		void EVENT_USB_Device_Disconnect(void); | ||||
| 		void EVENT_USB_Device_ConfigurationChanged(void); | ||||
| 		void EVENT_USB_Device_UnhandledControlRequest(void); | ||||
| 
 | ||||
| 		bool GetNextReport(USB_JoystickReport_Data_t* ReportData); | ||||
| 
 | ||||
| #endif | ||||
| /*
 | ||||
|              LUFA Library | ||||
|      Copyright (C) Dean Camera, 2010. | ||||
|                | ||||
|   dean [at] fourwalledcubicle [dot] com | ||||
|       www.fourwalledcubicle.com | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|   Copyright 2010  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 disclaim 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 Joystick.c. | ||||
|  */ | ||||
|   | ||||
| #ifndef _JOYSTICK_H_ | ||||
| #define _JOYSTICK_H_ | ||||
| 
 | ||||
| 	/* Includes: */ | ||||
| 		#include <avr/io.h> | ||||
| 		#include <avr/wdt.h> | ||||
| 		#include <avr/power.h> | ||||
| 		#include <avr/interrupt.h> | ||||
| 		#include <string.h> | ||||
| 
 | ||||
| 		#include "Descriptors.h" | ||||
| 
 | ||||
| 		#include <LUFA/Version.h> | ||||
| 		#include <LUFA/Drivers/USB/USB.h> | ||||
| 		#include <LUFA/Drivers/Board/Joystick.h> | ||||
| 		#include <LUFA/Drivers/Board/LEDs.h> | ||||
| 		#include <LUFA/Drivers/Board/Buttons.h> | ||||
| 
 | ||||
| 	/* Macros: */ | ||||
| 		/** HID Class specific request to get the next HID report from the device. */ | ||||
| 		#define REQ_GetReport             0x01 | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ | ||||
| 		#define LEDMASK_USB_NOTREADY      LEDS_LED1 | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ | ||||
| 		#define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3) | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that the USB interface is ready. */ | ||||
| 		#define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4) | ||||
| 
 | ||||
| 		/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ | ||||
| 		#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3) | ||||
| 	 | ||||
| 	/* Type Defines: */ | ||||
| 		/** Type define for the joystick HID report structure, for creating and sending HID reports to the host PC.
 | ||||
| 		 *  This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c. | ||||
| 		 */ | ||||
| 		typedef struct | ||||
| 		{ | ||||
| 			int8_t  X; /**< Current absolute joystick X position, as a signed 8-bit integer */ | ||||
| 			int8_t  Y; /**< Current absolute joystick Y position, as a signed 8-bit integer */ | ||||
| 			uint8_t Button; /**< Bit mask of the currently pressed joystick buttons */ | ||||
| 		} USB_JoystickReport_Data_t; | ||||
| 
 | ||||
| 	/* Function Prototypes: */ | ||||
| 		void SetupHardware(void); | ||||
| 		void HID_Task(void); | ||||
| 
 | ||||
| 		void EVENT_USB_Device_Connect(void); | ||||
| 		void EVENT_USB_Device_Disconnect(void); | ||||
| 		void EVENT_USB_Device_ConfigurationChanged(void); | ||||
| 		void EVENT_USB_Device_UnhandledControlRequest(void); | ||||
| 
 | ||||
| 		bool GetNextReport(USB_JoystickReport_Data_t* ReportData); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -1,73 +1,73 @@ | |||
| /** \file | ||||
|  * | ||||
|  *  This file contains special DoxyGen information for the generation of the main page and other special | ||||
|  *  documentation pages. It is not a project source file. | ||||
|  */ | ||||
|   | ||||
| /** \mainpage Joystick Device Demo | ||||
|  * | ||||
|  *  \section SSec_Compat Demo Compatibility: | ||||
|  * | ||||
|  *  The following list indicates what microcontrollers are compatible with this demo. | ||||
|  * | ||||
|  *  - Series 7 USB AVRs | ||||
|  *  - Series 6 USB AVRs | ||||
|  *  - Series 4 USB AVRs | ||||
|  *  - Series 2 USB AVRs | ||||
|  * | ||||
|  *  \section SSec_Info USB Information: | ||||
|  * | ||||
|  *  The following table gives a rundown of the USB utilization of this demo. | ||||
|  * | ||||
|  *  <table> | ||||
|  *   <tr> | ||||
|  *    <td><b>USB Mode:</b></td> | ||||
|  *    <td>Device</td> | ||||
|  *   </tr> | ||||
|  *   <tr> | ||||
|  *    <td><b>USB Class:</b></td> | ||||
|  *    <td>Human Interface Device (HID)</td> | ||||
|  *   </tr> | ||||
|  *   <tr>  | ||||
|  *    <td><b>USB Subclass:</b></td> | ||||
|  *    <td>N/A</td> | ||||
|  *   </tr> | ||||
|  *   <tr> | ||||
|  *    <td><b>Relevant Standards:</b></td> | ||||
|  *    <td>USBIF HID Specification \n | ||||
|  *        USBIF HID Usage Tables</td> | ||||
|  *   </tr> | ||||
|  *   <tr> | ||||
|  *    <td><b>Usable Speeds:</b></td> | ||||
|  *    <td>Low Speed Mode \n | ||||
|  *        Full Speed Mode</td> | ||||
|  *   </tr> | ||||
|  *  </table> | ||||
|  * | ||||
|  *  \section SSec_Description Project Description:  | ||||
|  * | ||||
|  *  Joystick demonstration application. This gives a simple reference | ||||
|  *  application for implementing a USB Keyboard device, for USB Joysticks | ||||
|  *  using the standard Keyboard HID profile. | ||||
|  *   | ||||
|  *  This device will show up as a generic joystick device, with two buttons. | ||||
|  *  Pressing the joystick inwards is the first button, and the HWB button | ||||
|  *  is the second. | ||||
|  *   | ||||
|  *  Moving the joystick on the selected board moves the joystick location on | ||||
|  *  the host computer. | ||||
|  *   | ||||
|  *  Currently only single interface joysticks are supported. | ||||
|  * | ||||
|  *  \section SSec_Options Project Options | ||||
|  * | ||||
|  *  The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. | ||||
|  * | ||||
|  *  <table> | ||||
|  *   <tr> | ||||
|  *    <td> | ||||
|  *     None | ||||
|  *    </td> | ||||
|  *   </tr> | ||||
|  *  </table> | ||||
| /** \file | ||||
|  * | ||||
|  *  This file contains special DoxyGen information for the generation of the main page and other special | ||||
|  *  documentation pages. It is not a project source file. | ||||
|  */ | ||||
|   | ||||
| /** \mainpage Joystick Device Demo | ||||
|  * | ||||
|  *  \section SSec_Compat Demo Compatibility: | ||||
|  * | ||||
|  *  The following list indicates what microcontrollers are compatible with this demo. | ||||
|  * | ||||
|  *  - Series 7 USB AVRs | ||||
|  *  - Series 6 USB AVRs | ||||
|  *  - Series 4 USB AVRs | ||||
|  *  - Series 2 USB AVRs | ||||
|  * | ||||
|  *  \section SSec_Info USB Information: | ||||
|  * | ||||
|  *  The following table gives a rundown of the USB utilization of this demo. | ||||
|  * | ||||
|  *  <table> | ||||
|  *   <tr> | ||||
|  *    <td><b>USB Mode:</b></td> | ||||
|  *    <td>Device</td> | ||||
|  *   </tr> | ||||
|  *   <tr> | ||||
|  *    <td><b>USB Class:</b></td> | ||||
|  *    <td>Human Interface Device (HID)</td> | ||||
|  *   </tr> | ||||
|  *   <tr>  | ||||
|  *    <td><b>USB Subclass:</b></td> | ||||
|  *    <td>N/A</td> | ||||
|  *   </tr> | ||||
|  *   <tr> | ||||
|  *    <td><b>Relevant Standards:</b></td> | ||||
|  *    <td>USBIF HID Specification \n | ||||
|  *        USBIF HID Usage Tables</td> | ||||
|  *   </tr> | ||||
|  *   <tr> | ||||
|  *    <td><b>Usable Speeds:</b></td> | ||||
|  *    <td>Low Speed Mode \n | ||||
|  *        Full Speed Mode</td> | ||||
|  *   </tr> | ||||
|  *  </table> | ||||
|  * | ||||
|  *  \section SSec_Description Project Description:  | ||||
|  * | ||||
|  *  Joystick demonstration application. This gives a simple reference | ||||
|  *  application for implementing a USB Keyboard device, for USB Joysticks | ||||
|  *  using the standard Keyboard HID profile. | ||||
|  *   | ||||
|  *  This device will show up as a generic joystick device, with two buttons. | ||||
|  *  Pressing the joystick inwards is the first button, and the HWB button | ||||
|  *  is the second. | ||||
|  *   | ||||
|  *  Moving the joystick on the selected board moves the joystick location on | ||||
|  *  the host computer. | ||||
|  *   | ||||
|  *  Currently only single interface joysticks are supported. | ||||
|  * | ||||
|  *  \section SSec_Options Project Options | ||||
|  * | ||||
|  *  The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. | ||||
|  * | ||||
|  *  <table> | ||||
|  *   <tr> | ||||
|  *    <td> | ||||
|  *     None | ||||
|  *    </td> | ||||
|  *   </tr> | ||||
|  *  </table> | ||||
|  */ | ||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dean Camera
						Dean Camera