1
0
Fork 0

Squashed 'tmk_core/' changes from caca2c0..dc0e46e

dc0e46e Rename LUFA to LUFA-git
3bfa7fa Remove LUFA-120730
215b764 Merge commit 'afa0f22a9299686fd88f58ce09c5b521ac917e8f' as 'protocol/lufa/LUFA'
afa0f22 Squashed 'protocol/lufa/LUFA/' content from commit def7fca
c0c42fa Remove submodule of LUFA
30f897d Merge commit '87ced33feb74e79c3281dda36eb6d6d153399b41' as 'protocol/usb_hid/USB_Host_Shield_2.0'
87ced33 Squashed 'protocol/usb_hid/USB_Host_Shield_2.0/' content from commit aab4a69
14f6d49 Remove submodule of USB_Host_Shield_2.0

git-subtree-dir: tmk_core
git-subtree-split: dc0e46eaa4367d4e218f8816e3c117895820f07c
This commit is contained in:
tmk 2015-05-13 11:13:10 +09:00
parent 4d116a04e9
commit f6d56675f9
1575 changed files with 421901 additions and 63190 deletions

View file

@ -0,0 +1,48 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 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 disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
* \brief Application Configuration Header File
*
* This is a header file which is be used to configure some of
* the application's compile time options, as an alternative to
* specifying the compile time constants supplied through a
* makefile or build system.
*
* For information on what each token does, refer to the
* \ref Sec_Options section of the application documentation.
*/
#ifndef _APP_CONFIG_H_
#define _APP_CONFIG_H_
#define GENERIC_REPORT_SIZE 8
#endif

View file

@ -0,0 +1,126 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 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 disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
* \brief LUFA Library Configuration Header File
*
* This header file is used to configure LUFA's compile time options,
* as an alternative to the compile time constants supplied through
* a makefile.
*
* For information on what each token does, refer to the LUFA
* manual section "Summary of Compile Tokens".
*/
#ifndef _LUFA_CONFIG_H_
#define _LUFA_CONFIG_H_
#if (ARCH == ARCH_AVR8)
/* Non-USB Related Configuration Tokens: */
// #define DISABLE_TERMINAL_CODES
/* USB Class Driver Related Tokens: */
// #define HID_HOST_BOOT_PROTOCOL_ONLY
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
// #define HID_MAX_COLLECTIONS {Insert Value Here}
// #define HID_MAX_REPORTITEMS {Insert Value Here}
// #define HID_MAX_REPORT_IDS {Insert Value Here}
// #define NO_CLASS_DRIVER_AUTOFLUSH
/* General USB Driver Related Tokens: */
// #define ORDERED_EP_CONFIG
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
#define USB_DEVICE_ONLY
// #define USB_HOST_ONLY
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
// #define NO_LIMITED_CONTROLLER_CONNECT
// #define NO_SOF_EVENTS
/* USB Device Mode Driver Related Tokens: */
// #define USE_RAM_DESCRIPTORS
#define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
#define FIXED_CONTROL_ENDPOINT_SIZE 8
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
#define FIXED_NUM_CONFIGURATIONS 1
// #define CONTROL_ONLY_DEVICE
// #define INTERRUPT_CONTROL_ENDPOINT
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER
/* USB Host Mode Driver Related Tokens: */
// #define HOST_STATE_AS_GPIOR {Insert Value Here}
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
// #define NO_AUTO_VBUS_MANAGEMENT
// #define INVERTED_VBUS_ENABLE_LINE
#elif (ARCH == ARCH_XMEGA)
/* Non-USB Related Configuration Tokens: */
// #define DISABLE_TERMINAL_CODES
/* USB Class Driver Related Tokens: */
// #define HID_HOST_BOOT_PROTOCOL_ONLY
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
// #define HID_MAX_COLLECTIONS {Insert Value Here}
// #define HID_MAX_REPORTITEMS {Insert Value Here}
// #define HID_MAX_REPORT_IDS {Insert Value Here}
// #define NO_CLASS_DRIVER_AUTOFLUSH
/* General USB Driver Related Tokens: */
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH)
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
// #define NO_LIMITED_CONTROLLER_CONNECT
// #define NO_SOF_EVENTS
/* USB Device Mode Driver Related Tokens: */
// #define USE_RAM_DESCRIPTORS
#define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
#define FIXED_CONTROL_ENDPOINT_SIZE 8
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
#define FIXED_NUM_CONFIGURATIONS 1
// #define CONTROL_ONLY_DEVICE
#define MAX_ENDPOINT_INDEX 1
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER
#else
#error Unsupported architecture for this LUFA configuration file.
#endif
#endif

