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,166 +1,166 @@
|
|||
/*
|
||||
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 Configuration Descriptor processing routines, to determine the correct pipe configurations
|
||||
* needed to communication with an attached USB device. Descriptors are special computer-readable structures
|
||||
* which the host requests upon device enumeration, to determine the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "ConfigDescriptor.h"
|
||||
|
||||
/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This
|
||||
* routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate
|
||||
* with compatible devices.
|
||||
*
|
||||
* This routine searches for a HID interface descriptor containing at least one Interrupt type IN endpoint and HID descriptor.
|
||||
*
|
||||
* \return An error code from the \ref MouseHostWithParser_GetConfigDescriptorDataCodes_t enum.
|
||||
*/
|
||||
uint8_t ProcessConfigurationDescriptor(void)
|
||||
{
|
||||
uint8_t ConfigDescriptorData[512];
|
||||
void* CurrConfigLocation = ConfigDescriptorData;
|
||||
uint16_t CurrConfigBytesRem;
|
||||
|
||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||
switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||
{
|
||||
case HOST_GETCONFIG_Successful:
|
||||
break;
|
||||
case HOST_GETCONFIG_InvalidData:
|
||||
return InvalidConfigDataReturned;
|
||||
case HOST_GETCONFIG_BuffOverflow:
|
||||
return DescriptorTooLarge;
|
||||
default:
|
||||
return ControlError;
|
||||
}
|
||||
|
||||
/* Get the mouse interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoHIDInterfaceFound;
|
||||
}
|
||||
|
||||
/* Get the mouse interface's HID descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoHIDDescriptorFound;
|
||||
}
|
||||
|
||||
/* Save the HID report size for later use */
|
||||
HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength;
|
||||
|
||||
/* Get the mouse interface's data endpoint descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoEndpointFound;
|
||||
}
|
||||
|
||||
/* Retrieve the endpoint address from the endpoint descriptor */
|
||||
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* Configure the mouse data pipe */
|
||||
Pipe_ConfigurePipe(MOUSE_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
/* Valid data found, return success */
|
||||
return SuccessfulConfigRead;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next Interface descriptor of the correct Mouse HID Class and Protocol values.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextMouseInterface(void* CurrentDescriptor)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
/* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */
|
||||
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == MOUSE_CLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == MOUSE_PROTOCOL))
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor,
|
||||
* aborting the search if another interface descriptor is found before the required endpoint.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
|
||||
{
|
||||
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Fail;
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next HID descriptor within the current HID interface descriptor.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextHID(void* CurrentDescriptor)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_HID)
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
else
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
/*
|
||||
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 Configuration Descriptor processing routines, to determine the correct pipe configurations
|
||||
* needed to communication with an attached USB device. Descriptors are special computer-readable structures
|
||||
* which the host requests upon device enumeration, to determine the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "ConfigDescriptor.h"
|
||||
|
||||
/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This
|
||||
* routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate
|
||||
* with compatible devices.
|
||||
*
|
||||
* This routine searches for a HID interface descriptor containing at least one Interrupt type IN endpoint and HID descriptor.
|
||||
*
|
||||
* \return An error code from the \ref MouseHostWithParser_GetConfigDescriptorDataCodes_t enum.
|
||||
*/
|
||||
uint8_t ProcessConfigurationDescriptor(void)
|
||||
{
|
||||
uint8_t ConfigDescriptorData[512];
|
||||
void* CurrConfigLocation = ConfigDescriptorData;
|
||||
uint16_t CurrConfigBytesRem;
|
||||
|
||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||
switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||
{
|
||||
case HOST_GETCONFIG_Successful:
|
||||
break;
|
||||
case HOST_GETCONFIG_InvalidData:
|
||||
return InvalidConfigDataReturned;
|
||||
case HOST_GETCONFIG_BuffOverflow:
|
||||
return DescriptorTooLarge;
|
||||
default:
|
||||
return ControlError;
|
||||
}
|
||||
|
||||
/* Get the mouse interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoHIDInterfaceFound;
|
||||
}
|
||||
|
||||
/* Get the mouse interface's HID descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoHIDDescriptorFound;
|
||||
}
|
||||
|
||||
/* Save the HID report size for later use */
|
||||
HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength;
|
||||
|
||||
/* Get the mouse interface's data endpoint descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoEndpointFound;
|
||||
}
|
||||
|
||||
/* Retrieve the endpoint address from the endpoint descriptor */
|
||||
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* Configure the mouse data pipe */
|
||||
Pipe_ConfigurePipe(MOUSE_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
/* Valid data found, return success */
|
||||
return SuccessfulConfigRead;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next Interface descriptor of the correct Mouse HID Class and Protocol values.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextMouseInterface(void* CurrentDescriptor)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
/* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */
|
||||
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == MOUSE_CLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == MOUSE_PROTOCOL))
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor,
|
||||
* aborting the search if another interface descriptor is found before the required endpoint.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
|
||||
{
|
||||
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Fail;
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next HID descriptor within the current HID interface descriptor.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextHID(void* CurrentDescriptor)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_HID)
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
else
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
|
|
@ -1,77 +1,77 @@
|
|||
/*
|
||||
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 ConfigDescriptor.c.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIGDESCRIPTOR_H_
|
||||
#define _CONFIGDESCRIPTOR_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "HIDReport.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Interface Class value for the Human Interface Device class */
|
||||
#define MOUSE_CLASS 0x03
|
||||
|
||||
/** Interface Protocol value for a Boot Protocol Mouse compliant device */
|
||||
#define MOUSE_PROTOCOL 0x02
|
||||
|
||||
/** Descriptor header type constant for a HID descriptor */
|
||||
#define DTYPE_HID 0x21
|
||||
|
||||
/** Descriptor header type constant for a HID report descriptor */
|
||||
#define DTYPE_Report 0x22
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the ProcessConfigurationDescriptor() function. */
|
||||
enum MouseHostWithParser_GetConfigDescriptorDataCodes_t
|
||||
{
|
||||
SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */
|
||||
ControlError = 1, /**< A control request to the device failed to complete successfully */
|
||||
DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
|
||||
InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
|
||||
NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */
|
||||
NoHIDDescriptorFound = 5, /**< A compatible HID descriptor was not found in the device's HID interface */
|
||||
NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t ProcessConfigurationDescriptor(void);
|
||||
|
||||
uint8_t DComp_NextMouseInterface(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextHID(void* CurrentDescriptor);
|
||||
|
||||
#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 ConfigDescriptor.c.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIGDESCRIPTOR_H_
|
||||
#define _CONFIGDESCRIPTOR_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "HIDReport.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Interface Class value for the Human Interface Device class */
|
||||
#define MOUSE_CLASS 0x03
|
||||
|
||||
/** Interface Protocol value for a Boot Protocol Mouse compliant device */
|
||||
#define MOUSE_PROTOCOL 0x02
|
||||
|
||||
/** Descriptor header type constant for a HID descriptor */
|
||||
#define DTYPE_HID 0x21
|
||||
|
||||
/** Descriptor header type constant for a HID report descriptor */
|
||||
#define DTYPE_Report 0x22
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the ProcessConfigurationDescriptor() function. */
|
||||
enum MouseHostWithParser_GetConfigDescriptorDataCodes_t
|
||||
{
|
||||
SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */
|
||||
ControlError = 1, /**< A control request to the device failed to complete successfully */
|
||||
DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
|
||||
InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
|
||||
NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */
|
||||
NoHIDDescriptorFound = 5, /**< A compatible HID descriptor was not found in the device's HID interface */
|
||||
NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t ProcessConfigurationDescriptor(void);
|
||||
|
||||
uint8_t DComp_NextMouseInterface(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextHID(void* CurrentDescriptor);
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,110 +1,110 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "HIDReport.h"
|
||||
|
||||
/** Size in bytes of the attached device's HID report descriptor */
|
||||
uint16_t HIDReportSize;
|
||||
|
||||
/** Processed HID report descriptor items structure, containing information on each HID report element */
|
||||
HID_ReportInfo_t HIDReportInfo;
|
||||
|
||||
|
||||
/** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read
|
||||
* structures via the HID parser routines in the LUFA library.
|
||||
*
|
||||
* \return A value from the MouseHostWithParser_GetHIDReportDataCodes_t enum
|
||||
*/
|
||||
uint8_t GetHIDReportData(void)
|
||||
{
|
||||
/* Create a buffer big enough to hold the entire returned HID report */
|
||||
uint8_t HIDReportData[HIDReportSize];
|
||||
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
|
||||
.bRequest = REQ_GetDescriptor,
|
||||
.wValue = (DTYPE_Report << 8),
|
||||
.wIndex = 0,
|
||||
.wLength = HIDReportSize,
|
||||
};
|
||||
|
||||
/* Select the control pipe for the request transfer */
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
|
||||
/* Send control request to retrieve the HID report from the attached device */
|
||||
if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)
|
||||
return ParseControlError;
|
||||
|
||||
/* Send the HID report to the parser for processing */
|
||||
if (USB_ProcessHIDReport(HIDReportData, HIDReportSize, &HIDReportInfo) != HID_PARSE_Successful)
|
||||
return ParseError;
|
||||
|
||||
return ParseSuccessful;
|
||||
}
|
||||
|
||||
/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
|
||||
* an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
|
||||
* we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
|
||||
* have occupied).
|
||||
*
|
||||
* \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
|
||||
*
|
||||
* \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded
|
||||
*/
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* CurrentItem)
|
||||
{
|
||||
bool IsMouse = false;
|
||||
|
||||
/* Iterate through the item's collection path, until either the root collection node or a collection with the
|
||||
* Mouse Usage is found - this prevents Joysticks, which use identical descriptors except for the Joystick usage
|
||||
* parent node, from being erroneously treated as a mouse
|
||||
*/
|
||||
for (HID_CollectionPath_t* CurrPath = CurrentItem->CollectionPath; CurrPath != NULL; CurrPath = CurrPath->Parent)
|
||||
{
|
||||
if ((CurrPath->Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
|
||||
(CurrPath->Usage.Usage == USAGE_MOUSE))
|
||||
{
|
||||
IsMouse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If a collection with the mouse usage was not found, indicate that we are not interested in this item */
|
||||
if (!IsMouse)
|
||||
return false;
|
||||
|
||||
/* Check the attributes of the current mouse item - see if we are interested in it or not;
|
||||
* only store BUTTON and GENERIC_DESKTOP_CONTROL items into the Processed HID Report
|
||||
* structure to save RAM and ignore the rest
|
||||
*/
|
||||
return ((CurrentItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) ||
|
||||
(CurrentItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL));
|
||||
}
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "HIDReport.h"
|
||||
|
||||
/** Size in bytes of the attached device's HID report descriptor */
|
||||
uint16_t HIDReportSize;
|
||||
|
||||
/** Processed HID report descriptor items structure, containing information on each HID report element */
|
||||
HID_ReportInfo_t HIDReportInfo;
|
||||
|
||||
|
||||
/** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read
|
||||
* structures via the HID parser routines in the LUFA library.
|
||||
*
|
||||
* \return A value from the MouseHostWithParser_GetHIDReportDataCodes_t enum
|
||||
*/
|
||||
uint8_t GetHIDReportData(void)
|
||||
{
|
||||
/* Create a buffer big enough to hold the entire returned HID report */
|
||||
uint8_t HIDReportData[HIDReportSize];
|
||||
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
|
||||
.bRequest = REQ_GetDescriptor,
|
||||
.wValue = (DTYPE_Report << 8),
|
||||
.wIndex = 0,
|
||||
.wLength = HIDReportSize,
|
||||
};
|
||||
|
||||
/* Select the control pipe for the request transfer */
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
|
||||
/* Send control request to retrieve the HID report from the attached device */
|
||||
if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)
|
||||
return ParseControlError;
|
||||
|
||||
/* Send the HID report to the parser for processing */
|
||||
if (USB_ProcessHIDReport(HIDReportData, HIDReportSize, &HIDReportInfo) != HID_PARSE_Successful)
|
||||
return ParseError;
|
||||
|
||||
return ParseSuccessful;
|
||||
}
|
||||
|
||||
/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
|
||||
* an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
|
||||
* we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
|
||||
* have occupied).
|
||||
*
|
||||
* \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
|
||||
*
|
||||
* \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded
|
||||
*/
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* CurrentItem)
|
||||
{
|
||||
bool IsMouse = false;
|
||||
|
||||
/* Iterate through the item's collection path, until either the root collection node or a collection with the
|
||||
* Mouse Usage is found - this prevents Joysticks, which use identical descriptors except for the Joystick usage
|
||||
* parent node, from being erroneously treated as a mouse
|
||||
*/
|
||||
for (HID_CollectionPath_t* CurrPath = CurrentItem->CollectionPath; CurrPath != NULL; CurrPath = CurrPath->Parent)
|
||||
{
|
||||
if ((CurrPath->Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
|
||||
(CurrPath->Usage.Usage == USAGE_MOUSE))
|
||||
{
|
||||
IsMouse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If a collection with the mouse usage was not found, indicate that we are not interested in this item */
|
||||
if (!IsMouse)
|
||||
return false;
|
||||
|
||||
/* Check the attributes of the current mouse item - see if we are interested in it or not;
|
||||
* only store BUTTON and GENERIC_DESKTOP_CONTROL items into the Processed HID Report
|
||||
* structure to save RAM and ignore the rest
|
||||
*/
|
||||
return ((CurrentItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) ||
|
||||
(CurrentItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL));
|
||||
}
|
||||
|
|
|
@ -1,97 +1,97 @@
|
|||
/*
|
||||
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 HIDReport.c.
|
||||
*/
|
||||
|
||||
#ifndef _HID_REPORT_H_
|
||||
#define _HID_REPORT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/USB/Class/Host/HIDParser.h>
|
||||
|
||||
#include "MouseHostWithParser.h"
|
||||
|
||||
/* Macros: */
|
||||
/** HID Report Descriptor Usage for a Mouse */
|
||||
#define USAGE_MOUSE 0x02
|
||||
|
||||
/** HID Report Descriptor Usage Page value for a toggle button */
|
||||
#define USAGE_PAGE_BUTTON 0x09
|
||||
|
||||
/** HID Report Descriptor Usage Page value for a Generic Desktop Control */
|
||||
#define USAGE_PAGE_GENERIC_DCTRL 0x01
|
||||
|
||||
/** HID Report Descriptor Usage value for a X axis movement */
|
||||
#define USAGE_X 0x30
|
||||
|
||||
/** HID Report Descriptor Usage value for a Y axis movement */
|
||||
#define USAGE_Y 0x31
|
||||
|
||||
/** HID Report Descriptor Usage value for a Scroll Wheel movement */
|
||||
#define USAGE_SCROLL_WHEEL 0x38
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the GetHIDReportData() function. */
|
||||
enum MouseHostWithParser_GetHIDReportDataCodes_t
|
||||
{
|
||||
ParseSuccessful = 0, /**< HID report descriptor parsed successfully */
|
||||
ParseError = 1, /**< Failed to fully process the HID report descriptor */
|
||||
ParseControlError = 2, /**< Control error occurred while trying to read the device HID descriptor */
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a HID descriptor. */
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length */
|
||||
|
||||
uint16_t HIDSpec; /**< Implemented HID class specification, in BCD encoded format */
|
||||
uint8_t CountryCode; /**< Country code value for localized hardware */
|
||||
|
||||
uint8_t TotalHIDDescriptors; /**< Total number of HID report descriptors in the current interface */
|
||||
|
||||
uint8_t HIDReportType; /**< HID report type of the first HID report descriptor */
|
||||
uint16_t HIDReportLength; /**< Total size in bytes of the first HID report descriptor */
|
||||
} USB_Descriptor_HID_t;
|
||||
|
||||
/* External Variables: */
|
||||
extern uint16_t HIDReportSize;
|
||||
extern HID_ReportInfo_t HIDReportInfo;
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t GetHIDReportData(void);
|
||||
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* CurrentItem);
|
||||
|
||||
#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 HIDReport.c.
|
||||
*/
|
||||
|
||||
#ifndef _HID_REPORT_H_
|
||||
#define _HID_REPORT_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/USB/Class/Host/HIDParser.h>
|
||||
|
||||
#include "MouseHostWithParser.h"
|
||||
|
||||
/* Macros: */
|
||||
/** HID Report Descriptor Usage for a Mouse */
|
||||
#define USAGE_MOUSE 0x02
|
||||
|
||||
/** HID Report Descriptor Usage Page value for a toggle button */
|
||||
#define USAGE_PAGE_BUTTON 0x09
|
||||
|
||||
/** HID Report Descriptor Usage Page value for a Generic Desktop Control */
|
||||
#define USAGE_PAGE_GENERIC_DCTRL 0x01
|
||||
|
||||
/** HID Report Descriptor Usage value for a X axis movement */
|
||||
#define USAGE_X 0x30
|
||||
|
||||
/** HID Report Descriptor Usage value for a Y axis movement */
|
||||
#define USAGE_Y 0x31
|
||||
|
||||
/** HID Report Descriptor Usage value for a Scroll Wheel movement */
|
||||
#define USAGE_SCROLL_WHEEL 0x38
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the GetHIDReportData() function. */
|
||||
enum MouseHostWithParser_GetHIDReportDataCodes_t
|
||||
{
|
||||
ParseSuccessful = 0, /**< HID report descriptor parsed successfully */
|
||||
ParseError = 1, /**< Failed to fully process the HID report descriptor */
|
||||
ParseControlError = 2, /**< Control error occurred while trying to read the device HID descriptor */
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a HID descriptor. */
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length */
|
||||
|
||||
uint16_t HIDSpec; /**< Implemented HID class specification, in BCD encoded format */
|
||||
uint8_t CountryCode; /**< Country code value for localized hardware */
|
||||
|
||||
uint8_t TotalHIDDescriptors; /**< Total number of HID report descriptors in the current interface */
|
||||
|
||||
uint8_t HIDReportType; /**< HID report type of the first HID report descriptor */
|
||||
uint16_t HIDReportLength; /**< Total size in bytes of the first HID report descriptor */
|
||||
} USB_Descriptor_HID_t;
|
||||
|
||||
/* External Variables: */
|
||||
extern uint16_t HIDReportSize;
|
||||
extern HID_ReportInfo_t HIDReportInfo;
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t GetHIDReportData(void);
|
||||
|
||||
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* CurrentItem);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,321 +1,321 @@
|
|||
/*
|
||||
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 MouseHostWithParser demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "MouseHostWithParser.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();
|
||||
|
||||
puts_P(PSTR(ESC_FG_CYAN "Mouse HID Parser Host Demo running.\r\n" ESC_FG_WHITE));
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Mouse_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 */
|
||||
SerialStream_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceAttached(void)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
|
||||
* stops the library USB task management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceUnattached(void)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_GREEN "Device Unattached.\r\n" ESC_FG_WHITE));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
|
||||
* enumerated by the host and is now ready to be used by the application.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationComplete(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
|
||||
void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
|
||||
{
|
||||
USB_ShutDown();
|
||||
|
||||
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
|
||||
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
|
||||
* enumerating an attached USB device.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
|
||||
" -- Error Code %d\r\n"
|
||||
" -- Sub Error Code %d\r\n"
|
||||
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Task to set the configuration of the attached device after it has been enumerated, and to read and process
|
||||
* the HID report descriptor and HID reports from the device and display the results onto the board LEDs.
|
||||
*/
|
||||
void Mouse_HID_Task(void)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Switch to determine what user-application handled host state the host state machine is in */
|
||||
switch (USB_HostState)
|
||||
{
|
||||
case HOST_STATE_Addressed:
|
||||
puts_P(PSTR("Getting Config Data.\r\n"));
|
||||
|
||||
/* Get and process the configuration descriptor data */
|
||||
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
|
||||
{
|
||||
if (ErrorCode == ControlError)
|
||||
puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));
|
||||
else
|
||||
puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));
|
||||
|
||||
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
|
||||
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
printf_P(PSTR("Processing HID Report (Size %d Bytes).\r\n"), HIDReportSize);
|
||||
|
||||
/* Get and process the device's first HID report descriptor */
|
||||
if ((ErrorCode = GetHIDReportData()) != ParseSuccessful)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n"));
|
||||
|
||||
if (!(HIDReportInfo.TotalReportItems))
|
||||
puts_P(PSTR("Not a valid Mouse." ESC_FG_WHITE));
|
||||
else
|
||||
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Total Reports: %d\r\n", HIDReportInfo.TotalDeviceReports);
|
||||
|
||||
for (uint8_t i = 0; i < HIDReportInfo.TotalDeviceReports; i++)
|
||||
{
|
||||
HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[i];
|
||||
|
||||
uint8_t ReportSizeInBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_In];
|
||||
uint8_t ReportSizeOutBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Out];
|
||||
uint8_t ReportSizeFeatureBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Feature];
|
||||
|
||||
/* Print out the byte sizes of each report within the device */
|
||||
printf_P(PSTR(" + Report ID %d - In: %d bytes, Out: %d bytes, Feature: %d bytes\r\n"),
|
||||
CurrReportIDInfo->ReportID,
|
||||
((ReportSizeInBits >> 3) + ((ReportSizeInBits & 0x07) != 0)),
|
||||
((ReportSizeOutBits >> 3) + ((ReportSizeOutBits & 0x07) != 0)),
|
||||
((ReportSizeFeatureBits >> 3) + ((ReportSizeFeatureBits & 0x07) != 0)));
|
||||
}
|
||||
|
||||
puts_P(PSTR("Mouse Enumerated.\r\n"));
|
||||
|
||||
USB_HostState = HOST_STATE_Configured;
|
||||
break;
|
||||
case HOST_STATE_Configured:
|
||||
/* Select and unfreeze mouse data pipe */
|
||||
Pipe_SelectPipe(MOUSE_DATAPIPE);
|
||||
Pipe_Unfreeze();
|
||||
|
||||
/* Check to see if a packet has been received */
|
||||
if (Pipe_IsINReceived())
|
||||
{
|
||||
/* Check if data has been received from the attached mouse */
|
||||
if (Pipe_IsReadWriteAllowed())
|
||||
{
|
||||
/* Create buffer big enough for the report */
|
||||
uint8_t MouseReport[Pipe_BytesInPipe()];
|
||||
|
||||
/* Load in the mouse report */
|
||||
Pipe_Read_Stream_LE(MouseReport, Pipe_BytesInPipe());
|
||||
|
||||
/* Process the read in mouse report from the device */
|
||||
ProcessMouseReport(MouseReport);
|
||||
}
|
||||
|
||||
/* Clear the IN endpoint, ready for next data packet */
|
||||
Pipe_ClearIN();
|
||||
}
|
||||
|
||||
/* Freeze mouse data pipe */
|
||||
Pipe_Freeze();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Processes a read HID report from an attached mouse, extracting out elements via the HID parser results
|
||||
* as required and displays movement and button presses on the board LEDs.
|
||||
*
|
||||
* \param[in] MouseReport Pointer to a HID report from an attached mouse device
|
||||
*/
|
||||
void ProcessMouseReport(uint8_t* MouseReport)
|
||||
{
|
||||
uint8_t LEDMask = LEDS_NO_LEDS;
|
||||
|
||||
/* Check each HID report item in turn, looking for mouse X/Y/button reports */
|
||||
for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)
|
||||
{
|
||||
/* Create a temporary item pointer to the next report item */
|
||||
HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];
|
||||
|
||||
bool FoundData;
|
||||
|
||||
if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) &&
|
||||
(ReportItem->ItemType == REPORT_ITEM_TYPE_In))
|
||||
{
|
||||
/* Get the mouse button value */
|
||||
FoundData = USB_GetHIDReportItemInfo(MouseReport, ReportItem);
|
||||
|
||||
/* For multi-report devices - if the requested data was not in the issued report, continue */
|
||||
if (!(FoundData))
|
||||
continue;
|
||||
|
||||
/* If button is pressed, all LEDs are turned on */
|
||||
if (ReportItem->Value)
|
||||
LEDMask = LEDS_ALL_LEDS;
|
||||
}
|
||||
else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
|
||||
(ReportItem->Attributes.Usage.Usage == USAGE_SCROLL_WHEEL) &&
|
||||
(ReportItem->ItemType == REPORT_ITEM_TYPE_In))
|
||||
{
|
||||
/* Get the mouse wheel value if it is contained within the current
|
||||
* report, if not, skip to the next item in the parser list
|
||||
*/
|
||||
if (!(USB_GetHIDReportItemInfo(MouseReport, ReportItem)))
|
||||
continue;
|
||||
|
||||
int16_t WheelDelta = HID_ALIGN_DATA(ReportItem, int16_t);
|
||||
|
||||
if (WheelDelta)
|
||||
LEDMask = (LEDS_LED1 | LEDS_LED2 | ((WheelDelta > 0) ? LEDS_LED3 : LEDS_LED4));
|
||||
}
|
||||
else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
|
||||
((ReportItem->Attributes.Usage.Usage == USAGE_X) ||
|
||||
(ReportItem->Attributes.Usage.Usage == USAGE_Y)) &&
|
||||
(ReportItem->ItemType == REPORT_ITEM_TYPE_In))
|
||||
{
|
||||
/* Get the mouse relative position value */
|
||||
FoundData = USB_GetHIDReportItemInfo(MouseReport, ReportItem);
|
||||
|
||||
/* For multi-report devices - if the requested data was not in the issued report, continue */
|
||||
if (!(FoundData))
|
||||
continue;
|
||||
|
||||
int16_t DeltaMovement = (int16_t)(ReportItem->Value << (16 - ReportItem->Attributes.BitSize));
|
||||
|
||||
/* Determine if the report is for the X or Y delta movement */
|
||||
if (ReportItem->Attributes.Usage.Usage == USAGE_X)
|
||||
{
|
||||
/* Turn on the appropriate LED according to direction if the delta is non-zero */
|
||||
if (DeltaMovement)
|
||||
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Turn on the appropriate LED according to direction if the delta is non-zero */
|
||||
if (DeltaMovement)
|
||||
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display the button information on the board LEDs */
|
||||
LEDs_SetAllLEDs(LEDMask);
|
||||
/*
|
||||
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 MouseHostWithParser demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "MouseHostWithParser.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();
|
||||
|
||||
puts_P(PSTR(ESC_FG_CYAN "Mouse HID Parser Host Demo running.\r\n" ESC_FG_WHITE));
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Mouse_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 */
|
||||
SerialStream_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceAttached(void)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
|
||||
* stops the library USB task management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceUnattached(void)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_GREEN "Device Unattached.\r\n" ESC_FG_WHITE));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
|
||||
* enumerated by the host and is now ready to be used by the application.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationComplete(void)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
|
||||
void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
|
||||
{
|
||||
USB_ShutDown();
|
||||
|
||||
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
|
||||
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
|
||||
* enumerating an attached USB device.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
|
||||
" -- Error Code %d\r\n"
|
||||
" -- Sub Error Code %d\r\n"
|
||||
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Task to set the configuration of the attached device after it has been enumerated, and to read and process
|
||||
* the HID report descriptor and HID reports from the device and display the results onto the board LEDs.
|
||||
*/
|
||||
void Mouse_HID_Task(void)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Switch to determine what user-application handled host state the host state machine is in */
|
||||
switch (USB_HostState)
|
||||
{
|
||||
case HOST_STATE_Addressed:
|
||||
puts_P(PSTR("Getting Config Data.\r\n"));
|
||||
|
||||
/* Get and process the configuration descriptor data */
|
||||
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
|
||||
{
|
||||
if (ErrorCode == ControlError)
|
||||
puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));
|
||||
else
|
||||
puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));
|
||||
|
||||
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
|
||||
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
printf_P(PSTR("Processing HID Report (Size %d Bytes).\r\n"), HIDReportSize);
|
||||
|
||||
/* Get and process the device's first HID report descriptor */
|
||||
if ((ErrorCode = GetHIDReportData()) != ParseSuccessful)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n"));
|
||||
|
||||
if (!(HIDReportInfo.TotalReportItems))
|
||||
puts_P(PSTR("Not a valid Mouse." ESC_FG_WHITE));
|
||||
else
|
||||
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Total Reports: %d\r\n", HIDReportInfo.TotalDeviceReports);
|
||||
|
||||
for (uint8_t i = 0; i < HIDReportInfo.TotalDeviceReports; i++)
|
||||
{
|
||||
HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[i];
|
||||
|
||||
uint8_t ReportSizeInBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_In];
|
||||
uint8_t ReportSizeOutBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Out];
|
||||
uint8_t ReportSizeFeatureBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Feature];
|
||||
|
||||
/* Print out the byte sizes of each report within the device */
|
||||
printf_P(PSTR(" + Report ID %d - In: %d bytes, Out: %d bytes, Feature: %d bytes\r\n"),
|
||||
CurrReportIDInfo->ReportID,
|
||||
((ReportSizeInBits >> 3) + ((ReportSizeInBits & 0x07) != 0)),
|
||||
((ReportSizeOutBits >> 3) + ((ReportSizeOutBits & 0x07) != 0)),
|
||||
((ReportSizeFeatureBits >> 3) + ((ReportSizeFeatureBits & 0x07) != 0)));
|
||||
}
|
||||
|
||||
puts_P(PSTR("Mouse Enumerated.\r\n"));
|
||||
|
||||
USB_HostState = HOST_STATE_Configured;
|
||||
break;
|
||||
case HOST_STATE_Configured:
|
||||
/* Select and unfreeze mouse data pipe */
|
||||
Pipe_SelectPipe(MOUSE_DATAPIPE);
|
||||
Pipe_Unfreeze();
|
||||
|
||||
/* Check to see if a packet has been received */
|
||||
if (Pipe_IsINReceived())
|
||||
{
|
||||
/* Check if data has been received from the attached mouse */
|
||||
if (Pipe_IsReadWriteAllowed())
|
||||
{
|
||||
/* Create buffer big enough for the report */
|
||||
uint8_t MouseReport[Pipe_BytesInPipe()];
|
||||
|
||||
/* Load in the mouse report */
|
||||
Pipe_Read_Stream_LE(MouseReport, Pipe_BytesInPipe());
|
||||
|
||||
/* Process the read in mouse report from the device */
|
||||
ProcessMouseReport(MouseReport);
|
||||
}
|
||||
|
||||
/* Clear the IN endpoint, ready for next data packet */
|
||||
Pipe_ClearIN();
|
||||
}
|
||||
|
||||
/* Freeze mouse data pipe */
|
||||
Pipe_Freeze();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Processes a read HID report from an attached mouse, extracting out elements via the HID parser results
|
||||
* as required and displays movement and button presses on the board LEDs.
|
||||
*
|
||||
* \param[in] MouseReport Pointer to a HID report from an attached mouse device
|
||||
*/
|
||||
void ProcessMouseReport(uint8_t* MouseReport)
|
||||
{
|
||||
uint8_t LEDMask = LEDS_NO_LEDS;
|
||||
|
||||
/* Check each HID report item in turn, looking for mouse X/Y/button reports */
|
||||
for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)
|
||||
{
|
||||
/* Create a temporary item pointer to the next report item */
|
||||
HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];
|
||||
|
||||
bool FoundData;
|
||||
|
||||
if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) &&
|
||||
(ReportItem->ItemType == REPORT_ITEM_TYPE_In))
|
||||
{
|
||||
/* Get the mouse button value */
|
||||
FoundData = USB_GetHIDReportItemInfo(MouseReport, ReportItem);
|
||||
|
||||
/* For multi-report devices - if the requested data was not in the issued report, continue */
|
||||
if (!(FoundData))
|
||||
continue;
|
||||
|
||||
/* If button is pressed, all LEDs are turned on */
|
||||
if (ReportItem->Value)
|
||||
LEDMask = LEDS_ALL_LEDS;
|
||||
}
|
||||
else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
|
||||
(ReportItem->Attributes.Usage.Usage == USAGE_SCROLL_WHEEL) &&
|
||||
(ReportItem->ItemType == REPORT_ITEM_TYPE_In))
|
||||
{
|
||||
/* Get the mouse wheel value if it is contained within the current
|
||||
* report, if not, skip to the next item in the parser list
|
||||
*/
|
||||
if (!(USB_GetHIDReportItemInfo(MouseReport, ReportItem)))
|
||||
continue;
|
||||
|
||||
int16_t WheelDelta = HID_ALIGN_DATA(ReportItem, int16_t);
|
||||
|
||||
if (WheelDelta)
|
||||
LEDMask = (LEDS_LED1 | LEDS_LED2 | ((WheelDelta > 0) ? LEDS_LED3 : LEDS_LED4));
|
||||
}
|
||||
else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
|
||||
((ReportItem->Attributes.Usage.Usage == USAGE_X) ||
|
||||
(ReportItem->Attributes.Usage.Usage == USAGE_Y)) &&
|
||||
(ReportItem->ItemType == REPORT_ITEM_TYPE_In))
|
||||
{
|
||||
/* Get the mouse relative position value */
|
||||
FoundData = USB_GetHIDReportItemInfo(MouseReport, ReportItem);
|
||||
|
||||
/* For multi-report devices - if the requested data was not in the issued report, continue */
|
||||
if (!(FoundData))
|
||||
continue;
|
||||
|
||||
int16_t DeltaMovement = (int16_t)(ReportItem->Value << (16 - ReportItem->Attributes.BitSize));
|
||||
|
||||
/* Determine if the report is for the X or Y delta movement */
|
||||
if (ReportItem->Attributes.Usage.Usage == USAGE_X)
|
||||
{
|
||||
/* Turn on the appropriate LED according to direction if the delta is non-zero */
|
||||
if (DeltaMovement)
|
||||
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Turn on the appropriate LED according to direction if the delta is non-zero */
|
||||
if (DeltaMovement)
|
||||
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display the button information on the board LEDs */
|
||||
LEDs_SetAllLEDs(LEDMask);
|
||||
}
|
|
@ -1,84 +1,84 @@
|
|||
/*
|
||||
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 MouseHostWithParser.c.
|
||||
*/
|
||||
|
||||
#ifndef _MOUSE_HOST_H_
|
||||
#define _MOUSE_HOST_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/Peripheral/SerialStream.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "ConfigDescriptor.h"
|
||||
#include "HIDReport.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Pipe number for the mouse report data pipe */
|
||||
#define MOUSE_DATAPIPE 1
|
||||
|
||||
/** 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)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void Mouse_HID_Task(void);
|
||||
void SetupHardware(void);
|
||||
|
||||
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
|
||||
void EVENT_USB_Host_DeviceAttached(void);
|
||||
void EVENT_USB_Host_DeviceUnattached(void);
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);
|
||||
void EVENT_USB_Host_DeviceEnumerationComplete(void);
|
||||
|
||||
void ProcessMouseReport(uint8_t* MouseReport);
|
||||
|
||||
#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 MouseHostWithParser.c.
|
||||
*/
|
||||
|
||||
#ifndef _MOUSE_HOST_H_
|
||||
#define _MOUSE_HOST_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <LUFA/Version.h>
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/Peripheral/SerialStream.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "ConfigDescriptor.h"
|
||||
#include "HIDReport.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Pipe number for the mouse report data pipe */
|
||||
#define MOUSE_DATAPIPE 1
|
||||
|
||||
/** 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)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void Mouse_HID_Task(void);
|
||||
void SetupHardware(void);
|
||||
|
||||
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
|
||||
void EVENT_USB_Host_DeviceAttached(void);
|
||||
void EVENT_USB_Host_DeviceUnattached(void);
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);
|
||||
void EVENT_USB_Host_DeviceEnumerationComplete(void);
|
||||
|
||||
void ProcessMouseReport(uint8_t* MouseReport);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
/** \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 Mouse Host With HID Descriptor Parser Demo
|
||||
*
|
||||
* \section SSec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 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>Host</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:
|
||||
*
|
||||
* Mouse host demonstration application. This gives a simple reference
|
||||
* application for implementing a USB Mouse host, for USB mice using
|
||||
* the standard mouse HID profile. It uses a HID parser for the HID
|
||||
* reports, allowing for correct operation across all USB mice. This
|
||||
* demo supports mice with a single HID report.
|
||||
*
|
||||
* Mouse and scroll wheel movement and button presses are displayed
|
||||
* on the board LEDs. On connection to a USB mouse, the report items
|
||||
* will be processed and printed as a formatted list through the USART
|
||||
* before the mouse is fully enumerated.
|
||||
*
|
||||
* Currently only single interface mice 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 Mouse Host With HID Descriptor Parser Demo
|
||||
*
|
||||
* \section SSec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 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>Host</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:
|
||||
*
|
||||
* Mouse host demonstration application. This gives a simple reference
|
||||
* application for implementing a USB Mouse host, for USB mice using
|
||||
* the standard mouse HID profile. It uses a HID parser for the HID
|
||||
* reports, allowing for correct operation across all USB mice. This
|
||||
* demo supports mice with a single HID report.
|
||||
*
|
||||
* Mouse and scroll wheel movement and button presses are displayed
|
||||
* on the board LEDs. On connection to a USB mouse, the report items
|
||||
* will be processed and printed as a formatted list through the USART
|
||||
* before the mouse is fully enumerated.
|
||||
*
|
||||
* Currently only single interface mice 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