1
0

Merge commit 'f6d56675f9f981c5464f0ca7a1fbb0162154e8c5'

This commit is contained in:
tmk 2015-05-13 11:13:10 +09:00
commit f1f2066657
1575 changed files with 421901 additions and 63190 deletions

View File

@ -1,6 +0,0 @@
[submodule "protocol/lufa/LUFA-git"]
path = protocol/lufa/LUFA-git
url = https://github.com/abcminiuser/lufa.git
[submodule "protocol/usb_hid/USB_Host_Shield_2.0"]
path = protocol/usb_hid/USB_Host_Shield_2.0
url = https://github.com/felis/USB_Host_Shield_2.0.git

View File

@ -1,11 +1,7 @@
LUFA_DIR = protocol/lufa
# Path to the LUFA library
ifeq (, $(wildcard $(TMK_DIR)/$(LUFA_DIR)/LUFA-git/LUFA/Version.h))
LUFA_PATH ?= $(LUFA_DIR)/LUFA-120730
else
LUFA_PATH ?= $(LUFA_DIR)/LUFA-git
endif
LUFA_PATH ?= $(LUFA_DIR)/LUFA-git
# Create the LUFA source path variables by including the LUFA makefile

View File

@ -1,116 +0,0 @@
#
# LUFA Library
# Copyright (C) Dean Camera, 2012.
#
# dean [at] fourwalledcubicle [dot] com
# www.lufa-lib.org
#
LUFA_BUILD_MODULES += SOURCES
LUFA_BUILD_TARGETS +=
LUFA_BUILD_MANDATORY_VARS += LUFA_PATH ARCH
LUFA_BUILD_OPTIONAL_VARS +=
LUFA_BUILD_PROVIDED_VARS += LUFA_SRC_USB LUFA_SRC_USBCLASS LUFA_SRC_TEMPERATURE LUFA_SRC_SERIAL LUFA_SRC_TWI LUFA_SRC_PLATFORM
LUFA_BUILD_PROVIDED_MACROS +=
# -----------------------------------------------------------------------------
# LUFA Sources Buildsystem Makefile Module.
# -----------------------------------------------------------------------------
# DESCRIPTION:
# Provides a set of makefile variables for the various LUFA module sources.
# Once included, the sources required to use a given LUFA module will become
# available using the makefile variable names listed in the LUFA project
# documentation.
# -----------------------------------------------------------------------------
# TARGETS:
#
# (None)
#
# MANDATORY PARAMETERS:
#
# LUFA_PATH - Path to the LUFA library core
# ARCH - Device architecture name
#
# OPTIONAL PARAMETERS:
#
# (None)
#
# PROVIDED VARIABLES:
#
# LUFA_SRC_USB - List of LUFA USB driver source files
# LUFA_SRC_USBCLASS - List of LUFA USB Class driver source files
# LUFA_SRC_TEMPERATURE - List of LUFA temperature sensor driver source
# files
# LUFA_SRC_SERIAL - List of LUFA Serial U(S)ART driver source files
# LUFA_SRC_TWI - List of LUFA TWI driver source files
# LUFA_SRC_PLATFORM - List of LUFA architecture specific platform
# management source files
#
# PROVIDED MACROS:
#
# (None)
#
# -----------------------------------------------------------------------------
SHELL = /bin/sh
ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
# Sanity check user supplied values
$(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
$(call ERROR_IF_EMPTY, LUFA_PATH)
$(call ERROR_IF_EMPTY, ARCH)
# Allow LUFA_ROOT_PATH to be overridden elsewhere to support legacy LUFA makefiles
LUFA_ROOT_PATH ?= $(patsubst %/,%,$(LUFA_PATH))
# Construct LUFA module source variables
LUFA_SRC_USB := $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Device_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Endpoint_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Host_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Pipe_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/USBController_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/USBInterrupt_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/EndpointStream_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/PipeStream_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/ConfigDescriptors.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/DeviceStandardReq.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/Events.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/HostStandardReq.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/USBTask.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Common/HIDParser.c
LUFA_SRC_USBCLASS := $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/AudioClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/CDCClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/HIDClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/MassStorageClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/MIDIClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/RNDISClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/AudioClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/CDCClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/HIDClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/MassStorageClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/MIDIClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/PrinterClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/RNDISClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/StillImageClassHost.c
LUFA_SRC_TEMPERATURE := $(LUFA_ROOT_PATH)/Drivers/Board/Temperature.c
LUFA_SRC_SERIAL := $(LUFA_ROOT_PATH)/Drivers/Peripheral/$(ARCH)/Serial_$(ARCH).c
LUFA_SRC_TWI := $(LUFA_ROOT_PATH)/Drivers/Peripheral/$(ARCH)/TWI_$(ARCH).c
ifeq ($(ARCH), UC3)
LUFA_SRC_PLATFORM := $(LUFA_ROOT_PATH)/Platform/UC3/Exception.S \
$(LUFA_ROOT_PATH)/Platform/UC3/InterruptManagement.c
else
LUFA_SRC_PLATFORM :=
endif
# Build a list of all available module sources
LUFA_SRC_ALL_FILES := $(LUFA_SRC_USB) \
$(LUFA_SRC_USBCLASS) \
$(LUFA_SRC_TEMPERATURE) \
$(LUFA_SRC_SERIAL) \
$(LUFA_SRC_TWI) \
$(LUFA_SRC_PLATFORM)

File diff suppressed because it is too large Load Diff

View File

@ -1,223 +0,0 @@
/** \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.
*/
/** \page Page_TokenSummary Summary of Compile Tokens
*
* The following lists all the possible tokens which can be defined in a project makefile, and passed to the
* compiler via the -D switch, to alter the LUFA library code. These tokens may alter the library behaviour,
* or remove features unused by a given application in order to save flash space.
*
* \note If the \c USE_LUFA_CONFIG_HEADER token is defined, the library will include a header file named \c LUFAConfig.h located
* in the user directory where the below compile time tokens may be defined. This allows for an alternative to makefile
* defined tokens for configuring the library.
*
* \section Sec_SummaryNonUSBTokens Non USB Related Tokens
* This section describes compile tokens which affect non-USB sections of the LUFA library.
*
* - <b>DISABLE_TERMINAL_CODES</b> - (\ref Group_Terminal) - <i>All Architectures</i> \n
* If an application contains ANSI terminal control codes listed in TerminalCodes.h, it might be desired to remove them
* at compile time for use with a terminal which is non-ANSI control code aware, without modifying the source code. If
* this token is defined, all ANSI control codes in the application code from the TerminalCodes.h header are removed from
* the source code at compile time.
*
*
* \section Sec_SummaryUSBClassTokens USB Class Driver Related Tokens
* This section describes compile tokens which affect USB class-specific drivers in the LUFA library.
*
* - <b>HID_HOST_BOOT_PROTOCOL_ONLY</b> - (\ref Group_USBClassHIDHost) - <i>All Architectures</i> \n
* By default, the USB HID Host class driver is designed to work with HID devices using either the Boot or Report HID
* communication protocols. On devices where the Report protocol is not used (i.e. in applications where only basic
* Mouse or Keyboard operation is desired, using boot compatible devices), the code responsible for the Report protocol
* mode can be removed to save space in the compiled application by defining this token. When defined, it is still necessary
* to explicitly put the attached device into Boot protocol mode via a call to \ref HID_Host_SetBootProtocol().
*
* - <b>HID_STATETABLE_STACK_DEPTH</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports may contain PUSH and POP elements, to store and retrieve the current HID state table onto a stack. This
* allows for reports to save the state table before modifying it slightly for a data item, and then restore the previous
* state table in a compact manner. This token may be defined to a non-zero 8-bit value to give the maximum depth of the state
* table stack. If not defined, this defaults to the value indicated in the HID.h file documentation.
*
* - <b>HID_USAGE_STACK_DEPTH</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports generally contain many USAGE elements, which are assigned to INPUT, OUTPUT and FEATURE items in succession
* when multiple items are defined at once (via REPORT COUNT elements). This allows for several items to be defined with
* different usages in a compact manner. This token may be defined to a non-zero 8-bit value to set the maximum depth of the
* usage stack, indicating the maximum number of USAGE items which can be stored temporarily until the next INPUT, OUTPUT
* and FEATURE item. If not defined, this defaults to the value indicated in the HID.h file documentation.
*
* - <b>HID_MAX_COLLECTIONS</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports generally contain several COLLECTION elements, used to group related data items together. Collection information
* is stored separately in the processed usage structure (and referred to by the data elements in the structure) to save space.
* This token may be defined to a non-zero 8-bit value to set the maximum number of COLLECTION items which can be processed by the
* parser into the resultant processed report structure. If not defined, this defaults to the value indicated in the HID.h file
* documentation.
*
* - <b>HID_MAX_REPORTITEMS</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* All HID reports contain one or more INPUT, OUTPUT and/or FEATURE items describing the data which can be sent to and from the HID
* device. Each item has associated usages, bit offsets in the item reports and other associated data indicating the manner in which
* the report data should be interpreted by the host. This token may be defined to a non-zero 8-bit value to set the maximum number of
* data elements which can be stored in the processed HID report structure, including INPUT, OUTPUT and (if enabled) FEATURE items.
* If a item has a multiple count (i.e. a REPORT COUNT of more than 1), each item in the report count is placed separately in the
* processed HID report table. If not defined, this defaults to the value indicated in the HID.h file documentation.
*
* - <b>HID_MAX_REPORT_IDS</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports may contain several report IDs, to logically distinguish grouped device data from one another - for example, a combination
* keyboard and mouse might use report IDs to separate the keyboard reports from the mouse reports. In order to determine the size of each
* report, and thus know how many bytes must be read or written, the size of each report (IN, OUT and FEATURE) must be calculated and
* stored. This token may be defined to a non-zero 8-bit value to set the maximum number of report IDs in a device which can be processed
* and their sizes calculated/stored into the resultant processed report structure. If not defined, this defaults to the value indicated in
* the HID.h file documentation.
*
* - <b>NO_CLASS_DRIVER_AUTOFLUSH</b> - (\ref Group_USBClassDrivers) - <i>All Architectures</i> \n
* Many of the device and host mode class drivers automatically flush any data waiting to be written to an interface, when the corresponding
* USB management task is executed. This is usually desirable to ensure that any queued data is sent as soon as possible once and new data is
* constructed in the main program loop. However, if flushing is to be controlled manually by the user application via the *_Flush() commands,
* the compile time token may be defined in the application's makefile to disable automatic flushing during calls to the class driver USB
* management tasks.
*
*
* \section Sec_SummaryUSBTokens General USB Driver Related Tokens
* This section describes compile tokens which affect USB driver stack as a whole in the LUFA library.
*
* - <b>ORDERED_EP_CONFIG</b> - (\ref Group_EndpointManagement , \ref Group_PipeManagement) - <i>AVR8, UC3</i> \n
* The USB AVRs do not allow for Endpoints and Pipes to be configured out of order; they <i>must</i> be configured in an ascending order to
* prevent data corruption issues. However, by default LUFA employs a workaround to allow for unordered Endpoint/Pipe initialization. This compile
* time token may be used to restrict the initialization order to ascending indexes only in exchange for a smaller compiled binary size. Use
* caution when applied to applications using the library USB Class drivers; the user application must ensure that all endpoints and pipes are
* allocated sequentially.
*
* - <b>USE_STATIC_OPTIONS</b>=<i>x</i> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* By default, the USB_Init() function accepts dynamic options at runtime to alter the library behaviour, including whether the USB pad
* voltage regulator is enabled, and the device speed when in device mode. By defining this token to a mask comprised of the USB options
* mask defines usually passed as the Options parameter to USB_Init(), the resulting compiled binary can be decreased in size by removing
* the dynamic options code, and replacing it with the statically set options. When defined, the USB_Init() function no longer accepts an
* Options parameter.
*
* - <b>USB_DEVICE_ONLY</b> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* For the USB AVR models supporting both device and host USB modes, the USB_Init() function contains a Mode parameter which specifies the
* mode the library should be initialized to. If only device mode is required, the code for USB host mode can be removed from the binary to
* save space. When defined, the USB_Init() function no longer accepts a Mode parameter. This define is irrelevant on smaller USB AVRs which
* do not support host mode.
*
* - <b>USB_HOST_ONLY</b> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* Same as USB_DEVICE_ONLY, except the library is fixed to USB host mode rather than USB device mode. Not available on some USB AVR models.
*
* - <b>USB_STREAM_TIMEOUT_MS</b>=<i>x</i> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* When endpoint and/or pipe stream functions are used, by default there is a timeout between each transfer which the connected device or host
* must satisfy, or the stream function aborts the remaining data transfer. This token may be defined to a non-zero 16-bit value to set the timeout
* period for stream transfers, specified in milliseconds. If not defined, the default value specified in LowLevel.h is used instead.
*
* - <b>NO_LIMITED_CONTROLLER_CONNECT</b> - (\ref Group_Events) - <i>AVR8 Only</i> \n
* On the smaller USB AVRs, the USB controller lacks VBUS events to determine the physical connection state of the USB bus to a host. In lieu of
* VBUS events, the library attempts to determine the connection state via the bus suspension and wake up events instead. This however may be
* slightly inaccurate due to the possibility of the host suspending the bus while the device is still connected. If accurate connection status is
* required, the VBUS line of the USB connector should be routed to an AVR pin to detect its level, so that the USB_DeviceState global
* can be accurately set and the \ref EVENT_USB_Device_Connect() and \ref EVENT_USB_Device_Disconnect() events manually raised by the RAISE_EVENT macro.
* When defined, this token disables the library's auto-detection of the connection state by the aforementioned suspension and wake up events.
*
* - <b>NO_SOF_EVENTS</b> - (\ref Group_Events) - <i>All Architectures</i> \n
* By default, there exists a LUFA application event for the start of each USB frame while the USB bus is not suspended in either host or device mode.
* This event can be selectively enabled or disabled by calling the appropriate device or host mode function. When this compile time token is defined,
* the ability to receive USB Start of Frame events via the \ref EVENT_USB_Device_StartOfFrame() or \ref EVENT_USB_Host_StartOfFrame() events is removed,
* reducing the compiled program's binary size.
*
*
* \section Sec_SummaryUSBDeviceTokens USB Device Mode Driver Related Tokens
* This section describes compile tokens which affect USB driver stack of the LUFA library when used in Device mode.
*
* - <b>USE_RAM_DESCRIPTORS</b> - (\ref Group_StdDescriptors) - <i>AVR8 Only</i> \n
* Define this token to indicate to the USB driver that all device descriptors are stored in RAM, rather than being located in any one
* of the AVR's memory spaces. RAM descriptors may be desirable in applications where the descriptors need to be modified at runtime.
*
* - <b>USE_FLASH_DESCRIPTORS</b> - (\ref Group_StdDescriptors) - <i>AVR8 Only</i> \n
* Similar to USE_RAM_DESCRIPTORS, but all descriptors are stored in the AVR's FLASH memory rather than RAM.
*
* - <b>USE_EEPROM_DESCRIPTORS</b> - (\ref Group_StdDescriptors) - <i>AVR8 Only</i> \n
* Similar to USE_RAM_DESCRIPTORS, but all descriptors are stored in the AVR's EEPROM memory rather than RAM.
*
* - <b>NO_INTERNAL_SERIAL</b> - (\ref Group_StdDescriptors) - <i>All Architectures</i> \n
* Some AVR models contain a unique serial number which can be used as the device serial number, while in device mode. This allows
* the host to uniquely identify the device regardless of if it is moved between USB ports on the same computer, allowing allocated
* resources (such as drivers, COM Port number allocations) to be preserved. This is not needed in many apps, and so the code that
* performs this task can be disabled by defining this option and passing it to the compiler via the -D switch.
*
* - <b>FIXED_CONTROL_ENDPOINT_SIZE</b>=<i>x</i> - (\ref Group_EndpointManagement) - <i>All Architectures</i> \n
* By default, the library determines the size of the control endpoint (when in device mode) by reading the device descriptor.
* Normally this reduces the amount of configuration required for the library, allows the value to change dynamically (if
* descriptors are stored in EEPROM or RAM rather than flash memory) and reduces code maintenance. However, this token can be
* defined to a non-zero value instead to give the size in bytes of the control endpoint, to reduce the size of the compiled
* binary.
*
* - <b>DEVICE_STATE_AS_GPIOR</b> - (\ref Group_Device) - <i>AVR8 Only</i> \n
* One of the most frequently used global variables in the stack is the USB_DeviceState global, which indicates the current state of
* the Device State Machine. To reduce the amount of code and time required to access and modify this global in an application, this token
* may be defined to a value between 0 and 2 to fix the state variable into one of the three general purpose IO registers inside the AVR
* reserved for application use. When defined, the corresponding GPIOR register should not be used within the user application except
* implicitly via the library APIs.
*
* - <b>FIXED_NUM_CONFIGURATIONS</b>=<i>x</i> - (\ref Group_Device) - <i>All Architectures</i> \n
* By default, the library determines the number of configurations a USB device supports by reading the device descriptor. This reduces
* the amount of configuration required to set up the library, and allows the value to change dynamically (if descriptors are stored in
* EEPROM or RAM rather than flash memory) and reduces code maintenance. However, this value may be fixed via this token in the project
* makefile to reduce the compiled size of the binary at the expense of flexibility.
*
* - <b>CONTROL_ONLY_DEVICE</b> - (\ref Group_Device) - <i>All Architectures</i> \n
* In some limited USB device applications, there are no device endpoints other than the control endpoint; i.e. all device communication
* is through control endpoint requests. Defining this token will remove several features related to the selection and control of device
* endpoints internally, saving space. Generally, this is usually only useful in (some) bootloaders and is best avoided.
*
* - <b>MAX_ENDPOINT_INDEX</b> - (\ref Group_Device) - <i>XMEGA Only</i> \n
* Defining this value to the highest index (not address - this excludes the direction flag) endpoint within the device will restrict the
* number of FIFOs created internally for the endpoint buffers, reducing the total RAM usage.
*
* - <b>INTERRUPT_CONTROL_ENDPOINT</b> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* Some applications prefer to not call the USB_USBTask() management task regularly while in device mode, as it can complicate code significantly.
* Instead, when device mode is used this token can be passed to the library via the -D switch to allow the library to manage the USB control
* endpoint entirely via USB controller interrupts asynchronously to the user application. When defined, USB_USBTask() does not need to be called
* when in USB device mode.
*
* - <b>NO_DEVICE_REMOTE_WAKEUP</b> - (\ref Group_Device) - <i>All Architectures</i> \n
* Many devices do not require the use of the Remote Wakeup features of USB, used to wake up the USB host when suspended. On these devices,
* the code required to manage device Remote Wakeup can be disabled by defining this token and passing it to the library via the -D switch.
*
* - <b>NO_DEVICE_SELF_POWER</b> - (\ref Group_Device) - <i>All Architectures</i> \n
* USB devices may be bus powered, self powered, or a combination of both. When a device can be both bus powered and self powered, the host may
* query the device to determine the current power source, via \ref USB_Device_CurrentlySelfPowered. For solely bus powered devices, this global
* and the code required to manage it may be disabled by passing this token to the library via the -D switch.
*
*
* \section Sec_SummaryUSBHostTokens USB Host Mode Driver Related Tokens
*
* This section describes compile tokens which affect USB driver stack of the LUFA library when used in Host mode.
*
* - <b>HOST_STATE_AS_GPIOR</b> - (\ref Group_Host) - <i>AVR8 Only</i> \n
* One of the most frequently used global variables in the stack is the USB_HostState global, which indicates the current state of
* the Host State Machine. To reduce the amount of code and time required to access and modify this global in an application, this token
* may be defined to a value between 0 and 2 to fix the state variable into one of the three general purpose IO registers inside the AVR
* reserved for application use. When defined, the corresponding GPIOR register should not be used within the user application except
* implicitly via the library APIs.
*
* - <b>USB_HOST_TIMEOUT_MS</b>=<i>x</i> - (\ref Group_Host) - <i>All Architectures</i> \n
* When a control transfer is initiated in host mode to an attached device, a timeout is used to abort the transfer if the attached
* device fails to respond within the timeout period. This token may be defined to a non-zero 16-bit value to set the timeout period for
* control transfers, specified in milliseconds. If not defined, the default value specified in Host.h is used instead.
*
* - <b>HOST_DEVICE_SETTLE_DELAY_MS</b>=<i>x</i> - (\ref Group_Host) - <i>All Architectures</i> \n
* Some devices require a delay of up to 5 seconds after they are connected to VBUS before the enumeration process can be started, or
* they will fail to enumerate correctly. By placing a delay before the enumeration process, it can be ensured that the bus has settled
* back to a known idle state before communications occur with the device. This token may be defined to a 16-bit value to set the device
* settle period, specified in milliseconds. If not defined, the default value specified in Host.h is used instead.
*
* - <b>INVERTED_VBUS_ENABLE_LINE</b> - (\ref Group_Host) - <i>All Architectures</i> \n
* If enabled, this will indicate that the USB target VBUS line polarity is inverted; i.e. it should be pulled low to enable VBUS to the
* target, and pulled high to stop the target VBUS generation.
*
* \attention On AVR8 architecture devices, this compile time option requires \c NO_AUTO_VBUS_MANAGEMENT to be set.
*
* - <b>NO_AUTO_VBUS_MANAGEMENT</b> - (\ref Group_Host) - <i>All Architectures</i> \n
* Disables the automatic management of VBUS to the target, i.e. automatic shut down in the even of an overcurrent situation. When enabled, VBUS
* is enabled while the USB controller is initialized in USB Host mode.
*/

View File

@ -1,44 +0,0 @@
/** \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.
*/
/** \page Page_KnownIssues Known Issues
* The following are known issues present in each official LUFA release. This list should contain all known
* issues in the library. Most of these issues should be corrected in the future release - see
* \ref Page_FutureChanges for a list of planned changes in future releases.
*
* \section Sec_KnownIssues120730 Version 120730
* - AVR8 Architecture
* - No known issues.
* - UC3 Architecture
* \warning The UC3 device support is currently <b>experimental</b> (incomplete and/or non-functional), and is included for preview purposes only. \n
*
* - No demos, bootloaders or projects have been ported for the UC3 devices in the current release,
* although the architecture is supported in the LUFA core library.
* - DMA transfers to and from the USB controller are not yet implemented for this release.
* - The UC3C, UC3D and UC3L sub-families of UC3 are not currently supported by the library due to their
* altered USB controller design.
* - The various \c CreateStream() functions for creating standard \c <stdio.h> compatible virtual file
* streams are not available on the UC3 architecture, due to a lack of suitable library support.
* - XMEGA Architecture
* \warning The XMEGA device support is currently <b>experimental</b> (incomplete and/or non-functional), and is included for preview purposes only.
*
* - No demos, bootloaders or projects have been ported for the XMEGA devices in the current release,
* although the architecture is supported in the LUFA core library.
* - Endpoints of more than 64 bytes are not currently supported in this release.
* - Isochronous endpoints are not currently supported in this release. As a result, the audio class
* cannot be used on XMEGA devices.
* - Multiple-bank endpoints are not currently supported in this release.
* - Early revisions of the ATXMEGA128A1U are incompatible with LUFA, due to their various errata
* relating to the USB controller.
* - Architecture Independent
* - The HID parser fails for array type elements that have a MIN and MAX usage applied; each element
* in the array will receive a unique incrementing usage from the MIN value, up to MAX.
* - The LUFA library is not watchdog aware, and thus timeouts are possible if short periods are used
* and a lengthy USB operation is initiated.
* - Build System
* - No known issues.
*/

View File

@ -1,22 +0,0 @@
/** \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.
*/
/**
* \page Page_LicenseInfo Source Code License
*
* The LUFA library is currently released under the MIT license, included below.
*
* Commercial entities can opt out of the public disclosure clause in this license
* for a one-time US$1500 payment. This provides a non-exclusive modified MIT licensed which
* allows for the free use of the LUFA library, bootloaders and (where the sole copyright
* is attributed to Dean Camera) demos without public disclosure within an organization, in
* addition to three free hours of consultation with the library author, and priority support.
* Please visit the Commercial License link on \ref Page_Resources for more information on
* ordering a commercial license for your company.
*
* \verbinclude License.txt
*/

View File

@ -1,424 +0,0 @@
/** \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.
*/
/** \page Page_VIDPID VID and PID values
*
* \section Sec_VIDPID_Allocations VID and PID Allocations
* The LUFA library uses VID/PID combinations generously donated by Atmel. The following VID/PID combinations
* are used within the LUFA demos, and thus may be re-used by derivations of each demo. Free PID values may be
* used by future LUFA demo projects.
*
* <b>These VID/PID values should not be used in commercial designs under any circumstances.</b> Private projects
* may use the following values freely, but must accept any collisions due to other LUFA derived private projects
* sharing identical values. It is suggested that private projects using interfaces compatible with existing
* demos share the same VID/PID value.
*
* <table>
*
* <tr>
* <td>
* <b>VID</b>
* </td>
* <td>
* <b>PID</b>
* </td>
* <td>
* <b>Usage</b>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2040
* </td>
* <td>
* Test VID/PID (See below)
* </td>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2041
* </td>
* <td>
* Mouse Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2042
* </td>
* <td>
* Keyboard Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2043
* </td>
* <td>
* Joystick Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2044
* </td>
* <td>
* CDC Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2045
* </td>
* <td>
* Mass Storage Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2046
* </td>
* <td>
* Audio Output Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2047
* </td>
* <td>
* Audio Input Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2048
* </td>
* <td>
* MIDI Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2049
* </td>
* <td>
* MagStripe Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204A
* </td>
* <td>
* CDC Bootloader
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204B
* </td>
* <td>
* USB to Serial Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204C
* </td>
* <td>
* RNDIS Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204D
* </td>
* <td>
* Combined Keyboard and Mouse Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204E
* </td>
* <td>
* Dual CDC Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204F
* </td>
* <td>
* Generic HID Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2060
* </td>
* <td>
* Benito Programmer Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2061
* </td>
* <td>
* Combined Mass Storage and Keyboard Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2062
* </td>
* <td>
* Combined CDC and Mouse Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2063
* </td>
* <td>
* Mass Storage/HID Interface Datalogger Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2064
* </td>
* <td>
* Interfaceless Control-Only LUFA Devices
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2065
* </td>
* <td>
* Test and Measurement Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2066
* </td>
* <td>
* Multiple Report Keyboard/Mouse HID Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2067
* </td>
* <td>
* HID Class Bootloader
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2068
* </td>
* <td>
* Virtual Serial/Mass Storage Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2069
* </td>
* <td>
* Webserver Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206A
* </td>
* <td>
* Media Control Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206B
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206C
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206D
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206E
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206F
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* </table>
*
* \section Sec_Test_VIDPID The Test VID/PID Combination
* For use in testing of LUFA powered devices during development only, by non-commercial entities.
* All devices must accept collisions on this VID/PID range (from other in-development LUFA devices)
* to be resolved by using a unique release number in the Device Descriptor. No devices using this
* VID/PID combination may be released to the general public.
*/

View File

@ -1,27 +0,0 @@
/** \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.
*/
/** \page Page_WritingBoardDrivers Writing LUFA Board Drivers
*
* LUFA ships with several basic pre-made board drivers, to control hardware present on the supported board
* hardware - such as Dataflash ICs, LEDs, Joysticks, or other hardware peripherals. When compiling an application
* which makes use of one or more board drivers located in LUFA/Drivers/Board, you must also indicate what board
* hardware you are using in your project makefile. This is done by defining the BOARD macro using the -D switch
* passed to the compiler, with a constant of BOARD_{Name}. For example <b>-DBOARD=BOARD_USBKEY</b> instructs the
* compiler to use the USBKEY board hardware drivers.
*
* If your application does not use *any* board level drivers, you can omit the definition of the BOARD macro.
* However, some users may wish to write their own custom board hardware drivers which are to remain compatible
* with the LUFA hardware API. To do this, the BOARD macro should be defined to the value BOARD_USER. This indicates
* that the board level drivers should be located in a folder named "Board" located inside the application's folder.
*
* When used, the driver stub files located in the LUFA/CodeTemplates/DriverStubs folder should be copied to the user
* Board/ directory, and fleshed out to include the values and code needed to control the custom board hardware. Once
* done, the existing LUFA board level APIs (accessed in the regular LUFA/Drivers/Board/ folder) will redirect to the
* user board drivers, maintaining code compatibility and allowing for a different board to be selected through the
* project makefile with no code changes.
*/

@ -1 +0,0 @@
Subproject commit b6c18b2a7c544653efbe12a1d4e8ba65e7d83c35

View File

@ -0,0 +1,14 @@
*.o
*.d
*.elf
*.hex
*.eep
*.sym
*.bin
*.lss
*.map
*.bak
*.class
Documentation/
LUFA/StudioIntegration/ProjectGenerator/*
LUFA/StudioIntegration/DocBook/*

View File

@ -0,0 +1,75 @@
/*
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
*
* Bootloader user application API functions.
*/
#include "BootloaderAPI.h"
void BootloaderAPI_ErasePage(const uint32_t Address)
{
boot_page_erase_safe(Address);
boot_spm_busy_wait();
boot_rww_enable();
}
void BootloaderAPI_WritePage(const uint32_t Address)
{
boot_page_write_safe(Address);
boot_spm_busy_wait();
boot_rww_enable();
}
void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word)
{
boot_page_fill_safe(Address, Word);
}
uint8_t BootloaderAPI_ReadSignature(const uint16_t Address)
{
return boot_signature_byte_get(Address);
}
uint8_t BootloaderAPI_ReadFuse(const uint16_t Address)
{
return boot_lock_fuse_bits_get(Address);
}
uint8_t BootloaderAPI_ReadLock(void)
{
return boot_lock_fuse_bits_get(GET_LOCK_BITS);
}
void BootloaderAPI_WriteLock(const uint8_t LockBits)
{
boot_lock_bits_set_safe(LockBits);
}

