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:
parent
4d116a04e9
commit
f6d56675f9
1575 changed files with 421901 additions and 63190 deletions
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
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_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 {Insert Value Here}
|
||||
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
|
||||
// #define FIXED_NUM_CONFIGURATIONS {Insert Value Here}
|
||||
// #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 0
|
||||
// #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
|
||||
|
||||
#else
|
||||
|
||||
#error Unsupported architecture for this LUFA configuration file.
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
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 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.
|
||||
*
|
||||
* \return An error code from the GenericHIDHost_GetConfigDescriptorDataCodes_t enum.
|
||||
*/
|
||||
uint8_t ProcessConfigurationDescriptor(void)
|
||||
{
|
||||
uint8_t ConfigDescriptorData[512];
|
||||
void* CurrConfigLocation = ConfigDescriptorData;
|
||||
uint16_t CurrConfigBytesRem;
|
||||
|
||||
USB_Descriptor_Interface_t* HIDInterface = NULL;
|
||||
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
|
||||
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
while (!(DataINEndpoint) || !(DataOUTEndpoint))
|
||||
{
|
||||
/* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
|
||||
if (!(HIDInterface) ||
|
||||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor
|
||||
* but only found the mandatory IN endpoint, it's safe to continue with the device enumeration */
|
||||
if (DataINEndpoint)
|
||||
break;
|
||||
|
||||
/* Get the next HID interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoCompatibleInterfaceFound;
|
||||
}
|
||||
|
||||
/* Save the interface in case we need to refer back to it later */
|
||||
HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
|
||||
|
||||
/* Clear any found endpoints */
|
||||
DataOUTEndpoint = NULL;
|
||||
|
||||
/* Skip the remainder of the loop as we have not found an endpoint yet */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Retrieve the endpoint address from the endpoint descriptor */
|
||||
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* If the endpoint is a IN type endpoint */
|
||||
if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
|
||||
DataINEndpoint = EndpointData;
|
||||
else
|
||||
DataOUTEndpoint = EndpointData;
|
||||
}
|
||||
|
||||
/* Configure the HID data IN pipe */
|
||||
Pipe_ConfigurePipe(HID_DATA_IN_PIPE, EP_TYPE_INTERRUPT, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, 1);
|
||||
Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
|
||||
|
||||
/* Check if the HID interface contained an optional OUT data endpoint */
|
||||
if (DataOUTEndpoint)
|
||||
{
|
||||
/* Configure the HID data OUT pipe */
|
||||
Pipe_ConfigurePipe(HID_DATA_OUT_PIPE, EP_TYPE_INTERRUPT, DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, 1);
|
||||
}
|
||||
|
||||
/* 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 HID Class value.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextHIDInterface(void* CurrentDescriptor)
|
||||
{
|
||||
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
|
||||
|
||||
/* Determine if the current descriptor is an interface descriptor */
|
||||
if (Header->Type == DTYPE_Interface)
|
||||
{
|
||||
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
|
||||
|
||||
/* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */
|
||||
if (Interface->Class == HID_CLASS)
|
||||
{
|
||||
/* Indicate that the descriptor being searched for has been found */
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
|
||||
/* Current descriptor does not match what this comparator is looking for */
|
||||
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 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_NextHIDInterfaceDataEndpoint(void* CurrentDescriptor)
|
||||
{
|
||||
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
|
||||
|
||||
/* Determine the type of the current descriptor */
|
||||
if (Header->Type == DTYPE_Endpoint)
|
||||
{
|
||||
/* Indicate that the descriptor being searched for has been found */
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
else if (Header->Type == DTYPE_Interface)
|
||||
{
|
||||
/* Indicate that the search has failed prematurely and should be aborted */
|
||||
return DESCRIPTOR_SEARCH_Fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Current descriptor does not match what this comparator is looking for */
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
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 ConfigDescriptor.c.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIGDESCRIPTOR_H_
|
||||
#define _CONFIGDESCRIPTOR_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "MissileLauncher.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Interface Class value for the Human Interface Device class. */
|
||||
#define HID_CLASS 0x03
|
||||
|
||||
/** Pipe address for the HID data IN pipe. */
|
||||
#define HID_DATA_IN_PIPE (PIPE_DIR_IN | 1)
|
||||
|
||||
/** Pipe address for the HID data OUT pipe. */
|
||||
#define HID_DATA_OUT_PIPE (PIPE_DIR_OUT | 2)
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
|
||||
enum GenericHIDHost_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 */
|
||||
NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t ProcessConfigurationDescriptor(void);
|
||||
|
||||
uint8_t DComp_NextHIDInterface(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextHIDInterfaceDataEndpoint(void* CurrentDescriptor);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
USB Missile Launcher Demo
|
||||
Copyright (C) Dave Fletcher, 2010.
|
||||
fletch at fletchtronics dot net
|
||||
|
||||
Based on research by Scott Weston at
|
||||
http://code.google.com/p/pymissile
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
Copyright 2010 Dave Fletcher (fletch [at] fletchtronics [dot] net)
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Missile Launcher host. This is a host driver for the popular USB-controller table top toy missile launchers,
|
||||
* which can typically aim and fire small foam "missiles" from a spring-loaded turret. This project controls the
|
||||
* launcher via a joystick and button to aim and fire missiles at targets without a PC.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the MissileLauncher application. This file contains the main tasks of
|
||||
* the application and is responsible for the initial application hardware configuration as well
|
||||
* as the sending of commands to the attached launcher toy.
|
||||
*/
|
||||
|
||||
#include "MissileLauncher.h"
|
||||
|
||||
/** Launcher first init command report data sequence */
|
||||
static const uint8_t CMD_INITA[8] = { 85, 83, 66, 67, 0, 0, 4, 0 };
|
||||
|
||||
/** Launcher second init command report data sequence */
|
||||
static const uint8_t CMD_INITB[8] = { 85, 83, 66, 67, 0, 64, 2, 0 };
|
||||
|
||||
/** Launcher command report data sequence to stop all movement */
|
||||
static const uint8_t CMD_STOP[8] = { 0, 0, 0, 0, 0, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move left */
|
||||
static const uint8_t CMD_LEFT[8] = { 0, 1, 0, 0, 0, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move right */
|
||||
static const uint8_t CMD_RIGHT[8] = { 0, 0, 1, 0, 0, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move up */
|
||||
static const uint8_t CMD_UP[8] = { 0, 0, 0, 1, 0, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move down */
|
||||
static const uint8_t CMD_DOWN[8] = { 0, 0, 0, 0, 1, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move left and up */
|
||||
static const uint8_t CMD_LEFTUP[8] = { 0, 1, 0, 1, 0, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move right and up */
|
||||
static const uint8_t CMD_RIGHTUP[8] = { 0, 0, 1, 1, 0, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move left and down */
|
||||
static const uint8_t CMD_LEFTDOWN[8] = { 0, 1, 0, 0, 1, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to move right and down */
|
||||
static const uint8_t CMD_RIGHTDOWN[8] = { 0, 0, 1, 0, 1, 0, 8, 8 };
|
||||
|
||||
/** Launcher command report data sequence to fire a missile */
|
||||
static const uint8_t CMD_FIRE[8] = { 0, 0, 0, 0, 0, 1, 8, 8 };
|
||||
|
||||
/** Last command sent to the launcher, to determine what new command (if any) must be sent */
|
||||
static const uint8_t* CmdState;
|
||||
|
||||
/** Buffer to hold a command to send to the launcher */
|
||||
static uint8_t CmdBuffer[LAUNCHER_CMD_BUFFER_SIZE];
|
||||
|
||||
|
||||
/** 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();
|
||||
|
||||
CmdState = CMD_STOP;
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
GlobalInterruptEnable();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Read_Joystick_Status();
|
||||
DiscardNextReport();
|
||||
|
||||
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);
|
||||
#endif
|
||||
|
||||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
Joystick_Init();
|
||||
Buttons_Init();
|
||||
}
|
||||
|
||||
/** Reads the joystick and button status, sending commands to the launcher as needed. */
|
||||
void Read_Joystick_Status(void)
|
||||
{
|
||||
uint8_t JoyStatus_LCL = Joystick_GetStatus();
|
||||
uint8_t Buttons_LCL = Buttons_GetStatus();
|
||||
|
||||
if (Buttons_LCL & BUTTONS_BUTTON1)
|
||||
Send_Command(CMD_FIRE);
|
||||
else if (JoyStatus_LCL & JOY_UP)
|
||||
Send_Command(CMD_UP);
|
||||
else if (JoyStatus_LCL & JOY_DOWN)
|
||||
Send_Command(CMD_DOWN);
|
||||
else if (JoyStatus_LCL & JOY_LEFT)
|
||||
Send_Command(CMD_LEFT);
|
||||
else if (JoyStatus_LCL & JOY_RIGHT)
|
||||
Send_Command(CMD_RIGHT);
|
||||
else if (CmdState != CMD_STOP)
|
||||
Send_Command(CMD_STOP);
|
||||
}
|
||||
|
||||
/** Lower level send routine, copies report into a larger buffer and sends.
|
||||
*
|
||||
* \param[in] Report Report data to send.
|
||||
* \param[in] ReportSize Report length in bytes.
|
||||
*/
|
||||
void Send_Command_Report(const uint8_t* const Report,
|
||||
const uint16_t ReportSize)
|
||||
{
|
||||
memcpy(CmdBuffer, Report, 8);
|
||||
WriteNextReport(CmdBuffer, ReportSize);
|
||||
}
|
||||
|
||||
/** Sends one of the \c CMD_* command constants to the attached device.
|
||||
*
|
||||
* \param[in] Command One of the command constants.
|
||||
*/
|
||||
void Send_Command(const uint8_t* const Command)
|
||||
{
|
||||
if ((CmdState == CMD_STOP && Command != CMD_STOP) ||
|
||||
(CmdState != CMD_STOP && Command == CMD_STOP))
|
||||
{
|
||||
LEDs_ToggleLEDs(LEDS_LED4);
|
||||
|
||||
Send_Command_Report(CMD_INITA, 8);
|
||||
Send_Command_Report(CMD_INITB, 8);
|
||||
Send_Command_Report(Command, LAUNCHER_CMD_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
CmdState = Command;
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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_ENUMERATING);
|
||||
|
||||
/* Get and process the configuration descriptor data */
|
||||
if (ProcessConfigurationDescriptor() != SuccessfulConfigRead)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
|
||||
if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
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_Disable();
|
||||
|
||||
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)
|
||||
{
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Reads in and discards the next report from the attached device. */
|
||||
void DiscardNextReport(void)
|
||||
{
|
||||
if (USB_HostState != HOST_STATE_Configured)
|
||||
return;
|
||||
|
||||
/* Select and unfreeze HID data IN pipe */
|
||||
Pipe_SelectPipe(HID_DATA_IN_PIPE);
|
||||
Pipe_Unfreeze();
|
||||
|
||||
/* Check to see if a packet has been received */
|
||||
if (!(Pipe_IsINReceived()))
|
||||
{
|
||||
/* Refreeze HID data IN pipe */
|
||||
Pipe_Freeze();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Clear the IN endpoint, ready for next data packet */
|
||||
Pipe_ClearIN();
|
||||
|
||||
/* Refreeze HID data IN pipe */
|
||||
Pipe_Freeze();
|
||||
}
|
||||
|
||||
/** Writes a report to the attached device.
|
||||
*
|
||||
* \param[in] ReportOUTData Buffer containing the report to send to the device
|
||||
* \param[in] ReportLength Length of the report to send
|
||||
*/
|
||||
void WriteNextReport(uint8_t* const ReportOUTData,
|
||||
const uint16_t ReportLength)
|
||||
{
|
||||
if (USB_HostState != HOST_STATE_Configured)
|
||||
return;
|
||||
|
||||
/* Select and unfreeze HID data OUT pipe */
|
||||
Pipe_SelectPipe(HID_DATA_OUT_PIPE);
|
||||
|
||||
/* Not all HID devices have an OUT endpoint (some require OUT reports to be sent over the
|
||||
* control endpoint instead) - check to see if the OUT endpoint has been initialized */
|
||||
if (Pipe_IsConfigured())
|
||||
{
|
||||
Pipe_Unfreeze();
|
||||
|
||||
/* Ensure pipe is ready to be written to before continuing */
|
||||
if (!(Pipe_IsOUTReady()))
|
||||
{
|
||||
/* Refreeze the data OUT pipe */
|
||||
Pipe_Freeze();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write out HID report data */
|
||||
Pipe_Write_Stream_LE(ReportOUTData, ReportLength, NULL);
|
||||
|
||||
/* Clear the OUT endpoint, send last data packet */
|
||||
Pipe_ClearOUT();
|
||||
|
||||
/* Refreeze the data OUT pipe */
|
||||
Pipe_Freeze();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Class specific request to send a HID report to the device */
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
|
||||
.bRequest = HID_REQ_SetReport,
|
||||
.wValue = 0x02,
|
||||
.wIndex = 0x01,
|
||||
.wLength = ReportLength,
|
||||
};
|
||||
|
||||
/* Select the control pipe for the request transfer */
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
|
||||
/* Send the request to the device */
|
||||
USB_Host_SendControlRequest(ReportOUTData);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
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 MissileLauncher.c.
|
||||
*/
|
||||
|
||||
#ifndef _MISSILELAUNCHER_HOST_H_
|
||||
#define _MISSILELAUNCHER_HOST_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/power.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Board/Buttons.h>
|
||||
#include <LUFA/Drivers/Board/Joystick.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Platform/Platform.h>
|
||||
|
||||
#include "ConfigDescriptor.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)
|
||||
|
||||
/** Size of the Launcher report command buffer. */
|
||||
#define LAUNCHER_CMD_BUFFER_SIZE 64
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
|
||||
void Read_Joystick_Status(void);
|
||||
void Send_Command_Report(const uint8_t* const Report,
|
||||
const uint16_t ReportSize);
|
||||
void Send_Command(const uint8_t* const Command);
|
||||
|
||||
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 DiscardNextReport(void);
|
||||
void WriteNextReport(uint8_t* const ReportOUTData,
|
||||
const uint16_t ReportLength);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/** \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 David Fletcher's Missile Launcher
|
||||
*
|
||||
* \section Sec_Compat Project Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this project.
|
||||
*
|
||||
* \li Series 7 USB AVRs (AT90USBxxx7)
|
||||
*
|
||||
* \section Sec_Info USB Information:
|
||||
*
|
||||
* The following table gives a rundown of the USB utilization of this project.
|
||||
*
|
||||
* <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, USBIF HID Usage Tables</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Supported USB Speeds:</b></td>
|
||||
* <td>Low Speed Mode, Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* Missile Launcher host. This is a host driver for the popular USB-controller table top toy missile launchers,
|
||||
* which can typically aim and fire small foam "missiles" from a spring-loaded turret. This project controls the
|
||||
* launcher via a joystick and button to aim and fire missiles at targets without a PC.
|
||||
*
|
||||
* \section Sec_Options Project Options
|
||||
*
|
||||
* The following defines can be found in this project, which can control the project behaviour when defined, or changed in value.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>
|
||||
* None
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
49
protocol/lufa/LUFA-git/Projects/MissileLauncher/asf.xml
Normal file
49
protocol/lufa/LUFA-git/Projects/MissileLauncher/asf.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<asf xmlversion="1.0">
|
||||
<project caption="Missile Launcher" id="lufa.projects.missile_launcher.avr8">
|
||||
<require idref="lufa.projects.missile_launcher"/>
|
||||
<require idref="lufa.boards.dummy.avr8"/>
|
||||
<generator value="as5_8"/>
|
||||
|
||||
<device-support value="at90usb1287"/>
|
||||
<config name="lufa.drivers.board.name" value="usbkey"/>
|
||||
|
||||
<build type="define" name="F_CPU" value="8000000UL"/>
|
||||
<build type="define" name="F_USB" value="8000000UL"/>
|
||||
</project>
|
||||
|
||||
<module type="application" id="lufa.projects.missile_launcher" caption="Missile Launcher">
|
||||
<info type="description" value="summary">
|
||||
Missile launcher project.
|
||||
</info>
|
||||
|
||||
<info type="gui-flag" value="move-to-root"/>
|
||||
|
||||
<info type="keyword" value="Technology">
|
||||
<keyword value="Low Level APIs"/>
|
||||
<keyword value="USB Host"/>
|
||||
</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="MissileLauncher.txt"/>
|
||||
|
||||
<build type="c-source" value="MissileLauncher.c"/>
|
||||
<build type="c-source" value="ConfigDescriptor.c"/>
|
||||
<build type="header-file" value="MissileLauncher.h"/>
|
||||
<build type="header-file" value="ConfigDescriptor.h"/>
|
||||
|
||||
<build type="module-config" subtype="path" value="Config"/>
|
||||
<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.buttons"/>
|
||||
<require idref="lufa.drivers.board.joystick"/>
|
||||
<require idref="lufa.drivers.board.leds"/>
|
||||
</module>
|
||||
</asf>
|
2364
protocol/lufa/LUFA-git/Projects/MissileLauncher/doxyfile
Normal file
2364
protocol/lufa/LUFA-git/Projects/MissileLauncher/doxyfile
Normal file
File diff suppressed because it is too large
Load diff
38
protocol/lufa/LUFA-git/Projects/MissileLauncher/makefile
Normal file
38
protocol/lufa/LUFA-git/Projects/MissileLauncher/makefile
Normal 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 = MissileLauncher
|
||||
SRC = $(TARGET).c ConfigDescriptor.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
|
Loading…
Add table
Add a link
Reference in a new issue