View file

@ -0,0 +1,220 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 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 disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
* computer-readable structures which the host requests upon device enumeration, to determine
* the device's capabilities and functions.
*/
#include "Descriptors.h"
/** 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.
*/
const USB_Descriptor_HIDReport_Datatype_t PROGMEM GenericReport[] =
{
/* Use the HID class driver's standard Vendor HID report.
* Vendor Usage Page: 0
* Vendor Collection Usage: 1
* Vendor Report IN Usage: 2
* Vendor Report OUT Usage: 3
* Vendor Report Size: GENERIC_REPORT_SIZE
*/
HID_DESCRIPTOR_VENDOR(0x00, 0x01, 0x02, 0x03, GENERIC_REPORT_SIZE)
};
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
* device characteristics, including the supported USB version, control endpoint size and the
* number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins.
*/
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(1,1,0),
.Class = USB_CSCP_NoDeviceClass,
.SubClass = USB_CSCP_NoDeviceSubclass,
.Protocol = USB_CSCP_NoDeviceProtocol,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x03EB,
.ProductID = 0x204F,
.ReleaseNumber = VERSION_BCD(0,0,1),
.ManufacturerStrIndex = STRING_ID_Manufacturer,
.ProductStrIndex = STRING_ID_Product,
.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.
*/
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Config =
{
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces = 1,
.ConfigurationNumber = 1,
.ConfigurationStrIndex = NO_DESCRIPTOR,
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
},
.HID_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = INTERFACE_ID_GenericHID,
.AlternateSetting = 0x00,
.TotalEndpoints = 1,
.Class = HID_CSCP_HIDClass,
.SubClass = HID_CSCP_NonBootSubclass,
.Protocol = HID_CSCP_NonBootProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.HID_GenericHID =
{
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
.HIDSpec = VERSION_BCD(1,1,1),
.CountryCode = 0x00,
.TotalReportDescriptors = 1,
.HIDReportType = HID_DTYPE_Report,
.HIDReportLength = sizeof(GenericReport)
},
.HID_ReportINEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = GENERIC_IN_EPADDR,
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = GENERIC_EPSIZE,
.PollingIntervalMS = 0x05
},
};
/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
* the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
* via the language ID table available at USB.org what languages the device supports for its string descriptors.
*/
const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera");
/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA Generic HID 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,
const void** const DescriptorAddress)
{
const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType)
{
case DTYPE_Device:
Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break;
case DTYPE_String:
switch (DescriptorNumber)
{
case STRING_ID_Language:
Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size);
break;
case STRING_ID_Manufacturer:
Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size);
break;
case STRING_ID_Product:
Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size);
break;
}
break;
case HID_DTYPE_HID:
Address = &ConfigurationDescriptor.HID_GenericHID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
case HID_DTYPE_Report:
Address = &GenericReport;
Size = sizeof(GenericReport);
break;
}
*DescriptorAddress = Address;
return Size;
}

View file