View File

@ -0,0 +1,58 @@
/*
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 BootloaderAPI.c.
*/
#ifndef _BOOTLOADER_API_H_
#define _BOOTLOADER_API_H_
/* Includes: */
#include <avr/io.h>
#include <avr/boot.h>
#include <stdbool.h>
#include <LUFA/Common/Common.h>
#include "Config/AppConfig.h"
/* Function Prototypes: */
void BootloaderAPI_ErasePage(const uint32_t Address);
void BootloaderAPI_WritePage(const uint32_t Address);
void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word);
uint8_t BootloaderAPI_ReadSignature(const uint16_t Address);
uint8_t BootloaderAPI_ReadFuse(const uint16_t Address);
uint8_t BootloaderAPI_ReadLock(void);
void BootloaderAPI_WriteLock(const uint8_t LockBits);
#endif

View File

@ -0,0 +1,91 @@
/*
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.
*/
; Trampolines to actual API implementations if the target address is outside the
; range of a rjmp instruction (can happen with large bootloader sections)
.section .apitable_trampolines, "ax"
.global BootloaderAPI_Trampolines
BootloaderAPI_Trampolines:
BootloaderAPI_ErasePage_Trampoline:
jmp BootloaderAPI_ErasePage
BootloaderAPI_WritePage_Trampoline:
jmp BootloaderAPI_WritePage
BootloaderAPI_FillWord_Trampoline:
jmp BootloaderAPI_FillWord
BootloaderAPI_ReadSignature_Trampoline:
jmp BootloaderAPI_ReadSignature
BootloaderAPI_ReadFuse_Trampoline:
jmp BootloaderAPI_ReadFuse
BootloaderAPI_ReadLock_Trampoline:
jmp BootloaderAPI_ReadLock
BootloaderAPI_WriteLock_Trampoline:
jmp BootloaderAPI_WriteLock
BootloaderAPI_UNUSED1:
ret
BootloaderAPI_UNUSED2:
ret
BootloaderAPI_UNUSED3:
ret
BootloaderAPI_UNUSED4:
ret
BootloaderAPI_UNUSED5:
ret
; API function jump table
.section .apitable_jumptable, "ax"
.global BootloaderAPI_JumpTable
BootloaderAPI_JumpTable:
rjmp BootloaderAPI_ErasePage_Trampoline
rjmp BootloaderAPI_WritePage_Trampoline
rjmp BootloaderAPI_FillWord_Trampoline
rjmp BootloaderAPI_ReadSignature_Trampoline
rjmp BootloaderAPI_ReadFuse_Trampoline
rjmp BootloaderAPI_ReadLock_Trampoline
rjmp BootloaderAPI_WriteLock_Trampoline
rjmp BootloaderAPI_UNUSED1 ; UNUSED ENTRY 1
rjmp BootloaderAPI_UNUSED2 ; UNUSED ENTRY 2
rjmp BootloaderAPI_UNUSED3 ; UNUSED ENTRY 3
rjmp BootloaderAPI_UNUSED4 ; UNUSED ENTRY 4
rjmp BootloaderAPI_UNUSED5 ; UNUSED ENTRY 5
; Bootloader table signatures and information
.section .apitable_signatures, "ax"
.global BootloaderAPI_Signatures
BootloaderAPI_Signatures:
.long BOOT_START_ADDR ; Start address of the bootloader
.word 0xDF00 ; Signature for the CDC class bootloader
.word 0xDCFB ; Signature for a LUFA class bootloader

