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,267 +1,267 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
|
||||
Based on code by 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 KeyboardReport[] =
|
||||
{
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x06, /* Usage (Keyboard) */
|
||||
0xa1, 0x01, /* Collection (Application) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x95, 0x08, /* Report Count (8) */
|
||||
0x05, 0x07, /* Usage Page (Key Codes) */
|
||||
0x19, 0xe0, /* Usage Minimum (Keyboard LeftControl) */
|
||||
0x29, 0xe7, /* Usage Maximum (Keyboard Right GUI) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x81, 0x02, /* Input (Data, Variable, Absolute) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x81, 0x03, /* Input (Const, Variable, Absolute) */
|
||||
0x95, 0x05, /* Report Count (5) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x05, 0x08, /* Usage Page (LEDs) */
|
||||
0x19, 0x01, /* Usage Minimum (Num Lock) */
|
||||
0x29, 0x05, /* Usage Maximum (Kana) */
|
||||
0x91, 0x02, /* Output (Data, Variable, Absolute) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x03, /* Report Size (3) */
|
||||
0x91, 0x03, /* Output (Const, Variable, Absolute) */
|
||||
0x95, 0x06, /* Report Count (6) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x65, /* Logical Maximum (101) */
|
||||
0x05, 0x07, /* Usage Page (Keyboard) */
|
||||
0x19, 0x00, /* Usage Minimum (Reserved (no event indicated)) */
|
||||
0x29, 0x65, /* Usage Maximum (Keyboard Application) */
|
||||
0x81, 0x00, /* Input (Data, Array, Absolute) */
|
||||
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 = 0x2042,
|
||||
.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 = 2,
|
||||
|
||||
.Class = 0x03,
|
||||
.SubClass = 0x01,
|
||||
.Protocol = 0x01,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.HID_KeyboardHID =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_HID_t), .Type = DTYPE_HID},
|
||||
|
||||
.HIDSpec = VERSION_BCD(01.11),
|
||||
.CountryCode = 0x00,
|
||||
.TotalReportDescriptors = 1,
|
||||
.HIDReportType = DTYPE_Report,
|
||||
.HIDReportLength = sizeof(KeyboardReport)
|
||||
},
|
||||
|
||||
.HID_ReportINEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | KEYBOARD_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = KEYBOARD_EPSIZE,
|
||||
.PollingIntervalMS = 0x0A
|
||||
},
|
||||
|
||||
.HID_ReportOUTEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | KEYBOARD_LEDS_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = KEYBOARD_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(16), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = L"Denver Gingerich"
|
||||
};
|
||||
|
||||
/** 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 Keyboard Demo"
|
||||
};
|
||||
|
||||
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
|
||||
* documentation) by the application code so that the address and size of a requested descriptor can be given
|
||||
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
|
||||
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
|
||||
* USB host.
|
||||
*/
|
||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const 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_KeyboardHID;
|
||||
Size = sizeof(USB_Descriptor_HID_t);
|
||||
break;
|
||||
case DTYPE_Report:
|
||||
Address = (void*)&KeyboardReport;
|
||||
Size = sizeof(KeyboardReport);
|
||||
break;
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
|
||||
Based on code by 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 KeyboardReport[] =
|
||||
{
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x06, /* Usage (Keyboard) */
|
||||
0xa1, 0x01, /* Collection (Application) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x95, 0x08, /* Report Count (8) */
|
||||
0x05, 0x07, /* Usage Page (Key Codes) */
|
||||
0x19, 0xe0, /* Usage Minimum (Keyboard LeftControl) */
|
||||
0x29, 0xe7, /* Usage Maximum (Keyboard Right GUI) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x81, 0x02, /* Input (Data, Variable, Absolute) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x81, 0x03, /* Input (Const, Variable, Absolute) */
|
||||
0x95, 0x05, /* Report Count (5) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x05, 0x08, /* Usage Page (LEDs) */
|
||||
0x19, 0x01, /* Usage Minimum (Num Lock) */
|
||||
0x29, 0x05, /* Usage Maximum (Kana) */
|
||||
0x91, 0x02, /* Output (Data, Variable, Absolute) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x03, /* Report Size (3) */
|
||||
0x91, 0x03, /* Output (Const, Variable, Absolute) */
|
||||
0x95, 0x06, /* Report Count (6) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x65, /* Logical Maximum (101) */
|
||||
0x05, 0x07, /* Usage Page (Keyboard) */
|
||||
0x19, 0x00, /* Usage Minimum (Reserved (no event indicated)) */
|
||||
0x29, 0x65, /* Usage Maximum (Keyboard Application) */
|
||||
0x81, 0x00, /* Input (Data, Array, Absolute) */
|
||||
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 = 0x2042,
|
||||
.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 = 2,
|
||||
|
||||
.Class = 0x03,
|
||||
.SubClass = 0x01,
|
||||
.Protocol = 0x01,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.HID_KeyboardHID =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_HID_t), .Type = DTYPE_HID},
|
||||
|
||||
.HIDSpec = VERSION_BCD(01.11),
|
||||
.CountryCode = 0x00,
|
||||
.TotalReportDescriptors = 1,
|
||||
.HIDReportType = DTYPE_Report,
|
||||
.HIDReportLength = sizeof(KeyboardReport)
|
||||
},
|
||||
|
||||
.HID_ReportINEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | KEYBOARD_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = KEYBOARD_EPSIZE,
|
||||
.PollingIntervalMS = 0x0A
|
||||
},
|
||||
|
||||
.HID_ReportOUTEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | KEYBOARD_LEDS_EPNUM),
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = KEYBOARD_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(16), .Type = DTYPE_String},
|
||||
|
||||
.UnicodeString = L"Denver Gingerich"
|
||||
};
|
||||
|
||||
/** 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 Keyboard Demo"
|
||||
};
|
||||
|
||||
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
|
||||
* documentation) by the application code so that the address and size of a requested descriptor can be given
|
||||
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
|
||||
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
|
||||
* USB host.
|
||||
*/
|
||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const 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_KeyboardHID;
|
||||
Size = sizeof(USB_Descriptor_HID_t);
|
||||
break;
|
||||
case DTYPE_Report:
|
||||
Address = (void*)&KeyboardReport;
|
||||
Size = sizeof(KeyboardReport);
|
||||
break;
|
||||
}
|
||||
|
||||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
|
|
@ -1,98 +1,98 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
|
||||
Based on code by 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_KeyboardHID;
|
||||
USB_Descriptor_Endpoint_t HID_ReportINEndpoint;
|
||||
USB_Descriptor_Endpoint_t HID_ReportOUTEndpoint;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the Keyboard HID reporting IN endpoint. */
|
||||
#define KEYBOARD_EPNUM 1
|
||||
|
||||
/** Endpoint number of the Keyboard HID reporting OUT endpoint. */
|
||||
#define KEYBOARD_LEDS_EPNUM 2
|
||||
|
||||
/** Size in bytes of the Keyboard HID reporting IN and OUT endpoints. */
|
||||
#define KEYBOARD_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 Denver Gingerich (denver [at] ossguy [dot] com)
|
||||
Based on code by 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_KeyboardHID;
|
||||
USB_Descriptor_Endpoint_t HID_ReportINEndpoint;
|
||||
USB_Descriptor_Endpoint_t HID_ReportOUTEndpoint;
|
||||
} USB_Descriptor_Configuration_t;
|
||||
|
||||
/* Macros: */
|
||||
/** Endpoint number of the Keyboard HID reporting IN endpoint. */
|
||||
#define KEYBOARD_EPNUM 1
|
||||
|
||||
/** Endpoint number of the Keyboard HID reporting OUT endpoint. */
|
||||
#define KEYBOARD_LEDS_EPNUM 2
|
||||
|
||||
/** Size in bytes of the Keyboard HID reporting IN and OUT endpoints. */
|
||||
#define KEYBOARD_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,387 +1,387 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [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 Keyboard demo. This file contains the main tasks of the demo and
|
||||
* is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
|
||||
* protocol reporting mode.
|
||||
*/
|
||||
bool UsingReportProtocol = true;
|
||||
|
||||
/** Current Idle period. This is set by the host via a Set Idle HID class request to silence the device's reports
|
||||
* for either the entire idle duration, or until the report status changes (e.g. the user presses a key).
|
||||
*/
|
||||
uint16_t IdleCount = 500;
|
||||
|
||||
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
|
||||
* milliseconds. This is separate to the IdleCount timer and is incremented and compared as the host may request
|
||||
* the current idle period via a Get Idle HID class request, thus its value must be preserved.
|
||||
*/
|
||||
uint16_t IdleMSRemaining = 0;
|
||||
|
||||
|
||||
/** 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();
|
||||
USB_Init();
|
||||
Buttons_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);
|
||||
|
||||
/* Default to report protocol on connect */
|
||||
UsingReportProtocol = true;
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
|
||||
* the status LEDs.
|
||||
*/
|
||||
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 sets the current configuration
|
||||
* of the USB device after enumeration, and configures the keyboard device endpoints.
|
||||
*/
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
/* Indicate USB connected and ready */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
|
||||
/* Setup Keyboard Keycode Report Endpoint */
|
||||
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_EPNUM, EP_TYPE_INTERRUPT,
|
||||
ENDPOINT_DIR_IN, KEYBOARD_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE)))
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/* Setup Keyboard LED Report Endpoint */
|
||||
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_LEDS_EPNUM, EP_TYPE_INTERRUPT,
|
||||
ENDPOINT_DIR_OUT, KEYBOARD_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE)))
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
USB_Device_EnableSOFEvents();
|
||||
}
|
||||
|
||||
/** 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_KeyboardReport_Data_t KeyboardReportData;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Create the next keyboard report for transmission to the host */
|
||||
CreateKeyboardReport(&KeyboardReportData);
|
||||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetReport:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Wait until the LED report has been sent by the host */
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read in the LED report from the host */
|
||||
uint8_t LEDStatus = Endpoint_Read_Byte();
|
||||
|
||||
/* Process the incoming LED report */
|
||||
ProcessLEDReport(LEDStatus);
|
||||
|
||||
/* Clear the endpoint data */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_GetProtocol:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the current protocol flag to the host */
|
||||
Endpoint_Write_Byte(UsingReportProtocol);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetProtocol:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */
|
||||
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetIdle:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Get idle period in MSB, IdleCount must be multiplied by 4 to get number of milliseconds */
|
||||
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_GetIdle:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the current idle duration to the host, must be divided by 4 before sent to host */
|
||||
Endpoint_Write_Byte(IdleCount >> 2);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Event handler for the USB device Start Of Frame event. */
|
||||
void EVENT_USB_Device_StartOfFrame(void)
|
||||
{
|
||||
/* One millisecond has elapsed, decrement the idle time remaining counter if it has not already elapsed */
|
||||
if (IdleMSRemaining)
|
||||
IdleMSRemaining--;
|
||||
}
|
||||
|
||||
/** 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
|
||||
*/
|
||||
void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)
|
||||
{
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
uint8_t ButtonStatus_LCL = Buttons_GetStatus();
|
||||
|
||||
uint8_t UsedKeyCodes = 0;
|
||||
|
||||
/* Clear the report contents */
|
||||
memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));
|
||||
|
||||
/* Make sent key uppercase by indicating that the left shift key is pressed */
|
||||
ReportData->Modifier = KEYBOARD_MODIFER_LEFTSHIFT;
|
||||
|
||||
if (JoyStatus_LCL & JOY_UP)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x04; // A
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x05; // B
|
||||
|
||||
if (JoyStatus_LCL & JOY_LEFT)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x06; // C
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x07; // D
|
||||
|
||||
if (JoyStatus_LCL & JOY_PRESS)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x08; // E
|
||||
|
||||
if (ButtonStatus_LCL & BUTTONS_BUTTON1)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x09; // F
|
||||
}
|
||||
|
||||
/** Processes a received LED report, and updates the board LEDs states to match.
|
||||
*
|
||||
* \param[in] LEDReport LED status report from the host
|
||||
*/
|
||||
void ProcessLEDReport(uint8_t LEDReport)
|
||||
{
|
||||
uint8_t LEDMask = LEDS_LED2;
|
||||
|
||||
if (LEDReport & KEYBOARD_LED_NUMLOCK)
|
||||
LEDMask |= LEDS_LED1;
|
||||
|
||||
if (LEDReport & KEYBOARD_LED_CAPSLOCK)
|
||||
LEDMask |= LEDS_LED3;
|
||||
|
||||
if (LEDReport & KEYBOARD_LED_SCROLLLOCK)
|
||||
LEDMask |= LEDS_LED4;
|
||||
|
||||
/* Set the status LEDs to the current Keyboard LED status */
|
||||
LEDs_SetAllLEDs(LEDMask);
|
||||
}
|
||||
|
||||
/** Sends the next HID report to the host, via the keyboard data endpoint. */
|
||||
void SendNextReport(void)
|
||||
{
|
||||
static USB_KeyboardReport_Data_t PrevKeyboardReportData;
|
||||
USB_KeyboardReport_Data_t KeyboardReportData;
|
||||
bool SendReport = true;
|
||||
|
||||
/* Create the next keyboard report for transmission to the host */
|
||||
CreateKeyboardReport(&KeyboardReportData);
|
||||
|
||||
/* Check to see if the report data has changed - if so a report MUST be sent */
|
||||
SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);
|
||||
|
||||
/* Check if the idle period is set and has elapsed */
|
||||
if ((IdleCount != HID_IDLE_CHANGESONLY) && (!(IdleMSRemaining)))
|
||||
{
|
||||
/* Reset the idle time remaining counter */
|
||||
IdleMSRemaining = IdleCount;
|
||||
|
||||
/* Idle period is set and has elapsed, must send a report to the host */
|
||||
SendReport = true;
|
||||
}
|
||||
|
||||
/* Select the Keyboard Report Endpoint */
|
||||
Endpoint_SelectEndpoint(KEYBOARD_EPNUM);
|
||||
|
||||
/* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */
|
||||
if (Endpoint_IsReadWriteAllowed() && SendReport)
|
||||
{
|
||||
/* Save the current report data for later comparison to check for changes */
|
||||
PrevKeyboardReportData = KeyboardReportData;
|
||||
|
||||
/* Write Keyboard Report Data */
|
||||
Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads the next LED status report from the host from the LED data endpoint, if one has been sent. */
|
||||
void ReceiveNextReport(void)
|
||||
{
|
||||
/* Select the Keyboard LED Report Endpoint */
|
||||
Endpoint_SelectEndpoint(KEYBOARD_LEDS_EPNUM);
|
||||
|
||||
/* Check if Keyboard LED Endpoint contains a packet */
|
||||
if (Endpoint_IsOUTReceived())
|
||||
{
|
||||
/* Check to see if the packet contains data */
|
||||
if (Endpoint_IsReadWriteAllowed())
|
||||
{
|
||||
/* Read in the LED report from the host */
|
||||
uint8_t LEDReport = Endpoint_Read_Byte();
|
||||
|
||||
/* Process the read LED report from the host */
|
||||
ProcessLEDReport(LEDReport);
|
||||
}
|
||||
|
||||
/* Handshake the OUT Endpoint - clear endpoint and ready for next report */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
}
|
||||
|
||||
/** Function to manage HID report generation and transmission to the host, when in report mode. */
|
||||
void HID_Task(void)
|
||||
{
|
||||
/* Device must be connected and configured for the task to run */
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||
return;
|
||||
|
||||
/* Send the next keypress report to the host */
|
||||
SendNextReport();
|
||||
|
||||
/* Process the LED report sent from the host */
|
||||
ReceiveNextReport();
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [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 Keyboard demo. This file contains the main tasks of the demo and
|
||||
* is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
/** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
|
||||
* protocol reporting mode.
|
||||
*/
|
||||
bool UsingReportProtocol = true;
|
||||
|
||||
/** Current Idle period. This is set by the host via a Set Idle HID class request to silence the device's reports
|
||||
* for either the entire idle duration, or until the report status changes (e.g. the user presses a key).
|
||||
*/
|
||||
uint16_t IdleCount = 500;
|
||||
|
||||
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
|
||||
* milliseconds. This is separate to the IdleCount timer and is incremented and compared as the host may request
|
||||
* the current idle period via a Get Idle HID class request, thus its value must be preserved.
|
||||
*/
|
||||
uint16_t IdleMSRemaining = 0;
|
||||
|
||||
|
||||
/** 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();
|
||||
USB_Init();
|
||||
Buttons_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);
|
||||
|
||||
/* Default to report protocol on connect */
|
||||
UsingReportProtocol = true;
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
|
||||
* the status LEDs.
|
||||
*/
|
||||
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 sets the current configuration
|
||||
* of the USB device after enumeration, and configures the keyboard device endpoints.
|
||||
*/
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
/* Indicate USB connected and ready */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
|
||||
/* Setup Keyboard Keycode Report Endpoint */
|
||||
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_EPNUM, EP_TYPE_INTERRUPT,
|
||||
ENDPOINT_DIR_IN, KEYBOARD_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE)))
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/* Setup Keyboard LED Report Endpoint */
|
||||
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_LEDS_EPNUM, EP_TYPE_INTERRUPT,
|
||||
ENDPOINT_DIR_OUT, KEYBOARD_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE)))
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
USB_Device_EnableSOFEvents();
|
||||
}
|
||||
|
||||
/** 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_KeyboardReport_Data_t KeyboardReportData;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Create the next keyboard report for transmission to the host */
|
||||
CreateKeyboardReport(&KeyboardReportData);
|
||||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetReport:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Wait until the LED report has been sent by the host */
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read in the LED report from the host */
|
||||
uint8_t LEDStatus = Endpoint_Read_Byte();
|
||||
|
||||
/* Process the incoming LED report */
|
||||
ProcessLEDReport(LEDStatus);
|
||||
|
||||
/* Clear the endpoint data */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_GetProtocol:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the current protocol flag to the host */
|
||||
Endpoint_Write_Byte(UsingReportProtocol);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetProtocol:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */
|
||||
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetIdle:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Get idle period in MSB, IdleCount must be multiplied by 4 to get number of milliseconds */
|
||||
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_GetIdle:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the current idle duration to the host, must be divided by 4 before sent to host */
|
||||
Endpoint_Write_Byte(IdleCount >> 2);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Event handler for the USB device Start Of Frame event. */
|
||||
void EVENT_USB_Device_StartOfFrame(void)
|
||||
{
|
||||
/* One millisecond has elapsed, decrement the idle time remaining counter if it has not already elapsed */
|
||||
if (IdleMSRemaining)
|
||||
IdleMSRemaining--;
|
||||
}
|
||||
|
||||
/** 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
|
||||
*/
|
||||
void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)
|
||||
{
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
uint8_t ButtonStatus_LCL = Buttons_GetStatus();
|
||||
|
||||
uint8_t UsedKeyCodes = 0;
|
||||
|
||||
/* Clear the report contents */
|
||||
memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));
|
||||
|
||||
/* Make sent key uppercase by indicating that the left shift key is pressed */
|
||||
ReportData->Modifier = KEYBOARD_MODIFER_LEFTSHIFT;
|
||||
|
||||
if (JoyStatus_LCL & JOY_UP)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x04; // A
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x05; // B
|
||||
|
||||
if (JoyStatus_LCL & JOY_LEFT)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x06; // C
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x07; // D
|
||||
|
||||
if (JoyStatus_LCL & JOY_PRESS)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x08; // E
|
||||
|
||||
if (ButtonStatus_LCL & BUTTONS_BUTTON1)
|
||||
ReportData->KeyCode[UsedKeyCodes++] = 0x09; // F
|
||||
}
|
||||
|
||||
/** Processes a received LED report, and updates the board LEDs states to match.
|
||||
*
|
||||
* \param[in] LEDReport LED status report from the host
|
||||
*/
|
||||
void ProcessLEDReport(uint8_t LEDReport)
|
||||
{
|
||||
uint8_t LEDMask = LEDS_LED2;
|
||||
|
||||
if (LEDReport & KEYBOARD_LED_NUMLOCK)
|
||||
LEDMask |= LEDS_LED1;
|
||||
|
||||
if (LEDReport & KEYBOARD_LED_CAPSLOCK)
|
||||
LEDMask |= LEDS_LED3;
|
||||
|
||||
if (LEDReport & KEYBOARD_LED_SCROLLLOCK)
|
||||
LEDMask |= LEDS_LED4;
|
||||
|
||||
/* Set the status LEDs to the current Keyboard LED status */
|
||||
LEDs_SetAllLEDs(LEDMask);
|
||||
}
|
||||
|
||||
/** Sends the next HID report to the host, via the keyboard data endpoint. */
|
||||
void SendNextReport(void)
|
||||
{
|
||||
static USB_KeyboardReport_Data_t PrevKeyboardReportData;
|
||||
USB_KeyboardReport_Data_t KeyboardReportData;
|
||||
bool SendReport = true;
|
||||
|
||||
/* Create the next keyboard report for transmission to the host */
|
||||
CreateKeyboardReport(&KeyboardReportData);
|
||||
|
||||
/* Check to see if the report data has changed - if so a report MUST be sent */
|
||||
SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);
|
||||
|
||||
/* Check if the idle period is set and has elapsed */
|
||||
if ((IdleCount != HID_IDLE_CHANGESONLY) && (!(IdleMSRemaining)))
|
||||
{
|
||||
/* Reset the idle time remaining counter */
|
||||
IdleMSRemaining = IdleCount;
|
||||
|
||||
/* Idle period is set and has elapsed, must send a report to the host */
|
||||
SendReport = true;
|
||||
}
|
||||
|
||||
/* Select the Keyboard Report Endpoint */
|
||||
Endpoint_SelectEndpoint(KEYBOARD_EPNUM);
|
||||
|
||||
/* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */
|
||||
if (Endpoint_IsReadWriteAllowed() && SendReport)
|
||||
{
|
||||
/* Save the current report data for later comparison to check for changes */
|
||||
PrevKeyboardReportData = KeyboardReportData;
|
||||
|
||||
/* Write Keyboard Report Data */
|
||||
Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads the next LED status report from the host from the LED data endpoint, if one has been sent. */
|
||||
void ReceiveNextReport(void)
|
||||
{
|
||||
/* Select the Keyboard LED Report Endpoint */
|
||||
Endpoint_SelectEndpoint(KEYBOARD_LEDS_EPNUM);
|
||||
|
||||
/* Check if Keyboard LED Endpoint contains a packet */
|
||||
if (Endpoint_IsOUTReceived())
|
||||
{
|
||||
/* Check to see if the packet contains data */
|
||||
if (Endpoint_IsReadWriteAllowed())
|
||||
{
|
||||
/* Read in the LED report from the host */
|
||||
uint8_t LEDReport = Endpoint_Read_Byte();
|
||||
|
||||
/* Process the read LED report from the host */
|
||||
ProcessLEDReport(LEDReport);
|
||||
}
|
||||
|
||||
/* Handshake the OUT Endpoint - clear endpoint and ready for next report */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
}
|
||||
|
||||
/** Function to manage HID report generation and transmission to the host, when in report mode. */
|
||||
void HID_Task(void)
|
||||
{
|
||||
/* Device must be connected and configured for the task to run */
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||
return;
|
||||
|
||||
/* Send the next keypress report to the host */
|
||||
SendNextReport();
|
||||
|
||||
/* Process the LED report sent from the host */
|
||||
ReceiveNextReport();
|
||||
}
|
||||
|
|
|
@ -1,152 +1,152 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
|
||||
Based on code by 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 Keyboard.c.
|
||||
*/
|
||||
|
||||
#ifndef _KEYBOARD_H_
|
||||
#define _KEYBOARD_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.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/Buttons.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Idle period indicating that reports should be sent only when the inputs have changed */
|
||||
#define HID_IDLE_CHANGESONLY 0
|
||||
|
||||
/** HID Class specific request to get the next HID report from the device. */
|
||||
#define REQ_GetReport 0x01
|
||||
|
||||
/** HID Class specific request to get the idle timeout period of the device. */
|
||||
#define REQ_GetIdle 0x02
|
||||
|
||||
/** HID Class specific request to send the next HID report to the device. */
|
||||
#define REQ_SetReport 0x09
|
||||
|
||||
/** HID Class specific request to set the idle timeout period of the device. */
|
||||
#define REQ_SetIdle 0x0A
|
||||
|
||||
/** HID Class specific request to get the current HID protocol in use, either report or boot. */
|
||||
#define REQ_GetProtocol 0x03
|
||||
|
||||
/** HID Class specific request to set the current HID protocol in use, either report or boot. */
|
||||
#define REQ_SetProtocol 0x0B
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left control key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTCTRL (1 << 0)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left shift key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTSHIFT (1 << 1)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left alt key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTALT (1 << 2)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left GUI key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTGUI (1 << 3)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right control key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTCTRL (1 << 4)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right shift key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTSHIFT (1 << 5)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right alt key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTALT (1 << 6)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right GUI key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTGUI (1 << 7)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's NUM LOCK mode is currently set. */
|
||||
#define KEYBOARD_LED_NUMLOCK (1 << 0)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's CAPS LOCK mode is currently set. */
|
||||
#define KEYBOARD_LED_CAPSLOCK (1 << 1)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's SCROLL LOCK mode is currently set. */
|
||||
#define KEYBOARD_LED_SCROLLLOCK (1 << 2)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's KATANA mode is currently set. */
|
||||
#define KEYBOARD_LED_KATANA (1 << 3)
|
||||
|
||||
/** 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 keyboard 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
|
||||
{
|
||||
uint8_t Modifier; /**< Modifier mask byte, containing a mask of modifier keys set (such as shift or CTRL) */
|
||||
uint8_t Reserved; /**< Reserved, always set as 0x00 */
|
||||
uint8_t KeyCode[6]; /**< Array of up to six simultaneous key codes of pressed keys */
|
||||
} USB_KeyboardReport_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);
|
||||
void EVENT_USB_Device_StartOfFrame(void);
|
||||
|
||||
void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);
|
||||
void ProcessLEDReport(uint8_t LEDReport);
|
||||
void SendNextReport(void);
|
||||
void ReceiveNextReport(void);
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
|
||||
Based on code by 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 Keyboard.c.
|
||||
*/
|
||||
|
||||
#ifndef _KEYBOARD_H_
|
||||
#define _KEYBOARD_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.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/Buttons.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
|
||||
/* Macros: */
|
||||
/** Idle period indicating that reports should be sent only when the inputs have changed */
|
||||
#define HID_IDLE_CHANGESONLY 0
|
||||
|
||||
/** HID Class specific request to get the next HID report from the device. */
|
||||
#define REQ_GetReport 0x01
|
||||
|
||||
/** HID Class specific request to get the idle timeout period of the device. */
|
||||
#define REQ_GetIdle 0x02
|
||||
|
||||
/** HID Class specific request to send the next HID report to the device. */
|
||||
#define REQ_SetReport 0x09
|
||||
|
||||
/** HID Class specific request to set the idle timeout period of the device. */
|
||||
#define REQ_SetIdle 0x0A
|
||||
|
||||
/** HID Class specific request to get the current HID protocol in use, either report or boot. */
|
||||
#define REQ_GetProtocol 0x03
|
||||
|
||||
/** HID Class specific request to set the current HID protocol in use, either report or boot. */
|
||||
#define REQ_SetProtocol 0x0B
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left control key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTCTRL (1 << 0)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left shift key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTSHIFT (1 << 1)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left alt key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTALT (1 << 2)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's left GUI key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_LEFTGUI (1 << 3)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right control key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTCTRL (1 << 4)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right shift key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTSHIFT (1 << 5)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right alt key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTALT (1 << 6)
|
||||
|
||||
/** Constant for a keyboard report modifier byte, indicating that the keyboard's right GUI key is currently pressed. */
|
||||
#define KEYBOARD_MODIFER_RIGHTGUI (1 << 7)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's NUM LOCK mode is currently set. */
|
||||
#define KEYBOARD_LED_NUMLOCK (1 << 0)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's CAPS LOCK mode is currently set. */
|
||||
#define KEYBOARD_LED_CAPSLOCK (1 << 1)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's SCROLL LOCK mode is currently set. */
|
||||
#define KEYBOARD_LED_SCROLLLOCK (1 << 2)
|
||||
|
||||
/** Constant for a keyboard output report LED byte, indicating that the host's KATANA mode is currently set. */
|
||||
#define KEYBOARD_LED_KATANA (1 << 3)
|
||||
|
||||
/** 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 keyboard 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
|
||||
{
|
||||
uint8_t Modifier; /**< Modifier mask byte, containing a mask of modifier keys set (such as shift or CTRL) */
|
||||
uint8_t Reserved; /**< Reserved, always set as 0x00 */
|
||||
uint8_t KeyCode[6]; /**< Array of up to six simultaneous key codes of pressed keys */
|
||||
} USB_KeyboardReport_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);
|
||||
void EVENT_USB_Device_StartOfFrame(void);
|
||||
|
||||
void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);
|
||||
void ProcessLEDReport(uint8_t LEDReport);
|
||||
void SendNextReport(void);
|
||||
void ReceiveNextReport(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
/** \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 Keyboard 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:
|
||||
*
|
||||
* Keyboard demonstration application. This gives a simple reference application
|
||||
* for implementing a USB Keyboard using the basic USB HID drivers in all modern
|
||||
* OSes (i.e. no special drivers required). It is boot protocol compatible, and thus
|
||||
* works under compatible BIOS as if it was a native keyboard (e.g. PS/2).
|
||||
*
|
||||
* On start-up the system will automatically enumerate and function as a keyboard
|
||||
* when the USB connection to a host is present. To use the keyboard example,
|
||||
* manipulate the joystick to send the letters a, b, c, d and e. See the USB HID
|
||||
* documentation for more information on sending keyboard event and key presses. Unlike
|
||||
* other LUFA Keyboard demos, this example shows explicitly how to send multiple keypresses
|
||||
* inside the same report to the host.
|
||||
*
|
||||
* \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 Keyboard 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:
|
||||
*
|
||||
* Keyboard demonstration application. This gives a simple reference application
|
||||
* for implementing a USB Keyboard using the basic USB HID drivers in all modern
|
||||
* OSes (i.e. no special drivers required). It is boot protocol compatible, and thus
|
||||
* works under compatible BIOS as if it was a native keyboard (e.g. PS/2).
|
||||
*
|
||||
* On start-up the system will automatically enumerate and function as a keyboard
|
||||
* when the USB connection to a host is present. To use the keyboard example,
|
||||
* manipulate the joystick to send the letters a, b, c, d and e. See the USB HID
|
||||
* documentation for more information on sending keyboard event and key presses. Unlike
|
||||
* other LUFA Keyboard demos, this example shows explicitly how to send multiple keypresses
|
||||
* inside the same report to the host.
|
||||
*
|
||||
* \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