@ -0,0 +1,95 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 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 disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for Descriptors.c.
*/
#ifndef _DESCRIPTORS_H_
#define _DESCRIPTORS_H_
/* Includes: */
#include <avr/pgmspace.h>
#include <LUFA/Drivers/USB/USB.h>
#include "Config/AppConfig.h"
/* Type Defines: */
/** 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;
// Generic HID Interface
USB_Descriptor_Interface_t HID_Interface;
USB_HID_Descriptor_HID_t HID_GenericHID;
USB_Descriptor_Endpoint_t HID_ReportINEndpoint;
} USB_Descriptor_Configuration_t;
/** Enum for the device interface descriptor IDs within the device. Each interface descriptor
* should have a unique ID index associated with it, which can be used to refer to the
* interface from other descriptors.
*/
enum InterfaceDescriptors_t
{
INTERFACE_ID_GenericHID = 0, /**< GenericHID interface descriptor ID */
};
/** Enum for the device string descriptor IDs within the device. Each string descriptor should
* have a unique ID index associated with it, which can be used to refer to the string from
* other descriptors.
*/
enum StringDescriptors_t
{
STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */
STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */
STRING_ID_Product = 2, /**< Product string ID */
};
/* Macros: */
/** Endpoint address of the Generic HID reporting IN endpoint. */
#define GENERIC_IN_EPADDR (ENDPOINT_DIR_IN | 1)
/** Size in bytes of the Generic HID reporting endpoint. */
#define GENERIC_EPSIZE 8
/* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif

View file

@ -0,0 +1,202 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 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 disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Main source file for the GenericHID demo. This file contains the main tasks of
* the demo and is responsible for the initial application hardware configuration.
*/
#include "GenericHID.h"
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
static uint8_t PrevHIDReportBuffer[GENERIC_REPORT_SIZE];
/** LUFA HID Class driver interface configuration and state information. This structure is
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_Device_t Generic_HID_Interface =
{
.Config =
{
.InterfaceNumber = INTERFACE_ID_GenericHID,
.ReportINEndpoint =
{
.Address = GENERIC_IN_EPADDR,
.Size = GENERIC_EPSIZE,
.Banks = 1,
},
.PrevReportINBuffer = PrevHIDReportBuffer,
.PrevReportINBufferSize = sizeof(PrevHIDReportBuffer),
},
};
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
GlobalInterruptEnable();
for (;;)
{
HID_Device_USBTask(&Generic_HID_Interface);
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
#if (ARCH == ARCH_AVR8)
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();
/* Disable clock division */
clock_prescale_set(clock_div_1);
#elif (ARCH == ARCH_XMEGA)
/* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
/* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif
/* Hardware Initialization */
LEDs_Init();
USB_Init();
}
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
}
/** Event handler for the library USB Disconnection event. */
void EVENT_USB_Device_Disconnect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
}
/** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void)
{
bool ConfigSuccess = true;
ConfigSuccess &= HID_Device_ConfigureEndpoints(&Generic_HID_Interface);
USB_Device_EnableSOFEvents();
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
HID_Device_ProcessControlRequest(&Generic_HID_Interface);
}
/** Event handler for the USB device Start Of Frame event. */
void EVENT_USB_Device_StartOfFrame(void)
{
HID_Device_MillisecondElapsed(&Generic_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.
*
* \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced
* \param[in,out] ReportID Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID
* \param[in] ReportType Type of the report to create, either HID_REPORT_ITEM_In or HID_REPORT_ITEM_Feature
* \param[out] ReportData Pointer to a buffer where the created report should be stored
* \param[out] ReportSize Number of bytes written in the report (or zero if no report is to be sent)
*
* \return Boolean \c true to force the sending of the report, \c false to let the library determine if it needs to be sent
*/
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
uint8_t* const ReportID,
const uint8_t ReportType,
void* ReportData,
uint16_t* const ReportSize)
{
uint8_t* Data = (uint8_t*)ReportData;
uint8_t CurrLEDMask = LEDs_GetLEDs();
Data[0] = ((CurrLEDMask & LEDS_LED1) ? 1 : 0);
Data[1] = ((CurrLEDMask & LEDS_LED2) ? 1 : 0);
Data[2] = ((CurrLEDMask & LEDS_LED3) ? 1 : 0);
Data[3] = ((CurrLEDMask & LEDS_LED4) ? 1 : 0);
*ReportSize = GENERIC_REPORT_SIZE;
return false;
}
/** HID class driver callback function for the processing of HID reports from the host.
*
* \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced
* \param[in] ReportID Report ID of the received report from the host
* \param[in] ReportType The type of report that the host has sent, either HID_REPORT_ITEM_Out or HID_REPORT_ITEM_Feature
* \param[in] ReportData Pointer to a buffer where the received report has been stored
* \param[in] ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
const uint8_t ReportID,
const uint8_t ReportType,
const void* ReportData,
const uint16_t ReportSize)
{
uint8_t* Data = (uint8_t*)ReportData;
uint8_t NewLEDMask = LEDS_NO_LEDS;
if (Data[0])
NewLEDMask |= LEDS_LED1;
if (Data[1])
NewLEDMask |= LEDS_LED2;
if (Data[2])
NewLEDMask |= LEDS_LED3;
if (Data[3])
NewLEDMask |= LEDS_LED4;
LEDs_SetAllLEDs(NewLEDMask);
}

View file

@ -0,0 +1,87 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2014 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 disclaims all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for GenericHID.c.
*/
#ifndef _GENERICHID_H_
#define _GENERICHID_H_
/* Includes: */
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <string.h>
#include "Descriptors.h"
#include "Config/AppConfig.h"
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Platform/Platform.h>
/* Macros: */
/** 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 SetupHardware(void);
void EVENT_USB_Device_Connect(void);
void EVENT_USB_Device_Disconnect(void);
void EVENT_USB_Device_ConfigurationChanged(void);
void EVENT_USB_Device_ControlRequest(void);
void EVENT_USB_Device_StartOfFrame(void);
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
uint8_t* const ReportID,
const uint8_t ReportType,
void* ReportData,
uint16_t* const ReportSize);
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
const uint8_t ReportID,
const uint8_t ReportType,
const void* ReportData,
const uint16_t ReportSize);
#endif

View file

@ -0,0 +1,79 @@
/** \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 Generic HID Device
*
* \section Sec_Compat Demo Compatibility:
*
* The following list indicates what microcontrollers are compatible with this demo.
*
* \li Series 7 USB AVRs (AT90USBxxx7)
* \li Series 6 USB AVRs (AT90USBxxx6)
* \li Series 4 USB AVRs (ATMEGAxxU4)
* \li Series 2 USB AVRs (AT90USBxx2, ATMEGAxxU2)
* \li Series AU XMEGA AVRs (ATXMEGAxxxAxU)
* \li Series B XMEGA AVRs (ATXMEGAxxxBxU)
* \li Series C XMEGA AVRs (ATXMEGAxxxCxU)
*
* \section Sec_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>Supported USB Speeds:</b></td>
* <td>Low Speed Mode \n
* Full Speed Mode</td>
* </tr>
* </table>
*
* \section Sec_Description Project Description:
*
* Generic HID device demonstration application. This gives a simple reference application
* for implementing a generic HID device, using the basic USB HID drivers in all modern
* OSes (i.e. no special drivers required). By default it accepts and sends up to 8 byte reports
* to and from a USB Host, and transmits the last sent report back to the host.
*
* On start-up the system will automatically enumerate and function as a vendor HID device.
* When controlled by a custom HID class application, reports can be sent and received by
* both the standard data endpoint and control request methods defined in the HID specification.
*
* \section Sec_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>
* <th><b>Define Name:</b></th>
* <th><b>Location:</b></th>
* <th><b>Description:</b></th>
* </tr>
* <tr>
* <td>GENERIC_REPORT_SIZE</td>
* <td>AppConfig.h</td>
* <td>This token defines the size of the device reports, both sent and received (including report ID byte). The value
* must be an integer ranging from 1 to 255.</td>
* </tr>
* </table>
*/

View file

@ -0,0 +1,143 @@
#!/usr/bin/env node
// LUFA Library
// Copyright (C) Dean Camera, 2014.
//
// dean [at] fourwalledcubicle [dot] com
// www.lufa-lib.org
// LUFA Generic HID device demo host test script. This script will send a
// continuous stream of generic reports to the device, to show a variable LED
// pattern on the target board. Send and received report data is printed to
// the terminal.
//
// You have to install the usb and async modules prior to executing this script:
// apt-get install libusb-1.0-0-dev
// npm install usb async sprintf
var usb = require('usb');
var async = require('async');
var sprintf = require('sprintf');
var deviceVid = 0x03EB;
var devicePid = 0x204F;
var reportLength = 8;
function getAndInitHidDeviceAndInterface()
{
device = usb.findByIds(deviceVid, devicePid);
if (!device) {
console.log('No device found');
process.exit(1);
}
device.open();
var hidInterface = device.interface(0);
if (hidInterface.isKernelDriverActive()) {
hidInterface.detachKernelDriver();
}
hidInterface.claim();
async.series([
function(callback) {
setConfiguration(0, function(error, data) {
callback();
});
}
]);
return {hidDevice:device, hidInterface:hidInterface};
}
function read(hidInterface, callback)
{
endpoint = hidInterface.endpoints[0];
endpoint.transfer(reportLength, function(error, data) {
if (error) {
console.log(error)
} else {
console.log("Received LED Pattern:", data.slice(0, 4));
}
callback();
});
}
function write(hidDevice, message, callback)
{
hidDevice.controlTransfer( // Send a Set Report control request
parseInt('00100001', 2), // bmRequestType (constant for this control request)
0x09, // bmRequest (constant for this control request)
0x0809, // wValue (MSB is report type, LSB is report number)
0, // wIndex (interface number)
message, // message to be sent
function(error, data) { // callback to be executed upon finishing the transfer
console.log("Sent LED Pattern:", message.slice(1, 5))
callback();
}
);
}
function setConfiguration(configurationNumber, callback)
{
device.controlTransfer( // Send a Set Configuration control request
parseInt('00000000', 2), // bmRequestType
0x09, // bmRequest
0, // wValue (Configuration value)
0, // wIndex
new Buffer(0), // message to be sent
callback // callback to be executed upon finishing the transfer
);
}
// @TODO: Fix this function because apparently it doesn't work for some reason.
function getStringDescriptor(stringId, languageId, callback)
{
var STRING_DESCRIPTOR_TYPE = 0x03;
var wValue = (STRING_DESCRIPTOR_TYPE << 8) | stringId;
device.controlTransfer( // Send a Get Descriptor control request
parseInt('10000000', 2), // bmRequestType
0x06, // bmRequest
wValue, // wValue
languageId, // wIndex
64, // response length
callback // callback to be executed upon finishing the transfer
);
}
function setNextPattern()
{
var pattern = [
hidInterface.interface,
(p >> 3) & 1,
(p >> 2) & 1,
(p >> 1) & 1,
(p >> 0) & 1
];
async.series([
function(callback) {
write(hidDevice, new Buffer(pattern), callback);
},
function(callback) {
read(hidInterface, callback);
},
function(callback) {
p = (p + 1) % 16
setTimeout(setNextPattern, 200);
callback();
}]);
}
var hidDeviceAndInterface = getAndInitHidDeviceAndInterface();
var hidDevice = hidDeviceAndInterface.hidDevice
var hidInterface = hidDeviceAndInterface.hidInterface;
console.log(sprintf("Connected to device 0x%04X/0x%04X - %s [%s]",
hidDevice.deviceDescriptor.idVendor,
hidDevice.deviceDescriptor.idProduct,
hidDevice.deviceDescriptor.iProduct,
hidDevice.deviceDescriptor.iManufacturer));
p = 0
setNextPattern();

View file

@ -0,0 +1,98 @@
#!/usr/bin/env python
"""
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
"""
"""
LUFA Generic HID device demo host test script. This script will send a
continuous stream of generic reports to the device, to show a variable LED
pattern on the target board. Send and received report data is printed to
the terminal.
Requires the PyUSB library (http://sourceforge.net/apps/trac/pyusb/).
"""
import sys
from time import sleep
import usb.core
import usb.util
# Generic HID device VID, PID and report payload length (length is increased
# by one to account for the Report ID byte that must be pre-pended)
device_vid = 0x03EB
device_pid = 0x204F
def get_and_init_hid_device():
device = usb.core.find(idVendor=device_vid, idProduct=device_pid)
if device is None:
sys.exit("Could not find USB device.")
if device.is_kernel_driver_active(0):
try:
device.detach_kernel_driver(0)
except usb.core.USBError as exception:
sys.exit("Could not detatch kernel driver: %s" % str(exception))
try:
device.set_configuration()
except usb.core.USBError as exception:
sys.exit("Could not set configuration: %s" % str(exception))
return device
def send_led_pattern(device, led1, led2, led3, led4):
# Report data for the demo is LED on/off data
report_data = [led1, led2, led3, led4]
# Send the generated report to the device
number_of_bytes_written = device.ctrl_transfer( # Set Report control request
0b00100001, # bmRequestType (constant for this control request)
0x09, # bmRequest (constant for this control request)
0, # wValue (MSB is report type, LSB is report number)
0, # wIndex (interface number)
report_data # report data to be sent
);
assert number_of_bytes_written == len(report_data)
print("Sent LED Pattern: {0}".format(report_data))
def receive_led_pattern(hid_device):
endpoint = hid_device[0][(0,0)][0]
report_data = hid_device.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize)
return list(report_data)
def main():
hid_device = get_and_init_hid_device()
print("Connected to device 0x%04X/0x%04X - %s [%s]" %
(hid_device.idVendor, hid_device.idProduct,
usb.util.get_string(hid_device, 256, hid_device.iProduct),
usb.util.get_string(hid_device, 256, hid_device.iManufacturer)))
p = 0
while (True):
# Convert the current pattern index to a bit-mask and send
send_led_pattern(hid_device,
(p >> 3) & 1,
(p >> 2) & 1,
(p >> 1) & 1,
(p >> 0) & 1)
# Receive and print the current LED pattern
led_pattern = receive_led_pattern(hid_device)[0:4]
print("Received LED Pattern: {0}".format(led_pattern))
# Compute next LED pattern in sequence
p = (p + 1) % 16
# Delay a bit for visual effect
sleep(.2)
if __name__ == '__main__':
main()