View File

@ -0,0 +1,641 @@
/*
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 CDC class bootloader. This file contains the complete bootloader logic.
*/
#define INCLUDE_FROM_BOOTLOADERCDC_C
#include "BootloaderCDC.h"
/** Contains the current baud rate and other settings of the first virtual serial port. This must be retained as some
* operating systems will not open the port unless the settings can be set successfully.
*/
static CDC_LineEncoding_t LineEncoding = { .BaudRateBPS = 0,
.CharFormat = CDC_LINEENCODING_OneStopBit,
.ParityType = CDC_PARITY_None,
.DataBits = 8 };
/** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host,
* and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued
* command.)
*/
static uint32_t CurrAddress;
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
* via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite
* loop until the AVR restarts and the application runs.
*/
static bool RunBootloader = true;
/** Magic lock for forced application start. If the HWBE fuse is programmed and BOOTRST is unprogrammed, the bootloader
* will start if the /HWB line of the AVR is held low and the system is reset. However, if the /HWB line is still held
* low when the application attempts to start via a watchdog reset, the bootloader will re-start. If set to the value
* \ref MAGIC_BOOT_KEY the special init function \ref Application_Jump_Check() will force the application to start.
*/
uint16_t MagicBootKey ATTR_NO_INIT;
/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
* start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
* this will force the user application to start via a software jump.
*/
void Application_Jump_Check(void)
{
bool JumpToApplication = false;
#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
/* Disable JTAG debugging */
JTAG_DISABLE();
/* Enable pull-up on the JTAG TCK pin so we can use it to select the mode */
PORTF |= (1 << 4);
Delay_MS(10);
/* If the TCK pin is not jumpered to ground, start the user application instead */
JumpToApplication |= ((PINF & (1 << 4)) != 0);
/* Re-enable JTAG debugging */
JTAG_ENABLE();
#endif
/* If the reset source was the bootloader and the key is correct, clear it and jump to the application */
if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
JumpToApplication |= true;
/* If a request has been made to jump to the user application, honor it */
if (JumpToApplication)
{
/* Turn off the watchdog */
MCUSR &= ~(1<<WDRF);
wdt_disable();
/* Clear the boot key and jump to the user application */
MagicBootKey = 0;
// cppcheck-suppress constStatement
((void (*)(void))0x0000)();
}
}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
* runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
* the loaded application code.
*/
int main(void)
{
/* Setup hardware required for the bootloader */
SetupHardware();
/* Turn on first LED on the board to indicate that the bootloader has started */
LEDs_SetAllLEDs(LEDS_LED1);
/* Enable global interrupts so that the USB stack can function */
GlobalInterruptEnable();
while (RunBootloader)
{
CDC_Task();
USB_USBTask();
}
/* Disconnect from the host - USB interface will be reset later along with the AVR */
USB_Detach();
/* Unlock the forced application start mode of the bootloader if it is restarted */
MagicBootKey = MAGIC_BOOT_KEY;
/* Enable the watchdog and force a timeout to reset the AVR */
wdt_enable(WDTO_250MS);
for (;;);
}
/** Configures all hardware required for the bootloader. */
static void SetupHardware(void)
{
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();
/* Disable clock division */
clock_prescale_set(clock_div_1);
/* Relocate the interrupt vector table to the bootloader section */
MCUCR = (1 << IVCE);
MCUCR = (1 << IVSEL);
/* Initialize the USB and other board hardware drivers */
USB_Init();
LEDs_Init();
/* Bootloader active LED toggle timer initialization */
TIMSK1 = (1 << TOIE1);
TCCR1B = ((1 << CS11) | (1 << CS10));
}
/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */
ISR(TIMER1_OVF_vect, ISR_BLOCK)
{
LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
}
/** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready
* to relay data to and from the attached USB host.
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Setup CDC Notification, Rx and Tx Endpoints */
Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT,
CDC_NOTIFICATION_EPSIZE, 1);
Endpoint_ConfigureEndpoint(CDC_TX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
Endpoint_ConfigureEndpoint(CDC_RX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
}
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
* the device from the USB host before passing along unhandled control requests to the library for processing
* internally.
*/
void EVENT_USB_Device_ControlRequest(void)
{
/* Ignore any requests that aren't directed to the CDC interface */
if ((USB_ControlRequest.bmRequestType & (CONTROL_REQTYPE_TYPE | CONTROL_REQTYPE_RECIPIENT)) !=
(REQTYPE_CLASS | REQREC_INTERFACE))
{
return;
}
/* Activity - toggle indicator LEDs */
LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
/* Process CDC specific control requests */
switch (USB_ControlRequest.bRequest)
{
case CDC_REQ_GetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
/* Write the line coding data to the control endpoint */
Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t));
Endpoint_ClearOUT();
}
break;
case CDC_REQ_SetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
/* Read the line coding data in from the host into the global struct */
Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t));
Endpoint_ClearIN();
}
break;
case CDC_REQ_SetControlLineState:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();
}
break;
}
}
#if !defined(NO_BLOCK_SUPPORT)
/** Reads or writes a block of EEPROM or FLASH memory to or from the appropriate CDC data endpoint, depending
* on the AVR109 protocol command issued.
*
* \param[in] Command Single character AVR109 protocol command indicating what memory operation to perform
*/
static void ReadWriteMemoryBlock(const uint8_t Command)
{
uint16_t BlockSize;
char MemoryType;
uint8_t HighByte = 0;
uint8_t LowByte = 0;
BlockSize = (FetchNextCommandByte() << 8);
BlockSize |= FetchNextCommandByte();
MemoryType = FetchNextCommandByte();
if ((MemoryType != MEMORY_TYPE_FLASH) && (MemoryType != MEMORY_TYPE_EEPROM))
{
/* Send error byte back to the host */
WriteNextResponseByte('?');
return;
}
/* Check if command is to read a memory block */
if (Command == AVR109_COMMAND_BlockRead)
{
/* Re-enable RWW section */
boot_rww_enable();
while (BlockSize--)
{
if (MemoryType == MEMORY_TYPE_FLASH)
{
/* Read the next FLASH byte from the current FLASH page */
#if (FLASHEND > 0xFFFF)
WriteNextResponseByte(pgm_read_byte_far(CurrAddress | HighByte));
#else
WriteNextResponseByte(pgm_read_byte(CurrAddress | HighByte));
#endif
/* If both bytes in current word have been read, increment the address counter */
if (HighByte)
CurrAddress += 2;
HighByte = !HighByte;
}
else
{
/* Read the next EEPROM byte into the endpoint */
WriteNextResponseByte(eeprom_read_byte((uint8_t*)(intptr_t)(CurrAddress >> 1)));
/* Increment the address counter after use */
CurrAddress += 2;
}
}
}
else
{
uint32_t PageStartAddress = CurrAddress;
if (MemoryType == MEMORY_TYPE_FLASH)
{
boot_page_erase(PageStartAddress);
boot_spm_busy_wait();
}
while (BlockSize--)
{
if (MemoryType == MEMORY_TYPE_FLASH)
{
/* If both bytes in current word have been written, increment the address counter */
if (HighByte)
{
/* Write the next FLASH word to the current FLASH page */
boot_page_fill(CurrAddress, ((FetchNextCommandByte() << 8) | LowByte));
/* Increment the address counter after use */
CurrAddress += 2;
}
else
{
LowByte = FetchNextCommandByte();
}
HighByte = !HighByte;
}
else
{
/* Write the next EEPROM byte from the endpoint */
eeprom_write_byte((uint8_t*)((intptr_t)(CurrAddress >> 1)), FetchNextCommandByte());
/* Increment the address counter after use */
CurrAddress += 2;
}
}
/* If in FLASH programming mode, commit the page after writing */
if (MemoryType == MEMORY_TYPE_FLASH)
{
/* Commit the flash page to memory */
boot_page_write(PageStartAddress);
/* Wait until write operation has completed */
boot_spm_busy_wait();
}
/* Send response byte back to the host */
WriteNextResponseByte('\r');
}
}
#endif
/** Retrieves the next byte from the host in the CDC data OUT endpoint, and clears the endpoint bank if needed
* to allow reception of the next data packet from the host.
*
* \return Next received byte from the host in the CDC data OUT endpoint
*/
static uint8_t FetchNextCommandByte(void)
{
/* Select the OUT endpoint so that the next data byte can be read */
Endpoint_SelectEndpoint(CDC_RX_EPADDR);
/* If OUT endpoint empty, clear it and wait for the next packet from the host */
while (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
while (!(Endpoint_IsOUTReceived()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return 0;
}
}
/* Fetch the next byte from the OUT endpoint */
return Endpoint_Read_8();
}
/** Writes the next response byte to the CDC data IN endpoint, and sends the endpoint back if needed to free up the
* bank when full ready for the next byte in the packet to the host.
*
* \param[in] Response Next response byte to send to the host
*/
static void WriteNextResponseByte(const uint8_t Response)
{
/* Select the IN endpoint so that the next data byte can be written */
Endpoint_SelectEndpoint(CDC_TX_EPADDR);
/* If IN endpoint full, clear it and wait until ready for the next packet to the host */
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
}
/* Write the next byte to the IN endpoint */
Endpoint_Write_8(Response);
}
/** Task to read in AVR109 commands from the CDC data OUT endpoint, process them, perform the required actions
* and send the appropriate response back to the host.
*/
static void CDC_Task(void)
{
/* Select the OUT endpoint */
Endpoint_SelectEndpoint(CDC_RX_EPADDR);
/* Check if endpoint has a command in it sent from the host */
if (!(Endpoint_IsOUTReceived()))