View file

@ -0,0 +1,96 @@
"""
LUFA Library
Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
"""
"""
LUFA Generic HID device demo host test script. This script will send a
continuous stream of generic reports to the device, to show a variable LED
pattern on the target board. Send and received report data is printed to
the terminal.
Requires the pywinusb library (https://pypi.python.org/pypi/pywinusb/).
"""
import sys
from time import sleep
import pywinusb.hid as hid
# Generic HID device VID, PID and report payload length (length is increased
# by one to account for the Report ID byte that must be pre-pended)
device_vid = 0x03EB
device_pid = 0x204F
report_length = 1 + 8
def get_hid_device_handle():
hid_device_filter = hid.HidDeviceFilter(vendor_id=device_vid,
product_id=device_pid)
valid_hid_devices = hid_device_filter.get_devices()
if len(valid_hid_devices) is 0:
return None
else:
return valid_hid_devices[0]
def send_led_pattern(device, led1, led2, led3, led4):
# Report data for the demo is the report ID (always zero) followed by the
# LED on/off data
report_data = [0, led1, led2, led3, led4]
# Zero-extend the array to the length the report should be
report_data.extend([0] * (report_length - len(report_data)))
# Send the generated report to the device
device.send_output_report(report_data)
print("Sent LED Pattern: {0}".format(report_data[1:5]))
def received_led_pattern(report_data):
print("Received LED Pattern: {0}".format(report_data[1:5]))
def main():
hid_device = get_hid_device_handle()
if hid_device is None:
print("No valid HID device found.")
sys.exit(1)
try:
hid_device.open()
print("Connected to device 0x%04X/0x%04X - %s [%s]" %
(hid_device.vendor_id, hid_device.product_id,
hid_device.product_name, hid_device.vendor_name))
# Set up the HID input report handler to receive reports
hid_device.set_raw_data_handler(received_led_pattern)
p = 0
while (hid_device.is_plugged()):
# Convert the current pattern index to a bit-mask and send
send_led_pattern(hid_device,
(p >> 3) & 1,
(p >> 2) & 1,
(p >> 1) & 1,
(p >> 0) & 1)
# Compute next LED pattern in sequence
p = (p + 1) % 16
# Delay a bit for visual effect
sleep(.2)
finally:
hid_device.close()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,63 @@
<asf xmlversion="1.0">
<project caption="Generic HID Device Demo (Class Driver APIs)" id="lufa.demos.device.class.generic_hid.example.avr8">
<require idref="lufa.demos.device.class.generic_hid"/>
<require idref="lufa.boards.dummy.avr8"/>
<generator value="as5_8"/>
<device-support value="at90usb1287"/>
<config name="lufa.drivers.board.name" value="none"/>
<build type="define" name="F_CPU" value="16000000UL"/>
<build type="define" name="F_USB" value="16000000UL"/>
</project>
<project caption="Generic HID Device Demo (Class Driver APIs)" id="lufa.demos.device.class.generic_hid.example.xmega">
<require idref="lufa.demos.device.class.generic_hid"/>
<require idref="lufa.boards.dummy.xmega"/>
<generator value="as5_8"/>
<device-support value="atxmega128a1u"/>
<config name="lufa.drivers.board.name" value="none"/>
<build type="define" name="F_CPU" value="32000000UL"/>
<build type="define" name="F_USB" value="48000000UL"/>
</project>
<module type="application" id="lufa.demos.device.class.generic_hid" caption="Generic HID Device Demo (Class Driver APIs)">
<info type="description" value="summary">
Generic HID device demo, implementing a device whose LEDs can be controlled via HID messages from the host. This demo uses the user-friendly USB Class Driver APIs to provide a simple, abstracted interface into the USB stack.
</info>
<info type="gui-flag" value="move-to-root"/>
<info type="keyword" value="Technology">
<keyword value="Class Driver APIs"/>
<keyword value="USB Device"/>
<keyword value="HID Class"/>
</info>
<device-support-alias value="lufa_avr8"/>
<device-support-alias value="lufa_xmega"/>
<device-support-alias value="lufa_uc3"/>
<build type="distribute" subtype="user-file" value="doxyfile"/>
<build type="distribute" subtype="user-file" value="GenericHID.txt"/>
<build type="distribute" subtype="directory" value="HostTestApp"/>
<build type="c-source" value="GenericHID.c"/>
<build type="c-source" value="Descriptors.c"/>
<build type="header-file" value="GenericHID.h"/>
<build type="header-file" value="Descriptors.h"/>
<build type="module-config" subtype="path" value="Config"/>
<build type="module-config" subtype="required-header-file" value="AppConfig.h"/>
<build type="header-file" value="Config/AppConfig.h"/>
<build type="header-file" value="Config/LUFAConfig.h"/>
<require idref="lufa.common"/>
<require idref="lufa.platform"/>
<require idref="lufa.drivers.usb"/>
<require idref="lufa.drivers.board"/>
<require idref="lufa.drivers.board.leds"/>
</module>
</asf>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
#
# LUFA Library
# Copyright (C) Dean Camera, 2014.
#
# dean [at] fourwalledcubicle [dot] com
# www.lufa-lib.org
#
# --------------------------------------
# LUFA Project Makefile.
# --------------------------------------
# Run "make help" for target help.
MCU = at90usb1287
ARCH = AVR8
BOARD = USBKEY
F_CPU = 8000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = GenericHID
SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
LUFA_PATH = ../../../../LUFA
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/
LD_FLAGS =
# Default target
all:
# Include LUFA build script makefiles
include $(LUFA_PATH)/Build/lufa_core.mk
include $(LUFA_PATH)/Build/lufa_sources.mk
include $(LUFA_PATH)/Build/lufa_build.mk
include $(LUFA_PATH)/Build/lufa_cppcheck.mk
include $(LUFA_PATH)/Build/lufa_doxygen.mk
include $(LUFA_PATH)/Build/lufa_dfu.mk
include $(LUFA_PATH)/Build/lufa_hid.mk
include $(LUFA_PATH)/Build/lufa_avrdude.mk
include $(LUFA_PATH)/Build/lufa_atprogram.mk